@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.
Files changed (149) hide show
  1. package/.editorconfig +14 -0
  2. package/.gitattributes +11 -0
  3. package/.nvmrc +1 -0
  4. package/LICENSE +22 -0
  5. package/README.md +11 -0
  6. package/TODO.md +1 -0
  7. package/dist/RaftAttributeHandler.d.ts +12 -0
  8. package/dist/RaftAttributeHandler.js +241 -0
  9. package/dist/RaftAttributeHandler.js.map +1 -0
  10. package/dist/RaftChannel.d.ts +18 -0
  11. package/dist/RaftChannel.js +12 -0
  12. package/dist/RaftChannel.js.map +1 -0
  13. package/dist/RaftChannelWebBLE.d.ts +38 -0
  14. package/dist/RaftChannelWebBLE.js +274 -0
  15. package/dist/RaftChannelWebBLE.js.map +1 -0
  16. package/dist/RaftChannelWebSerial.d.ts +37 -0
  17. package/dist/RaftChannelWebSerial.js +319 -0
  18. package/dist/RaftChannelWebSerial.js.map +1 -0
  19. package/dist/RaftChannelWebSocket.d.ts +28 -0
  20. package/dist/RaftChannelWebSocket.js +197 -0
  21. package/dist/RaftChannelWebSocket.js.map +1 -0
  22. package/dist/RaftCommsStats.d.ts +39 -0
  23. package/dist/RaftCommsStats.js +128 -0
  24. package/dist/RaftCommsStats.js.map +1 -0
  25. package/dist/RaftConnEvents.d.ts +31 -0
  26. package/dist/RaftConnEvents.js +44 -0
  27. package/dist/RaftConnEvents.js.map +1 -0
  28. package/dist/RaftConnector.d.ts +242 -0
  29. package/dist/RaftConnector.js +613 -0
  30. package/dist/RaftConnector.js.map +1 -0
  31. package/dist/RaftCustomAttrHandler.d.ts +4 -0
  32. package/dist/RaftCustomAttrHandler.js +50 -0
  33. package/dist/RaftCustomAttrHandler.js.map +1 -0
  34. package/dist/RaftDeviceInfo.d.ts +64 -0
  35. package/dist/RaftDeviceInfo.js +36 -0
  36. package/dist/RaftDeviceInfo.js.map +1 -0
  37. package/dist/RaftDeviceManager.d.ts +37 -0
  38. package/dist/RaftDeviceManager.js +450 -0
  39. package/dist/RaftDeviceManager.js.map +1 -0
  40. package/dist/RaftDeviceMsg.d.ts +9 -0
  41. package/dist/RaftDeviceMsg.js +11 -0
  42. package/dist/RaftDeviceMsg.js.map +1 -0
  43. package/dist/RaftDeviceStates.d.ts +33 -0
  44. package/dist/RaftDeviceStates.js +60 -0
  45. package/dist/RaftDeviceStates.js.map +1 -0
  46. package/dist/RaftFileHandler.d.ts +52 -0
  47. package/dist/RaftFileHandler.js +502 -0
  48. package/dist/RaftFileHandler.js.map +1 -0
  49. package/dist/RaftLog.d.ts +22 -0
  50. package/dist/RaftLog.js +63 -0
  51. package/dist/RaftLog.js.map +1 -0
  52. package/dist/RaftMiniHDLC.d.ts +18 -0
  53. package/dist/RaftMiniHDLC.js +383 -0
  54. package/dist/RaftMiniHDLC.js.map +1 -0
  55. package/dist/RaftMsgHandler.d.ts +57 -0
  56. package/dist/RaftMsgHandler.js +480 -0
  57. package/dist/RaftMsgHandler.js.map +1 -0
  58. package/dist/RaftMsgTrackInfo.d.ts +17 -0
  59. package/dist/RaftMsgTrackInfo.js +42 -0
  60. package/dist/RaftMsgTrackInfo.js.map +1 -0
  61. package/dist/RaftProtocolDefs.d.ts +30 -0
  62. package/dist/RaftProtocolDefs.js +48 -0
  63. package/dist/RaftProtocolDefs.js.map +1 -0
  64. package/dist/RaftStreamHandler.d.ts +38 -0
  65. package/dist/RaftStreamHandler.js +257 -0
  66. package/dist/RaftStreamHandler.js.map +1 -0
  67. package/dist/RaftSystemType.d.ts +21 -0
  68. package/dist/RaftSystemType.js +3 -0
  69. package/dist/RaftSystemType.js.map +1 -0
  70. package/dist/RaftSystemUtils.d.ts +136 -0
  71. package/dist/RaftSystemUtils.js +410 -0
  72. package/dist/RaftSystemUtils.js.map +1 -0
  73. package/dist/RaftTypes.d.ts +184 -0
  74. package/dist/RaftTypes.js +157 -0
  75. package/dist/RaftTypes.js.map +1 -0
  76. package/dist/RaftUpdateEvents.d.ts +33 -0
  77. package/dist/RaftUpdateEvents.js +46 -0
  78. package/dist/RaftUpdateEvents.js.map +1 -0
  79. package/dist/RaftUpdateManager.d.ts +61 -0
  80. package/dist/RaftUpdateManager.js +618 -0
  81. package/dist/RaftUpdateManager.js.map +1 -0
  82. package/dist/RaftUtils.d.ts +125 -0
  83. package/dist/RaftUtils.js +454 -0
  84. package/dist/RaftUtils.js.map +1 -0
  85. package/dist/RaftWifiTypes.d.ts +23 -0
  86. package/dist/RaftWifiTypes.js +43 -0
  87. package/dist/RaftWifiTypes.js.map +1 -0
  88. package/dist/TestDataGen.d.ts +7 -0
  89. package/dist/TestDataGen.js +133 -0
  90. package/dist/TestDataGen.js.map +1 -0
  91. package/dist/main.d.ts +18 -0
  92. package/dist/main.js +42 -0
  93. package/dist/main.js.map +1 -0
  94. package/eslint.config.mjs +33 -0
  95. package/examples/dashboard/package.json +39 -0
  96. package/examples/dashboard/src/ConnManager.ts +86 -0
  97. package/examples/dashboard/src/Main.tsx +100 -0
  98. package/examples/dashboard/src/StatusScreen.tsx +72 -0
  99. package/examples/dashboard/src/SystemTypeCog/CogStateInfo.ts +144 -0
  100. package/examples/dashboard/src/SystemTypeCog/SystemTypeCog.ts +77 -0
  101. package/examples/dashboard/src/SystemTypeMarty/RICAddOn.ts +70 -0
  102. package/examples/dashboard/src/SystemTypeMarty/RICAddOnBase.ts +33 -0
  103. package/examples/dashboard/src/SystemTypeMarty/RICAddOnManager.ts +342 -0
  104. package/examples/dashboard/src/SystemTypeMarty/RICCommsStats.ts +170 -0
  105. package/examples/dashboard/src/SystemTypeMarty/RICHWElem.ts +123 -0
  106. package/examples/dashboard/src/SystemTypeMarty/RICLEDPatternChecker.ts +207 -0
  107. package/examples/dashboard/src/SystemTypeMarty/RICROSSerial.ts +464 -0
  108. package/examples/dashboard/src/SystemTypeMarty/RICServoFaultDetector.ts +146 -0
  109. package/examples/dashboard/src/SystemTypeMarty/RICStateInfo.ts +32 -0
  110. package/examples/dashboard/src/SystemTypeMarty/RICSystemUtils.ts +371 -0
  111. package/examples/dashboard/src/SystemTypeMarty/RICTypes.ts +20 -0
  112. package/examples/dashboard/src/SystemTypeMarty/SystemTypeMarty.ts +113 -0
  113. package/examples/dashboard/src/index.html +15 -0
  114. package/examples/dashboard/src/index.tsx +15 -0
  115. package/examples/dashboard/src/styles.css +122 -0
  116. package/examples/dashboard/tsconfig.json +18 -0
  117. package/jest.config.js +11 -0
  118. package/package.json +50 -0
  119. package/src/RaftAttributeHandler.ts +289 -0
  120. package/src/RaftChannel.ts +30 -0
  121. package/src/RaftChannelWebBLE.ts +342 -0
  122. package/src/RaftChannelWebSerial.ts +408 -0
  123. package/src/RaftChannelWebSocket.ts +245 -0
  124. package/src/RaftCommsStats.ts +142 -0
  125. package/src/RaftConnEvents.ts +46 -0
  126. package/src/RaftConnector.ts +745 -0
  127. package/src/RaftCustomAttrHandler.ts +54 -0
  128. package/src/RaftDeviceInfo.ts +104 -0
  129. package/src/RaftDeviceManager.ts +542 -0
  130. package/src/RaftDeviceMsg.ts +20 -0
  131. package/src/RaftDeviceStates.ts +89 -0
  132. package/src/RaftFileHandler.ts +668 -0
  133. package/src/RaftLog.ts +70 -0
  134. package/src/RaftMiniHDLC.ts +396 -0
  135. package/src/RaftMsgHandler.ts +778 -0
  136. package/src/RaftMsgTrackInfo.ts +51 -0
  137. package/src/RaftProtocolDefs.ts +46 -0
  138. package/src/RaftStreamHandler.ts +328 -0
  139. package/src/RaftSystemType.ts +25 -0
  140. package/src/RaftSystemUtils.ts +487 -0
  141. package/src/RaftTypes.ts +250 -0
  142. package/src/RaftUpdateEvents.ts +48 -0
  143. package/src/RaftUpdateManager.ts +778 -0
  144. package/src/RaftUtils.ts +484 -0
  145. package/src/RaftWifiTypes.ts +36 -0
  146. package/src/TestDataGen.ts +157 -0
  147. package/src/main.ts +28 -0
  148. package/testdata/TestDeviceTypeRecs.json +492 -0
  149. 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 &deg; with the actual char
33
+ return unitsEncoding.replace(/&deg;/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
+ }