Skip to content

Commit a164843

Browse files
author
AJ Keller
committed
ADD: Code and functions for ganglion
1 parent 6fc6205 commit a164843

File tree

4 files changed

+96
-1
lines changed

4 files changed

+96
-1
lines changed

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 0.2.1
2+
3+
### New Features
4+
5+
* Add features for `openbci-ganglion`
6+
17
# 0.2.0
28

39
### New Feature

openBCIUtilities.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ let utilitiesModule = {
141141
},
142142
transformRawDataPacketToSample,
143143
transformRawDataPacketsToSample,
144+
convertGanglionArrayToBuffer,
144145
getRawPacketType,
145146
getFromTimePacketAccel,
146147
getFromTimePacketTime,
@@ -1041,6 +1042,18 @@ function transformRawDataPacketToSample (o) {
10411042
return sample;
10421043
}
10431044

1045+
/**
1046+
* Used to convert a ganglions decompressed back into a buffer
1047+
* @param arr {Array} - An array of four numbers
1048+
* @param data {Buffer} - A buffer to store into
1049+
*/
1050+
function convertGanglionArrayToBuffer (arr, data) {
1051+
for (let i = 0; i < k.OBCINumberOfChannelsGanglion; i++) {
1052+
let threeByteBuffer = floatTo3ByteBuffer(arr[i]);
1053+
threeByteBuffer.copy(data, (i * 3));
1054+
}
1055+
}
1056+
10441057
/**
10451058
* @description This function takes a raw data buffer of 4 3-byte signed integers for ganglion
10461059
* @param o {Object} - The input object

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.2.0",
3+
"version": "0.2.1",
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

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,82 @@ describe('openBCIUtilities', function () {
3737
accelArray = [0, 0, 0];
3838
});
3939
afterEach(() => bluebirdChecks.noPendingPromises());
40+
describe('#convertGanglionArrayToBuffer', function () {
41+
it('should fill the packet with values from data', function () {
42+
const numChannels = k.numberOfChannelsForBoardType(k.OBCIBoardGanglion);
43+
let arr = [0,1,2,3];
44+
let rawDataPacket = k.rawDataToSampleObjectDefault(numChannels).rawDataPacket;
45+
rawDataPacket.fill(0); // fill with zeros
46+
let bleRawBuf = openBCIUtilities.convertGanglionArrayToBuffer(arr, data);
47+
const sampleNumber = 23;
48+
openBCIUtilities.ganglionFillRawDataPacket({
49+
data: bleRawBuf,
50+
rawDataPacket,
51+
sampleNumber
52+
});
53+
expect(bufferEqual(rawDataPacket.slice(2, 2 + k.OBCIPacketSizeBLERaw), bleRawBuf), `expected ${bleRawBuf.toString('hex')} but got ${rawDataPacket.slice(2, 2 + k.OBCIPacketSizeBLERaw).toString('hex')}`).to.be.true();
54+
expect(rawDataPacket[k.OBCIPacketPositionSampleNumber]).to.equal(sampleNumber);
55+
expect(rawDataPacket[k.OBCIPacketPositionStartByte]).to.equal(k.OBCIByteStart);
56+
expect(rawDataPacket[k.OBCIPacketPositionStopByte]).to.equal(k.OBCIStreamPacketStandardRawAux);
57+
});
58+
describe('#errorConditions', function () {
59+
it('send undefined data buffer', function () {
60+
expect(openBCIUtilities.ganglionFillRawDataPacket.bind(openBCIUtilities, {
61+
rawDataPacket: Buffer.alloc(k.OBCIPacketSize),
62+
sampleNumber: 0
63+
})).to.throw(k.OBCIErrorUndefinedOrNullInput);
64+
});
65+
it('send null data buffer', function () {
66+
expect(openBCIUtilities.ganglionFillRawDataPacket.bind(openBCIUtilities, {
67+
data: null,
68+
rawDataPacket: Buffer.alloc(k.OBCIPacketSize),
69+
sampleNumber: 0
70+
})).to.throw(k.OBCIErrorUndefinedOrNullInput);
71+
});
72+
it('send undefined rawDataPacket buffer', function () {
73+
expect(openBCIUtilities.ganglionFillRawDataPacket.bind(openBCIUtilities, {
74+
data: Buffer.alloc(k.OBCIPacketSizeBLERaw),
75+
sampleNumber: 0
76+
})).to.throw(k.OBCIErrorUndefinedOrNullInput);
77+
});
78+
it('send null rawDataPacket buffer', function () {
79+
expect(openBCIUtilities.ganglionFillRawDataPacket.bind(openBCIUtilities, {
80+
data: Buffer.alloc(k.OBCIPacketSizeBLERaw),
81+
rawDataPacket: null,
82+
sampleNumber: 0
83+
})).to.throw(k.OBCIErrorUndefinedOrNullInput);
84+
});
85+
it('no sample number', function () {
86+
expect(openBCIUtilities.ganglionFillRawDataPacket.bind(openBCIUtilities, {
87+
data: Buffer.alloc(k.OBCIPacketSizeBLERaw),
88+
rawDataPacket: Buffer.alloc(k.OBCIPacketSize)
89+
})).to.throw(k.OBCIErrorUndefinedOrNullInput);
90+
});
91+
it('wrong number of bytes rawDataPacket', function () {
92+
expect(openBCIUtilities.ganglionFillRawDataPacket.bind(openBCIUtilities, {
93+
data: Buffer.alloc(k.OBCIPacketSizeBLERaw),
94+
rawDataPacket: Buffer.alloc(5),
95+
sampleNumber: 0
96+
})).to.throw(k.OBCIErrorInvalidByteLength);
97+
});
98+
it('wrong number of bytes data', function () {
99+
expect(openBCIUtilities.ganglionFillRawDataPacket.bind(openBCIUtilities, {
100+
data: Buffer.alloc(5),
101+
rawDataPacket: Buffer.alloc(k.OBCIPacketSize),
102+
sampleNumber: 0
103+
})).to.throw(k.OBCIErrorInvalidByteLength);
104+
});
105+
it('undefined', function () {
106+
expect(openBCIUtilities.ganglionFillRawDataPacket.bind(openBCIUtilities)).to.throw(k.OBCIErrorUndefinedOrNullInput);
107+
expect(openBCIUtilities.ganglionFillRawDataPacket.bind(openBCIUtilities), {
108+
rawDataPacket: Buffer.alloc(k.OBCIPacketSize)
109+
}).to.throw(k.OBCIErrorUndefinedOrNullInput);
110+
expect(openBCIUtilities.ganglionFillRawDataPacket.bind(openBCIUtilities), {
111+
data: Buffer.alloc(k.OBCIPacketSizeBLERaw)
112+
}).to.throw(k.OBCIErrorUndefinedOrNullInput);
113+
});
114+
});
115+
});
40116
describe('#ganglionFillRawDataPacket', function () {
41117
it('should fill the packet with values from data', function () {
42118
const numChannels = k.numberOfChannelsForBoardType(k.OBCIBoardGanglion);

0 commit comments

Comments
 (0)