Merge pull request #47 from aileo/macaddress
Add mac address to hub/lpf2hub
This commit is contained in:
commit
2482422302
10
src/hub.ts
10
src/hub.ts
@ -26,6 +26,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 _hardwareVersion: string = "0.0.00.0000";
|
protected _hardwareVersion: string = "0.0.00.0000";
|
||||||
|
protected _primaryMACAddress: 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;
|
||||||
@ -72,6 +73,15 @@ export class Hub extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @readonly
|
||||||
|
* @property {string} primaryMACAddress Primary MAC address of the hub
|
||||||
|
*/
|
||||||
|
public get primaryMACAddress () {
|
||||||
|
return this._primaryMACAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @readonly
|
* @readonly
|
||||||
* @property {string} uuid UUID of the hub
|
* @property {string} uuid UUID of the hub
|
||||||
|
@ -21,6 +21,10 @@ 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 Array.from(v).map((n) => toHex(n, 2)).join(":");
|
||||||
|
}
|
||||||
|
|
||||||
protected _ledPort: number = 0x32;
|
protected _ledPort: number = 0x32;
|
||||||
protected _voltagePort: number | undefined;
|
protected _voltagePort: number | undefined;
|
||||||
protected _voltageMaxV: number = 9.6;
|
protected _voltageMaxV: number = 9.6;
|
||||||
@ -45,6 +49,7 @@ export class LPF2Hub extends Hub {
|
|||||||
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, 0x04, 0x05])); // Request hardware version
|
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x04, 0x05])); // Request hardware 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
|
||||||
if (this._voltagePort !== undefined) {
|
if (this._voltagePort !== undefined) {
|
||||||
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, this._voltagePort, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate voltage reports
|
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, this._voltagePort, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate voltage reports
|
||||||
}
|
}
|
||||||
@ -267,6 +272,10 @@ export class LPF2Hub extends Hub {
|
|||||||
} else if (data[3] === 0x04) {
|
} else if (data[3] === 0x04) {
|
||||||
this._hardwareVersion = LPF2Hub.decodeVersion(data.readInt32LE(5));
|
this._hardwareVersion = LPF2Hub.decodeVersion(data.readInt32LE(5));
|
||||||
|
|
||||||
|
// primary MAC Address
|
||||||
|
} else if (data[3] === 0x0d) {
|
||||||
|
this._primaryMACAddress = 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];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user