Skip to content

Commit c2958f4

Browse files
author
AJ Keller
committed
Add tests for new daisy code and Enh separated radio tests from main board test
1 parent 0dd0ece commit c2958f4

File tree

6 files changed

+1174
-917
lines changed

6 files changed

+1174
-917
lines changed

changelog.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
### New Features
44
* New simulator option `simulatorDaisyModuleCanBeAttached` - Boolean, deafults to true, allows the simulation of the a hot swapped daisy board or simulates a misinformed module.
5+
* New `EventEmitter` - `hardSet` - for when the module detects the board is not configured as the options for the module intended and tries to save itself. i.e. when the `daisy` option is `true` and a soft reset message is parsed and the module determines that a daisy was not detected, the module will emit `hardSet` then send an attach daisy command to recover. Either `error` will be emitted if unable to attach or `ready` will be emitted if success.
6+
7+
### Breaking changes
8+
* `.setInfoForBoardType()` changed to `.overrideInfoForBoardType()` to elevate it's dangerous nature.
9+
* `.setMaxChannels()` changed to `.hardSetBoardType()` and input changed from numerical to string: 8 and 16 to `default` and `daisy` respectively.
510

611
### Bug Fixes
712
* Fixes #131 - 16 chan not working by sending a channel command and parsing the return.
813
* Fixed bug where end of transmission characters would not be ejected from buffer.
9-
10-
### Breaking changes
11-
* `.overrideInfoForBoardType()` changed to `.overrideInfoForBoardType()` to elevate it's dangerous nature.
14+
15+
### Enhancements
16+
* Separated radio tests from main board test file.
1217

1318
# 1.4.4
1419

openBCIBoard.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function OpenBCIFactory () {
2020
var _options = {
2121
boardType: [k.OBCIBoardDefault, k.OBCIBoardDaisy, k.OBCIBoardGanglion],
2222
baudRate: 115200,
23+
hardSet: false,
2324
simulate: false,
2425
simulatorBoardFailure: false,
2526
simulatorDaisyModuleAttached: false,
@@ -54,6 +55,10 @@ function OpenBCIFactory () {
5455
* `ganglion` - 4 Channel board
5556
* (NOTE: THIS IS IN-OP TIL RELEASE OF GANGLION BOARD 07/2016)
5657
*
58+
* - `hardSet` {Boolean} - Recommended if using `daisy` board! For some reason, the `daisy` is sometimes
59+
* not picked up by the module so you can set `hardSet` to true which will ensure the daisy
60+
* is picked up. (Default `false`)
61+
*
5762
* - `simulate` {Boolean} - Full functionality, just mock data. Must attach Daisy module by setting
5863
* `simulatorDaisyModuleAttached` to `true` in order to get 16 channels. (Default `false`)
5964
*
@@ -1056,12 +1061,18 @@ function OpenBCIFactory () {
10561061
this.info.boardType = k.OBCIBoardDaisy;
10571062
this.info.numberOfChannels = k.OBCINumberOfChannelsDaisy;
10581063
this.info.sampleRate = k.OBCISampleRate125;
1064+
this.channelSettingsArray = k.channelSettingsArrayInit(k.OBCINumberOfChannelsDaisy);
1065+
this.goertzelObject = openBCISample.goertzelNewObject(k.OBCINumberOfChannelsDaisy);
1066+
this.impedanceArray = openBCISample.impedanceArray(k.OBCINumberOfChannelsDaisy);
10591067
break;
10601068
case k.OBCIBoardDefault:
10611069
default:
10621070
this.info.boardType = k.OBCIBoardDefault;
10631071
this.info.numberOfChannels = k.OBCINumberOfChannelsDefault;
10641072
this.info.sampleRate = k.OBCISampleRate250;
1073+
this.channelSettingsArray = k.channelSettingsArrayInit(k.OBCINumberOfChannelsDefault);
1074+
this.goertzelObject = openBCISample.goertzelNewObject(k.OBCINumberOfChannelsDefault);
1075+
this.impedanceArray = openBCISample.impedanceArray(k.OBCINumberOfChannelsDefault);
10651076
break;
10661077
}
10671078
};
@@ -1807,7 +1818,7 @@ function OpenBCIFactory () {
18071818
case k.OBCIParsingEOT:
18081819
if (openBCISample.doesBufferHaveEOT(data)) {
18091820
this.curParsingMode = k.OBCIParsingNormal;
1810-
this.emit('eot', data);
1821+
this.emit(k.OBCIEmitterEot, data);
18111822
this.buffer = openBCISample.stripToEOTBuffer(data);
18121823
} else {
18131824
this.buffer = data;
@@ -1817,9 +1828,31 @@ function OpenBCIFactory () {
18171828
// Does the buffer have an EOT in it?
18181829
if (openBCISample.doesBufferHaveEOT(data)) {
18191830
this._processParseBufferForReset(data);
1820-
this.curParsingMode = k.OBCIParsingNormal;
1821-
this.emit('ready');
1822-
this.buffer = openBCISample.stripToEOTBuffer(data);
1831+
if (this.options.hardSet) {
1832+
if (this.getBoardType() !== this.options.boardType) {
1833+
this.emit(k.OBCIEmitterHardSet);
1834+
this.hardSetBoardType(this.options.boardType)
1835+
.then(() => {
1836+
this.emit(k.OBCIEmitterReady)
1837+
})
1838+
.catch((err) => {
1839+
this.emit(k.OBCIEmitterError, err);
1840+
});
1841+
1842+
} else {
1843+
this.curParsingMode = k.OBCIParsingNormal;
1844+
this.emit(k.OBCIEmitterReady);
1845+
this.buffer = openBCISample.stripToEOTBuffer(data);
1846+
}
1847+
1848+
} else {
1849+
if (this.getBoardType() !== this.options.boardType && this.options.verbose) {
1850+
console.log(`Module detected ${this.getBoardType()} board type but you specified ${this.options.boardType}, use 'hardSet' to force the module to correct itself`);
1851+
}
1852+
this.curParsingMode = k.OBCIParsingNormal;
1853+
this.emit(k.OBCIEmitterReady);
1854+
this.buffer = openBCISample.stripToEOTBuffer(data);
1855+
}
18231856
} else {
18241857
this.buffer = data;
18251858
}

openBCIConstants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ const obciEmitterClose = 'close';
342342
const obciEmitterDroppedPacket = 'droppedPacket';
343343
const obciEmitterEot = 'eot';
344344
const obciEmitterError = 'error';
345+
const obciEmitterHardSet = 'hardSet';
345346
const obciEmitterImpedanceArray = 'impedanceArray';
346347
const obciEmitterQuery = 'query';
347348
const obciEmitterRawDataPacket = 'rawDataPacket';
@@ -907,6 +908,7 @@ module.exports = {
907908
OBCIEmitterDroppedPacket: obciEmitterDroppedPacket,
908909
OBCIEmitterEot: obciEmitterEot,
909910
OBCIEmitterError: obciEmitterError,
911+
OBCIEmitterHardSet: obciEmitterHardSet,
910912
OBCIEmitterImpedanceArray: obciEmitterImpedanceArray,
911913
OBCIEmitterQuery: obciEmitterQuery,
912914
OBCIEmitterRawDataPacket: obciEmitterRawDataPacket,

test/OpenBCIConstants-test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ describe('OpenBCIConstants', function () {
448448
assert.equal('daisy removed', k.OBCIChannelMaxNumber8SuccessDaisyRemoved);
449449
assert.equal('16', k.OBCIChannelMaxNumber16DaisyAlreadyAttached);
450450
assert.equal('daisy attached16', k.OBCIChannelMaxNumber16DaisyAttached);
451-
assert.equal('no daisy to attach!', k.OBCIChannelMaxNumber16NoDaisyAttached);
451+
assert.equal('no daisy to attach!8', k.OBCIChannelMaxNumber16NoDaisyAttached);
452452
});
453453
});
454454
describe('On board filters', function () {
@@ -1453,6 +1453,9 @@ describe('OpenBCIConstants', function () {
14531453
it('Event Emitter Error', function () {
14541454
assert.equal('error', k.OBCIEmitterError);
14551455
});
1456+
it('Event Emitter Hard Set', function () {
1457+
assert.equal('hardSet', k.OBCIEmitterHardSet);
1458+
});
14561459
it('Event Emitter Impedance Array', function () {
14571460
assert.equal('impedanceArray', k.OBCIEmitterImpedanceArray);
14581461
});

0 commit comments

Comments
 (0)