Comparar commits

..

33 Commits

Autor SHA1 Mensagem Data
AJ Keller 595c6dea5a Add: Coverage over sampleRate and numberOfChannels when info property is null 2016-12-05 10:48:17 -05:00
AJ Keller 89b5f35abc Add test for testSignal function 2016-12-05 10:48:17 -05:00
AJ Keller 9dd090df44 Add: test for print register settings 2016-12-05 10:47:52 -05:00
AJ Keller 8993a6c23b Enh: Drop factory Add: index.js Remove: Node 4 and 5 support 2016-12-05 10:47:52 -05:00
AJ Keller 888be5d60f Merge pull request #132 from aj-ptw/add-exp-python
Remove simulator line from python example
2016-12-05 10:29:56 -05:00
AJ Keller 57e6d9f7c2 Remove simulator line from python example 2016-12-05 10:26:39 -05:00
AJ Keller fb3d722fc8 Update package.json 2016-12-02 02:34:29 -05:00
AJ Keller 2728617126 Update readme.md 2016-12-02 02:34:09 -05:00
AJ Keller dd7639829a Update readme.md 2016-12-02 02:33:27 -05:00
AJ Keller b11775ecde Update README.md 2016-12-02 02:16:56 -05:00
AJ Keller f96cdd94ec Merge pull request #130 from aj-ptw/add-exp-python
Add exp python
2016-12-02 02:14:51 -05:00
AJ Keller 4ce630dc4c Add: Python example 2016-12-02 02:14:08 -05:00
AJ Keller 8557444c55 1.4.2 2016-12-02 00:25:07 -05:00
AJ Keller c2c75fe9d8 Merge pull request #129 from aj-ptw/add-exp-debug
Add debug and get streaming examples
2016-12-02 00:23:26 -05:00
AJ Keller 13d4f57003 Add debug and get streaming examples 2016-12-02 00:23:02 -05:00
AJ Keller b9d0a466f8 Update changelog.md 2016-11-16 01:41:53 -05:00
AJ Keller 4428040a06 Merge pull request #123 from OpenBCI/development
1.4.1
2016-11-16 01:40:52 -05:00
AJ Keller f7e5c4988e Merge pull request #124 from baffo32/1.4.0-writes-resolve-promises
Write Promises Resolve When Write Completes
2016-11-09 23:56:24 -05:00
Karl Semich d4799dd45a Improve coverage 2016-11-09 19:54:09 +00:00
AJ Keller 212db205f2 Merge pull request #125 from baffo32/no-parallel-sntp
Refrain from testing sntp in parallel
2016-11-09 14:29:03 -05:00
Karl Semich 47b2df5802 openBCIBoard.js: make use of write promises 2016-11-09 18:59:34 +00:00
Karl Semich d06b6101e3 Resolve write promises when writes complete. Fixes #91 2016-11-09 18:58:17 +00:00
Karl Semich eb0510be6f Refrain from testing sntp in parallel 2016-11-09 18:48:37 +00:00
AJ Keller c696d4f5ca Update changelog.md 2016-11-08 02:37:17 -05:00
AJ Keller 677517715a Merge pull request #122 from khwilson/fix-typos-in-readme
Some fixes to typos in the README
2016-11-08 02:35:33 -05:00
AJ Keller 600b1b2b28 Merge pull request #121 from khwilson/fix-channelSet-so-promise-only-resolves-one-value
Bugfix: channelSet always fails due to bad resolve()
2016-11-07 16:38:00 -05:00
Kevin Wilson 32d011d1f9 Bugfix: channelSet always fails due to bad resolve()
The `resolve` function of a Promise takes *exactly one* argument.
All further arguments are ignored. Thus, the newChannelSettingsObject
that was being returned by the channelSet Promise was ignored and
the corresponding value in openBCIBoard was always undefined.

Thus, any calls to channel set would actually break the openBCISample
code as the channelSettingsArray contained an `undefined`.

This fixes the bug.
2016-11-07 15:44:30 -05:00
Kevin Wilson ee6c50294c Some fixes to typos in the README
Contributing should be off of the `development` branch, `SNTP` misspelled,
and a broken link to the `Testing` section.
2016-11-07 15:44:08 -05:00
AJ Keller 34be4c9fe3 Update changelog.md 2016-11-02 21:53:37 -04:00
AJ Keller 57dc399742 Merge pull request #118 from baffo32/1.4.0-bugtests
Fragmented and Buffered Samples (#115)
2016-11-02 21:41:44 -04:00
Karl Semich 5d989f6ea4 lint fixes 2016-11-03 00:29:32 +00:00
AJ Keller 2eebde6053 Add strip to EOT function and tests. 2016-11-03 00:29:32 +00:00
AJ Keller f7f8517c28 Update verison number to 1.4.1 2016-11-01 15:43:23 -04:00
26 arquivos alterados com 4076 adições e 3007 exclusões
+2 -7
Ver Arquivo
@@ -1,12 +1,5 @@
language: node_js
node_js:
- "4.0"
- "4.1"
- "4.2"
- "4.3"
- "4.4"
- "4.5"
- "4.6"
- "5.11.0"
- "6.0"
- "6.1"
@@ -17,6 +10,8 @@ node_js:
- "6.6"
- "6.7"
- "6.8"
- "7.0"
- "7.1"
install:
- npm install --all
script:
+314 -298
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+45 -1
Ver Arquivo
@@ -1,3 +1,46 @@
# 2.0.0
### New Features
* `index.js` file allows for ES6 destructing
### Breaking Changes
* Change name of `OpenBCIBoard` to `Cyton` to follow new naming convention.
Simply change:
```ecmascript 6
const OpenBCIBoard = require('openbci').OpenBCIBoard;
const ourBoard = new OpenBCIBoard();
```
```ecmascript 6
const Cyton = require('openbci').Cyton;
const ourBoard = new Cyton();
```
* Major change to how board is initialized with removal of `factory` paradigm.
* Drop support for Node 4 and 5 due to lack of EMACS 6
### Bug Fixes
* Documentation error with `testSignal` function.
### Enhancements
* Add more tests for public API functions.
# 1.4.3
### New examples
* Add example of node to python
# 1.4.2
### New examples
* Add example of debug
* Add example of get streaming
# 1.4.1
### Bug Fixes
* Fixes bug where extra data after EOT (`$$$`) was dumped by preserving the poriton after the EOT for further decomposition.
* Fixes bug where any calls to channel set would actually break the openBCISample code as the channelSettingsArray contained an undefined.
* Writes promises resolve when they are actually sent over the serial port.
# 1.4.0
### New Features
@@ -22,6 +65,7 @@
* The `.streaming` property has been removed, replaced by `.isStreaming()`. Removed from docs.
* An error event will be emitted if sntp fails to initialize on construction
* The simulator will no longer communicate when disconnected
* Promises returned by writes will now only resolve after the write has been sent
### Bug Fixes
@@ -218,7 +262,7 @@ The second major release for the OpenBCI Node.js SDK brings major changes, impro
### Bug Fixes
* updates to README.me and comments to change ntp to sntp, because the two are similar, but not the same and we do not want to be misleading
* Extended [Stnp](https://www.npmjs.com/package/sntp) to main openBCIBoard.js
* Extended [Stnp](https://www.npmjs.com/package/sntp) to main openBCICyton.js
* Add `.sntpNow()` function to get ntp time.
# 0.3.1
+108
Ver Arquivo
@@ -0,0 +1,108 @@
/**
* This is an example of debugging the board. Thanks to Karl @baffo32
* On windows you should run with PowerShell not git bash.
* Install
* [nodejs](https://nodejs.org/en/)
*
* To run:
* change directory to this file `cd examples/debug`
* do `npm install`
* then `npm start`
*/
var stream = true;
var debug = true; // Pretty print any bytes in and out... it's amazing...
var verbose = true; // Adds verbosity to functions
var OpenBCIBoard = require('openbci').OpenBCIBoard;
var ourBoard = new OpenBCIBoard({
debug: debug,
verbose: verbose
});
ourBoard.autoFindOpenBCIBoard().then(portName => {
if (portName) {
/**
* Connect to the board with portName
* Only works if one board is plugged in
* 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 */
console.log('Unable to auto find OpenBCI board');
}
});
/**
* The board is ready to start streaming after the ready function is fired.
*/
var readyFunc = () => {
// Get the sample rate after 'ready'
sampleRate = ourBoard.sampleRate();
if (stream) {
ourBoard.streamStart()
.catch(err => {
console.log(`stream start: ${err}`);
});
}
};
var sampleFunc = sample => {
/**
* Checkout the README.md for all other API functions.
* We support every feature.
* */
};
// Subscribe to your functions
ourBoard.on('ready', readyFunc);
ourBoard.on('sample', sampleFunc);
function exitHandler (options, err) {
if (options.cleanup) {
if (verbose) console.log('clean');
/** Do additional clean up here */
}
if (err) console.log(err.stack);
if (options.exit) {
if (verbose) console.log('exit');
if (stream) {
ourBoard.streamStop().catch(console.log);
}
ourBoard.disconnect().catch(console.log);
}
}
if (process.platform === "win32") {
const rl = require("readline").createInterface({
input: process.stdin,
output: process.stdout
});
rl.on("SIGINT", function () {
process.emit("SIGINT");
});
}
// do something when app is closing
process.on('exit', exitHandler.bind(null, {
cleanup: true
}));
// catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, {
exit: true
}));
// catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {
exit: true
}));
+18
Ver Arquivo
@@ -0,0 +1,18 @@
{
"name": "debug",
"version": "1.0.0",
"description": "Debug example",
"main": "debug.js",
"scripts": {
"start": "node debug.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"debug"
],
"author": "AJ Keller",
"license": "MIT",
"dependencies": {
"openbci": "^1.4.1"
}
}
+87
Ver Arquivo
@@ -0,0 +1,87 @@
/**
* This is an example from the readme.md
* On windows you should run with PowerShell not git bash.
* Install
* [nodejs](https://nodejs.org/en/)
*
* To run:
* change directory to this file `cd examples/debug`
* do `npm install`
* then `npm start`
*/
var debug = false; // Pretty print any bytes in and out... it's amazing...
var verbose = true; // Adds verbosity to functions
var OpenBCIBoard = require('openbci').OpenBCIBoard;
var ourBoard = new OpenBCIBoard({
debug: debug,
verbose: verbose
});
ourBoard.autoFindOpenBCIBoard().then(portName => {
if (portName) {
/**
* Connect to the board with portName
* Only works if one board is plugged in
* i.e. ourBoard.connect(portName).....
*/
ourBoard.connect(portName) // Port name is a serial port name, see `.listPorts()`
.then(() => {
ourBoard.on('ready',() => {
ourBoard.streamStart();
ourBoard.on('sample',(sample) => {
/** Work with sample */
for (var i = 0; i < ourBoard.numberOfChannels(); i++) {
console.log("Channel " + (i + 1) + ": " + sample.channelData[i].toFixed(8) + " Volts.");
// prints to the console
// "Channel 1: 0.00001987 Volts."
// "Channel 2: 0.00002255 Volts."
// ...
// "Channel 8: -0.00001875 Volts."
}
});
});
});
} else {
/** Unable to auto find OpenBCI board */
console.log('Unable to auto find OpenBCI board');
}
});
function exitHandler (options, err) {
if (options.cleanup) {
if (verbose) console.log('clean');
/** Do additional clean up here */
}
if (err) console.log(err.stack);
if (options.exit) {
if (verbose) console.log('exit');
ourBoard.disconnect().catch(console.log);
}
}
if (process.platform === "win32") {
const rl = require("readline").createInterface({
input: process.stdin,
output: process.stdout
});
rl.on("SIGINT", function () {
process.emit("SIGINT");
});
}
// do something when app is closing
process.on('exit', exitHandler.bind(null, {
cleanup: true
}));
// catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, {
exit: true
}));
// catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {
exit: true
}));
+18
Ver Arquivo
@@ -0,0 +1,18 @@
{
"name": "get-streaming",
"version": "1.0.0",
"description": "Get streaming example",
"main": "getStreaming.js",
"scripts": {
"start": "node getStreaming.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"get"
],
"author": "AJ Keller",
"license": "MIT",
"dependencies": {
"openbci": "^1.4.1"
}
}
+117
Ver Arquivo
@@ -0,0 +1,117 @@
import json
import sys
import numpy as np
import time
import zmq
class Interface:
def __init__(self, verbose=False):
context = zmq.Context()
self._socket = context.socket(zmq.PAIR)
self._socket.connect("tcp://localhost:3004")
self.verbose = verbose
if self.verbose:
print "Client Ready!"
# Send a quick message to tell node process we are up and running
self.send(json.dumps({
'action': 'started',
'command': 'status',
'message': time.time()*1000.0
}))
def send(self, msg):
"""
Sends a message to TCP server
:param msg: str
A string to send to node TCP server, could be a JSON dumps...
:return: None
"""
if self.verbose:
print '<- out ' + msg
self._socket.send(msg)
return
def recv(self):
"""
Checks the ZeroMQ for data
:return: str
String of data
"""
return self._socket.recv()
class RingBuffer(np.ndarray):
"""A multidimensional ring buffer."""
def __new__(cls, input_array):
obj = np.asarray(input_array).view(cls)
return obj
def __array_finalize__(self, obj):
if obj is None:
return
def __array_wrap__(self, out_arr, context=None):
return np.ndarray.__array_wrap__(self, out_arr, context)
def append(self, x):
"""Adds element x to the ring buffer."""
x = np.asarray(x)
self[:, :-1] = self[:, 1:]
self[:, -1] = x
def main(argv):
nb_chan = 8
verbose = True
# Create a new python interface.
interface = Interface(verbose=verbose)
# Signal buffer
signal = RingBuffer(np.zeros((nb_chan + 1, 2500)))
while True:
msg = interface.recv()
try:
dicty = json.loads(msg)
action = dicty.get('action')
command = dicty.get('command')
message = dicty.get('message')
if command == 'sample':
if action == 'process':
# Do sample processing here
try:
if type(message) is not dict:
print "sample is not a dict", message
raise ValueError
# Get keys of sample
data = np.zeros(9)
data[:-1] = message.get('channelData')
data[-1] = message.get('timeStamp')
# Add data to end of ring buffer
signal.append(data)
print message.get('sampleNumber')
except ValueError as e:
print e
elif command == 'status':
if action == 'active':
interface.send(json.dumps({
'action': 'alive',
'command': 'status',
'message': time.time() * 1000.0
}))
except BaseException as e:
print e
if __name__ == '__main__':
main(sys.argv[1:])
+212
Ver Arquivo
@@ -0,0 +1,212 @@
/**
* This is an example from the readme.md
* On windows you should run with PowerShell not git bash.
* Install
* [nodejs](https://nodejs.org/en/)
*
* To run:
* change directory to this file `cd examples/debug`
* do `npm install`
* then `npm start`
*/
var OpenBCIBoard = require('openbci').OpenBCIBoard;
var port_pub = 'tcp://127.0.0.1:3004';
var zmq = require('zmq-prebuilt');
var socket = zmq.socket('pair');
var simulate = true; // Sends synthetic data
var debug = false; // Pretty print any bytes in and out... it's amazing...
var verbose = true; // Adds verbosity to functions
var ourBoard = new OpenBCIBoard({
// simulate: simulate, // Uncomment to see how it works with simulator!
simulatorFirmwareVersion: 'v2',
debug: debug,
verbose: verbose
});
var sampleRate = 250; // Default to 250, ALWAYS verify with a call to `.sampleRate()` after 'ready' event!
var timeSyncPossible = false;
var resyncPeriodMin = 1;
var secondsInMinute = 60;
var resyncPeriod = ourBoard.sampleRate() * resyncPeriodMin * secondsInMinute;
ourBoard.autoFindOpenBCIBoard().then(portName => {
if (portName) {
/**
* Connect to the board with portName
* i.e. ourBoard.connect(portName).....
*/
// Call to connect
ourBoard.connect(portName)
.then(() => {
ourBoard.on('ready', () => {
// 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 {
console.log('not able to time sync');
}
})
})
.catch(err => {
console.log(`connect: ${err}`);
});
} else {
/** Unable to auto find OpenBCI board */
console.log('Unable to auto find OpenBCI board');
}
});
var sampleFunc = sample => {
if (sample._count % resyncPeriod === 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}`);
} else {
sendToPython({
action: 'process',
command: 'sample',
message: sample
});
}
}
};
// Subscribe to your functions
ourBoard.on('sample', sampleFunc);
// ZMQ fun
socket.bind(port_pub, function (err) {
if (err) throw err;
console.log(`bound to ${port_pub}`);
});
/**
* Used to send a message to the Python process.
* @param {Object} interProcessObject The standard inter-process object.
* @return {None}
*/
var sendToPython = (interProcessObject, verbose) => {
if (verbose) {
console.log(`<- out ${JSON.stringify(interProcessObject)}`);
}
if (socket) {
socket.send(JSON.stringify(interProcessObject));
}
};
var receiveFromPython = (raw_data) => {
try {
let body = JSON.parse(raw_data); // five because `resp `
processInterfaceObject(body);
} catch (err) {
console.log('in -> ' + 'bad json');
}
};
socket.on('message', receiveFromPython);
var sendStatus = () => {
sendToPython({'action': 'active', 'message': 'ready', 'command': 'status'}, true);
};
sendStatus();
/**
* Process an incoming message
* @param {String} body A stringify JSON object that shall be parsed.
* @return {None}
*/
var processInterfaceObject = (body) => {
switch (body.command) {
case 'status':
processStatus(body);
break;
default:
unrecognizedCommand(body);
break;
}
};
/**
* Used to process a status related command from TCP IPC.
* @param {Object} body
* @return {None}
*/
var processStatus = (body) => {
switch (body.action) {
case 'started':
console.log(`python started @ ${body.message}ms`);
break;
case 'alive':
console.log(`python duplex communication test completed @ ${body.message}ms`);
break;
default:
unrecognizedCommand(body);
break;
}
};
function unrecognizedCommand (body) {
console.log(`unrecognizedCommand ${body}`);
}
function exitHandler (options, err) {
if (options.cleanup) {
if (verbose) console.log('clean');
/** Do additional clean up here */
}
if (err) console.log(err.stack);
if (options.exit) {
if (verbose) console.log('exit');
ourBoard.disconnect().catch(console.log);
}
}
if (process.platform === "win32") {
const rl = require("readline").createInterface({
input: process.stdin,
output: process.stdout
});
rl.on("SIGINT", function () {
process.emit("SIGINT");
});
}
// do something when app is closing
process.on('exit', exitHandler.bind(null, {
cleanup: true
}));
// catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, {
exit: true
}));
// catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {
exit: true
}));
+29
Ver Arquivo
@@ -0,0 +1,29 @@
{
"name": "python",
"version": "1.0.0",
"description": "node to python example",
"main": "index.js",
"scripts": {
"start": "concurrently --kill-others \"python handoff.py\" \"node index.js\"",
"start-node": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"python",
"openbci",
"node"
],
"author": "AJ Keller",
"license": "MIT",
"dependencies": {
"openbci": "^1.4.2",
"zmq-prebuilt": "^2.1.0"
},
"devEngines": {
"node": "<=6.x",
"npm": ">=3.x"
},
"devDependencies": {
"concurrently": "^3.1.0"
}
}
+40
Ver Arquivo
@@ -0,0 +1,40 @@
# OpenBCI Node SDK to Python
## About
Written to end the struggles of python researchers and developers. ~ written with love by [Push The World!](http://www.pushtheworldllc.com)
This module has every feature available on the OpenBCI Board.
## Prerequisites
* [Python 2.7](https://www.python.org/downloads/)
* [ZeroMQ](http://zeromq.org/bindings:python)
```py
pip install pyzmq
```
* [Node.js LTS](https://nodejs.org/en/)
## Installation
For Python 2.7 do:
```bash
python setup.py install
```
For Node:
```bash
npm install
```
## Running
```
npm start
```
For running just the node, for example if you were running the python in a separate ide and debugging, it's useful.
```python
npm run start-node
```
## Contributing
Please PR if you have code to contribute!
+12
Ver Arquivo
@@ -0,0 +1,12 @@
from setuptools import setup, find_packages
setup(name='openbci-node-python',
version='0.0.1',
description='Node to Python the right way',
url='',
author='AJ Keller',
author_email='pushtheworldllc@gmail.com',
license='MIT',
packages=find_packages(),
install_requires=['numpy', 'pyzmq'],
zip_safe=False)
+39
Ver Arquivo
@@ -29,6 +29,7 @@ ourBoard.autoFindOpenBCIBoard().then(portName => {
});
} else {
/** Unable to auto find OpenBCI board */
console.log('Unable to auto find OpenBCI board');
}
});
@@ -86,3 +87,41 @@ var sampleFunc = sample => {
// Subscribe to your functions
ourBoard.on('ready', readyFunc);
ourBoard.on('sample', sampleFunc);
function exitHandler (options, err) {
if (options.cleanup) {
if (verbose) console.log('clean');
/** Do additional clean up here */
}
if (err) console.log(err.stack);
if (options.exit) {
if (verbose) console.log('exit');
ourBoard.disconnect().catch(console.log);
}
}
if (process.platform === "win32") {
const rl = require("readline").createInterface({
input: process.stdin,
output: process.stdout
});
rl.on("SIGINT", function () {
process.emit("SIGINT");
});
}
// do something when app is closing
process.on('exit', exitHandler.bind(null, {
cleanup: true
}));
// catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, {
exit: true
}));
// catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {
exit: true
}));
+2
Ver Arquivo
@@ -0,0 +1,2 @@
module.exports.Cyton = require('./openBCICyton');
module.exports.Constants = require('./openBCIConstants');
-2402
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+17 -3
Ver Arquivo
@@ -203,6 +203,7 @@ const obciSimulatorFragmentationNone = 'none';
/** Possible Sample Rates */
const obciSampleRate125 = 125;
const obciSampleRate200 = 200;
const obciSampleRate250 = 250;
/** Max sample number */
@@ -232,9 +233,13 @@ const obciByteStart = 0xA0;
const obciByteStop = 0xC0;
/** Errors */
const errorNobleAlreadyScanning = 'Scan already under way';
const errorNobleNotAlreadyScanning = 'No scan started';
const errorNobleNotInPoweredOnState = 'Please turn blue tooth on.';
const errorInvalidByteLength = 'Invalid Packet Byte Length';
const errorInvalidByteStart = 'Invalid Start Byte';
const errorInvalidByteStop = 'Invalid Stop Byte';
const errorInvalidType = 'Invalid Type';
const errorTimeSyncIsNull = "'this.sync.curSyncObj' must not be null";
const errorTimeSyncNoComma = 'Missed the time sync sent confirmation. Try sync again';
const errorUndefinedOrNullInput = 'Undefined or Null Input';
@@ -337,6 +342,7 @@ const obciEmitterClose = 'close';
const obciEmitterDroppedPacket = 'droppedPacket';
const obciEmitterError = 'error';
const obciEmitterImpedanceArray = 'impedanceArray';
const obciEmitterMessage = 'message';
const obciEmitterQuery = 'query';
const obciEmitterRawDataPacket = 'rawDataPacket';
const obciEmitterReady = 'ready';
@@ -749,6 +755,7 @@ module.exports = {
},
/** Possible Sample Rates */
OBCISampleRate125: obciSampleRate125,
OBCISampleRate200: obciSampleRate200,
OBCISampleRate250: obciSampleRate250,
/** Max sample number */
OBCISampleNumberMax: obciSampleNumberMax,
@@ -758,9 +765,13 @@ module.exports = {
OBCIByteStart: obciByteStart,
OBCIByteStop: obciByteStop,
/** Errors */
OBCIErrorNobleAlreadyScanning: errorNobleAlreadyScanning,
OBCIErrorNobleNotAlreadyScanning: errorNobleNotAlreadyScanning,
OBCIErrorNobleNotInPoweredOnState: errorNobleNotInPoweredOnState,
OBCIErrorInvalidByteLength: errorInvalidByteLength,
OBCIErrorInvalidByteStart: errorInvalidByteStart,
OBCIErrorInvalidByteStop: errorInvalidByteStop,
OBCIErrorInvalidType: errorInvalidType,
OBCIErrorTimeSyncIsNull: errorTimeSyncIsNull,
OBCIErrorTimeSyncNoComma: errorTimeSyncNoComma,
OBCIErrorUndefinedOrNullInput: errorUndefinedOrNullInput,
@@ -896,6 +907,7 @@ module.exports = {
OBCIEmitterDroppedPacket: obciEmitterDroppedPacket,
OBCIEmitterError: obciEmitterError,
OBCIEmitterImpedanceArray: obciEmitterImpedanceArray,
OBCIEmitterMessage: obciEmitterMessage,
OBCIEmitterQuery: obciEmitterQuery,
OBCIEmitterRawDataPacket: obciEmitterRawDataPacket,
OBCIEmitterReady: obciEmitterReady,
@@ -926,7 +938,10 @@ module.exports = {
* false -> Disconnect all N inputs from SRB1 (default))
* Select to connect (true) all channels' N inputs to SRB1. This effects all pins,
* and disconnects all N inputs from the ADC.
* @returns {Promise} resolves array of commands to be sent, rejects on bad input or no board
* @returns {Promise} resolves {commandArray: array of commands to be sent,
newChannelSettingsObject: an updated channel settings object
to be stored in openBCIBoard.channelSettingsArray},
rejects on bad input or no board
*/
function channelSetter (channelNumber, powerDown, gain, inputType, bias, srb2, srb1) {
// Used to store and assemble the commands
@@ -991,8 +1006,7 @@ function channelSetter (channelNumber, powerDown, gain, inputType, bias, srb2, s
cmdSrb1,
obciChannelCmdLatch
];
// console.log(outputArray)
resolve(outputArray, newChannelSettingsObject);
resolve({commandArray: outputArray, newChannelSettingsObject: newChannelSettingsObject});
});
});
}
+2351
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+30 -4
Ver Arquivo
@@ -1,7 +1,7 @@
'use strict';
var gaussian = require('gaussian');
var k = require('./openBCIConstants');
var StreamSearch = require('streamsearch');
const gaussian = require('gaussian');
const k = require('./openBCIConstants');
const StreamSearch = require('streamsearch');
/** Constants for interpreting the EEG data */
// Reference voltage for ADC in ADS1299.
@@ -274,7 +274,7 @@ var sampleModule = {
return (prefix << 16) | (twoByteBuffer[0] << 8) | twoByteBuffer[1];
},
interpret24bitAsInt32: threeByteBuffer => {
interpret24bitAsInt32: (threeByteBuffer) => {
var prefix = 0;
if (threeByteBuffer[0] > 127) {
@@ -522,6 +522,7 @@ var sampleModule = {
makeTailByteFromPacketType,
isStopByte,
newSyncObject,
stripToEOTBuffer,
/**
* @description Checks to make sure the previous sample number is one less
* then the new sample number. Takes into account sample numbers wrapping
@@ -1111,6 +1112,31 @@ function isSuccessInBuffer (dataBuffer) {
return s.matches >= 1;
}
/**
* @description Used to slice a buffer for the EOT '$$$'.
* @param dataBuffer {Buffer} - The buffer of some length to parse
* @returns {Buffer} - The remaining buffer.
*/
function stripToEOTBuffer (dataBuffer) {
let indexOfEOT = dataBuffer.indexOf(k.OBCIParseEOT);
if (indexOfEOT > 0) {
indexOfEOT += k.OBCIParseEOT.length;
} else {
return dataBuffer;
}
if (indexOfEOT < dataBuffer.byteLength) {
if (k.getVersionNumber(process.version) >= 6) {
// From introduced in node version 6.x.x
return Buffer.from(dataBuffer.slice(indexOfEOT));
} else {
return new Buffer(dataBuffer.slice(indexOfEOT));
}
} else {
return null;
}
}
/**
* @description Used to parse a buffer for the `,` character that is acked back after a time sync request is sent
* @param dataBuffer {Buffer} - The buffer of some length to parse
+4 -2
Ver Arquivo
@@ -101,11 +101,13 @@ function OpenBCISimulatorFactory () {
// TODO: upgrade from old-style streams to stream.Duplex or stream.Transform
util.inherits(OpenBCISimulator, stream.Stream);
OpenBCISimulator.prototype.flush = function () {
OpenBCISimulator.prototype.flush = function (callback) {
this.outputBuffered = 0;
clearTimeout(this.outputLoopHandle);
this.outputLoopHandle = null;
if (callback) callback();
};
OpenBCISimulator.prototype.isOpen = function () {
@@ -118,7 +120,7 @@ function OpenBCISimulatorFactory () {
if (size > this.outputBuffered) size = this.outputBuffered;
// buffer is copied because presently openBCIBoard.js reuses it
// buffer is copied because presently openBCICyton.js reuses it
var outBuffer = new Buffer(this.outputBuffer.slice(0, size));
this.outputBuffer.copy(this.outputBuffer, 0, size, this.outputBuffered);
+35
Ver Arquivo
@@ -0,0 +1,35 @@
module.exports = {
debugBytes
};
/**
* @description Output passed bytes on the console as a hexdump, if enabled
* @param prefix - label to show to the left of bytes
* @param data - bytes to output, a buffer or string
* @private
*/
function debugBytes (prefix, data) {
if (typeof data === 'string') data = new Buffer(data);
console.log('Debug bytes:');
for (var j = 0; j < data.length;) {
var hexPart = '';
var ascPart = '';
for (var end = Math.min(data.length, j + 16); j < end; ++j) {
var byt = data[j];
var hex = ('0' + byt.toString(16)).slice(-2);
hexPart += (((j & 0xf) === 0x8) ? ' ' : ' '); // puts an extra space 8 bytes in
hexPart += hex;
var asc = (byt >= 0x20 && byt < 0x7f) ? String.fromCharCode(byt) : '.';
ascPart += asc;
}
// pad to fixed width for alignment
hexPart = (hexPart + ' ').substring(0, 3 * 17);
console.log(prefix + ' ' + hexPart + '|' + ascPart + '|');
}
}
+6 -3
Ver Arquivo
@@ -1,8 +1,8 @@
{
"name": "openbci",
"version": "1.4.0",
"version": "2.0.0",
"description": "The official Node.js SDK for the OpenBCI Biosensor Board.",
"main": "openBCIBoard",
"main": "index.js",
"scripts": {
"start": "node index",
"test": "semistandard | snazzy && mocha test",
@@ -16,10 +16,12 @@
"license": "MIT",
"dependencies": {
"buffer-equal": "^1.0.0",
"clone": "^2.0.0",
"gaussian": "^1.0.0",
"lodash": "^4.16.6",
"mathjs": "^3.3.0",
"performance-now": "^0.2.0",
"serialport": "4.0.1",
"serialport": "4.0.6",
"sntp": "^2.0.0",
"streamsearch": "^0.1.2"
},
@@ -53,6 +55,7 @@
"semistandard": {
"globals": [
"describe",
"xdescribe",
"context",
"before",
"beforeEach",
+249 -57
Ver Arquivo
@@ -764,6 +764,9 @@ describe('OpenBCIConstants', function () {
it('should be 125', function () {
assert.equal(125, k.OBCISampleRate125);
});
it('should be 250', function () {
assert.equal(200, k.OBCISampleRate200);
});
it('should be 250', function () {
assert.equal(250, k.OBCISampleRate250);
});
@@ -792,32 +795,60 @@ describe('OpenBCIConstants', function () {
describe('channel input selection works', function () {
// this.timeout(5000)
it('channel 2', function (done) {
k.getChannelSetter(2, false, 24, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[1].should.equal('2');
k.getChannelSetter(2, false, 24, 'normal', true, true, false).then(function (val) {
val.commandArray[1].should.equal('2');
val.newChannelSettingsObject.channelNumber.should.equal(2);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('channel 5', function (done) {
k.getChannelSetter(5, false, 24, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[1].should.equal('5');
k.getChannelSetter(5, false, 24, 'normal', true, true, false).then(function (val) {
val.commandArray[1].should.equal('5');
val.newChannelSettingsObject.channelNumber.should.equal(5);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('channel 9', function (done) {
k.getChannelSetter(9, false, 24, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[1].should.equal('Q');
k.getChannelSetter(9, false, 24, 'normal', true, true, false).then(function (val) {
val.commandArray[1].should.equal('Q');
val.newChannelSettingsObject.channelNumber.should.equal(9);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('channel 15', function (done) {
k.getChannelSetter(15, false, 24, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[1].should.equal('U');
k.getChannelSetter(15, false, 24, 'normal', true, true, false).then(function (val) {
val.commandArray[1].should.equal('U');
val.newChannelSettingsObject.channelNumber.should.equal(15);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
@@ -832,16 +863,30 @@ describe('OpenBCIConstants', function () {
});
describe('power selection works', function () {
it('on', function (done) {
k.getChannelSetter(1, false, 24, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[2].should.equal('0');
k.getChannelSetter(1, false, 24, 'normal', true, true, false).then(function (val) {
val.commandArray[2].should.equal('0');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('off', function (done) {
k.getChannelSetter(1, true, 24, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[2].should.equal('1');
k.getChannelSetter(1, true, 24, 'normal', true, true, false).then(function (val) {
val.commandArray[2].should.equal('1');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(true);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
@@ -853,56 +898,105 @@ describe('OpenBCIConstants', function () {
});
describe('gain selection works', function () {
it('1x', function (done) {
k.getChannelSetter(1, false, 1, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[3].should.equal('0');
k.getChannelSetter(1, false, 1, 'normal', true, true, false).then(function (val) {
val.commandArray[3].should.equal('0');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(1);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('2x', function (done) {
k.getChannelSetter(1, false, 2, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[3].should.equal('1');
k.getChannelSetter(1, false, 2, 'normal', true, true, false).then(function (val) {
val.commandArray[3].should.equal('1');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(2);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('4x', function (done) {
k.getChannelSetter(1, false, 4, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[3].should.equal('2');
k.getChannelSetter(1, false, 4, 'normal', true, true, false).then(function (val) {
val.commandArray[3].should.equal('2');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(4);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('6x', function (done) {
k.getChannelSetter(1, false, 6, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[3].should.equal('3');
k.getChannelSetter(1, false, 6, 'normal', true, true, false).then(function (val) {
val.commandArray[3].should.equal('3');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(6);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('8x', function (done) {
k.getChannelSetter(1, false, 8, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[3].should.equal('4');
k.getChannelSetter(1, false, 8, 'normal', true, true, false).then(function (val) {
val.commandArray[3].should.equal('4');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(8);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('12x', function (done) {
k.getChannelSetter(1, false, 12, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[3].should.equal('5');
k.getChannelSetter(1, false, 12, 'normal', true, true, false).then(function (val) {
val.commandArray[3].should.equal('5');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(12);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('24x', function (done) {
k.getChannelSetter(1, false, 24, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[3].should.equal('6');
k.getChannelSetter(1, false, 24, 'normal', true, true, false).then(function (val) {
val.commandArray[3].should.equal('6');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
@@ -917,64 +1011,120 @@ describe('OpenBCIConstants', function () {
});
describe('input type', function () {
it('normal', function (done) {
k.getChannelSetter(1, false, 24, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[4].should.equal('0');
k.getChannelSetter(1, false, 24, 'normal', true, true, false).then(function (val) {
val.commandArray[4].should.equal('0');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('shorted', function (done) {
k.getChannelSetter(1, false, 24, 'shorted', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[4].should.equal('1');
k.getChannelSetter(1, false, 24, 'shorted', true, true, false).then(function (val) {
val.commandArray[4].should.equal('1');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('shorted');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('biasMethod', function (done) {
k.getChannelSetter(1, false, 24, 'biasMethod', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[4].should.equal('2');
k.getChannelSetter(1, false, 24, 'biasMethod', true, true, false).then(function (val) {
val.commandArray[4].should.equal('2');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('biasMethod');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('mvdd', function (done) {
k.getChannelSetter(1, false, 24, 'mvdd', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[4].should.equal('3');
k.getChannelSetter(1, false, 24, 'mvdd', true, true, false).then(function (val) {
val.commandArray[4].should.equal('3');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('mvdd');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('temp', function (done) {
k.getChannelSetter(1, false, 24, 'temp', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[4].should.equal('4');
k.getChannelSetter(1, false, 24, 'temp', true, true, false).then(function (val) {
val.commandArray[4].should.equal('4');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('temp');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('testsig', function (done) {
k.getChannelSetter(1, false, 24, 'testSig', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[4].should.equal('5');
k.getChannelSetter(1, false, 24, 'testSig', true, true, false).then(function (val) {
val.commandArray[4].should.equal('5');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('testSig');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('biasDrp', function (done) {
k.getChannelSetter(1, false, 24, 'biasDrp', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[4].should.equal('6');
k.getChannelSetter(1, false, 24, 'biasDrp', true, true, false).then(function (val) {
val.commandArray[4].should.equal('6');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('biasDrp');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('biasDrn', function (done) {
k.getChannelSetter(1, false, 24, 'biasDrn', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[4].should.equal('7');
k.getChannelSetter(1, false, 24, 'biasDrn', true, true, false).then(function (val) {
val.commandArray[4].should.equal('7');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('biasDrn');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
@@ -989,16 +1139,30 @@ describe('OpenBCIConstants', function () {
});
describe('bias selection works', function () {
it('Include', function (done) {
k.getChannelSetter(1, false, 24, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[5].should.equal('1');
k.getChannelSetter(1, false, 24, 'normal', true, true, false).then(function (val) {
val.commandArray[5].should.equal('1');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('Remove', function (done) {
k.getChannelSetter(1, false, 24, 'normal', false, true, false).then(function (arrayOfCommands) {
arrayOfCommands[5].should.equal('0');
k.getChannelSetter(1, false, 24, 'normal', false, true, false).then(function (val) {
val.commandArray[5].should.equal('0');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(false);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
@@ -1010,16 +1174,30 @@ describe('OpenBCIConstants', function () {
});
describe('SRB2 selection works', function () {
it('Connect', function (done) {
k.getChannelSetter(1, false, 24, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[6].should.equal('1');
k.getChannelSetter(1, false, 24, 'normal', true, true, false).then(function (val) {
val.commandArray[6].should.equal('1');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
});
});
it('Disconnect', function (done) {
k.getChannelSetter(1, false, 24, 'normal', true, false, false).then(function (arrayOfCommands) {
arrayOfCommands[6].should.equal('0');
k.getChannelSetter(1, false, 24, 'normal', true, false, false).then(function (val) {
val.commandArray[6].should.equal('0');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(false);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
@@ -1031,16 +1209,30 @@ describe('OpenBCIConstants', function () {
});
describe('SRB1 selection works', function () {
it('Connect', function (done) {
k.getChannelSetter(1, false, 24, 'normal', true, true, true).then(function (arrayOfCommands) {
arrayOfCommands[7].should.equal('1');
k.getChannelSetter(1, false, 24, 'normal', true, true, true).then(function (val) {
val.commandArray[7].should.equal('1');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(true);
done();
}).catch(function (err) {
done(err);
});
});
it('Disconnect', function (done) {
k.getChannelSetter(1, false, 24, 'normal', true, true, false).then(function (arrayOfCommands) {
arrayOfCommands[7].should.equal('0');
k.getChannelSetter(1, false, 24, 'normal', true, true, false).then(function (val) {
val.commandArray[7].should.equal('0');
val.newChannelSettingsObject.channelNumber.should.equal(1);
val.newChannelSettingsObject.powerDown.should.equal(false);
val.newChannelSettingsObject.gain.should.equal(24);
val.newChannelSettingsObject.inputType.should.equal('normal');
val.newChannelSettingsObject.bias.should.equal(true);
val.newChannelSettingsObject.srb2.should.equal(true);
val.newChannelSettingsObject.srb1.should.equal(false);
done();
}).catch(function (err) {
done(err);
@@ -1257,6 +1449,9 @@ describe('OpenBCIConstants', function () {
it('Event Emitter Impedance Array', function () {
assert.equal('impedanceArray', k.OBCIEmitterImpedanceArray);
});
it('Event Emitter Message', function () {
assert.equal('message', k.OBCIEmitterMessage);
});
it('Event Emitter Query', function () {
assert.equal('query', k.OBCIEmitterQuery);
});
@@ -1270,7 +1465,4 @@ describe('OpenBCIConstants', function () {
assert.equal('sample', k.OBCIEmitterSample);
});
});
describe('Errors', function () {
});
});
+80 -35
Ver Arquivo
@@ -2,28 +2,28 @@
* Created by ajk on 12/15/15.
*/
'use strict';
var bluebirdChecks = require('./bluebirdChecks');
var openBCISample = require('../openBCISample');
var chai = require('chai');
var expect = chai.expect;
var assert = chai.assert;
var should = chai.should(); // eslint-disable-line no-unused-vars
const bluebirdChecks = require('./bluebirdChecks');
const openBCISample = require('../openBCISample');
const chai = require('chai');
const expect = chai.expect;
const assert = chai.assert;
const should = chai.should(); // eslint-disable-line no-unused-vars
var chaiAsPromised = require('chai-as-promised');
var sinonChai = require('sinon-chai');
const chaiAsPromised = require('chai-as-promised');
const sinonChai = require('sinon-chai');
chai.use(chaiAsPromised);
chai.use(sinonChai);
var bufferEqual = require('buffer-equal');
const bufferEqual = require('buffer-equal');
var k = openBCISample.k;
const k = require('../openBCIConstants');
const defaultChannelSettingsArray = k.channelSettingsArrayInit(k.OBCINumberOfChannelsDefault);
var sampleBuf = openBCISample.samplePacket();
const sampleBuf = openBCISample.samplePacket();
var accelArray;
let accelArray;
var channelScaleFactor = 4.5 / 24 / (Math.pow(2, 23) - 1);
const channelScaleFactor = 4.5 / 24 / (Math.pow(2, 23) - 1);
describe('openBCISample', function () {
beforeEach(function () {
@@ -600,28 +600,6 @@ describe('openBCISample', function () {
expect(sample.timeStamp).to.equal(time + timeOffset);
});
});
describe('#interpret24bitAsInt32', function () {
it('converts a small positive number', function () {
var buf1 = new Buffer([0x00, 0x06, 0x90]); // 0x000690 === 1680
var num = openBCISample.interpret24bitAsInt32(buf1);
assert.equal(num, 1680);
});
it('converts a large positive number', function () {
var buf1 = new Buffer([0x02, 0xC0, 0x01]); // 0x02C001 === 180225
var num = openBCISample.interpret24bitAsInt32(buf1);
assert.equal(num, 180225);
});
it('converts a small negative number', function () {
var buf1 = new Buffer([0xFF, 0xFF, 0xFF]); // 0xFFFFFF === -1
var num = openBCISample.interpret24bitAsInt32(buf1);
num.should.be.approximately(-1, 1);
});
it('converts a large negative number', function () {
var buf1 = new Buffer([0x81, 0xA1, 0x01]); // 0x81A101 === -8281855
var num = openBCISample.interpret24bitAsInt32(buf1);
num.should.be.approximately(-8281855, 1);
});
});
describe('#interpret16bitAsInt32', function () {
it('converts a small positive number', function () {
var buf1 = new Buffer([0x06, 0x90]); // 0x0690 === 1680
@@ -644,6 +622,28 @@ describe('openBCISample', function () {
assert.equal(num, -32351);
});
});
describe('#interpret24bitAsInt32', function () {
it('converts a small positive number', function () {
var buf1 = new Buffer([0x00, 0x06, 0x90]); // 0x000690 === 1680
var num = openBCISample.interpret24bitAsInt32(buf1);
assert.equal(num, 1680);
});
it('converts a large positive number', function () {
var buf1 = new Buffer([0x02, 0xC0, 0x01]); // 0x02C001 === 180225
var num = openBCISample.interpret24bitAsInt32(buf1);
assert.equal(num, 180225);
});
it('converts a small negative number', function () {
var buf1 = new Buffer([0xFF, 0xFF, 0xFF]); // 0xFFFFFF === -1
var num = openBCISample.interpret24bitAsInt32(buf1);
num.should.be.approximately(-1, 1);
});
it('converts a large negative number', function () {
var buf1 = new Buffer([0x81, 0xA1, 0x01]); // 0x81A101 === -8281855
var num = openBCISample.interpret24bitAsInt32(buf1);
num.should.be.approximately(-8281855, 1);
});
});
describe('#floatTo3ByteBuffer', function () {
it('converts random floats to a 3-byte buffer', function () {
var generateSample = openBCISample.randomSample(k.OBCINumberOfChannelsDefault, k.OBCISampleRate250);
@@ -1210,6 +1210,51 @@ $$$`);
expect(openBCISample.droppedPacketCheck(previous, current)).to.be.null;
});
});
describe('#stripToEOTBuffer', function () {
it('should return the buffer if no EOT', function () {
let buf = null;
if (k.getVersionNumber(process.version) >= 6) {
// From introduced in node version 6.x.x
buf = Buffer.from('tacos are delicious');
} else {
buf = new Buffer('tacos are delicious');
}
expect(openBCISample.stripToEOTBuffer(buf).toString()).to.equal(buf.toString());
});
it('should slice the buffer after eot $$$', function () {
let bufPre = null;
let eotBuf = null;
let bufPost = null;
if (k.getVersionNumber(process.version) >= 6) {
// From introduced in node version 6.x.x
bufPre = Buffer.from('tacos are delicious');
eotBuf = Buffer.from(k.OBCIParseEOT);
bufPost = Buffer.from('tacos');
} else {
bufPre = new Buffer('tacos are delicious');
eotBuf = new Buffer(k.OBCIParseEOT);
bufPost = new Buffer('tacos');
}
let totalBuf = Buffer.concat([bufPre, eotBuf, bufPost]);
expect(openBCISample.stripToEOTBuffer(totalBuf).toString()).to.equal(bufPost.toString());
});
it('should return null if nothing left', function () {
let bufPre = null;
let eotBuf = null;
if (k.getVersionNumber(process.version) >= 6) {
// From introduced in node version 6.x.x
bufPre = Buffer.from('tacos are delicious');
eotBuf = Buffer.from(k.OBCIParseEOT);
} else {
bufPre = new Buffer('tacos are delicious');
eotBuf = new Buffer(k.OBCIParseEOT);
}
let totalBuf = Buffer.concat([bufPre, eotBuf]);
expect(openBCISample.stripToEOTBuffer(totalBuf)).to.equal(null);
});
});
});
describe('#goertzelProcessSample', function () {
@@ -1,13 +1,13 @@
'use strict';
var bluebirdChecks = require('./bluebirdChecks');
var chai = require('chai');
var should = chai.should(); // eslint-disable-line no-unused-vars
var openBCIBoard = require('../openBCIBoard');
var openBCISample = openBCIBoard.OpenBCISample;
var k = openBCISample.k;
const bluebirdChecks = require('./bluebirdChecks');
const chai = require('chai');
const should = chai.should(); // eslint-disable-line no-unused-vars
const Cyton = require('../openBCICyton');
const openBCISample = require('../openBCISample');
const k = openBCISample.k;
var chaiAsPromised = require('chai-as-promised');
var sinonChai = require('sinon-chai');
const chaiAsPromised = require('chai-as-promised');
const sinonChai = require('sinon-chai');
chai.use(chaiAsPromised);
chai.use(sinonChai);
@@ -16,7 +16,7 @@ describe('#impedanceTesting', function () {
this.timeout(20000);
before(function (done) {
ourBoard = new openBCIBoard.OpenBCIBoard({
ourBoard = new Cyton({
verbose: true,
simulatorFragmentation: k.OBCISimulatorFragmentationRandom
});
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+10 -10
Ver Arquivo
@@ -1,13 +1,13 @@
'use strict';
var bluebirdChecks = require('./bluebirdChecks');
var bufferEqual = require('buffer-equal');
var chai = require('chai');
var chaiAsPromised = require(`chai-as-promised`);
var expect = chai.expect;
var should = chai.should(); // eslint-disable-line no-unused-vars
var openBCISimulator = require('../openBCISimulator');
var openBCISample = require('../openBCISample');
var k = openBCISample.k;
const bluebirdChecks = require('./bluebirdChecks');
const bufferEqual = require('buffer-equal');
const chai = require('chai');
const chaiAsPromised = require(`chai-as-promised`);
const expect = chai.expect;
const should = chai.should(); // eslint-disable-line no-unused-vars
const openBCISimulator = require('../openBCISimulator');
const openBCISample = require('../openBCISample');
const k = require('../openBCIConstants');
chai.use(chaiAsPromised);
@@ -667,7 +667,7 @@ describe('openBCISimulator', function () {
bufferSize: bufferSize,
latencyTime: 1000
});
simulator.on('data', function (buffer) {
simulator.once('data', function (buffer) {
expect(buffer.length).to.equal(bufferSize);
done();
});