Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes [for case of packet fragmentation] #102

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

* Implement and adapt semi-standard code style. Closes #83

### Bug Fixes

* Don't drop early packet fragments after board reset

# 1.3.3

### New Features
Expand Down
2 changes: 2 additions & 0 deletions openBCIBoard.js
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,8 @@ function OpenBCIFactory () {
this.curParsingMode = k.OBCIParsingNormal;
this.buffer = null;
this.emit('ready');
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good!

this.buffer = data;
}
break;
case k.OBCIParsingTimeSyncSent:
Expand Down
4 changes: 4 additions & 0 deletions openBCISample.js
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,10 @@ function countADSPresent (dataBuffer) {
* @param dataBuffer - The buffer of some length to parse
* @returns {boolean} - True if the `$$$` was found.
*/
// TODO: StreamSearch is optimized to search incoming chunks of data, streaming in,
// but a new search is constructed here with every call. This is not making use
// of StreamSearch's optimizations; the object should be preserved between chunks,
// and only fed the new data. TODO: also check other uses of StreamSearch
function doesBufferHaveEOT (dataBuffer) {
const s = new StreamSearch(new Buffer(k.OBCIParseEOT));

Expand Down
3 changes: 1 addition & 2 deletions test/openBCIBoard-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1449,8 +1449,7 @@ $$$`);
var buf1 = new Buffer(`OpenBCI V3 Simulator
On Board ADS1299 Device ID: 0x12345
`);
var buf2 = new Buffer(`On Daisy ADS1299 Device ID: 0xFFFFF
LIS3DH Device ID: `);
var buf2 = new Buffer(`LIS3DH Device ID: `);
var buf3 = new Buffer(`0x38422
$$$`);

Expand Down
18 changes: 13 additions & 5 deletions test/openBCISimulator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('openBCISimulator', function () {
expect(simulator.options.sampleRate).to.equal(k.OBCISampleRate250);
expect(simulator.options.serialPortFailure).to.be.false;
expect(simulator.options.verbose).to.be.false;
expect(simulator.options.fragmentation).to.equal(k.OBCISimulatorFragmentationRandom);
});
it('should be able to get into daisy mode', function () {
simulator = new openBCISimulator.OpenBCISimulator(portName, {
Expand Down Expand Up @@ -113,7 +114,9 @@ describe('openBCISimulator', function () {
});
describe(`_startStream`, function () {
it('should return a packet with sample data in it', function (done) {
var simulator = new openBCISimulator.OpenBCISimulator(k.OBCISimulatorPortName);
var simulator = new openBCISimulator.OpenBCISimulator(k.OBCISimulatorPortName, {
fragmentation: k.OBCISimulatorFragmentationNone
});
var sampleCounter = 0;
var sampleTestSize = 5;

Expand All @@ -137,7 +140,9 @@ describe('openBCISimulator', function () {
simulator._startStream();
});
it('should return a sync set packet with accel', function (done) {
var simulator = new openBCISimulator.OpenBCISimulator(k.OBCISimulatorPortName);
var simulator = new openBCISimulator.OpenBCISimulator(k.OBCISimulatorPortName, {
fragmentation: k.OBCISimulatorFragmentationNone
});
var sampleCounter = 0;
var sampleTestSize = 5;

Expand Down Expand Up @@ -170,7 +175,8 @@ describe('openBCISimulator', function () {
});
it('should return a sync set packet with raw aux', function (done) {
var simulator = new openBCISimulator.OpenBCISimulator(k.OBCISimulatorPortName, {
accel: false
accel: false,
fragmentation: k.OBCISimulatorFragmentationNone
});
var sampleCounter = 0;
var sampleTestSize = 5;
Expand Down Expand Up @@ -207,7 +213,8 @@ describe('openBCISimulator', function () {
var simulator;
beforeEach(() => {
simulator = new openBCISimulator.OpenBCISimulator(k.OBCISimulatorPortName, {
firmwareVersion: 'v2'
firmwareVersion: 'v2',
fragmentation: k.OBCISimulatorFragmentationNone
});
});
afterEach(() => {
Expand Down Expand Up @@ -589,7 +596,8 @@ describe('openBCISimulator', function () {
var simulator;
beforeEach(function (done) {
simulator = new openBCISimulator.OpenBCISimulator(portName, {
firmwareVersion: 'v2'
firmwareVersion: 'v2',
fragmentation: k.OBCISimulatorFragmentationNone
});
simulator.once('open', () => {
done();
Expand Down