-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i-beacon.entity.ts
32 lines (29 loc) · 871 Bytes
/
i-beacon.entity.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Tag } from './tag.entity';
import { Peripheral } from '@abandonware/noble';
export class IBeacon extends Tag {
constructor(
peripheral: Peripheral,
majorMask: number = 0xffff,
minorMask: number = 0xffff
) {
super(peripheral);
this.uuid = this.peripheral.advertisement.manufacturerData
.slice(4, 20)
.toString('hex');
this.major =
this.peripheral.advertisement.manufacturerData.readUInt16BE(20) &
majorMask; // tslint:disable-line:no-bitwise
this.minor =
this.peripheral.advertisement.manufacturerData.readUInt16BE(22) &
minorMask; // tslint:disable-line:no-bitwise
this.measuredPower = this.peripheral.advertisement.manufacturerData.readInt8(
24
);
}
uuid: string;
major: number;
minor: number;
get id() {
return `${this.uuid}-${this.major}-${this.minor}`;
}
}