Skip to content

Commit 0b7e199

Browse files
author
AJ Keller
authored
Merge pull request #30 from aj-ptw/master
FIX: ganglion messages not processed properly
2 parents ec75e84 + 9ba4b9e commit 0b7e199

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# v0.3.6
2+
3+
### Bug Fixes
4+
5+
* Fix bug where parseGanglion could result in a concat of non-buffer types
6+
17
# v0.3.5
28

39
### Bug Fixes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openbci-utilities",
3-
"version": "0.3.5",
3+
"version": "0.3.6",
44
"description": "The official utility package of Node.js SDK for the OpenBCI Biosensor Boards.",
55
"main": "dist/openbci-utilities.js",
66
"module": "src/index.js",

src/utilities.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,9 @@ let utilitiesModule = {
728728
0b00000111 // 19
729729
]);
730730
},
731-
parseGanglion
731+
parseGanglion,
732+
processMultiBytePacket,
733+
processMultiBytePacketStop
732734
};
733735

734736
/**
@@ -860,7 +862,7 @@ function processImpedanceData (o) {
860862
*/
861863
function processMultiBytePacket (o) {
862864
if (o.multiPacketBuffer) {
863-
o.multiPacketBuffer = Buffer.concat([o.multiPacketBuffer, o.rawDataPacket.slice(k.OBCIGanglionPacket19Bit.dataStart, k.OBCIGanglionPacket19Bit.dataStop)]);
865+
o.multiPacketBuffer = Buffer.concat([Buffer.from(o.multiPacketBuffer), Buffer.from(o.rawDataPacket.slice(k.OBCIGanglionPacket19Bit.dataStart, k.OBCIGanglionPacket19Bit.dataStop))]);
864866
} else {
865867
o.multiPacketBuffer = o.rawDataPacket.slice(k.OBCIGanglionPacket19Bit.dataStart, k.OBCIGanglionPacket19Bit.dataStop);
866868
}
@@ -873,9 +875,11 @@ function processMultiBytePacket (o) {
873875
*/
874876
function processMultiBytePacketStop (o) {
875877
processMultiBytePacket(o);
876-
const str = o.multiPacketBuffer;
878+
const str = o.multiPacketBuffer.toString();
877879
o.multiPacketBuffer = null;
878-
return str;
880+
return {
881+
'message': str
882+
};
879883
}
880884

881885
/**

test/openBCIUtilities-test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,43 @@ describe('openBCIUtilities', function () {
3737
accelArray = [0, 0, 0];
3838
});
3939
afterEach(() => bluebirdChecks.noPendingPromises());
40+
describe('#processMultiBytePacketStop', function () {
41+
it('should output the message', function () {
42+
const rawBuf = Buffer.from([0xCF, 0x65, 0x64, 0x0A]);
43+
44+
const expectedOutput = 'ed\n';
45+
46+
const actualOutput = openBCIUtilities.processMultiBytePacketStop({
47+
multiPacketBuffer: null,
48+
rawDataPacket: rawBuf
49+
});
50+
expect(actualOutput.message).to.equal(expectedOutput);
51+
});
52+
});
53+
describe('#processMultiBytePacket', function () {
54+
it('should be convert raw data packtet to string', function () {
55+
const rawBufMulti = Buffer.from([0xCE, 0x61, 0x63, 0x63, 0x65, 0x6C, 0x65, 0x72, 0x6F, 0x6D, 0x65, 0x74, 0x65, 0x72, 0x20, 0x65, 0x6E, 0x61, 0x62, 0x6C]);
56+
57+
const expectedRawBufMulti = Buffer.from([0x61, 0x63, 0x63, 0x65, 0x6C, 0x65, 0x72, 0x6F, 0x6D, 0x65, 0x74, 0x65, 0x72, 0x20, 0x65, 0x6E, 0x61, 0x62, 0x6C]);
58+
59+
const o = {};
60+
o.rawDataPacket = rawBufMulti;
61+
openBCIUtilities.processMultiBytePacket(o);
62+
expect(o.multiPacketBuffer.toString()).to.equal(expectedRawBufMulti.toString());
63+
});
64+
it('should be able to concat multi byte messages', function () {
65+
const rawBufMulti = Buffer.from([0xCE, 0x61, 0x63, 0x63, 0x65, 0x6C, 0x65, 0x72, 0x6F, 0x6D, 0x65, 0x74, 0x65, 0x72, 0x20, 0x65, 0x6E, 0x61, 0x62, 0x6C]);
66+
const o = {
67+
multiPacketBuffer: rawBufMulti.slice(1).toString()
68+
};
69+
const rawBufStop = Buffer.from([0xCF, 0x65, 0x64, 0x0A]);
70+
const expectedRawBufMulti = Buffer.from([0x61, 0x63, 0x63, 0x65, 0x6C, 0x65, 0x72, 0x6F, 0x6D, 0x65, 0x74, 0x65, 0x72, 0x20, 0x65, 0x6E, 0x61, 0x62, 0x6C, 0x65, 0x64, 0x0A]);
71+
72+
o.rawDataPacket = rawBufStop;
73+
openBCIUtilities.processMultiBytePacket(o);
74+
expect(o.multiPacketBuffer.toString()).to.equal(expectedRawBufMulti.toString());
75+
});
76+
});
4077
describe('#convertGanglionArrayToBuffer', function () {
4178
it('should fill the packet with values from data', function () {
4279
const numChannels = k.numberOfChannelsForBoardType(k.OBCIBoardGanglion);

0 commit comments

Comments
 (0)