@robdobsn/raftjs 1.8.5 → 1.10.7
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/.editorconfig +14 -0
- package/.gitattributes +11 -0
- package/.nvmrc +1 -0
- package/TODO.md +1 -0
- package/dist/react-native/RaftAttributeHandler.d.ts +14 -0
- package/dist/react-native/RaftAttributeHandler.js +375 -0
- package/dist/react-native/RaftAttributeHandler.js.map +1 -0
- package/dist/react-native/RaftChannel.d.ts +20 -0
- package/dist/react-native/RaftChannel.js +12 -0
- package/dist/react-native/RaftChannel.js.map +1 -0
- package/dist/react-native/RaftChannelBLE.native.d.ts +95 -0
- package/dist/react-native/RaftChannelBLE.native.js +483 -0
- package/dist/react-native/RaftChannelBLE.native.js.map +1 -0
- package/dist/react-native/RaftChannelBLE.web.d.ts +40 -0
- package/dist/react-native/RaftChannelBLE.web.js +302 -0
- package/dist/react-native/RaftChannelBLE.web.js.map +1 -0
- package/dist/react-native/RaftChannelBLEFactory.d.ts +10 -0
- package/dist/react-native/RaftChannelBLEFactory.js +17 -0
- package/dist/react-native/RaftChannelBLEFactory.js.map +1 -0
- package/dist/react-native/RaftChannelBLEScanner.native.d.ts +18 -0
- package/dist/react-native/RaftChannelBLEScanner.native.js +138 -0
- package/dist/react-native/RaftChannelBLEScanner.native.js.map +1 -0
- package/dist/react-native/RaftChannelSimulated.d.ts +42 -0
- package/dist/react-native/RaftChannelSimulated.js +1000 -0
- package/dist/react-native/RaftChannelSimulated.js.map +1 -0
- package/dist/react-native/RaftChannelWebSerial.d.ts +39 -0
- package/dist/react-native/RaftChannelWebSerial.js +329 -0
- package/dist/react-native/RaftChannelWebSerial.js.map +1 -0
- package/dist/react-native/RaftChannelWebSocket.d.ts +30 -0
- package/dist/react-native/RaftChannelWebSocket.js +222 -0
- package/dist/react-native/RaftChannelWebSocket.js.map +1 -0
- package/dist/react-native/RaftCommsStats.d.ts +39 -0
- package/dist/react-native/RaftCommsStats.js +128 -0
- package/dist/react-native/RaftCommsStats.js.map +1 -0
- package/dist/react-native/RaftConnEvents.d.ts +39 -0
- package/dist/react-native/RaftConnEvents.js +54 -0
- package/dist/react-native/RaftConnEvents.js.map +1 -0
- package/dist/react-native/RaftConnector.d.ts +248 -0
- package/dist/react-native/RaftConnector.js +658 -0
- package/dist/react-native/RaftConnector.js.map +1 -0
- package/dist/react-native/RaftCustomAttrHandler.d.ts +6 -0
- package/dist/react-native/RaftCustomAttrHandler.js +93 -0
- package/dist/react-native/RaftCustomAttrHandler.js.map +1 -0
- package/dist/react-native/RaftDeviceInfo.d.ts +71 -0
- package/dist/react-native/RaftDeviceInfo.js +50 -0
- package/dist/react-native/RaftDeviceInfo.js.map +1 -0
- package/dist/react-native/RaftDeviceManager.d.ts +61 -0
- package/dist/react-native/RaftDeviceManager.js +665 -0
- package/dist/react-native/RaftDeviceManager.js.map +1 -0
- package/dist/react-native/RaftDeviceMgrIF.d.ts +15 -0
- package/dist/react-native/RaftDeviceMgrIF.js +11 -0
- package/dist/react-native/RaftDeviceMgrIF.js.map +1 -0
- package/dist/react-native/RaftDeviceMsg.d.ts +9 -0
- package/dist/react-native/RaftDeviceMsg.js +11 -0
- package/dist/react-native/RaftDeviceMsg.js.map +1 -0
- package/dist/react-native/RaftDeviceStates.d.ts +37 -0
- package/dist/react-native/RaftDeviceStates.js +60 -0
- package/dist/react-native/RaftDeviceStates.js.map +1 -0
- package/dist/react-native/RaftFileHandler.d.ts +52 -0
- package/dist/react-native/RaftFileHandler.js +502 -0
- package/dist/react-native/RaftFileHandler.js.map +1 -0
- package/dist/react-native/RaftLog.d.ts +22 -0
- package/dist/react-native/RaftLog.js +63 -0
- package/dist/react-native/RaftLog.js.map +1 -0
- package/dist/react-native/RaftMiniHDLC.d.ts +18 -0
- package/dist/react-native/RaftMiniHDLC.js +383 -0
- package/dist/react-native/RaftMiniHDLC.js.map +1 -0
- package/dist/react-native/RaftMsgHandler.d.ts +62 -0
- package/dist/react-native/RaftMsgHandler.js +511 -0
- package/dist/react-native/RaftMsgHandler.js.map +1 -0
- package/dist/react-native/RaftMsgTrackInfo.d.ts +17 -0
- package/dist/react-native/RaftMsgTrackInfo.js +42 -0
- package/dist/react-native/RaftMsgTrackInfo.js.map +1 -0
- package/dist/react-native/RaftProtocolDefs.d.ts +30 -0
- package/dist/react-native/RaftProtocolDefs.js +48 -0
- package/dist/react-native/RaftProtocolDefs.js.map +1 -0
- package/dist/react-native/RaftStreamHandler.d.ts +38 -0
- package/dist/react-native/RaftStreamHandler.js +258 -0
- package/dist/react-native/RaftStreamHandler.js.map +1 -0
- package/dist/react-native/RaftStruct.d.ts +3 -0
- package/dist/react-native/RaftStruct.js +258 -0
- package/dist/react-native/RaftStruct.js.map +1 -0
- package/dist/react-native/RaftSysTypeManager.d.ts +16 -0
- package/dist/react-native/RaftSysTypeManager.js +78 -0
- package/dist/react-native/RaftSysTypeManager.js.map +1 -0
- package/dist/react-native/RaftSystemType.d.ts +30 -0
- package/dist/react-native/RaftSystemType.js +3 -0
- package/dist/react-native/RaftSystemType.js.map +1 -0
- package/dist/react-native/RaftSystemUtils.d.ts +136 -0
- package/dist/react-native/RaftSystemUtils.js +412 -0
- package/dist/react-native/RaftSystemUtils.js.map +1 -0
- package/dist/react-native/RaftTypes.d.ts +195 -0
- package/dist/react-native/RaftTypes.js +153 -0
- package/dist/react-native/RaftTypes.js.map +1 -0
- package/dist/react-native/RaftUpdateEvents.d.ts +33 -0
- package/dist/react-native/RaftUpdateEvents.js +46 -0
- package/dist/react-native/RaftUpdateEvents.js.map +1 -0
- package/dist/react-native/RaftUpdateManager.d.ts +61 -0
- package/dist/react-native/RaftUpdateManager.js +621 -0
- package/dist/react-native/RaftUpdateManager.js.map +1 -0
- package/dist/react-native/RaftUtils.d.ts +128 -0
- package/dist/react-native/RaftUtils.js +487 -0
- package/dist/react-native/RaftUtils.js.map +1 -0
- package/dist/react-native/RaftWifiTypes.d.ts +23 -0
- package/dist/react-native/RaftWifiTypes.js +43 -0
- package/dist/react-native/RaftWifiTypes.js.map +1 -0
- package/dist/react-native/main.d.ts +26 -0
- package/dist/react-native/main.js +51 -0
- package/dist/react-native/main.js.map +1 -0
- package/dist/web/RaftAttributeHandler.js +1 -1
- package/dist/web/RaftAttributeHandler.js.map +1 -1
- package/dist/web/RaftChannelBLE.web.js +8 -6
- package/dist/web/RaftChannelBLE.web.js.map +1 -1
- package/dist/web/RaftChannelSimulated.d.ts +10 -0
- package/dist/web/RaftChannelSimulated.js +662 -80
- package/dist/web/RaftChannelSimulated.js.map +1 -1
- package/dist/web/RaftChannelWebSerial.js +2 -2
- package/dist/web/RaftChannelWebSerial.js.map +1 -1
- package/dist/web/RaftChannelWebSocket.js +16 -1
- package/dist/web/RaftChannelWebSocket.js.map +1 -1
- package/dist/web/RaftConnector.d.ts +2 -0
- package/dist/web/RaftConnector.js +38 -15
- package/dist/web/RaftConnector.js.map +1 -1
- package/dist/web/RaftCustomAttrHandler.d.ts +2 -0
- package/dist/web/RaftCustomAttrHandler.js +54 -26
- package/dist/web/RaftCustomAttrHandler.js.map +1 -1
- package/dist/web/RaftDeviceInfo.d.ts +3 -1
- package/dist/web/RaftDeviceInfo.js +17 -3
- package/dist/web/RaftDeviceInfo.js.map +1 -1
- package/dist/web/RaftDeviceManager.d.ts +19 -1
- package/dist/web/RaftDeviceManager.js +89 -3
- package/dist/web/RaftDeviceManager.js.map +1 -1
- package/dist/web/RaftDeviceStates.d.ts +1 -1
- package/dist/web/RaftDeviceStates.js +2 -2
- package/dist/web/RaftDeviceStates.js.map +1 -1
- package/dist/web/RaftMsgHandler.js.map +1 -1
- package/dist/web/RaftStreamHandler.js +2 -1
- package/dist/web/RaftStreamHandler.js.map +1 -1
- package/dist/web/RaftStruct.js +197 -147
- package/dist/web/RaftStruct.js.map +1 -1
- package/dist/web/RaftUpdateManager.js +1 -1
- package/dist/web/RaftUpdateManager.js.map +1 -1
- package/dist/web/RaftUtils.d.ts +2 -0
- package/dist/web/RaftUtils.js +20 -0
- package/dist/web/RaftUtils.js.map +1 -1
- package/dist/web/main.d.ts +1 -0
- package/dist/web/main.js.map +1 -1
- package/eslint.config.mjs +33 -0
- package/examples/dashboard/package.json +36 -0
- package/examples/dashboard/src/CommandPanel.tsx +147 -0
- package/examples/dashboard/src/ConnManager.ts +166 -0
- package/examples/dashboard/src/DeviceActionsForm.tsx +133 -0
- package/examples/dashboard/src/DeviceAttrsForm.tsx +49 -0
- package/examples/dashboard/src/DeviceLineChart.tsx +163 -0
- package/examples/dashboard/src/DevicePanel.tsx +171 -0
- package/examples/dashboard/src/DevicesPanel.tsx +58 -0
- package/examples/dashboard/src/DispLedGrid.tsx +110 -0
- package/examples/dashboard/src/DispOneLed.tsx +20 -0
- package/examples/dashboard/src/LatencyTest.ts +130 -0
- package/examples/dashboard/src/LatencyTestPanel.tsx +92 -0
- package/examples/dashboard/src/Main.tsx +234 -0
- package/examples/dashboard/src/SettingsManager.ts +67 -0
- package/examples/dashboard/src/SettingsScreen.tsx +174 -0
- package/examples/dashboard/src/StatusPanel.tsx +71 -0
- package/examples/dashboard/src/SystemTypeCog/CogStateInfo.ts +162 -0
- package/examples/dashboard/src/SystemTypeCog/SystemTypeCog.ts +91 -0
- package/examples/dashboard/src/SystemTypeGeneric/StateInfoGeneric.ts +30 -0
- package/examples/dashboard/src/SystemTypeGeneric/SystemTypeGeneric.ts +91 -0
- package/examples/dashboard/src/SystemTypeMarty/RICAddOn.ts +70 -0
- package/examples/dashboard/src/SystemTypeMarty/RICAddOnBase.ts +33 -0
- package/examples/dashboard/src/SystemTypeMarty/RICAddOnManager.ts +342 -0
- package/examples/dashboard/src/SystemTypeMarty/RICCommsStats.ts +170 -0
- package/examples/dashboard/src/SystemTypeMarty/RICHWElem.ts +123 -0
- package/examples/dashboard/src/SystemTypeMarty/RICLEDPatternChecker.ts +207 -0
- package/examples/dashboard/src/SystemTypeMarty/RICROSSerial.ts +464 -0
- package/examples/dashboard/src/SystemTypeMarty/RICServoFaultDetector.ts +146 -0
- package/examples/dashboard/src/SystemTypeMarty/RICStateInfo.ts +97 -0
- package/examples/dashboard/src/SystemTypeMarty/RICSystemUtils.ts +371 -0
- package/examples/dashboard/src/SystemTypeMarty/RICTypes.ts +20 -0
- package/examples/dashboard/src/SystemTypeMarty/SystemTypeMarty.ts +119 -0
- package/examples/dashboard/src/index.html +15 -0
- package/examples/dashboard/src/index.tsx +13 -0
- package/examples/dashboard/src/styles.css +408 -0
- package/examples/dashboard/tsconfig.json +18 -0
- package/jest.config.js +11 -0
- package/package.json +4 -7
- package/src/RaftAttributeHandler.ts +450 -0
- package/src/RaftChannel.ts +32 -0
- package/src/RaftChannelBLE.native.ts +617 -0
- package/src/RaftChannelBLE.web.ts +374 -0
- package/src/RaftChannelBLEFactory.ts +13 -0
- package/src/RaftChannelBLEScanner.native.ts +184 -0
- package/src/RaftChannelSimulated.ts +1176 -0
- package/src/RaftChannelWebSerial.ts +420 -0
- package/src/RaftChannelWebSocket.ts +272 -0
- package/src/RaftCommsStats.ts +142 -0
- package/src/RaftConnEvents.ts +58 -0
- package/src/RaftConnector.ts +785 -0
- package/src/RaftCustomAttrHandler.ts +117 -0
- package/src/RaftDeviceInfo.ts +125 -0
- package/src/RaftDeviceManager.ts +844 -0
- package/src/RaftDeviceMgrIF.ts +33 -0
- package/src/RaftDeviceMsg.ts +20 -0
- package/src/RaftDeviceStates.ts +92 -0
- package/src/RaftFileHandler.ts +668 -0
- package/src/RaftLog.ts +70 -0
- package/src/RaftMiniHDLC.ts +396 -0
- package/src/RaftMsgHandler.ts +812 -0
- package/src/RaftMsgTrackInfo.ts +51 -0
- package/src/RaftProtocolDefs.ts +46 -0
- package/src/RaftStreamHandler.ts +329 -0
- package/src/RaftStruct.ts +282 -0
- package/src/RaftSysTypeManager.ts +87 -0
- package/src/RaftSystemType.ts +34 -0
- package/src/RaftSystemUtils.ts +489 -0
- package/src/RaftTypes.ts +279 -0
- package/src/RaftUpdateEvents.ts +48 -0
- package/src/RaftUpdateManager.ts +781 -0
- package/src/RaftUtils.ts +514 -0
- package/src/RaftWifiTypes.ts +36 -0
- package/src/main.ts +39 -0
- package/testdata/TestDeviceTypeRecs.json +492 -0
- package/tsconfig.json +30 -0
- package/tsconfig.react-native.json +29 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
//
|
|
3
|
+
// RaftCustomAttrHandler
|
|
4
|
+
// Custom attribute handler for Raft devices
|
|
5
|
+
//
|
|
6
|
+
// Rob Dobson (C) 2024
|
|
7
|
+
//
|
|
8
|
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
9
|
+
|
|
10
|
+
import { CustomFunctionDefinition, DeviceTypePollRespMetadata } from "./RaftDeviceInfo";
|
|
11
|
+
|
|
12
|
+
type CustomAttrJsFn = (
|
|
13
|
+
buf: Uint8Array,
|
|
14
|
+
attrValues: Record<string, number[]>,
|
|
15
|
+
attrValueVecs: number[][],
|
|
16
|
+
pollRespMetadata: DeviceTypePollRespMetadata,
|
|
17
|
+
msgBuffer: Uint8Array,
|
|
18
|
+
msgBufIdx: number,
|
|
19
|
+
numMsgBytes: number
|
|
20
|
+
) => void;
|
|
21
|
+
|
|
22
|
+
export default class CustomAttrHandler {
|
|
23
|
+
|
|
24
|
+
private _jsFunctionCache = new Map<string, CustomAttrJsFn>();
|
|
25
|
+
|
|
26
|
+
public handleAttr(pollRespMetadata: DeviceTypePollRespMetadata, msgBuffer: Uint8Array, msgBufIdx: number): number[][] {
|
|
27
|
+
|
|
28
|
+
// Number of bytes in each message
|
|
29
|
+
const numMsgBytes = pollRespMetadata.b;
|
|
30
|
+
|
|
31
|
+
// Create a vector for each attribute in the metadata
|
|
32
|
+
const attrValueVecs: number[][] = [];
|
|
33
|
+
|
|
34
|
+
// Reference to each vector by attribute name
|
|
35
|
+
const attrValues: Record<string, number[]> = {};
|
|
36
|
+
|
|
37
|
+
// Add attributes to the vector
|
|
38
|
+
for (let attrIdx = 0; attrIdx < pollRespMetadata.a.length; attrIdx++) {
|
|
39
|
+
attrValueVecs.push([]);
|
|
40
|
+
attrValues[pollRespMetadata.a[attrIdx].n] = attrValueVecs[attrIdx];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const customFnDef = pollRespMetadata.c;
|
|
44
|
+
if (!customFnDef) {
|
|
45
|
+
return attrValueVecs;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Provide the message buffer sliced to the data portion
|
|
49
|
+
const buf = msgBuffer.slice(msgBufIdx);
|
|
50
|
+
if (buf.length < numMsgBytes) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Execute supplied JS implementation if provided
|
|
55
|
+
if (customFnDef.j && customFnDef.j.trim().length > 0) {
|
|
56
|
+
const jsFn = this.getOrCompileJsFunction(customFnDef);
|
|
57
|
+
if (!jsFn) {
|
|
58
|
+
return attrValueVecs;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
jsFn(buf, attrValues, attrValueVecs, pollRespMetadata, msgBuffer, msgBufIdx, numMsgBytes);
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.error(`CustomAttrHandler JS function ${customFnDef.n} execution failed`, err);
|
|
64
|
+
}
|
|
65
|
+
return attrValueVecs;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Custom code for each device type handled natively
|
|
69
|
+
if (customFnDef.n === "max30101_fifo") {
|
|
70
|
+
// Generated code ...
|
|
71
|
+
const N = (buf[0] + 32 - buf[2]) % 32;
|
|
72
|
+
let k = 3;
|
|
73
|
+
let i = 0;
|
|
74
|
+
while (i < N) {
|
|
75
|
+
attrValues["Red"].push(0);
|
|
76
|
+
attrValues["Red"][attrValues["Red"].length - 1] = (buf[k] << 16) | (buf[k + 1] << 8) | buf[k + 2];
|
|
77
|
+
attrValues["IR"].push(0);
|
|
78
|
+
attrValues["IR"][attrValues["IR"].length - 1] = (buf[k + 3] << 16) | (buf[k + 4] << 8) | buf[k + 5];
|
|
79
|
+
k += 6;
|
|
80
|
+
i++;
|
|
81
|
+
}
|
|
82
|
+
} else if (customFnDef.n === "gravity_o2_calc") {
|
|
83
|
+
const key = 20.9 / 120.0;
|
|
84
|
+
const val = key * (buf[0] + buf[1] / 10.0 + buf[2] / 100.0);
|
|
85
|
+
attrValues["oxygen"].push(val);
|
|
86
|
+
}
|
|
87
|
+
return attrValueVecs;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private getOrCompileJsFunction(customFnDef: CustomFunctionDefinition): CustomAttrJsFn | null {
|
|
91
|
+
if (!customFnDef.j) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const cacheKey = `${customFnDef.n}::${customFnDef.j}`;
|
|
95
|
+
const cachedFn = this._jsFunctionCache.get(cacheKey);
|
|
96
|
+
if (cachedFn) {
|
|
97
|
+
return cachedFn;
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const compiledFn = new Function(
|
|
101
|
+
"buf",
|
|
102
|
+
"attrValues",
|
|
103
|
+
"attrValueVecs",
|
|
104
|
+
"pollRespMetadata",
|
|
105
|
+
"msgBuffer",
|
|
106
|
+
"msgBufIdx",
|
|
107
|
+
"numMsgBytes",
|
|
108
|
+
customFnDef.j
|
|
109
|
+
) as CustomAttrJsFn;
|
|
110
|
+
this._jsFunctionCache.set(cacheKey, compiledFn);
|
|
111
|
+
return compiledFn;
|
|
112
|
+
} catch (err) {
|
|
113
|
+
console.error(`CustomAttrHandler failed to compile JS function ${customFnDef.n}`, err);
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
//
|
|
3
|
+
// RaftDeviceInfo
|
|
4
|
+
// Device information for Raft devices
|
|
5
|
+
//
|
|
6
|
+
// Rob Dobson (C) 2024
|
|
7
|
+
//
|
|
8
|
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
9
|
+
|
|
10
|
+
const attrTypeBits: { [key: string]: number } = {
|
|
11
|
+
"c": 8, "b": 8, "B": 8, "?": 8,
|
|
12
|
+
"h": 16, "H": 16, ">h": 16, "<h": 16, ">H": 16, "<H": 16,
|
|
13
|
+
"i": 32, "I": 32, ">i": 32, "<i": 32, ">I": 32, "<I": 32, "l": 32, "L": 32, ">l": 32, "<l": 32, ">L": 32, "<L": 32,
|
|
14
|
+
"q": 64, "Q": 64, ">q": 64, "<q": 64, ">Q": 64, "<Q": 64,
|
|
15
|
+
"f": 32, ">f": 32, "<f": 32,
|
|
16
|
+
"d": 64, ">d": 64, "<d": 64,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function getAttrTypeBits(attrType: string): number {
|
|
20
|
+
let repeat = 1;
|
|
21
|
+
let baseAttrType = attrType;
|
|
22
|
+
|
|
23
|
+
const repeatStartIdx = attrType.indexOf("[");
|
|
24
|
+
if (repeatStartIdx >= 0) {
|
|
25
|
+
const repeatEndIdx = attrType.indexOf("]", repeatStartIdx + 1);
|
|
26
|
+
if (repeatEndIdx > repeatStartIdx) {
|
|
27
|
+
const repeatStr = attrType.slice(repeatStartIdx + 1, repeatEndIdx);
|
|
28
|
+
const parsedRepeat = parseInt(repeatStr, 10);
|
|
29
|
+
if (Number.isFinite(parsedRepeat) && parsedRepeat > 0) {
|
|
30
|
+
repeat = parsedRepeat;
|
|
31
|
+
}
|
|
32
|
+
baseAttrType = attrType.slice(0, repeatStartIdx);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (baseAttrType in attrTypeBits) {
|
|
37
|
+
return attrTypeBits[baseAttrType] * repeat;
|
|
38
|
+
}
|
|
39
|
+
return 8 * repeat;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function isAttrTypeSigned(attrType: string): boolean {
|
|
43
|
+
const attrStr = attrType.charAt(0) === ">" || attrType.charAt(0) === "<" ? attrType.slice(1).charAt(0) : attrType.charAt(0);
|
|
44
|
+
return attrStr === "b" || attrStr === "h" || attrStr === "i" || attrStr === "l" || attrStr === "q";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function decodeAttrUnitsEncoding(unitsEncoding: string): string {
|
|
48
|
+
// Replace instances of HTML encoded chars like ° with the actual char
|
|
49
|
+
return unitsEncoding.replace(/°/g, "°");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface LUTRow {
|
|
53
|
+
r: string;
|
|
54
|
+
v: number;
|
|
55
|
+
}
|
|
56
|
+
export interface DeviceTypeAttribute {
|
|
57
|
+
n: string; // Name
|
|
58
|
+
t: string; // Type in python struct module format (e.g. 'H' uint16, 'h' int16, 'f' float etc.)
|
|
59
|
+
at?: number | number[]; // Start pos in buffer (after timestamp) if present (otherwise use relative position) or array of byte positions for non-contiguous data
|
|
60
|
+
u?: string; // Units (e.g. mm)
|
|
61
|
+
r?: number[]; // Range (either min, max or min, max, step or discrete values)
|
|
62
|
+
x?: number | string; // XOR bit mask to invert bits in the attribute value
|
|
63
|
+
m?: number | string; // AND bit mask to extract the attribute value from the message
|
|
64
|
+
s?: number; // Shift value to shift the attribute value to the right (or left if negative)
|
|
65
|
+
sb?: number; // Sign-bit position (0-based)
|
|
66
|
+
ss?: number; // Sign-bit subtraction value
|
|
67
|
+
d?: number; // Divisor to convert the raw attribute value (after operations above) to the actual value
|
|
68
|
+
a?: number; // Value to add after division
|
|
69
|
+
f?: string; // Format string similar to C printf format string (e.g. %d, %x, %f, %04d, %08x, %08.2f etc.), %b = boolean (0 iff 0, else 1)
|
|
70
|
+
o?: string; // Type of output value (e.g. 'bool', 'uint8', 'float')
|
|
71
|
+
v?: boolean | number; // Visibility of the attribute in all locations (mainly used to hide attributes that are not useful to the user)
|
|
72
|
+
vs?: boolean | number; // Display attribute value in time-series graphs
|
|
73
|
+
vf?: boolean | number; // Display attribute value in the device info panel
|
|
74
|
+
vft?: string; // Attribute validity based on the value of another named attribute
|
|
75
|
+
lut?: Array<LUTRow>; // Lookup table for the attribute value - each row is a lookup table for a range of values e.g. [{"r":"0x20-0x30","v":0},{"r":"1,2,3","v":42},{r:"","v":1}]
|
|
76
|
+
resolution?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface CustomFunctionDefinition {
|
|
80
|
+
n: string; // Function name
|
|
81
|
+
c: string; // Function pseudo-code
|
|
82
|
+
j?: string; // Optional JavaScript implementation
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface DeviceTypePollRespMetadata {
|
|
86
|
+
b: number; // Size of polled response data block in bytes (excluding timestamp)
|
|
87
|
+
a: DeviceTypeAttribute[]; // Attributes in the polled response
|
|
88
|
+
c?: CustomFunctionDefinition; // Custom function definition
|
|
89
|
+
us?: number; // Time between consecutive samples in microseconds
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface DeviceTypeAction {
|
|
93
|
+
n: string; // Action name
|
|
94
|
+
t?: string; // Action type using python struct module format (e.g. 'H' for unsigned short, 'h' for signed short, 'f' for float etc.)
|
|
95
|
+
w: string; // Prefix to write to cmd API
|
|
96
|
+
wz?: string; // Postfix to write to cmd API
|
|
97
|
+
r?: number[]; // Range of valid values for the action
|
|
98
|
+
f?: string; // Custom formatting options (e.g. LEDPIX for LED pixel grid)
|
|
99
|
+
NX?: number; // Number of X in the LED pixel grid
|
|
100
|
+
NY?: number; // Number of Y in the LED pixel grid
|
|
101
|
+
concat?: boolean; // Concatenate the all values into a single command
|
|
102
|
+
mul?: number; // Multiplier to apply
|
|
103
|
+
sub?: number; // Value to subtract before multiplying
|
|
104
|
+
d?: number; // Default value
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface DeviceTypeInfo {
|
|
108
|
+
name: string;
|
|
109
|
+
desc: string;
|
|
110
|
+
manu: string;
|
|
111
|
+
type: string;
|
|
112
|
+
resp?: DeviceTypePollRespMetadata;
|
|
113
|
+
clas?: Array<string>;
|
|
114
|
+
actions?: DeviceTypeAction[];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface DeviceTypeInfoRecs {
|
|
118
|
+
[devType: string]: DeviceTypeInfo;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type RaftDevTypeInfoResponse = {
|
|
122
|
+
req: string;
|
|
123
|
+
rslt: string;
|
|
124
|
+
devinfo: DeviceTypeInfo;
|
|
125
|
+
};
|