@ovok/native 0.4.4 → 0.4.6
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/bt-management/services/devices/bp2/bp2.device.js +8 -23
- package/lib/commonjs/modules/bt-management/services/devices/bp2/bp2.device.js.map +1 -1
- package/lib/commonjs/modules/bt-management/services/devices/bp2/bp2.frame-reader.js +89 -0
- package/lib/commonjs/modules/bt-management/services/devices/bp2/bp2.frame-reader.js.map +1 -0
- package/lib/commonjs/modules/bt-management/services/devices/bp2/bp2.main-services.js +50 -21
- package/lib/commonjs/modules/bt-management/services/devices/bp2/bp2.main-services.js.map +1 -1
- package/lib/commonjs/modules/bt-management/services/devices/bt-connection-handler.js +32 -2
- package/lib/commonjs/modules/bt-management/services/devices/bt-connection-handler.js.map +1 -1
- package/lib/commonjs/modules/bt-management/services/devices/bt-data-processor.js +80 -85
- package/lib/commonjs/modules/bt-management/services/devices/bt-data-processor.js.map +1 -1
- package/lib/commonjs/modules/bt-management/services/devices/bt-managed-device.js +25 -3
- package/lib/commonjs/modules/bt-management/services/devices/bt-managed-device.js.map +1 -1
- package/lib/commonjs/modules/bt-management/services/devices/frame-parser.js +54 -0
- package/lib/commonjs/modules/bt-management/services/devices/frame-parser.js.map +1 -0
- package/lib/commonjs/modules/bt-management/services/devices/measurement-state-machine.js +63 -0
- package/lib/commonjs/modules/bt-management/services/devices/measurement-state-machine.js.map +1 -0
- package/lib/commonjs/modules/bt-management/types/frame-read-result.js +6 -0
- package/lib/commonjs/modules/bt-management/types/frame-read-result.js.map +1 -0
- package/lib/commonjs/modules/bt-management/types/frame-read-status.js +17 -0
- package/lib/commonjs/modules/bt-management/types/frame-read-status.js.map +1 -0
- package/lib/commonjs/modules/bt-management/types/frame-reader.js +6 -0
- package/lib/commonjs/modules/bt-management/types/frame-reader.js.map +1 -0
- package/lib/commonjs/modules/bt-management/utils/calculate-crc-8.js +43 -0
- package/lib/commonjs/modules/bt-management/utils/calculate-crc-8.js.map +1 -0
- package/lib/commonjs/modules/bt-management/utils/convert-bp-state-flag.js +8 -1
- package/lib/commonjs/modules/bt-management/utils/convert-bp-state-flag.js.map +1 -1
- package/lib/commonjs/modules/bt-management/utils/le-16-from-hex.js.map +1 -1
- package/lib/module/modules/bt-management/services/devices/bp2/bp2.device.js +9 -23
- package/lib/module/modules/bt-management/services/devices/bp2/bp2.device.js.map +1 -1
- package/lib/module/modules/bt-management/services/devices/bp2/bp2.frame-reader.js +84 -0
- package/lib/module/modules/bt-management/services/devices/bp2/bp2.frame-reader.js.map +1 -0
- package/lib/module/modules/bt-management/services/devices/bp2/bp2.main-services.js +50 -21
- package/lib/module/modules/bt-management/services/devices/bp2/bp2.main-services.js.map +1 -1
- package/lib/module/modules/bt-management/services/devices/bt-connection-handler.js +32 -2
- package/lib/module/modules/bt-management/services/devices/bt-connection-handler.js.map +1 -1
- package/lib/module/modules/bt-management/services/devices/bt-data-processor.js +80 -85
- package/lib/module/modules/bt-management/services/devices/bt-data-processor.js.map +1 -1
- package/lib/module/modules/bt-management/services/devices/bt-managed-device.js +25 -3
- package/lib/module/modules/bt-management/services/devices/bt-managed-device.js.map +1 -1
- package/lib/module/modules/bt-management/services/devices/frame-parser.js +50 -0
- package/lib/module/modules/bt-management/services/devices/frame-parser.js.map +1 -0
- package/lib/module/modules/bt-management/services/devices/measurement-state-machine.js +58 -0
- package/lib/module/modules/bt-management/services/devices/measurement-state-machine.js.map +1 -0
- package/lib/module/modules/bt-management/types/frame-read-result.js +4 -0
- package/lib/module/modules/bt-management/types/frame-read-result.js.map +1 -0
- package/lib/module/modules/bt-management/types/frame-read-status.js +13 -0
- package/lib/module/modules/bt-management/types/frame-read-status.js.map +1 -0
- package/lib/module/modules/bt-management/types/frame-reader.js +4 -0
- package/lib/module/modules/bt-management/types/frame-reader.js.map +1 -0
- package/lib/module/modules/bt-management/utils/calculate-crc-8.js +38 -0
- package/lib/module/modules/bt-management/utils/calculate-crc-8.js.map +1 -0
- package/lib/module/modules/bt-management/utils/convert-bp-state-flag.js +9 -1
- package/lib/module/modules/bt-management/utils/convert-bp-state-flag.js.map +1 -1
- package/lib/module/modules/bt-management/utils/le-16-from-hex.js.map +1 -1
- package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bp2/bp2.device.d.ts +3 -1
- package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bp2/bp2.device.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bp2/bp2.frame-reader.d.ts +14 -0
- package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bp2/bp2.frame-reader.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bp2/bp2.main-services.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bt-connection-handler.d.ts +9 -1
- package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bt-connection-handler.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bt-data-processor.d.ts +27 -10
- package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bt-data-processor.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bt-managed-device.d.ts +23 -1
- package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bt-managed-device.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/bt-management/services/devices/frame-parser.d.ts +19 -0
- package/lib/typescript/commonjs/src/modules/bt-management/services/devices/frame-parser.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/bt-management/services/devices/measurement-state-machine.d.ts +30 -0
- package/lib/typescript/commonjs/src/modules/bt-management/services/devices/measurement-state-machine.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/bt-management/types/frame-read-result.d.ts +21 -0
- package/lib/typescript/commonjs/src/modules/bt-management/types/frame-read-result.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/bt-management/types/frame-read-status.d.ts +10 -0
- package/lib/typescript/commonjs/src/modules/bt-management/types/frame-read-status.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/bt-management/types/frame-reader.d.ts +13 -0
- package/lib/typescript/commonjs/src/modules/bt-management/types/frame-reader.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/bt-management/utils/calculate-crc-8.d.ts +10 -0
- package/lib/typescript/commonjs/src/modules/bt-management/utils/calculate-crc-8.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/bt-management/utils/convert-bp-state-flag.d.ts +7 -0
- package/lib/typescript/commonjs/src/modules/bt-management/utils/convert-bp-state-flag.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/bt-management/utils/le-16-from-hex.d.ts +1 -1
- package/lib/typescript/commonjs/src/modules/bt-management/utils/le-16-from-hex.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/bt-management/services/devices/bp2/bp2.device.d.ts +3 -1
- package/lib/typescript/module/src/modules/bt-management/services/devices/bp2/bp2.device.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/bt-management/services/devices/bp2/bp2.frame-reader.d.ts +14 -0
- package/lib/typescript/module/src/modules/bt-management/services/devices/bp2/bp2.frame-reader.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/bt-management/services/devices/bp2/bp2.main-services.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/bt-management/services/devices/bt-connection-handler.d.ts +9 -1
- package/lib/typescript/module/src/modules/bt-management/services/devices/bt-connection-handler.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/bt-management/services/devices/bt-data-processor.d.ts +27 -10
- package/lib/typescript/module/src/modules/bt-management/services/devices/bt-data-processor.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/bt-management/services/devices/bt-managed-device.d.ts +23 -1
- package/lib/typescript/module/src/modules/bt-management/services/devices/bt-managed-device.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/bt-management/services/devices/frame-parser.d.ts +19 -0
- package/lib/typescript/module/src/modules/bt-management/services/devices/frame-parser.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/bt-management/services/devices/measurement-state-machine.d.ts +30 -0
- package/lib/typescript/module/src/modules/bt-management/services/devices/measurement-state-machine.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/bt-management/types/frame-read-result.d.ts +21 -0
- package/lib/typescript/module/src/modules/bt-management/types/frame-read-result.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/bt-management/types/frame-read-status.d.ts +10 -0
- package/lib/typescript/module/src/modules/bt-management/types/frame-read-status.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/bt-management/types/frame-reader.d.ts +13 -0
- package/lib/typescript/module/src/modules/bt-management/types/frame-reader.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/bt-management/utils/calculate-crc-8.d.ts +10 -0
- package/lib/typescript/module/src/modules/bt-management/utils/calculate-crc-8.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/bt-management/utils/convert-bp-state-flag.d.ts +7 -0
- package/lib/typescript/module/src/modules/bt-management/utils/convert-bp-state-flag.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/bt-management/utils/le-16-from-hex.d.ts +1 -1
- package/lib/typescript/module/src/modules/bt-management/utils/le-16-from-hex.d.ts.map +1 -1
- package/package.json +12 -1
|
@@ -4,6 +4,27 @@ import { MeasurementTypeKey } from "@ovok/core";
|
|
|
4
4
|
import { CaseType } from "../../../types/case-type.js";
|
|
5
5
|
import { convertBpStateFlag } from "../../../utils/convert-bp-state-flag.js";
|
|
6
6
|
import { convertEcgDiagnosticFlag } from "../../../utils/convert-ecg-diagnostic-flag.js";
|
|
7
|
+
const bloodPressureResultFields = [{
|
|
8
|
+
name: "systolic",
|
|
9
|
+
parseType: "number",
|
|
10
|
+
byteIndexes: [21, 20],
|
|
11
|
+
parseReference: 16
|
|
12
|
+
}, {
|
|
13
|
+
name: "diastolic",
|
|
14
|
+
parseType: "number",
|
|
15
|
+
byteIndexes: [23, 22],
|
|
16
|
+
parseReference: 16
|
|
17
|
+
}, {
|
|
18
|
+
name: "heartRate",
|
|
19
|
+
parseType: "number",
|
|
20
|
+
byteIndexes: [27, 26],
|
|
21
|
+
parseReference: 16
|
|
22
|
+
}, {
|
|
23
|
+
name: "status",
|
|
24
|
+
parseType: "custom",
|
|
25
|
+
byteIndexes: [28],
|
|
26
|
+
customParserDefinition: a => convertBpStateFlag(a)
|
|
27
|
+
}];
|
|
7
28
|
export const bp2MainServices = [{
|
|
8
29
|
uuid: "14839ac4-7d7e-415c-9a42-167340cf2339",
|
|
9
30
|
monitorUuids: [{
|
|
@@ -48,27 +69,35 @@ export const bp2MainServices = [{
|
|
|
48
69
|
measurementTypeKey: MeasurementTypeKey.bloodPressure,
|
|
49
70
|
caseType: CaseType.RESULT,
|
|
50
71
|
caseValue: "a50805",
|
|
51
|
-
parseDefinitions: [
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
parseDefinitions: [...bloodPressureResultFields]
|
|
73
|
+
}, {
|
|
74
|
+
measurementTypeKey: MeasurementTypeKey.bloodPressure,
|
|
75
|
+
caseType: CaseType.STREAM,
|
|
76
|
+
caseValue: "a5080f",
|
|
77
|
+
parseDefinitions: [],
|
|
78
|
+
description: "Averaging run: a measurement is in progress"
|
|
79
|
+
}, {
|
|
80
|
+
measurementTypeKey: MeasurementTypeKey.bloodPressure,
|
|
81
|
+
caseType: CaseType.STREAM,
|
|
82
|
+
caseValue: "a50810",
|
|
83
|
+
parseDefinitions: [],
|
|
84
|
+
description: "Averaging run: waiting between measurements, run not finished"
|
|
85
|
+
}, {
|
|
86
|
+
measurementTypeKey: MeasurementTypeKey.bloodPressure,
|
|
87
|
+
caseType: CaseType.RESULT,
|
|
88
|
+
caseValue: "a50811",
|
|
89
|
+
parseDefinitions: bloodPressureResultFields,
|
|
90
|
+
description: "Averaging run finished. Carries the same payload as a single measurement"
|
|
91
|
+
}, {
|
|
92
|
+
caseType: CaseType.OTHER,
|
|
93
|
+
caseValue: "a50814",
|
|
94
|
+
parseDefinitions: [],
|
|
95
|
+
description: "Venous congestion detected, measurement abandoned"
|
|
96
|
+
}, {
|
|
97
|
+
caseType: CaseType.OTHER,
|
|
98
|
+
caseValue: "a508ff",
|
|
99
|
+
parseDefinitions: [],
|
|
100
|
+
description: "Device reports an invalid state"
|
|
72
101
|
}, {
|
|
73
102
|
measurementTypeKey: MeasurementTypeKey.ecg,
|
|
74
103
|
caseType: CaseType.STREAM,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MeasurementTypeKey","CaseType","convertBpStateFlag","convertEcgDiagnosticFlag","
|
|
1
|
+
{"version":3,"names":["MeasurementTypeKey","CaseType","convertBpStateFlag","convertEcgDiagnosticFlag","bloodPressureResultFields","name","parseType","byteIndexes","parseReference","customParserDefinition","a","bp2MainServices","uuid","monitorUuids","parsingModel","caseValuePosition","cases","caseType","OTHER","caseValue","parseDefinitions","description","measurementTypeKey","bloodPressure","STREAM","RESULT","ecg","writeUuid","mainCommandUuid"],"sourceRoot":"../../../../../../../src","sources":["modules/bt-management/services/devices/bp2/bp2.main-services.ts"],"mappings":";;AAAA,SAASA,kBAAkB,QAAQ,YAAY;AAE/C,SAASC,QAAQ,QAAQ,6BAA0B;AAGnD,SAASC,kBAAkB,QAAQ,yCAAsC;AACzE,SAASC,wBAAwB,QAAQ,+CAA4C;AAErF,MAAMC,yBAA6C,GAAG,CACpD;EACEC,IAAI,EAAE,UAAU;EAChBC,SAAS,EAAE,QAAQ;EACnBC,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;EACrBC,cAAc,EAAE;AAClB,CAAC,EACD;EACEH,IAAI,EAAE,WAAW;EACjBC,SAAS,EAAE,QAAQ;EACnBC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AE;QACpBC,WAAW,EAAE;MACf,CAAC,EACD;QACEC,kBAAkB,EAAEtB,kBAAkB,CAAC0B,GAAG;QAC1CT,QAAQ,EAAEhB,QAAQ,CAACuB,MAAM;QACzBL,SAAS,EAAE,QAAQ;QACnBC,gBAAgB,EAAE,EAAE;QACpBC,WAAW,EACT;MACJ,CAAC,EACD;QACEC,kBAAkB,EAAEtB,kBAAkB,CAAC0B,GAAG;QAC1CT,QAAQ,EAAEhB,QAAQ,CAACwB,MAAM;QACzBN,SAAS,EAAE,QAAQ;QACnBC,gBAAgB,EAAE,CAChB;UACEf,IAAI,EAAE,WAAW;UACjBC,SAAS,EAAE,QAAQ;UACnBC,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;UACrBC,cAAc,EAAE;QAClB,CAAC,EACD;UACEH,IAAI,EAAE,kBAAkB;UACxBC,SAAS,EAAE,QAAQ;UACnBC,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;UAC7BE,sBAAsB,EAAGC,CAAS,IAChCP,wBAAwB,CAACO,CAAC;QAC9B,CAAC;MAEL,CAAC;IAEL;EACF,CAAC,CACF;EACDiB,SAAS,EAAE;IACTf,IAAI,EAAE,sCAAsC;IAC5CgB,eAAe,EAAE;EACnB;AACF,CAAC,CACF","ignoreList":[]}
|
|
@@ -9,14 +9,16 @@ export class BTConnectionHandler {
|
|
|
9
9
|
characteristicSubscriptions = [];
|
|
10
10
|
isSendingCommand = false;
|
|
11
11
|
retryCount = 0;
|
|
12
|
-
constructor(device, mainServices, callbacks) {
|
|
12
|
+
constructor(device, mainServices, callbacks, preferredMtu) {
|
|
13
13
|
this.device = device;
|
|
14
14
|
this.mainServices = mainServices;
|
|
15
15
|
this.callbacks = callbacks;
|
|
16
|
+
this.preferredMtu = preferredMtu;
|
|
16
17
|
}
|
|
17
18
|
connect = async () => {
|
|
18
19
|
try {
|
|
19
20
|
await this.connectWithRetries();
|
|
21
|
+
await this.requestPreferredMtu();
|
|
20
22
|
this.callbacks.onStatusChanged?.(DeviceStatus.CONNECTED);
|
|
21
23
|
await this.device.discoverAllServicesAndCharacteristics();
|
|
22
24
|
this.onDisconnectSubscription = this.device.onDisconnected(this.onDeviceDisconnected);
|
|
@@ -50,6 +52,28 @@ export class BTConnectionHandler {
|
|
|
50
52
|
this.isSendingCommand = false;
|
|
51
53
|
this.retryCount = 0;
|
|
52
54
|
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Asks for a larger MTU so a frame arrives in fewer notifications.
|
|
58
|
+
*
|
|
59
|
+
* A device or platform that will not grant it keeps working at the default, so a
|
|
60
|
+
* refusal is recorded and the connection continues.
|
|
61
|
+
*/
|
|
62
|
+
requestPreferredMtu = async () => {
|
|
63
|
+
if (!this.preferredMtu) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
await this.device.requestMTU(this.preferredMtu);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
sentryLogger("info", "DEVICE: MTU request was not granted", {
|
|
70
|
+
deviceId: this.device.id,
|
|
71
|
+
deviceName: this.device.name,
|
|
72
|
+
requestedMtu: this.preferredMtu,
|
|
73
|
+
error: error instanceof Error ? error.message : String(error)
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
53
77
|
connectWithRetries = async () => {
|
|
54
78
|
const maxRetries = 5;
|
|
55
79
|
const retryDelay = 1000;
|
|
@@ -94,8 +118,14 @@ export class BTConnectionHandler {
|
|
|
94
118
|
});
|
|
95
119
|
if (error) {
|
|
96
120
|
this.callbacks.onError?.(error);
|
|
97
|
-
return;
|
|
98
121
|
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The teardown runs whether or not the disconnect carried an error. A link that drops
|
|
125
|
+
* on its own reports one, and returning early there left the device reported as
|
|
126
|
+
* connected with its subscriptions still attached, so it was never rediscovered and
|
|
127
|
+
* only a device restart recovered it.
|
|
128
|
+
*/
|
|
99
129
|
this.callbacks.onStatusChanged?.(DeviceStatus.DISCONNECTED);
|
|
100
130
|
this.destroy();
|
|
101
131
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["slog","sentryLogger","DeviceStatus","base64ToHex","hexToBase64","BTConnectionHandler","characteristicSubscriptions","isSendingCommand","retryCount","constructor","device","mainServices","callbacks","connect","connectWithRetries","onStatusChanged","CONNECTED","discoverAllServicesAndCharacteristics","onDisconnectSubscription","onDisconnected","onDeviceDisconnected","subscribeToAllCharacteristics","error","Error","message","deviceName","name","onError","DISCONNECTED","destroy","forEach","sub","remove","sendCommandToDevice","mainService","writeUuid","sendCommand","
|
|
1
|
+
{"version":3,"names":["slog","sentryLogger","DeviceStatus","base64ToHex","hexToBase64","BTConnectionHandler","characteristicSubscriptions","isSendingCommand","retryCount","constructor","device","mainServices","callbacks","preferredMtu","connect","connectWithRetries","requestPreferredMtu","onStatusChanged","CONNECTED","discoverAllServicesAndCharacteristics","onDisconnectSubscription","onDisconnected","onDeviceDisconnected","subscribeToAllCharacteristics","error","Error","message","deviceName","name","onError","DISCONNECTED","destroy","forEach","sub","remove","sendCommandToDevice","mainService","writeUuid","sendCommand","requestMTU","deviceId","id","requestedMtu","String","maxRetries","retryDelay","maxDelay","connected","isConnected","errorCode","willRetry","Promise","resolve","setTimeout","Math","min","pow","monitorUuid","monitorUuids","subscription","monitorCharacteristicForService","uuid","result","value","hexValue","onDataReceived","push","command","mainCommandUuid","writeCharacteristicWithResponseForService"],"sourceRoot":"../../../../../../src","sources":["modules/bt-management/services/devices/bt-connection-handler.ts"],"mappings":";;AAEA,SAASA,IAAI,QAAQ,2BAAkB;AACvC,SAASC,YAAY,QAAQ,yCAAsC;AACnE,SAASC,YAAY,QAAQ,8BAA2B;AAGxD,SAASC,WAAW,QAAQ,+BAA4B;AACxD,SAASC,WAAW,QAAQ,+BAA4B;AAQxD,OAAO,MAAMC,mBAAmB,CAAC;EAEvBC,2BAA2B,GAAmB,EAAE;EAChDC,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ACrDG,UAAU,EAAE,IAAI,CAACjB,MAAM,CAACkB;QAC1B,CAAC,CAAC;QACF,IAAI,IAAI,CAACpB,UAAU,KAAK,CAAC,EAAE;UACzBR,IAAI,CAACwB,KAAK,EAAE,8CAA8C,EAAE;YAC1DG,UAAU,EAAE,IAAI,CAACjB,MAAM,CAACkB;UAC1B,CAAC,CAAC;QACJ;MACF;IACF;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import { sentryLogger } from "../../../helpers/utils/sentry-logger.js";
|
|
3
4
|
import { CaseType } from "../../types/case-type.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { FrameReadStatus } from "../../types/frame-read-status.js";
|
|
6
|
+
import { FrameParser } from "./frame-parser.js";
|
|
7
|
+
import { MeasurementStateMachine } from "./measurement-state-machine.js";
|
|
6
8
|
export class BTDataProcessor {
|
|
7
9
|
/**
|
|
8
10
|
* One buffer per characteristic.
|
|
@@ -14,21 +16,23 @@ export class BTDataProcessor {
|
|
|
14
16
|
* error. Keeping the buffers apart makes that impossible.
|
|
15
17
|
*/
|
|
16
18
|
buffers = new Map();
|
|
17
|
-
|
|
18
|
-
constructor(device, mainServices, stuckDataTimeoutDuration, callbacks) {
|
|
19
|
+
constructor(device, mainServices, stuckDataTimeoutDuration, callbacks, frameReader) {
|
|
19
20
|
this.device = device;
|
|
20
|
-
this.mainServices = mainServices;
|
|
21
21
|
this.stuckDataTimeoutDuration = stuckDataTimeoutDuration;
|
|
22
22
|
this.callbacks = callbacks;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
this.frameReader = frameReader;
|
|
24
|
+
this.frameParser = new FrameParser(mainServices);
|
|
25
|
+
this.measurementState = new MeasurementStateMachine({
|
|
26
|
+
onStatusChanged: callbacks.onStatusChanged,
|
|
27
|
+
onStreamStart: callbacks.onStreamStart,
|
|
28
|
+
onResult: callbacks.onResult
|
|
29
|
+
});
|
|
26
30
|
}
|
|
27
31
|
currentUuid = "";
|
|
28
32
|
destroy = () => {
|
|
29
33
|
this.buffers.clear();
|
|
30
34
|
this.currentUuid = "";
|
|
31
|
-
this.
|
|
35
|
+
this.measurementState.reset();
|
|
32
36
|
clearTimeout(this.stuckDataTimeout);
|
|
33
37
|
this.stuckDataTimeout = undefined;
|
|
34
38
|
};
|
|
@@ -38,13 +42,61 @@ export class BTDataProcessor {
|
|
|
38
42
|
buffer.push(...hexValue);
|
|
39
43
|
this.buffers.set(this.currentUuid, buffer);
|
|
40
44
|
this.startStuckTimeout();
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
if (this.frameReader) {
|
|
46
|
+
this.readFramesFromBuffer(this.frameReader, uuid, buffer);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this.readWholeBuffer(uuid, buffer);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Drains every complete frame the buffer holds.
|
|
54
|
+
*
|
|
55
|
+
* One notification can complete several frames and can also carry bytes that belong to
|
|
56
|
+
* no frame at all, so the reader is asked repeatedly until it stops making progress.
|
|
57
|
+
* A frame that fails its integrity check is reported and skipped rather than parsed.
|
|
58
|
+
*/
|
|
59
|
+
readFramesFromBuffer = (reader, uuid, buffer) => {
|
|
60
|
+
let hasReadFrame = false;
|
|
61
|
+
while (buffer.length > 0) {
|
|
62
|
+
const result = reader.readFrame(buffer);
|
|
63
|
+
const hasProgressed = result.consumedBytes > 0;
|
|
64
|
+
buffer.splice(0, result.consumedBytes);
|
|
65
|
+
if (result.status === FrameReadStatus.COMPLETE) {
|
|
66
|
+
hasReadFrame = true;
|
|
67
|
+
this.handleFrame(uuid, result.frame);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (result.status === FrameReadStatus.CORRUPT) {
|
|
71
|
+
this.reportCorruptFrame();
|
|
72
|
+
}
|
|
73
|
+
if (result.status === FrameReadStatus.INCOMPLETE || !hasProgressed) {
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (hasReadFrame) {
|
|
78
|
+
this.callbacks.onSendCommandToDevice?.();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Treats the whole buffer as one frame, for devices that have not declared a reader.
|
|
84
|
+
*/
|
|
85
|
+
readWholeBuffer = (uuid, buffer) => {
|
|
86
|
+
if (!this.callbacks.validatePackage(buffer, uuid)) {
|
|
43
87
|
return;
|
|
44
88
|
}
|
|
45
|
-
|
|
89
|
+
this.handleFrame(uuid, buffer);
|
|
90
|
+
this.buffers.set(this.currentUuid, []);
|
|
91
|
+
this.callbacks.onSendCommandToDevice?.();
|
|
92
|
+
};
|
|
93
|
+
handleFrame = (uuid, frame) => {
|
|
94
|
+
const data = this.frameParser.parse(uuid, frame);
|
|
46
95
|
if (!data) {
|
|
47
|
-
|
|
96
|
+
sentryLogger("info", "BT_MANAGER: Frame matched no declared case", {
|
|
97
|
+
uuid,
|
|
98
|
+
frame: frame.join("")
|
|
99
|
+
});
|
|
48
100
|
return;
|
|
49
101
|
}
|
|
50
102
|
|
|
@@ -56,81 +108,24 @@ export class BTDataProcessor {
|
|
|
56
108
|
if (data.parsingCase.caseType === CaseType.DEPENDENT) {
|
|
57
109
|
dependentData = this.callbacks.handleDependentResult?.(data);
|
|
58
110
|
}
|
|
59
|
-
this.
|
|
60
|
-
this.resetDataAndSendCommandToDevice();
|
|
111
|
+
this.measurementState.advance(dependentData || data, frame);
|
|
61
112
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
const value = parsingModel.caseValuePosition?.map(index => this.collectedValues[index]).join("") || "";
|
|
68
|
-
const parsingCase = this.findParsingCase(value, parsingModel);
|
|
69
|
-
if (!parsingCase) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const parsedData = this.parseData(this.collectedValues, parsingCase);
|
|
73
|
-
if (!parsedData) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const measurementTypeKey = parsingCase.measurementTypeKey;
|
|
77
|
-
return {
|
|
78
|
-
parsingCase,
|
|
79
|
-
measurementTypeKey,
|
|
80
|
-
parsedData: parsedData
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
findParsingModel(uuid) {
|
|
84
|
-
let parsingModel;
|
|
85
|
-
for (const mainService of this.mainServices) {
|
|
86
|
-
const characteristic = mainService.monitorUuids.find(e => e.uuid.toLowerCase() === uuid.toLowerCase());
|
|
87
|
-
if (characteristic) {
|
|
88
|
-
parsingModel = characteristic.parsingModel;
|
|
89
|
-
break;
|
|
113
|
+
reportCorruptFrame = () => {
|
|
114
|
+
this.callbacks.onError?.(new Error("feedback-messages.measurement.corrupt-frame-error", {
|
|
115
|
+
cause: {
|
|
116
|
+
message: "Frame failed its integrity check"
|
|
90
117
|
}
|
|
91
|
-
}
|
|
92
|
-
return parsingModel;
|
|
93
|
-
}
|
|
94
|
-
findParsingCase(caseValue, parsingModel) {
|
|
95
|
-
if (!parsingModel) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const parsingCase = parsingModel.cases?.find(e => e.caseValue === caseValue);
|
|
99
|
-
return parsingCase;
|
|
100
|
-
}
|
|
101
|
-
parseData(successResult, parsingCase) {
|
|
102
|
-
if (!parsingCase) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
return parseMeasurement(successResult, parsingCase);
|
|
106
|
-
}
|
|
107
|
-
handleStatusChanges({
|
|
108
|
-
parsingCase,
|
|
109
|
-
measurementTypeKey,
|
|
110
|
-
parsedData
|
|
111
|
-
}) {
|
|
112
|
-
if (parsingCase.caseType === CaseType.STREAM && !this.isMeasuring) {
|
|
113
|
-
this.callbacks.onStreamStart?.();
|
|
114
|
-
this.callbacks.onStatusChanged?.(DeviceStatus.MEASURING, measurementTypeKey);
|
|
115
|
-
this.isMeasuring = true;
|
|
116
|
-
}
|
|
117
|
-
if (this.isMeasuring && parsingCase.caseType === CaseType.OTHER) {
|
|
118
|
-
this.callbacks.onStatusChanged?.(DeviceStatus.CONNECTED, measurementTypeKey);
|
|
119
|
-
this.isMeasuring = false;
|
|
120
|
-
}
|
|
121
|
-
let skipConnectedChange = false;
|
|
122
|
-
if (this.isMeasuring) {
|
|
123
|
-
skipConnectedChange = this.callbacks.onResult?.(parsedData, this.collectedValues) ?? false;
|
|
124
|
-
}
|
|
125
|
-
if (parsingCase.caseType === CaseType.RESULT && this.isMeasuring && !skipConnectedChange) {
|
|
126
|
-
this.isMeasuring = false;
|
|
127
|
-
this.callbacks.onStatusChanged?.(DeviceStatus.CONNECTED, measurementTypeKey);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
resetDataAndSendCommandToDevice = () => {
|
|
131
|
-
this.buffers.set(this.currentUuid, []);
|
|
132
|
-
this.callbacks.onSendCommandToDevice?.();
|
|
118
|
+
}));
|
|
133
119
|
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Reports a parsed frame and moves the device between measuring and connected.
|
|
123
|
+
*
|
|
124
|
+
* A result is reported whether or not a stream preceded it, because a device already
|
|
125
|
+
* holding a finished measurement when the app connects has a real reading to hand over.
|
|
126
|
+
* Repeats are suppressed on the case transition rather than on the values, so a second
|
|
127
|
+
* measurement that happens to read the same is still reported.
|
|
128
|
+
*/
|
|
134
129
|
startStuckTimeout = () => {
|
|
135
130
|
if (this.stuckDataTimeout) {
|
|
136
131
|
clearTimeout(this.stuckDataTimeout);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["CaseType","
|
|
1
|
+
{"version":3,"names":["sentryLogger","CaseType","FrameReadStatus","FrameParser","MeasurementStateMachine","BTDataProcessor","buffers","Map","constructor","device","mainServices","stuckDataTimeoutDuration","callbacks","frameReader","frameParser","measurementState","onStatusChanged","onStreamStart","onResult","currentUuid","destroy","clear","reset","clearTimeout","stuckDataTimeout","undefined","processData","uuid","hexValue","String","toLowerCase","buffer","get","push","set","startStuckTimeout","readFramesFromBuffer","readWholeBuffer","reader","hasReadFrame","length","result","readFrame","hasProgressed","consumedBytes","splice","status","COMPLETE","handleFrame","frame","CORRUPT","reportCorruptFrame","INCOMPLETE","onSendCommandToDevice","validatePackage","data","parse","join","dependentData","parsingCase","caseType","DEPENDENT","handleDependentResult","advance","onError","Error","cause","message","setTimeout","cancelConnection"],"sourceRoot":"../../../../../../src","sources":["modules/bt-management/services/devices/bt-data-processor.ts"],"mappings":";;AAGA,SAASA,YAAY,QAAQ,yCAAsC;AACnE,SAASC,QAAQ,QAAQ,0BAAuB;AAGhD,SAASC,eAAe,QAAQ,kCAA+B;AAK/D,SAASC,WAAW,QAAQ,mBAAgB;AAC5C,SAASC,uBAAuB,QAAQ,gCAA6B;AAoBrE,OAAO,MAAMC,eAAe,CAAwB;EAClD;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACUC,OAAO,GAAG,IAAIC,GAAG,CAAmB,CAAC;EAI7CC,WAAWA,CACQC,MAAc,EAC/BC,YAA2C,EAC1BC,wBAAgC,EAChCC,SAAoC,EACpCC,WAAyB,EAC1C;IAAA,KALiBJ,MAAc,GAAdA,MAAc;IAAA,KAEdE,wBAAgC,GAAhCA,wBAAgC;IAAA,KAChCC,SAAoC,GAApCA,SAAoC;IAAA,KACpCC,WAAyB,GAAzBA,WAAyB;IAE1C,IAAI,CAACC,WAAW,GAAG,IAAIX,WAAW,CAACO,YAAY,CAAC;IAChD,IAAI,CAACK,gBAAgB,GAAG,IAAIX,uBAAuB,CAAC;MAClDY,eAAe,EAAEJ,SAAS,CAACI,eAAe;MAC1CC,aAAa,EAAEL,SAAS,CAACK,aAAa;MACtCC,QAAQ,EAAEN,SAAS,CAACM;IACtB,CAAC,CAAC;EACJ;EAEQC,WAAW,GAAW,EAAE;EAEzBC,OAAO,GAAGA,CAAA,KAAM;IACrB,IAAI,CAACd,OAAO,CAACe,KA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WAAW,CAACC,QAAQ,KAAK3D,QAAQ,CAAC4D,SAAS,EAAE;MACpDH,aAAa,GAAG,IAAI,CAAC9C,SAAS,CAACkD,qBAAqB,GAAGP,IAAI,CAAC;IAC9D;IAEA,IAAI,CAACxC,gBAAgB,CAACgD,OAAO,CAACL,aAAa,IAAIH,IAAI,EAAEN,KAAK,CAAC;EAC7D,CAAC;EAEOE,kBAAkB,GAAGA,CAAA,KAAM;IACjC,IAAI,CAACvC,SAAS,CAACoD,OAAO,GACpB,IAAIC,KAAK,CAAC,mDAAmD,EAAE;MAC7DC,KAAK,EAAE;QACLC,OAAO,EAAE;MACX;IACF,CAAC,CACH,CAAC;EACH,CAAC;;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACUhC,iBAAiB,GAAGA,CAAA,KAAM;IAChC,IAAI,IAAI,CAACX,gBAAgB,EAAE;MACzBD,YAAY,CAAC,IAAI,CAACC,gBAAgB,CAAC;IACrC;IAEA,IAAI,CAACA,gBAAgB,GAAG4C,UAAU,CAAC,MAAM;MACvC,IAAI,CAACxD,SAAS,CAACoD,OAAO,GACpB,IAAIC,KAAK,CAAC,2CAA2C,EAAE;QACrDC,KAAK,EAAE;UACLC,OAAO,EAAE;QACX;MACF,CAAC,CACH,CAAC;MACD,IAAI,CAAC1D,MAAM,CAAC4D,gBAAgB,GAAG,CAAC;IAClC,CAAC,EAAE,IAAI,CAAC1D,wBAAwB,CAAC;EACnC,CAAC;AACH","ignoreList":[]}
|
|
@@ -18,6 +18,28 @@ export class BTManagedDevice {
|
|
|
18
18
|
* @returns The handled data.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Locates frame boundaries inside the notification buffer.
|
|
23
|
+
*
|
|
24
|
+
* A device that leaves this undefined has its whole buffer handed to
|
|
25
|
+
* `validatePackage` and parsed as a single frame, which only holds while a
|
|
26
|
+
* notification can neither split a frame nor carry more than one.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* MTU to ask for once connected.
|
|
31
|
+
*
|
|
32
|
+
* A larger MTU carries a frame in fewer notifications, which matters most for the
|
|
33
|
+
* long payloads. Devices that leave this undefined keep the platform default.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Decides whether the buffer holds a parseable frame.
|
|
38
|
+
*
|
|
39
|
+
* Only consulted for devices that declare no frameReader. A device that declares
|
|
40
|
+
* neither parses nothing, so an unknown buffer is never decoded on trust.
|
|
41
|
+
*/
|
|
42
|
+
|
|
21
43
|
constructor(device, {
|
|
22
44
|
deviceName,
|
|
23
45
|
onError: onErrorCallback,
|
|
@@ -109,11 +131,11 @@ export class BTManagedDevice {
|
|
|
109
131
|
onDataReceived: (uuid, hexValue) => {
|
|
110
132
|
this.dataProcessor?.processData(uuid, hexValue);
|
|
111
133
|
}
|
|
112
|
-
});
|
|
134
|
+
}, this.preferredMtu);
|
|
113
135
|
this.dataProcessor = new BTDataProcessor(this.device, this.mainServices, this.stuckDataTimeout, {
|
|
114
136
|
onStatusChanged: this.onDeviceStatusChanged?.bind(this),
|
|
115
137
|
onStreamStart: this.onStreamStart?.bind(this),
|
|
116
|
-
validatePackage: this.validatePackage
|
|
138
|
+
validatePackage: this.validatePackage?.bind(this) ?? (() => false),
|
|
117
139
|
onResult: (parsedData, collectedValues) => {
|
|
118
140
|
try {
|
|
119
141
|
return this.handleSuccessResult.bind(this)(parsedData, collectedValues);
|
|
@@ -124,7 +146,7 @@ export class BTManagedDevice {
|
|
|
124
146
|
onSendCommandToDevice: this.connectionHandler?.sendCommandToDevice?.bind(this),
|
|
125
147
|
onError: this.onError?.bind(this),
|
|
126
148
|
handleDependentResult: this.handleDependentResult?.bind(this)
|
|
127
|
-
});
|
|
149
|
+
}, this.frameReader);
|
|
128
150
|
await this.connectionHandler.connect();
|
|
129
151
|
};
|
|
130
152
|
getSupportedMeasurementTypeKeys = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["sentryLogger","DeviceStatus","BTConnectionHandler","BTDataProcessor","BTManagedDevice","constructor","device","deviceName","onError","onErrorCallback","onDeviceStatusChanged","onDeviceStatusChangedCallback","onResult","onResultCallback","onDeviceDisconnected","onDeviceDisconnectedCallback","deviceId","id","deviceData","name","localName","manufacturerData","sn","measurementTypes","status","measurementTypeKey","error","Error","message","caseType","_","data","diagramPoints","length","undefined","destroy","connectionHandler","dataProcessor","connect","getSupportedMeasurementTypeKeys","mainServices","onStatusChanged","bind","DISCONNECTED","onDataReceived","uuid","hexValue","processData","stuckDataTimeout","onStreamStart","validatePackage","parsedData","collectedValues","handleSuccessResult","onSendCommandToDevice","sendCommandToDevice","handleDependentResult","flatMap","service","monitorUuids","parsingModel","cases","map","c","filter","type","uniqueMeasurementTypes","Set","flat"],"sourceRoot":"../../../../../../src","sources":["modules/bt-management/services/devices/bt-managed-device.ts"],"mappings":";;AAGA,SAASA,YAAY,QAAQ,yCAAsC;AAMnE,SAASC,YAAY,QAAQ,8BAA2B;
|
|
1
|
+
{"version":3,"names":["sentryLogger","DeviceStatus","BTConnectionHandler","BTDataProcessor","BTManagedDevice","constructor","device","deviceName","onError","onErrorCallback","onDeviceStatusChanged","onDeviceStatusChangedCallback","onResult","onResultCallback","onDeviceDisconnected","onDeviceDisconnectedCallback","deviceId","id","deviceData","name","localName","manufacturerData","sn","measurementTypes","status","measurementTypeKey","error","Error","message","caseType","_","data","diagramPoints","length","undefined","destroy","connectionHandler","dataProcessor","connect","getSupportedMeasurementTypeKeys","mainServices","onStatusChanged","bind","DISCONNECTED","onDataReceived","uuid","hexValue","processData","preferredMtu","stuckDataTimeout","onStreamStart","validatePackage","parsedData","collectedValues","handleSuccessResult","onSendCommandToDevice","sendCommandToDevice","handleDependentResult","frameReader","flatMap","service","monitorUuids","parsingModel","cases","map","c","filter","type","uniqueMeasurementTypes","Set","flat"],"sourceRoot":"../../../../../../src","sources":["modules/bt-management/services/devices/bt-managed-device.ts"],"mappings":";;AAGA,SAASA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reList":[]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { parseMeasurement } from "../../utils/parse-measurement.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Turns a verified frame into a measurement, by selecting the parsing case the frame
|
|
7
|
+
* matches and applying that case's field definitions.
|
|
8
|
+
*
|
|
9
|
+
* A frame whose characteristic is unknown, whose selector bytes match no declared case,
|
|
10
|
+
* or whose fields do not parse yields nothing: it is the caller's decision whether that
|
|
11
|
+
* is worth reporting.
|
|
12
|
+
*/
|
|
13
|
+
export class FrameParser {
|
|
14
|
+
constructor(mainServices) {
|
|
15
|
+
this.mainServices = mainServices;
|
|
16
|
+
}
|
|
17
|
+
parse(uuid, frame) {
|
|
18
|
+
const parsingModel = this.findParsingModel(uuid);
|
|
19
|
+
if (!parsingModel) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const caseValue = this.readCaseValue(parsingModel, frame);
|
|
23
|
+
const parsingCase = parsingModel.cases?.find(declared => declared.caseValue === caseValue);
|
|
24
|
+
if (!parsingCase) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const parsedData = parseMeasurement(frame, parsingCase);
|
|
28
|
+
if (!parsedData) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
parsingCase,
|
|
33
|
+
measurementTypeKey: parsingCase.measurementTypeKey,
|
|
34
|
+
parsedData: parsedData
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
findParsingModel(uuid) {
|
|
38
|
+
for (const mainService of this.mainServices) {
|
|
39
|
+
const characteristic = mainService.monitorUuids.find(monitored => monitored.uuid.toLowerCase() === uuid.toLowerCase());
|
|
40
|
+
if (characteristic) {
|
|
41
|
+
return characteristic.parsingModel;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
readCaseValue(parsingModel, frame) {
|
|
47
|
+
return parsingModel.caseValuePosition?.map(index => frame[index]).join("") || "";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=frame-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["parseMeasurement","FrameParser","constructor","mainServices","parse","uuid","frame","parsingModel","findParsingModel","caseValue","readCaseValue","parsingCase","cases","find","declared","parsedData","measurementTypeKey","mainService","characteristic","monitorUuids","monitored","toLowerCase","undefined","caseValuePosition","map","index","join"],"sourceRoot":"../../../../../../src","sources":["modules/bt-management/services/devices/frame-parser.ts"],"mappings":";;AAMA,SAASA,gBAAgB,QAAQ,kCAA+B;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,WAAW,CAAwB;EAC9CC,WAAWA,CAAkBC,YAA2C,EAAE;IAAA,KAA7CA,YAA2C,GAA3CA,YAA2C;EAAG;EAEpEC,KAAKA,CACVC,IAAY,EACZC,KAAe,EAC8B;IAC7C,MAAMC,YAAY,GAAG,IAAI,CAACC,gBAAgB,CAACH,IAAI,CAAC;IAEhD,IAAI,CAACE,YAAY,EAAE;MACjB;IACF;IAEA,MAAME,SAAS,GAAG,IAAI,CAACC,aAAa,CAACH,YAAY,EAAED,KAAK,CAAC;IAEzD,MAAMK,WAAW,GAAGJ,YAAY,CAACK,KAAK,EAAEC,IAAI,CACzCC,QAAQ,IAAKA,QAAQ,CAACL,SAAS,KAAKA,SACvC,CAAC;IAED,IAAI,CAACE,WAAW,EAAE;MAChB;IACF;IAEA,MAAMI,UAAU,GAAGf,gBAAgB,CAACM,KAAK,EAAEK,WAAW,CAAC;IAEvD,IAAI,CAACI,UAAU,EAAE;MACf;IACF;IAEA,OAAO;MACLJ,WAAW;MACXK,kBAAkB,EAAEL,WAAW,CAACK,kBAAkB;MAClDD,UAAU,EAAEA;IACd,CAAC;EACH;EAEQP,gBAAgBA,CAACH,IAAY,EAA4B;IAC/D,KAAK,MAAMY,WAAW,I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