Skip to content

Commit 676c0d1

Browse files
author
AJ Keller
committed
2 parents 08e3628 + 392cb14 commit 676c0d1

File tree

4 files changed

+51
-23
lines changed

4 files changed

+51
-23
lines changed

Diff for: 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

Diff for: 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,
@@ -1609,21 +1609,21 @@ function doesBufferHaveEOT (dataBuffer) {
16091609
}
16101610

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

16291629
/**

Diff for: 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": {

Diff for: test/openBCIUtilities-test.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -1345,33 +1345,51 @@ $$$`);
13451345
expect(openBCIUtilities.doesBufferHaveEOT(buf)).to.equal(true);
13461346
});
13471347
});
1348-
describe('#findV2Firmware', function () {
1348+
describe('#getMajorFirmwareVersion', function () {
13491349
it('should not crash on small buff', function () {
13501350
let buf = new Buffer('AJ!');
13511351

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

1357-
expect(openBCIUtilities.findV2Firmware(buf)).to.be.false();
1357+
expect(openBCIUtilities.getFirmware(buf)).to.equal(null);
13581358
});
13591359
it('should not find a v2', function () {
13601360
let buf = new Buffer(`OpenBCI V3 Simulator
13611361
On Board ADS1299 Device ID: 0x12345
13621362
LIS3DH Device ID: 0x38422$$$`);
13631363

1364-
expect(openBCIUtilities.findV2Firmware(buf)).to.be.false();
1364+
expect(openBCIUtilities.getFirmware(buf)).to.equal(null);
13651365
});
13661366
it('should find a v2', function () {
13671367
let buf = new Buffer(`OpenBCI V3 Simulator
13681368
On Board ADS1299 Device ID: 0x12345
13691369
On Daisy ADS1299 Device ID: 0xFFFFF
13701370
LIS3DH Device ID: 0x38422
1371-
Firmware: v2
1371+
Firmware: v2.0.1
1372+
$$$`);
1373+
1374+
expect(openBCIUtilities.getFirmware(buf)).to.deep.equal({
1375+
major: 2,
1376+
minor: 0,
1377+
patch: 1
1378+
});
1379+
});
1380+
it('should find a v3', function () {
1381+
let buf = new Buffer(`OpenBCI V3 Simulator
1382+
On Board ADS1299 Device ID: 0x12345
1383+
On Daisy ADS1299 Device ID: 0xFFFFF
1384+
LIS3DH Device ID: 0x38422
1385+
Firmware: v3.0.1
13721386
$$$`);
13731387

1374-
expect(openBCIUtilities.findV2Firmware(buf)).to.equal(true);
1388+
expect(openBCIUtilities.getFirmware(buf)).to.deep.equal({
1389+
major: 3,
1390+
minor: 0,
1391+
patch: 1
1392+
});
13751393
});
13761394
});
13771395
describe('#isFailureInBuffer', function () {

0 commit comments

Comments
 (0)