Comparar commits
3 Commits
| Autor | SHA1 | Data | |
|---|---|---|---|
| d6335257e1 | |||
| aea599a7dd | |||
| 031861d2ed |
@@ -3,11 +3,20 @@ node_js:
|
||||
- "4.0"
|
||||
- "4.1"
|
||||
- "4.2"
|
||||
- "4.3"
|
||||
- "4.4"
|
||||
- "4.5"
|
||||
- "4.6"
|
||||
- "5.11.0"
|
||||
- "6.0"
|
||||
- "6.1"
|
||||
- "6.2"
|
||||
- "6.3"
|
||||
- "6.4"
|
||||
- "6.5"
|
||||
- "6.6"
|
||||
- "6.7"
|
||||
- "6.8"
|
||||
install:
|
||||
- npm install --all
|
||||
script:
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
# 1.3.3
|
||||
|
||||
### New Features
|
||||
|
||||
* Add `timeOffsetMaster` to object emitted when bad time sync.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fixed log statement on impedance setting function
|
||||
* Remove event emitter with time sync on reject of sync clock full
|
||||
|
||||
# 1.3.2
|
||||
|
||||
### Enhancements
|
||||
|
||||
@@ -63,16 +63,16 @@ 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!`);
|
||||
}
|
||||
});
|
||||
.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
|
||||
|
||||
+14
-5
@@ -176,6 +176,7 @@ function OpenBCIFactory() {
|
||||
this._lowerChannelsSampleObject = null;
|
||||
this.sync = {
|
||||
curSyncObj: null,
|
||||
eventEmitter: null,
|
||||
objArray: [],
|
||||
sntpActive: false,
|
||||
timeOffsetMaster: 0,
|
||||
@@ -1327,7 +1328,6 @@ function OpenBCIFactory() {
|
||||
if (this.options.verbose) console.log('pInput: ' + pInput + ' nInput: ' + nInput);
|
||||
// Get impedance settings to send the board
|
||||
k.getImpedanceSetter(channelNumber,pInput,nInput).then((commandsArray) => {
|
||||
console.log(commandsArray);
|
||||
this.write(commandsArray);
|
||||
//delayInMS += commandsArray.length * k.OBCIWriteIntervalDelayMSLong;
|
||||
delayInMS += this.commandsToWrite * k.OBCIWriteIntervalDelayMSShort; // Account for commands waiting to be sent in the write buffer
|
||||
@@ -1564,10 +1564,11 @@ function OpenBCIFactory() {
|
||||
if (!this.usingVersionTwoFirmware()) reject('Time sync not implemented on v1 firmware, please update to v2');
|
||||
setTimeout(() => {
|
||||
return reject('syncClocksFull timeout after 500ms with no sync');
|
||||
}, 1000); // Should not take more than 1s to sync up
|
||||
this.once('synced',syncObj => {
|
||||
}, 500); // Should not take more than 1s to sync up
|
||||
this.sync.eventEmitter = syncObj => {
|
||||
return resolve(syncObj);
|
||||
});
|
||||
};
|
||||
this.once('synced', this.sync.eventEmitter);
|
||||
this.sync.curSyncObj = openBCISample.newSyncObject();
|
||||
this.sync.curSyncObj.timeSyncSent = this.time();
|
||||
this.curParsingMode = k.OBCIParsingTimeSyncSent;
|
||||
@@ -1853,7 +1854,9 @@ function OpenBCIFactory() {
|
||||
// Fix the curParsingMode back to normal
|
||||
this.curParsingMode = k.OBCIParsingNormal;
|
||||
// Emit the bad sync object for fun
|
||||
this.emit('synced',openBCISample.newSyncObject());
|
||||
var badObject = openBCISample.newSyncObject();
|
||||
badObject.timeOffsetMaster = this.sync.timeOffsetMaster;
|
||||
this.emit('synced', badObject);
|
||||
// Set back to null
|
||||
this.sync.curSyncObj = null;
|
||||
// Return will exit this method with the err
|
||||
@@ -1951,6 +1954,12 @@ function OpenBCIFactory() {
|
||||
return resolve(rawPacket);
|
||||
})
|
||||
.catch(err => {
|
||||
// Emit the bad sync object for fun
|
||||
var badObject = openBCISample.newSyncObject();
|
||||
badObject.timeOffsetMaster = this.sync.timeOffsetMaster;
|
||||
this.emit('synced', badObject);
|
||||
// Set back to null
|
||||
this.sync.curSyncObj = null;
|
||||
console.log('Error in _processPacketTimeSyncSet', err)
|
||||
return reject(err);
|
||||
});
|
||||
|
||||
+6
-5
@@ -707,7 +707,6 @@ function parsePacketTimeSyncedAccel(dataBuf,channelSettingsArray,boardOffsetTime
|
||||
return new Promise((resolve, reject) => {
|
||||
// The sample object we are going to build
|
||||
var sampleObject = {};
|
||||
|
||||
if (dataBuf.byteLength != k.OBCIPacketSize) reject("Error [parsePacketTimeSyncedAccel]: input buffer must be " + k.OBCIPacketSize + " bytes!");
|
||||
|
||||
// Get the sample number
|
||||
@@ -803,10 +802,12 @@ function getFromTimePacketTime(dataBuf) {
|
||||
// Ths packet has 'A0','00'....,'00','00','FF','FF','FF','FF','C3' where the 'FF's are times
|
||||
const lastBytePosition = k.OBCIPacketSize - 1; // This is 33, but 0 indexed would be 32 minus 1 for the stop byte and another two for the aux channel or the
|
||||
return new Promise((resolve, reject) => {
|
||||
if (dataBuf.byteLength != k.OBCIPacketSize) reject("Error [getFromTimePacketTime]: input buffer must be " + k.OBCIPacketSize + " bytes!");
|
||||
|
||||
// Grab the time from the packet
|
||||
resolve(dataBuf.readUInt32BE(lastBytePosition - k.OBCIStreamPacketTimeByteSize));
|
||||
if (dataBuf.byteLength != k.OBCIPacketSize) {
|
||||
reject("Error [getFromTimePacketTime]: input buffer must be " + k.OBCIPacketSize + " bytes!");
|
||||
} else {
|
||||
// Grab the time from the packet
|
||||
resolve(dataBuf.readUInt32BE(lastBytePosition - k.OBCIStreamPacketTimeByteSize));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "openbci",
|
||||
"version": "1.3.2",
|
||||
"version": "1.3.3",
|
||||
"description": "The official Node.js SDK for the OpenBCI Biosensor Board.",
|
||||
"main": "openBCIBoard",
|
||||
"scripts": {
|
||||
|
||||
+155
-15
@@ -296,6 +296,16 @@ describe('openbci-sdk',function() {
|
||||
(ourBoard.impedanceTest.onChannel).should.equal(0);
|
||||
(ourBoard.impedanceTest.sampleNumber).should.equal(0);
|
||||
});
|
||||
it('configures sync object correctly', function() {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard();
|
||||
expect(ourBoard.sync.curSyncObj).to.be.null;
|
||||
expect(ourBoard.sync.eventEmitter).to.be.null;
|
||||
expect(ourBoard.sync.objArray.length).to.equal(0);
|
||||
(ourBoard.sync.sntpActive).should.equal(false);
|
||||
(ourBoard.sync.timeOffsetMaster).should.equal(0);
|
||||
(ourBoard.sync.timeOffsetAvg).should.equal(0);
|
||||
expect(ourBoard.sync.timeOffsetArray.length).to.equal(0);
|
||||
});
|
||||
it('configures impedance array with the correct amount of channels for default', function() {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard();
|
||||
(ourBoard.impedanceArray.length).should.equal(8);
|
||||
@@ -1085,19 +1095,64 @@ describe('openbci-sdk',function() {
|
||||
.catch(function(err) {
|
||||
expect(ourBoard.curParsingMode).to.equal(k.OBCIParsingNormal);
|
||||
expect(ourBoard.sync.curSyncObj).to.be.null;
|
||||
expect(ourBoard.sync.eventEmitter).to.be.null;
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should emit sycned event with valid false", function(done) {
|
||||
var timeSetPacketArrived = ourBoard.time();
|
||||
var expectedTimeSyncOffsetMaster = 72;
|
||||
ourBoard.curParsingMode = k.OBCIParsingTimeSyncSent;
|
||||
ourBoard.sync.curSyncObj = openBCISample.newSyncObject();
|
||||
ourBoard.sync.timeOffsetMaster = expectedTimeSyncOffsetMaster;
|
||||
ourBoard.once('synced',obj => {
|
||||
expect(obj.valid).to.be.false;
|
||||
expect(obj.timeOffsetMaster).to.equal(expectedTimeSyncOffsetMaster);
|
||||
done();
|
||||
})
|
||||
});
|
||||
ourBoard._processPacketTimeSyncSet(timeSyncSetPacket,timeSetPacketArrived);
|
||||
});
|
||||
it("should reset when bad raw packet", function(done) {
|
||||
var timeSetPacketArrived = ourBoard.time();
|
||||
var badPacket;
|
||||
if (k.getVersionNumber(process.version) >= 6) {
|
||||
// from introduced in node version 6.x.x
|
||||
badPacket = Buffer.from(timeSyncSetPacket.slice(0,30));
|
||||
} else {
|
||||
badPacket = new Buffer(timeSyncSetPacket.slice(0,30));
|
||||
}
|
||||
ourBoard.sync.curSyncObj = openBCISample.newSyncObject();
|
||||
ourBoard._processPacketTimeSyncSet(badPacket,timeSetPacketArrived)
|
||||
.then(() => {
|
||||
done("failed to get rejected");
|
||||
})
|
||||
.catch(function(err) {
|
||||
expect(ourBoard.curParsingMode).to.equal(k.OBCIParsingNormal);
|
||||
expect(ourBoard.sync.curSyncObj).to.be.null;
|
||||
expect(ourBoard.sync.eventEmitter).to.be.null;
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should emit bad synced object bad raw packet", function(done) {
|
||||
var timeSetPacketArrived = ourBoard.time();
|
||||
var expectedTimeSyncOffsetMaster = 72;
|
||||
var badPacket;
|
||||
if (k.getVersionNumber(process.version) >= 6) {
|
||||
// from introduced in node version 6.x.x
|
||||
badPacket = Buffer.from(timeSyncSetPacket.slice(0,30));
|
||||
} else {
|
||||
badPacket = new Buffer(timeSyncSetPacket.slice(0,30));
|
||||
}
|
||||
ourBoard.curParsingMode = k.OBCIParsingTimeSyncSent;
|
||||
ourBoard.sync.curSyncObj = openBCISample.newSyncObject();
|
||||
ourBoard.sync.timeOffsetMaster = expectedTimeSyncOffsetMaster;
|
||||
ourBoard.once('synced',obj => {
|
||||
expect(obj.valid).to.be.false;
|
||||
expect(obj.timeOffsetMaster).to.equal(expectedTimeSyncOffsetMaster);
|
||||
done();
|
||||
});
|
||||
ourBoard._processPacketTimeSyncSet(badPacket,timeSetPacketArrived);
|
||||
});
|
||||
it("should calculate round trip time as the difference between time sent and time set packet arrived",function(done) {
|
||||
var timeSetPacketArrived = ourBoard.time();
|
||||
var expectedRoundTripTime = 20; //ms
|
||||
@@ -1554,7 +1609,7 @@ describe('openbci-sdk',function() {
|
||||
// Pretend that half of buf1 got sent in the first serial flush
|
||||
// and that the last half of it will arrive a lil later
|
||||
var splitPoint = 15;
|
||||
if (process.version > 6) {
|
||||
if (k.getVersionNumber(process.version) >= 6) {
|
||||
// from introduced in node version 6.x.x
|
||||
ourBoard.buffer = Buffer.from(buf1.slice(0,splitPoint));
|
||||
} else {
|
||||
@@ -1593,7 +1648,7 @@ describe('openbci-sdk',function() {
|
||||
|
||||
ourBoard["buffer"] = null;
|
||||
var bufFirstHalf, bufLastHalf;
|
||||
if (process.version > 6) {
|
||||
if (k.getVersionNumber(process.version) >= 6) {
|
||||
// from introduced in node version 6.x.x
|
||||
bufFirstHalf = Buffer.from(buf3.slice(0,splitPoint));
|
||||
bufLastHalf = Buffer.from(buf3.slice(splitPoint));
|
||||
@@ -2881,7 +2936,7 @@ describe('#daisy', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#sync', function() {
|
||||
describe('#syncWhileStreaming', function() {
|
||||
var ourBoard;
|
||||
this.timeout(4000);
|
||||
before(function (done) {
|
||||
@@ -2943,43 +2998,128 @@ describe('#sync', function() {
|
||||
it('can sync while streaming', done => {
|
||||
var syncAfterSamples = 50;
|
||||
var notSynced = true;
|
||||
var syncFunc = obj => {
|
||||
ourBoard.removeListener('sample',samp);
|
||||
done();
|
||||
};
|
||||
var samp = sample => {
|
||||
if (sample.sampleNumber >= syncAfterSamples && notSynced) {
|
||||
notSynced = false;
|
||||
// Call the first one
|
||||
ourBoard.syncClocks().catch(err => done);
|
||||
ourBoard.syncClocks()
|
||||
.catch((err) => {
|
||||
ourBoard.removeListener('sample',samp);
|
||||
ourBoard.removeListener('synced',syncFunc);
|
||||
done();
|
||||
});
|
||||
}
|
||||
};
|
||||
ourBoard.on('sample',samp);
|
||||
// Attached the emitted
|
||||
ourBoard.once('synced',obj => {
|
||||
console.log('syhnc obj', obj);
|
||||
ourBoard.removeListener('sample',samp);
|
||||
done();
|
||||
});
|
||||
ourBoard.once('synced', syncFunc);
|
||||
});
|
||||
});
|
||||
describe('#syncClocksFull', function() {
|
||||
it('can run a full clock sync', done => {
|
||||
var notSynced = true;
|
||||
var sampleFun = sample => {
|
||||
console.log('sample',sample);
|
||||
|
||||
if (notSynced) {
|
||||
notSynced = false;
|
||||
// Call the first one
|
||||
ourBoard.syncClocksFull()
|
||||
.then(syncObj => {
|
||||
console.log(syncObj);
|
||||
if (syncObj.valid) {
|
||||
ourBoard.removeListener('sample',sampleFun);
|
||||
done();
|
||||
} else {
|
||||
ourBoard.removeListener('sample',sampleFun);
|
||||
done("Not able to sync");
|
||||
}
|
||||
}).catch(err => done);
|
||||
}).catch((err) => {
|
||||
ourBoard.removeListener('sample',sampleFun);
|
||||
done();
|
||||
});
|
||||
}
|
||||
};
|
||||
ourBoard.on('sample',sampleFun);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#syncErrors', function() {
|
||||
var ourBoard;
|
||||
this.timeout(4000);
|
||||
before(function (done) {
|
||||
ourBoard = new openBCIBoard.OpenBCIBoard({
|
||||
verbose:true,
|
||||
simulatorFirmwareVersion: 'v2'
|
||||
});
|
||||
var useSim = () => {
|
||||
ourBoard.simulatorEnable()
|
||||
.then(() => {
|
||||
return ourBoard.connect(k.OBCISimulatorPortName);
|
||||
})
|
||||
.then(() => {
|
||||
return ourBoard.softReset();
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
};
|
||||
ourBoard.autoFindOpenBCIBoard()
|
||||
.then(portName => {
|
||||
return setTimeout(() => {
|
||||
console.log('Issuing connect');
|
||||
ourBoard.connect(portName);
|
||||
},500);
|
||||
})
|
||||
.catch((err) => {
|
||||
useSim();
|
||||
})
|
||||
.then(() => {
|
||||
//console.log('connected');
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('Error: ' + err);
|
||||
});
|
||||
|
||||
|
||||
ourBoard.once('ready', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
after(function(done) {
|
||||
if (ourBoard.connected) {
|
||||
ourBoard.disconnect().then(() => {
|
||||
done();
|
||||
}).catch(() => done);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
});
|
||||
afterEach(() => {
|
||||
this.buffer = null;
|
||||
});
|
||||
describe('#syncClocksFull', function() {
|
||||
it('should reject syncClocksFull request because of timeout', done => {
|
||||
var notSynced = true;
|
||||
var sampleFun = sample => {
|
||||
if (notSynced) {
|
||||
notSynced = false;
|
||||
// Call the first one
|
||||
ourBoard.syncClocksFull()
|
||||
.then(syncObj => {
|
||||
done("Should not be able to sync");
|
||||
}).catch((err) => {
|
||||
ourBoard.removeListener('sample',sampleFun);
|
||||
done();
|
||||
});
|
||||
ourBoard.streamStop();
|
||||
}
|
||||
};
|
||||
ourBoard.streamStart()
|
||||
.catch(err => {
|
||||
ourBoard.removeListener('sample',sampleFun);
|
||||
done('coulnd not start stime sync')
|
||||
});
|
||||
ourBoard.on('sample',sampleFun);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário