@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,146 +0,0 @@
1
- /**
2
- * The RICServoFaultDetection class is responsible for detecting faults in the RIC servos.
3
- * These are the faults that can currently be detected:
4
- 1) Wiring fault - Intermittent connection to servo potentiometer
5
- 2) Wiring fault - no connection to servo potentiometer
6
- 3) Wiring fault - faulty connection to servo drive
7
- 4) Servo horn has shifted out of position
8
-
9
- * To detect these faults:
10
- 1) get the list of all servos
11
- 1.1) We filter out the servos that don't have the fault bit enabled in their status byte
12
- 2) sending an atomic read command to the servos
13
- 2.1) the servos will respond with a report msg
14
- 2.2) the fault flags are on the 11th byte of the report msg
15
- 2.3) The 'fault' byte has 8 bits, each of which corresponds to a specific type of fault (there are only 4 types of faults so far, so the remaining 4 bits are unused.)
16
- Bit 0: Intermittent connection to potentiometer
17
- Bit 1: No connection to potentiometer
18
- Bit 2: Faulty connection to motor drive
19
- Bit 3: Servo horn position error
20
- 3) in a second phase, we receive the report msg from the app, and check the fault flags
21
- */
22
-
23
- import { RICServoFaultFlags } from "./RICTypes";
24
- import { RICStateInfo } from "./RICStateInfo";
25
- import RaftMsgHandler from "../../../../src/RaftMsgHandler";
26
- import RaftLog from "../../../../src/RaftLog";
27
- import { RICHWElemList_Min } from "./RICHWElem";
28
- import { RaftReportMsg } from "../../../../src/RaftTypes";
29
-
30
- export default class RICServoFaultDetector {
31
- private _raftMsgHandler: RaftMsgHandler;
32
- private static expirationDate: Date = new Date();
33
- private static _servoList: string[] = [];
34
- private ricStateReference: RICStateInfo;
35
-
36
- constructor(raftMsgHandler: RaftMsgHandler, ricStateReference: RICStateInfo) {
37
- this._raftMsgHandler = raftMsgHandler;
38
- this.ricStateReference = ricStateReference;
39
- }
40
-
41
- private async getAllServos(): Promise<void> {
42
- RICServoFaultDetector._servoList = [];
43
- const response = await this._raftMsgHandler.sendRICRESTURL<RICHWElemList_Min>("hwstatus/minstat?filterByType=SmartServo");
44
- if (!response || !response.hw) {
45
- RaftLog.warn("RICServoFaultDetector: Error getting servo list");
46
- return;
47
- }
48
- const servosWithIdAndName = response.hw.map((smartServo) => ({ id: smartServo.I, name: smartServo.n }));
49
- // filter only the servos that they have enabled the fault bit in their status byte
50
- const servosWithFaultBitEnabled = servosWithIdAndName.filter((smartServo) => {
51
- const foundSmartServoStatus = this.ricStateReference.smartServos.smartServos.find((smartServoStat) => smartServoStat.id === +smartServo.id);
52
- if (!foundSmartServoStatus) {
53
- return false;
54
- }
55
- return RICServoFaultDetector.isFaultBitEnabled(foundSmartServoStatus.status);
56
- });
57
- const filteredServoArrayWithNames = servosWithFaultBitEnabled.map((smartServo) => smartServo.name);
58
- try {
59
- RICServoFaultDetector._servoList = filteredServoArrayWithNames;
60
- } catch (e) {
61
- console.log("Error getting servo list");
62
- }
63
- }
64
-
65
- async atomicReadOperation(expirationTime = 5000): Promise<void> {
66
- await this.getAllServos();
67
- // setting an expiration date within which the interpreter should receive the report msg
68
- RICServoFaultDetector.expirationDate = new Date(Date.now() + expirationTime);
69
- for (let i = 0; i < RICServoFaultDetector._servoList.length; i++) {
70
- const servoName = RICServoFaultDetector._servoList[i];
71
- try {
72
- await this._raftMsgHandler.sendRICRESTURL<void>(`elem/${servoName}/json?cmd=raw&numToRd=11&msgKey=100${i}`);
73
- } catch (e) {
74
- RaftLog.warn(`RICServoFaultDetector: Error sending atomic read command to servo ${servoName}`);
75
- }
76
- }
77
- }
78
-
79
- static interpretReportMsg(reportMsg: RaftReportMsg): RICServoFaultFlags | undefined {
80
- // make sure the report msg is not expired
81
- if (new Date() > RICServoFaultDetector.expirationDate) {
82
- RaftLog.warn(`RICServoFaultDetector: Received report msg after expiration date: ${reportMsg}`);
83
- return;
84
- }
85
- // make sure this is a raw report msg
86
- if (reportMsg.msgType !== "raw") {
87
- RaftLog.warn(`RICServoFaultDetector: Received non-raw report msg: ${reportMsg}`);
88
- return;
89
- }
90
- // making sure the report msg is from a servo
91
- if (reportMsg.elemName && !RICServoFaultDetector._servoList.includes(reportMsg.elemName)) {
92
- RaftLog.warn(`RICServoFaultDetector: Received report msg from non-servo: ${reportMsg}`);
93
- return;
94
- }
95
- const hexRd = reportMsg.hexRd;
96
- if (!hexRd) {
97
- RaftLog.warn(`RICServoFaultDetector: Received report msg with no hexRd: ${reportMsg}`);
98
- return;
99
- }
100
- const faultByteHex = hexRd.slice(20, 22); // the fault byte is the 11th byte of the report msg
101
- if (!faultByteHex || hexRd.length !== 22) { // since we are reading 11 bytes, the hexRd should be 22 characters long
102
- RaftLog.warn(`RICServoFaultDetector: Received report msg with invalid hexRd: ${reportMsg}`);
103
- return;
104
- }
105
- try {
106
- return RICServoFaultDetector.decodeFault(faultByteHex);
107
- } catch (e) {
108
- RaftLog.warn(`RICServoFaultDetector: Received report msg with invalid fault byte: ${reportMsg}`);
109
- return;
110
- }
111
- }
112
-
113
- private static decodeFault(faultByteHex: string): RICServoFaultFlags {
114
- const byte = parseInt(faultByteHex, 16);
115
- return {
116
- intermittentConnection: !!(byte & 0b0001),
117
- noConnection: !!(byte & 0b0010),
118
- faultyConnection: !!(byte & 0b0100),
119
- servoHornPositionError: !!(byte & 0b1000)
120
- };
121
- }
122
-
123
- public static isFaultBitEnabled(input: number | string): boolean {
124
- let num: number;
125
-
126
- // If input is a hexadecimal string, convert it to a decimal number
127
- if (typeof input === "string") {
128
- if (!input.startsWith("0x")) {
129
- throw new Error("Input string must start with '0x' for hexadecimal representation");
130
- }
131
- num = parseInt(input, 16);
132
- } else {
133
- num = input;
134
- }
135
-
136
- // Check if number is an 8-bit number
137
- if (num < 0 || num > 255 || !Number.isInteger(num)) {
138
- throw new Error("Input is not an 8-bit number");
139
- }
140
-
141
- // Check if the 6th bit (from the right) is enabled
142
- return Boolean(num & 64);
143
- }
144
-
145
-
146
- }
@@ -1,97 +0,0 @@
1
- import RaftDeviceMgrIF from "../../../../src/RaftDeviceMgrIF";
2
- import { DeviceAttributeState, DevicesState, DeviceState } from "../../../../src/RaftDeviceStates";
3
- import { RICSERIAL_PAYLOAD_POS } from "../../../../src/RaftProtocolDefs";
4
- import RICAddOnManager from "./RICAddOnManager";
5
- import RICCommsStats from "./RICCommsStats";
6
- import { RICROSSerial, ROSCameraData, ROSSerialAddOnStatusList, ROSSerialIMU, ROSSerialPowerStatus, ROSSerialRobotStatus, ROSSerialSmartServos } from "./RICROSSerial";
7
-
8
- export class RICStateInfo implements RaftDeviceMgrIF {
9
- smartServos: ROSSerialSmartServos = new ROSSerialSmartServos();
10
- smartServosValidMs = 0;
11
- imuData: ROSSerialIMU = new ROSSerialIMU();
12
- imuDataValidMs = 0;
13
- power: ROSSerialPowerStatus = new ROSSerialPowerStatus();
14
- powerValidMs = 0;
15
- addOnInfo: ROSSerialAddOnStatusList = new ROSSerialAddOnStatusList();
16
- addOnInfoValidMs = 0;
17
- robotStatus: ROSSerialRobotStatus = new ROSSerialRobotStatus();
18
- robotStatusValidMs = 0;
19
- cameraData: ROSCameraData = new ROSCameraData();
20
- cameraDataValidMs = 0;
21
-
22
- updateFromROSSerialMsg(rxMsg: Uint8Array, commsStats: RICCommsStats,
23
- addOnManager: RICAddOnManager, frameTimeMs: number): Array<number> {
24
- return RICROSSerial.decode(
25
- rxMsg,
26
- RICSERIAL_PAYLOAD_POS,
27
- commsStats,
28
- addOnManager,
29
- this,
30
- frameTimeMs
31
- );
32
- }
33
-
34
- getDevicesState(): DevicesState {
35
-
36
- // TODO - implement if RICStateInfo is to be used as a DeviceMgr
37
- return {};
38
- }
39
-
40
- getDeviceState(deviceKey: string): DeviceState {
41
-
42
- // TODO - implement if RICStateInfo is to be used as a DeviceMgr
43
- return {
44
- deviceTypeInfo: undefined,
45
- deviceTimeline: {
46
- timestampsUs: [],
47
- lastReportTimestampUs: 0,
48
- reportTimestampOffsetUs: 0
49
- },
50
- deviceAttributes: {},
51
- deviceIsNew: false,
52
- stateChanged: false,
53
- isOnline: false,
54
- deviceAddress: "",
55
- deviceType: "",
56
- busName: ""
57
- };
58
- }
59
-
60
- setMaxDataPointsToStore(maxDataPointsToStore: number): void {
61
- // TODO - implement if RICStateInfo is to be used as a DeviceMgr
62
- }
63
-
64
- addNewDeviceCallback(callback: (deviceKey: string, state: DeviceState) => void): void {
65
- // TODO - implement if RICStateInfo is to be used as a DeviceMgr
66
- }
67
-
68
- removeNewDeviceCallback(callback: (deviceKey: string, state: DeviceState) => void): void {
69
- // TODO - implement if RICStateInfo is to be used as a DeviceMgr
70
- }
71
-
72
- addNewAttributeCallback(callback: (deviceKey: string, attrState: DeviceAttributeState) => void): void {
73
- // TODO - implement if RICStateInfo is to be used as a DeviceMgr
74
- }
75
-
76
- removeNewAttributeCallback(callback: (deviceKey: string, attrState: DeviceAttributeState) => void): void {
77
- // TODO - implement if RICStateInfo is to be used as a DeviceMgr
78
- }
79
-
80
- addAttributeDataCallback(callback: (deviceKey: string, attrState: DeviceAttributeState) => void): void {
81
- // TODO - implement if RICStateInfo is to be used as a DeviceMgr
82
- }
83
-
84
- removeAttributeDataCallback(callback: (deviceKey: string, attrState: DeviceAttributeState) => void): void {
85
- // TODO - implement if RICStateInfo is to be used as a DeviceMgr
86
- }
87
-
88
- sendAction(deviceKey: string, action: any, data: any): void {
89
- // TODO - implement if RICStateInfo is to be used as a DeviceMgr
90
- }
91
-
92
- sendCompoundAction(deviceKey: string, action: any, data: any): void {
93
- // TODO - implement if RICStateInfo is to be used as a DeviceMgr
94
- }
95
-
96
- }
97
-
@@ -1,371 +0,0 @@
1
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
- //
3
- // RICJS
4
- // Communications Library
5
- //
6
- // Rob Dobson & Chris Greening 2020-2022
7
- // (C) 2020-2022
8
- //
9
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10
-
11
- import RaftLog from "../../../../src/RaftLog";
12
- import RaftMsgHandler from "../../../../src/RaftMsgHandler";
13
- import { RaftOKFail, RaftReportMsg } from "../../../../src/RaftTypes";
14
- import { RICConfiguredAddOns } from "./RICAddOn";
15
- import RICAddOnManager from "./RICAddOnManager";
16
- import { RICHWElem, RICHWElemList, RICHWElemList_Str } from "./RICHWElem";
17
- import { RICCalibInfo } from "./RICTypes";
18
-
19
- export default class RICSystemUtils {
20
-
21
- // Message handler
22
- private _msgHandler: RaftMsgHandler;
23
-
24
- // Add-on manager
25
- private _addOnManager: RICAddOnManager;
26
-
27
- // HWElems (connected to RIC) - excluding AddOns
28
- private _hwElemsExcludingAddOns: Array<RICHWElem> = new Array<RICHWElem>();
29
- private _connectedAddOns: Array<RICHWElem> = new Array<RICHWElem>();
30
-
31
- // Calibration info
32
- private _calibInfo: RICCalibInfo | null = null;
33
-
34
- /**
35
- * constructor
36
- * @param raftMsgHandler
37
- * @param addOnManager
38
- */
39
- constructor(msgHandler: RaftMsgHandler, addOnManager: RICAddOnManager) {
40
- this._msgHandler = msgHandler;
41
- this._addOnManager = addOnManager;
42
- }
43
-
44
- /**
45
- * invalidate
46
- */
47
- invalidate() {
48
- // Invalidate system info
49
- this._hwElemsExcludingAddOns = new Array<RICHWElem>();
50
- this._connectedAddOns = new Array<RICHWElem>();
51
- this._addOnManager.clear();
52
- this._calibInfo = null;
53
- RaftLog.debug("RICSystem information invalidated");
54
- }
55
-
56
- /**
57
- * getSystemInfo - get system info
58
- * @returns Promise<RICSystemInfo>
59
- *
60
- */
61
- async retrieveInfo(): Promise<boolean> {
62
- // Get HWElems (connected to RIC)
63
- try {
64
- await this.getHWElemList();
65
- } catch (error) {
66
- RaftLog.warn("retrieveInfo - failed to get HWElems " + error);
67
- return false;
68
- }
69
-
70
- // Get calibration info
71
- try {
72
- await this.getRICCalibInfo(true);
73
- } catch (error) {
74
- RaftLog.warn("retrieveInfo - failed to get calib info " + error);
75
- return false;
76
- }
77
-
78
- // Get HWElems (connected to RIC)
79
- try {
80
- await this.getHWElemList();
81
- } catch (error) {
82
- RaftLog.warn("retrieveInfo - failed to get HWElems " + error);
83
- return false;
84
- }
85
- return true;
86
- }
87
-
88
- /**
89
- * Get information Marty system
90
- *
91
- * @return void
92
- *
93
- */
94
- async retrieveMartySystemInfo(): Promise<boolean> {
95
-
96
- // Retrieve system info
97
- try {
98
- const retrieveResult = await this.retrieveInfo();
99
- return retrieveResult;
100
- } catch (err) {
101
- RaftLog.error(`retrieveMartySystemInfo: error ${err}`);
102
- }
103
- return false;
104
- }
105
-
106
- // Mark: Calibration -----------------------------------------------------------------------------------------
107
-
108
- async calibrate(
109
- cmd: string,
110
- jointList: Array<string>,
111
- jointNames: { [key: string]: string }
112
- ) {
113
- let overallResult = true;
114
- if (cmd === "set") {
115
- // Set calibration
116
- for (const jnt of jointList) {
117
- try {
118
- // Set calibration on joint
119
- const cmdUrl = "calibrate/set/" + jnt;
120
- const rsl = await this._msgHandler.sendRICRESTURL<RaftOKFail>(
121
- cmdUrl
122
- );
123
- // saving the calibration... (For the new servo boards it is necessary
124
- // to send a "save" command after the calibration ones or any servo
125
- // parameter changes in order to save any changes made into nonvolatile storage)
126
- const saveCalibCmd = `elem/${jnt}/saveparams`;
127
- await this._msgHandler.sendRICRESTURL<RaftOKFail>(saveCalibCmd);
128
- if (rsl.rslt != "ok") overallResult = false;
129
- } catch (error) {
130
- console.log(`calibrate failed on joint ${jnt}`, error);
131
- }
132
-
133
- // Wait as writing to flash blocks servo access
134
- // as of v0.0.113 of firmware, the pause is no longer required
135
- //await new Promise(resolve => setTimeout(resolve, 3000));
136
- }
137
-
138
- // ensure all joints are enabled
139
- for (const jnt in jointNames) {
140
- try {
141
- // enable joint
142
- const cmdUrl = "servo/" + jnt + "/enable/1";
143
- const rsl = await this._msgHandler.sendRICRESTURL<RaftOKFail>(
144
- cmdUrl
145
- );
146
- if (rsl.rslt != "ok") overallResult = false;
147
- } catch (error) {
148
- console.log(`enable failed on joint ${jnt}`, error);
149
- }
150
- }
151
-
152
- // Result
153
- console.log("Set calibration flag to true");
154
- const rslt = new RaftOKFail();
155
- rslt.rslt = overallResult ? "ok" : "fail";
156
- return rslt;
157
- }
158
- return false;
159
- }
160
-
161
- /**
162
- *
163
- * getRICCalibInfo
164
- * @returns Promise<RICCalibInfo>
165
- *
166
- */
167
- async getRICCalibInfo(forceGetFromRIC = false): Promise<RICCalibInfo> {
168
- if (!forceGetFromRIC && this._calibInfo) {
169
- return this._calibInfo;
170
- }
171
- try {
172
- this._calibInfo = await this._msgHandler.sendRICRESTURL<RICCalibInfo>(
173
- "calibrate"
174
- );
175
- RaftLog.debug("getRICCalibInfo returned " + this._calibInfo);
176
- this._calibInfo.validMs = Date.now();
177
- return this._calibInfo;
178
- } catch (error) {
179
- RaftLog.debug(`getRICCalibInfo Failed to get version ${error}`);
180
- return new RICCalibInfo();
181
- }
182
- }
183
-
184
- /**
185
- *
186
- * getHWElemList - get the list of hardware elements connected to the robot
187
- * - the result (if successful) is processed as follows:
188
- * = if no filter is applied then all non-add-ons found are stored in
189
- * this._hwElemsExcludingAddOns and all addons are stored in this._connectedAddOns
190
- * = if a filter is applied and this filter is RSAddOns then this._connectedAddOns is
191
- * updated with the new list of addons
192
- * = in all cases the discovered list is returned
193
- *
194
- * @returns Promise<RICHWElemList>
195
- *
196
- */
197
-
198
- async getHWElemList(filterByType?: string): Promise<Array<RICHWElem>> {
199
- // Form a list of the requests to make
200
- const reqList: Array<string> = [];
201
- let addToNonAddOnsList = false;
202
- if (!filterByType) {
203
- reqList.push("SmartServo");
204
- reqList.push("RSAddOn");
205
- reqList.push("BusPixels");
206
- reqList.push("!SmartServo,RSAddOn,BusPixels"); // not SmartServo or RSAddOn or BusPixels
207
- this._hwElemsExcludingAddOns = new Array<RICHWElem>();
208
- addToNonAddOnsList = true;
209
- } else if (filterByType === "RSAddOn") {
210
- // we treat BusPixels as an RSAddOn
211
- // (batch 4 led eye add-ons have type BusPixels)
212
- reqList.push("RSAddOn");
213
- reqList.push("BusPixels");
214
- this._connectedAddOns = new Array<RICHWElem>();
215
- } else {
216
- reqList.push(filterByType);
217
- }
218
-
219
- // Make the requests
220
- const fullListOfElems = new Array<RICHWElem>();
221
- this._connectedAddOns = [];
222
- for (const reqType of reqList) {
223
- try {
224
- const hwElemList_Str = await this._msgHandler.sendRICRESTURL<
225
- RICHWElemList_Str
226
- >(`hwstatus/strstat?filterByType=${reqType}`);
227
- // if the results of hwElem indicates that we are on an older fw version
228
- // send the old hwstatus command and don't expand()
229
- // the logic behind deciding if we are on a fw version that
230
- // supports strstat is: given that hwElemList_Str.hw === object[]
231
- // if we get back string[], then we know we are on an older version
232
- // if hw === empty array, then we don't have any hw elems in which
233
- // case we can stop at that point
234
- const hwElems = hwElemList_Str.hw;
235
- let hwElemList;
236
- if (hwElems.length) {
237
- if (typeof hwElems[0] !== "object") {
238
- // we are on an older version
239
- hwElemList = await this._msgHandler.sendRICRESTURL<
240
- RICHWElemList
241
- >(`hwstatus?filterByType=${reqType}`);
242
- } else {
243
- // we are on the fw version that supports strstat
244
- hwElemList = RICHWElemList_Str.expand(hwElemList_Str);
245
- }
246
- }
247
- if (hwElemList && hwElemList.rslt && hwElemList.rslt === "ok") {
248
- fullListOfElems.push(...hwElemList.hw);
249
- if (reqType === "RSAddOn") {
250
- this._connectedAddOns = hwElemList.hw;
251
- this._addOnManager.setHWElems(this._connectedAddOns);
252
- // Debug
253
- RaftLog.debug(
254
- `getHWElemList: found ${hwElemList.hw.length} addons/buspixels`
255
- );
256
- } else if (reqType === "BusPixels") {
257
- // BusPixels are treated as an RSAddOn
258
- this._connectedAddOns.push(...hwElemList.hw);
259
- this._addOnManager.setHWElems(this._connectedAddOns);
260
- // Debug
261
- RaftLog.debug(
262
- `getHWElemList: found ${hwElemList.hw.length} addons/buspixels`
263
-
264
- } else if (addToNonAddOnsList) {
265
- this._hwElemsExcludingAddOns.push(...hwElemList.hw);
266
- // Debug
267
- RaftLog.debug(
268
- `getHWElemList: found ${hwElemList.hw.length} elems matching ${reqType}`
269
- );
270
- }
271
- }
272
- } catch (error) {
273
- RaftLog.debug(`getHWElemList failed to get ${reqType} ${error}`);
274
- return new Array<RICHWElem>();
275
- }
276
- }
277
-
278
- // Handle any callbacks
279
- try {
280
- const reports: Array<RaftReportMsg> = [];
281
- // add callback to subscribe to report messages
282
- this._msgHandler.reportMsgCallbacksSet("getHWElemCB", function (
283
- report: RaftReportMsg
284
- ) {
285
- reports.push(report);
286
- RaftLog.debug(`getHWElemCB Report callback ${JSON.stringify(report)}`);
287
- });
288
-
289
- // run any required initialisation for the addons
290
- const initCmds = this._addOnManager.getInitCmds();
291
- // send init commands to the robot
292
- const timeInitStart = Date.now();
293
- for (let i = 0; i < initCmds.length; i++) {
294
- this.runCommand(initCmds[i], {});
295
- }
296
- // wait a couple of seconds for any report messages to be received
297
- await new Promise((resolve) => setTimeout(resolve, 2000));
298
- // pass report messages to add on manager for processing
299
- this._addOnManager.processReportMsg(reports, timeInitStart);
300
-
301
- // clean up callback
302
- this._msgHandler.reportMsgCallbacksDelete("getHWElemCB");
303
- } catch (error) {
304
- RaftLog.debug(`getHWElemList failed processing callback reports ${error}`);
305
- return new Array<RICHWElem>();
306
- }
307
-
308
- // return the full list of elements
309
- return fullListOfElems;
310
- }
311
-
312
- /**
313
- *
314
- * getAddOnConfigs - get list of add-ons configured on the robot
315
- * @returns Promise<RICConfiguredAddOns>
316
- *
317
- */
318
- async getAddOnConfigs(): Promise<RICConfiguredAddOns> {
319
- try {
320
- const addOnList = await this._msgHandler.sendRICRESTURL<
321
- RICConfiguredAddOns
322
- >("addon/list");
323
- RaftLog.debug("getAddOnConfigs returned " + addOnList);
324
- return addOnList;
325
- } catch (error) {
326
- RaftLog.debug(`getAddOnConfigs Failed to get list of add-ons ${error}`);
327
- return new RICConfiguredAddOns();
328
- }
329
- }
330
-
331
- /**
332
- *
333
- * runCommand
334
- * @param commandName command API string
335
- * @param params parameters (simple name value pairs only) to parameterize trajectory
336
- * @returns Promise<RaftOKFail>
337
- *
338
- */
339
- async runCommand(commandName: string, params: object): Promise<RaftOKFail> {
340
- try {
341
- // Format the paramList as query string
342
- const paramEntries = Object.entries(params);
343
- let paramQueryStr = "";
344
- for (const param of paramEntries) {
345
- if (paramQueryStr.length > 0) paramQueryStr += "&";
346
- paramQueryStr += param[0] + "=" + param[1];
347
- }
348
- // Format the url to send
349
- if (paramQueryStr.length > 0) commandName += "?" + paramQueryStr;
350
- return await this._msgHandler.sendRICRESTURL<RaftOKFail>(commandName);
351
- } catch (error) {
352
- RaftLog.debug(`RaftSystemUtils runCommand failed ${error}`);
353
- return new RaftOKFail();
354
- }
355
- }
356
-
357
- getCachedAddOnList(): Array<RICHWElem> {
358
- return this._connectedAddOns;
359
- }
360
-
361
- getCachedAllHWElems(): Array<RICHWElem> {
362
- const allHWElems = new Array<RICHWElem>();
363
- allHWElems.push(...this._connectedAddOns);
364
- allHWElems.push(...this._hwElemsExcludingAddOns);
365
- return allHWElems;
366
- }
367
-
368
- getCachedCalibInfo(): RICCalibInfo | null {
369
- return this._calibInfo;
370
- }
371
- }
@@ -1,20 +0,0 @@
1
- export type RICLEDPatternCheckerColour = {
2
- led: string;
3
- lcd: string;
4
- }
5
-
6
- export type RICLedLcdColours = Array<RICLEDPatternCheckerColour>;
7
-
8
- export type RICServoFaultFlags = {
9
- intermittentConnection: boolean,
10
- noConnection: boolean,
11
- faultyConnection: boolean,
12
- servoHornPositionError: boolean
13
- };
14
-
15
- export class RICCalibInfo {
16
- rslt = '';
17
- calDone = 0;
18
- validMs?= 0;
19
- }
20
-