@robdobsn/raftjs 1.7.2 → 1.7.5

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 (198) hide show
  1. package/dist/web/RaftAttributeHandler.d.ts +2 -0
  2. package/dist/web/RaftAttributeHandler.js +107 -5
  3. package/dist/web/RaftAttributeHandler.js.map +1 -1
  4. package/dist/web/RaftConnector.d.ts +2 -1
  5. package/dist/web/RaftConnector.js +14 -0
  6. package/dist/web/RaftConnector.js.map +1 -1
  7. package/dist/web/RaftDeviceInfo.d.ts +6 -0
  8. package/dist/web/RaftMsgHandler.d.ts +1 -1
  9. package/dist/web/RaftMsgHandler.js +1 -1
  10. package/dist/web/RaftMsgHandler.js.map +1 -1
  11. package/dist/web/RaftTypes.d.ts +2 -1
  12. package/dist/web/RaftTypes.js.map +1 -1
  13. package/package.json +5 -2
  14. package/.editorconfig +0 -14
  15. package/.gitattributes +0 -11
  16. package/.nvmrc +0 -1
  17. package/TODO.md +0 -1
  18. package/dist/react-native/RaftAttributeHandler.d.ts +0 -12
  19. package/dist/react-native/RaftAttributeHandler.js +0 -249
  20. package/dist/react-native/RaftAttributeHandler.js.map +0 -1
  21. package/dist/react-native/RaftChannel.d.ts +0 -20
  22. package/dist/react-native/RaftChannel.js +0 -12
  23. package/dist/react-native/RaftChannel.js.map +0 -1
  24. package/dist/react-native/RaftChannelBLE.native.d.ts +0 -95
  25. package/dist/react-native/RaftChannelBLE.native.js +0 -482
  26. package/dist/react-native/RaftChannelBLE.native.js.map +0 -1
  27. package/dist/react-native/RaftChannelBLE.web.d.ts +0 -40
  28. package/dist/react-native/RaftChannelBLE.web.js +0 -300
  29. package/dist/react-native/RaftChannelBLE.web.js.map +0 -1
  30. package/dist/react-native/RaftChannelBLEFactory.d.ts +0 -10
  31. package/dist/react-native/RaftChannelBLEFactory.js +0 -17
  32. package/dist/react-native/RaftChannelBLEFactory.js.map +0 -1
  33. package/dist/react-native/RaftChannelBLEScanner.native.d.ts +0 -18
  34. package/dist/react-native/RaftChannelBLEScanner.native.js +0 -138
  35. package/dist/react-native/RaftChannelBLEScanner.native.js.map +0 -1
  36. package/dist/react-native/RaftChannelSimulated.d.ts +0 -32
  37. package/dist/react-native/RaftChannelSimulated.js +0 -418
  38. package/dist/react-native/RaftChannelSimulated.js.map +0 -1
  39. package/dist/react-native/RaftChannelWebSerial.d.ts +0 -39
  40. package/dist/react-native/RaftChannelWebSerial.js +0 -329
  41. package/dist/react-native/RaftChannelWebSerial.js.map +0 -1
  42. package/dist/react-native/RaftChannelWebSocket.d.ts +0 -30
  43. package/dist/react-native/RaftChannelWebSocket.js +0 -207
  44. package/dist/react-native/RaftChannelWebSocket.js.map +0 -1
  45. package/dist/react-native/RaftCommsStats.d.ts +0 -39
  46. package/dist/react-native/RaftCommsStats.js +0 -128
  47. package/dist/react-native/RaftCommsStats.js.map +0 -1
  48. package/dist/react-native/RaftConnEvents.d.ts +0 -39
  49. package/dist/react-native/RaftConnEvents.js +0 -54
  50. package/dist/react-native/RaftConnEvents.js.map +0 -1
  51. package/dist/react-native/RaftConnector.d.ts +0 -245
  52. package/dist/react-native/RaftConnector.js +0 -621
  53. package/dist/react-native/RaftConnector.js.map +0 -1
  54. package/dist/react-native/RaftCustomAttrHandler.d.ts +0 -4
  55. package/dist/react-native/RaftCustomAttrHandler.js +0 -50
  56. package/dist/react-native/RaftCustomAttrHandler.js.map +0 -1
  57. package/dist/react-native/RaftDeviceInfo.d.ts +0 -63
  58. package/dist/react-native/RaftDeviceInfo.js +0 -36
  59. package/dist/react-native/RaftDeviceInfo.js.map +0 -1
  60. package/dist/react-native/RaftDeviceManager.d.ts +0 -40
  61. package/dist/react-native/RaftDeviceManager.js +0 -499
  62. package/dist/react-native/RaftDeviceManager.js.map +0 -1
  63. package/dist/react-native/RaftDeviceMgrIF.d.ts +0 -15
  64. package/dist/react-native/RaftDeviceMgrIF.js +0 -11
  65. package/dist/react-native/RaftDeviceMgrIF.js.map +0 -1
  66. package/dist/react-native/RaftDeviceMsg.d.ts +0 -9
  67. package/dist/react-native/RaftDeviceMsg.js +0 -11
  68. package/dist/react-native/RaftDeviceMsg.js.map +0 -1
  69. package/dist/react-native/RaftDeviceStates.d.ts +0 -37
  70. package/dist/react-native/RaftDeviceStates.js +0 -60
  71. package/dist/react-native/RaftDeviceStates.js.map +0 -1
  72. package/dist/react-native/RaftFileHandler.d.ts +0 -52
  73. package/dist/react-native/RaftFileHandler.js +0 -502
  74. package/dist/react-native/RaftFileHandler.js.map +0 -1
  75. package/dist/react-native/RaftLog.d.ts +0 -22
  76. package/dist/react-native/RaftLog.js +0 -63
  77. package/dist/react-native/RaftLog.js.map +0 -1
  78. package/dist/react-native/RaftMiniHDLC.d.ts +0 -18
  79. package/dist/react-native/RaftMiniHDLC.js +0 -383
  80. package/dist/react-native/RaftMiniHDLC.js.map +0 -1
  81. package/dist/react-native/RaftMsgHandler.d.ts +0 -62
  82. package/dist/react-native/RaftMsgHandler.js +0 -511
  83. package/dist/react-native/RaftMsgHandler.js.map +0 -1
  84. package/dist/react-native/RaftMsgTrackInfo.d.ts +0 -17
  85. package/dist/react-native/RaftMsgTrackInfo.js +0 -42
  86. package/dist/react-native/RaftMsgTrackInfo.js.map +0 -1
  87. package/dist/react-native/RaftProtocolDefs.d.ts +0 -30
  88. package/dist/react-native/RaftProtocolDefs.js +0 -48
  89. package/dist/react-native/RaftProtocolDefs.js.map +0 -1
  90. package/dist/react-native/RaftStreamHandler.d.ts +0 -38
  91. package/dist/react-native/RaftStreamHandler.js +0 -257
  92. package/dist/react-native/RaftStreamHandler.js.map +0 -1
  93. package/dist/react-native/RaftStruct.d.ts +0 -3
  94. package/dist/react-native/RaftStruct.js +0 -208
  95. package/dist/react-native/RaftStruct.js.map +0 -1
  96. package/dist/react-native/RaftSysTypeManager.d.ts +0 -14
  97. package/dist/react-native/RaftSysTypeManager.js +0 -53
  98. package/dist/react-native/RaftSysTypeManager.js.map +0 -1
  99. package/dist/react-native/RaftSystemType.d.ts +0 -28
  100. package/dist/react-native/RaftSystemType.js +0 -3
  101. package/dist/react-native/RaftSystemType.js.map +0 -1
  102. package/dist/react-native/RaftSystemUtils.d.ts +0 -136
  103. package/dist/react-native/RaftSystemUtils.js +0 -410
  104. package/dist/react-native/RaftSystemUtils.js.map +0 -1
  105. package/dist/react-native/RaftTypes.d.ts +0 -194
  106. package/dist/react-native/RaftTypes.js +0 -153
  107. package/dist/react-native/RaftTypes.js.map +0 -1
  108. package/dist/react-native/RaftUpdateEvents.d.ts +0 -33
  109. package/dist/react-native/RaftUpdateEvents.js +0 -46
  110. package/dist/react-native/RaftUpdateEvents.js.map +0 -1
  111. package/dist/react-native/RaftUpdateManager.d.ts +0 -61
  112. package/dist/react-native/RaftUpdateManager.js +0 -621
  113. package/dist/react-native/RaftUpdateManager.js.map +0 -1
  114. package/dist/react-native/RaftUtils.d.ts +0 -126
  115. package/dist/react-native/RaftUtils.js +0 -467
  116. package/dist/react-native/RaftUtils.js.map +0 -1
  117. package/dist/react-native/RaftWifiTypes.d.ts +0 -23
  118. package/dist/react-native/RaftWifiTypes.js +0 -43
  119. package/dist/react-native/RaftWifiTypes.js.map +0 -1
  120. package/dist/react-native/main.d.ts +0 -25
  121. package/dist/react-native/main.js +0 -51
  122. package/dist/react-native/main.js.map +0 -1
  123. package/eslint.config.mjs +0 -33
  124. package/examples/dashboard/package.json +0 -36
  125. package/examples/dashboard/src/CommandPanel.tsx +0 -147
  126. package/examples/dashboard/src/ConnManager.ts +0 -164
  127. package/examples/dashboard/src/DeviceActionsForm.tsx +0 -133
  128. package/examples/dashboard/src/DeviceAttrsForm.tsx +0 -49
  129. package/examples/dashboard/src/DeviceLineChart.tsx +0 -163
  130. package/examples/dashboard/src/DevicePanel.tsx +0 -166
  131. package/examples/dashboard/src/DevicesPanel.tsx +0 -58
  132. package/examples/dashboard/src/DispLedGrid.tsx +0 -110
  133. package/examples/dashboard/src/DispOneLed.tsx +0 -20
  134. package/examples/dashboard/src/LatencyTest.ts +0 -130
  135. package/examples/dashboard/src/LatencyTestPanel.tsx +0 -92
  136. package/examples/dashboard/src/Main.tsx +0 -234
  137. package/examples/dashboard/src/SettingsManager.ts +0 -67
  138. package/examples/dashboard/src/SettingsScreen.tsx +0 -174
  139. package/examples/dashboard/src/StatusPanel.tsx +0 -71
  140. package/examples/dashboard/src/SystemTypeCog/CogStateInfo.ts +0 -163
  141. package/examples/dashboard/src/SystemTypeCog/SystemTypeCog.ts +0 -91
  142. package/examples/dashboard/src/SystemTypeGeneric/StateInfoGeneric.ts +0 -30
  143. package/examples/dashboard/src/SystemTypeGeneric/SystemTypeGeneric.ts +0 -91
  144. package/examples/dashboard/src/SystemTypeMarty/RICAddOn.ts +0 -70
  145. package/examples/dashboard/src/SystemTypeMarty/RICAddOnBase.ts +0 -33
  146. package/examples/dashboard/src/SystemTypeMarty/RICAddOnManager.ts +0 -342
  147. package/examples/dashboard/src/SystemTypeMarty/RICCommsStats.ts +0 -170
  148. package/examples/dashboard/src/SystemTypeMarty/RICHWElem.ts +0 -123
  149. package/examples/dashboard/src/SystemTypeMarty/RICLEDPatternChecker.ts +0 -207
  150. package/examples/dashboard/src/SystemTypeMarty/RICROSSerial.ts +0 -464
  151. package/examples/dashboard/src/SystemTypeMarty/RICServoFaultDetector.ts +0 -146
  152. package/examples/dashboard/src/SystemTypeMarty/RICStateInfo.ts +0 -97
  153. package/examples/dashboard/src/SystemTypeMarty/RICSystemUtils.ts +0 -371
  154. package/examples/dashboard/src/SystemTypeMarty/RICTypes.ts +0 -20
  155. package/examples/dashboard/src/SystemTypeMarty/SystemTypeMarty.ts +0 -119
  156. package/examples/dashboard/src/index.html +0 -15
  157. package/examples/dashboard/src/index.tsx +0 -13
  158. package/examples/dashboard/src/styles.css +0 -408
  159. package/examples/dashboard/tsconfig.json +0 -18
  160. package/jest.config.js +0 -11
  161. package/src/RaftAttributeHandler.ts +0 -298
  162. package/src/RaftChannel.ts +0 -32
  163. package/src/RaftChannelBLE.native.ts +0 -616
  164. package/src/RaftChannelBLE.web.ts +0 -372
  165. package/src/RaftChannelBLEFactory.ts +0 -13
  166. package/src/RaftChannelBLEScanner.native.ts +0 -184
  167. package/src/RaftChannelSimulated.ts +0 -482
  168. package/src/RaftChannelWebSerial.ts +0 -420
  169. package/src/RaftChannelWebSocket.ts +0 -258
  170. package/src/RaftCommsStats.ts +0 -142
  171. package/src/RaftConnEvents.ts +0 -58
  172. package/src/RaftConnector.ts +0 -743
  173. package/src/RaftCustomAttrHandler.ts +0 -54
  174. package/src/RaftDeviceInfo.ts +0 -102
  175. package/src/RaftDeviceManager.ts +0 -607
  176. package/src/RaftDeviceMgrIF.ts +0 -33
  177. package/src/RaftDeviceMsg.ts +0 -20
  178. package/src/RaftDeviceStates.ts +0 -92
  179. package/src/RaftFileHandler.ts +0 -668
  180. package/src/RaftLog.ts +0 -70
  181. package/src/RaftMiniHDLC.ts +0 -396
  182. package/src/RaftMsgHandler.ts +0 -813
  183. package/src/RaftMsgTrackInfo.ts +0 -51
  184. package/src/RaftProtocolDefs.ts +0 -46
  185. package/src/RaftStreamHandler.ts +0 -328
  186. package/src/RaftStruct.ts +0 -209
  187. package/src/RaftSysTypeManager.ts +0 -60
  188. package/src/RaftSystemType.ts +0 -32
  189. package/src/RaftSystemUtils.ts +0 -487
  190. package/src/RaftTypes.ts +0 -278
  191. package/src/RaftUpdateEvents.ts +0 -48
  192. package/src/RaftUpdateManager.ts +0 -781
  193. package/src/RaftUtils.ts +0 -494
  194. package/src/RaftWifiTypes.ts +0 -36
  195. package/src/main.ts +0 -38
  196. package/testdata/TestDeviceTypeRecs.json +0 -492
  197. package/tsconfig.json +0 -30
  198. package/tsconfig.react-native.json +0 -29
@@ -1,298 +0,0 @@
1
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
- //
3
- // RaftAttributeHandler
4
- // Attribute handler for Raft devices
5
- //
6
- // Rob Dobson (C) 2024
7
- //
8
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9
-
10
- import CustomAttrHandler from "./RaftCustomAttrHandler";
11
- import { DeviceTypeAttribute, DeviceTypePollRespMetadata, decodeAttrUnitsEncoding, isAttrTypeSigned } from "./RaftDeviceInfo";
12
- import { DeviceAttributesState, DeviceTimeline } from "./RaftDeviceStates";
13
- import { structSizeOf, structUnpack } from "./RaftStruct";
14
-
15
- export default class AttributeHandler {
16
-
17
- // Custom attribute handler
18
- private _customAttrHandler = new CustomAttrHandler();
19
-
20
- // Message timestamp size
21
- private POLL_RESULT_TIMESTAMP_SIZE = 2;
22
- private POLL_RESULT_WRAP_VALUE = this.POLL_RESULT_TIMESTAMP_SIZE === 2 ? 65536 : 4294967296;
23
- private POLL_RESULT_RESOLUTION_US = 1000;
24
-
25
- public processMsgAttrGroup(msgBuffer: Uint8Array, msgBufIdx: number, deviceTimeline: DeviceTimeline, pollRespMetadata: DeviceTypePollRespMetadata,
26
- devAttrsState: DeviceAttributesState, maxDataPoints: number): number {
27
-
28
- // console.log(`processMsgAttrGroup msg ${msgHexStr} timestamp ${timestamp} origTimestamp ${origTimestamp} msgBufIdx ${msgBufIdx}`)
29
-
30
- // Extract msg timestamp
31
- const { newBufIdx, timestampUs } = this.extractTimestampAndAdvanceIdx(msgBuffer, msgBufIdx, deviceTimeline);
32
- if (newBufIdx < 0)
33
- return -1;
34
- msgBufIdx = newBufIdx;
35
-
36
- // Start of message data
37
- const msgDataStartIdx = msgBufIdx;
38
-
39
- // New attribute values (in order as they appear in the attributes JSON)
40
- let newAttrValues: number[][] = [];
41
- if ("c" in pollRespMetadata) {
42
-
43
- // Extract attribute values using custom handler
44
- newAttrValues = this._customAttrHandler.handleAttr(pollRespMetadata, msgBuffer, msgBufIdx);
45
-
46
- } else {
47
-
48
- // Iterate over attributes
49
- for (let attrIdx = 0; attrIdx < pollRespMetadata.a.length; attrIdx++) {
50
-
51
- // Get the attribute definition
52
- const attrDef: DeviceTypeAttribute = pollRespMetadata.a[attrIdx];
53
- if (!("t" in attrDef)) {
54
- console.warn(`DeviceManager msg unknown msgBuffer ${msgBuffer} tsUs ${timestampUs} attrDef ${JSON.stringify(attrDef)}`);
55
- newAttrValues.push([]);
56
- continue;
57
- }
58
-
59
- // Process the attribute
60
- const { values, newMsgBufIdx } = this.processMsgAttribute(attrDef, msgBuffer, msgBufIdx, msgDataStartIdx);
61
- if (newMsgBufIdx < 0) {
62
- newAttrValues.push([]);
63
- continue;
64
- }
65
- msgBufIdx = newMsgBufIdx;
66
- newAttrValues.push(values);
67
- }
68
-
69
- }
70
-
71
- // Number of bytes in group
72
- let pollRespSizeBytes = msgBufIdx - msgDataStartIdx;
73
- if (pollRespSizeBytes < pollRespMetadata.b) {
74
- pollRespSizeBytes = pollRespMetadata.b;
75
- }
76
-
77
- // Check if any attributes were added (in addition to timestamp)
78
- if (newAttrValues.length === 0) {
79
- console.warn(`DeviceManager msg attrGroup ${JSON.stringify(pollRespMetadata)} newAttrValues ${newAttrValues} is empty`);
80
- return msgDataStartIdx+pollRespSizeBytes;
81
- }
82
-
83
- // All attributes must have the same number of new values
84
- const numNewDataPoints = newAttrValues[0].length;
85
- for (let i = 1; i < newAttrValues.length; i++) {
86
- if (newAttrValues[i].length !== numNewDataPoints) {
87
- console.warn(`DeviceManager msg attrGroup ${pollRespMetadata} attrName ${pollRespMetadata.a[i].n} newAttrValues ${newAttrValues} do not have the same length`);
88
- return msgDataStartIdx+pollRespSizeBytes;
89
- }
90
- }
91
-
92
- // All attributes in the schema should have values
93
- if (newAttrValues.length !== pollRespMetadata.a.length) {
94
- console.warn(`DeviceManager msg attrGroup ${pollRespMetadata} newAttrValues ${newAttrValues} length does not match attrGroup.a length`);
95
- return msgDataStartIdx+pollRespSizeBytes;
96
- }
97
-
98
- // Add the new attribute values to the device state
99
- for (let attrIdx = 0; attrIdx < pollRespMetadata.a.length; attrIdx++) {
100
- // Check if attribute already exists in the device state
101
- const attrDef: DeviceTypeAttribute = pollRespMetadata.a[attrIdx];
102
- if (!(attrDef.n in devAttrsState)) {
103
- devAttrsState[attrDef.n] = {
104
- name: attrDef.n,
105
- newAttribute: true,
106
- newData: false,
107
- numNewValues: 0,
108
- values: [],
109
- units: decodeAttrUnitsEncoding(attrDef.u || ""),
110
- range: attrDef.r || [0, 0],
111
- format: ("f" in attrDef && typeof attrDef.f == "string") ? attrDef.f : "",
112
- visibleSeries: "v" in attrDef ? attrDef.v === 0 || attrDef.v === false : ("vs" in attrDef ? (attrDef.vs === 0 || attrDef.vs === false ? false : !!attrDef.vs) : true),
113
- visibleForm: "v" in attrDef ? attrDef.v === 0 || attrDef.v === false : ("vf" in attrDef ? (attrDef.vf === 0 || attrDef.vf === false ? false : !!attrDef.vf) : true),
114
- };
115
- }
116
-
117
- // Check if any data points need to be discarded
118
- const discardCount = Math.max(0, devAttrsState[attrDef.n].values.length + newAttrValues[attrIdx].length - maxDataPoints);
119
- if (discardCount > 0) {
120
- devAttrsState[attrDef.n].values.splice(0, discardCount);
121
- }
122
-
123
- // Add the new values
124
- devAttrsState[attrDef.n].values.push(...newAttrValues[attrIdx]);
125
- devAttrsState[attrDef.n].newData = newAttrValues[attrIdx].length > 0;
126
- devAttrsState[attrDef.n].numNewValues = newAttrValues[attrIdx].length;
127
- }
128
-
129
- // Handle the timestamps with increments if specified
130
- const timeIncUs: number = pollRespMetadata.us ? pollRespMetadata.us : 1000;
131
- const timestampsUs = Array(numNewDataPoints).fill(0);
132
- for (let i = 0; i < numNewDataPoints; i++) {
133
- timestampsUs[i] = timestampUs + i * timeIncUs;
134
- }
135
-
136
- // Check if timeline points need to be discarded
137
- const discardCount = Math.max(0, deviceTimeline.timestampsUs.length + timestampsUs.length - maxDataPoints);
138
- if (discardCount > 0) {
139
- deviceTimeline.timestampsUs.splice(0, discardCount);
140
- }
141
-
142
- // Add the new timestamps
143
- deviceTimeline.timestampsUs.push(...timestampsUs);
144
-
145
- // Return the next message buffer index
146
- return msgDataStartIdx+pollRespSizeBytes;
147
- }
148
-
149
- private processMsgAttribute(attrDef: DeviceTypeAttribute, msgBuffer: Uint8Array, msgBufIdx: number, msgDataStartIdx: number): { values: number[], newMsgBufIdx: number} {
150
-
151
- // Current field message string index
152
- let curFieldBufIdx = msgBufIdx;
153
- let attrUsesAbsPos = false;
154
-
155
- // Check for "at": N which means start reading from byte N of the message (after the timestamp bytes)
156
- if (attrDef.at !== undefined) {
157
- curFieldBufIdx = msgDataStartIdx + attrDef.at;
158
- attrUsesAbsPos = true;
159
- }
160
-
161
- // Check if outside bounds of message
162
- if (curFieldBufIdx >= msgBuffer.length) {
163
- console.warn(`DeviceManager msg outside bounds msgBuffer ${msgBuffer} attrName ${attrDef.n}`);
164
- return { values: [], newMsgBufIdx: -1 };
165
- }
166
-
167
- // Attribute type
168
- const attrTypesOnly = attrDef.t;
169
-
170
- // Slice into buffer
171
- const attrBuf = msgBuffer.slice(curFieldBufIdx);
172
-
173
- // Check if a mask is used and the value is signed
174
- const maskOnSignedValue = "m" in attrDef && isAttrTypeSigned(attrTypesOnly);
175
-
176
- // Extract the value using python-struct
177
- const unpackValues = structUnpack(maskOnSignedValue ? attrTypesOnly.toUpperCase() : attrTypesOnly, attrBuf);
178
- let attrValues = unpackValues as number[];
179
-
180
- // Get number of bytes consumed
181
- const numBytesConsumed = structSizeOf(attrTypesOnly);
182
-
183
- // // Check if sign extendable mask specified on signed value
184
- // if (mmSpecifiedOnSignedValue) {
185
- // const signBitMask = 1 << (signExtendableMaskSignPos - 1);
186
- // const valueOnlyMask = signBitMask - 1;
187
- // if (value & signBitMask) {
188
- // value = (value & valueOnlyMask) - signBitMask;
189
- // } else {
190
- // value = value & valueOnlyMask;
191
- // }
192
- // }
193
-
194
- // Check for XOR mask
195
- if ("x" in attrDef) {
196
- const mask = typeof attrDef.x === "string" ? parseInt(attrDef.x, 16) : attrDef.x as number;
197
- attrValues = attrValues.map((value) => value ^ mask);
198
- }
199
-
200
- // Check for AND mask
201
- if ("m" in attrDef) {
202
- const mask = typeof attrDef.m === "string" ? parseInt(attrDef.m, 16) : attrDef.m as number;
203
- attrValues = attrValues.map((value) => (maskOnSignedValue ? this.signExtend(value, mask) : value & mask));
204
- }
205
-
206
- // Check for a sign-bit
207
- if ("sb" in attrDef) {
208
- const signBitPos = attrDef.sb as number;
209
- const signBitMask = 1 << signBitPos;
210
- if ("ss" in attrDef) {
211
- const signBitSubtract = attrDef.ss as number;
212
- attrValues = attrValues.map((value) => (value & signBitMask) ? signBitSubtract - value : value);
213
- } else {
214
- attrValues = attrValues.map((value) => (value & signBitMask) ? value - (signBitMask << 1) : value);
215
- }
216
- }
217
-
218
- // Check for bit shift required
219
- if ("s" in attrDef && attrDef.s) {
220
- const bitshift = attrDef.s as number;
221
- if (bitshift > 0) {
222
- attrValues = attrValues.map((value) => (value) >> bitshift);
223
- } else if (bitshift < 0) {
224
- attrValues = attrValues.map((value) => (value) << -bitshift);
225
- }
226
- }
227
-
228
- // Check for divisor
229
- if ("d" in attrDef && attrDef.d) {
230
- const divisor = attrDef.d as number;
231
- attrValues = attrValues.map((value) => (value) / divisor);
232
- }
233
-
234
- // Check for value to add
235
- if ("a" in attrDef && attrDef.a !== undefined) {
236
- const addValue = attrDef.a as number;
237
- attrValues = attrValues.map((value) => (value) + addValue);
238
- }
239
-
240
- // console.log(`DeviceManager msg attrGroup ${attrGroup} devkey ${deviceKey} valueHexChars ${valueHexChars} msgHexStr ${msgHexStr} ts ${timestamp} attrName ${attrDef.n} type ${attrDef.t} value ${value} signExtendableMaskSignPos ${signExtendableMaskSignPos} attrTypeDefForStruct ${attrTypeDefForStruct} attrDef ${attrDef}`);
241
- // Move buffer position if using relative positioning
242
- msgBufIdx += attrUsesAbsPos ? 0 : numBytesConsumed;
243
-
244
- // if (attrDef.n === "amb0") {
245
- // console.log(`${new Date().toISOString()} ${attrDef.n} ${attrValues}`);
246
- // }
247
-
248
- // Return the value
249
- return { values: attrValues, newMsgBufIdx: msgBufIdx };
250
- }
251
-
252
- private signExtend(value: number, mask: number): number {
253
- const signBitMask = (mask + 1) >> 1;
254
- const signBit = value & signBitMask;
255
-
256
- if (signBit !== 0) { // If sign bit is set
257
- const highBitsMask = ~mask & ~((mask + 1) >> 1);
258
- value |= highBitsMask; // Apply the sign extension
259
- }
260
-
261
- return value;
262
- }
263
-
264
- private extractTimestampAndAdvanceIdx(msgBuffer: Uint8Array, msgBufIdx: number, timestampWrapHandler: DeviceTimeline):
265
- { newBufIdx: number, timestampUs: number } {
266
-
267
- // Check there are enough characters for the timestamp
268
- if (msgBufIdx + this.POLL_RESULT_TIMESTAMP_SIZE > msgBuffer.length) {
269
- return { newBufIdx: -1, timestampUs: 0 };
270
- }
271
-
272
- // Use struct to extract the timestamp
273
- const tsBuffer = msgBuffer.slice(msgBufIdx, msgBufIdx + this.POLL_RESULT_TIMESTAMP_SIZE);
274
- let timestampUs: number;
275
- if (this.POLL_RESULT_TIMESTAMP_SIZE === 2) {
276
- timestampUs = structUnpack(">H", tsBuffer)[0] as number * this.POLL_RESULT_RESOLUTION_US;
277
- } else {
278
- timestampUs = structUnpack(">I", tsBuffer)[0] as number * this.POLL_RESULT_RESOLUTION_US;
279
- }
280
-
281
- // Check if time is before lastReportTimeMs - in which case a wrap around occurred to add on the max value
282
- if (timestampUs < timestampWrapHandler.lastReportTimestampUs) {
283
- timestampWrapHandler.reportTimestampOffsetUs += this.POLL_RESULT_WRAP_VALUE * this.POLL_RESULT_RESOLUTION_US;
284
- }
285
- timestampWrapHandler.lastReportTimestampUs = timestampUs;
286
-
287
- // Offset timestamp
288
- timestampUs += timestampWrapHandler.reportTimestampOffsetUs;
289
-
290
- // Advance the index
291
- msgBufIdx += this.POLL_RESULT_TIMESTAMP_SIZE;
292
-
293
- // Return the timestamp
294
- return { newBufIdx: msgBufIdx, timestampUs: timestampUs };
295
- }
296
-
297
-
298
- }
@@ -1,32 +0,0 @@
1
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
- //
3
- // RaftChannel
4
- // Part of RaftJS
5
- //
6
- // Rob Dobson & Chris Greening 2020-2024
7
- // (C) 2020-2024 All rights reserved
8
- //
9
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10
-
11
- import { RaftConnEventFn } from "./RaftConnEvents";
12
- import RaftMsgHandler from "./RaftMsgHandler";
13
- import { ConnectorOptions } from "./RaftSystemType";
14
-
15
- export default interface RaftChannel
16
- {
17
- isConnected(): boolean;
18
- connect(locator: string | object, connectorOptions: ConnectorOptions): Promise<boolean>;
19
- disconnect(): Promise<void>;
20
- getConnectedLocator(): string | object;
21
- setOnConnEvent(connEventFn: RaftConnEventFn): void;
22
- setMsgHandler(raftMsgHandler: RaftMsgHandler): void;
23
- sendTxMsg(msg: Uint8Array, sendWithResponse: boolean): Promise<boolean>;
24
- sendTxMsgNoAwait(msg: Uint8Array, sendWithResponse: boolean): Promise<boolean>;
25
- sendTxMsgRaw(msg: string): boolean;
26
- sendTxMsgRawAndWaitForReply<T>(msgPayload: Uint8Array): T;
27
- requiresSubscription(): boolean;
28
- ricRestCmdBeforeDisconnect(): string | null;
29
- fhBatchAckSize(): number;
30
- fhFileBlockSize(): number;
31
- pauseConnection(pause: boolean): void;
32
- }