@ovok/native 1.16.1-dev.2099 → 1.16.1-dev.2101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/modules/next/bluetooth/channel.js +89 -0
- package/lib/commonjs/modules/next/bluetooth/channel.js.map +1 -0
- package/lib/commonjs/modules/next/bluetooth/driver.js +48 -0
- package/lib/commonjs/modules/next/bluetooth/driver.js.map +1 -0
- package/lib/commonjs/modules/next/bluetooth/drivers.js +20 -0
- package/lib/commonjs/modules/next/bluetooth/drivers.js.map +1 -0
- package/lib/commonjs/modules/next/bluetooth/index.js +65 -0
- package/lib/commonjs/modules/next/bluetooth/index.js.map +1 -0
- package/lib/commonjs/modules/next/bluetooth/legacy-driver.js +55 -0
- package/lib/commonjs/modules/next/bluetooth/legacy-driver.js.map +1 -0
- package/lib/commonjs/modules/next/bluetooth/link.js +105 -0
- package/lib/commonjs/modules/next/bluetooth/link.js.map +1 -0
- package/lib/commonjs/modules/next/bluetooth/result-policy.js +69 -0
- package/lib/commonjs/modules/next/bluetooth/result-policy.js.map +1 -0
- package/lib/commonjs/modules/next/bluetooth/sig-profiles.js +164 -0
- package/lib/commonjs/modules/next/bluetooth/sig-profiles.js.map +1 -0
- package/lib/commonjs/modules/next/bluetooth/sig-values.js +46 -0
- package/lib/commonjs/modules/next/bluetooth/sig-values.js.map +1 -0
- package/lib/module/modules/next/bluetooth/channel.js +85 -0
- package/lib/module/modules/next/bluetooth/channel.js.map +1 -0
- package/lib/module/modules/next/bluetooth/driver.js +45 -0
- package/lib/module/modules/next/bluetooth/driver.js.map +1 -0
- package/lib/module/modules/next/bluetooth/drivers.js +17 -0
- package/lib/module/modules/next/bluetooth/drivers.js.map +1 -0
- package/lib/module/modules/next/bluetooth/index.js +8 -0
- package/lib/module/modules/next/bluetooth/index.js.map +1 -0
- package/lib/module/modules/next/bluetooth/legacy-driver.js +51 -0
- package/lib/module/modules/next/bluetooth/legacy-driver.js.map +1 -0
- package/lib/module/modules/next/bluetooth/link.js +103 -0
- package/lib/module/modules/next/bluetooth/link.js.map +1 -0
- package/lib/module/modules/next/bluetooth/result-policy.js +61 -0
- package/lib/module/modules/next/bluetooth/result-policy.js.map +1 -0
- package/lib/module/modules/next/bluetooth/sig-profiles.js +156 -0
- package/lib/module/modules/next/bluetooth/sig-profiles.js.map +1 -0
- package/lib/module/modules/next/bluetooth/sig-values.js +38 -0
- package/lib/module/modules/next/bluetooth/sig-values.js.map +1 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/channel.d.ts +19 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/channel.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/driver.d.ts +32 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/driver.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/drivers.d.ts +7 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/drivers.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/index.d.ts +9 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/legacy-driver.d.ts +8 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/legacy-driver.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/link.d.ts +13 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/link.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/result-policy.d.ts +14 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/result-policy.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/sig-profiles.d.ts +16 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/sig-profiles.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/sig-values.d.ts +15 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/sig-values.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/next/bluetooth/channel.d.ts +19 -0
- package/lib/typescript/module/src/modules/next/bluetooth/channel.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/next/bluetooth/driver.d.ts +32 -0
- package/lib/typescript/module/src/modules/next/bluetooth/driver.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/next/bluetooth/drivers.d.ts +7 -0
- package/lib/typescript/module/src/modules/next/bluetooth/drivers.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/next/bluetooth/index.d.ts +9 -0
- package/lib/typescript/module/src/modules/next/bluetooth/index.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/next/bluetooth/legacy-driver.d.ts +8 -0
- package/lib/typescript/module/src/modules/next/bluetooth/legacy-driver.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/next/bluetooth/link.d.ts +13 -0
- package/lib/typescript/module/src/modules/next/bluetooth/link.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/next/bluetooth/result-policy.d.ts +14 -0
- package/lib/typescript/module/src/modules/next/bluetooth/result-policy.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/next/bluetooth/sig-profiles.d.ts +16 -0
- package/lib/typescript/module/src/modules/next/bluetooth/sig-profiles.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/next/bluetooth/sig-values.d.ts +15 -0
- package/lib/typescript/module/src/modules/next/bluetooth/sig-values.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Channel = void 0;
|
|
7
|
+
const DONE = {
|
|
8
|
+
value: undefined,
|
|
9
|
+
done: true
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** Callback-pushed values as an async iterator for one consumer; `onClose` runs once, however it ends. */
|
|
13
|
+
class Channel {
|
|
14
|
+
buffered = [];
|
|
15
|
+
closed = false;
|
|
16
|
+
constructor(onClose = () => {}) {
|
|
17
|
+
this.onClose = onClose;
|
|
18
|
+
}
|
|
19
|
+
push(value) {
|
|
20
|
+
if (this.closed) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const waiter = this.takeWaiter();
|
|
24
|
+
if (waiter) {
|
|
25
|
+
waiter.resolve({
|
|
26
|
+
value,
|
|
27
|
+
done: false
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
this.buffered.push(value);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
end() {
|
|
34
|
+
if (this.close()) {
|
|
35
|
+
this.takeWaiter()?.resolve(DONE);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
fail(error) {
|
|
39
|
+
if (this.close()) {
|
|
40
|
+
this.failure = {
|
|
41
|
+
error
|
|
42
|
+
};
|
|
43
|
+
this.takeWaiter()?.reject(error);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
next() {
|
|
47
|
+
if (this.buffered.length > 0) {
|
|
48
|
+
return Promise.resolve({
|
|
49
|
+
value: this.buffered.shift(),
|
|
50
|
+
done: false
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (this.failure) {
|
|
54
|
+
return Promise.reject(this.failure.error);
|
|
55
|
+
}
|
|
56
|
+
if (this.closed) {
|
|
57
|
+
return Promise.resolve(DONE);
|
|
58
|
+
}
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
this.waiter = {
|
|
61
|
+
resolve,
|
|
62
|
+
reject
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return() {
|
|
67
|
+
this.buffered.length = 0;
|
|
68
|
+
this.end();
|
|
69
|
+
return Promise.resolve(DONE);
|
|
70
|
+
}
|
|
71
|
+
[Symbol.asyncIterator]() {
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
close() {
|
|
75
|
+
if (this.closed) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
this.closed = true;
|
|
79
|
+
this.onClose();
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
takeWaiter() {
|
|
83
|
+
const waiter = this.waiter;
|
|
84
|
+
this.waiter = undefined;
|
|
85
|
+
return waiter;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.Channel = Channel;
|
|
89
|
+
//# sourceMappingURL=channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DONE","value","undefined","done","Channel","buffered","closed","constructor","onClose","push","waiter","takeWaiter","resolve","end","close","fail","error","failure","reject","next","length","Promise","shift","return","Symbol","asyncIterator","exports"],"sourceRoot":"../../../../../src","sources":["modules/next/bluetooth/channel.ts"],"mappings":";;;;;;AAKA,MAAMA,IAAqC,GAAG;EAAEC,KAAK,EAAEC,SAAS;EAAEC,IAAI,EAAE;AAAK,CAAC;;AAE9E;AACA,MAAMC,OAAO,CAAwC;EAClCC,QAAQ,GAAQ,EAAE;EAG3BC,MAAM,GAAG,KAAK;EAEfC,WAAWA,CAAkBC,OAAmB,GAAGA,CAAA,KAAM,CAAC,CAAC,EAAE;IAAA,KAAhCA,OAAmB,GAAnBA,OAAmB;EAAc;EAE9DC,IAAIA,CAACR,KAAQ,EAAQ;IAC1B,IAAI,IAAI,CAACK,MAAM,EAAE;MACf;IACF;IAEA,MAAMI,MAAM,GAAG,IAAI,CAACC,UAAU,CAAC,CAAC;IAEhC,IAAID,MAAM,EAAE;MACVA,MAAM,CAACE,OAAO,CAAC;QAAEX,KAAK;QAAEE,IAAI,EAAE;MAAM,CAAC,CAAC;IACxC,CAAC,MAAM;MACL,IAAI,CAACE,QAAQ,CAACI,IAAI,CAACR,KAAK,CAAC;IAC3B;EACF;EAEOY,GAAGA,CAAA,EAAS;IACjB,IAAI,IAAI,CAACC,KAAK,CAAC,CAAC,EAAE;MAChB,IAAI,CAACH,UAAU,CAAC,CAAC,EAAEC,OAAO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Ed,OAAO,IAAI;EACb;EAEQG,UAAUA,CAAA,EAA0B;IAC1C,MAAMD,MAAM,GAAG,IAAI,CAACA,MAAM;IAE1B,IAAI,CAACA,MAAM,GAAGR,SAAS;IAEvB,OAAOQ,MAAM;EACf;AACF;AAACgB,OAAA,CAAAtB,OAAA,GAAAA,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.gattDriver = void 0;
|
|
7
|
+
var _deviceStatus = require("../../bt-management/types/device-status.js");
|
|
8
|
+
var _resultIdentity = require("../../bt-management/utils/result-identity.js");
|
|
9
|
+
var _link = require("./link.js");
|
|
10
|
+
/** Connects to a scanned device and reports what happens until it disconnects or `signal` aborts. */
|
|
11
|
+
|
|
12
|
+
/** One device's conversation over a link, as the readings it produces. */
|
|
13
|
+
|
|
14
|
+
const readingIdentity = (deviceName, device) => ({
|
|
15
|
+
id: device.id,
|
|
16
|
+
name: deviceName,
|
|
17
|
+
localName: device.localName ?? "",
|
|
18
|
+
manufacturerData: device.manufacturerData ?? "",
|
|
19
|
+
sn: "",
|
|
20
|
+
measurementTypes: []
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
/** Runs a protocol over a fresh BLE link. */
|
|
24
|
+
const gattDriver = (deviceName, protocol) => async function* (device, signal) {
|
|
25
|
+
const link = await (0, _link.openBleLink)(device, signal);
|
|
26
|
+
const identity = readingIdentity(deviceName, device);
|
|
27
|
+
try {
|
|
28
|
+
yield {
|
|
29
|
+
kind: "status",
|
|
30
|
+
status: _deviceStatus.DeviceStatus.CONNECTED
|
|
31
|
+
};
|
|
32
|
+
for await (const reading of protocol(link)) {
|
|
33
|
+
yield {
|
|
34
|
+
kind: "reading",
|
|
35
|
+
id: (0, _resultIdentity.createStableResultId)(identity, reading),
|
|
36
|
+
reading
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
yield {
|
|
40
|
+
kind: "status",
|
|
41
|
+
status: _deviceStatus.DeviceStatus.DISCONNECTED
|
|
42
|
+
};
|
|
43
|
+
} finally {
|
|
44
|
+
await link.close();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.gattDriver = gattDriver;
|
|
48
|
+
//# sourceMappingURL=driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_deviceStatus","require","_resultIdentity","_link","readingIdentity","deviceName","device","id","name","localName","manufacturerData","sn","measurementTypes","gattDriver","protocol","signal","link","openBleLink","identity","kind","status","DeviceStatus","CONNECTED","reading","createStableResultId","DISCONNECTED","close","exports"],"sourceRoot":"../../../../../src","sources":["modules/next/bluetooth/driver.ts"],"mappings":";;;;;;AAMA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AAUA;;AAGA;;AAGA,MAAMG,eAAe,GAAGA,CAACC,UAAqB,EAAEC,MAAc,MAAM;EAClEC,EAAE,EAAED,MAAM,CAACC,EAAE;EACbC,IAAI,EAAEH,UAAU;EAChBI,SAAS,EAAEH,MAAM,CAACG,SAAS,IAAI,EAAE;EACjCC,gBAAgB,EAAEJ,MAAM,CAACI,gBAAgB,IAAI,EAAE;EAC/CC,EAAE,EAAE,EAAE;EACNC,gBAAgB,EAAE;AACpB,CAAC,CAAC;;AAEF;AACA,MAAMC,UAAU,GAAGA,CAACR,UAAqB,EAAES,QAAwB,KACjE,iBAAiBR,MAAM,EAAES,MAAM,EAAE;EAC/B,MAAMC,IAAI,GAAG,MAAM,IAAAC,iBAAW,EAACX,MAAM,EAAES,MAAM,CAAC;EAC9C,MAAMG,QAAQ,GAAGd,eAAe,CAACC,UAAU,EAAEC,MAAM,CAAC;EAEpD,IAAI;IACF,MAAM;MAAEa,IAAI,EAAE,QAAQ;MAAEC,MAAM,EAAEC,0BAAY,CAACC;IAAU,CAAC;IACxD,WAAW,MAAMC,OAAO,IAAIT,QAAQ,CAACE,IAAI,CAAC,EAAE;MAC1C,MAAM;QAAEG,IAAI,EAAE,SAAS;QAAEZ,EAAE,EAAE,IAAAiB,oCAAoB,EAACN,QAAQ,EAAEK,OAAO,CAAC;QAAEA;MAAQ,CAAC;IACjF;IACA,MAAM;MAAEJ,IAAI,EAAE,QAAQ;MAAEC,MAAM,EAAEC,0BAAY,CAACI;IAAa,CAAC;EAC7D,CAAC,SAAS;IACR,MAAMT,IAAI,CAACU,KAAK,CAAC,CAAC;EACpB;AACF,CAAC;AAACC,OAAA,CAAAd,UAAA,GAAAA,UAAA","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createDrivers = void 0;
|
|
7
|
+
var _deviceCreator = require("../../bt-management/services/device-creator.js");
|
|
8
|
+
var _driver = require("./driver.js");
|
|
9
|
+
var _legacyDriver = require("./legacy-driver.js");
|
|
10
|
+
var _sigProfiles = require("./sig-profiles.js");
|
|
11
|
+
/** The driver for each device key `accepted` can resolve: its native protocol, else its legacy class. */
|
|
12
|
+
const createDrivers = accepted => {
|
|
13
|
+
const creator = new _deviceCreator.DeviceCreator(accepted);
|
|
14
|
+
return deviceName => {
|
|
15
|
+
const protocol = _sigProfiles.SIG_PROTOCOLS.get(String(deviceName));
|
|
16
|
+
return protocol ? (0, _driver.gattDriver)(deviceName, protocol) : (0, _legacyDriver.legacyDriver)(creator, deviceName);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
exports.createDrivers = createDrivers;
|
|
20
|
+
//# sourceMappingURL=drivers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_deviceCreator","require","_driver","_legacyDriver","_sigProfiles","createDrivers","accepted","creator","DeviceCreator","deviceName","protocol","SIG_PROTOCOLS","get","String","gattDriver","legacyDriver","exports"],"sourceRoot":"../../../../../src","sources":["modules/next/bluetooth/drivers.ts"],"mappings":";;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAIA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAEA;AACA,MAAMI,aAAa,GAAIC,QAAmC,IAA0C;EAClG,MAAMC,OAAO,GAAG,IAAIC,4BAAa,CAACF,QAAQ,CAAC;EAE3C,OAAQG,UAAU,IAAK;IACrB,MAAMC,QAAQ,GAAGC,0BAAa,CAACC,GAAG,CAACC,MAAM,CAACJ,UAAU,CAAC,CAAC;IAEtD,OAAOC,QAAQ,GAAG,IAAAI,kBAAU,EAACL,UAAU,EAAEC,QAAQ,CAAC,GAAG,IAAAK,0BAAY,EAACR,OAAO,EAAEE,UAAU,CAAC;EACxF,CAAC;AACH,CAAC;AAACO,OAAA,CAAAX,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "SIG_PROTOCOLS", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _sigProfiles.SIG_PROTOCOLS;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "createDrivers", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _drivers.createDrivers;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "dailyTotalsOnly", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _resultPolicy.dailyTotalsOnly;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "everyReading", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _resultPolicy.everyReading;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "firstReadingPerKind", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _resultPolicy.firstReadingPerKind;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "gattDriver", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _driver.gattDriver;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "keepReadings", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _resultPolicy.keepReadings;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "openBleLink", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _link.openBleLink;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "policyByKind", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _resultPolicy.policyByKind;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
var _driver = require("./driver.js");
|
|
61
|
+
var _drivers = require("./drivers.js");
|
|
62
|
+
var _link = require("./link.js");
|
|
63
|
+
var _resultPolicy = require("./result-policy.js");
|
|
64
|
+
var _sigProfiles = require("./sig-profiles.js");
|
|
65
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_driver","require","_drivers","_link","_resultPolicy","_sigProfiles"],"sourceRoot":"../../../../../src","sources":["modules/next/bluetooth/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAEA,IAAAG,aAAA,GAAAH,OAAA;AAEA,IAAAI,YAAA,GAAAJ,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.legacyDriver = void 0;
|
|
7
|
+
var _deviceStatus = require("../../bt-management/types/device-status.js");
|
|
8
|
+
var _channel = require("./channel.js");
|
|
9
|
+
/** Runs a device class from `@ovok/native/bt-management` until its protocol moves to a `DeviceProtocol`. */
|
|
10
|
+
const legacyDriver = (creator, deviceName) => (device, signal) => {
|
|
11
|
+
const events = new _channel.Channel(() => void managed.disconnect());
|
|
12
|
+
const managed = creator.createDevice({
|
|
13
|
+
device,
|
|
14
|
+
deviceName,
|
|
15
|
+
onResult: ({
|
|
16
|
+
id,
|
|
17
|
+
data
|
|
18
|
+
}) => events.push({
|
|
19
|
+
kind: "reading",
|
|
20
|
+
id,
|
|
21
|
+
reading: data
|
|
22
|
+
}),
|
|
23
|
+
onDeviceStatusChanged: ({
|
|
24
|
+
status
|
|
25
|
+
}) => {
|
|
26
|
+
events.push({
|
|
27
|
+
kind: "status",
|
|
28
|
+
status
|
|
29
|
+
});
|
|
30
|
+
if (status === _deviceStatus.DeviceStatus.DISCONNECTED) {
|
|
31
|
+
events.end();
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
onConnectionEvent: ({
|
|
35
|
+
deviceData: _deviceData,
|
|
36
|
+
...event
|
|
37
|
+
}) => events.push({
|
|
38
|
+
kind: "connection",
|
|
39
|
+
event
|
|
40
|
+
}),
|
|
41
|
+
onError: ({
|
|
42
|
+
error
|
|
43
|
+
}) => events.push({
|
|
44
|
+
kind: "error",
|
|
45
|
+
error
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
signal.addEventListener("abort", () => events.end(), {
|
|
49
|
+
once: true
|
|
50
|
+
});
|
|
51
|
+
managed.connect().catch(error => events.fail(error));
|
|
52
|
+
return events;
|
|
53
|
+
};
|
|
54
|
+
exports.legacyDriver = legacyDriver;
|
|
55
|
+
//# sourceMappingURL=legacy-driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_deviceStatus","require","_channel","legacyDriver","creator","deviceName","device","signal","events","Channel","managed","disconnect","createDevice","onResult","id","data","push","kind","reading","onDeviceStatusChanged","status","DeviceStatus","DISCONNECTED","end","onConnectionEvent","deviceData","_deviceData","event","onError","error","addEventListener","once","connect","catch","fail","exports"],"sourceRoot":"../../../../../src","sources":["modules/next/bluetooth/legacy-driver.ts"],"mappings":";;;;;;AAKA,IAAAA,aAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AAGA;AACA,MAAME,YAAY,GAAGA,CAACC,OAAiD,EAAEC,UAAqB,KAC5F,CAACC,MAAM,EAAEC,MAAM,KAAK;EAClB,MAAMC,MAAM,GAAG,IAAIC,gBAAO,CAAc,MAAM,KAAKC,OAAO,CAACC,UAAU,CAAC,CAAC,CAAC;EAExE,MAAMD,OAAO,GAAGN,OAAO,CAACQ,YAAY,CAAC;IACnCN,MAAM;IACND,UAAU;IACVQ,QAAQ,EAAEA,CAAC;MAAEC,EAAE;MAAEC;IAAK,CAAC,KAAKP,MAAM,CAACQ,IAAI,CAAC;MAAEC,IAAI,EAAE,SAAS;MAAEH,EAAE;MAAEI,OAAO,EAAEH;IAAoB,CAAC,CAAC;IAC9FI,qBAAqB,EAAEA,CAAC;MAAEC;IAAO,CAAC,KAAK;MACrCZ,MAAM,CAACQ,IAAI,CAAC;QAAEC,IAAI,EAAE,QAAQ;QAAEG;MAAO,CAAC,CAAC;MACvC,IAAIA,MAAM,KAAKC,0BAAY,CAACC,YAAY,EAAE;QACxCd,MAAM,CAACe,GAAG,CAAC,CAAC;MACd;IACF,CAAC;IACDC,iBAAiB,EAAEA,CAAC;MAAEC,UAAU,EAAEC,WAAW;MAAE,GAAGC;IAAM,CAAC,KAAKnB,MAAM,CAACQ,IAAI,CAAC;MAAEC,IAAI,EAAE,YAAY;MAAEU;IAAM,CAAC,CAAC;IACxGC,OAAO,EAAEA,CAAC;MAAEC;IAAM,CAAC,KAAKrB,MAAM,CAACQ,IAAI,CAAC;MAAEC,IAAI,EAAE,OAAO;MAAEY;IAAM,CAAC;EAC9D,CAAC,CAAC;EAEFtB,MAAM,CAACuB,gBAAgB,CAAC,OAAO,EAAE,MAAMtB,MAAM,CAACe,GAAG,CAAC,CAAC,EAAE;IAAEQ,IAAI,EAAE;EAAK,CAAC,CAAC;EACpErB,OAAO,CAACsB,OAAO,CAAC,CAAC,CAACC,KAAK,CAAEJ,KAAc,IAAKrB,MAAM,CAAC0B,IAAI,CAACL,KAAK,CAAC,CAAC;EAE/D,OAAOrB,MAAM;AACf,CAAC;AAAC2B,OAAA,CAAAhC,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.openBleLink = openBleLink;
|
|
7
|
+
var _bluetoothError = require("../../bt-management/types/bluetooth-error.js");
|
|
8
|
+
var _sentryLogger = require("../../helpers/utils/sentry-logger.js");
|
|
9
|
+
var _channel = require("./channel.js");
|
|
10
|
+
/** An open GATT connection: bytes in, bytes out, no knowledge of any device. */
|
|
11
|
+
|
|
12
|
+
const CONNECT_ATTEMPTS = 5;
|
|
13
|
+
const FIRST_RETRY_DELAY_MS = 1000;
|
|
14
|
+
const MAX_RETRY_DELAY_MS = 5000;
|
|
15
|
+
|
|
16
|
+
/** BleErrorCode.OperationCancelled and DeviceDisconnected; the enum is not available at runtime. */
|
|
17
|
+
const ENDS_THE_LINK = new Set([2, 201]);
|
|
18
|
+
const toBytes = base64 => Uint8Array.from(atob(base64), char => char.charCodeAt(0));
|
|
19
|
+
const toBase64 = bytes => btoa(String.fromCharCode(...bytes));
|
|
20
|
+
const retryDelay = attempt => Math.min(FIRST_RETRY_DELAY_MS * 2 ** (attempt - 1), MAX_RETRY_DELAY_MS);
|
|
21
|
+
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
22
|
+
const abortReason = signal => signal.reason ?? new Error("The Bluetooth connection was cancelled");
|
|
23
|
+
async function connectWithRetries(device, signal) {
|
|
24
|
+
for (let attempt = 1;; attempt += 1) {
|
|
25
|
+
if (signal.aborted) {
|
|
26
|
+
throw abortReason(signal);
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
if (!(await device.isConnected())) {
|
|
30
|
+
await device.connect();
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (attempt >= CONNECT_ATTEMPTS) {
|
|
35
|
+
(0, _sentryLogger.sentryLogger)("error", "BLUETOOTH: Connection failed", {
|
|
36
|
+
errorCode: (0, _bluetoothError.toBluetoothError)(error).code,
|
|
37
|
+
attempts: attempt
|
|
38
|
+
});
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
await wait(retryDelay(attempt));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
class BleLink {
|
|
46
|
+
channels = new Set();
|
|
47
|
+
ended = false;
|
|
48
|
+
constructor(device) {
|
|
49
|
+
this.device = device;
|
|
50
|
+
this.disconnected = device.onDisconnected(() => this.endAll());
|
|
51
|
+
}
|
|
52
|
+
subscribe(service, characteristic) {
|
|
53
|
+
const channel = new _channel.Channel(() => {
|
|
54
|
+
subscription.remove();
|
|
55
|
+
this.channels.delete(channel);
|
|
56
|
+
});
|
|
57
|
+
const subscription = this.device.monitorCharacteristicForService(service, characteristic, (error, value) => {
|
|
58
|
+
if (error) {
|
|
59
|
+
this.endOrFail(channel, error);
|
|
60
|
+
} else if (value?.value) {
|
|
61
|
+
channel.push(toBytes(value.value));
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
this.channels.add(channel);
|
|
65
|
+
if (this.ended) {
|
|
66
|
+
channel.end();
|
|
67
|
+
}
|
|
68
|
+
return channel;
|
|
69
|
+
}
|
|
70
|
+
async write(service, characteristic, bytes) {
|
|
71
|
+
await this.device.writeCharacteristicWithResponseForService(service, characteristic, toBase64(bytes));
|
|
72
|
+
}
|
|
73
|
+
async close() {
|
|
74
|
+
this.endAll();
|
|
75
|
+
this.disconnected.remove();
|
|
76
|
+
await this.device.cancelConnection().catch(() => undefined);
|
|
77
|
+
}
|
|
78
|
+
endOrFail(channel, error) {
|
|
79
|
+
if (ENDS_THE_LINK.has(error.errorCode)) {
|
|
80
|
+
channel.end();
|
|
81
|
+
} else {
|
|
82
|
+
channel.fail((0, _bluetoothError.toBluetoothError)(error));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
endAll() {
|
|
86
|
+
this.ended = true;
|
|
87
|
+
[...this.channels].forEach(channel => channel.end());
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Connects (retrying with backoff) and discovers services; aborting `signal` closes the link. */
|
|
92
|
+
async function openBleLink(device, signal) {
|
|
93
|
+
await connectWithRetries(device, signal);
|
|
94
|
+
await device.discoverAllServicesAndCharacteristics();
|
|
95
|
+
const link = new BleLink(device);
|
|
96
|
+
if (signal.aborted) {
|
|
97
|
+
await link.close();
|
|
98
|
+
throw abortReason(signal);
|
|
99
|
+
}
|
|
100
|
+
signal.addEventListener("abort", () => void link.close(), {
|
|
101
|
+
once: true
|
|
102
|
+
});
|
|
103
|
+
return link;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_bluetoothError","require","_sentryLogger","_channel","CONNECT_ATTEMPTS","FIRST_RETRY_DELAY_MS","MAX_RETRY_DELAY_MS","ENDS_THE_LINK","Set","toBytes","base64","Uint8Array","from","atob","char","charCodeAt","toBase64","bytes","btoa","String","fromCharCode","retryDelay","attempt","Math","min","wait","ms","Promise","resolve","setTimeout","abortReason","signal","reason","Error","connectWithRetries","device","aborted","isConnected","connect","error","sentryLogger","errorCode","toBluetoothError","code","attempts","BleLink","channels","ended","constructor","disconnected","onDisconnected","endAll","subscribe","service","characteristic","channel","Channel","subscription","remove","delete","monitorCharacteristicForService","value","endOrFail","push","add","end","write","writeCharacteristicWithResponseForService","close","cancelConnection","catch","undefined","has","fail","forEach","openBleLink","discoverAllServicesAndCharacteristics","link","addEventListener","once"],"sourceRoot":"../../../../../src","sources":["modules/next/bluetooth/link.ts"],"mappings":";;;;;;AAEA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAEA,IAAAE,QAAA,GAAAF,OAAA;AAEA;;AASA,MAAMG,gBAAgB,GAAG,CAAC;AAC1B,MAAMC,oBAAoB,GAAG,IAAI;AACjC,MAAMC,kBAAkB,GAAG,IAAI;;AAE/B;AACA,MAAMC,aAAkC,GAAG,IAAIC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAE5D,MAAMC,OAAO,GAAIC,MAAc,IAAiBC,UAAU,CAACC,IAAI,CAACC,IAAI,CAACH,MAAM,CAAC,EAAGI,IAAI,IAAKA,IAAI,CAACC,UAAU,CAAC,CAAC,CAAC,CAAC;AAE3G,MAAMC,QAAQ,GAAIC,KAAiB,IAAaC,IAAI,CAACC,MAAM,CAACC,YAAY,CAAC,GAAGH,KAAK,CAAC,CAAC;AAEnF,MAAMI,UAAU,GAAIC,OAAe,IACjCC,IAAI,CAACC,GAAG,CAACnB,oBAAoB,GAAG,CAAC,KAAKiB,OAAO,GAAG,CAAC,CAAC,EAAEhB,kBAAkB,CAAC;AAEzE,MAAMmB,IAAI,GAAIC,EAAU,IAAoB,IAAIC,OAAO,CAAEC,OAAO,IAAKC,UAAU,CAACD,OAA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C;IACvC;EACF;EAEQY,MAAMA,CAAA,EAAS;IACrB,IAAI,CAACJ,KAAK,GAAG,IAAI;IACjB,CAAC,GAAG,IAAI,CAACD,QAAQ,CAAC,CAAC4B,OAAO,CAAEnB,OAAO,IAAKA,OAAO,CAACU,GAAG,CAAC,CAAC,CAAC;EACxD;AACF;;AAEA;AACA,eAAeU,WAAWA,CAACxC,MAAc,EAAEJ,MAAmB,EAAiB;EAC7E,MAAMG,kBAAkB,CAACC,MAAM,EAAEJ,MAAM,CAAC;EACxC,MAAMI,MAAM,CAACyC,qCAAqC,CAAC,CAAC;EAEpD,MAAMC,IAAI,GAAG,IAAIhC,OAAO,CAACV,MAAM,CAAC;EAEhC,IAAIJ,MAAM,CAACK,OAAO,EAAE;IAClB,MAAMyC,IAAI,CAACT,KAAK,CAAC,CAAC;IAClB,MAAMtC,WAAW,CAACC,MAAM,CAAC;EAC3B;EAEAA,MAAM,CAAC+C,gBAAgB,CAAC,OAAO,EAAE,MAAM,KAAKD,IAAI,CAACT,KAAK,CAAC,CAAC,EAAE;IAAEW,IAAI,EAAE;EAAK,CAAC,CAAC;EAEzE,OAAOF,IAAI;AACb","ignoreList":[]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.firstReadingPerKind = exports.everyReading = exports.dailyTotalsOnly = void 0;
|
|
7
|
+
exports.keepReadings = keepReadings;
|
|
8
|
+
exports.policyByKind = void 0;
|
|
9
|
+
var _dailyTotalDay = require("../../bt-management/utils/daily-total-day.js");
|
|
10
|
+
/** Makes, for each connection, the test of which readings to keep. */
|
|
11
|
+
|
|
12
|
+
const everyReading = () => () => true;
|
|
13
|
+
exports.everyReading = everyReading;
|
|
14
|
+
const firstReadingPerKind = () => {
|
|
15
|
+
const reported = new Set();
|
|
16
|
+
return ({
|
|
17
|
+
measurementTypeKey
|
|
18
|
+
}) => {
|
|
19
|
+
if (reported.has(measurementTypeKey)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
reported.add(measurementTypeKey);
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** Activity totals count only once their day has closed, and each day only once. */
|
|
28
|
+
exports.firstReadingPerKind = firstReadingPerKind;
|
|
29
|
+
const dailyTotalsOnly = () => {
|
|
30
|
+
const reported = new Set();
|
|
31
|
+
return reading => {
|
|
32
|
+
const day = (0, _dailyTotalDay.dailyTotalDay)(reading, Date.now());
|
|
33
|
+
if (day === undefined) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
const key = `${reading.measurementTypeKey}:${day}`;
|
|
37
|
+
if (day === "future" || reported.has(key)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
reported.add(key);
|
|
41
|
+
return true;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
exports.dailyTotalsOnly = dailyTotalsOnly;
|
|
45
|
+
const policyByKind = (policies, fallback = everyReading) => () => {
|
|
46
|
+
const tests = new Map();
|
|
47
|
+
const fallbackTest = fallback();
|
|
48
|
+
return reading => {
|
|
49
|
+
const policy = policies[reading.measurementTypeKey];
|
|
50
|
+
if (!policy) {
|
|
51
|
+
return fallbackTest(reading);
|
|
52
|
+
}
|
|
53
|
+
const test = tests.get(reading.measurementTypeKey) ?? policy();
|
|
54
|
+
tests.set(reading.measurementTypeKey, test);
|
|
55
|
+
return test(reading);
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** A driver's events minus the readings `policy` drops. */
|
|
60
|
+
exports.policyByKind = policyByKind;
|
|
61
|
+
async function* keepReadings(events, policy) {
|
|
62
|
+
const keep = policy();
|
|
63
|
+
for await (const event of events) {
|
|
64
|
+
if (event.kind !== "reading" || keep(event.reading)) {
|
|
65
|
+
yield event;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=result-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_dailyTotalDay","require","everyReading","exports","firstReadingPerKind","reported","Set","measurementTypeKey","has","add","dailyTotalsOnly","reading","day","dailyTotalDay","Date","now","undefined","key","policyByKind","policies","fallback","tests","Map","fallbackTest","policy","test","get","set","keepReadings","events","keep","event","kind"],"sourceRoot":"../../../../../src","sources":["modules/next/bluetooth/result-policy.ts"],"mappings":";;;;;;;;AAEA,IAAAA,cAAA,GAAAC,OAAA;AAIA;;AAGA,MAAMC,YAA0B,GAAGA,CAAA,KAAM,MAAM,IAAI;AAACC,OAAA,CAAAD,YAAA,GAAAA,YAAA;AAEpD,MAAME,mBAAiC,GAAGA,CAAA,KAAM;EAC9C,MAAMC,QAAQ,GAAG,IAAIC,GAAG,CAAqB,CAAC;EAE9C,OAAO,CAAC;IAAEC;EAAmB,CAAC,KAAK;IACjC,IAAIF,QAAQ,CAACG,GAAG,CAACD,kBAAkB,CAAC,EAAE;MACpC,OAAO,KAAK;IACd;IAEAF,QAAQ,CAACI,GAAG,CAACF,kBAAkB,CAAC;IAEhC,OAAO,IAAI;EACb,CAAC;AACH,CAAC;;AAED;AAAAJ,OAAA,CAAAC,mBAAA,GAAAA,mBAAA;AACA,MAAMM,eAA6B,GAAGA,CAAA,KAAM;EAC1C,MAAML,QAAQ,GAAG,IAAIC,GAAG,CAAS,CAAC;EAElC,OAAQK,OAAO,IAAK;IAClB,MAAMC,GAAG,GAAG,IAAAC,4BAAa,EAACF,OAAO,EAAEG,IAAI,CAACC,GAAG,CAAC,CAAC,CAAC;IAE9C,IAAIH,GAAG,KAAKI,SAAS,EAAE;MACrB,OAAO,IAAI;IACb;IAEA,MAAMC,GAAG,GAAG,GAAGN,OAAO,CAACJ,kBAAkB,IAAIK,GAAG,EAAE;IAElD,IAAIA,GAAG,KAAK,QAAQ,IAAIP,QAAQ,CAACG,GAAG,CAACS,G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+
exports.temperature = exports.pulseOximetry = exports.heartRate = exports.bodyWeight = exports.bloodPressure = exports.SIG_PROTOCOLS = void 0;
|
|
7
|
+
var _next = require("@ovok/core/next");
|
|
8
|
+
var _bloodPressureStates = require("../../bt-management/types/blood-pressure-states.js");
|
|
9
|
+
var _sigUuid = require("../../bt-management/utils/sig-uuid.js");
|
|
10
|
+
var _sigValues = require("./sig-values.js");
|
|
11
|
+
const KPA_TO_MMHG = 7.50062;
|
|
12
|
+
const KG_PER_SI_COUNT = 0.005;
|
|
13
|
+
const KG_PER_IMPERIAL_COUNT = 0.01 * 0.45359237;
|
|
14
|
+
const WEIGHT_UNSUCCESSFUL = 0xffff;
|
|
15
|
+
const DATE_TIME_BYTES = 7;
|
|
16
|
+
const BP_KPA = 0x01;
|
|
17
|
+
const BP_TIMESTAMP = 0x02;
|
|
18
|
+
const BP_PULSE = 0x04;
|
|
19
|
+
const BP_USER = 0x08;
|
|
20
|
+
const BP_STATUS = 0x10;
|
|
21
|
+
const BP_BODY_MOVEMENT = 0x01;
|
|
22
|
+
const BP_LOOSE_CUFF = 0x02;
|
|
23
|
+
const BP_IRREGULAR_PULSE = 0x04;
|
|
24
|
+
const TEMPERATURE_FAHRENHEIT = 0x01;
|
|
25
|
+
const TEMPERATURE_TIMESTAMP = 0x02;
|
|
26
|
+
const WEIGHT_IMPERIAL = 0x01;
|
|
27
|
+
const WEIGHT_TIMESTAMP = 0x02;
|
|
28
|
+
const PLX_TIMESTAMP = 0x01;
|
|
29
|
+
const HEART_RATE_UINT16 = 0x01;
|
|
30
|
+
const HEART_RATE_CONTACT_BITS = 0x06;
|
|
31
|
+
const HEART_RATE_NO_CONTACT = 0x04;
|
|
32
|
+
|
|
33
|
+
/** Core does not export its status enum; this one has the same values. */
|
|
34
|
+
|
|
35
|
+
const bloodPressureStatus = status => {
|
|
36
|
+
if (status & BP_BODY_MOVEMENT) {
|
|
37
|
+
return _bloodPressureStates.BloodPressureStates.DISTURB_DETECTED;
|
|
38
|
+
}
|
|
39
|
+
return status & BP_LOOSE_CUFF ? _bloodPressureStates.BloodPressureStates.LOOSE_SLEEVE : _bloodPressureStates.BloodPressureStates.REGULAR;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** The fields a blood-pressure frame's flags add after the pressures, each in flag order. */
|
|
43
|
+
const bloodPressureExtras = (view, flags) => {
|
|
44
|
+
let offset = 7;
|
|
45
|
+
const extras = {};
|
|
46
|
+
if (flags & BP_TIMESTAMP) {
|
|
47
|
+
extras.recordedAt = (0, _sigValues.dateTimeAt)(view, offset);
|
|
48
|
+
offset += DATE_TIME_BYTES;
|
|
49
|
+
}
|
|
50
|
+
if (flags & BP_PULSE) {
|
|
51
|
+
extras.heartRate = (0, _sigValues.sfloatAt)(view, offset);
|
|
52
|
+
offset += 2;
|
|
53
|
+
}
|
|
54
|
+
if (flags & BP_USER) {
|
|
55
|
+
const user = view.getUint8(offset);
|
|
56
|
+
extras.memorySlot = user < 2 ? user + 1 : undefined;
|
|
57
|
+
offset += 1;
|
|
58
|
+
}
|
|
59
|
+
if (flags & BP_STATUS) {
|
|
60
|
+
const status = view.getUint16(offset, true);
|
|
61
|
+
extras.status = bloodPressureStatus(status);
|
|
62
|
+
extras.irregularHeartbeat = status & BP_IRREGULAR_PULSE ? true : undefined;
|
|
63
|
+
}
|
|
64
|
+
return extras;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** Blood Pressure Measurement 0x2A35, in mmHg. */
|
|
68
|
+
const bloodPressure = view => {
|
|
69
|
+
const flags = view.getUint8(0);
|
|
70
|
+
const pressure = value => flags & BP_KPA ? (0, _sigValues.roundTo)(value * KPA_TO_MMHG, 0) : value;
|
|
71
|
+
const [systolic, diastolic, mean] = [1, 3, 5].map(offset => (0, _sigValues.sfloatAt)(view, offset));
|
|
72
|
+
if (systolic === undefined || diastolic === undefined) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
const reading = {
|
|
76
|
+
measurementTypeKey: _next.MeasurementTypeKey.bloodPressure,
|
|
77
|
+
systolic: pressure(systolic),
|
|
78
|
+
diastolic: pressure(diastolic)
|
|
79
|
+
};
|
|
80
|
+
return (0, _sigValues.withDefined)(reading, {
|
|
81
|
+
meanArterialPressure: mean === undefined ? undefined : pressure(mean),
|
|
82
|
+
...bloodPressureExtras(view, flags)
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** Temperature Measurement 0x2A1C, in Celsius. */
|
|
87
|
+
exports.bloodPressure = bloodPressure;
|
|
88
|
+
const temperature = view => {
|
|
89
|
+
const flags = view.getUint8(0);
|
|
90
|
+
const value = (0, _sigValues.floatAt)(view, 1);
|
|
91
|
+
if (value === undefined) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const reading = {
|
|
95
|
+
measurementTypeKey: _next.MeasurementTypeKey.temperature,
|
|
96
|
+
bodyTemp: flags & TEMPERATURE_FAHRENHEIT ? (0, _sigValues.roundTo)((value - 32) * 5 / 9, 2) : value
|
|
97
|
+
};
|
|
98
|
+
return flags & TEMPERATURE_TIMESTAMP ? (0, _sigValues.withDefined)(reading, {
|
|
99
|
+
recordedAt: (0, _sigValues.dateTimeAt)(view, 5)
|
|
100
|
+
}) : reading;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/** Weight Measurement 0x2A9D, in kilograms. */
|
|
104
|
+
exports.temperature = temperature;
|
|
105
|
+
const bodyWeight = view => {
|
|
106
|
+
const flags = view.getUint8(0);
|
|
107
|
+
const counts = view.getUint16(1, true);
|
|
108
|
+
if (counts === WEIGHT_UNSUCCESSFUL) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
const reading = {
|
|
112
|
+
measurementTypeKey: _next.MeasurementTypeKey.bodyWeight,
|
|
113
|
+
bodyWeight: (0, _sigValues.roundTo)(counts * (flags & WEIGHT_IMPERIAL ? KG_PER_IMPERIAL_COUNT : KG_PER_SI_COUNT), 3)
|
|
114
|
+
};
|
|
115
|
+
return flags & WEIGHT_TIMESTAMP ? (0, _sigValues.withDefined)(reading, {
|
|
116
|
+
recordedAt: (0, _sigValues.dateTimeAt)(view, 3)
|
|
117
|
+
}) : reading;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/** PLX Spot-Check Measurement 0x2A5E. */
|
|
121
|
+
exports.bodyWeight = bodyWeight;
|
|
122
|
+
const pulseOximetry = view => {
|
|
123
|
+
const flags = view.getUint8(0);
|
|
124
|
+
const bloodOxygen = (0, _sigValues.sfloatAt)(view, 1);
|
|
125
|
+
const pulseRate = (0, _sigValues.sfloatAt)(view, 3);
|
|
126
|
+
if (bloodOxygen === undefined || pulseRate === undefined) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
const reading = {
|
|
130
|
+
measurementTypeKey: _next.MeasurementTypeKey.bloodOxygenPulseRate,
|
|
131
|
+
bloodOxygen,
|
|
132
|
+
pulseRate
|
|
133
|
+
};
|
|
134
|
+
return flags & PLX_TIMESTAMP ? (0, _sigValues.withDefined)(reading, {
|
|
135
|
+
recordedAt: (0, _sigValues.dateTimeAt)(view, 5)
|
|
136
|
+
}) : reading;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/** Heart Rate Measurement 0x2A37; a strap reporting no skin contact has no reading. */
|
|
140
|
+
exports.pulseOximetry = pulseOximetry;
|
|
141
|
+
const heartRate = view => {
|
|
142
|
+
const flags = view.getUint8(0);
|
|
143
|
+
if ((flags & HEART_RATE_CONTACT_BITS) === HEART_RATE_NO_CONTACT) {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
const reading = {
|
|
147
|
+
measurementTypeKey: _next.MeasurementTypeKey.heartRate,
|
|
148
|
+
heartRate: flags & HEART_RATE_UINT16 ? view.getUint16(1, true) : view.getUint8(1)
|
|
149
|
+
};
|
|
150
|
+
return reading;
|
|
151
|
+
};
|
|
152
|
+
exports.heartRate = heartRate;
|
|
153
|
+
const subscribed = (service, characteristic, decode) => async function* (link) {
|
|
154
|
+
for await (const frame of link.subscribe((0, _sigUuid.sigUuid)(service), (0, _sigUuid.sigUuid)(characteristic))) {
|
|
155
|
+
const reading = (0, _sigValues.decodeFrame)(decode, frame);
|
|
156
|
+
if (reading) {
|
|
157
|
+
yield reading;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/** By the ids the SDK catalog gives the Bluetooth SIG profiles. */
|
|
163
|
+
const SIG_PROTOCOLS = exports.SIG_PROTOCOLS = new Map([["standard-blood-pressure", subscribed("1810", "2a35", bloodPressure)], ["standard-body-temperature", subscribed("1809", "2a1c", temperature)], ["standard-body-weight", subscribed("181d", "2a9d", bodyWeight)], ["standard-blood-oxygen-pulse-rate", subscribed("1822", "2a5e", pulseOximetry)], ["standard-heart-rate", subscribed("180d", "2a37", heartRate)]]);
|
|
164
|
+
//# sourceMappingURL=sig-profiles.js.map
|