Skip to content

Commit e88b405

Browse files
author
AJ Keller
committed
FEAT: add new firmware version extracting function
1 parent ea423f1 commit e88b405

File tree

4 files changed

+37
-62
lines changed

4 files changed

+37
-62
lines changed

Diff for: changelog.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
# 0.0.11
1+
# 0.1.0
22

33
### New Functions
44

5-
* Add functions to help determine the board firmware version
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
610

711
# 0.0.10
812

Diff for: openBCIUtilities.js

+15-23
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,7 @@ var utilitiesModule = {
555555
isOdd,
556556
countADSPresent,
557557
doesBufferHaveEOT,
558-
findV2Firmware,
559-
getMajorFirmwareVersion,
558+
getFirmware,
560559
isFailureInBuffer,
561560
isSuccessInBuffer,
562561
isTimeSyncSetConfirmationInBuffer,
@@ -1604,28 +1603,21 @@ function doesBufferHaveEOT (dataBuffer) {
16041603
}
16051604

16061605
/**
1607-
* @description Used to parse a soft reset response to determine if the board is running the v2 firmware
1608-
* @param dataBuffer {Buffer} - The data to parse
1609-
* @returns {boolean} - True if `v2`is indeed found in the `dataBuffer`
1610-
*/
1611-
function findV2Firmware (dataBuffer) {
1612-
const s = new StreamSearch(new Buffer(k.OBCIParseFirmware));
1613-
1614-
// Clear the buffer
1615-
s.reset();
1616-
1617-
// Push the new data buffer. This runs the search.
1618-
s.push(dataBuffer);
1619-
1620-
// Check and see if there is a match
1621-
return s.matches >= 1;
1622-
}
1623-
1624-
function getMajorFirmwareVersion (dataBuffer) {
1625-
const regexPattern = /v\d/;
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/;
16261612
const ret = dataBuffer.toString().match(regexPattern);
1627-
if (ret) return ret[0];
1628-
else return ret;
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;
16291621
}
16301622

16311623
/**

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

+15-36
Original file line numberDiff line numberDiff line change
@@ -1319,72 +1319,51 @@ $$$`);
13191319
expect(openBCIUtilities.doesBufferHaveEOT(buf)).to.equal(true);
13201320
});
13211321
});
1322-
describe('#findV2Firmware', function () {
1323-
it('should not crash on small buff', function () {
1324-
let buf = new Buffer('AJ!');
1325-
1326-
expect(openBCIUtilities.findV2Firmware(buf)).to.be.false();
1327-
});
1328-
it('should not find any v2', function () {
1329-
let buf = new Buffer('AJ Keller is an awesome programmer!\n I know right!');
1330-
1331-
expect(openBCIUtilities.findV2Firmware(buf)).to.be.false();
1332-
});
1333-
it('should not find a v2', function () {
1334-
let buf = new Buffer(`OpenBCI V3 Simulator
1335-
On Board ADS1299 Device ID: 0x12345
1336-
LIS3DH Device ID: 0x38422$$$`);
1337-
1338-
expect(openBCIUtilities.findV2Firmware(buf)).to.be.false();
1339-
});
1340-
it('should find a v2', function () {
1341-
let buf = new Buffer(`OpenBCI V3 Simulator
1342-
On Board ADS1299 Device ID: 0x12345
1343-
On Daisy ADS1299 Device ID: 0xFFFFF
1344-
LIS3DH Device ID: 0x38422
1345-
Firmware: v2.0.0
1346-
$$$`);
1347-
1348-
expect(openBCIUtilities.findV2Firmware(buf)).to.equal(true);
1349-
});
1350-
});
13511322
describe('#getMajorFirmwareVersion', function () {
13521323
it('should not crash on small buff', function () {
13531324
let buf = new Buffer('AJ!');
13541325

1355-
expect(openBCIUtilities.getMajorFirmwareVersion(buf)).to.equal(null);
1326+
expect(openBCIUtilities.getFirmware(buf)).to.equal(null);
13561327
});
13571328
it('should not find any v2', function () {
13581329
let buf = new Buffer('AJ Keller is an awesome programmer!\n I know right!');
13591330

1360-
expect(openBCIUtilities.getMajorFirmwareVersion(buf)).to.equal(null)
1331+
expect(openBCIUtilities.getFirmware(buf)).to.equal(null)
13611332
});
13621333
it('should not find a v2', function () {
13631334
let buf = new Buffer(`OpenBCI V3 Simulator
13641335
On Board ADS1299 Device ID: 0x12345
13651336
LIS3DH Device ID: 0x38422$$$`);
13661337

1367-
expect(openBCIUtilities.getMajorFirmwareVersion(buf)).to.equal(null)
1338+
expect(openBCIUtilities.getFirmware(buf)).to.equal(null)
13681339
});
13691340
it('should find a v2', function () {
13701341
let buf = new Buffer(`OpenBCI V3 Simulator
13711342
On Board ADS1299 Device ID: 0x12345
13721343
On Daisy ADS1299 Device ID: 0xFFFFF
13731344
LIS3DH Device ID: 0x38422
1374-
Firmware: v2.0.0
1345+
Firmware: v2.0.1
13751346
$$$`);
13761347

1377-
expect(openBCIUtilities.getMajorFirmwareVersion(buf)).to.equal('v2');
1348+
expect(openBCIUtilities.getFirmware(buf)).to.deep.equal({
1349+
major: 2,
1350+
minor: 0,
1351+
patch: 1
1352+
});
13781353
});
13791354
it('should find a v3', function () {
13801355
let buf = new Buffer(`OpenBCI V3 Simulator
13811356
On Board ADS1299 Device ID: 0x12345
13821357
On Daisy ADS1299 Device ID: 0xFFFFF
13831358
LIS3DH Device ID: 0x38422
1384-
Firmware: v3.0.0
1359+
Firmware: v3.0.1
13851360
$$$`);
13861361

1387-
expect(openBCIUtilities.getMajorFirmwareVersion(buf)).to.equal('v3');
1362+
expect(openBCIUtilities.getFirmware(buf)).to.deep.equal({
1363+
major: 3,
1364+
minor: 0,
1365+
patch: 1
1366+
});
13881367
});
13891368
});
13901369
describe('#isFailureInBuffer', function () {

0 commit comments

Comments
 (0)