Comparar commits
112 Commits
| Autor | SHA1 | Data | |
|---|---|---|---|
| 6fd9ddf01b | |||
| fe2abac07b | |||
| 2528d56ac9 | |||
| 18b137b498 | |||
| 470ee81928 | |||
| 3c46100e1d | |||
| 2c0b2e37d2 | |||
| 094e328296 | |||
| 4c9bbb1f6d | |||
| b51cb54f92 | |||
| 19f05e362f | |||
| c33d08b486 | |||
| 97cff2dac9 | |||
| 6cf5e993ed | |||
| 6cbf99e635 | |||
| 9bd1121ab8 | |||
| 7d878f1a16 | |||
| ba4370793c | |||
| e88922c106 | |||
| a43c52fdec | |||
| 5cf97383b9 | |||
| d51c8f80d4 | |||
| 0a1f3de1a7 | |||
| e68f85d5b3 | |||
| 9c51fd673e | |||
| 2cf1a46994 | |||
| 77f7946790 | |||
| 9bd83aaf15 | |||
| 22f5ddbcef | |||
| 918451ebcb | |||
| a03250502c | |||
| 265e89284c | |||
| 0cd2e57f96 | |||
| 4a58dcb36a | |||
| 82a3fc3ced | |||
| 23e8364185 | |||
| e21160fa4d | |||
| 6d3813c4e1 | |||
| d8342879cf | |||
| 3322e9ca5c | |||
| 5f0085ddb3 | |||
| a005c8b711 | |||
| 49d0a5376f | |||
| de22e725d5 | |||
| 74cd163bd5 | |||
| 9fd53d2bec | |||
| da8e407e84 | |||
| d624b1d387 | |||
| f861563326 | |||
| 083df5a109 | |||
| aa5e42575a | |||
| cd482558bb | |||
| fa5890d5ad | |||
| 3df7d3170c | |||
| 46edd477a5 | |||
| c36e9d6126 | |||
| ccd2983cc9 | |||
| 08a575cc9c | |||
| 83223cb50a | |||
| dbd9987d5e | |||
| 2832fcb6b2 | |||
| 61a2971275 | |||
| cc177e200d | |||
| 12429398ca | |||
| de3604f3b8 | |||
| 6f6ffe7ad8 | |||
| f4cd6b3a65 | |||
| 443ee211ad | |||
| bfc0fe62a1 | |||
| 4d7d4eb5d8 | |||
| f948ec25f2 | |||
| 78b830e5c0 | |||
| 63a15cb950 | |||
| f5bf4db9a0 | |||
| 117c4411da | |||
| 927f6c1596 | |||
| 81af1098ed | |||
| a8fa5bab02 | |||
| 982688008a | |||
| cbbecc8b37 | |||
| 4080fe0d1b | |||
| 9e745331eb | |||
| b1c8b81aa1 | |||
| de6e1ab353 | |||
| cd108bd29a | |||
| 79b46ecb53 | |||
| f8a47560b8 | |||
| 03ed89b516 | |||
| bc436a7e1f | |||
| 2108ae2a75 | |||
| 70689548a1 | |||
| 701bc75a1f | |||
| cce4f930ef | |||
| 737f40e51e | |||
| f00988716a | |||
| 7e7eb8f549 | |||
| 8383070639 | |||
| b24d682e49 | |||
| b36a7b3409 | |||
| cfa8f4bdc8 | |||
| ee66c49ff0 | |||
| abfb37a38e | |||
| 48be1a01db | |||
| 8bbc011ead | |||
| cc839b3b32 | |||
| e2cd5d1dd7 | |||
| 682074dff7 | |||
| 0af11eabe5 | |||
| 31eea736dd | |||
| 8cafa3f7ff | |||
| 971787720e | |||
| c267cca924 |
+1
-1
@@ -33,10 +33,10 @@ public
|
||||
|
||||
# Test output files
|
||||
myOutput.txt
|
||||
hardwareVoltageOutputAll.txt
|
||||
|
||||
# Local npm builds for testing end in .tgz
|
||||
*.tgz
|
||||
|
||||
# For git
|
||||
*.orig
|
||||
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "4.0"
|
||||
- "4.1"
|
||||
- "4.2"
|
||||
- "5.11.0"
|
||||
- "6.0"
|
||||
- "6.1"
|
||||
- "6.2"
|
||||
- "6.3"
|
||||
install:
|
||||
- npm install --all
|
||||
script:
|
||||
|
||||
+557
-185
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
+155
-7
@@ -1,4 +1,153 @@
|
||||
# 0.3.3
|
||||
# 1.3.2
|
||||
|
||||
### Enhancements
|
||||
|
||||
* Added master time offset `timeOffsetMaster` to `syncObj` which is a running average across sync attempts.
|
||||
|
||||
# 1.3.1
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fixed bug where `connected` and `streaming` were not set in constructor
|
||||
|
||||
# 1.3.0
|
||||
|
||||
### New Features
|
||||
|
||||
* Add dropped packet detection, new event `droppedPacket` can be added to get an array of dropped packet numbers in the case of the dropped packet event.
|
||||
|
||||
# 1.2.3
|
||||
|
||||
### Enhancements
|
||||
|
||||
* Add table of contents to read me
|
||||
* Reduce size of repo by removing impedance test report
|
||||
|
||||
# 1.2.2
|
||||
|
||||
### Enhancements
|
||||
|
||||
* Upgrade serialport to 4.x
|
||||
|
||||
# 1.2.1
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fixed bug where set channel function allowed for channel 0 to be set. Cannot set system to channel 0; lower limit is 1.
|
||||
|
||||
# 1.2.0
|
||||
|
||||
### New Features
|
||||
|
||||
* Add tutorial/sample code for interfacing the module with lab streaming layer.
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
* Fixed time synced accel to work OpenBCI_32bit_Library release candidate 5 and newer.
|
||||
|
||||
# 1.1.0
|
||||
|
||||
### New Features
|
||||
|
||||
* Add function `.time()` which should be used in time syncing
|
||||
* Add function `.syncClocksFull()` which should be used for immediate consecutive time syncs
|
||||
* Synced object can be emitted on `synced` event. Check `valid` property for if the sync was done
|
||||
* Add detailed description of object returned on `synced` event to README.md
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
* Changed option named `timeSync` to `sntpTimeSync`
|
||||
* Removed function called `.sntpNow()` because it was replaced by `.time()`
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Time sync working
|
||||
* Module could not work with local time
|
||||
|
||||
# 1.0.1
|
||||
|
||||
### New Features
|
||||
|
||||
* Add time sync tutorial in `README.md`
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fixed bug in simulator that lead to samples being all zeros.
|
||||
* Fixed time sync sent confirmation bug that led to bad time values.
|
||||
|
||||
# 1.0.0
|
||||
|
||||
The second major release for the OpenBCI Node.js SDK brings major changes, improvements and stability, on top of a push to increase automated test coverage.
|
||||
|
||||
### New Features
|
||||
|
||||
* NPM Module now called `openbci` instead of `openbci-sdk`
|
||||
* Firmware version 2.0 support.
|
||||
* Clock synchronization between OpenBCI board and this driver
|
||||
* `.info` property which contains verified board information parsed from the OpenBCI's `softReset()` response.
|
||||
* `eot` event that is emitted when a user sends a command that results in an EOT ("$$$") being sent from the board
|
||||
* Daisy (16 channel) support
|
||||
* Simulator overhaul, it completely mocks the board. Can now simulate board failure, where the board stops talking to the dongle. Can also mock a serial port failure.
|
||||
* `error` and `close` events from serialport now emtted events users can subscribe to.
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
* NPM package is not called `openbci-sdk` anymore, now called `openbci`
|
||||
* Accelerometer data now goes into `.accelData` array instead of `.auxData` array.
|
||||
* In openBCISample.js
|
||||
* `parseRawPacket()` is now called `parseRawPacketStandard()`
|
||||
* `ready` event only triggered after soft reset. `eot` event emitted in all other conditions resulting in the board sending EOT ("$$$")
|
||||
* Must use camel case on the OpenBCISimulator object.
|
||||
* Renamed constructor options for readability:
|
||||
* `simulatorAlpha` to `simulatorInjectAlpha`
|
||||
* `simulatorLineNoise` to `simulatorInjectLineNoise`
|
||||
* `connect()` no longer rejects on `close` or `error` event from the serialport.
|
||||
|
||||
# 0.3.9
|
||||
|
||||
### Enhancements
|
||||
|
||||
* Add tests for parsing raw packets
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Removed `got here` log from `.streamStart()`
|
||||
* Validate stop byte before emitting `rawDataPacket`
|
||||
|
||||
# 0.3.8
|
||||
|
||||
### Bug Fixes
|
||||
* Fixed readme.md
|
||||
|
||||
# 0.3.7
|
||||
|
||||
### New Features
|
||||
|
||||
* Upgrade dependencies
|
||||
* Update Travis
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* `.numberOfChannels()` now uses the info object, which is set in the constructor and on the return message from `.softReset()`
|
||||
* `.sampleRate()` now uses the info object, which is set in the constructor and on the return message from `.softReset()`
|
||||
|
||||
# 0.3.6
|
||||
|
||||
### New Features
|
||||
|
||||
* Simulator now has accelerometer data
|
||||
|
||||
# 0.3.5
|
||||
|
||||
### New Features
|
||||
|
||||
* SD card support! Now logging to an SD card is easier than ever.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Sample rate does not return correct sample rate for custom rate on simulator. #58
|
||||
|
||||
# 0.3.4
|
||||
|
||||
### New Features
|
||||
|
||||
@@ -8,7 +157,6 @@
|
||||
|
||||
* [https://github.com/OpenBCI/openbci-js-sdk/issues/44](#44)
|
||||
|
||||
|
||||
# 0.3.3
|
||||
|
||||
### Bug Fixes
|
||||
@@ -43,7 +191,7 @@
|
||||
* OpenBCI Radio Test File
|
||||
* Added Sntp npm module with helper functions
|
||||
* Removed stopByte and startByte from sampleObjects
|
||||
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
* Changed simulator name to `OpenBCISimulator`
|
||||
@@ -54,15 +202,15 @@
|
||||
|
||||
* NTP Time Synchronization
|
||||
* Goertzel algorithm to get voltage for impedance calculation
|
||||
|
||||
|
||||
### Bug fixes
|
||||
|
||||
* Impedance calculations
|
||||
* Readme updates
|
||||
* Serial buffer had the chance to become permanently unaligned, optimized and completely transformed and refactored the way bytes are processed.
|
||||
* Changes to gain of channels not working correctly.
|
||||
* Node 5 compatibility
|
||||
|
||||
* Node 5 compatibility
|
||||
|
||||
### Github Issues Addressed
|
||||
|
||||
* #25, #26, #27, #29, #30, #31, #33, #34
|
||||
* #25, #26, #27, #29, #30, #31, #33, #34
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "timesync",
|
||||
"version": "1.0.0",
|
||||
"description": "Time sync example",
|
||||
"main": "timeSync.js",
|
||||
"scripts": {
|
||||
"start": "node timeSync.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [
|
||||
"time",
|
||||
"sync"
|
||||
],
|
||||
"author": "AJ Keller",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"openbci": "^1.3.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* This is an example of time syncing every second for one minute. Used with a
|
||||
* real board.
|
||||
* To run:
|
||||
* change directory to this file `cd examples/timeSync`
|
||||
* do `npm install`
|
||||
* then `npm start`
|
||||
*/
|
||||
|
||||
var OpenBCIBoard = require('openbci').OpenBCIBoard;
|
||||
|
||||
var ourBoard = new OpenBCIBoard({});
|
||||
|
||||
const resyncPeriodMin = 5; // re sync every five minutes
|
||||
const secondsInMinute = 60;
|
||||
var sampleRate = 250; // Default to 250, ALWAYS verify with a call to `.sampleRate()` after 'ready' event!
|
||||
var timeSyncPossible = false;
|
||||
|
||||
ourBoard.autoFindOpenBCIBoard().then(portName => {
|
||||
if(portName) {
|
||||
/**
|
||||
* Connect to the board with portName
|
||||
* i.e. ourBoard.connect(portName).....
|
||||
*/
|
||||
// Call to connect
|
||||
ourBoard.connect(portName).then(() => {
|
||||
console.log(`connected`);
|
||||
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(`connect: ${err}`);
|
||||
});
|
||||
} else {
|
||||
/**Unable to auto find OpenBCI board*/
|
||||
}
|
||||
});
|
||||
|
||||
var readyFunc = () => {
|
||||
// Get the sample rate after 'ready'
|
||||
sampleRate = ourBoard.sampleRate();
|
||||
// Find out if you can even time sync, you must be using v2 and this is only accurate after a `.softReset()` call which is called internally on `.connect()`. We parse the `.softReset()` response for the presence of firmware version 2 properties.
|
||||
timeSyncPossible = ourBoard.usingVersionTwoFirmware();
|
||||
|
||||
if (timeSyncPossible) {
|
||||
ourBoard.streamStart()
|
||||
.catch(err => {
|
||||
console.log(`stream start: ${err}`);
|
||||
});
|
||||
} else {
|
||||
killFunc();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var killFunc = () => {
|
||||
ourBoard.disconnect()
|
||||
.then(() => {
|
||||
process.kill();
|
||||
});
|
||||
}
|
||||
|
||||
var sampleFunc = sample => {
|
||||
// Resynchronize every every second
|
||||
if (sample._count % (sampleRate * 1) === 0) {
|
||||
ourBoard.syncClocksFull()
|
||||
.then(syncObj => {
|
||||
// Sync was successful
|
||||
if (syncObj.valid) {
|
||||
// Log the object to check it out!
|
||||
console.log(`timeOffset`,syncObj.timeOffsetMaster);
|
||||
} else {
|
||||
// Retry it
|
||||
console.log(`Was not able to sync... retry!`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (sample.timeStamp) { // true after the first successful sync
|
||||
if (sample.timeStamp < 10 * 60 * 60 * 1000) { // Less than 10 hours
|
||||
console.log(`Bad time sync ${sample.timeStamp}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Stop after one minute
|
||||
if (sample._count > sampleRate * 60) {
|
||||
killFunc();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Subscribe to your functions
|
||||
ourBoard.on('ready',readyFunc);
|
||||
ourBoard.on('sample',sampleFunc);
|
||||
Arquivo binário não exibido.
+1141
-239
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
+668
-459
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
+886
-135
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
+243
-66
@@ -12,18 +12,19 @@ var now = require('performance-now');
|
||||
function OpenBCISimulatorFactory() {
|
||||
var factory = this;
|
||||
|
||||
|
||||
|
||||
var _options = {
|
||||
samplerate: 250,
|
||||
daisy: false,
|
||||
verbose: false,
|
||||
accel: true,
|
||||
alpha: true,
|
||||
lineNoise: '60Hz'
|
||||
boardFailure:false,
|
||||
daisy: false,
|
||||
drift: 0,
|
||||
firmwareVersion: k.OBCIFirmwareV1,
|
||||
lineNoise: '60Hz',
|
||||
sampleRate: 250,
|
||||
serialPortFailure:false,
|
||||
verbose: false
|
||||
};
|
||||
|
||||
|
||||
|
||||
function OpenBCISimulator(portName, options) {
|
||||
options = (typeof options !== 'function') && options || {};
|
||||
var opts = {};
|
||||
@@ -31,45 +32,62 @@ function OpenBCISimulatorFactory() {
|
||||
stream.Stream.call(this);
|
||||
|
||||
/** Configuring Options */
|
||||
opts.sampleRate = options.sampleRate || options.samplerate || _options.samplerate;
|
||||
if (options.accel === false) {
|
||||
opts.accel = false;
|
||||
} else {
|
||||
opts.accel = _options.accel;
|
||||
}
|
||||
if (options.alpha === false) {
|
||||
opts.alpha = false;
|
||||
} else {
|
||||
opts.alpha = _options.alpha;
|
||||
}
|
||||
opts.boardFailure = options.boardFailure || _options.boardFailure;
|
||||
opts.daisy = options.daisy || _options.daisy;
|
||||
opts.lineNoise = options.lineNoise || options.linenoise || _options.lineNoise;
|
||||
opts.alpha = options.alpha || _options.alpha;
|
||||
opts.drift = options.drift || _options.drift;
|
||||
opts.firmwareVersion = options.firmwareVersion || _options.firmwareVersion;
|
||||
opts.lineNoise = options.lineNoise || _options.lineNoise;
|
||||
if (options.sampleRate) {
|
||||
opts.sampleRate = options.sampleRate;
|
||||
} else {
|
||||
opts.sampleRate = k.OBCISampleRate250;
|
||||
}
|
||||
opts.serialPortFailure = options.serialPortFailure || _options.serialPortFailure;
|
||||
opts.verbose = options.verbose || _options.verbose;
|
||||
|
||||
this.options = opts;
|
||||
|
||||
// Bools
|
||||
this.connected = false;
|
||||
this.sd = {
|
||||
active:false,
|
||||
startTime: 0
|
||||
};
|
||||
this.streaming = false;
|
||||
this.synced = false;
|
||||
this.sendSyncSetPacket = false;
|
||||
// Buffers
|
||||
this.buffer = new Buffer(500);
|
||||
// Numbers
|
||||
this.channelNumber = 1;
|
||||
this.hostChannelNumber = this.channelNumber;
|
||||
this.pollTime = 80;
|
||||
this.sampleNumber = -1; // So the first sample is 0
|
||||
// Objects
|
||||
this.sampleGenerator = openBCISample.randomSample(k.OBCINumberOfChannelsDefault, this.options.sampleRate, this.options.alpha, this.options.lineNoise);
|
||||
this.time = {
|
||||
current: 0,
|
||||
start: now(),
|
||||
loop: null,
|
||||
ntp0: 0,
|
||||
ntp1: 0,
|
||||
ntp2: 0,
|
||||
ntp3: 0
|
||||
loop: null
|
||||
};
|
||||
console.log('Simulator started at time: ' + this.time.start);
|
||||
console.log('Time board has been running: ' + (now() - this.time.start));
|
||||
// Strings
|
||||
this.portName = portName || k.OBCISimulatorPortName;
|
||||
|
||||
// Call 'open'
|
||||
if (this.options.verbose) console.log(`Port name: ${portName}`);
|
||||
setTimeout(() => {
|
||||
console.log('Port name: ' + portName);
|
||||
if (portName === k.OBCISimulatorPortName) {
|
||||
this.emit('open');
|
||||
this.connected = true;
|
||||
} else {
|
||||
var err = new Error('Serialport not open.');
|
||||
this.emit('error',err);
|
||||
}
|
||||
this.emit('open');
|
||||
this.connected = true;
|
||||
}, 200);
|
||||
|
||||
}
|
||||
@@ -83,27 +101,62 @@ function OpenBCISimulatorFactory() {
|
||||
};
|
||||
|
||||
OpenBCISimulator.prototype.write = function(data,callback) {
|
||||
|
||||
switch (data[0]) {
|
||||
case k.OBCIRadioKey:
|
||||
this._processPrivateRadioMessage(data);
|
||||
break;
|
||||
case k.OBCIStreamStart:
|
||||
if (!this.stream) this._startStream();
|
||||
this.streaming = true;
|
||||
break;
|
||||
case k.OBCIStreamStop:
|
||||
if (this.stream) clearInterval(this.stream); // Stops the stream
|
||||
this.streaming = false;
|
||||
break;
|
||||
case k.OBCIMiscSoftReset:
|
||||
if (this.stream) clearInterval(this.stream);
|
||||
this.emit('data', new Buffer('OpenBCI Board Simulator\nPush The World V-0.2\n$$$'));
|
||||
this.streaming = false;
|
||||
this.emit('data', new Buffer(`OpenBCI V3 Simulator\nOn Board ADS1299 Device ID: 0x12345\n${this.options.daisy ? "On Daisy ADS1299 Device ID: 0xFFFFF\n" : ""}LIS3DH Device ID: 0x38422\n${this.options.firmware === k.OBCIFirmwareV2 ? "Firmware: v2.0.0\n" : ""}$$$`));
|
||||
break;
|
||||
case k.OBCISyncClockStart:
|
||||
setTimeout(() => {
|
||||
if (this.options.verbose) console.log('Recieved sync command');
|
||||
this._syncStart();
|
||||
}, 10);
|
||||
case k.OBCISDLogForHour1:
|
||||
case k.OBCISDLogForHour2:
|
||||
case k.OBCISDLogForHour4:
|
||||
case k.OBCISDLogForHour12:
|
||||
case k.OBCISDLogForHour24:
|
||||
case k.OBCISDLogForMin5:
|
||||
case k.OBCISDLogForMin15:
|
||||
case k.OBCISDLogForMin30:
|
||||
case k.OBCISDLogForSec14:
|
||||
// If we are not streaming, then do verbose output
|
||||
if (!this.streaming) {
|
||||
this.emit('data', new Buffer('Wiring is correct and a card is present.\nCorresponding SD file OBCI_69.TXT\n$$$'));
|
||||
}
|
||||
this.sd.active = true;
|
||||
this.sd.startTime = now();
|
||||
break;
|
||||
case k.OBCISyncClockServerData:
|
||||
this.time.ntp3 = this.time.current;
|
||||
this._syncUp(data.slice(1));
|
||||
case k.OBCISDLogStop:
|
||||
if (!this.streaming) {
|
||||
if (this.SDLogActive) {
|
||||
this.emit('data', new Buffer(`Total Elapsed Time: ${now() - this.sd.startTime} ms\n`));
|
||||
this.emit('data', new Buffer(`Max write time: ${Math.random()*500} us\n`));
|
||||
this.emit('data', new Buffer(`Min write time: ${Math.random()*200} us\n`));
|
||||
this.emit('data', new Buffer(`Overruns: 0\n`));
|
||||
this._printEOT();
|
||||
} else {
|
||||
this.emit('data', new Buffer('No open file to close\n'));
|
||||
this._printEOT();
|
||||
}
|
||||
}
|
||||
this.SDLogActive = false;
|
||||
break;
|
||||
case k.OBCISyncTimeSet:
|
||||
if (this.options.firmwareVersion === k.OBCIFirmwareV2) {
|
||||
this.synced = true;
|
||||
setTimeout(() => {
|
||||
this.emit('data', new Buffer(k.OBCISyncTimeSent));
|
||||
this._syncUp();
|
||||
}, 10);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -117,7 +170,6 @@ function OpenBCISimulatorFactory() {
|
||||
|
||||
OpenBCISimulator.prototype.drain = function(callback) {
|
||||
callback();
|
||||
//if (this.options.verbose) console.log('drain');
|
||||
};
|
||||
|
||||
OpenBCISimulator.prototype.close = function(callback) {
|
||||
@@ -125,7 +177,6 @@ function OpenBCISimulatorFactory() {
|
||||
this.emit('close');
|
||||
}
|
||||
this.connected = false;
|
||||
//if (this.options.verbose) console.log('close');
|
||||
callback();
|
||||
};
|
||||
|
||||
@@ -134,10 +185,31 @@ function OpenBCISimulatorFactory() {
|
||||
|
||||
if (intervalInMS < 2) intervalInMS = 2;
|
||||
|
||||
var generateSample = openBCISample.randomSample(k.OBCINumberOfChannelsDefault, k.OBCISampleRate250, this.options.alpha, this.options.lineNoise);
|
||||
|
||||
var getNewPacket = sampNumber => {
|
||||
return openBCISample.convertSampleToPacket(generateSample(sampNumber));
|
||||
if (this.options.accel) {
|
||||
if (this.synced) {
|
||||
if (this.sendSyncSetPacket) {
|
||||
this.sendSyncSetPacket = false;
|
||||
return openBCISample.convertSampleToPacketAccelTimeSyncSet(this.sampleGenerator(sampNumber),now().toFixed(0));
|
||||
} else {
|
||||
return openBCISample.convertSampleToPacketAccelTimeSynced(this.sampleGenerator(sampNumber),now().toFixed(0));
|
||||
}
|
||||
} else {
|
||||
return openBCISample.convertSampleToPacketStandard(this.sampleGenerator(sampNumber));
|
||||
}
|
||||
} else {
|
||||
if (this.synced) {
|
||||
if (this.sendSyncSetPacket) {
|
||||
this.sendSyncSetPacket = false;
|
||||
return openBCISample.convertSampleToPacketRawAuxTimeSyncSet(this.sampleGenerator(sampNumber),now().toFixed(0),new Buffer([0,0,0,0,0,0]));
|
||||
} else {
|
||||
return openBCISample.convertSampleToPacketRawAuxTimeSynced(this.sampleGenerator(sampNumber),now().toFixed(0),new Buffer([0,0,0,0,0,0]));
|
||||
}
|
||||
} else {
|
||||
return openBCISample.convertSampleToPacketRawAux(this.sampleGenerator(sampNumber),new Buffer([0,0,0,0,0,0]));
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
this.stream = setInterval(() => {
|
||||
@@ -146,40 +218,145 @@ function OpenBCISimulatorFactory() {
|
||||
}, intervalInMS);
|
||||
};
|
||||
|
||||
OpenBCISimulator.prototype._syncStart = function() {
|
||||
|
||||
this.time.ntp0 = now();
|
||||
var buffer = new Buffer('$a$' + this.time.ntp0);
|
||||
this.emit('data',buffer);
|
||||
OpenBCISimulator.prototype._syncUp = function() {
|
||||
setTimeout(() => {
|
||||
this.sendSyncSetPacket = true;
|
||||
}, 12); // 3 packets later
|
||||
};
|
||||
|
||||
OpenBCISimulator.prototype._syncUp = function(data) {
|
||||
// get the first number
|
||||
console.log(data.length);
|
||||
var halfwayPoint = (data.length / 2);
|
||||
this.time.ntp1 = parseFloat(data.slice(0,halfwayPoint-1));
|
||||
this.time.ntp2 = parseFloat(data.slice(halfwayPoint));
|
||||
console.log('ntp1: ' + this.time.ntp1 + ' ntp2: ' + this.time.ntp2);
|
||||
OpenBCISimulator.prototype._printEOT = function () {
|
||||
this.emit('data', new Buffer("$$$"));
|
||||
};
|
||||
|
||||
var timeSpentOnNetwork = this.time.ntp3 - this.time.ntp0 - (this.time.ntp2 - this.time.ntp1);
|
||||
OpenBCISimulator.prototype._printFailure = function () {
|
||||
this.emit('data', new Buffer("Failure: "));
|
||||
};
|
||||
|
||||
var transferTime = timeSpentOnNetwork / 2;
|
||||
OpenBCISimulator.prototype._printSuccess = function () {
|
||||
this.emit('data', new Buffer("Success: "));
|
||||
};
|
||||
|
||||
var trueTime = this.time.ntp2 + transferTime;
|
||||
|
||||
var delta = trueTime - this.time.ntp3;
|
||||
console.log('Delta: ' + delta);
|
||||
|
||||
this.time.start += delta;
|
||||
|
||||
|
||||
|
||||
this.emit('data','Synced!' + '$$$');
|
||||
OpenBCISimulator.prototype._printValidatedCommsTimeout = function () {
|
||||
this._printFailure();
|
||||
this.emit('data', new Buffer("Communications timeout - Device failed to poll Host"));
|
||||
this._printEOT();
|
||||
};
|
||||
|
||||
OpenBCISimulator.prototype._processPrivateRadioMessage = function(dataBuffer) {
|
||||
switch (dataBuffer[1]) {
|
||||
case k.OBCIRadioCmdChannelGet:
|
||||
if (this.options.firmwareVersion === k.OBCIFirmwareV2) {
|
||||
if (!this.options.boardFailure) {
|
||||
this._printSuccess();
|
||||
this.emit('data', new Buffer(`Host and Device on Channel Number ${this.channelNumber}`));
|
||||
this.emit('data', new Buffer([this.channelNumber]));
|
||||
this._printEOT();
|
||||
} else if (!this.serialPortFailure) {
|
||||
this._printFailure();
|
||||
this.emit('data', new Buffer(`Host on Channel Number ${this.channelNumber}`));
|
||||
this.emit('data', new Buffer([this.channelNumber]));
|
||||
this._printEOT();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case k.OBCIRadioCmdChannelSet:
|
||||
if (this.options.firmwareVersion === k.OBCIFirmwareV2) {
|
||||
if (!this.options.boardFailure) {
|
||||
if (dataBuffer[2] < k.OBCIRadioChannelMax) {
|
||||
this.channelNumber = dataBuffer[2];
|
||||
this.hostChannelNumber = this.channelNumber;
|
||||
this._printSuccess();
|
||||
this.emit('data', new Buffer(`Channel Number ${this.channelNumber}`));
|
||||
this.emit('data', new Buffer([this.channelNumber]));
|
||||
this._printEOT();
|
||||
} else {
|
||||
this._printFailure();
|
||||
this.emit('data', new Buffer("Verify channel number is less than 25"));
|
||||
this._printEOT();
|
||||
}
|
||||
} else if (!this.serialPortFailure) {
|
||||
this._printValidatedCommsTimeout();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case k.OBCIRadioCmdChannelSetOverride:
|
||||
if (this.options.firmwareVersion === k.OBCIFirmwareV2) {
|
||||
if (dataBuffer[2] < k.OBCIRadioChannelMax) {
|
||||
if (dataBuffer[2] === this.channelNumber) {
|
||||
this.options.boardFailure = false;
|
||||
} else {
|
||||
this.options.boardFailure = true;
|
||||
}
|
||||
this.hostChannelNumber = dataBuffer[2];
|
||||
this._printSuccess();
|
||||
this.emit('data', new Buffer(`Host override - Channel Number ${this.hostChannelNumber}`));
|
||||
this.emit('data', new Buffer([this.hostChannelNumber]));
|
||||
this._printEOT();
|
||||
} else {
|
||||
this._printFailure();
|
||||
this.emit('data', new Buffer("Verify channel number is less than 25"));
|
||||
this._printEOT();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case k.OBCIRadioCmdPollTimeGet:
|
||||
if (this.options.firmwareVersion === k.OBCIFirmwareV2) {
|
||||
if (!this.options.boardFailure) {
|
||||
this._printSuccess();
|
||||
this.emit('data', new Buffer(`Poll Time ${this.pollTime}`));
|
||||
this.emit('data', new Buffer([this.pollTime]));
|
||||
this._printEOT();
|
||||
} else {
|
||||
this._printValidatedCommsTimeout();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case k.OBCIRadioCmdPollTimeSet:
|
||||
if (this.options.firmwareVersion === k.OBCIFirmwareV2) {
|
||||
if (!this.options.boardFailure) {
|
||||
this.pollTime = dataBuffer[2];
|
||||
this._printSuccess();
|
||||
this.emit('data', new Buffer(`Poll Time ${this.pollTime}`));
|
||||
this.emit('data', new Buffer([this.pollTime]));
|
||||
this._printEOT();
|
||||
} else {
|
||||
this._printValidatedCommsTimeout();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case k.OBCIRadioCmdBaudRateSetDefault:
|
||||
if (this.options.firmwareVersion === k.OBCIFirmwareV2) {
|
||||
this._printSuccess();
|
||||
this.emit('data', new Buffer("Switch your baud rate to 115200"));
|
||||
this.emit('data', new Buffer([0x24,0x24,0x24,0xFF])); // The board really does this
|
||||
}
|
||||
break;
|
||||
case k.OBCIRadioCmdBaudRateSetFast:
|
||||
if (this.options.firmwareVersion === k.OBCIFirmwareV2) {
|
||||
this._printSuccess();
|
||||
this.emit('data', new Buffer("Switch your baud rate to 230400"));
|
||||
this.emit('data', new Buffer([0x24,0x24,0x24,0xFF])); // The board really does this
|
||||
}
|
||||
break;
|
||||
case k.OBCIRadioCmdSystemStatus:
|
||||
if (this.options.firmwareVersion === k.OBCIFirmwareV2) {
|
||||
if (!this.options.boardFailure) {
|
||||
this._printSuccess();
|
||||
this.emit('data', new Buffer("System is Up"));
|
||||
this._printEOT();
|
||||
} else {
|
||||
this._printFailure();
|
||||
this.emit('data', new Buffer("System is Down"));
|
||||
this._printEOT();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
factory.OpenBCISimulator = OpenBCISimulator;
|
||||
|
||||
}
|
||||
|
||||
util.inherits(OpenBCISimulatorFactory, EventEmitter);
|
||||
|
||||
+13
-10
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "openbci-sdk",
|
||||
"version": "0.3.4",
|
||||
"description": "A fully NodeJS based API for the OpenBCI board connecting to the hardware directly over serial",
|
||||
"name": "openbci",
|
||||
"version": "1.3.2",
|
||||
"description": "The official Node.js SDK for the OpenBCI Biosensor Board.",
|
||||
"main": "openBCIBoard",
|
||||
"scripts": {
|
||||
"start": "node index",
|
||||
@@ -15,11 +15,13 @@
|
||||
"author": "AJ Keller <aj@pushtheworld.us> (www.openbci.com)",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"buffer-equal": "^1.0.0",
|
||||
"gaussian": "^1.0.0",
|
||||
"istanbul": "^0.4.2",
|
||||
"mathjs": "^3.3.0",
|
||||
"performance-now": "^0.2.0",
|
||||
"serialport": "~2.1.0",
|
||||
"sntp": "^2.0.0"
|
||||
"serialport": "4.0.1",
|
||||
"sntp": "^2.0.0",
|
||||
"streamsearch": "^0.1.2"
|
||||
},
|
||||
"directories": {
|
||||
"test": "test"
|
||||
@@ -28,19 +30,20 @@
|
||||
"chai": "^3.4.1",
|
||||
"chai-as-promised": "^5.2.0",
|
||||
"codecov": "^1.0.1",
|
||||
"mocha": "^2.3.4",
|
||||
"istanbul": "^0.4.4",
|
||||
"mocha": "^3.0.2",
|
||||
"sandboxed-module": "^2.0.3",
|
||||
"sinon": "^1.17.2",
|
||||
"sinon-chai": "^2.8.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/openbci/openbci-js-sdk.git"
|
||||
"url": "git+https://github.com/openbci/openbci_nodejs.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/openbci/openbci-js-sdk/issues"
|
||||
"url": "https://github.com/openbci/openbci_nodejs/issues"
|
||||
},
|
||||
"homepage": "https://github.com/openbci/openbci-js-sdk#readme",
|
||||
"homepage": "https://github.com/openbci/openbci_nodejs#readme",
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
}
|
||||
|
||||
+191
-31
@@ -291,6 +291,20 @@ describe('OpenBCIConstants', function() {
|
||||
assert.equal('1', k.OBCIChannelImpedanceTestSignalApplied);
|
||||
});
|
||||
});
|
||||
describe('Time Sync Stuff',function() {
|
||||
it('Can get proper array size',function() {
|
||||
assert.equal(10, k.OBCITimeSyncArraySize);
|
||||
});
|
||||
it('Get correct time sync with conf',function() {
|
||||
assert.equal(0.9, k.OBCITimeSyncMultiplierWithSyncConf);
|
||||
});
|
||||
it('Get correct time sync without conf',function() {
|
||||
assert.equal(0.75, k.OBCITimeSyncMultiplierWithoutSyncConf);
|
||||
});
|
||||
it('Get correct time sync transmission threshold',function() {
|
||||
assert.equal(10, k.OBCITimeSyncThresholdTransFailureMS);
|
||||
});
|
||||
});
|
||||
describe('SD card Commands',function() {
|
||||
it('logs for 1 hour', function() {
|
||||
assert.equal('G', k.OBCISDLogForHour1);
|
||||
@@ -323,6 +337,86 @@ describe('OpenBCIConstants', function() {
|
||||
assert.equal('j', k.OBCISDLogStop);
|
||||
});
|
||||
});
|
||||
describe('SD card string Commands',function() {
|
||||
it('logs for 1 hour', function() {
|
||||
assert.equal('1hour', k.OBCIStringSDHour1);
|
||||
});
|
||||
it('logs for 2 hours', function() {
|
||||
assert.equal('2hour', k.OBCIStringSDHour2);
|
||||
});
|
||||
it('logs for 4 hours', function() {
|
||||
assert.equal('4hour', k.OBCIStringSDHour4);
|
||||
});
|
||||
it('logs for 12 hours', function() {
|
||||
assert.equal('12hour', k.OBCIStringSDHour12);
|
||||
});
|
||||
it('logs for 24 hours', function() {
|
||||
assert.equal('24hour', k.OBCIStringSDHour24);
|
||||
});
|
||||
it('logs for 5 minutes', function() {
|
||||
assert.equal('5min', k.OBCIStringSDMin5);
|
||||
});
|
||||
it('logs for 15 minutes', function() {
|
||||
assert.equal('15min', k.OBCIStringSDMin15);
|
||||
});
|
||||
it('logs for 30 minutes', function() {
|
||||
assert.equal('30min', k.OBCIStringSDMin30);
|
||||
});
|
||||
it('logs for 14 seconds', function() {
|
||||
assert.equal('14sec', k.OBCIStringSDSec14);
|
||||
});
|
||||
});
|
||||
describe('#sdSettingForString',function() {
|
||||
it('correct command for 1 hour', function() {
|
||||
var expectation = k.OBCISDLogForHour1;
|
||||
var result = k.sdSettingForString('1hour');
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('correct command for 2 hour', function() {
|
||||
var expectation = k.OBCISDLogForHour2;
|
||||
var result = k.sdSettingForString('2hour');
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('correct command for 4 hour', function() {
|
||||
var expectation = k.OBCISDLogForHour4;
|
||||
var result = k.sdSettingForString('4hour');
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('correct command for 12 hour', function() {
|
||||
var expectation = k.OBCISDLogForHour12;
|
||||
var result = k.sdSettingForString('12hour');
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('correct command for 24 hour', function() {
|
||||
var expectation = k.OBCISDLogForHour24;
|
||||
var result = k.sdSettingForString('24hour');
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('correct command for 5 min', function() {
|
||||
var expectation = k.OBCISDLogForMin5;
|
||||
var result = k.sdSettingForString('5min');
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('correct command for 15 min', function() {
|
||||
var expectation = k.OBCISDLogForMin15;
|
||||
var result = k.sdSettingForString('15min');
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('correct command for 30 min', function() {
|
||||
var expectation = k.OBCISDLogForMin30;
|
||||
var result = k.sdSettingForString('30min');
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('correct command for 14 seconds', function() {
|
||||
var expectation = k.OBCISDLogForSec14;
|
||||
var result = k.sdSettingForString('14sec');
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Invalid command request', function() {
|
||||
var result = k.sdSettingForString('taco');
|
||||
return expect(result).to.be.rejected;
|
||||
});
|
||||
});
|
||||
describe('Stream Data Commands',function() {
|
||||
it('starts',function () {
|
||||
assert.equal('b', k.OBCIStreamStart);
|
||||
@@ -355,6 +449,45 @@ describe('OpenBCIConstants', function() {
|
||||
assert.equal('f', k.OBCIFilterEnable);
|
||||
});
|
||||
});
|
||||
describe('Stream packet types/codes',function() {
|
||||
it('Standard with Accel',function () {
|
||||
assert.equal(0, k.OBCIStreamPacketStandardAccel);
|
||||
});
|
||||
it('Standard with Raw Aux',function () {
|
||||
assert.equal(1, k.OBCIStreamPacketStandardRawAux);
|
||||
});
|
||||
it('User Defined Packet',function () {
|
||||
assert.equal(2, k.OBCIStreamPacketUserDefinedType);
|
||||
});
|
||||
it('Time Sync Set with accel',function () {
|
||||
assert.equal(3, k.OBCIStreamPacketAccelTimeSyncSet);
|
||||
});
|
||||
it('Time Synced with Accel',function () {
|
||||
assert.equal(4, k.OBCIStreamPacketAccelTimeSynced);
|
||||
});
|
||||
it('Time Sync set with Raw Aux',function () {
|
||||
assert.equal(5, k.OBCIStreamPacketRawAuxTimeSyncSet);
|
||||
});
|
||||
it('Time Synced with Raw Aux',function () {
|
||||
assert.equal(6, k.OBCIStreamPacketRawAuxTimeSynced);
|
||||
});
|
||||
});
|
||||
describe('Time synced with accel packet',function() {
|
||||
it('X axis',function () {
|
||||
assert.equal(7, k.OBCIAccelAxisX);
|
||||
});
|
||||
it('Y axis',function () {
|
||||
assert.equal(8, k.OBCIAccelAxisY);
|
||||
});
|
||||
it('Z axis',function () {
|
||||
assert.equal(9, k.OBCIAccelAxisZ);
|
||||
});
|
||||
});
|
||||
describe('Time sync useful numbers',function() {
|
||||
it('Time from the board is 4 bytes',function () {
|
||||
assert.equal(4, k.OBCIStreamPacketTimeByteSize);
|
||||
});
|
||||
});
|
||||
describe('should return the right command for each channel', function(){
|
||||
it('Channel 1', function() {
|
||||
var expectation = '1';
|
||||
@@ -534,78 +667,78 @@ describe('OpenBCIConstants', function() {
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Channel 2', function() {
|
||||
var expectation = '!';
|
||||
var result = k.commandChannelOn(1);
|
||||
var expectation = '@';
|
||||
var result = k.commandChannelOn(2);
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Channel 3', function() {
|
||||
var expectation = '!';
|
||||
var result = k.commandChannelOn(1);
|
||||
var expectation = '#';
|
||||
var result = k.commandChannelOn(3);
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Channel 4', function() {
|
||||
var expectation = '!';
|
||||
var result = k.commandChannelOn(1);
|
||||
var expectation = '$';
|
||||
var result = k.commandChannelOn(4);
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Channel 5', function() {
|
||||
var expectation = '!';
|
||||
var result = k.commandChannelOn(1);
|
||||
var expectation = '%';
|
||||
var result = k.commandChannelOn(5);
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Channel 6', function() {
|
||||
var expectation = '!';
|
||||
var result = k.commandChannelOn(1);
|
||||
var expectation = '^';
|
||||
var result = k.commandChannelOn(6);
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Channel 7', function() {
|
||||
var expectation = '!';
|
||||
var result = k.commandChannelOn(1);
|
||||
var expectation = '&';
|
||||
var result = k.commandChannelOn(7);
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Channel 8', function() {
|
||||
var expectation = '!';
|
||||
var result = k.commandChannelOn(1);
|
||||
var expectation = '*';
|
||||
var result = k.commandChannelOn(8);
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Channel 9', function() {
|
||||
var expectation = '!';
|
||||
var result = k.commandChannelOn(1);
|
||||
var expectation = 'Q';
|
||||
var result = k.commandChannelOn(9);
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Channel 10', function() {
|
||||
var expectation = '!';
|
||||
var result = k.commandChannelOn(1);
|
||||
var expectation = 'W';
|
||||
var result = k.commandChannelOn(10);
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Channel 11', function() {
|
||||
var expectation = '!';
|
||||
var result = k.commandChannelOn(1);
|
||||
var expectation = 'E';
|
||||
var result = k.commandChannelOn(11);
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Channel 12', function() {
|
||||
var expectation = '!';
|
||||
var result = k.commandChannelOn(1);
|
||||
var expectation = 'R';
|
||||
var result = k.commandChannelOn(12);
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Channel 13', function() {
|
||||
var expectation = '!';
|
||||
var result = k.commandChannelOn(1);
|
||||
var expectation = 'T';
|
||||
var result = k.commandChannelOn(13);
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Channel 14', function() {
|
||||
var expectation = '!';
|
||||
var result = k.commandChannelOn(1);
|
||||
var expectation = 'Y';
|
||||
var result = k.commandChannelOn(14);
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Channel 15', function() {
|
||||
var expectation = '!';
|
||||
var result = k.commandChannelOn(1);
|
||||
var expectation = 'U';
|
||||
var result = k.commandChannelOn(15);
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Channel 16', function() {
|
||||
var expectation = '!';
|
||||
var result = k.commandChannelOn(1);
|
||||
var expectation = 'I';
|
||||
var result = k.commandChannelOn(16);
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
it('Invalid channel request', function() {
|
||||
@@ -632,6 +765,25 @@ describe('OpenBCIConstants', function() {
|
||||
assert.equal(250, k.OBCISampleRate250);
|
||||
});
|
||||
});
|
||||
describe('Max sample number',function() {
|
||||
it('should be 255',function () {
|
||||
assert.equal(255, k.OBCISampleNumberMax);
|
||||
});
|
||||
});
|
||||
describe("Radio Channel Limits", function() {
|
||||
it("should get the right channel number max",function () {
|
||||
expect(k.OBCIRadioChannelMax).to.be.equal(25);
|
||||
});
|
||||
it("should get the right channel number min",function () {
|
||||
expect(k.OBCIRadioChannelMin).to.be.equal(1);
|
||||
});
|
||||
it("should get the right poll time max",function () {
|
||||
expect(k.OBCIRadioPollTimeMax).to.be.equal(255);
|
||||
});
|
||||
it("should get the right poll time min",function () {
|
||||
expect(k.OBCIRadioPollTimeMin).to.be.equal(0);
|
||||
});
|
||||
});
|
||||
describe('#getChannelSetter', function() {
|
||||
//'channel 1, power on, gain 24, inputType normal, bias include, srb2 connect, srb1 dissconnect'
|
||||
describe('channel input selection works', function() {
|
||||
@@ -933,6 +1085,14 @@ describe('OpenBCIConstants', function() {
|
||||
return expect(result).to.eventually.equal(expectation);
|
||||
});
|
||||
});
|
||||
describe('#getVersionNumber', function() {
|
||||
it('should get the major version number from a github standard version string',() => {
|
||||
var expectedVersion = 6;
|
||||
var inputStringVersion = 'v6.0.0';
|
||||
|
||||
expect(k.getVersionNumber(inputStringVersion)).to.equal(expectedVersion);
|
||||
});
|
||||
});
|
||||
describe('#getImpedanceSetter', function() {
|
||||
describe('channel input selection works', function () {
|
||||
it('channel 2', function (done) {
|
||||
@@ -1036,4 +1196,4 @@ describe('OpenBCIConstants', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+1169
-50
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -3,543 +3,18 @@ var chai = require('chai'),
|
||||
should = chai.should(),
|
||||
expect = chai.expect,
|
||||
openBCIBoard = require('../openBCIBoard'),
|
||||
OpenBCISample = openBCIBoard.OpenBCISample,
|
||||
k = OpenBCISample.k;
|
||||
openBCISample = openBCIBoard.OpenBCISample,
|
||||
k = openBCISample.k;
|
||||
|
||||
var chaiAsPromised = require("chai-as-promised");
|
||||
var sinonChai = require("sinon-chai");
|
||||
chai.use(chaiAsPromised);
|
||||
chai.use(sinonChai);
|
||||
|
||||
var bufferEqual = require('buffer-equal');
|
||||
var fs = require('fs');
|
||||
//var wstream = fs.createWriteStream('myOutput.txt');
|
||||
|
||||
|
||||
describe('openbci-sdk',function() {
|
||||
this.timeout(2000);
|
||||
var ourBoard, masterPortName, realBoard, spy;
|
||||
|
||||
before(function(done) {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard();
|
||||
ourBoard.autoFindOpenBCIBoard()
|
||||
.then(portName => {
|
||||
ourBoard = null;
|
||||
realBoard = true;
|
||||
masterPortName = portName;
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
ourBoard = null;
|
||||
realBoard = false;
|
||||
masterPortName = k.OBCISimulatorPortName;
|
||||
done();
|
||||
})
|
||||
});
|
||||
describe('#constructor', function () {
|
||||
it('constructs with the correct default options', function() {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard();
|
||||
(ourBoard.options.boardType).should.equal('default');
|
||||
(ourBoard.options.baudRate).should.equal(115200);
|
||||
(ourBoard.options.verbose).should.equal(false);
|
||||
(ourBoard.options.simulate).should.equal(false);
|
||||
(ourBoard.options.simulatorSampleRate).should.equal(250);
|
||||
(ourBoard.options.simulatorAlpha).should.equal(true);
|
||||
(ourBoard.options.simulatorLineNoise).should.equal('60Hz');
|
||||
describe('#sampleRate', function() {
|
||||
it('should get value for default',function() {
|
||||
ourBoard.sampleRate().should.equal(250);
|
||||
});
|
||||
});
|
||||
describe('#numberOfChannels', function() {
|
||||
it('should get value for default',function() {
|
||||
ourBoard.numberOfChannels().should.equal(8);
|
||||
});
|
||||
});
|
||||
});
|
||||
it('can set daisy mode', function() {
|
||||
var ourBoard1 = new openBCIBoard.OpenBCIBoard({
|
||||
boardType: 'daisy'
|
||||
});
|
||||
var ourBoard2 = new openBCIBoard.OpenBCIBoard({
|
||||
boardtype: 'daisy'
|
||||
});
|
||||
(ourBoard1.options.boardType).should.equal('daisy');
|
||||
(ourBoard2.options.boardType).should.equal('daisy');
|
||||
describe('#sampleRate', function() {
|
||||
it('should get value for daisy',function() {
|
||||
ourBoard1.sampleRate().should.equal(125);
|
||||
});
|
||||
});
|
||||
describe('#numberOfChannels', function() {
|
||||
it('should get value for daisy',function() {
|
||||
ourBoard1.numberOfChannels().should.equal(16);
|
||||
});
|
||||
});
|
||||
});
|
||||
it('can set ganglion mode', function() {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
boardType: 'ganglion'
|
||||
});
|
||||
(ourBoard.options.boardType).should.equal('ganglion');
|
||||
});
|
||||
it('can change baud rate', function() {
|
||||
var ourBoard1 = new openBCIBoard.OpenBCIBoard({
|
||||
baudRate: 9600
|
||||
});
|
||||
(ourBoard1.options.baudRate).should.equal(9600);
|
||||
var ourBoard2 = new openBCIBoard.OpenBCIBoard({
|
||||
baudrate: 9600
|
||||
});
|
||||
(ourBoard2.options.baudRate).should.equal(9600);
|
||||
});
|
||||
it('can enter verbose mode', function() {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
verbose: true
|
||||
});
|
||||
(ourBoard.options.verbose).should.equal(true);
|
||||
});
|
||||
it('can enter simulate mode', function() {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
simulate: true
|
||||
});
|
||||
(ourBoard.options.simulate).should.equal(true);
|
||||
});
|
||||
it('can turn 50Hz line noise on', function() {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
simulatorLineNoise: '50Hz'
|
||||
});
|
||||
(ourBoard.options.simulatorLineNoise).should.equal('50Hz');
|
||||
});
|
||||
it('can turn no line noise on', function() {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
simulatorLineNoise: 'None'
|
||||
});
|
||||
(ourBoard.options.simulatorLineNoise).should.equal('None');
|
||||
});
|
||||
it('defaults to 60Hz line noise when bad input', function() {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
simulatorLineNoise: '20Hz'
|
||||
});
|
||||
(ourBoard.options.simulatorLineNoise).should.equal('60Hz');
|
||||
});
|
||||
it('will not inject alpha', function() {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
simulatorAlpha: false
|
||||
});
|
||||
(ourBoard.options.simulatorAlpha).should.equal(false);
|
||||
});
|
||||
it('configures impedance testing variables correctly', function() {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard();
|
||||
(ourBoard.impedanceTest.active).should.equal(false);
|
||||
(ourBoard.impedanceTest.isTestingNInput).should.equal(false);
|
||||
(ourBoard.impedanceTest.isTestingPInput).should.equal(false);
|
||||
(ourBoard.impedanceTest.onChannel).should.equal(0);
|
||||
(ourBoard.impedanceTest.sampleNumber).should.equal(0);
|
||||
});
|
||||
it('configures impedance array with the correct amount of channels for default', function() {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard();
|
||||
(ourBoard.impedanceArray.length).should.equal(8);
|
||||
});
|
||||
it('configures impedance array with the correct amount of channels for daisy', function() {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
boardType: 'daisy'
|
||||
});
|
||||
(ourBoard.impedanceArray.length).should.equal(16);
|
||||
});
|
||||
it('configures impedance array with the correct amount of channels for ganglion', function() {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
boardType: 'ganglion'
|
||||
});
|
||||
(ourBoard.impedanceArray.length).should.equal(4);
|
||||
});
|
||||
});
|
||||
describe('#simulator', function() {
|
||||
it('can enable simulator after constructor', function(done) {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
verbose: true
|
||||
});
|
||||
ourBoard.simulatorEnable().should.be.fulfilled.and.notify(done);
|
||||
});
|
||||
it('should disable sim and call disconnected', function(done) {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
verbose: true
|
||||
});
|
||||
var disconnectSpy = sinon.spy(ourBoard,"disconnect");
|
||||
ourBoard.options.simulate.should.equal(false);
|
||||
ourBoard.connected = true;
|
||||
ourBoard.simulatorEnable().then(() => {
|
||||
disconnectSpy.should.have.been.calledOnce;
|
||||
ourBoard.options.simulate.should.equal(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should not enable the simulator if already simulating', function(done) {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
verbose: true,
|
||||
simulate: true
|
||||
});
|
||||
ourBoard.simulatorEnable().should.be.rejected.and.notify(done);
|
||||
});
|
||||
it('can disable simulator', function(done) {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
verbose: true,
|
||||
simulate: true
|
||||
});
|
||||
ourBoard.simulatorDisable().should.be.fulfilled.and.notify(done);
|
||||
});
|
||||
it('should not disable simulator if not in simulate mode', function(done) {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
verbose: true
|
||||
});
|
||||
ourBoard.simulatorDisable().should.be.rejected.and.notify(done);
|
||||
});
|
||||
it('should start sim and call disconnected', function(done) {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
verbose: true,
|
||||
simulate: true
|
||||
});
|
||||
var disconnectSpy = sinon.spy(ourBoard,"disconnect");
|
||||
ourBoard.options.simulate.should.equal(true);
|
||||
ourBoard.connected = true;
|
||||
ourBoard.simulatorDisable().then(() => {
|
||||
disconnectSpy.should.have.been.calledOnce;
|
||||
ourBoard.options.simulate.should.equal(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#boardTests', function() {
|
||||
this.timeout(2000);
|
||||
before(function() {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
simulate: !realBoard,
|
||||
verbose: true
|
||||
});
|
||||
spy = sinon.spy(ourBoard,"_writeAndDrain");
|
||||
});
|
||||
after(function(done) {
|
||||
if (ourBoard.connected) {
|
||||
ourBoard.disconnect().then(() => {
|
||||
done();
|
||||
});
|
||||
} else {
|
||||
done()
|
||||
}
|
||||
});
|
||||
afterEach(function() {
|
||||
if (spy) spy.reset();
|
||||
});
|
||||
describe('#connect/disconnect/streamStart/streamStop', function () {
|
||||
it('sends a stop streaming command before disconnecting', function(done) {
|
||||
//spy = sinon.spy(ourBoard,"_writeAndDrain");
|
||||
|
||||
ourBoard.connect(masterPortName).catch(err => done(err));
|
||||
|
||||
ourBoard.once('ready', function() {
|
||||
ourBoard.streamStart().catch(err => done(err)); // start streaming
|
||||
|
||||
ourBoard.once('sample',(sample) => { // wait till we get a sample
|
||||
//console.log('got a sample');
|
||||
ourBoard.disconnect().then(() => { // call disconnect
|
||||
//console.log('Device is streaming: ' + ourBoard.streaming ? 'true' : 'false');
|
||||
setTimeout(() => {
|
||||
spy.should.have.been.calledWithMatch(k.OBCIStreamStop);
|
||||
var conditionalTimeout = realBoard ? 300 : 0;
|
||||
setTimeout(() => {
|
||||
done();
|
||||
}, conditionalTimeout);
|
||||
}, 4 * k.OBCIWriteIntervalDelayMSShort); // give plenty of time
|
||||
}).catch(err => done(err));
|
||||
});
|
||||
});
|
||||
});
|
||||
it('gets the ready ($$$) signal from board', function(done) {
|
||||
ourBoard.connect(masterPortName).catch(err => done(err));
|
||||
// for the ready signal test
|
||||
ourBoard.once('ready', function() {
|
||||
//console.log('got here');
|
||||
ourBoard.disconnect()
|
||||
.then(() => {
|
||||
//console.log('disconnected');
|
||||
var conditionalTimeout = realBoard ? 300 : 0;
|
||||
setTimeout(() => {
|
||||
done();
|
||||
}, conditionalTimeout);
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
it('rawDataPacket is emitted', function(done) {
|
||||
ourBoard.connect(masterPortName).catch(err => done(err));
|
||||
// for the ready signal test
|
||||
ourBoard.once('ready', function() {
|
||||
ourBoard.streamStart().catch(err => done(err)); // start streaming
|
||||
|
||||
ourBoard.once('rawDataPacket',(rawDataPacket) => { // wait till we get a raw data packet
|
||||
console.log('got a sample');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('#write', function() {
|
||||
before(function(done) {
|
||||
if (ourBoard.connected) {
|
||||
ourBoard.disconnect().then(() => {
|
||||
done();
|
||||
});
|
||||
} else {
|
||||
done()
|
||||
}
|
||||
});
|
||||
it('rejects when not connected', function(done) {
|
||||
ourBoard.write('b').should.be.rejected.and.notify(done);
|
||||
});
|
||||
});
|
||||
// good
|
||||
describe('#listPorts', function () {
|
||||
it('returns a list of ports',function(done) {
|
||||
ourBoard.listPorts().then(ports => {
|
||||
if (ports.some(port => {
|
||||
if (port.comName === masterPortName) {
|
||||
return true;
|
||||
}
|
||||
})) {
|
||||
done();
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
// bad
|
||||
describe('#channelOff', function () {
|
||||
before(function(done) {
|
||||
if (!ourBoard.connected) {
|
||||
ourBoard.connect(masterPortName)
|
||||
.then(done)
|
||||
.catch(err => done(err));
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('should call the write function with proper command for channel 1', function(done) {
|
||||
ourBoard.channelOff(1).then(() => {
|
||||
setTimeout(() => {
|
||||
spy.should.have.been.calledWith(k.OBCIChannelOff_1);
|
||||
done();
|
||||
}, 5 * k.OBCIWriteIntervalDelayMSShort);
|
||||
});
|
||||
});
|
||||
it('should call the write function with proper command for channel 16', function(done) {
|
||||
//spy = sinon.spy(ourBoard,"_writeAndDrain");
|
||||
|
||||
ourBoard.channelOff(16).then(() => {
|
||||
setTimeout(() => {
|
||||
spy.should.have.been.calledWith(k.OBCIChannelOff_16);
|
||||
done();
|
||||
}, 5 * k.OBCIWriteIntervalDelayMSShort);
|
||||
});
|
||||
});
|
||||
it('should reject with invalid channel', function(done) {
|
||||
ourBoard.channelOff(0).should.be.rejected.and.notify(done);
|
||||
});
|
||||
it('should turn the realBoard channel off', function(done) {
|
||||
ourBoard.channelOff(1).then(() => {
|
||||
setTimeout(() => {
|
||||
spy.should.have.been.calledWith(k.OBCIChannelOff_1);
|
||||
done();
|
||||
}, 5 * k.OBCIWriteIntervalDelayMSShort);
|
||||
});
|
||||
});
|
||||
});
|
||||
// good
|
||||
describe('#channelOn', function () {
|
||||
before(function(done) {
|
||||
if (!ourBoard.connected) {
|
||||
ourBoard.connect(masterPortName)
|
||||
.then(done)
|
||||
.catch(err => done(err));
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('should call the write function with proper command for channel 2', function(done) {
|
||||
ourBoard.channelOn(2).then(() => {
|
||||
setTimeout(() => {
|
||||
spy.should.have.been.calledWith(k.OBCIChannelOn_2);
|
||||
done();
|
||||
}, 5 * k.OBCIWriteIntervalDelayMSShort);
|
||||
|
||||
});
|
||||
});
|
||||
it('should call the write function with proper command for channel 16', function(done) {
|
||||
ourBoard.channelOn(16).then(() => {
|
||||
setTimeout(() => {
|
||||
spy.should.have.been.calledWith(k.OBCIChannelOn_16);
|
||||
done();
|
||||
}, 5 * k.OBCIWriteIntervalDelayMSShort);
|
||||
|
||||
});
|
||||
});
|
||||
it('should reject with invalid channel', function(done) {
|
||||
ourBoard.channelOn(0).should.be.rejected.and.notify(done);
|
||||
});
|
||||
});
|
||||
// bad
|
||||
describe('#channelSet', function () {
|
||||
this.timeout(6000);
|
||||
before(function(done) {
|
||||
if (!ourBoard.connected) {
|
||||
ourBoard.connect(masterPortName)
|
||||
.then(done)
|
||||
.catch(err => done(err));
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
});
|
||||
it('should call the writeAndDrain function array of commands 9 times', function(done) {
|
||||
setTimeout(() => {
|
||||
spy.reset();
|
||||
ourBoard.channelSet(1,true,24,'normal',true,true,true)
|
||||
.then(() => {
|
||||
setTimeout(() => {
|
||||
spy.callCount.should.equal(9);
|
||||
done()
|
||||
}, 15 * k.OBCIWriteIntervalDelayMSShort);
|
||||
})
|
||||
.catch(err => done(err));
|
||||
}, 10 * k.OBCIWriteIntervalDelayMSShort); // give some time for writer to finish
|
||||
});
|
||||
|
||||
it('should be rejected', function(done) {
|
||||
ourBoard.channelSet(1,true,24,'normal','taco',true,true).should.be.rejected.and.notify(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#impedanceTest Not Connected Rejects ',function() {
|
||||
it('rejects all channeles when not streaming', function(done) {
|
||||
ourBoard.impedanceTestAllChannels().should.be.rejected.and.notify(done);
|
||||
});
|
||||
it('rejects array channels when not streaming', function(done) {
|
||||
ourBoard.impedanceTestChannels(['-','N','n','p','P','-','b','b']).should.be.rejected.and.notify(done);
|
||||
});
|
||||
});
|
||||
describe('#impedancePrivates', function () {
|
||||
describe('disconnected', function() {
|
||||
before(function(done) {
|
||||
if (ourBoard.connected) {
|
||||
ourBoard.disconnect()
|
||||
.then(done)
|
||||
.catch(err => done(err));
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
});
|
||||
describe('#_impedanceTestSetChannel', function () {
|
||||
it('should reject because not connected', function(done) {
|
||||
ourBoard._impedanceTestSetChannel(0,false,false).should.be.rejected.and.notify(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
xdescribe('#hardwareValidation', function() {
|
||||
this.timeout(20000); // long timeout for pleanty of stream time :)
|
||||
var runHardwareValidation = masterPortName !== k.OBCISimulatorPortName;
|
||||
var wstream;
|
||||
before(function(done) {
|
||||
if (runHardwareValidation) {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
verbose:true
|
||||
});
|
||||
// Use the line below to output the
|
||||
wstream = fs.createWriteStream('hardwareVoltageOutputAll.txt');
|
||||
|
||||
ourBoard.connect(masterPortName)
|
||||
.catch(err => done(err));
|
||||
|
||||
ourBoard.once('ready',() => {
|
||||
done();
|
||||
});
|
||||
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
|
||||
});
|
||||
after(function() {
|
||||
if (runHardwareValidation) {
|
||||
ourBoard.disconnect();
|
||||
}
|
||||
});
|
||||
it('test all output signals', function(done) {
|
||||
if (runHardwareValidation) {
|
||||
ourBoard.streamStart()
|
||||
.then(() => {
|
||||
console.log('Started stream');
|
||||
console.log('--------');
|
||||
|
||||
})
|
||||
.catch(err => done(err));
|
||||
|
||||
setTimeout(() => {
|
||||
console.log('*-------');
|
||||
ourBoard.testSignal('pulse1xSlow');
|
||||
},3000);
|
||||
setTimeout(() => {
|
||||
console.log('**------');
|
||||
ourBoard.testSignal('pulse2xSlow');
|
||||
},5000);
|
||||
setTimeout(() => {
|
||||
console.log('***-----');
|
||||
ourBoard.testSignal('pulse1xFast');
|
||||
},7000);
|
||||
setTimeout(() => {
|
||||
console.log('****----');
|
||||
ourBoard.testSignal('pulse2xFast');
|
||||
},9000);
|
||||
setTimeout(() => {
|
||||
console.log('*****---');
|
||||
ourBoard.testSignal('none');
|
||||
},11000);
|
||||
setTimeout(() => {
|
||||
console.log('******--');
|
||||
ourBoard.testSignal('pulse1xSlow');
|
||||
},13000);
|
||||
setTimeout(() => {
|
||||
console.log('*******-');
|
||||
ourBoard.testSignal('none');
|
||||
},15000);
|
||||
|
||||
|
||||
ourBoard.on('sample', sample => {
|
||||
OpenBCISample.samplePrintLine(sample)
|
||||
.then(line => {
|
||||
wstream.write(line);
|
||||
});
|
||||
});
|
||||
// This stops the test
|
||||
setTimeout(() => {
|
||||
console.log('********');
|
||||
done();
|
||||
},19000);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#impedanceTesting', function() {
|
||||
var ourBoard;
|
||||
this.timeout(20000);
|
||||
@@ -548,7 +23,6 @@ describe('#impedanceTesting', function() {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
verbose: true
|
||||
});
|
||||
|
||||
var useSim = () => {
|
||||
ourBoard.simulatorEnable().then(() => {
|
||||
return ourBoard.connect(k.OBCISimulatorPortName);
|
||||
@@ -579,13 +53,21 @@ describe('#impedanceTesting', function() {
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
done(err);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
after(function() {
|
||||
ourBoard.disconnect();
|
||||
after(done => {
|
||||
if(ourBoard["connected"]) {
|
||||
ourBoard.disconnect()
|
||||
.then(() => {
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
done(err);
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
describe('#impedanceTestAllChannels', function () {
|
||||
@@ -786,7 +268,7 @@ describe('#impedanceTesting', function() {
|
||||
impedanceArray = arr;
|
||||
done();
|
||||
});
|
||||
ourBoard.impedanceArray[0] = openBCIBoard.OpenBCISample.impedanceObject(1);
|
||||
ourBoard.impedanceArray[0] = openBCISample.impedanceObject(1);
|
||||
ourBoard.impedanceTestChannels(['-','N','n','p','P','p','b','B']).catch(err => done(err));
|
||||
});
|
||||
describe('#channel1',function() {
|
||||
@@ -1138,55 +620,3 @@ describe('#impedanceTesting', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#sync', function() {
|
||||
var ourBoard;
|
||||
this.timeout(5000);
|
||||
before(function (done) {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard();
|
||||
|
||||
var useSim = () => {
|
||||
ourBoard.simulatorEnable()
|
||||
.then(() => {
|
||||
return ourBoard.connect(k.OBCISimulatorPortName);
|
||||
})
|
||||
.then(() => {
|
||||
return ourBoard.softReset();
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
};
|
||||
ourBoard.autoFindOpenBCIBoard()
|
||||
.then(portName => {
|
||||
return ourBoard.connect(portName);
|
||||
})
|
||||
.catch((err) => {
|
||||
useSim();
|
||||
})
|
||||
.then(() => {
|
||||
//console.log('connected');
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('Error: ' + err);
|
||||
});
|
||||
|
||||
|
||||
ourBoard.once('ready', () => {
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
after(function () {
|
||||
ourBoard.disconnect();
|
||||
});
|
||||
describe('#sntp', function() {
|
||||
it('can get sntp time and verify extend of sntp valid', function(done) {
|
||||
ourBoard.sntpStart()
|
||||
.then(() => {
|
||||
// sntp.now should be extended into ourBoard.sntpNow
|
||||
ourBoard.sntpNow().should.equal(ourBoard.sntp.now());
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -0,0 +1,710 @@
|
||||
var sinon = require('sinon'),
|
||||
chai = require('chai'),
|
||||
should = chai.should(),
|
||||
expect = chai.expect,
|
||||
openBCISimulator = require('../openBCISimulator'),
|
||||
openBCISample = require('../openBCISample'),
|
||||
k = openBCISample.k;
|
||||
|
||||
var chaiAsPromised = require("chai-as-promised");
|
||||
var sinonChai = require("sinon-chai");
|
||||
chai.use(chaiAsPromised);
|
||||
chai.use(sinonChai);
|
||||
var bufferEqual = require('buffer-equal');
|
||||
var fs = require('fs');
|
||||
|
||||
describe('openBCISimulator',function() {
|
||||
this.timeout(4000);
|
||||
var portName = k.OBCISimulatorPortName;
|
||||
describe('#constructor', function () {
|
||||
var simulator;
|
||||
afterEach(() => {
|
||||
simulator = null;
|
||||
});
|
||||
after(done => {
|
||||
setTimeout(() => {
|
||||
// Since there is a conditional timeout, it's important to wait to start the next test till this ends for sure
|
||||
done();
|
||||
}, 200); // The same amount of time in the simulator
|
||||
});
|
||||
it('constructs with the correct default options', function() {
|
||||
simulator = new openBCISimulator.OpenBCISimulator();
|
||||
expect(simulator.options.accel).to.be.true;
|
||||
expect(simulator.options.alpha).to.be.true;
|
||||
expect(simulator.options.boardFailure).to.be.false;
|
||||
expect(simulator.options.daisy).to.be.false;
|
||||
expect(simulator.options.drift).to.equal(0);
|
||||
expect(simulator.options.firmwareVersion).to.equal(k.OBCIFirmwareV1);
|
||||
expect(simulator.options.lineNoise).to.equal(k.OBCISimulatorLineNoiseHz60);
|
||||
expect(simulator.options.sampleRate).to.equal(k.OBCISampleRate250);
|
||||
expect(simulator.options.serialPortFailure).to.be.false;
|
||||
expect(simulator.options.verbose).to.be.false;
|
||||
});
|
||||
it('should be able to get into daisy mode',function () {
|
||||
simulator = new openBCISimulator.OpenBCISimulator(portName,{
|
||||
daisy: true
|
||||
});
|
||||
expect(simulator.options.daisy).to.be.true;
|
||||
});
|
||||
it('should set the correct sample rate in daisy mode, if no sampleRate is provided',function () {
|
||||
simulator = new openBCISimulator.OpenBCISimulator(portName,{
|
||||
daisy: true
|
||||
});
|
||||
expect(simulator.options.sampleRate).to.equal(250); // produce samples at same rate
|
||||
});
|
||||
it('should use provided sample rate even if daisy is true',function () {
|
||||
simulator = new openBCISimulator.OpenBCISimulator(portName,{
|
||||
daisy: true,
|
||||
sampleRate: 20
|
||||
});
|
||||
expect(simulator.options.daisy).to.be.true;
|
||||
expect(simulator.options.sampleRate).to.equal(20);
|
||||
});
|
||||
it('should be able to put into firmware version 2', function () {
|
||||
simulator = new openBCISimulator.OpenBCISimulator(portName,{
|
||||
firmwareVersion: 'v2'
|
||||
});
|
||||
expect(simulator.options.firmwareVersion).to.equal(k.OBCIFirmwareV2);
|
||||
});
|
||||
it('should be able to simulate board failure',function () {
|
||||
simulator = new openBCISimulator.OpenBCISimulator(portName,{
|
||||
boardFailure: true
|
||||
});
|
||||
expect(simulator.options.boardFailure).to.be.true;
|
||||
});
|
||||
it('should be able to simulate serial port failure',function () {
|
||||
simulator = new openBCISimulator.OpenBCISimulator(portName,{
|
||||
serialPortFailure: true
|
||||
});
|
||||
expect(simulator.options.serialPortFailure).to.be.true;
|
||||
});
|
||||
it('can turn 50Hz line noise on', function() {
|
||||
simulator = new openBCISimulator.OpenBCISimulator(portName,{
|
||||
lineNoise: '50Hz'
|
||||
});
|
||||
(simulator.options.lineNoise).should.equal(k.OBCISimulatorLineNoiseHz50);
|
||||
});
|
||||
it('can turn no line noise on', function() {
|
||||
simulator = new openBCISimulator.OpenBCISimulator(portName,{
|
||||
lineNoise: 'None'
|
||||
});
|
||||
(simulator.options.lineNoise).should.equal(k.OBCISimulatorLineNoiseNone);
|
||||
});
|
||||
it('should not inject alpha if desired', function() {
|
||||
simulator = new openBCISimulator.OpenBCISimulator(portName,{
|
||||
alpha: false
|
||||
});
|
||||
expect(simulator.options.alpha).to.be.false;
|
||||
});
|
||||
it('should be able to not use the accel', function() {
|
||||
simulator = new openBCISimulator.OpenBCISimulator(portName,{
|
||||
accel: false
|
||||
});
|
||||
expect(simulator.options.accel).to.be.false;
|
||||
});
|
||||
it('should be able to set positive drift', function() {
|
||||
simulator = new openBCISimulator.OpenBCISimulator(portName,{
|
||||
drift: 1
|
||||
});
|
||||
expect(simulator.options.drift).to.be.greaterThan(0);
|
||||
});
|
||||
it('should be able to set negative drift', function() {
|
||||
simulator = new openBCISimulator.OpenBCISimulator(portName,{
|
||||
drift: -1
|
||||
});
|
||||
expect(simulator.options.drift).to.be.lessThan(0);
|
||||
});
|
||||
});
|
||||
describe("_startStream", function() {
|
||||
it('should return a packet with sample data in it', function(done) {
|
||||
var simulator = new openBCISimulator.OpenBCISimulator(k.OBCISimulatorPortName);
|
||||
var sampleCounter = 0;
|
||||
var sampleTestSize = 5;
|
||||
|
||||
var newDataFunc = data => {
|
||||
if (sampleCounter > sampleTestSize) {
|
||||
simulator.write(new Buffer([k.OBCIStreamStop]));
|
||||
simulator.removeListener('data',newDataFunc);
|
||||
openBCISample.parseRawPacketStandard(data,k.channelSettingsArrayInit(k.OBCINumberOfChannelsDefault),true)
|
||||
.then(sampleObject => {
|
||||
sampleObject.channelData.forEach((channelValue, index) => {
|
||||
expect(channelValue).to.not.equal(0);
|
||||
});
|
||||
simulator = null;
|
||||
done();
|
||||
});
|
||||
} else {
|
||||
sampleCounter++;
|
||||
}
|
||||
}
|
||||
simulator.on('data',newDataFunc);
|
||||
simulator._startStream();
|
||||
});
|
||||
it('should return a sync set packet with accel',function(done) {
|
||||
var simulator = new openBCISimulator.OpenBCISimulator(k.OBCISimulatorPortName);
|
||||
var sampleCounter = 0;
|
||||
var sampleTestSize = 5;
|
||||
|
||||
var newDataFunc = data => {
|
||||
if (sampleCounter === 0) {
|
||||
// Ensure everything is switched on for this test
|
||||
simulator.options.accel = true;
|
||||
simulator.synced = true;
|
||||
simulator.sendSyncSetPacket = true;
|
||||
expect(data[k.OBCIPacketPositionStopByte]).to.equal(openBCISample.makeTailByteFromPacketType(k.OBCIStreamPacketStandardAccel));
|
||||
} else if (sampleCounter === 1) {
|
||||
// Now this data should be the time sync up packet
|
||||
expect(data[k.OBCIPacketPositionStopByte]).to.equal(openBCISample.makeTailByteFromPacketType(k.OBCIStreamPacketAccelTimeSyncSet));
|
||||
// Expect flag to be down
|
||||
expect(simulator.sendSyncSetPacket).to.be.false;
|
||||
} else if (sampleCounter >= sampleTestSize) {
|
||||
simulator.write(new Buffer([k.OBCIStreamStop]));
|
||||
simulator.removeListener('data',newDataFunc);
|
||||
simulator = null;
|
||||
done();
|
||||
} else {
|
||||
// Now this data should be the time sync up packet
|
||||
expect(data[k.OBCIPacketPositionStopByte]).to.equal(openBCISample.makeTailByteFromPacketType(k.OBCIStreamPacketAccelTimeSynced));
|
||||
}
|
||||
sampleCounter++;
|
||||
}
|
||||
|
||||
simulator.on('data',newDataFunc);
|
||||
simulator._startStream();
|
||||
});
|
||||
it('should return a sync set packet with raw aux',function(done) {
|
||||
var simulator = new openBCISimulator.OpenBCISimulator(k.OBCISimulatorPortName,{
|
||||
accel: false
|
||||
});
|
||||
var sampleCounter = 0;
|
||||
var sampleTestSize = 5;
|
||||
|
||||
var newDataFunc = data => {
|
||||
if (sampleCounter === 0) {
|
||||
// Ensure everything is switched on for this test
|
||||
simulator.synced = true;
|
||||
simulator.sendSyncSetPacket = true;
|
||||
expect(data[k.OBCIPacketPositionStopByte]).to.equal(openBCISample.makeTailByteFromPacketType(k.OBCIStreamPacketStandardRawAux));
|
||||
} else if (sampleCounter === 1) {
|
||||
// Now this data should be the time sync up packet
|
||||
expect(data[k.OBCIPacketPositionStopByte]).to.equal(openBCISample.makeTailByteFromPacketType(k.OBCIStreamPacketRawAuxTimeSyncSet));
|
||||
// Expect flag to be down
|
||||
expect(simulator.sendSyncSetPacket).to.be.false;
|
||||
} else if (sampleCounter >= sampleTestSize) {
|
||||
simulator.write(new Buffer([k.OBCIStreamStop]));
|
||||
simulator.removeListener('data',newDataFunc);
|
||||
simulator = null;
|
||||
done();
|
||||
} else {
|
||||
// Now this data should be the time sync up packet
|
||||
expect(data[k.OBCIPacketPositionStopByte]).to.equal(openBCISample.makeTailByteFromPacketType(k.OBCIStreamPacketRawAuxTimeSynced));
|
||||
}
|
||||
sampleCounter++;
|
||||
}
|
||||
|
||||
simulator.on('data',newDataFunc);
|
||||
simulator._startStream();
|
||||
});
|
||||
});
|
||||
describe("firmwareVersion1",function () {
|
||||
|
||||
});
|
||||
describe("firmwareVersion2",function () {
|
||||
var simulator;
|
||||
beforeEach(() => {
|
||||
simulator = new openBCISimulator.OpenBCISimulator(k.OBCISimulatorPortName,{
|
||||
firmwareVersion: 'v2'
|
||||
});
|
||||
});
|
||||
afterEach(() => {
|
||||
simulator = null;
|
||||
});
|
||||
describe('_processPrivateRadioMessage',function () {
|
||||
describe('OBCIRadioCmdChannelGet',function () {
|
||||
it('should emit success if firmware version 2', done => {
|
||||
simulator.channelNumber = 0;
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.true;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.false;
|
||||
expect(buf[buf.length - 4]).to.equal(0);
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdChannelGet]));
|
||||
});
|
||||
it('should emit failure if board failure and host channel number', done => {
|
||||
// Turn board failure mode
|
||||
simulator.options.boardFailure = true;
|
||||
simulator.channelNumber = 9;
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.false;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.true;
|
||||
expect(buf[buf.length - 4]).to.equal(9);
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdChannelGet]));
|
||||
});
|
||||
});
|
||||
describe('OBCIRadioCmdChannelSet',function () {
|
||||
it('should set the channel number if in bounds', done => {
|
||||
var newChanNum = 20;
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.true;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.false;
|
||||
expect(buf[buf.length - 4]).to.equal(newChanNum);
|
||||
expect(simulator.channelNumber).to.equal(newChanNum);
|
||||
expect(simulator.hostChannelNumber).to.equal(newChanNum);
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdChannelSet,newChanNum]));
|
||||
});
|
||||
it('should not set the channel number if out of bounds', done => {
|
||||
var newChanNum = 26;
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.false;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.true;
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdChannelSet,newChanNum]));
|
||||
});
|
||||
it('should emit failure if board failure', done => {
|
||||
// Turn board failure mode
|
||||
simulator.options.boardFailure = true;
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.false;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.true;
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdChannelSet,7]));
|
||||
});
|
||||
});
|
||||
describe('OBCIRadioCmdChannelSetOverride',function () {
|
||||
it('should change just the hosts channel number and not the systems channel number and force a board comms failure', done => {
|
||||
var systemChannelNumber = 0;
|
||||
var newHostChannelNumber = 1;
|
||||
simulator.channelNumber = systemChannelNumber;
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.true;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.false;
|
||||
expect(buf[buf.length - 4]).to.equal(newHostChannelNumber);
|
||||
expect(simulator.options.boardFailure).to.be.true;
|
||||
expect(simulator.channelNumber).to.equal(systemChannelNumber);
|
||||
expect(simulator.hostChannelNumber).to.equal(newHostChannelNumber);
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdChannelSetOverride,newHostChannelNumber]));
|
||||
});
|
||||
it('should change just the hosts channel number and not the systems channel number and fix a board failure', done => {
|
||||
var systemChannelNumber = 0;
|
||||
var oldHostChannelNumber = 1;
|
||||
simulator.channelNumber = systemChannelNumber;
|
||||
simulator.hostChannelNumber = oldHostChannelNumber;
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.true;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.false;
|
||||
expect(buf[buf.length - 4]).to.equal(systemChannelNumber);
|
||||
expect(simulator.options.boardFailure).to.be.false;
|
||||
expect(simulator.channelNumber).to.equal(systemChannelNumber);
|
||||
expect(simulator.hostChannelNumber).to.equal(systemChannelNumber);
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdChannelSetOverride,systemChannelNumber]));
|
||||
});
|
||||
it('should not set the channel number if out of bounds', done => {
|
||||
var newChanNum = 26;
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.false;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.true;
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdChannelSetOverride,newChanNum]));
|
||||
});
|
||||
});
|
||||
describe('OBCIRadioCmdPollTimeGet',function () {
|
||||
it('should emit success if firmware version 2 with poll time', done => {
|
||||
var expectedPollTime = 80;
|
||||
simulator.pollTime = expectedPollTime;
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.true;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.false;
|
||||
expect(buf[buf.length - 4]).to.equal(expectedPollTime);
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdPollTimeGet]));
|
||||
});
|
||||
it('should emit failure if board failure', done => {
|
||||
// Turn board failure mode
|
||||
simulator.options.boardFailure = true;
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.false;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.true;
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdPollTimeGet]));
|
||||
});
|
||||
});
|
||||
describe('OBCIRadioCmdPollTimeSet',function () {
|
||||
it('should set the poll time if in bounds', done => {
|
||||
var newPollTime = 20;
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.true;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.false;
|
||||
expect(buf[buf.length - 4]).to.equal(newPollTime);
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdPollTimeSet,newPollTime]));
|
||||
});
|
||||
it('should emit failure if board failure', done => {
|
||||
// Turn board failure mode
|
||||
simulator.options.boardFailure = true;
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.false;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.true;
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdPollTimeSet,7]));
|
||||
});
|
||||
});
|
||||
describe('OBCIRadioCmdBaudRateSetDefault',function () {
|
||||
it('should emit success if firmware version 2 with proper baud rate', done => {
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.true;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.false;
|
||||
var eotBuf = new Buffer('$$$');
|
||||
var newBaudRateBuf;
|
||||
for (var i = buf.length; i > 3; i--) {
|
||||
if (bufferEqual(buf.slice(i - 3, i),eotBuf)) {
|
||||
newBaudRateBuf = buf.slice(i - 9, i - 3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
var newBaudRateNum = Number(newBaudRateBuf.toString());
|
||||
expect(newBaudRateNum).to.equal(k.OBCIRadioBaudRateDefault);
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdBaudRateSetDefault]));
|
||||
});
|
||||
it('should emit success if board failure', done => {
|
||||
// Turn board failure mode
|
||||
simulator.options.boardFailure = true;
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.true;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.false;
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdBaudRateSetDefault]));
|
||||
});
|
||||
});
|
||||
describe('OBCIRadioCmdBaudRateSetFast',function () {
|
||||
it('should emit success if firmware version 2 with proper baud rate', done => {
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.true;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.false;
|
||||
var eotBuf = new Buffer("$$$");
|
||||
var newBaudRateBuf;
|
||||
for (var i = buf.length; i > 3; i--) {
|
||||
if (bufferEqual(buf.slice(i - 3, i),eotBuf)) {
|
||||
newBaudRateBuf = buf.slice(i - 9, i - 3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
var newBaudRateNum = Number(newBaudRateBuf.toString());
|
||||
expect(newBaudRateNum).to.equal(k.OBCIRadioBaudRateFast);
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdBaudRateSetFast]));
|
||||
});
|
||||
it('should emit success if board failure', done => {
|
||||
// Turn board failure mode
|
||||
simulator.options.boardFailure = true;
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.true;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.false;
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdBaudRateSetFast]));
|
||||
});
|
||||
});
|
||||
describe('OBCIRadioCmdSystemStatus',function () {
|
||||
it('should emit success if firmware version 2', done => {
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.true;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.false;
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdSystemStatus]));
|
||||
});
|
||||
it('should emit failure if board failure', done => {
|
||||
// Turn board failure mode
|
||||
simulator.options.boardFailure = true;
|
||||
var buf = new Buffer(0);
|
||||
var dataEmit = data => {
|
||||
buf = Buffer.concat([buf,data]);
|
||||
if (openBCISample.doesBufferHaveEOT(buf)) {
|
||||
expect(openBCISample.isSuccessInBuffer(buf)).to.be.false;
|
||||
expect(openBCISample.isFailureInBuffer(buf)).to.be.true;
|
||||
simulator.removeListener('data',dataEmit);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
simulator.on('data',dataEmit);
|
||||
|
||||
simulator._processPrivateRadioMessage(new Buffer([k.OBCIRadioKey,k.OBCIRadioCmdSystemStatus]));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("boardFailure",function () {
|
||||
|
||||
});
|
||||
|
||||
describe("#sync",function () {
|
||||
this.timeout(2000);
|
||||
var simulator;
|
||||
beforeEach(function(done) {
|
||||
simulator = new openBCISimulator.OpenBCISimulator(portName, {
|
||||
firmwareVersion: 'v2'
|
||||
});
|
||||
simulator.once('open',() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
afterEach(function() {
|
||||
simulator = null;
|
||||
});
|
||||
it("should emit the time sync sent command", function(done) {
|
||||
simulator.once('data',data => {
|
||||
expect(openBCISample.isTimeSyncSetConfirmationInBuffer(data)).to.be.true;
|
||||
done();
|
||||
});
|
||||
simulator.write(k.OBCISyncTimeSet, (err, msg) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
it("should set synced to true", function(done) {
|
||||
simulator.synced = false;
|
||||
var newData = data => {
|
||||
expect(simulator.synced).to.be.true;
|
||||
simulator.removeListener('data', newData);
|
||||
done();
|
||||
};
|
||||
|
||||
simulator.on('data', data => {
|
||||
newData(data);
|
||||
});
|
||||
|
||||
simulator.write(k.OBCISyncTimeSet, (err, msg) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
it("should emit a time sync set packet followed by a time synced accel packet after sync up call", function(done) {
|
||||
simulator.synced = false;
|
||||
var emitCounter = 0;
|
||||
var maxPacketsBetweenSetPacket = 5;
|
||||
var newData = data => {
|
||||
if (emitCounter === 0) { // the time sync packet is emitted here
|
||||
// Make a call to start streaming
|
||||
simulator.write(k.OBCIStreamStart, err => {
|
||||
if (err) done(err);
|
||||
});
|
||||
} else if (emitCounter < maxPacketsBetweenSetPacket) {
|
||||
if (openBCISample.getRawPacketType(data[k.OBCIPacketPositionStopByte]) === k.OBCIStreamPacketAccelTimeSyncSet) {
|
||||
simulator.removeListener('data', newData);
|
||||
simulator.write(k.OBCIStreamStop, err => {
|
||||
if (err) done(err);
|
||||
done();
|
||||
});
|
||||
} else {
|
||||
expect(openBCISample.getRawPacketType(data[k.OBCIPacketPositionStopByte])).to.equal(k.OBCIStreamPacketAccelTimeSynced);
|
||||
|
||||
}
|
||||
} else {
|
||||
done("Failed to get set packet in time")
|
||||
}
|
||||
emitCounter++;
|
||||
};
|
||||
|
||||
simulator.on('data', newData);
|
||||
|
||||
simulator.write(k.OBCISyncTimeSet, (err, msg) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
it("should emit a time sync set raw aux, then time synced raw aux packet after sync up call", function(done) {
|
||||
simulator.synced = false;
|
||||
simulator.options.accel = false;
|
||||
var emitCounter = 0;
|
||||
var maxPacketsBetweenSetPacket = 5;
|
||||
var newData = data => {
|
||||
if (emitCounter === 0) { // the time sync packet is emitted here
|
||||
// Make a call to start streaming
|
||||
simulator.write(k.OBCIStreamStart, err => {
|
||||
if (err) done(err);
|
||||
});
|
||||
} else if (emitCounter < maxPacketsBetweenSetPacket) {
|
||||
if (openBCISample.getRawPacketType(data[k.OBCIPacketPositionStopByte]) === k.OBCIStreamPacketRawAuxTimeSyncSet) {
|
||||
simulator.removeListener('data', newData);
|
||||
simulator.write(k.OBCIStreamStop, err => {
|
||||
if (err) done(err);
|
||||
done();
|
||||
});
|
||||
} else {
|
||||
expect(openBCISample.getRawPacketType(data[k.OBCIPacketPositionStopByte])).to.equal(k.OBCIStreamPacketRawAuxTimeSynced);
|
||||
}
|
||||
} else {
|
||||
done("Failed to get set packet in time")
|
||||
}
|
||||
|
||||
emitCounter++;
|
||||
};
|
||||
|
||||
simulator.on('data', newData);
|
||||
|
||||
simulator.write(k.OBCISyncTimeSet, (err, msg) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
Referência em uma Nova Issue
Bloquear um usuário