Comparar commits

...

83 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
AJ Keller d4f62ef382 Merge pull request #96 from OpenBCI/1.4.0
1.4.0
2016-10-31 19:49:39 -04:00
AJ Keller c4e29bbaa7 Merge pull request #117 from aj-ptw/fix-promise-data-processing
Fix promise data processing
2016-10-31 19:25:15 -04:00
AJ Keller f553cdea35 Fix: Remove promise functions from all internal data processing events. 2016-10-31 19:14:24 -04:00
AJ Keller 25c7871fec Merge pull request #111 from baffo32/1.4.x-socket-close-resources
Fix connection-related leaks and inconsistencies
2016-10-30 21:58:45 -04:00
Karl Semich c2097670e7 Use bluebird to detect runaway promises and timing events.
Plug most runaway tasks, and some other issues, raised by the new infrastructure.
2016-10-31 00:35:59 +00:00
Karl Semich cfb8071a9d Improvements for SNTP robustness and occasional test failures
Also added an unrelated test to improve coverage
2016-10-31 00:26:10 +00:00
Karl Semich 22aca53dac New API functions: .isConnected() .isStreaming()
All checks for connection state are normalized to use it.

The name `.connected()` may have been more consistent with the rest of
the library, but it would incorrectly evaluate to true in code that
used the old, undocumented `.connected` field, generating hard-to-find
bugs.  So `isConnected()` was chosen to avoid that situation.
2016-10-31 00:04:36 +00:00
Karl Semich 9467d8a052 Add unified _disconnected() function to handle serial cleanup
also mark _reset function which sounds important but does nothing
2016-10-31 00:01:26 +00:00
Karl Semich b6ef09c220 Add tests verifying connection/disconnection state 2016-10-30 23:59:49 +00:00
AJ Keller 238d4cc119 contributing update (#110)
* Update README.md
2016-10-22 22:20:14 -04:00
AJ Keller c59cd18cf4 Merge pull request #107 from baffo32/1.4.x-debugging-packet-dump
Added a debug option to dump serial traffic
2016-10-21 10:15:32 -04:00
Karl Semich 69cd84f446 Merge branch '1.4.0' into 1.4.x-debugging-packet-dump 2016-10-21 09:32:44 +00:00
AJ Keller 9a17e41c0b Merge pull request #108 from baffo32/1.4.x-throw-invalid-options
Throw an error if invalid options are passed
2016-10-21 00:56:20 -04:00
Karl Semich edff39504c Use backticks in changelog from other pull review 2016-10-21 04:00:42 +00:00
Karl Semich 2d1285a887 Merge branch '1.4.0' into 1.4.x-throw-invalid-options 2016-10-21 03:42:02 +00:00
Karl Semich 2100aaee5c Changelog updates per PR review 2016-10-21 03:41:00 +00:00
Karl Semich eba46f8e6c debugBytes fixups, pull review 2016-10-21 03:35:09 +00:00
AJ Keller de57563f51 Merge pull request #109 from baffo32/1.4.x-double-connection 2016-10-20 13:32:42 -04:00
Karl Semich f59b41109d Connection fails if already connected (fixes #93)
Resources were not being cleaned up previously.
Although failing is somewhat harsh, this fix makes possible errors more visible.
2016-10-20 13:10:05 +00:00
Karl Semich 0193031d20 Add tests for debug option 2016-10-20 12:20:40 +00:00
Karl Semich 2904830309 Throw an error if invalid options are passed 2016-10-20 11:49:07 +00:00
Karl Semich 08ce44d4e9 Added a debug option to dump serial traffic 2016-10-20 11:20:12 +00:00
AJ Keller 62a69e01cc Merge pull request #104 from baffo32/1.4.0-use-fragmentation-simulation
use fragmentation simulation
2016-10-20 00:35:57 -04:00
AJ Keller e9e6dbd624 Merge pull request #105 from baffo32/1.4.0-options-algorithm
Automate the interpretation of options and defaults
2016-10-19 21:53:20 -04:00
AJ Keller 1ade656876 Merge pull request #106 from baffo32/1.4.0-firmware-typo
Stop outputting v2.0.0 after reset for v1 firmware
2016-10-19 21:52:37 -04:00
Karl Semich 83d32bc9b9 Stop outputting v2.0.0 after reset for v1 firmware 2016-10-20 00:26:51 +00:00
Karl Semich 4b5e4ab0a6 Automate the interpretation of options and defaults. 2016-10-19 23:41:36 +00:00
Karl Semich 2cc0d42fdf Enable fragmentation for some tests to ensure code withstands it 2016-10-19 23:08:17 +00:00
Karl Semich 94e0a13d71 Fix off-by-one max simulated radio channel 2016-10-19 23:08:17 +00:00
AJ Keller 6b11910fa7 Merge pull request #101 from baffo32/1.4.0-simulate-fragmentation 2016-10-19 18:26:12 -04:00
Karl Semich 83ac939d4e Updated incorrect default 2016-10-19 21:15:46 +00:00
Karl Semich 38687d42bb Add test to cover random fragmentation 2016-10-19 21:11:41 +00:00
Karl Semich 1a43a06786 Per PR review, change default fragmentation to 'none'.
Also removed associated test changes, and added some missing tests.
2016-10-19 20:43:25 +00:00
Karl Semich 47c6918194 Frag test adjustment: notice time sync replies even in byte 0 of a buffer 2016-10-19 20:39:54 +00:00
Karl Semich c351f3afd1 Add test: options propagate from public api to simulator
Revealed associated bugs which I fixed
2016-10-19 15:17:05 +00:00
Karl Semich e65707cb31 Merge branch '1.4.0' into 1.4.0-simulate-fragmentation 2016-10-19 14:20:43 +00:00
Karl Semich 97e44171b8 Some tests for simulating fragmentation.
Also fixed a few miscontructed buffer calls I ran into.
2016-10-19 13:40:05 +00:00
Karl Semich 0f7bb33434 Frag test adjustment: allow multiple matches for overbuffered data 2016-10-19 11:22:03 +00:00
Karl Semich 884f2f14ee Frag test adjustment: preserve buffer when parsing reset
- fixes bug with fragmented eot after reset which would result in a freeze
- removed daisy board specification in test; after this bugfix it was actually parsed, and conflicts with next tests, which assume 8 channels
2016-10-19 11:22:02 +00:00
Karl Semich 5fde5b09bf Frag test adjustment: disable for simulator tests so they pass 2016-10-19 11:21:46 +00:00
Karl Semich 23776e4b9c Add #98 to changelog 2016-10-19 11:12:09 +00:00
Karl Semich 5b70268390 Add simulation for buffer size and latency time (fixes #63)
Also minor changes to address comments on PR #100
2016-10-19 10:57:38 +00:00
AJ Keller 37db876f11 Update README.md 2016-10-18 23:15:56 -04:00
Karl Semich 864469d3d8 Simulate packet fragmentation; fixes #100 2016-10-19 01:31:24 +00:00
AJ Keller 7d78748532 Merge pull request #98 from baffo32/1.4.0-auto-find-linux
add autoFind patterns for Linux FTDI
2016-10-16 22:59:43 -04:00
Karl Semich d6fbce3e4c add autoFind patterns for Linux FTDI 2016-10-17 01:05:47 +00:00
AJ Keller 7ecff0a08d Rebased off 1.3.3 2016-10-16 16:47:04 -04:00
AJ Keller ab891d7565 saving 2016-10-16 16:40:06 -04:00
AJ Keller 3e99a77e88 ENH semistandard lint 2016-10-16 16:40:06 -04:00
AJ Keller e3061c03ce Fix log statements 2016-10-16 16:06:03 -04:00
34 arquivos alterados com 14032 adições e 12354 exclusões
+1
Ver Arquivo
@@ -0,0 +1 @@
{"extends": ["standard"], "parser": "babel-eslint"}
+3
Ver Arquivo
@@ -40,3 +40,6 @@ hardwareVoltageOutputAll.txt
# For git
*.orig
# Text editor temporary files
.*.sw* # vi/vim
+2 -1
Ver Arquivo
@@ -17,4 +17,5 @@ node_modules
.DS_Store
public
myOutput.txt
*.tgz
*.tgz
openBCISerialFormat
+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:
+340 -310
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+80 -1
Ver Arquivo
@@ -1,3 +1,82 @@
# 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
* Three new initialization options: `simulatorFragmentation`, `simulatorBufferSize`, and `simulatorLatencyTimer`. Together, these enable a more _realistic_ serial port simulation, mimicking different potential user computer systems.
* New option `debug` gives a live dump of serial traffic on the console if enabled
* New API function `.isConnected()` to check if communications are active.
* New API function `.isStreaming()` to check if samples are coming from the board.
### Enhancements
* Implement and adapt semi-standard code style. Closes #83
* autoFindOpenBCIBoard now notices and uses the stock dongle on Linux
* 'synced' object now has `error` property, null on good syncs, error description on bad syncs.
### Breaking Changes
* The setting for simulatorInjectLineNoise has changed from `None` to `none`
* connect() will now fail if already connected
* The constructor will throw an error now if an invalid option is passed
* The `.connected` property has been removed, replaced by `.isConnected()`. Removed from docs.
* 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
* Fixed bug where early packet fragments were dropped after board reset
* Fixed bug where time sync replies that began a buffered chunk were ignored
* Fixed bug where simulator would output wrong version in its reset message
* Fixed bug where resources were not cleaned up if connect was called twice
* Fixed bug where serial data was written after disconnection
* Fixed bug where unexpected disconnection was not detected
* Fixed bug where promises could lead to out of order packet processing.
# 1.3.3
### New Features
@@ -183,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)
+94 -60
Ver Arquivo
@@ -11,83 +11,117 @@ 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 */
console.log('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);
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');
-2293
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+1094 -1038
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+2351
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+1189 -1205
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+422 -323
Ver Arquivo
@@ -1,5 +1,4 @@
'use strict';
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var stream = require('stream');
@@ -8,355 +7,455 @@ 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, k.OBCIFirmwareV2],
fragmentation: [k.OBCISimulatorFragmentationNone, k.OBCISimulatorFragmentationRandom, k.OBCISimulatorFragmentationFullBuffers, k.OBCISimulatorFragmentationOneByOne],
latencyTime: 16,
bufferSize: 4096,
lineNoise: [k.OBCISimulatorLineNoiseHz60, k.OBCISimulatorLineNoiseHz50, k.OBCISimulatorLineNoiseNone],
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 = {};
function OpenBCISimulator(portName, options) {
options = (typeof options !== 'function') && options || {};
var opts = {};
stream.Stream.call(this);
stream.Stream.call(this);
/** Configuring Options */
var o;
for (o in _options) {
var userValue = options[o];
delete options[o];
/** Configuring Options */
if (options.accel === false) {
opts.accel = false;
if (typeof _options[o] === 'object') {
// an array specifying a list of choices
// if the choice is not in the list, the first one is defaulted to
if (_options[o].indexOf(userValue) !== -1) {
opts[o] = userValue;
} else {
opts.accel = _options.accel;
opts[o] = _options[o][0];
}
if (options.alpha === false) {
opts.alpha = false;
} else {
// anything else takes the user value if provided, otherwise is a default
if (userValue !== undefined) {
opts[o] = userValue;
} else {
opts.alpha = _options.alpha;
opts[o] = _options[o];
}
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;
// Call 'open'
if (this.options.verbose) console.log(`Port name: ${portName}`);
setTimeout(() => {
this.emit('open');
this.connected = true;
}, 200);
}
}
// This allows us to use the emitter class freely outside of the module
util.inherits(OpenBCISimulator, stream.Stream);
for (o in options) throw new Error('"' + o + '" is not a valid option');
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
};
this.streaming = false;
this.synced = false;
this.sendSyncSetPacket = false;
// Buffers
this.outputBuffer = new Buffer(this.options.bufferSize);
this.outputBuffered = 0;
// 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;
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;
// Call 'open'
if (this.options.verbose) console.log(`Port name: ${portName}`);
setTimeout(() => {
this.connected = true;
this.emit('open');
}, 200);
}
// This allows us to use the emitter class freely outside of the module
// TODO: upgrade from old-style streams to stream.Duplex or stream.Transform
util.inherits(OpenBCISimulator, stream.Stream);
OpenBCISimulator.prototype.flush = function (callback) {
this.outputBuffered = 0;
clearTimeout(this.outputLoopHandle);
this.outputLoopHandle = null;
if (callback) callback();
};
OpenBCISimulator.prototype.isOpen = function () {
return this.connected;
};
// output only size bytes of the output buffer
OpenBCISimulator.prototype._partialDrain = function (size) {
if (!this.connected) throw new Error('not connected');
if (size > this.outputBuffered) size = this.outputBuffered;
// 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);
this.outputBuffered -= size;
this.emit('data', outBuffer);
};
// queue some data for output and send it out depending on options.fragmentation
OpenBCISimulator.prototype._output = function (dataBuffer) {
// drain full buffers until there is no overflow
while (this.outputBuffered + dataBuffer.length > this.outputBuffer.length) {
var len = dataBuffer.copy(this.outputBuffer, this.outputBuffered);
dataBuffer = dataBuffer.slice(len);
this.outputBuffered += len;
this._partialDrain(this.outputBuffered);
this.flush();
}
dataBuffer.copy(this.outputBuffer, this.outputBuffered);
this.outputBuffered += dataBuffer.length;
if (!this.outputLoopHandle) {
var latencyTime = this.options.latencyTime;
if (this.options.fragmentation === k.OBCISimulatorFragmentationOneByOne ||
this.options.fragmentation === k.OBCISimulatorFragmentationNone) {
// no need to wait for latencyTime
// note that this is the only difference between 'none' and 'fullBuffers'
latencyTime = 0;
}
var outputLoop = () => {
var size;
switch (this.options.fragmentation) {
case k.OBCISimulatorFragmentationRandom:
if (Math.random() < 0.5) {
// randomly picked to send out a fragment
size = Math.ceil(Math.random() * Math.max(this.outputBuffered, 62));
break;
} // else, randomly picked to send a complete buffer in next block
/* falls through */
case k.OBCISimulatorFragmentationFullBuffers:
case k.OBCISimulatorFragmentationNone:
case false:
size = this.outputBuffered;
break;
case k.OBCISimulatorFragmentationOneByOne:
size = 1;
break;
}
/** Handle Callback */
if (this.connected) {
callback(null,'Success!');
this._partialDrain(size);
if (this.outputBuffered) {
this.outputLoopHandle = setTimeout(outputLoop, latencyTime);
} else {
this.outputLoopHandle = null;
}
};
};
if (latencyTime === 0) {
outputLoop();
} else {
this.outputLoopHandle = setTimeout(outputLoop, latencyTime);
}
}
};
OpenBCISimulator.prototype.drain = function(callback) {
callback();
};
OpenBCISimulator.prototype.write = function (data, callback) {
if (!this.connected) {
if (callback) callback('Not connected');
else throw new Error('Not connected!');
return;
}
OpenBCISimulator.prototype.close = function(callback) {
if (this.connected) {
this.emit('close');
// TODO: this function assumes a type of Buffer for radio, and a type of String otherwise
// FIX THIS it makes it unusable outside the api code
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._output(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.firmwareVersion === 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._output(new Buffer('Wiring is correct and a card is present.\nCorresponding SD file OBCI_69.TXT\n$$$'));
}
this.connected = false;
callback();
this.sd.active = true;
this.sd.startTime = now();
break;
case k.OBCISDLogStop:
if (!this.streaming) {
if (this.SDLogActive) {
this._output(new Buffer(`Total Elapsed Time: ${now() - this.sd.startTime} ms`));
this._output(new Buffer(`Max write time: ${Math.random() * 500} us`));
this._output(new Buffer(`Min write time: ${Math.random() * 200} us`));
this._output(new Buffer(`Overruns: 0`));
this._printEOT();
} else {
this._output(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._output(new Buffer(k.OBCISyncTimeSent));
this._syncUp();
}, 10);
}
break;
default:
break;
}
/** Handle Callback */
if (callback) {
callback(null, 'Success!');
}
};
OpenBCISimulator.prototype.drain = function (callback) {
if (callback) callback();
};
OpenBCISimulator.prototype.close = function (callback) {
if (this.connected) {
this.flush();
if (this.stream) clearInterval(this.stream);
this.connected = false;
this.emit('close');
if (callback) callback();
} else {
if (callback) callback('not connected');
}
};
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));
}
} 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._startStream = function() {
var intervalInMS = 1000 / this.options.sampleRate;
this.stream = setInterval(() => {
this._output(getNewPacket(this.sampleNumber));
this.sampleNumber++;
}, intervalInMS);
};
if (intervalInMS < 2) intervalInMS = 2;
OpenBCISimulator.prototype._syncUp = function () {
setTimeout(() => {
this.sendSyncSetPacket = true;
}, 12); // 3 packets later
};
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));
}
OpenBCISimulator.prototype._printEOT = function () {
this._output(new Buffer('$$$'));
};
OpenBCISimulator.prototype._printFailure = function () {
this._output(new Buffer('Failure: '));
};
OpenBCISimulator.prototype._printSuccess = function () {
this._output(new Buffer('Success: '));
};
OpenBCISimulator.prototype._printValidatedCommsTimeout = function () {
this._printFailure();
this._output(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._output(new Buffer(`Host and Device on Channel Number ${this.channelNumber}`));
this._output(new Buffer([this.channelNumber]));
this._printEOT();
} else if (!this.serialPortFailure) {
this._printFailure();
this._output(new Buffer(`Host on Channel Number ${this.channelNumber}`));
this._output(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._output(new Buffer(`Channel Number ${this.channelNumber}`));
this._output(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._output(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._output(new Buffer(`Host override - Channel Number ${this.hostChannelNumber}`));
this._output(new Buffer([this.hostChannelNumber]));
this._printEOT();
} else {
this._printFailure();
this._output(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._output(new Buffer(`Poll Time ${this.pollTime}`));
this._output(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._output(new Buffer(`Poll Time ${this.pollTime}`));
this._output(new Buffer([this.pollTime]));
this._printEOT();
} else {
this._printValidatedCommsTimeout();
}
}
break;
case k.OBCIRadioCmdBaudRateSetDefault:
if (this.options.firmwareVersion === k.OBCIFirmwareV2) {
this._printSuccess();
this._output(new Buffer('Switch your baud rate to 115200'));
this._output(new Buffer([0x24, 0x24, 0x24, 0xFF])); // The board really does this
}
break;
case k.OBCIRadioCmdBaudRateSetFast:
if (this.options.firmwareVersion === k.OBCIFirmwareV2) {
this._printSuccess();
this._output(new Buffer('Switch your baud rate to 230400'));
this._output(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._output(new Buffer('System is Up'));
this._printEOT();
} else {
this._printFailure();
this._output(new Buffer('System is Down'));
this._printEOT();
}
}
break;
default:
break;
}
};
factory.OpenBCISimulator = OpenBCISimulator;
factory.OpenBCISimulator = OpenBCISimulator;
}
util.inherits(OpenBCISimulatorFactory, EventEmitter);
+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 + '|');
}
}
+24 -5
Ver Arquivo
@@ -1,11 +1,11 @@
{
"name": "openbci",
"version": "1.3.3",
"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": "mocha test",
"test": "semistandard | snazzy && mocha test",
"test-cov": "istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec && codecov"
},
"keywords": [
@@ -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"
},
@@ -27,14 +29,17 @@
"test": "test"
},
"devDependencies": {
"bluebird": "3.4.6",
"chai": "^3.4.1",
"chai-as-promised": "^5.2.0",
"codecov": "^1.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 +51,19 @@
"homepage": "https://github.com/openbci/openbci_nodejs#readme",
"engines": {
"node": ">=4.0.0"
},
"semistandard": {
"globals": [
"describe",
"xdescribe",
"context",
"before",
"beforeEach",
"after",
"afterEach",
"it",
"expect",
"should"
]
}
}
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+1226 -1383
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+142
Ver Arquivo
@@ -0,0 +1,142 @@
var timingEventsAsPromises = require('./timingEventsAsPromises');
exports.BluebirdPromise = require('bluebird');
exports.PromiseIgnored = global.Promise;
// Enable bluebird for all promise usage during tests only
// Fails tests for issues bluebird finds
// Exports a function to list all promises (getPendingPromises)
// Exports a function to verify no promises pending within a timeout (noPendingPromises)
exports.BluebirdPromise.config({
// TODO: wForgottenReturn is disabled because timingEventsAsPromises triggers it; find a workaround
warnings: { wForgottenReturn: false },
longStackTraces: true,
monitoring: true,
cancellation: true
});
// nextTick conveniently not instrumented by timingEventsAsPromises
exports.BluebirdPromise.setScheduler(process.nextTick);
// unhandled rejections become test failures
process.on('unhandledRejection', (reason, promise) => {
if (!(reason instanceof Error)) {
reason = new Error('unhandled promise rejection: ' + reason);
} else {
reason.message = 'unhandled promise rejection: ' + reason.message;
}
process.nextTick(() => { throw reason; });
});
// // warnings become test failures
// process.on('warning', (warning) => {
// var error = new Error(warning);
// process.nextTick(() => { throw error; });
// });
// provide access to all currently pending promises
var pendingPromises = {};
var promiseId = 0;
var nested = 0;
function promiseCreationHandler (promise) {
// promise created already resolved; ignore
if (!promise.isPending()) return;
// need to create another promise to get access to the extended stack trace
// nested detects if we are inside our own dummy promise
++nested;
if (nested === 1) {
// not the dummy promise
promise.___id = ++promiseId;
// store promise details
var error = new Error('Promise ' + promise.___id + ' is still pending');
var entry = {
promise: promise,
id: promise.___id,
error: error
};
pendingPromises[promise.___id] = entry;
// extract stack trace by rejecting an error; bluebird fills in expanded stack
exports.BluebirdPromise.reject(error).catch(error => {
entry.error = error;
entry.stack = error.stack;
});
} else {
promise.___nested = nested;
}
--nested;
}
process.on('promiseCreated', promiseCreationHandler);
function promiseDoneHandler (promise) {
if (promise.___nested) return;
delete pendingPromises[promise.___id];
}
process.on('promiseFulfilled', promiseDoneHandler);
process.on('promiseRejected', promiseDoneHandler);
process.on('promiseResolved', promiseDoneHandler);
process.on('promiseCancelled', promiseDoneHandler);
exports.getPendingPromises = function () {
var ret = [];
for (var promise in pendingPromises) {
ret.push(pendingPromises[promise]);
}
return ret;
};
exports.noPendingPromises = function (milliseconds) {
if (!milliseconds) milliseconds = 0;
return new exports.PromiseIgnored((resolve, reject) => {
function waited100 () {
var promises = exports.getPendingPromises();
if (promises.length === 0) {
return resolve();
}
if (milliseconds > 0) {
milliseconds -= 100;
return timingEventsAsPromises.setTimeoutIgnored(waited100, 100);
}
// timed out, but promises remaining: cancel all
console.log(promises.length + ' promises still pending');
promises.forEach(promise => {
promise.promise.cancel();
});
// report one
reject(promises[0].error);
}
timingEventsAsPromises.setTimeoutIgnored(waited100, 0);
});
};
// now instrument the Promise object itself to always use a simplified version of bluebird
// bluebird is composed inside a bare-bones Promise object providing only the official calls
global.Promise = function (handler) {
this._promise = new exports.BluebirdPromise(handler);
};
// compose class methods
['all', 'race', 'reject', 'resolve'].forEach(classMethod => {
global.Promise[classMethod] = function () {
return exports.BluebirdPromise[classMethod].apply(exports.BluebirdPromise, [].slice.call(arguments));
};
Object.defineProperty(global.Promise[classMethod], 'name', { value: 'Promise.' + classMethod });
});
// compose object methods
['then', 'catch'].forEach(objectMethod => {
global.Promise.prototype[objectMethod] = function () {
return this._promise[objectMethod].apply(this._promise, [].slice.call(arguments));
};
Object.defineProperty(global.Promise.prototype[objectMethod], 'name', { value: 'Promise.' + objectMethod });
});
-622
Ver Arquivo
@@ -1,622 +0,0 @@
var sinon = require('sinon');
var chai = require('chai'),
should = chai.should(),
expect = chai.expect,
openBCIBoard = require('../openBCIBoard'),
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('#impedanceTesting', function() {
var ourBoard;
this.timeout(20000);
before(function(done) {
ourBoard = new openBCIBoard.OpenBCIBoard({
verbose: true
});
var useSim = () => {
ourBoard.simulatorEnable().then(() => {
return ourBoard.connect(k.OBCISimulatorPortName);
});
};
ourBoard.autoFindOpenBCIBoard()
.then(portName => {
return ourBoard.connect(portName);
})
.catch((err) => {
useSim();
})
.then(() => {
console.log('connected');
})
.catch(err => {
console.log('Error: '+ err);
});
ourBoard.once('ready',() => {
ourBoard.streamStart()
.then(() => {
setTimeout(() => {
done();
}, 100); // give some time for the stream command to be sent
})
.catch(err => {
console.log(err);
done(err);
});
});
});
after(done => {
if(ourBoard["connected"]) {
ourBoard.disconnect()
.then(() => {
done();
})
.catch(err => {
done(err);
})
}
});
describe('#impedanceTestAllChannels', function () {
var impedanceArray = [];
before(function(done) {
ourBoard.once('impedanceArray', arr => {
impedanceArray = arr;
console.log(impedanceArray);
done();
});
ourBoard.impedanceTestAllChannels();
});
describe('#channel1',function() {
it('has valid channel number', function() {
impedanceArray[0].channel.should.be.equal(1);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceArray[0].P.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[0].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceArray[0].N.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[0].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel2',function() {
it('has valid channel number', function() {
impedanceArray[1].channel.should.be.equal(2);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceArray[1].P.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[1].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceArray[1].N.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[1].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel3',function() {
it('has valid channel number', function() {
impedanceArray[2].channel.should.be.equal(3);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceArray[2].P.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[2].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceArray[2].N.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[2].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel4',function() {
it('has valid channel number', function() {
impedanceArray[3].channel.should.be.equal(4);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceArray[3].P.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[3].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceArray[3].N.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[3].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel5',function() {
it('has valid channel number', function() {
impedanceArray[4].channel.should.be.equal(5);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceArray[4].P.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[4].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceArray[4].N.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[4].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel6',function() {
it('has valid channel number', function() {
impedanceArray[5].channel.should.be.equal(6);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceArray[5].P.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[5].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceArray[5].N.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[5].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel7',function() {
it('has valid channel number', function() {
impedanceArray[6].channel.should.be.equal(7);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceArray[6].P.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[6].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceArray[6].N.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[6].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel8',function() {
it('has valid channel number', function () {
impedanceArray[7].channel.should.be.equal(8);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[7].P.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function () {
impedanceArray[7].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[7].N.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function () {
impedanceArray[7].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
});
describe('#impedanceTestChannelsRejects', function() {
it('rejects when it does not get an array', function(done) {
ourBoard.impedanceTestChannels('taco').should.be.rejected.and.notify(done);
});
it('rejects when it array length does not match number of channels', function(done) {
ourBoard.impedanceTestChannels(['-','N','n','p','P','p','b']).should.be.rejected.and.notify(done);
});
});
describe('#impedanceTestChannels', function () {
var impedanceArray = [];
before(function(done) {
ourBoard.once('impedanceArray', arr => {
impedanceArray = arr;
done();
});
ourBoard.impedanceArray[0] = openBCISample.impedanceObject(1);
ourBoard.impedanceTestChannels(['-','N','n','p','P','p','b','B']).catch(err => done(err));
});
describe('#channel1',function() {
it('has valid channel number', function() {
impedanceArray[0].channel.should.be.equal(1);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceArray[0].P.should.have.property('raw').equal(-1);
});
it('text is not \'init\'', function() {
impedanceArray[0].P.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceArray[0].N.should.have.property('raw').equal(-1);
});
it('text is not \'init\'', function() {
impedanceArray[0].N.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel2',function() {
it('has valid channel number', function() {
impedanceArray[1].channel.should.be.equal(2);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceArray[1].P.should.have.property('raw').equal(-1);
});
it('text is not \'init\'', function() {
impedanceArray[1].P.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceArray[1].N.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[1].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel3',function() {
it('has valid channel number', function() {
impedanceArray[2].channel.should.be.equal(3);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceArray[2].P.should.have.property('raw').equal(-1);
});
it('text is not \'init\'', function() {
impedanceArray[2].P.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceArray[2].N.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[2].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel4',function() {
it('has valid channel number', function() {
impedanceArray[3].channel.should.be.equal(4);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceArray[3].P.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[3].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceArray[3].N.should.have.property('raw').equal(-1);
});
it('text is not \'init\'', function() {
impedanceArray[3].N.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel5',function() {
it('has valid channel number', function() {
impedanceArray[4].channel.should.be.equal(5);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceArray[4].P.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[4].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceArray[4].N.should.have.property('raw').equal(-1);
});
it('text is not \'init\'', function() {
impedanceArray[4].N.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel6',function() {
it('has valid channel number', function() {
impedanceArray[5].channel.should.be.equal(6);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceArray[5].P.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[5].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceArray[5].N.should.have.property('raw').equal(-1);
});
it('text is not \'init\'', function() {
impedanceArray[5].N.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel7',function() {
it('has valid channel number', function() {
impedanceArray[6].channel.should.be.equal(7);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceArray[6].P.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[6].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceArray[6].N.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceArray[6].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel8',function() {
it('has valid channel number', function () {
impedanceArray[7].channel.should.be.equal(8);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[7].P.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function () {
impedanceArray[7].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[7].N.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function () {
impedanceArray[7].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
});
describe('#impedanceTestChannel', function () {
var impedanceObject = {};
before(function(done) {
ourBoard.impedanceTestChannel(1)
.then(impdObj => {
impedanceObject = impdObj;
done();
})
.catch(err => done(err));
});
describe('#channel1',function() {
it('has valid channel number', function() {
impedanceObject.channel.should.be.equal(1);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceObject.P.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceObject.P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceObject.N.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceObject.N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
});
describe('#impedanceTestChannelInputP', function () {
var impedanceObject = {};
before(function(done) {
ourBoard.impedanceTestChannelInputP(1)
.then(impdObj => {
impedanceObject = impdObj;
done();
})
.catch(err => done(err));
});
describe('#channel1',function() {
it('has valid channel number', function() {
impedanceObject.channel.should.be.equal(1);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceObject.P.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceObject.P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceObject.N.should.have.property('raw').equal(-1);
});
it('text is not \'init\'', function() {
impedanceObject.N.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
});
});
describe('#impedanceTestChannelInputN', function () {
var impedanceObject = {};
//wstream = fs.createWriteStream('hardwareVoltageOutputAll.txt');
before(function(done) {
console.log('7');
ourBoard.on('sample',sample => {
//console.log('8');
//OpenBCISample.debugPrettyPrint(sample);
// good to start impedance testing..
});
ourBoard.impedanceTestChannelInputN(1)
.then(impdObj => {
impedanceObject = impdObj;
setTimeout(() => {
done();
}, 1000);
})
.catch(err => done(err));
});
describe('#channel1',function() {
it('has valid channel number', function() {
impedanceObject.channel.should.be.equal(1);
});
describe('#inputP', function() {
it('got raw impedance value',function() {
impedanceObject.P.should.have.property('raw').equal(-1);
});
it('text is not \'init\'', function() {
impedanceObject.P.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function() {
it('got raw impedance value',function() {
impedanceObject.N.should.have.property('raw').above(-1);
});
it('text is not \'init\'', function() {
impedanceObject.N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
});
describe('#impedanceTestContinuousStXX', function () {
var impedanceArray = [];
before(function(done) {
ourBoard.impedanceTestContinuousStart()
.then(done).catch(err => done(err));
});
after(function(done) {
ourBoard.impedanceTestContinuousStop()
.then(done);
});
it('prints 10 impedance arrays', function(done) {
var count = 1;
var listener = impedanceArray => {
//console.log('\nImpedance Array: ' + count);
//console.log(impedanceArray);
count++;
if (count > 10) {
ourBoard.removeListener('impedanceArray', listener);
done();
}
};
ourBoard.on('impedanceArray', listener);
});
});
describe('#_impedanceTestSetChannel', function () {
it('reject with invalid channel', function(done) {
ourBoard._impedanceTestSetChannel(0,false,false).should.be.rejected.and.notify(done);
});
});
describe('#_impedanceTestCalculateChannel', function () {
it('reject with low invalid channel', function(done) {
ourBoard._impedanceTestCalculateChannel(0,false,false).should.be.rejected.and.notify(done);
});
it('reject with high invalid channel', function(done) {
ourBoard._impedanceTestCalculateChannel(69,false,false).should.be.rejected.and.notify(done);
});
it('reject with invalid data type pInput', function(done) {
ourBoard._impedanceTestCalculateChannel(1,'taco',false).should.be.rejected.and.notify(done);
});
it('reject with invalid data type nInput', function(done) {
ourBoard._impedanceTestCalculateChannel(1,false,'taco').should.be.rejected.and.notify(done);
});
});
describe('#_impedanceTestFinalizeChannel', function () {
it('reject with low invalid channel', function(done) {
ourBoard._impedanceTestFinalizeChannel(0,false,false).should.be.rejected.and.notify(done);
});
it('reject with high invalid channel', function(done) {
ourBoard._impedanceTestFinalizeChannel(69,false,false).should.be.rejected.and.notify(done);
});
it('reject with invalid data type pInput', function(done) {
ourBoard._impedanceTestFinalizeChannel(1,'taco',false).should.be.rejected.and.notify(done);
});
it('reject with invalid data type nInput', function(done) {
ourBoard._impedanceTestFinalizeChannel(1,false,'taco').should.be.rejected.and.notify(done);
});
});
});
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+608
Ver Arquivo
@@ -0,0 +1,608 @@
'use strict';
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;
const chaiAsPromised = require('chai-as-promised');
const sinonChai = require('sinon-chai');
chai.use(chaiAsPromised);
chai.use(sinonChai);
describe('#impedanceTesting', function () {
var ourBoard;
this.timeout(20000);
before(function (done) {
ourBoard = new Cyton({
verbose: true,
simulatorFragmentation: k.OBCISimulatorFragmentationRandom
});
var useSim = () => {
return ourBoard.simulatorEnable().then(() => {
return ourBoard.connect(k.OBCISimulatorPortName);
});
};
ourBoard.autoFindOpenBCIBoard()
.then(portName => {
return ourBoard.connect(portName);
})
.catch(() => {
return useSim();
})
.then(() => {
console.log('connected');
})
.catch(err => {
console.log('Error: ' + err);
});
ourBoard.once('ready', () => {
ourBoard.streamStart()
.then(() => {
setTimeout(() => {
done();
}, 100); // give some time for the stream command to be sent
})
.catch(err => {
console.log(err);
done(err);
});
});
});
after(done => {
if (ourBoard.isConnected()) {
ourBoard.disconnect()
.then(() => {
done();
})
.catch(err => {
done(err);
});
} else {
done();
}
});
after(() => bluebirdChecks.noPendingPromises());
describe('#impedanceTestAllChannels', function () {
var impedanceArray = [];
before(function (done) {
ourBoard.once('impedanceArray', arr => {
impedanceArray = arr;
console.log(impedanceArray);
done();
});
ourBoard.impedanceTestAllChannels();
});
describe('#channel1', function () {
it('has valid channel number', function () {
impedanceArray[0].channel.should.be.equal(1);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[0].P.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[0].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[0].N.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[0].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel2', function () {
it('has valid channel number', function () {
impedanceArray[1].channel.should.be.equal(2);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[1].P.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[1].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[1].N.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[1].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel3', function () {
it('has valid channel number', function () {
impedanceArray[2].channel.should.be.equal(3);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[2].P.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[2].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[2].N.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[2].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel4', function () {
it('has valid channel number', function () {
impedanceArray[3].channel.should.be.equal(4);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[3].P.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[3].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[3].N.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[3].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel5', function () {
it('has valid channel number', function () {
impedanceArray[4].channel.should.be.equal(5);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[4].P.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[4].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[4].N.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[4].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel6', function () {
it('has valid channel number', function () {
impedanceArray[5].channel.should.be.equal(6);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[5].P.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[5].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[5].N.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[5].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel7', function () {
it('has valid channel number', function () {
impedanceArray[6].channel.should.be.equal(7);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[6].P.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[6].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[6].N.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[6].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel8', function () {
it('has valid channel number', function () {
impedanceArray[7].channel.should.be.equal(8);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[7].P.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[7].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[7].N.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[7].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
});
describe('#impedanceTestChannelsRejects', function () {
it('rejects when it does not get an array', function (done) {
ourBoard.impedanceTestChannels('taco').should.be.rejected.and.notify(done);
});
it('rejects when it array length does not match number of channels', function (done) {
ourBoard.impedanceTestChannels(['-', 'N', 'n', 'p', 'P', 'p', 'b']).should.be.rejected.and.notify(done);
});
});
describe('#impedanceTestChannels', function () {
var impedanceArray = [];
before(function (done) {
ourBoard.once('impedanceArray', arr => {
impedanceArray = arr;
done();
});
ourBoard.impedanceArray[0] = openBCISample.impedanceObject(1);
ourBoard.impedanceTestChannels(['-', 'N', 'n', 'p', 'P', 'p', 'b', 'B']).catch(err => done(err));
});
describe('#channel1', function () {
it('has valid channel number', function () {
impedanceArray[0].channel.should.be.equal(1);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[0].P.should.have.property('raw').equal(-1);
});
it("text is not 'init'", function () {
impedanceArray[0].P.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[0].N.should.have.property('raw').equal(-1);
});
it("text is not 'init'", function () {
impedanceArray[0].N.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel2', function () {
it('has valid channel number', function () {
impedanceArray[1].channel.should.be.equal(2);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[1].P.should.have.property('raw').equal(-1);
});
it("text is not 'init'", function () {
impedanceArray[1].P.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[1].N.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[1].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel3', function () {
it('has valid channel number', function () {
impedanceArray[2].channel.should.be.equal(3);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[2].P.should.have.property('raw').equal(-1);
});
it("text is not 'init'", function () {
impedanceArray[2].P.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[2].N.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[2].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel4', function () {
it('has valid channel number', function () {
impedanceArray[3].channel.should.be.equal(4);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[3].P.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[3].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[3].N.should.have.property('raw').equal(-1);
});
it("text is not 'init'", function () {
impedanceArray[3].N.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel5', function () {
it('has valid channel number', function () {
impedanceArray[4].channel.should.be.equal(5);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[4].P.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[4].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[4].N.should.have.property('raw').equal(-1);
});
it("text is not 'init'", function () {
impedanceArray[4].N.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel6', function () {
it('has valid channel number', function () {
impedanceArray[5].channel.should.be.equal(6);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[5].P.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[5].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[5].N.should.have.property('raw').equal(-1);
});
it("text is not 'init'", function () {
impedanceArray[5].N.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel7', function () {
it('has valid channel number', function () {
impedanceArray[6].channel.should.be.equal(7);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[6].P.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[6].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[6].N.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[6].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
describe('#channel8', function () {
it('has valid channel number', function () {
impedanceArray[7].channel.should.be.equal(8);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceArray[7].P.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[7].P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceArray[7].N.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceArray[7].N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
});
describe('#impedanceTestChannel', function () {
var impedanceObject = {};
before(function (done) {
ourBoard.impedanceTestChannel(1)
.then(impdObj => {
impedanceObject = impdObj;
done();
})
.catch(err => done(err));
});
describe('#channel1', function () {
it('has valid channel number', function () {
impedanceObject.channel.should.be.equal(1);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceObject.P.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceObject.P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceObject.N.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceObject.N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
});
describe('#impedanceTestChannelInputP', function () {
var impedanceObject = {};
before(function (done) {
ourBoard.impedanceTestChannelInputP(1)
.then(impdObj => {
impedanceObject = impdObj;
done();
})
.catch(err => done(err));
});
describe('#channel1', function () {
it('has valid channel number', function () {
impedanceObject.channel.should.be.equal(1);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceObject.P.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceObject.P.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceObject.N.should.have.property('raw').equal(-1);
});
it("text is not 'init'", function () {
impedanceObject.N.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
});
});
describe('#impedanceTestChannelInputN', function () {
var impedanceObject = {};
// wstream = fs.createWriteStream('hardwareVoltageOutputAll.txt')
before(function (done) {
console.log('7');
ourBoard.on('sample', sample => {
// console.log('8')
// OpenBCISample.debugPrettyPrint(sample)
// good to start impedance testing..
});
ourBoard.impedanceTestChannelInputN(1)
.then(impdObj => {
impedanceObject = impdObj;
setTimeout(() => {
done();
}, 1000);
})
.catch(err => done(err));
});
describe('#channel1', function () {
it('has valid channel number', function () {
impedanceObject.channel.should.be.equal(1);
});
describe('#inputP', function () {
it('got raw impedance value', function () {
impedanceObject.P.should.have.property('raw').equal(-1);
});
it("text is not 'init'", function () {
impedanceObject.P.should.have.property('text').equal(k.OBCIImpedanceTextInit);
});
});
describe('#inputN', function () {
it('got raw impedance value', function () {
impedanceObject.N.should.have.property('raw').above(-1);
});
it("text is not 'init'", function () {
impedanceObject.N.should.have.property('text').not.be.equal(k.OBCIImpedanceTextInit);
});
});
});
});
describe('#impedanceTestContinuousStXX', function () {
before(function (done) {
ourBoard.impedanceTestContinuousStart()
.then(done).catch(err => done(err));
});
after(function (done) {
ourBoard.impedanceTestContinuousStop()
.then(done);
});
it('prints 10 impedance arrays', function (done) {
var count = 1;
var listener = impedanceArray => {
// console.log('\nImpedance Array: ' + count)
// console.log(impedanceArray)
count++;
if (count > 10) {
ourBoard.removeListener('impedanceArray', listener);
done();
}
};
ourBoard.on('impedanceArray', listener);
});
});
describe('#_impedanceTestSetChannel', function () {
it('reject with invalid channel', function (done) {
ourBoard._impedanceTestSetChannel(0, false, false).should.be.rejected.and.notify(done);
});
});
describe('#_impedanceTestCalculateChannel', function () {
it('reject with low invalid channel', function (done) {
ourBoard._impedanceTestCalculateChannel(0, false, false).should.be.rejected.and.notify(done);
});
it('reject with high invalid channel', function (done) {
ourBoard._impedanceTestCalculateChannel(69, false, false).should.be.rejected.and.notify(done);
});
it('reject with invalid data type pInput', function (done) {
ourBoard._impedanceTestCalculateChannel(1, 'taco', false).should.be.rejected.and.notify(done);
});
it('reject with invalid data type nInput', function (done) {
ourBoard._impedanceTestCalculateChannel(1, false, 'taco').should.be.rejected.and.notify(done);
});
});
describe('#_impedanceTestFinalizeChannel', function () {
it('reject with low invalid channel', function (done) {
ourBoard._impedanceTestFinalizeChannel(0, false, false).should.be.rejected.and.notify(done);
});
it('reject with high invalid channel', function (done) {
ourBoard._impedanceTestFinalizeChannel(69, false, false).should.be.rejected.and.notify(done);
});
it('reject with invalid data type pInput', function (done) {
ourBoard._impedanceTestFinalizeChannel(1, 'taco', false).should.be.rejected.and.notify(done);
});
it('reject with invalid data type nInput', function (done) {
ourBoard._impedanceTestFinalizeChannel(1, false, 'taco').should.be.rejected.and.notify(done);
});
});
});
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+108
Ver Arquivo
@@ -0,0 +1,108 @@
// Converts timing events to use promises, to gain bluebird's checks
function instrumentTimingEvents (module, type) {
// replaces module[type] with a function that does the same thing but uses a promise
// assumes the first argument will be to a callback function
// if this a setSomething function with a clearSomething partner, the partner will also be instrumented
var setName = type;
var clearName = null;
if (type.substring(0, 3) === 'set') {
clearName = 'clear' + type.substring(3);
}
if (!module[setName]) return;
// store original functions
var originalSet = module[setName];
var originalClear = module[clearName];
exports[setName + 'Ignored'] = originalSet;
// dictionary to store promise details for each call
var events = {};
// setAsPromise() is the brunt of the function. It replaces the previous global function,
// and sets up a promise to resolve when the callback is called
var eventCount = 0;
var setAsPromise = function (callback) {
var args = [].slice.call(arguments);
var eventNum = ++eventCount;
var eventHandle;
if (setAsPromise._ignoreCount > 0) {
--setAsPromise._ignoreCount;
return originalSet.apply(this, args);
}
// actual callback is replaced by promise resolve
args[0] = function () {
if (!events[eventNum]) throw new Error(setName + ' ' + eventNum + ' disappeared');
events[eventNum].resolve([].slice.call(arguments));
};
eventHandle = originalSet.apply(this, args) || eventNum;
// this portion is a function so that setInterval may be handled via recursion
function dispatch () {
var handlerDetails = { handle: eventHandle };
var promise = new Promise((resolve, reject) => {
handlerDetails.resolve = resolve;
handlerDetails.reject = reject;
});
handlerDetails.promise = promise;
events[eventNum] = handlerDetails;
promise.then(function (argumentArray) {
if (type !== 'setInterval') {
delete events[eventNum];
} else {
dispatch();
}
// call original handler
callback.apply(this, argumentArray);
}, () => {
originalClear(eventHandle);
delete events[eventNum];
});
return promise;
}
dispatch();
return eventNum;
};
// actually replace functions with instrumented ones
setAsPromise._ignoreCount = 0;
module[setName] = setAsPromise;
Object.defineProperty(setAsPromise, 'name', { value: setName + 'AsPromise' });
if (clearName) {
module[clearName] = (eventNum) => {
if (!events[eventNum]) {
originalClear(eventNum);
} else {
events[eventNum].reject(new Error('cleared'));
}
};
Object.defineProperty(module[clearName], 'name', { value: clearName + 'AsPromise' });
}
}
instrumentTimingEvents(global, 'setTimeout');
instrumentTimingEvents(global, 'setInterval');
instrumentTimingEvents(global, 'setImmediate');
// // Possible TODO: nextTick needs some exceptions included to prevent infinite recursion
// instrumentTimingEvents(process, 'nextTick');
// the next call to the passed function should not be promisified
// may be queued multiple times
exports.ignoreOnce = (ignored) => {
ignored._ignoreCount ++;
};
-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;