@robotical/raftjs 1.3.3 → 1.4.0

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 (128) hide show
  1. package/dist/react-native/RaftAttributeHandler.d.ts +1 -1
  2. package/dist/react-native/RaftAttributeHandler.js +18 -10
  3. package/dist/react-native/RaftAttributeHandler.js.map +1 -1
  4. package/dist/react-native/RaftChannelBLE.native.d.ts +11 -11
  5. package/dist/react-native/RaftChannelBLE.native.js +61 -41
  6. package/dist/react-native/RaftChannelBLE.native.js.map +1 -1
  7. package/dist/react-native/RaftChannelBLE.web.d.ts +3 -4
  8. package/dist/react-native/RaftChannelBLE.web.js +7 -8
  9. package/dist/react-native/RaftChannelBLE.web.js.map +1 -1
  10. package/dist/react-native/RaftChannelBLEScanner.native.d.ts +6 -6
  11. package/dist/react-native/RaftChannelBLEScanner.native.js +38 -46
  12. package/dist/react-native/RaftChannelBLEScanner.native.js.map +1 -1
  13. package/dist/react-native/RaftConnector.d.ts +3 -3
  14. package/dist/react-native/RaftConnector.js +4 -4
  15. package/dist/react-native/RaftConnector.js.map +1 -1
  16. package/dist/react-native/RaftCustomAttrHandler.d.ts +1 -1
  17. package/dist/react-native/RaftCustomAttrHandler.js +4 -4
  18. package/dist/react-native/RaftCustomAttrHandler.js.map +1 -1
  19. package/dist/react-native/RaftDeviceInfo.d.ts +3 -0
  20. package/dist/react-native/RaftDeviceManager.d.ts +16 -11
  21. package/dist/react-native/RaftDeviceManager.js +196 -50
  22. package/dist/react-native/RaftDeviceManager.js.map +1 -1
  23. package/dist/react-native/RaftDeviceMgrIF.d.ts +9 -6
  24. package/dist/react-native/RaftDeviceStates.d.ts +5 -1
  25. package/dist/react-native/RaftDeviceStates.js +3 -3
  26. package/dist/react-native/RaftDeviceStates.js.map +1 -1
  27. package/dist/react-native/RaftMsgHandler.d.ts +1 -1
  28. package/dist/react-native/RaftMsgHandler.js +1 -2
  29. package/dist/react-native/RaftMsgHandler.js.map +1 -1
  30. package/dist/react-native/RaftStruct.d.ts +3 -0
  31. package/dist/react-native/RaftStruct.js +208 -0
  32. package/dist/react-native/RaftStruct.js.map +1 -0
  33. package/dist/react-native/RaftSysTypeManager.d.ts +14 -0
  34. package/dist/react-native/RaftSysTypeManager.js +53 -0
  35. package/dist/react-native/RaftSysTypeManager.js.map +1 -0
  36. package/dist/react-native/RaftSystemType.d.ts +3 -0
  37. package/dist/react-native/RaftTypes.d.ts +14 -15
  38. package/dist/react-native/RaftTypes.js +13 -50
  39. package/dist/react-native/RaftTypes.js.map +1 -1
  40. package/dist/react-native/RaftUpdateManager.js +6 -3
  41. package/dist/react-native/RaftUpdateManager.js.map +1 -1
  42. package/dist/react-native/RaftUtils.d.ts +1 -0
  43. package/dist/react-native/RaftUtils.js +17 -4
  44. package/dist/react-native/RaftUtils.js.map +1 -1
  45. package/dist/react-native/main.d.ts +2 -1
  46. package/dist/react-native/main.js +4 -4
  47. package/dist/react-native/main.js.map +1 -1
  48. package/dist/web/RaftAttributeHandler.d.ts +1 -1
  49. package/dist/web/RaftAttributeHandler.js +18 -10
  50. package/dist/web/RaftAttributeHandler.js.map +1 -1
  51. package/dist/web/RaftChannelBLE.web.d.ts +3 -4
  52. package/dist/web/RaftChannelBLE.web.js +7 -8
  53. package/dist/web/RaftChannelBLE.web.js.map +1 -1
  54. package/dist/web/RaftConnector.d.ts +3 -3
  55. package/dist/web/RaftConnector.js +4 -4
  56. package/dist/web/RaftConnector.js.map +1 -1
  57. package/dist/web/RaftCustomAttrHandler.d.ts +1 -1
  58. package/dist/web/RaftCustomAttrHandler.js +4 -4
  59. package/dist/web/RaftCustomAttrHandler.js.map +1 -1
  60. package/dist/web/RaftDeviceInfo.d.ts +3 -0
  61. package/dist/web/RaftDeviceManager.d.ts +16 -11
  62. package/dist/web/RaftDeviceManager.js +196 -50
  63. package/dist/web/RaftDeviceManager.js.map +1 -1
  64. package/dist/web/RaftDeviceMgrIF.d.ts +9 -6
  65. package/dist/web/RaftDeviceStates.d.ts +5 -1
  66. package/dist/web/RaftDeviceStates.js +3 -3
  67. package/dist/web/RaftDeviceStates.js.map +1 -1
  68. package/dist/web/RaftMsgHandler.d.ts +1 -1
  69. package/dist/web/RaftMsgHandler.js +1 -2
  70. package/dist/web/RaftMsgHandler.js.map +1 -1
  71. package/dist/web/RaftStruct.d.ts +3 -0
  72. package/dist/web/RaftStruct.js +208 -0
  73. package/dist/web/RaftStruct.js.map +1 -0
  74. package/dist/web/RaftSysTypeManager.d.ts +14 -0
  75. package/dist/web/RaftSysTypeManager.js +53 -0
  76. package/dist/web/RaftSysTypeManager.js.map +1 -0
  77. package/dist/web/RaftSystemType.d.ts +3 -0
  78. package/dist/web/RaftTypes.d.ts +14 -15
  79. package/dist/web/RaftTypes.js +13 -50
  80. package/dist/web/RaftTypes.js.map +1 -1
  81. package/dist/web/RaftUpdateManager.js +6 -3
  82. package/dist/web/RaftUpdateManager.js.map +1 -1
  83. package/dist/web/RaftUtils.d.ts +1 -0
  84. package/dist/web/RaftUtils.js +17 -4
  85. package/dist/web/RaftUtils.js.map +1 -1
  86. package/dist/web/main.d.ts +2 -1
  87. package/dist/web/main.js +4 -4
  88. package/dist/web/main.js.map +1 -1
  89. package/examples/dashboard/package.json +8 -15
  90. package/examples/dashboard/src/ConnManager.ts +18 -14
  91. package/examples/dashboard/src/DeviceActionsForm.tsx +49 -49
  92. package/examples/dashboard/src/DeviceLineChart.tsx +44 -20
  93. package/examples/dashboard/src/DevicePanel.tsx +33 -2
  94. package/examples/dashboard/src/DevicesPanel.tsx +5 -4
  95. package/examples/dashboard/src/LatencyTest.ts +130 -0
  96. package/examples/dashboard/src/LatencyTestPanel.tsx +92 -0
  97. package/examples/dashboard/src/Main.tsx +191 -73
  98. package/examples/dashboard/src/SettingsManager.ts +67 -0
  99. package/examples/dashboard/src/SettingsScreen.tsx +174 -0
  100. package/examples/dashboard/src/SystemTypeCog/CogStateInfo.ts +14 -8
  101. package/examples/dashboard/src/SystemTypeCog/SystemTypeCog.ts +12 -5
  102. package/examples/dashboard/src/SystemTypeGeneric/StateInfoGeneric.ts +30 -0
  103. package/examples/dashboard/src/SystemTypeGeneric/SystemTypeGeneric.ts +91 -0
  104. package/examples/dashboard/src/SystemTypeMarty/RICStateInfo.ts +23 -4
  105. package/examples/dashboard/src/SystemTypeMarty/RICSystemUtils.ts +1 -1
  106. package/examples/dashboard/src/SystemTypeMarty/SystemTypeMarty.ts +5 -2
  107. package/examples/dashboard/src/index.html +2 -2
  108. package/examples/dashboard/src/index.tsx +0 -2
  109. package/examples/dashboard/src/styles.css +14 -0
  110. package/package.json +6 -14
  111. package/src/RaftAttributeHandler.ts +23 -14
  112. package/src/RaftChannelBLE.native.ts +77 -53
  113. package/src/RaftChannelBLE.web.ts +8 -8
  114. package/src/RaftChannelBLEScanner.native.ts +38 -44
  115. package/src/RaftConnector.ts +5 -5
  116. package/src/RaftCustomAttrHandler.ts +5 -5
  117. package/src/RaftDeviceInfo.ts +3 -0
  118. package/src/RaftDeviceManager.ts +236 -65
  119. package/src/RaftDeviceMgrIF.ts +11 -6
  120. package/src/RaftDeviceStates.ts +7 -3
  121. package/src/RaftMsgHandler.ts +1 -2
  122. package/src/RaftStruct.ts +209 -0
  123. package/src/RaftSysTypeManager.ts +60 -0
  124. package/src/RaftSystemType.ts +3 -0
  125. package/src/RaftTypes.ts +30 -33
  126. package/src/RaftUpdateManager.ts +6 -3
  127. package/src/RaftUtils.ts +14 -4
  128. package/src/main.ts +2 -2
@@ -1,11 +1,10 @@
1
1
  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
2
  //
3
- // RICBLEScanner
4
- // Communications Connector for RIC V2
3
+ // RaftChannelBLEScanner.native.ts
4
+ // Communications Connector for RaftJS
5
5
  //
6
- // RIC V2
7
- // Rob Dobson 2022
8
- // (C) Robotical 2022
6
+ // Rob Dobson 2022-24
7
+ // (C) Robotical 2022-24
9
8
  //
10
9
  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11
10
 
@@ -14,20 +13,20 @@ import {
14
13
  Device,
15
14
  BleError,
16
15
  } from 'react-native-ble-plx';
17
- import { DiscoveredRIC } from './RaftTypes';
16
+ import { DiscoveredDevice } from './RaftTypes';
18
17
  import RaftLog from './RaftLog';
19
18
  import { RaftConnEvent, RaftConnEventFn } from './RaftConnEvents';
20
19
 
21
- export default class RICBLEScanner {
20
+ export default class RaftChannelBLEScanner {
22
21
 
23
22
  // BleManager
24
23
  _bleManager: BleManager;
25
24
 
26
25
  // Services to scan for
27
- _uuidsOfServicesToScanFor: Array<string> = [];
26
+ _defaultUUIDsOfServicesToScanFor: Array<string> = [];
28
27
 
29
28
  // Scanned devices found on BLE
30
- _discoveredRICs: DiscoveredRIC[] = [];
29
+ _discoveredDevices: DiscoveredDevice[] = [];
31
30
  static _scanInProgress = false;
32
31
 
33
32
  // Time to scan for
@@ -38,40 +37,34 @@ export default class RICBLEScanner {
38
37
 
39
38
  constructor(bleManager: BleManager, uuidsOfServicesToScanFor: Array<string>, eventCallback: RaftConnEventFn) {
40
39
  this._bleManager = bleManager;
41
- this._uuidsOfServicesToScanFor = uuidsOfServicesToScanFor;
40
+ this._defaultUUIDsOfServicesToScanFor = uuidsOfServicesToScanFor;
42
41
  this._eventCallback = eventCallback;
43
42
  }
44
43
 
45
- // Get discovered RICs
46
- getDiscoveredRICs(): DiscoveredRIC[] {
47
- return this._discoveredRICs;
44
+ // Get discovered Devices
45
+ getDiscoveredDevices(): DiscoveredDevice[] {
46
+ return this._discoveredDevices;
48
47
  }
49
48
 
50
49
  // Check is a scan is in progress
51
50
  isScanInProgress(): boolean {
52
- return RICBLEScanner._scanInProgress;
51
+ return RaftChannelBLEScanner._scanInProgress;
53
52
  }
54
53
 
55
- async scanningStart(uuid?: string): Promise<boolean> {
56
- let uuidsOfServicesToScanFor: string[] = [];
57
- if (uuid) {
58
- uuidsOfServicesToScanFor.push(uuid);
59
- } else {
60
- uuidsOfServicesToScanFor = this._uuidsOfServicesToScanFor;
61
- }
54
+ async scanningStart(uuids: string[]): Promise<boolean> {
62
55
  // Handle discovery
63
56
  RaftLog.debug('Starting Scanning...');
64
57
 
65
58
  // Clear list
66
- this._discoveredRICs = [];
59
+ this._discoveredDevices = [];
67
60
 
68
61
  // Disconnect any connections
69
- RICBLEScanner._scanInProgress = true;
62
+ RaftChannelBLEScanner._scanInProgress = true;
70
63
 
71
64
  // Start scan
72
65
  try {
73
66
  this._bleManager.startDeviceScan(
74
- uuidsOfServicesToScanFor,
67
+ uuids.length > 0 ? uuids : this._defaultUUIDsOfServicesToScanFor,
75
68
  { allowDuplicates: true },
76
69
  (error: BleError | null, device: Device | null) => {
77
70
  // RaftLog.debug(`discoveryFoundCB error ${error}`);
@@ -93,15 +86,15 @@ export default class RICBLEScanner {
93
86
  RaftLog.debug('scanningStop');
94
87
 
95
88
  // Emit finished if we were scanning
96
- RaftLog.debug(`IS SCANNING IN PROGRESS: ${RICBLEScanner._scanInProgress}`);
97
- if (RICBLEScanner._scanInProgress) {
89
+ RaftLog.debug(`IS SCANNING IN PROGRESS: ${RaftChannelBLEScanner._scanInProgress}`);
90
+ if (RaftChannelBLEScanner._scanInProgress) {
98
91
  RaftLog.debug(`sending BLE_SCANNING_FINISHED event`);
99
- this._eventCallback(RaftConnEvent.BLE_SCANNING_FINISHED, { discoveredRICs: this._discoveredRICs });
92
+ this._eventCallback(RaftConnEvent.BLE_SCANNING_FINISHED, { discoveredDevices: this._discoveredDevices });
100
93
  }
101
94
 
102
95
  // Cancel scanning
103
96
  this._bleManager.stopDeviceScan();
104
- RICBLEScanner._scanInProgress = false;
97
+ RaftChannelBLEScanner._scanInProgress = false;
105
98
  }
106
99
 
107
100
  // Callback from BLE-PLX library on device discovered
@@ -113,28 +106,28 @@ export default class RICBLEScanner {
113
106
  //RaftLog.warn(`⚠️ Scan Error >> ${error.toString()}`);
114
107
  RaftLog.warn(`⚠️ Scan Error >> ${JSON.stringify(error)}`);
115
108
  // Event if we were scanning
116
- if (RICBLEScanner._scanInProgress) {
109
+ if (RaftChannelBLEScanner._scanInProgress) {
117
110
  this._eventCallback(RaftConnEvent.BLE_SCANNING_FINISHED, {
118
- discoveredRICs: this._discoveredRICs,
111
+ discoveredDevices: this._discoveredDevices,
119
112
  });
120
- RICBLEScanner._scanInProgress = false;
113
+ RaftChannelBLEScanner._scanInProgress = false;
121
114
  }
122
115
  return;
123
116
  }
124
117
 
125
118
  // See if already in the list
126
- const ricAlreadyFound = this._discoveredRICs.find(
119
+ const deviceAlreadyFound = this._discoveredDevices.find(
127
120
  item => item.id === scannedDevice!.id,
128
121
  );
129
122
 
130
123
  RaftLog.debug(`✅ Scanning... >> ${scannedDevice}`);
131
124
 
132
- if (ricAlreadyFound) {
125
+ if (deviceAlreadyFound) {
133
126
  // update the rssi value if it's not 127
134
127
  if (scannedDevice!.rssi !== null && scannedDevice!.rssi !== 127) {
135
- ricAlreadyFound._rssi = scannedDevice!.rssi;
128
+ deviceAlreadyFound._rssi = scannedDevice!.rssi;
136
129
  this._eventCallback(RaftConnEvent.BLE_DEVICE_FOUND, {
137
- discoveredRIC: ricAlreadyFound
130
+ discoveredDevice: deviceAlreadyFound
138
131
  });
139
132
  }
140
133
  return;
@@ -147,19 +140,20 @@ export default class RICBLEScanner {
147
140
  // will have all the needed info
148
141
  return;
149
142
  }
150
- const newDiscoveredRic = new DiscoveredRIC(
143
+ const newDiscoveredDevice = new DiscoveredDevice(
151
144
  scannedDevice.localName !== null ? scannedDevice.localName : '',
152
145
  scannedDevice.name !== null ? scannedDevice.name : '',
153
146
  scannedDevice.id,
154
147
  scannedDevice.rssi !== null ? scannedDevice.rssi : -150,
148
+ scannedDevice.serviceUUIDs,
155
149
  );
156
- this._discoveredRICs.push(newDiscoveredRic);
150
+ this._discoveredDevices.push(newDiscoveredDevice);
157
151
  // send the newly found ric to the state so it can pop-up on the front-end
158
152
  this._eventCallback(RaftConnEvent.BLE_DEVICE_FOUND, {
159
- discoveredRIC: newDiscoveredRic
153
+ discoveredDevice: newDiscoveredDevice
160
154
  });
161
155
  }
162
- RaftLog.debug(`🤖 Scanned RICs >> ${this._discoveredRICs}`);
156
+ RaftLog.debug(`🤖 Scanned RICs >> ${this._discoveredDevices}`);
163
157
  }
164
158
 
165
159
  // Time-limit on device scanning
@@ -169,22 +163,22 @@ export default class RICBLEScanner {
169
163
  this._bleManager.stopDeviceScan();
170
164
 
171
165
  // Check we were scanning
172
- if (RICBLEScanner._scanInProgress) {
166
+ if (RaftChannelBLEScanner._scanInProgress) {
173
167
  // Sort by signal strength
174
- // this._discoveredRICs.sort((a, b) => {
168
+ // this._discoveredDevices.sort((a, b) => {
175
169
  // return b!.rssi! - a!.rssi!;
176
170
  // });
177
171
 
178
172
  // Debug
179
- const msg = `🤖 ${this._discoveredRICs.length} RICs found! Choose one to connect`;
173
+ const msg = `🤖 ${this._discoveredDevices.length} RICs found! Choose one to connect`;
180
174
  RaftLog.debug(msg);
181
175
 
182
176
  // Finished event
183
177
  this._eventCallback(RaftConnEvent.BLE_SCANNING_FINISHED, {
184
- discoveredRICs: this._discoveredRICs,
178
+ discoveredDevices: this._discoveredDevices,
185
179
  });
186
180
  }
187
- RICBLEScanner._scanInProgress = false;
181
+ RaftChannelBLEScanner._scanInProgress = false;
188
182
  }, timeLimitMs);
189
183
  }
190
184
  }
@@ -157,9 +157,9 @@ export default class RaftConnector {
157
157
  }
158
158
 
159
159
  /**
160
- * Get connection locator
161
- * @returns string | object - connection locator
162
- * */
160
+ * Get connection locator
161
+ * @returns string | object - connection locator
162
+ * */
163
163
  getConnLocator(): any | null {
164
164
  return this._raftChannel ? this._raftChannel.getConnectedLocator() : null;
165
165
  }
@@ -353,7 +353,7 @@ export default class RaftConnector {
353
353
  return await this._raftMsgHandler.sendRICRESTURL<RaftOKFail>(commandName, bridgeID);
354
354
  } catch (error) {
355
355
  RaftLog.warn(`sendRICRESTMsg failed ${error}`);
356
- return new RaftOKFail();
356
+ return { rslt: 'fail' };
357
357
  }
358
358
  }
359
359
 
@@ -653,7 +653,7 @@ export default class RaftConnector {
653
653
  // Connect
654
654
  try {
655
655
  if (this._raftChannel) {
656
- const connected = await this._raftChannel.connect(this._channelConnLocator, this._systemType ? this._systemType.connectorOptions : {});
656
+ const connected = await this._raftChannel.connect(this._channelConnLocator, this._systemType ? this._systemType.connectorOptions : { });
657
657
  if (connected) {
658
658
  this._retryIfLostIsConnected = true;
659
659
  return true;
@@ -11,16 +11,16 @@ import { DeviceTypePollRespMetadata } from "./RaftDeviceInfo";
11
11
 
12
12
  export default class CustomAttrHandler {
13
13
 
14
- public handleAttr(pollRespMetadata: DeviceTypePollRespMetadata, msgBuffer: Buffer, msgBufIdx: number): number[][] {
14
+ public handleAttr(pollRespMetadata: DeviceTypePollRespMetadata, msgBuffer: Uint8Array, msgBufIdx: number): number[][] {
15
15
 
16
16
  // Number of bytes in the each message
17
17
  const numMsgBytes = pollRespMetadata.b;
18
18
 
19
19
  // Create a vector for each attribute in the metadata
20
- let attrValueVecs: [][] = [];
20
+ const attrValueVecs: [][] = [];
21
21
 
22
22
  // Reference to each vector by attribute name
23
- let attrValues: { [key: string]: number[] } = {};
23
+ const attrValues: { [key: string]: number[] } = {};
24
24
 
25
25
  // Add attributes to the vector
26
26
  for (let attrIdx = 0; attrIdx < pollRespMetadata.a.length; attrIdx++) {
@@ -32,13 +32,13 @@ export default class CustomAttrHandler {
32
32
  if (pollRespMetadata.c!.n === "max30101_fifo") {
33
33
  // Hex dump msgBuffer
34
34
  // console.log(`CustomAttrHandler handleAttr ${pollRespMetadata.c!.n} msgBuffer: ${msgBuffer.toString('hex')}`);
35
- let buf = msgBuffer.slice(msgBufIdx);
35
+ const buf = msgBuffer.slice(msgBufIdx);
36
36
  if (buf.length < numMsgBytes) {
37
37
  return [];
38
38
  }
39
39
 
40
40
  // Generated code ...
41
- let N=(buf[0]+32-buf[2])%32;
41
+ const N=(buf[0]+32-buf[2])%32;
42
42
  let k=3;
43
43
  let i=0;
44
44
  while (i<N) {
@@ -69,11 +69,14 @@ export interface DeviceTypeAction {
69
69
  n: string; // Action name
70
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
71
  w: string; // Prefix to write to cmd API
72
+ wz?: string; // Postfix to write to cmd API
72
73
  r?: number[]; // Range of valid values for the action
73
74
  f?: string; // Custom formatting options (e.g. LEDPIX for LED pixel grid)
74
75
  NX?: number; // Number of X in the LED pixel grid
75
76
  NY?: number; // Number of Y in the LED pixel grid
76
77
  concat?: boolean; // Concatenate the all values into a single command
78
+ mul?: number; // Multiplier to apply
79
+ sub?: number; // Value to subtract before multiplying
77
80
  d?: number; // Default value
78
81
  }
79
82