Add: max channel support for simulator

Esse commit está contido em:
AJ Keller
2017-01-03 00:25:34 -05:00
commit 0dd0eceb46
11 arquivos alterados com 379 adições e 116 exclusões
+1 -1
Ver Arquivo
@@ -847,7 +847,7 @@ Stop logging to the SD card and close any open file. If you are not streaming wh
**_Returns_** resolves if the command was added to the write queue.
### <a name="method-set-info-for-board-type"></a> .setInfoForBoardType(boardType)
### <a name="method-set-info-for-board-type"></a> .overrideInfoForBoardType(boardType)
Set the info property for board type.
+14 -2
Ver Arquivo
@@ -1,9 +1,21 @@
# 1.5.0
### New Features
* New simulator option `simulatorDaisyModuleCanBeAttached` - Boolean, deafults to true, allows the simulation of the a hot swapped daisy board or simulates a misinformed module.
### Bug Fixes
* Fixes #131 - 16 chan not working by sending a channel command and parsing the return.
* Fixed bug where end of transmission characters would not be ejected from buffer.
### Breaking changes
* `.overrideInfoForBoardType()` changed to `.overrideInfoForBoardType()` to elevate it's dangerous nature.
# 1.4.4
### New Features
* Set max number of channels for the board to use with `.setMaxChannels()` see readme.md
* Set the core info object that drives the module with `.setInfoForBoardType()` see readme.md
* Get info for the core obhect that drives the module with `.getInfo()` see readme.md
* Set the core info object that drives the module with `.overrideInfoForBoardType()` see readme.md
* Get info for the core object that drives the module with `.getInfo()` see readme.md
### Work In Progress
* Bug where daisy would sometimes not be recognized which destroyed all data.
+154 -89
Ver Arquivo
@@ -23,6 +23,7 @@ function OpenBCIFactory () {
simulate: false,
simulatorBoardFailure: false,
simulatorDaisyModuleAttached: false,
simulatorDaisyModuleCanBeAttached: true,
simulatorFirmwareVersion: [k.OBCIFirmwareV1, k.OBCIFirmwareV2],
simulatorFragmentation: [k.OBCISimulatorFragmentationNone, k.OBCISimulatorFragmentationRandom, k.OBCISimulatorFragmentationFullBuffers, k.OBCISimulatorFragmentationOneByOne],
simulatorLatencyTime: 16,
@@ -41,80 +42,84 @@ function OpenBCIFactory () {
};
/**
* @description The initialization method to call first, before any other method.
* @param options (optional) - Board optional configurations.
* - `baudRate` {Number} - Baud Rate, defaults to 115200. Manipulating this is allowed if
* firmware on board has been previously configured.
*
* - `boardType` {String} - Specifies type of OpenBCI board.
* 3 Possible Boards:
* `default` - 8 Channel OpenBCI board (Default)
* `daisy` - 8 Channel OpenBCI board with Daisy Module. Total of 16 channels.
* `ganglion` - 4 Channel board
* (NOTE: THIS IS IN-OP TIL RELEASE OF GANGLION BOARD 07/2016)
*
* - `simulate` {Boolean} - Full functionality, just mock data. Must attach Daisy module by setting
* `simulatorDaisyModuleAttached` to `true` in order to get 16 channels. (Default `false`)
*
* - `simulatorBoardFailure` {Boolean} - Simulates board communications failure. This occurs when the RFduino on
* the board is not polling the RFduino on the dongle. (Default `false`)
*
* - `simulatorDaisyModuleAttached` {Boolean} - Simulates a daisy module being attached to the OpenBCI board.
* This is useful if you want to test how your application reacts to a user requesting 16 channels
* but there is no daisy module actually attached, or vice versa, where there is a daisy module
* attached and the user only wants to use 8 channels. (Default `false`)
*
* - `simulatorFirmwareVersion` {String} - Allows simulator to be started with firmware version 2 features
* 2 Possible Options:
* `v1` - Firmware Version 1 (Default)
* `v2` - Firmware Version 2
*
* - `simulatorFragmentation` {String} - Specifies how to break packets to simulate fragmentation, which
* occurs commonly in real devices. It is recommended to test code with this enabled.
* 4 Possible Options:
* `none` - do not fragment packets; output complete chunks immediately when produced (Default)
* `random` - output random small chunks of data interspersed with full buffers
* `fullBuffers` - allow buffers to fill up until the latency timer has expired
* `oneByOne` - output each byte separately
*
* - `simulatorLatencyTime` {Number} - The time in milliseconds to wait before sending partially full buffers,
if `simulatorFragmentation` is specified. (Default `16`)
*
* - `simulatorBufferSize` {Number} - The size of a full buffer of data, if `simulatorFragmentation` is
* specified. (Default `4096`)
*
* - `simulatorHasAccelerometer` - {Boolean} - Sets simulator to send packets with accelerometer data. (Default `true`)
*
* - `simulatorInjectAlpha` - {Boolean} - Inject a 10Hz alpha wave in Channels 1 and 2 (Default `true`)
*
* - `simulatorInjectLineNoise` {String} - Injects line noise on channels.
* 3 Possible Options:
* `60Hz` - 60Hz line noise (Default) [America]
* `50Hz` - 50Hz line noise [Europe]
* `none` - Do not inject line noise.
*
* - `simulatorSampleRate` {Number} - The sample rate to use for the simulator. Simulator will set to 125 if
* `simulatorDaisyModuleAttached` is set `true`. However, setting this option overrides that
* setting and this sample rate will be used. (Default is `250`)
*
* - `simulatorSerialPortFailure` {Boolean} - Simulates not being able to open a serial connection. Most likely
* due to a OpenBCI dongle not being plugged in.
*
* - `sntpTimeSync` - {Boolean} Syncs the module up with an SNTP time server and uses that as single source
* of truth instead of local computer time. If you are running experiements on your local
* computer, keep this `false`. (Default `false`)
*
* - `sntpTimeSyncHost` - {String} The ntp server to use, can be either sntp or ntp. (Defaults `pool.ntp.org`).
*
* - `sntpTimeSyncPort` - {Number} The port to access the ntp server. (Defaults `123`)
*
* - `verbose` {Boolean} - Print out useful debugging events. (Default `false`)
*
* - `debug` {Boolean} - Print out a raw dump of bytes sent and received. (Default `false`)
*
* @constructor
* @author AJ Keller (@pushtheworldllc)
*/
* @description The initialization method to call first, before any other method.
* @param options (optional) - Board optional configurations.
* - `baudRate` {Number} - Baud Rate, defaults to 115200. Manipulating this is allowed if
* firmware on board has been previously configured.
*
* - `boardType` {String} - Specifies type of OpenBCI board.
* 3 Possible Boards:
* `default` - 8 Channel OpenBCI board (Default)
* `daisy` - 8 Channel OpenBCI board with Daisy Module. Total of 16 channels.
* `ganglion` - 4 Channel board
* (NOTE: THIS IS IN-OP TIL RELEASE OF GANGLION BOARD 07/2016)
*
* - `simulate` {Boolean} - Full functionality, just mock data. Must attach Daisy module by setting
* `simulatorDaisyModuleAttached` to `true` in order to get 16 channels. (Default `false`)
*
* - `simulatorBoardFailure` {Boolean} - Simulates board communications failure. This occurs when the RFduino on
* the board is not polling the RFduino on the dongle. (Default `false`)
*
* - `simulatorDaisyModuleAttached` {Boolean} - Simulates a daisy module being attached to the OpenBCI board.
* This is useful if you want to test how your application reacts to a user requesting 16 channels
* but there is no daisy module actually attached, or vice versa, where there is a daisy module
* attached and the user only wants to use 8 channels. (Default `false`)
*
* - `simulatorDaisyModuleCanBeAttached` {Boolean} - Allows the simulation of the a hot swapped daisy board.
* For example: You coule simulate if the board has only detected 8 channels and the user requested
* 16 channels. (Default `true`)
*
* - `simulatorFirmwareVersion` {String} - Allows simulator to be started with firmware version 2 features
* 2 Possible Options:
* `v1` - Firmware Version 1 (Default)
* `v2` - Firmware Version 2
*
* - `simulatorFragmentation` {String} - Specifies how to break packets to simulate fragmentation, which
* occurs commonly in real devices. It is recommended to test code with this enabled.
* 4 Possible Options:
* `none` - do not fragment packets; output complete chunks immediately when produced (Default)
* `random` - output random small chunks of data interspersed with full buffers
* `fullBuffers` - allow buffers to fill up until the latency timer has expired
* `oneByOne` - output each byte separately
*
* - `simulatorLatencyTime` {Number} - The time in milliseconds to wait before sending partially full buffers,
* if `simulatorFragmentation` is specified. (Default `16`)
*
* - `simulatorBufferSize` {Number} - The size of a full buffer of data, if `simulatorFragmentation` is
* specified. (Default `4096`)
*
* - `simulatorHasAccelerometer` - {Boolean} - Sets simulator to send packets with accelerometer data. (Default `true`)
*
* - `simulatorInjectAlpha` - {Boolean} - Inject a 10Hz alpha wave in Channels 1 and 2 (Default `true`)
*
* - `simulatorInjectLineNoise` {String} - Injects line noise on channels.
* 3 Possible Options:
* `60Hz` - 60Hz line noise (Default) [America]
* `50Hz` - 50Hz line noise [Europe]
* `none` - Do not inject line noise.
*
* - `simulatorSampleRate` {Number} - The sample rate to use for the simulator. Simulator will set to 125 if
* `simulatorDaisyModuleAttached` is set `true`. However, setting this option overrides that
* setting and this sample rate will be used. (Default is `250`)
*
* - `simulatorSerialPortFailure` {Boolean} - Simulates not being able to open a serial connection. Most likely
* due to a OpenBCI dongle not being plugged in.
*
* - `sntpTimeSync` - {Boolean} Syncs the module up with an SNTP time server and uses that as single source
* of truth instead of local computer time. If you are running experiements on your local
* computer, keep this `false`. (Default `false`)
*
* - `sntpTimeSyncHost` - {String} The ntp server to use, can be either sntp or ntp. (Defaults `pool.ntp.org`).
*
* - `sntpTimeSyncPort` - {Number} The port to access the ntp server. (Defaults `123`)
*
* - `verbose` {Boolean} - Print out useful debugging events. (Default `false`)
*
* - `debug` {Boolean} - Print out a raw dump of bytes sent and received. (Default `false`)
*
* @constructor
* @author AJ Keller (@pushtheworldllc)
*/
function OpenBCIBoard (options) {
options = (typeof options !== 'function') && options || {};
var opts = {};
@@ -206,6 +211,7 @@ function OpenBCIFactory () {
this.timeOfPacketArrival = 0;
this.writeOutDelay = k.OBCIWriteIntervalDelayMSShort;
// Strings
this.portName = null;
// NTP
if (this.options.sntpTimeSync) {
@@ -254,6 +260,7 @@ function OpenBCIFactory () {
alpha: this.options.simulatorInjectAlpha,
boardFailure: this.options.simulatorBoardFailure,
daisy: this.options.simulatorDaisyModuleAttached,
daisyCanBeAttached: this.options.simulatorDaisyModuleCanBeAttached,
drift: this.options.simulatorInternalClockDrift,
firmwareVersion: this.options.simulatorFirmwareVersion,
fragmentation: this.options.simulatorFragmentation,
@@ -378,14 +385,24 @@ function OpenBCIFactory () {
return this.serial.isOpen();
};
/**
* @description Checks if the board is currently sending samples.
* @returns {boolean} - True if streaming.
*/
OpenBCIBoard.prototype.isSimulating = function () {
return this.options.simulate;
};
/**
* @description Checks if the board is currently sending samples.
* @returns {boolean} - True if streaming.
*/
OpenBCIBoard.prototype.isStreaming = function () {
return this._streaming;
};
/**
* @description Sends a start streaming command to the board.
* @returns {Promise} indicating if the signal was able to be sent.
@@ -1012,6 +1029,14 @@ function OpenBCIFactory () {
});
};
/**
* Get the board type.
* @return boardType: string
*/
OpenBCIBoard.prototype.getBoardType = function() {
return this.info.boardType;
};
/**
* Get the core info object.
* @return {{boardType: string, sampleRate: number, firmware: string, numberOfChannels: number, missedPackets: number}}
@@ -1025,7 +1050,7 @@ function OpenBCIFactory () {
* @param boardType {String}
* `default` or `daisy`. Defaults to `default`.
*/
OpenBCIBoard.prototype.setInfoForBoardType = function(boardType) {
OpenBCIBoard.prototype.overrideInfoForBoardType = function(boardType) {
switch (boardType) {
case k.OBCIBoardDaisy:
this.info.boardType = k.OBCIBoardDaisy;
@@ -1043,20 +1068,60 @@ function OpenBCIFactory () {
/**
* Used to set the max number of channels on the Cyton board.
* @param numberOfChannels {number}
* Either 8 or 16
* @param boardType {String}
* Either `default` or `daisy`
* @return {Promise}
*/
OpenBCIBoard.prototype.setMaxChannels = function (numberOfChannels) {
if (numberOfChannels === k.OBCINumberOfChannelsDefault) {
this.curParsingMode = k.OBCIParsingEOT;
return this.write(k.OBCIChannelMaxNumber8);
} else if (numberOfChannels === k.OBCINumberOfChannelsDaisy) {
this.curParsingMode = k.OBCIParsingEOT;
return this.write(k.OBCIChannelMaxNumber16);
} else {
return Promise.reject('invalid number of channels');
}
OpenBCIBoard.prototype.hardSetBoardType = function (boardType) {
if (this.isStreaming()) return Promise.reject('Must not be streaming!');
return new Promise((resolve, reject) => {
const eotFunc = (data) => {
switch (data.slice(0, data.length - k.OBCIParseEOT.length).toString()) {
case k.OBCIChannelMaxNumber8NoDaisyToRemove:
this.overrideInfoForBoardType(k.OBCIBoardDefault);
resolve('no daisy to remove');
break;
case k.OBCIChannelMaxNumber8SuccessDaisyRemoved:
this.overrideInfoForBoardType(k.OBCIBoardDefault);
resolve('daisy removed');
break;
case k.OBCIChannelMaxNumber16DaisyAlreadyAttached:
this.overrideInfoForBoardType(k.OBCIBoardDaisy);
resolve('daisy already attached');
break;
case k.OBCIChannelMaxNumber16DaisyAttached:
this.overrideInfoForBoardType(k.OBCIBoardDaisy);
resolve('daisy attached');
break;
case k.OBCIChannelMaxNumber16NoDaisyAttached:
this.overrideInfoForBoardType(k.OBCIBoardDefault);
reject('unable to attach daisy');
break;
default:
reject(Error('invalid return, board may not be configured correctly.'));
break;
}
};
if (boardType === k.OBCIBoardDefault) {
this.curParsingMode = k.OBCIParsingEOT;
this.once(k.OBCIEmitterEot, eotFunc);
this.write(k.OBCIChannelMaxNumber8)
.catch((err) => {
this.removeListener(k.OBCIEmitterEot, eotFunc);
reject(err);
});
} else if (boardType === k.OBCIBoardDaisy) {
this.curParsingMode = k.OBCIParsingEOT;
this.once(k.OBCIEmitterEot, eotFunc);
this.write(k.OBCIChannelMaxNumber16)
.catch((err) => {
this.removeListener(k.OBCIEmitterEot, eotFunc);
reject(err);
});
} else {
reject('invalid board type');
}
});
};
/**
@@ -1854,9 +1919,9 @@ function OpenBCIFactory () {
*/
OpenBCIBoard.prototype._processParseBufferForReset = function (dataBuffer) {
if (openBCISample.countADSPresent(dataBuffer) === 2) {
this.setInfoForBoardType(k.OBCIBoardDaisy);
this.overrideInfoForBoardType(k.OBCIBoardDaisy);
} else {
this.setInfoForBoardType(k.OBCIBoardDefault);
this.overrideInfoForBoardType(k.OBCIBoardDefault);
}
if (openBCISample.findV2Firmware(dataBuffer)) {
+12
Ver Arquivo
@@ -156,6 +156,11 @@ const obciMiscSoftReset = 'v';
/** 16 Channel Commands */
const obciChannelMaxNumber8 = 'c';
const obciChannelMaxNumber16 = 'C';
const obciChannelMaxNumber8NoDaisyToRemove = '';
const obciChannelMaxNumber8SuccessDaisyRemoved = 'daisy removed';
const obciChannelMaxNumber16DaisyAlreadyAttached = '16';
const obciChannelMaxNumber16DaisyAttached = 'daisy attached16';
const obciChannelMaxNumber16NoDaisyAttached = 'no daisy to attach!8';
/** 60Hz line filter */
const obciFilterDisable = 'g';
@@ -335,6 +340,7 @@ const obciRadioBaudRateFastStr = 'fast';
/** Emitters */
const obciEmitterClose = 'close';
const obciEmitterDroppedPacket = 'droppedPacket';
const obciEmitterEot = 'eot';
const obciEmitterError = 'error';
const obciEmitterImpedanceArray = 'impedanceArray';
const obciEmitterQuery = 'query';
@@ -724,6 +730,11 @@ module.exports = {
/** 16 Channel Commands */
OBCIChannelMaxNumber8: obciChannelMaxNumber8,
OBCIChannelMaxNumber16: obciChannelMaxNumber16,
OBCIChannelMaxNumber8NoDaisyToRemove: obciChannelMaxNumber8NoDaisyToRemove,
OBCIChannelMaxNumber8SuccessDaisyRemoved: obciChannelMaxNumber8SuccessDaisyRemoved,
OBCIChannelMaxNumber16DaisyAlreadyAttached: obciChannelMaxNumber16DaisyAlreadyAttached,
OBCIChannelMaxNumber16DaisyAttached: obciChannelMaxNumber16DaisyAttached,
OBCIChannelMaxNumber16NoDaisyAttached: obciChannelMaxNumber16NoDaisyAttached,
/** Filters */
OBCIFilterDisable: obciFilterDisable,
OBCIFilterEnable: obciFilterEnable,
@@ -894,6 +905,7 @@ module.exports = {
/** Emitters */
OBCIEmitterClose: obciEmitterClose,
OBCIEmitterDroppedPacket: obciEmitterDroppedPacket,
OBCIEmitterEot: obciEmitterEot,
OBCIEmitterError: obciEmitterError,
OBCIEmitterImpedanceArray: obciEmitterImpedanceArray,
OBCIEmitterQuery: obciEmitterQuery,
+1 -1
Ver Arquivo
@@ -1119,7 +1119,7 @@ function isSuccessInBuffer (dataBuffer) {
*/
function stripToEOTBuffer (dataBuffer) {
let indexOfEOT = dataBuffer.indexOf(k.OBCIParseEOT);
if (indexOfEOT > 0) {
if (indexOfEOT >= 0) {
indexOfEOT += k.OBCIParseEOT.length;
} else {
return dataBuffer;
+25
Ver Arquivo
@@ -15,6 +15,7 @@ function OpenBCISimulatorFactory () {
alpha: true,
boardFailure: false,
daisy: false,
daisyCanBeAttached: true,
drift: 0,
firmwareVersion: [k.OBCIFirmwareV1, k.OBCIFirmwareV2],
fragmentation: [k.OBCISimulatorFragmentationNone, k.OBCISimulatorFragmentationRandom, k.OBCISimulatorFragmentationFullBuffers, k.OBCISimulatorFragmentationOneByOne],
@@ -252,6 +253,30 @@ function OpenBCISimulatorFactory () {
}, 10);
}
break;
case k.OBCIChannelMaxNumber8:
if (this.options.daisy) {
this.options.daisy = false;
this._output(new Buffer(k.OBCIChannelMaxNumber8SuccessDaisyRemoved));
this._printEOT();
} else {
this._printEOT();
}
break;
case k.OBCIChannelMaxNumber16:
if (this.options.daisy) {
this._output(new Buffer(k.OBCIChannelMaxNumber16DaisyAlreadyAttached));
this._printEOT();
} else {
if (this.options.daisyCanBeAttached) {
this.options.daisy = true;
this._output(new Buffer(k.OBCIChannelMaxNumber16DaisyAttached));
this._printEOT();
} else {
this._output(new Buffer(k.OBCIChannelMaxNumber16NoDaisyAttached));
this._printEOT();
}
}
break;
default:
break;
}
+1 -1
Ver Arquivo
@@ -1,6 +1,6 @@
{
"name": "openbci",
"version": "1.4.4",
"version": "1.4.5",
"description": "The official Node.js SDK for the OpenBCI Biosensor Board.",
"main": "openBCIBoard",
"scripts": {
+10
Ver Arquivo
@@ -443,6 +443,13 @@ describe('OpenBCIConstants', function () {
it('sets max of 16', function () {
assert.equal('C', k.OBCIChannelMaxNumber16);
});
it('has correct return messages', function () {
assert.equal('', k.OBCIChannelMaxNumber8NoDaisyToRemove);
assert.equal('daisy removed', k.OBCIChannelMaxNumber8SuccessDaisyRemoved);
assert.equal('16', k.OBCIChannelMaxNumber16DaisyAlreadyAttached);
assert.equal('daisy attached16', k.OBCIChannelMaxNumber16DaisyAttached);
assert.equal('no daisy to attach!', k.OBCIChannelMaxNumber16NoDaisyAttached);
});
});
describe('On board filters', function () {
it('disable', function () {
@@ -1440,6 +1447,9 @@ describe('OpenBCIConstants', function () {
it('Event Emitter Dropped Packet', function () {
assert.equal('droppedPacket', k.OBCIEmitterDroppedPacket);
});
it('Event Emitter EOT', function () {
assert.equal('eot', k.OBCIEmitterEot);
});
it('Event Emitter Error', function () {
assert.equal('error', k.OBCIEmitterError);
});
+15
Ver Arquivo
@@ -1221,6 +1221,21 @@ $$$`);
}
expect(openBCISample.stripToEOTBuffer(buf).toString()).to.equal(buf.toString());
});
it('should slice the buffer after just eot $$$', function () {
let eotBuf = null;
let bufPost = null;
if (k.getVersionNumber(process.version) >= 6) {
// From introduced in node version 6.x.x
eotBuf = Buffer.from(k.OBCIParseEOT);
bufPost = Buffer.from('tacos');
} else {
eotBuf = new Buffer(k.OBCIParseEOT);
bufPost = new Buffer('tacos');
}
let totalBuf = Buffer.concat([eotBuf, bufPost]);
expect(openBCISample.stripToEOTBuffer(totalBuf).toString()).to.equal(bufPost.toString());
});
it('should slice the buffer after eot $$$', function () {
let bufPre = null;
let eotBuf = null;
+87 -21
Ver Arquivo
@@ -73,6 +73,7 @@ describe('openbci-sdk', function () {
expect(board.options.simulate).to.be.false;
expect(board.options.simulatorBoardFailure).to.be.false;
expect(board.options.simulatorDaisyModuleAttached).to.be.false;
expect(board.options.simulatorDaisyModuleCanBeAttached).to.be.true;
expect(board.options.simulatorFirmwareVersion).to.equal(k.OBCIFirmwareV1);
expect(board.options.simulatorHasAccelerometer).to.be.true;
expect(board.options.simulatorInternalClockDrift).to.equal(0);
@@ -402,6 +403,7 @@ describe('openbci-sdk', function () {
});
ourBoard.connect(k.OBCISimulatorPortName).catch(done);
ourBoard.on('ready', function () {
expect(ourBoard.isSimulating()).to.equal(true);
var disconnectSpy = sinon.spy(ourBoard, 'disconnect');
ourBoard.options.simulate.should.equal(true);
ourBoard.simulatorDisable().then(() => {
@@ -418,6 +420,7 @@ describe('openbci-sdk', function () {
simulate: true,
simulatorBoardFailure: true,
simulatorDaisyModuleAttached: true,
simulatorDaisyModuleCanBeAttached: false,
simulatorFirmwareVersion: k.OBCIFirmwareV2,
simulatorHasAccelerometer: false,
simulatorInternalClockDrift: -1,
@@ -439,6 +442,7 @@ describe('openbci-sdk', function () {
expect(simOptions.alpha).to.be.false;
expect(simOptions.boardFailure).to.be.true;
expect(simOptions.daisy).to.be.true;
expect(simOptions.daisyCanBeAttached).to.be.false;
expect(simOptions.drift).to.be.below(0);
expect(simOptions.firmwareVersion).to.be.equal(k.OBCIFirmwareV2);
expect(simOptions.fragmentation).to.be.equal(k.OBCISimulatorFragmentationOneByOne);
@@ -456,7 +460,7 @@ describe('openbci-sdk', function () {
ourBoard.info.boardType = 'burrito';
ourBoard.info.sampleRate = 60;
ourBoard.info.numberOfChannels = 200;
ourBoard.setInfoForBoardType('default');
ourBoard.overrideInfoForBoardType('default');
expect(ourBoard.getInfo().boardType).to.be.equal(k.OBCIBoardDefault);
expect(ourBoard.getInfo().numberOfChannels).to.be.equal(k.OBCINumberOfChannelsDefault);
expect(ourBoard.getInfo().sampleRate).to.be.equal(k.OBCISampleRate250);
@@ -465,7 +469,7 @@ describe('openbci-sdk', function () {
ourBoard.info.boardType = 'burrito';
ourBoard.info.sampleRate = 60;
ourBoard.info.numberOfChannels = 200;
ourBoard.setInfoForBoardType('daisy');
ourBoard.overrideInfoForBoardType('daisy');
expect(ourBoard.getInfo().boardType).to.be.equal(k.OBCIBoardDaisy);
expect(ourBoard.getInfo().numberOfChannels).to.be.equal(k.OBCINumberOfChannelsDaisy);
expect(ourBoard.getInfo().sampleRate).to.be.equal(k.OBCISampleRate125);
@@ -474,7 +478,7 @@ describe('openbci-sdk', function () {
ourBoard.info.boardType = 'burrito';
ourBoard.info.sampleRate = 60;
ourBoard.info.numberOfChannels = 200;
ourBoard.setInfoForBoardType('taco');
ourBoard.overrideInfoForBoardType('taco');
expect(ourBoard.getInfo().boardType).to.be.equal(k.OBCIBoardDefault);
expect(ourBoard.getInfo().numberOfChannels).to.be.equal(k.OBCINumberOfChannelsDefault);
expect(ourBoard.getInfo().sampleRate).to.be.equal(k.OBCISampleRate250);
@@ -814,36 +818,98 @@ describe('openbci-sdk', function () {
});
});
});
describe('#setMaxChannels', function () {
describe('#setBoardType', function () {
before(function (done) {
if (!ourBoard.isConnected()) {
ourBoard.connect(masterPortName)
.then(done)
.catch(err => done(err));
.catch(done);
} else {
done();
}
});
it('should write the command to set channels to 8', function (done) {
ourBoard.setMaxChannels(8)
.then(() => {
setTimeout(() => {
spy.should.have.been.calledWith(k.OBCIChannelMaxNumber8);
done();
}, 5 * k.OBCIWriteIntervalDelayMSShort);
}).catch(done);
after(function (done) {
ourBoard.disconnect()
.then(done)
.catch(done);
});
it('should write the command to set channels to 16', function (done) {
ourBoard.setMaxChannels(16)
.then(() => {
setTimeout(() => {
spy.should.have.been.calledWith(k.OBCIChannelMaxNumber16);
it('should resolve for setting max channels to 8 when already 8', function (done) {
if (ourBoard.isSimulating()) {
ourBoard.serial.options.daisy = false;
ourBoard.hardSetBoardType('default')
.then((res) => {
expect(res).to.equal('no daisy to remove');
expect(ourBoard.getBoardType()).to.equal(k.OBCIBoardDefault);
done();
}, 5 * k.OBCIWriteIntervalDelayMSShort);
}).catch(done);
}).catch(done);
} else {
done();
}
});
it('should resolve for setting max channels to 8', function (done) {
if (ourBoard.isSimulating()) {
ourBoard.serial.options.daisy = true;
ourBoard.hardSetBoardType('default')
.then((res) => {
expect(res).to.equal('daisy removed');
expect(ourBoard.getBoardType()).to.equal(k.OBCIBoardDefault);
done();
}).catch(done);
} else {
done();
}
});
it('should resolve for setting max channels to 16 if daisy already attached', function (done) {
if (ourBoard.isSimulating()) {
ourBoard.serial.options.daisy = true;
ourBoard.hardSetBoardType('daisy')
.then((res) => {
expect(res).to.equal('daisy already attached');
expect(ourBoard.getBoardType()).to.equal(k.OBCIBoardDaisy);
done();
}).catch(done);
} else {
done();
}
});
it('should resolve for setting max channels to 16 if daisy able to be attached', function (done) {
if (ourBoard.isSimulating()) {
ourBoard.serial.options.daisy = false;
ourBoard.hardSetBoardType('daisy')
.then((res) => {
expect(res).to.equal('daisy attached');
expect(ourBoard.getBoardType()).to.equal(k.OBCIBoardDaisy);
done();
}).catch(done);
} else {
done();
}
});
it('should reject when setting max channels to 16 if daisy not able to be attached', function (done) {
if (ourBoard.isSimulating()) {
ourBoard.serial.options.daisy = false;
ourBoard.serial.options.daisyCanBeAttached = false;
ourBoard.hardSetBoardType('daisy')
.then(done)
.catch((err) => {
expect(err).to.equal('unable to attach daisy');
expect(ourBoard.getBoardType()).to.equal(k.OBCIBoardDefault);
done();
});
} else {
done();
}
});
it('should not write a command if invalid channel number', function (done) {
ourBoard.setMaxChannels(0).should.be.rejected.and.notify(done);
ourBoard.once('sample', () => {
ourBoard.streamStop();
ourBoard.hardSetBoardType('default').should.be.rejected.and.notify(done);
});
ourBoard.streamStart()
.catch(done);
});
it('should not write a command if invalid channel number', function (done) {
ourBoard.hardSetBoardType(0).should.be.rejected.and.notify(done);
});
});
// bad
+59 -1
Ver Arquivo
@@ -32,6 +32,7 @@ describe('openBCISimulator', function () {
expect(simulator.options.alpha).to.be.true;
expect(simulator.options.boardFailure).to.be.false;
expect(simulator.options.daisy).to.be.false;
expect(simulator.options.daisyCanBeAttached).to.be.true;
expect(simulator.options.drift).to.equal(0);
expect(simulator.options.firmwareVersion).to.equal(k.OBCIFirmwareV1);
expect(simulator.options.lineNoise).to.equal(k.OBCISimulatorLineNoiseHz60);
@@ -272,12 +273,69 @@ describe('openBCISimulator', function () {
simulator.once('open', done);
});
afterEach(() => {
simulator.removeAllListeners('data');
simulator = null;
});
describe('set max channels', function () {
this.timeout(100);
it('should send nothing if no daisy attached', function (done) {
simulator.options.daisy = false;
simulator.on('data', function (data) {
expect(data.toString().match(k.OBCIParseEOT)).to.not.equal(null);
if (data.toString().match(k.OBCIParseEOT)) {
done();
}
});
simulator.write(k.OBCIChannelMaxNumber8);
});
it('should send daisy removed if daisy attached', function (done) {
simulator.options.daisy = true;
simulator.on('data', function (data) {
expect(data.toString().match(`daisy removed${k.OBCIParseEOT}`)).to.not.equal(null);
if (data.toString().match(k.OBCIParseEOT)) {
expect(simulator.options.daisy).to.equal(false);
done();
}
});
simulator.write(k.OBCIChannelMaxNumber8);
});
it('should send just 16 if daisy already attached', function (done) {
simulator.options.daisy = true;
simulator.on('data', function (data) {
expect(data.toString().match(`16${k.OBCIParseEOT}`)).to.not.equal(null);
if (data.toString().match(k.OBCIParseEOT)) {
done();
}
});
simulator.write(k.OBCIChannelMaxNumber16);
});
it('should send daisy attached if able to attach', function (done) {
simulator.options.daisy = false;
simulator.options.daisyCanBeAttached = true;
simulator.on('data', function (data) {
expect(data.toString().match(`daisy attached16`)).to.not.equal(null);
if (data.toString().match(k.OBCIParseEOT)) {
expect(simulator.options.daisy).to.equal(true);
done();
}
});
simulator.write(k.OBCIChannelMaxNumber16);
});
it('should send daisy attached if not able to attach', function (done) {
simulator.options.daisy = false;
simulator.options.daisyCanBeAttached = false;
simulator.on('data', function (data) {
expect(data.toString().match(`no daisy to attach!`)).to.not.equal(null);
if (data.toString().match(k.OBCIParseEOT)) {
done();
}
});
simulator.write(k.OBCIChannelMaxNumber16);
});
});
describe('reset', function () {
it('should be v2', function (done) {
simulator.on('data', function (data) {
console.log(data.toString());
expect(data.toString().match('v2')).to.not.equal(null);
done();
});