Initial pass at getting the firmware version

This commit is contained in:
Nathan Kellenicki 2019-01-16 11:41:44 -08:00
parent 363eb5f4d0
commit c6c470e863
4 changed files with 162 additions and 6 deletions

64
DOCS.md
View File

@ -92,6 +92,7 @@ Emits when a Powered UP Hub device is found.
* [WeDo2SmartHub](#WeDo2SmartHub) ⇐ <code>Hub</code>
* [new WeDo2SmartHub()](#new_WeDo2SmartHub_new)
* [.name](#Hub+name)
* [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@ -135,6 +136,17 @@ The WeDo2SmartHub is emitted if the discovered device is a WeDo 2.0 Smart Hub.
| --- | --- | --- |
| name | <code>string</code> | Name of the hub |
<a name="Hub+firmwareVersion"></a>
### weDo2SmartHub.firmwareVersion
**Kind**: instance property of [<code>WeDo2SmartHub</code>](#WeDo2SmartHub)
**Read only**: true
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| firmwareVersion | <code>string</code> | Firmware version of the hub |
<a name="Hub+uuid"></a>
### weDo2SmartHub.uuid
@ -453,6 +465,7 @@ Emits when an attached motor or sensor is detached from the Hub.
* [new BoostMoveHub()](#new_BoostMoveHub_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
* [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@ -509,6 +522,18 @@ The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
| --- | --- | --- |
| name | <code>string</code> | Name of the hub |
<a name="Hub+firmwareVersion"></a>
### boostMoveHub.firmwareVersion
**Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>firmwareVersion</code>](#Hub+firmwareVersion)
**Read only**: true
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| firmwareVersion | <code>string</code> | Firmware version of the hub |
<a name="Hub+uuid"></a>
### boostMoveHub.uuid
@ -853,6 +878,7 @@ Emits when an attached motor or sensor is detached from the Hub.
* [new PUPHub()](#new_PUPHub_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
* [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@ -907,6 +933,18 @@ The PUPHub is emitted if the discovered device is a Powered UP Hub.
| --- | --- | --- |
| name | <code>string</code> | Name of the hub |
<a name="Hub+firmwareVersion"></a>
### pupHub.firmwareVersion
**Kind**: instance property of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>firmwareVersion</code>](#Hub+firmwareVersion)
**Read only**: true
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| firmwareVersion | <code>string</code> | Firmware version of the hub |
<a name="Hub+uuid"></a>
### pupHub.uuid
@ -1225,6 +1263,7 @@ Emits when an attached motor or sensor is detached from the Hub.
* [new PUPRemote()](#new_PUPRemote_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
* [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@ -1270,6 +1309,18 @@ The PUPRemote is emitted if the discovered device is a Powered UP Remote.
| --- | --- | --- |
| name | <code>string</code> | Name of the hub |
<a name="Hub+firmwareVersion"></a>
### pupRemote.firmwareVersion
**Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>firmwareVersion</code>](#Hub+firmwareVersion)
**Read only**: true
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| firmwareVersion | <code>string</code> | Firmware version of the hub |
<a name="Hub+uuid"></a>
### pupRemote.uuid
@ -1473,6 +1524,7 @@ A combined color and distance event, emits when the sensor is activated.
* [new DuploTrainBase()](#new_DuploTrainBase_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
* [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@ -1523,6 +1575,18 @@ The DuploTrainBase is emitted if the discovered device is a Duplo Train Base.
| --- | --- | --- |
| name | <code>string</code> | Name of the hub |
<a name="Hub+firmwareVersion"></a>
### duploTrainBase.firmwareVersion
**Kind**: instance property of [<code>DuploTrainBase</code>](#DuploTrainBase)
**Overrides**: [<code>firmwareVersion</code>](#Hub+firmwareVersion)
**Read only**: true
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| firmwareVersion | <code>string</code> | Firmware version of the hub |
<a name="Hub+uuid"></a>
### duploTrainBase.uuid

View File

@ -185,6 +185,7 @@ Emits when a Powered UP Hub device is found.
* [WeDo2SmartHub](#WeDo2SmartHub) ⇐ <code>Hub</code>
* [new WeDo2SmartHub()](#new_WeDo2SmartHub_new)
* [.name](#Hub+name)
* [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@ -228,6 +229,17 @@ The WeDo2SmartHub is emitted if the discovered device is a WeDo 2.0 Smart Hub.
| --- | --- | --- |
| name | <code>string</code> | Name of the hub |
<a name="Hub+firmwareVersion"></a>
### weDo2SmartHub.firmwareVersion
**Kind**: instance property of [<code>WeDo2SmartHub</code>](#WeDo2SmartHub)
**Read only**: true
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| firmwareVersion | <code>string</code> | Firmware version of the hub |
<a name="Hub+uuid"></a>
### weDo2SmartHub.uuid
@ -546,6 +558,7 @@ Emits when an attached motor or sensor is detached from the Hub.
* [new BoostMoveHub()](#new_BoostMoveHub_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
* [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@ -602,6 +615,18 @@ The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
| --- | --- | --- |
| name | <code>string</code> | Name of the hub |
<a name="Hub+firmwareVersion"></a>
### boostMoveHub.firmwareVersion
**Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>firmwareVersion</code>](#Hub+firmwareVersion)
**Read only**: true
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| firmwareVersion | <code>string</code> | Firmware version of the hub |
<a name="Hub+uuid"></a>
### boostMoveHub.uuid
@ -946,6 +971,7 @@ Emits when an attached motor or sensor is detached from the Hub.
* [new PUPHub()](#new_PUPHub_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
* [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@ -1000,6 +1026,18 @@ The PUPHub is emitted if the discovered device is a Powered UP Hub.
| --- | --- | --- |
| name | <code>string</code> | Name of the hub |
<a name="Hub+firmwareVersion"></a>
### pupHub.firmwareVersion
**Kind**: instance property of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>firmwareVersion</code>](#Hub+firmwareVersion)
**Read only**: true
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| firmwareVersion | <code>string</code> | Firmware version of the hub |
<a name="Hub+uuid"></a>
### pupHub.uuid
@ -1318,6 +1356,7 @@ Emits when an attached motor or sensor is detached from the Hub.
* [new PUPRemote()](#new_PUPRemote_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
* [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@ -1363,6 +1402,18 @@ The PUPRemote is emitted if the discovered device is a Powered UP Remote.
| --- | --- | --- |
| name | <code>string</code> | Name of the hub |
<a name="Hub+firmwareVersion"></a>
### pupRemote.firmwareVersion
**Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>firmwareVersion</code>](#Hub+firmwareVersion)
**Read only**: true
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| firmwareVersion | <code>string</code> | Firmware version of the hub |
<a name="Hub+uuid"></a>
### pupRemote.uuid
@ -1566,6 +1617,7 @@ A combined color and distance event, emits when the sensor is activated.
* [new DuploTrainBase()](#new_DuploTrainBase_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
* [.firmwareVersion](#Hub+firmwareVersion)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
@ -1616,6 +1668,18 @@ The DuploTrainBase is emitted if the discovered device is a Duplo Train Base.
| --- | --- | --- |
| name | <code>string</code> | Name of the hub |
<a name="Hub+firmwareVersion"></a>
### duploTrainBase.firmwareVersion
**Kind**: instance property of [<code>DuploTrainBase</code>](#DuploTrainBase)
**Overrides**: [<code>firmwareVersion</code>](#Hub+firmwareVersion)
**Read only**: true
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| firmwareVersion | <code>string</code> | Firmware version of the hub |
<a name="Hub+uuid"></a>
### duploTrainBase.uuid

View File

@ -25,6 +25,7 @@ export class Hub extends EventEmitter {
protected _characteristics: {[uuid: string]: Characteristic} = {};
protected _name: string;
protected _firmwareVersion: string = "0.0.0.0";
protected _batteryLevel: number = 100;
private _peripheral: Peripheral;
@ -49,6 +50,15 @@ export class Hub extends EventEmitter {
}
/**
* @readonly
* @property {string} firmwareVersion Firmware version of the hub
*/
public get firmwareVersion () {
return this._firmwareVersion;
}
/**
* @readonly
* @property {string} uuid UUID of the hub

View File

@ -40,6 +40,7 @@ export class LPF2Hub extends Hub {
const characteristic = this._getCharacteristic(Consts.BLECharacteristic.LPF2_ALL);
this._subscribeToCharacteristic(characteristic, this._parseMessage.bind(this));
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x02, 0x02])); // Activate button reports
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x03, 0x05])); // Get firmware version
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, 0x3b, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate current reports
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, 0x3c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate voltage reports
if (this.type === Consts.HubType.DUPLO_TRAIN_HUB) {
@ -190,6 +191,18 @@ export class LPF2Hub extends Hub {
this.emit("button", "GREEN", Consts.ButtonState.RELEASED);
return;
}
} else if (data[3] === 3) {
const fwData = data.slice(5, data.length);
let bcd = fwData.readUInt8(3);
const major = bcd >>> 4;
const minor = bcd & 0xf;
bcd = fwData.readUInt8(2);
const bugFix = bcd >>> 4 * 10 + bcd & 0xf;
bcd = fwData.readUInt8(1);
let build = bcd >>> 4 * 1000 + bcd & 0xf * 100;
bcd = fwData.readUInt8(0);
build = build + bcd >>> 4 * 10 + bcd & 0xf;
this._firmwareVersion = `${major}.${minor}.${bugFix}.${build}`;
}
}
@ -238,7 +251,17 @@ export class LPF2Hub extends Hub {
private _parseSensorMessage (data: Buffer) {
if ((data[3] === 0x3b && this.type === Consts.HubType.POWERED_UP_REMOTE) || (data[3] === 0x3c && this.type !== Consts.HubType.POWERED_UP_REMOTE)) { // Voltage
if ((data[3] === 0x3b && this.type === Consts.HubType.POWERED_UP_REMOTE)) { // Voltage (PUP Remote)
data = this._padMessage(data, 6);
const batteryLevel = data.readUInt16LE(4) / 500;
this._batteryLevel = Math.floor(batteryLevel);
return;
} else if (data[3] === 0x3c && this.type === Consts.HubType.POWERED_UP_REMOTE) { // Current (PUP Remote)
data = this._padMessage(data, 6);
const current = data.readUInt16LE(4) / 1000;
this._current = current;
return;
} else if (data[3] === 0x3c && this.type !== Consts.HubType.POWERED_UP_REMOTE) { // Voltage (Non-PUP Remote)
data = this._padMessage(data, 6);
const batteryLevel = data.readUInt16LE(4) / 400;
this._batteryLevel = Math.floor(batteryLevel);
@ -248,11 +271,6 @@ export class LPF2Hub extends Hub {
const current = data.readUInt16LE(4) / 4096;
this._current = current * 100;
return;
} else if (data[3] === 0x3c) { // Current (PUP Remote)
data = this._padMessage(data, 6);
const current = data.readUInt16LE(4) / 1000;
this._current = current;
return;
}
const port = this._getPortForPortNumber(data[3]);