Skip to content

Commit 392cb14

Browse files
author
AJ Keller
authored
Merge pull request #8 from aj-ptw/master
v0.1.0
2 parents 12d4977 + c7e3a05 commit 392cb14

File tree

4 files changed

+51
-23
lines changed

4 files changed

+51
-23
lines changed

changelog.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# 0.1.0
2+
3+
### New Functions
4+
5+
* Add function `getFirmware(dataBuffer)` to utilities
6+
7+
### Breaking Changes
8+
9+
* Removed function called `findV2Firmware()` because it's useless with v3.0.0 firmware
10+
111
# 0.0.10
212

313
### New Function

openBCIUtilities.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ var utilitiesModule = {
555555
isOdd,
556556
countADSPresent,
557557
doesBufferHaveEOT,
558-
findV2Firmware,
558+
getFirmware,
559559
isFailureInBuffer,
560560
isSuccessInBuffer,
561561
isTimeSyncSetConfirmationInBuffer,
@@ -1603,21 +1603,21 @@ function doesBufferHaveEOT (dataBuffer) {
16031603
}
16041604

16051605
/**
1606-
* @description Used to parse a soft reset response to determine if the board is running the v2 firmware
1607-
* @param dataBuffer {Buffer} - The data to parse
1608-
* @returns {boolean} - True if `v2`is indeed found in the `dataBuffer`
1609-
*/
1610-
function findV2Firmware (dataBuffer) {
1611-
const s = new StreamSearch(new Buffer(k.OBCIParseFirmware));
1612-
1613-
// Clear the buffer
1614-
s.reset();
1615-
1616-
// Push the new data buffer. This runs the search.
1617-
s.push(dataBuffer);
1618-
1619-
// Check and see if there is a match
1620-
return s.matches >= 1;
1606+
* Used to extract the major version from
1607+
* @param dataBuffer
1608+
* @return {*}
1609+
*/
1610+
function getFirmware (dataBuffer) {
1611+
const regexPattern = /v\d.\d.\d/;
1612+
const ret = dataBuffer.toString().match(regexPattern);
1613+
if (ret) {
1614+
const elems = ret[0].split('.');
1615+
return {
1616+
major: Number(elems[0][1]),
1617+
minor: Number(elems[1]),
1618+
patch: Number(elems[2])
1619+
};
1620+
} else return ret;
16211621
}
16221622

16231623
/**

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openbci-utilities",
3-
"version": "0.0.10",
3+
"version": "0.1.0",
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

+24-6
Original file line numberDiff line numberDiff line change
@@ -1319,33 +1319,51 @@ $$$`);
13191319
expect(openBCIUtilities.doesBufferHaveEOT(buf)).to.equal(true);
13201320
});
13211321
});
1322-
describe('#findV2Firmware', function () {
1322+
describe('#getMajorFirmwareVersion', function () {
13231323
it('should not crash on small buff', function () {
13241324
let buf = new Buffer('AJ!');
13251325

1326-
expect(openBCIUtilities.findV2Firmware(buf)).to.be.false();
1326+
expect(openBCIUtilities.getFirmware(buf)).to.equal(null);
13271327
});
13281328
it('should not find any v2', function () {
13291329
let buf = new Buffer('AJ Keller is an awesome programmer!\n I know right!');
13301330

1331-
expect(openBCIUtilities.findV2Firmware(buf)).to.be.false();
1331+
expect(openBCIUtilities.getFirmware(buf)).to.equal(null);
13321332
});
13331333
it('should not find a v2', function () {
13341334
let buf = new Buffer(`OpenBCI V3 Simulator
13351335
On Board ADS1299 Device ID: 0x12345
13361336
LIS3DH Device ID: 0x38422$$$`);
13371337

1338-
expect(openBCIUtilities.findV2Firmware(buf)).to.be.false();
1338+
expect(openBCIUtilities.getFirmware(buf)).to.equal(null);
13391339
});
13401340
it('should find a v2', function () {
13411341
let buf = new Buffer(`OpenBCI V3 Simulator
13421342
On Board ADS1299 Device ID: 0x12345
13431343
On Daisy ADS1299 Device ID: 0xFFFFF
13441344
LIS3DH Device ID: 0x38422
1345-
Firmware: v2
1345+
Firmware: v2.0.1
1346+
$$$`);
1347+
1348+
expect(openBCIUtilities.getFirmware(buf)).to.deep.equal({
1349+
major: 2,
1350+
minor: 0,
1351+
patch: 1
1352+
});
1353+
});
1354+
it('should find a v3', function () {
1355+
let buf = new Buffer(`OpenBCI V3 Simulator
1356+
On Board ADS1299 Device ID: 0x12345
1357+
On Daisy ADS1299 Device ID: 0xFFFFF
1358+
LIS3DH Device ID: 0x38422
1359+
Firmware: v3.0.1
13461360
$$$`);
13471361

1348-
expect(openBCIUtilities.findV2Firmware(buf)).to.equal(true);
1362+
expect(openBCIUtilities.getFirmware(buf)).to.deep.equal({
1363+
major: 3,
1364+
minor: 0,
1365+
patch: 1
1366+
});
13491367
});
13501368
});
13511369
describe('#isFailureInBuffer', function () {

0 commit comments

Comments
 (0)