Skip to content

Commit 9ba4b9e

Browse files
author
AJ Keller
committed
ADD: tests to ensure proper operation for multi packet messages
1 parent ffac915 commit 9ba4b9e

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/utilities.js

Lines changed: 3 additions & 1 deletion
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
/**

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)