ENH semistandard lint

Esse commit está contido em:
AJ Keller
2016-10-03 17:15:46 -04:00
commit 3e99a77e88
16 arquivos alterados com 11711 adições e 11896 exclusões
+1
Ver Arquivo
@@ -0,0 +1 @@
{"extends": ["standard"], "parser": "babel-eslint"}
+2 -1
Ver Arquivo
@@ -17,4 +17,5 @@ node_modules
.DS_Store
public
myOutput.txt
*.tgz
*.tgz
openBCISerialFormat
+1
Ver Arquivo
@@ -4,6 +4,7 @@
[![codecov](https://codecov.io/gh/OpenBCI/OpenBCI_NodeJS/branch/master/graph/badge.svg)](https://codecov.io/gh/OpenBCI/OpenBCI_NodeJS)
[![Dependency Status](https://david-dm.org/OpenBCI/OpenBCI_NodeJS.svg)](https://david-dm.org/OpenBCI/OpenBCI_NodeJS)
[![npm](https://img.shields.io/npm/dm/openbci.svg?maxAge=2592000)](http://npmjs.com/package/openbci)
[![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?style=flat-square)](https://github.com/Flet/semistandard)
# OpenBCI Node.js SDK
+6 -1
Ver Arquivo
@@ -1,3 +1,9 @@
# 1.4.0
### Enhancements
* Implement and adapt semi-standard code style. Closes #83
# 1.3.3
### New Features
@@ -9,7 +15,6 @@
* Fixed log statement on impedance setting function
* Remove event emitter with time sync on reject of sync clock full
# 1.3.2
### Enhancements
+55 -60
Ver Arquivo
@@ -11,83 +11,78 @@ 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*/
}
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();
// 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();
}
}
if (timeSyncPossible) {
ourBoard.streamStart()
.catch(err => {
console.log(`stream start: ${err}`);
});
} else {
killFunc();
}
};
var killFunc = () => {
ourBoard.disconnect()
ourBoard.disconnect()
.then(() => {
process.kill();
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}`);
// 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!`);
}
}
});
}
// Stop after one minute
if (sample._count > sampleRate * 60) {
killFunc();
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);
ourBoard.on('ready', readyFunc);
ourBoard.on('sample', sampleFunc);
+2178 -2206
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+1036 -1038
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+1199 -1215
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+324 -327
Ver Arquivo
@@ -8,355 +8,352 @@ var openBCISample = require('./openBCISample');
var k = openBCISample.k;
var now = require('performance-now');
function OpenBCISimulatorFactory () {
var factory = this;
function OpenBCISimulatorFactory() {
var factory = this;
var _options = {
accel: true,
alpha: true,
boardFailure: false,
daisy: false,
drift: 0,
firmwareVersion: k.OBCIFirmwareV1,
lineNoise: '60Hz',
sampleRate: 250,
serialPortFailure: false,
verbose: false
};
var _options = {
accel: true,
alpha: true,
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 = {};
stream.Stream.call(this);
/** Configuring Options */
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.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
};
// Strings
this.portName = portName || k.OBCISimulatorPortName;
function OpenBCISimulator(portName, options) {
options = (typeof options !== 'function') && options || {};
var opts = {};
// Call 'open'
if (this.options.verbose) console.log(`Port name: ${portName}`);
setTimeout(() => {
this.emit('open');
this.connected = true;
}, 200);
}
stream.Stream.call(this);
// This allows us to use the emitter class freely outside of the module
util.inherits(OpenBCISimulator, stream.Stream);
/** Configuring Options */
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.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;
OpenBCISimulator.prototype.flush = function () {
this.buffer.fill(0);
// if (this.options.verbose) console.log('flushed')
};
this.options = opts;
// Bools
this.connected = false;
this.sd = {
active:false,
startTime: 0
};
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;
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
};
// Strings
this.portName = portName || k.OBCISimulatorPortName;
// Call 'open'
if (this.options.verbose) console.log(`Port name: ${portName}`);
setTimeout(() => {
this.emit('open');
this.connected = true;
}, 200);
break;
case k.OBCIMiscSoftReset:
if (this.stream) clearInterval(this.stream);
this.streaming = false;
this.emit('data', new Buffer(`OpenBCI V3 Simulator On Board ADS1299 Device ID: 0x12345 ${this.options.daisy ? `On Daisy ADS1299 Device ID: 0xFFFFF\n` : ``} LIS3DH Device ID: 0x38422 ${this.options.firmware === k.OBCIFirmwareV2 ? `Firmware: v2.0.0\n` : ``}$$$`));
break;
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.OBCISDLogStop:
if (!this.streaming) {
if (this.SDLogActive) {
this.emit('data', new Buffer(`Total Elapsed Time: ${now() - this.sd.startTime} ms`));
this.emit('data', new Buffer(`Max write time: ${Math.random() * 500} us`));
this.emit('data', new Buffer(`Min write time: ${Math.random() * 200} us`));
this.emit('data', new Buffer(`Overruns: 0`));
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;
}
// This allows us to use the emitter class freely outside of the module
util.inherits(OpenBCISimulator, stream.Stream);
/** Handle Callback */
if (this.connected) {
callback(null, 'Success!');
}
};
OpenBCISimulator.prototype.flush = function() {
this.buffer.fill(0);
//if (this.options.verbose) console.log('flushed');
};
OpenBCISimulator.prototype.drain = function (callback) {
callback();
};
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.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.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.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;
OpenBCISimulator.prototype.close = function (callback) {
if (this.connected) {
this.emit('close');
}
this.connected = false;
callback();
};
OpenBCISimulator.prototype._startStream = function () {
var intervalInMS = 1000 / this.options.sampleRate;
if (intervalInMS < 2) intervalInMS = 2;
var getNewPacket = 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));
}
/** Handle Callback */
if (this.connected) {
callback(null,'Success!');
} 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]));
}
}
};
OpenBCISimulator.prototype.drain = function(callback) {
callback();
};
this.stream = setInterval(() => {
this.emit('data', getNewPacket(this.sampleNumber));
this.sampleNumber++;
}, intervalInMS);
};
OpenBCISimulator.prototype.close = function(callback) {
if (this.connected) {
this.emit('close');
OpenBCISimulator.prototype._syncUp = function () {
setTimeout(() => {
this.sendSyncSetPacket = true;
}, 12); // 3 packets later
};
OpenBCISimulator.prototype._printEOT = function () {
this.emit('data', new Buffer('$$$'));
};
OpenBCISimulator.prototype._printFailure = function () {
this.emit('data', new Buffer('Failure: '));
};
OpenBCISimulator.prototype._printSuccess = function () {
this.emit('data', new Buffer('Success: '));
};
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();
}
}
this.connected = false;
callback();
};
OpenBCISimulator.prototype._startStream = function() {
var intervalInMS = 1000 / this.options.sampleRate;
if (intervalInMS < 2) intervalInMS = 2;
var getNewPacket = 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));
}
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 {
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._printFailure();
this.emit('data', new Buffer('Verify channel number is less than 25'));
this._printEOT();
}
};
this.stream = setInterval(() => {
this.emit('data', getNewPacket(this.sampleNumber));
this.sampleNumber++;
}, intervalInMS);
};
OpenBCISimulator.prototype._syncUp = function() {
setTimeout(() => {
this.sendSyncSetPacket = true;
}, 12); // 3 packets later
};
OpenBCISimulator.prototype._printEOT = function () {
this.emit('data', new Buffer("$$$"));
};
OpenBCISimulator.prototype._printFailure = function () {
this.emit('data', new Buffer("Failure: "));
};
OpenBCISimulator.prototype._printSuccess = function () {
this.emit('data', new Buffer("Success: "));
};
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;
} 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;
factory.OpenBCISimulator = OpenBCISimulator;
}
util.inherits(OpenBCISimulatorFactory, EventEmitter);
+22 -3
Ver Arquivo
@@ -1,11 +1,11 @@
{
"name": "openbci",
"version": "1.3.3",
"version": "1.4.0",
"description": "The official Node.js SDK for the OpenBCI Biosensor Board.",
"main": "openBCIBoard",
"scripts": {
"start": "node index",
"test": "mocha test",
"test": "semistandard | snazzy && mocha test",
"test-cov": "istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec && codecov"
},
"keywords": [
@@ -27,14 +27,20 @@
"test": "test"
},
"devDependencies": {
"babel-eslint": "^7.0.0",
"chai": "^3.4.1",
"chai-as-promised": "^5.2.0",
"codecov": "^1.0.1",
"eslint-config-standard": "^6.2.0",
"eslint-plugin-promise": "^2.0.1",
"eslint-plugin-standard": "^2.0.1",
"istanbul": "^0.4.4",
"mocha": "^3.0.2",
"sandboxed-module": "^2.0.3",
"semistandard": "^9.0.0",
"sinon": "^1.17.2",
"sinon-chai": "^2.8.0"
"sinon-chai": "^2.8.0",
"snazzy": "^5.0.0"
},
"repository": {
"type": "git",
@@ -46,5 +52,18 @@
"homepage": "https://github.com/openbci/openbci_nodejs#readme",
"engines": {
"node": ">=4.0.0"
},
"semistandard": {
"globals": [
"describe",
"context",
"before",
"beforeEach",
"after",
"afterEach",
"it",
"expect",
"should"
]
}
}
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+1443 -1424
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+3022 -3036
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
-135
Ver Arquivo
@@ -1,135 +0,0 @@
// This takes a openbci-sdk factory and mocks the shit out of it in complete isolation per require of this file
"use strict";
var Hardware = function () {
this.bciBoard = {};
//this.mockBinding = {
// connect: this.connect.bind(this),
// disconnect: this.disconnect.bind(this),
// streamStart: this.streamStart.bind(this),
// streamStop: this.streamStop.bind(this),
// write: this.write.bind(this),
// softReset: this.softReset.bind(this),
// autoFindOpenBCIBoard: this.autoFindOpenBCIBoard.bind(this),
// simulatorEnable: this.simulatorEnable.bind(this),
// simulatorDisable: this.simulatorDisable.bind(this)
//};
};
Hardware.prototype.reset = function () {
this.bciBoard = {};
};
Hardware.prototype.createBoard = function () {
this.bciBoard = {
serial: null,
connected: false,
streaming: false,
isSimulating: false,
badPackets: 0,
bytesIn: 0,
commandsToWrite: 0,
sampleCount: 0
}
};
Hardware.prototype.connect = function (portName) {
return new Promise((resolve, reject) => {
if(!this.bciBoard) reject('Board does not exist - call hardware.createBoard() first');
this.bciBoard.connected = true;
this.bciBoard.serial = {
portName:portName,
baudRate:115200
};
resolve(this.bciBoard.serial);
});
};
Hardware.prototype.disconnect = function () {
return new Promise((resolve,reject) => {
if(!this.bciBoard) reject('Board does not exist - call hardware.createBoard() first');
this.bciBoard.connected = false;
this.bciBoard.serial = null;
});
};
Hardware.prototype.streamStart = function () {
return new Promise((resolve,reject) => {
if(!this.bciBoard) reject('Board does not exist - call hardware.createBoard() first');
this.bciBoard.streaming = true;
resolve();
});
};
Hardware.prototype.streamStop = function () {
return new Promise((resolve,reject) => {
if(!this.bciBoard) reject('Board does not exist - call hardware.createBoard() first');
this.bciBoard.streaming = false;
resolve();
});
};
Hardware.prototype.simulatorEnable = function () {
return new Promise((resolve,reject) => {
if(!this.bciBoard) reject('Board does not exist - call hardware.createBoard() first');
this.bciBoard.isSimulating = true;
resolve();
});
};
Hardware.prototype.simulatorDisable = function () {
return new Promise((resolve,reject) => {
if(!this.bciBoard) reject('Board does not exist - call hardware.createBoard() first');
this.bciBoard.isSimulating = false;
resolve();
});
};
Hardware.prototype.autoFindOpenBCIBoard = function () {
return new Promise((resolve,reject) => {
resolve('/dev/tty.usbserial-D069XXX');
});
};
Hardware.prototype.emitSample = function (data) {
return new Promise((resolve,reject) => {
if(!this.bciBoard) reject('Board does not exist - call hardware.createBoard() first');
this.bciBoard.isSimulating = false;
resolve();
});
};
Hardware.prototype.fakeData = function (data) {
//do something, not quite sure what yet...
};
var hardware = new Hardware();
var SandboxedModule = require('sandboxed-module');
var openBCIBoard = SandboxedModule.require('../openBCIBoard', {
requires: {
fs: {
read: hardware.fakeData.bind(hardware)
}
},
globals: {
process: {
platform: 'darwin',
nextTick: process.nextTick
}
}
});
openBCIBoard.hardware = hardware;
module.exports = openBCIBoard;