@robdobsn/raftjs 1.1.1
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/LICENSE +22 -0
- package/README.md +11 -0
- package/TODO.md +1 -0
- package/dist/RaftAttributeHandler.d.ts +12 -0
- package/dist/RaftAttributeHandler.js +241 -0
- package/dist/RaftAttributeHandler.js.map +1 -0
- package/dist/RaftChannel.d.ts +18 -0
- package/dist/RaftChannel.js +12 -0
- package/dist/RaftChannel.js.map +1 -0
- package/dist/RaftChannelWebBLE.d.ts +38 -0
- package/dist/RaftChannelWebBLE.js +274 -0
- package/dist/RaftChannelWebBLE.js.map +1 -0
- package/dist/RaftChannelWebSerial.d.ts +37 -0
- package/dist/RaftChannelWebSerial.js +319 -0
- package/dist/RaftChannelWebSerial.js.map +1 -0
- package/dist/RaftChannelWebSocket.d.ts +28 -0
- package/dist/RaftChannelWebSocket.js +197 -0
- package/dist/RaftChannelWebSocket.js.map +1 -0
- package/dist/RaftCommsStats.d.ts +39 -0
- package/dist/RaftCommsStats.js +128 -0
- package/dist/RaftCommsStats.js.map +1 -0
- package/dist/RaftConnEvents.d.ts +31 -0
- package/dist/RaftConnEvents.js +44 -0
- package/dist/RaftConnEvents.js.map +1 -0
- package/dist/RaftConnector.d.ts +242 -0
- package/dist/RaftConnector.js +613 -0
- package/dist/RaftConnector.js.map +1 -0
- package/dist/RaftCustomAttrHandler.d.ts +4 -0
- package/dist/RaftCustomAttrHandler.js +50 -0
- package/dist/RaftCustomAttrHandler.js.map +1 -0
- package/dist/RaftDeviceInfo.d.ts +64 -0
- package/dist/RaftDeviceInfo.js +36 -0
- package/dist/RaftDeviceInfo.js.map +1 -0
- package/dist/RaftDeviceManager.d.ts +37 -0
- package/dist/RaftDeviceManager.js +450 -0
- package/dist/RaftDeviceManager.js.map +1 -0
- package/dist/RaftDeviceMsg.d.ts +9 -0
- package/dist/RaftDeviceMsg.js +11 -0
- package/dist/RaftDeviceMsg.js.map +1 -0
- package/dist/RaftDeviceStates.d.ts +33 -0
- package/dist/RaftDeviceStates.js +60 -0
- package/dist/RaftDeviceStates.js.map +1 -0
- package/dist/RaftFileHandler.d.ts +52 -0
- package/dist/RaftFileHandler.js +502 -0
- package/dist/RaftFileHandler.js.map +1 -0
- package/dist/RaftLog.d.ts +22 -0
- package/dist/RaftLog.js +63 -0
- package/dist/RaftLog.js.map +1 -0
- package/dist/RaftMiniHDLC.d.ts +18 -0
- package/dist/RaftMiniHDLC.js +383 -0
- package/dist/RaftMiniHDLC.js.map +1 -0
- package/dist/RaftMsgHandler.d.ts +57 -0
- package/dist/RaftMsgHandler.js +480 -0
- package/dist/RaftMsgHandler.js.map +1 -0
- package/dist/RaftMsgTrackInfo.d.ts +17 -0
- package/dist/RaftMsgTrackInfo.js +42 -0
- package/dist/RaftMsgTrackInfo.js.map +1 -0
- package/dist/RaftProtocolDefs.d.ts +30 -0
- package/dist/RaftProtocolDefs.js +48 -0
- package/dist/RaftProtocolDefs.js.map +1 -0
- package/dist/RaftStreamHandler.d.ts +38 -0
- package/dist/RaftStreamHandler.js +257 -0
- package/dist/RaftStreamHandler.js.map +1 -0
- package/dist/RaftSystemType.d.ts +21 -0
- package/dist/RaftSystemType.js +3 -0
- package/dist/RaftSystemType.js.map +1 -0
- package/dist/RaftSystemUtils.d.ts +136 -0
- package/dist/RaftSystemUtils.js +410 -0
- package/dist/RaftSystemUtils.js.map +1 -0
- package/dist/RaftTypes.d.ts +184 -0
- package/dist/RaftTypes.js +157 -0
- package/dist/RaftTypes.js.map +1 -0
- package/dist/RaftUpdateEvents.d.ts +33 -0
- package/dist/RaftUpdateEvents.js +46 -0
- package/dist/RaftUpdateEvents.js.map +1 -0
- package/dist/RaftUpdateManager.d.ts +61 -0
- package/dist/RaftUpdateManager.js +618 -0
- package/dist/RaftUpdateManager.js.map +1 -0
- package/dist/RaftUtils.d.ts +125 -0
- package/dist/RaftUtils.js +454 -0
- package/dist/RaftUtils.js.map +1 -0
- package/dist/RaftWifiTypes.d.ts +23 -0
- package/dist/RaftWifiTypes.js +43 -0
- package/dist/RaftWifiTypes.js.map +1 -0
- package/dist/TestDataGen.d.ts +7 -0
- package/dist/TestDataGen.js +133 -0
- package/dist/TestDataGen.js.map +1 -0
- package/dist/main.d.ts +18 -0
- package/dist/main.js +42 -0
- package/dist/main.js.map +1 -0
- package/eslint.config.mjs +33 -0
- package/examples/dashboard/package.json +39 -0
- package/examples/dashboard/src/ConnManager.ts +86 -0
- package/examples/dashboard/src/Main.tsx +100 -0
- package/examples/dashboard/src/StatusScreen.tsx +72 -0
- package/examples/dashboard/src/SystemTypeCog/CogStateInfo.ts +144 -0
- package/examples/dashboard/src/SystemTypeCog/SystemTypeCog.ts +77 -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 +32 -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 +113 -0
- package/examples/dashboard/src/index.html +15 -0
- package/examples/dashboard/src/index.tsx +15 -0
- package/examples/dashboard/src/styles.css +122 -0
- package/examples/dashboard/tsconfig.json +18 -0
- package/jest.config.js +11 -0
- package/package.json +50 -0
- package/src/RaftAttributeHandler.ts +289 -0
- package/src/RaftChannel.ts +30 -0
- package/src/RaftChannelWebBLE.ts +342 -0
- package/src/RaftChannelWebSerial.ts +408 -0
- package/src/RaftChannelWebSocket.ts +245 -0
- package/src/RaftCommsStats.ts +142 -0
- package/src/RaftConnEvents.ts +46 -0
- package/src/RaftConnector.ts +745 -0
- package/src/RaftCustomAttrHandler.ts +54 -0
- package/src/RaftDeviceInfo.ts +104 -0
- package/src/RaftDeviceManager.ts +542 -0
- package/src/RaftDeviceMsg.ts +20 -0
- package/src/RaftDeviceStates.ts +89 -0
- package/src/RaftFileHandler.ts +668 -0
- package/src/RaftLog.ts +70 -0
- package/src/RaftMiniHDLC.ts +396 -0
- package/src/RaftMsgHandler.ts +778 -0
- package/src/RaftMsgTrackInfo.ts +51 -0
- package/src/RaftProtocolDefs.ts +46 -0
- package/src/RaftStreamHandler.ts +328 -0
- package/src/RaftSystemType.ts +25 -0
- package/src/RaftSystemUtils.ts +487 -0
- package/src/RaftTypes.ts +250 -0
- package/src/RaftUpdateEvents.ts +48 -0
- package/src/RaftUpdateManager.ts +778 -0
- package/src/RaftUtils.ts +484 -0
- package/src/RaftWifiTypes.ts +36 -0
- package/src/TestDataGen.ts +157 -0
- package/src/main.ts +28 -0
- package/testdata/TestDeviceTypeRecs.json +492 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
//
|
|
3
|
+
// RaftCustomAttrHandler
|
|
4
|
+
// Custom attribute handler for Raft devices
|
|
5
|
+
//
|
|
6
|
+
// Rob Dobson (C) 2024
|
|
7
|
+
//
|
|
8
|
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
9
|
+
|
|
10
|
+
import { DeviceTypePollRespMetadata } from "./RaftDeviceInfo";
|
|
11
|
+
|
|
12
|
+
export default class CustomAttrHandler {
|
|
13
|
+
|
|
14
|
+
public handleAttr(pollRespMetadata: DeviceTypePollRespMetadata, msgBuffer: Buffer, msgBufIdx: number): number[][] {
|
|
15
|
+
|
|
16
|
+
// Number of bytes in the each message
|
|
17
|
+
const numMsgBytes = pollRespMetadata.b;
|
|
18
|
+
|
|
19
|
+
// Create a vector for each attribute in the metadata
|
|
20
|
+
let attrValueVecs: [][] = [];
|
|
21
|
+
|
|
22
|
+
// Reference to each vector by attribute name
|
|
23
|
+
let attrValues: { [key: string]: number[] } = {};
|
|
24
|
+
|
|
25
|
+
// Add attributes to the vector
|
|
26
|
+
for (let attrIdx = 0; attrIdx < pollRespMetadata.a.length; attrIdx++) {
|
|
27
|
+
attrValueVecs.push([]);
|
|
28
|
+
attrValues[pollRespMetadata.a[attrIdx].n] = attrValueVecs[attrIdx];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Custom code for each device type
|
|
32
|
+
if (pollRespMetadata.c!.n === "max30101_fifo") {
|
|
33
|
+
// Hex dump msgBuffer
|
|
34
|
+
// console.log(`CustomAttrHandler handleAttr ${pollRespMetadata.c!.n} msgBuffer: ${msgBuffer.toString('hex')}`);
|
|
35
|
+
let buf = msgBuffer.slice(msgBufIdx);
|
|
36
|
+
if (buf.length < numMsgBytes) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Generated code ...
|
|
41
|
+
let N=(buf[0]+32-buf[2])%32;
|
|
42
|
+
let k=3;
|
|
43
|
+
let i=0;
|
|
44
|
+
while (i<N) {
|
|
45
|
+
attrValues['Red'].push(0); attrValues['Red'][attrValues['Red'].length-1] =(buf[k]<<16)|(buf[k+1]<<8)|buf[k+2];
|
|
46
|
+
attrValues['IR'].push(0); attrValues['IR'][attrValues['IR'].length-1] =(buf[k+3]<<16)|(buf[k+4]<<8)|buf[k+5];
|
|
47
|
+
k+=6;
|
|
48
|
+
i++;
|
|
49
|
+
;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return attrValueVecs;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
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
|
+
if (attrType in attrTypeBits) {
|
|
21
|
+
return attrTypeBits[attrType];
|
|
22
|
+
}
|
|
23
|
+
return 8;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isAttrTypeSigned(attrType: string): boolean {
|
|
27
|
+
const attrStr = attrType.charAt(0) === ">" || attrType.charAt(0) === "<" ? attrType.slice(1).charAt(0) : attrType.charAt(0);
|
|
28
|
+
return attrStr === "b" || attrStr === "h" || attrStr === "i" || attrStr === "l" || attrStr === "q";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function decodeAttrUnitsEncoding(unitsEncoding: string): string {
|
|
32
|
+
// Replace instances of HTML encoded chars like ° with the actual char
|
|
33
|
+
return unitsEncoding.replace(/°/g, "°");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface DeviceTypeAttribute {
|
|
37
|
+
n: string; // Name
|
|
38
|
+
t: string; // Type in python struct module format (e.g. 'H' uint16, 'h' int16, 'f' float etc.)
|
|
39
|
+
at?: number; // Start pos in buffer (after timestamp) if present (otherwise use relative position)
|
|
40
|
+
u?: string; // Units (e.g. mm)
|
|
41
|
+
r?: number[]; // Range (either min, max or min, max, step or discrete values)
|
|
42
|
+
x?: number; // XOR bit mask to invert bits in the attribute value
|
|
43
|
+
m?: number | string; // AND bit mask to extract the attribute value from the message
|
|
44
|
+
s?: number; // Shift value to shift the attribute value to the right (or left if negative)
|
|
45
|
+
sb?: number; // Sign-bit position (0-based)
|
|
46
|
+
ss?: number; // Sign-bit subtraction value
|
|
47
|
+
d?: number; // Divisor to convert the raw attribute value (after operations above) to the actual value
|
|
48
|
+
a?: number; // Value to add after division
|
|
49
|
+
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)
|
|
50
|
+
o?: string; // Type of output value (e.g. 'bool', 'uint8', 'float')
|
|
51
|
+
v?: boolean | number; // Visibility of the attribute in all locations (mainly used to hide attributes that are not useful to the user)
|
|
52
|
+
vs?: boolean | number; // Display attribute value in time-series graphs
|
|
53
|
+
vf?: boolean | number; // Display attribute value in the device info panel
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface CustomFunctionDefinition {
|
|
57
|
+
n: string; // Function name
|
|
58
|
+
c: string; // Function pseudo-code
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface DeviceTypePollRespMetadata {
|
|
62
|
+
b: number; // Size of polled response data block in bytes (excluding timestamp)
|
|
63
|
+
a: DeviceTypeAttribute[]; // Attributes in the polled response
|
|
64
|
+
c?: CustomFunctionDefinition; // Custom function definition
|
|
65
|
+
us?: number; // Time between consecutive samples in microseconds
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface DeviceTypeAction {
|
|
69
|
+
n: string; // Action name
|
|
70
|
+
t?: string; // Action type using python struct module format (e.g. 'H' for unsigned short, 'h' for signed short, 'f' for float etc.)
|
|
71
|
+
w: string; // Prefix to write to cmd API
|
|
72
|
+
r?: number[]; // Range of valid values for the action
|
|
73
|
+
f?: string; // Custom formatting options (e.g. LEDPIX for LED pixel grid)
|
|
74
|
+
NX?: number; // Number of X in the LED pixel grid
|
|
75
|
+
NY?: number; // Number of Y in the LED pixel grid
|
|
76
|
+
concat?: boolean; // Concatenate the all values into a single command
|
|
77
|
+
d?: number; // Default value
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface DeviceTypeInfo {
|
|
81
|
+
name: string;
|
|
82
|
+
desc: string;
|
|
83
|
+
manu: string;
|
|
84
|
+
type: string;
|
|
85
|
+
resp?: DeviceTypePollRespMetadata;
|
|
86
|
+
actions?: DeviceTypeAction[];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface DeviceTypeInfoRecs {
|
|
90
|
+
[devType: string]: DeviceTypeInfo;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface DeviceTypeInfoTestJsonRec {
|
|
94
|
+
addresses?: string;
|
|
95
|
+
devInfoJson: DeviceTypeInfo;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface DeviceTypeInfoTestJsonElem {
|
|
99
|
+
[devType: string]: DeviceTypeInfoTestJsonRec;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface DeviceTypeInfoTestJsonFile {
|
|
103
|
+
devTypes: DeviceTypeInfoTestJsonElem;
|
|
104
|
+
}
|