Skip to content

Commit d633525

Browse files
author
AJ Keller
authored
Merge pull request #94 from aj-ptw/minor-patches
Fix leaked event emitter with time sync, remove extra log statement
2 parents 6fd9ddf + aea599a commit d633525

File tree

7 files changed

+206
-36
lines changed

7 files changed

+206
-36
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@ node_js:
33
- "4.0"
44
- "4.1"
55
- "4.2"
6+
- "4.3"
7+
- "4.4"
8+
- "4.5"
9+
- "4.6"
610
- "5.11.0"
711
- "6.0"
812
- "6.1"
913
- "6.2"
1014
- "6.3"
15+
- "6.4"
16+
- "6.5"
17+
- "6.6"
18+
- "6.7"
19+
- "6.8"
1120
install:
1221
- npm install --all
1322
script:

changelog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# 1.3.3
2+
3+
### New Features
4+
5+
* Add `timeOffsetMaster` to object emitted when bad time sync.
6+
7+
### Bug Fixes
8+
9+
* Fixed log statement on impedance setting function
10+
* Remove event emitter with time sync on reject of sync clock full
11+
112
# 1.3.2
213

314
### Enhancements

examples/timeSync/timeSync.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ var sampleFunc = sample => {
6363
// Resynchronize every every second
6464
if (sample._count % (sampleRate * 1) === 0) {
6565
ourBoard.syncClocksFull()
66-
.then(syncObj => {
67-
// Sync was successful
68-
if (syncObj.valid) {
69-
// Log the object to check it out!
70-
console.log(`timeOffset`,syncObj.timeOffsetMaster);
71-
} else {
72-
// Retry it
73-
console.log(`Was not able to sync... retry!`);
74-
}
75-
});
66+
.then(syncObj => {
67+
// Sync was successful
68+
if (syncObj.valid) {
69+
// Log the object to check it out!
70+
console.log(`timeOffset`,syncObj.timeOffsetMaster);
71+
} else {
72+
// Retry it
73+
console.log(`Was not able to sync... retry!`);
74+
}
75+
});
7676
}
7777

7878
if (sample.timeStamp) { // true after the first successful sync

openBCIBoard.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ function OpenBCIFactory() {
176176
this._lowerChannelsSampleObject = null;
177177
this.sync = {
178178
curSyncObj: null,
179+
eventEmitter: null,
179180
objArray: [],
180181
sntpActive: false,
181182
timeOffsetMaster: 0,
@@ -1327,7 +1328,6 @@ function OpenBCIFactory() {
13271328
if (this.options.verbose) console.log('pInput: ' + pInput + ' nInput: ' + nInput);
13281329
// Get impedance settings to send the board
13291330
k.getImpedanceSetter(channelNumber,pInput,nInput).then((commandsArray) => {
1330-
console.log(commandsArray);
13311331
this.write(commandsArray);
13321332
//delayInMS += commandsArray.length * k.OBCIWriteIntervalDelayMSLong;
13331333
delayInMS += this.commandsToWrite * k.OBCIWriteIntervalDelayMSShort; // Account for commands waiting to be sent in the write buffer
@@ -1564,10 +1564,11 @@ function OpenBCIFactory() {
15641564
if (!this.usingVersionTwoFirmware()) reject('Time sync not implemented on v1 firmware, please update to v2');
15651565
setTimeout(() => {
15661566
return reject('syncClocksFull timeout after 500ms with no sync');
1567-
}, 1000); // Should not take more than 1s to sync up
1568-
this.once('synced',syncObj => {
1567+
}, 500); // Should not take more than 1s to sync up
1568+
this.sync.eventEmitter = syncObj => {
15691569
return resolve(syncObj);
1570-
});
1570+
};
1571+
this.once('synced', this.sync.eventEmitter);
15711572
this.sync.curSyncObj = openBCISample.newSyncObject();
15721573
this.sync.curSyncObj.timeSyncSent = this.time();
15731574
this.curParsingMode = k.OBCIParsingTimeSyncSent;
@@ -1853,7 +1854,9 @@ function OpenBCIFactory() {
18531854
// Fix the curParsingMode back to normal
18541855
this.curParsingMode = k.OBCIParsingNormal;
18551856
// Emit the bad sync object for fun
1856-
this.emit('synced',openBCISample.newSyncObject());
1857+
var badObject = openBCISample.newSyncObject();
1858+
badObject.timeOffsetMaster = this.sync.timeOffsetMaster;
1859+
this.emit('synced', badObject);
18571860
// Set back to null
18581861
this.sync.curSyncObj = null;
18591862
// Return will exit this method with the err
@@ -1951,6 +1954,12 @@ function OpenBCIFactory() {
19511954
return resolve(rawPacket);
19521955
})
19531956
.catch(err => {
1957+
// Emit the bad sync object for fun
1958+
var badObject = openBCISample.newSyncObject();
1959+
badObject.timeOffsetMaster = this.sync.timeOffsetMaster;
1960+
this.emit('synced', badObject);
1961+
// Set back to null
1962+
this.sync.curSyncObj = null;
19541963
console.log('Error in _processPacketTimeSyncSet', err)
19551964
return reject(err);
19561965
});

openBCISample.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,6 @@ function parsePacketTimeSyncedAccel(dataBuf,channelSettingsArray,boardOffsetTime
707707
return new Promise((resolve, reject) => {
708708
// The sample object we are going to build
709709
var sampleObject = {};
710-
711710
if (dataBuf.byteLength != k.OBCIPacketSize) reject("Error [parsePacketTimeSyncedAccel]: input buffer must be " + k.OBCIPacketSize + " bytes!");
712711

713712
// Get the sample number
@@ -803,10 +802,12 @@ function getFromTimePacketTime(dataBuf) {
803802
// Ths packet has 'A0','00'....,'00','00','FF','FF','FF','FF','C3' where the 'FF's are times
804803
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
805804
return new Promise((resolve, reject) => {
806-
if (dataBuf.byteLength != k.OBCIPacketSize) reject("Error [getFromTimePacketTime]: input buffer must be " + k.OBCIPacketSize + " bytes!");
807-
808-
// Grab the time from the packet
809-
resolve(dataBuf.readUInt32BE(lastBytePosition - k.OBCIStreamPacketTimeByteSize));
805+
if (dataBuf.byteLength != k.OBCIPacketSize) {
806+
reject("Error [getFromTimePacketTime]: input buffer must be " + k.OBCIPacketSize + " bytes!");
807+
} else {
808+
// Grab the time from the packet
809+
resolve(dataBuf.readUInt32BE(lastBytePosition - k.OBCIStreamPacketTimeByteSize));
810+
}
810811
});
811812
}
812813

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openbci",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"description": "The official Node.js SDK for the OpenBCI Biosensor Board.",
55
"main": "openBCIBoard",
66
"scripts": {

0 commit comments

Comments
 (0)