Skip to content

Commit 8751b47

Browse files
author
AJ Keller
committed
FIX: Sample objects were inconsistent and closes #147
1 parent 12697be commit 8751b47

File tree

4 files changed

+124
-8
lines changed

4 files changed

+124
-8
lines changed

changelog.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 0.1.2
2+
3+
### Bug Fixes
4+
5+
* Send counts did not work for daisy.
6+
* Sample output was inconsistent
7+
* Fixed `timeStamp` to `timestamp` this was pr #147 (thanks @alexdevmotion)
8+
19
# 0.1.1
210

311
### Bug Fixes

openBCIUtilities.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,9 @@ function parsePacketStandardAccel (o) {
10451045

10461046
sampleObject.valid = true;
10471047

1048+
sampleObject.timestamp = Date.now();
1049+
sampleObject.boardTime = 0;
1050+
10481051
return sampleObject;
10491052
}
10501053

@@ -1090,6 +1093,9 @@ function parsePacketStandardRawAux (o) {
10901093

10911094
sampleObject.valid = true;
10921095

1096+
sampleObject.timestamp = Date.now();
1097+
sampleObject.boardTime = 0;
1098+
10931099
return sampleObject;
10941100
}
10951101

@@ -1130,7 +1136,11 @@ function parsePacketTimeSyncedAccel (o) {
11301136

11311137
// Get the board time
11321138
sampleObject.boardTime = getFromTimePacketTime(o.rawDataPacket);
1133-
sampleObject.timeStamp = sampleObject.boardTime + o.timeOffset;
1139+
if (o.hasOwnProperty('timeOffset')) {
1140+
sampleObject.timestamp = sampleObject.boardTime + o.timeOffset;
1141+
} else {
1142+
sampleObject.timestamp = Date.now();
1143+
}
11341144

11351145
// Extract the aux data
11361146
sampleObject.auxData = getFromTimePacketRawAux(o.rawDataPacket);
@@ -1183,7 +1193,11 @@ function parsePacketTimeSyncedRawAux (o) {
11831193

11841194
// Get the board time
11851195
sampleObject.boardTime = getFromTimePacketTime(o.rawDataPacket);
1186-
sampleObject.timeStamp = sampleObject.boardTime + o.timeOffset;
1196+
if (o.hasOwnProperty('timeOffset')) {
1197+
sampleObject.timestamp = sampleObject.boardTime + o.timeOffset;
1198+
} else {
1199+
sampleObject.timestamp = Date.now();
1200+
}
11871201

11881202
// Extract the aux data
11891203
sampleObject.auxData = getFromTimePacketRawAux(o.rawDataPacket);
@@ -1403,7 +1417,7 @@ function newSample (sampleNumber) {
14031417
auxData: null,
14041418
stopByte: k.OBCIByteStop,
14051419
boardTime: 0,
1406-
timeStamp: 0
1420+
timestamp: 0
14071421
};
14081422
}
14091423

@@ -1496,6 +1510,8 @@ function makeDaisySampleObject (lowerSampleObject, upperSampleObject) {
14961510
daisySampleObject['accelData'] = upperSampleObject.accelData;
14971511
}
14981512

1513+
daisySampleObject['valid'] = true;
1514+
14991515
return daisySampleObject;
15001516
}
15011517

@@ -1547,6 +1563,8 @@ function makeDaisySampleObjectWifi (lowerSampleObject, upperSampleObject) {
15471563
daisySampleObject['accelData'] = upperSampleObject.accelData;
15481564
}
15491565

1566+
daisySampleObject['valid'] = true;
1567+
15501568
return daisySampleObject;
15511569
}
15521570

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openbci-utilities",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "The official utility package of Node.js SDK for the OpenBCI Biosensor Boards.",
55
"main": "index.js",
66
"scripts": {

test/openBCIUtilities-test.js

+94-4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ describe('openBCIUtilities', function () {
5555

5656
expect(sample.sampleNumber).to.equal(0x45);
5757
});
58+
it('should be valid', function () {
59+
let sample = openBCIUtilities.parsePacketStandardAccel({
60+
rawDataPacket: sampleBuf,
61+
channelSettings: defaultChannelSettingsArray,
62+
scale: true
63+
});
64+
expect(sample.valid).to.be.true();
65+
});
5866
it('all the channels should have the same number value as their (index + 1) * scaleFactor', function () {
5967
// sampleBuf has its channel number for each 3 byte integer. See line 20...
6068
let sample = openBCIUtilities.parsePacketStandardAccel({
@@ -138,6 +146,23 @@ describe('openBCIUtilities', function () {
138146
samplesReceived++;
139147
}
140148
});
149+
it('should be have time stamp when none given', function () {
150+
let sample = openBCIUtilities.parsePacketStandardAccel({
151+
rawDataPacket: sampleBuf,
152+
channelSettings: defaultChannelSettingsArray,
153+
scale: true
154+
});
155+
expect(sample.boardTime).to.equal(0);
156+
expect(sample.timestamp).to.be.greaterThan(0);
157+
});
158+
it('should be valid', function () {
159+
let sample = openBCIUtilities.parsePacketStandardAccel({
160+
rawDataPacket: sampleBuf,
161+
channelSettings: defaultChannelSettingsArray,
162+
scale: true
163+
});
164+
expect(sample.valid).to.be.true();
165+
});
141166
it('has the right sample number', function () {
142167
let expectedSampleNumber = 0x45;
143168
let sample = openBCIUtilities.parsePacketStandardAccel({
@@ -246,6 +271,25 @@ describe('openBCIUtilities', function () {
246271
});
247272
expect(sample.sampleNumber).to.equal(expectedSampleNumber);
248273
});
274+
it('should be valid', function () {
275+
packet = openBCIUtilities.samplePacketStandardRawAux(0);
276+
let sample = openBCIUtilities.parsePacketStandardRawAux({
277+
rawDataPacket: packet,
278+
channelSettings: defaultChannelSettingsArray,
279+
scale: true
280+
});
281+
expect(sample.valid).to.be.true();
282+
});
283+
it('should be have time stamp when none given', function () {
284+
packet = openBCIUtilities.samplePacketStandardRawAux(0);
285+
let sample = openBCIUtilities.parsePacketStandardRawAux({
286+
rawDataPacket: packet,
287+
channelSettings: defaultChannelSettingsArray,
288+
scale: true
289+
});
290+
expect(sample.boardTime).to.equal(0);
291+
expect(sample.timestamp).to.be.greaterThan(0);
292+
});
249293
it('has the right stop byte', function () {
250294
packet = openBCIUtilities.samplePacketStandardRawAux(0);
251295
let sample = openBCIUtilities.parsePacketStandardRawAux({
@@ -423,6 +467,25 @@ describe('openBCIUtilities', function () {
423467
expect(channelValue).to.equal(index + 1);
424468
});
425469
});
470+
it('should be have time stamp when none given', function () {
471+
packet1 = openBCIUtilities.samplePacketAccelTimeSynced(0);
472+
let sample = openBCIUtilities.parsePacketTimeSyncedAccel({
473+
rawDataPacket: packet1,
474+
channelSettings: defaultChannelSettingsArray,
475+
scale: true
476+
});
477+
expect(sample.boardTime).to.equal(1);
478+
expect(sample.timestamp).to.be.greaterThan(0);
479+
});
480+
it('should be valid', function () {
481+
packet1 = openBCIUtilities.samplePacketAccelTimeSynced(0);
482+
let sample = openBCIUtilities.parsePacketTimeSyncedAccel({
483+
rawDataPacket: packet1,
484+
channelSettings: defaultChannelSettingsArray,
485+
scale: true
486+
});
487+
expect(sample.valid).to.be.true();
488+
});
426489
it('has the right sample number', function () {
427490
let expectedSampleNumber = 69;
428491
packet1 = openBCIUtilities.samplePacketAccelTimeSynced(expectedSampleNumber);
@@ -519,6 +582,25 @@ describe('openBCIUtilities', function () {
519582
expect(channelValue).to.equal(index + 1);
520583
});
521584
});
585+
it('should be valid', function () {
586+
packet = openBCIUtilities.samplePacketRawAuxTimeSynced(0);
587+
let sample = openBCIUtilities.parsePacketTimeSyncedRawAux({
588+
rawDataPacket: packet,
589+
channelSettings: defaultChannelSettingsArray,
590+
scale: true
591+
});
592+
expect(sample.valid).to.be.true();
593+
});
594+
it('should be have time stamp when none given', function () {
595+
packet = openBCIUtilities.samplePacketRawAuxTimeSynced(0);
596+
let sample = openBCIUtilities.parsePacketTimeSyncedRawAux({
597+
rawDataPacket: packet,
598+
channelSettings: defaultChannelSettingsArray,
599+
scale: true
600+
});
601+
expect(sample.boardTime).to.equal(1);
602+
expect(sample.timestamp).to.be.greaterThan(0);
603+
});
522604
it('has the right sample number', function () {
523605
let expectedSampleNumber = 69;
524606
packet = openBCIUtilities.samplePacketRawAuxTimeSynced(expectedSampleNumber);
@@ -689,8 +771,8 @@ describe('openBCIUtilities', function () {
689771
timeOffset: timeOffset,
690772
accelArray
691773
});
692-
expect(sample.timeStamp).to.exist();
693-
expect(sample.timeStamp).to.equal(time + timeOffset);
774+
expect(sample.timestamp).to.exist();
775+
expect(sample.timestamp).to.equal(time + timeOffset);
694776
});
695777
});
696778
describe('#convertSampleToPacketRawAuxTimeSynced', function () {
@@ -755,8 +837,8 @@ describe('openBCIUtilities', function () {
755837
timeOffset: timeOffset,
756838
scale: false
757839
});
758-
expect(sample.timeStamp).to.exist();
759-
expect(sample.timeStamp).to.equal(time + timeOffset);
840+
expect(sample.timestamp).to.exist();
841+
expect(sample.timestamp).to.equal(time + timeOffset);
760842
});
761843
});
762844
describe('#interpret24bitAsInt32', function () {
@@ -947,6 +1029,10 @@ describe('openBCIUtilities', function () {
9471029
// Call the function under test
9481030
daisySampleObjectNoScale = openBCIUtilities.makeDaisySampleObject(lowerSampleObjectNoScale, upperSampleObjectNoScale);
9491031
});
1032+
it('should have valid object true', function () {
1033+
expect(daisySampleObject.valid).to.be.true();
1034+
expect(daisySampleObjectNoScale.valid).to.be.true();
1035+
});
9501036
it('should make a channelData array 16 elements long', function () {
9511037
expect(daisySampleObject.channelData).to.have.length(k.OBCINumberOfChannelsDaisy);
9521038
expect(daisySampleObjectNoScale.channelDataCounts).to.have.length(k.OBCINumberOfChannelsDaisy);
@@ -1024,6 +1110,10 @@ describe('openBCIUtilities', function () {
10241110
// Call the function under test
10251111
daisySampleObjectNoScale = openBCIUtilities.makeDaisySampleObjectWifi(lowerSampleObjectNoScale, upperSampleObjectNoScale);
10261112
});
1113+
it('should have valid object true', function () {
1114+
expect(daisySampleObject.valid).to.be.true();
1115+
expect(daisySampleObjectNoScale.valid).to.be.true();
1116+
});
10271117
it('should make a channelData array 16 elements long', function () {
10281118
expect(daisySampleObject.channelData).to.have.length(k.OBCINumberOfChannelsDaisy);
10291119
expect(daisySampleObjectNoScale.channelDataCounts).to.have.length(k.OBCINumberOfChannelsDaisy);

0 commit comments

Comments
 (0)