Add mac address to hub/lpf2hub

- should close nathankellenicki/node-poweredup/issues/46
This commit is contained in:
Leo Bonnargent 2019-11-13 20:58:09 +01:00
parent 01cd067460
commit abbbd218ee
2 changed files with 26 additions and 0 deletions

View File

@ -25,6 +25,7 @@ export class Hub extends EventEmitter {
protected _name: string = ""; protected _name: string = "";
protected _firmwareVersion: string = "0.0.00.0000"; protected _firmwareVersion: string = "0.0.00.0000";
protected _macAddress: string = "00:00:00:00:00:00";
protected _batteryLevel: number = 100; protected _batteryLevel: number = 100;
protected _voltage: number = 0; protected _voltage: number = 0;
protected _current: number = 0; protected _current: number = 0;
@ -63,6 +64,15 @@ export class Hub extends EventEmitter {
} }
/**
* @readonly
* @property {string} macAddress Primary mac address of the hub
*/
public get macAddress () {
return this._macAddress;
}
/** /**
* @readonly * @readonly
* @property {string} uuid UUID of the hub * @property {string} uuid UUID of the hub

View File

@ -20,6 +20,17 @@ export class LPF2Hub extends Hub {
return [t[0], t[1], t.substring(2, 4), t.substring(4)].join("."); return [t[0], t[1], t.substring(2, 4), t.substring(4)].join(".");
} }
private static decodeMacAddress(v: Uint8Array) {
return [
("00" + v[0].toString(16)).slice(-2),
("00" + v[1].toString(16)).slice(-2),
("00" + v[2].toString(16)).slice(-2),
("00" + v[3].toString(16)).slice(-2),
("00" + v[4].toString(16)).slice(-2),
("00" + v[5].toString(16)).slice(-2),
].join(":");
}
protected _ledPort: number = 0x32; protected _ledPort: number = 0x32;
private _lastTiltX: number = 0; private _lastTiltX: number = 0;
@ -37,6 +48,7 @@ export class LPF2Hub extends Hub {
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x02, 0x02])); // Activate button reports 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])); // Request firmware version this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x03, 0x05])); // Request firmware version
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x06, 0x02])); // Activate battery level reports this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x06, 0x02])); // Activate battery level reports
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x0d, 0x05])); // Request primary MAC address
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, 0x3c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate voltage reports this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, 0x3c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate voltage reports
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, 0x3b, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate current reports
if (this.type === Consts.HubType.DUPLO_TRAIN_HUB) { if (this.type === Consts.HubType.DUPLO_TRAIN_HUB) {
@ -250,6 +262,10 @@ export class LPF2Hub extends Hub {
this._firmwareVersion = LPF2Hub.decodeVersion(data.readInt32LE(5)); this._firmwareVersion = LPF2Hub.decodeVersion(data.readInt32LE(5));
this._checkFirmware(this._firmwareVersion); this._checkFirmware(this._firmwareVersion);
// primary MAC Address
} else if (data[3] === 0x0d) {
this._macAddress = LPF2Hub.decodeMacAddress(data.slice(4, 10));
// Battery level reports // Battery level reports
} else if (data[3] === 0x06) { } else if (data[3] === 0x06) {
this._batteryLevel = data[5]; this._batteryLevel = data[5];