@robdobsn/raftjs 1.3.2 → 1.5.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 (121) hide show
  1. package/dist/react-native/RaftAttributeHandler.d.ts +1 -1
  2. package/dist/react-native/RaftAttributeHandler.js +19 -11
  3. package/dist/react-native/RaftAttributeHandler.js.map +1 -1
  4. package/dist/react-native/RaftChannelBLE.native.d.ts +9 -11
  5. package/dist/react-native/RaftChannelBLE.native.js +34 -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 +3 -3
  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/RaftDeviceManager.d.ts +15 -10
  20. package/dist/react-native/RaftDeviceManager.js +164 -45
  21. package/dist/react-native/RaftDeviceManager.js.map +1 -1
  22. package/dist/react-native/RaftDeviceMgrIF.d.ts +9 -6
  23. package/dist/react-native/RaftDeviceStates.d.ts +5 -1
  24. package/dist/react-native/RaftDeviceStates.js +3 -3
  25. package/dist/react-native/RaftDeviceStates.js.map +1 -1
  26. package/dist/react-native/RaftMsgHandler.js +1 -2
  27. package/dist/react-native/RaftMsgHandler.js.map +1 -1
  28. package/dist/react-native/RaftStruct.d.ts +3 -0
  29. package/dist/react-native/RaftStruct.js +207 -0
  30. package/dist/react-native/RaftStruct.js.map +1 -0
  31. package/dist/react-native/RaftSysTypeManager.d.ts +14 -0
  32. package/dist/react-native/RaftSysTypeManager.js +53 -0
  33. package/dist/react-native/RaftSysTypeManager.js.map +1 -0
  34. package/dist/react-native/RaftSystemType.d.ts +3 -0
  35. package/dist/react-native/RaftTypes.d.ts +2 -2
  36. package/dist/react-native/RaftTypes.js +3 -3
  37. package/dist/react-native/RaftTypes.js.map +1 -1
  38. package/dist/react-native/RaftUpdateManager.js +6 -3
  39. package/dist/react-native/RaftUpdateManager.js.map +1 -1
  40. package/dist/react-native/RaftUtils.d.ts +1 -0
  41. package/dist/react-native/RaftUtils.js +17 -4
  42. package/dist/react-native/RaftUtils.js.map +1 -1
  43. package/dist/react-native/main.d.ts +1 -0
  44. package/dist/react-native/main.js +3 -1
  45. package/dist/react-native/main.js.map +1 -1
  46. package/dist/web/RaftAttributeHandler.d.ts +1 -1
  47. package/dist/web/RaftAttributeHandler.js +19 -11
  48. package/dist/web/RaftAttributeHandler.js.map +1 -1
  49. package/dist/web/RaftChannelBLE.web.d.ts +3 -4
  50. package/dist/web/RaftChannelBLE.web.js +7 -8
  51. package/dist/web/RaftChannelBLE.web.js.map +1 -1
  52. package/dist/web/RaftConnector.d.ts +3 -3
  53. package/dist/web/RaftConnector.js +3 -3
  54. package/dist/web/RaftConnector.js.map +1 -1
  55. package/dist/web/RaftCustomAttrHandler.d.ts +1 -1
  56. package/dist/web/RaftCustomAttrHandler.js +4 -4
  57. package/dist/web/RaftCustomAttrHandler.js.map +1 -1
  58. package/dist/web/RaftDeviceManager.d.ts +15 -10
  59. package/dist/web/RaftDeviceManager.js +164 -45
  60. package/dist/web/RaftDeviceManager.js.map +1 -1
  61. package/dist/web/RaftDeviceMgrIF.d.ts +9 -6
  62. package/dist/web/RaftDeviceStates.d.ts +5 -1
  63. package/dist/web/RaftDeviceStates.js +3 -3
  64. package/dist/web/RaftDeviceStates.js.map +1 -1
  65. package/dist/web/RaftMsgHandler.js +1 -2
  66. package/dist/web/RaftMsgHandler.js.map +1 -1
  67. package/dist/web/RaftStruct.d.ts +3 -0
  68. package/dist/web/RaftStruct.js +207 -0
  69. package/dist/web/RaftStruct.js.map +1 -0
  70. package/dist/web/RaftSysTypeManager.d.ts +14 -0
  71. package/dist/web/RaftSysTypeManager.js +53 -0
  72. package/dist/web/RaftSysTypeManager.js.map +1 -0
  73. package/dist/web/RaftSystemType.d.ts +3 -0
  74. package/dist/web/RaftTypes.d.ts +2 -2
  75. package/dist/web/RaftTypes.js +3 -3
  76. package/dist/web/RaftTypes.js.map +1 -1
  77. package/dist/web/RaftUpdateManager.js +6 -3
  78. package/dist/web/RaftUpdateManager.js.map +1 -1
  79. package/dist/web/RaftUtils.d.ts +1 -0
  80. package/dist/web/RaftUtils.js +17 -4
  81. package/dist/web/RaftUtils.js.map +1 -1
  82. package/dist/web/main.d.ts +1 -0
  83. package/dist/web/main.js +3 -1
  84. package/dist/web/main.js.map +1 -1
  85. package/examples/dashboard/package.json +5 -14
  86. package/examples/dashboard/src/ConnManager.ts +13 -16
  87. package/examples/dashboard/src/DeviceLineChart.tsx +40 -20
  88. package/examples/dashboard/src/DevicePanel.tsx +33 -2
  89. package/examples/dashboard/src/DevicesPanel.tsx +5 -4
  90. package/examples/dashboard/src/LatencyTest.ts +119 -0
  91. package/examples/dashboard/src/LatencyTestPanel.tsx +81 -0
  92. package/examples/dashboard/src/Main.tsx +185 -73
  93. package/examples/dashboard/src/SettingsManager.ts +65 -0
  94. package/examples/dashboard/src/SettingsScreen.tsx +125 -0
  95. package/examples/dashboard/src/SystemTypeCog/CogStateInfo.ts +13 -8
  96. package/examples/dashboard/src/SystemTypeCog/SystemTypeCog.ts +12 -5
  97. package/examples/dashboard/src/SystemTypeGeneric/StateInfoGeneric.ts +30 -0
  98. package/examples/dashboard/src/SystemTypeGeneric/SystemTypeGeneric.ts +91 -0
  99. package/examples/dashboard/src/SystemTypeMarty/RICCommsStats.ts +0 -0
  100. package/examples/dashboard/src/SystemTypeMarty/RICStateInfo.ts +23 -4
  101. package/examples/dashboard/src/SystemTypeMarty/SystemTypeMarty.ts +4 -1
  102. package/examples/dashboard/src/index.tsx +0 -2
  103. package/examples/dashboard/src/styles.css +14 -0
  104. package/package.json +4 -13
  105. package/src/RaftAttributeHandler.ts +24 -15
  106. package/src/RaftChannelBLE.native.ts +44 -52
  107. package/src/RaftChannelBLE.web.ts +8 -8
  108. package/src/RaftChannelBLEScanner.native.ts +37 -44
  109. package/src/RaftConnector.ts +3 -3
  110. package/src/RaftCustomAttrHandler.ts +5 -5
  111. package/src/RaftDeviceManager.ts +195 -59
  112. package/src/RaftDeviceMgrIF.ts +11 -6
  113. package/src/RaftDeviceStates.ts +7 -3
  114. package/src/RaftMsgHandler.ts +1 -2
  115. package/src/RaftStruct.ts +208 -0
  116. package/src/RaftSysTypeManager.ts +60 -0
  117. package/src/RaftSystemType.ts +3 -0
  118. package/src/RaftTypes.ts +3 -3
  119. package/src/RaftUpdateManager.ts +6 -3
  120. package/src/RaftUtils.ts +14 -4
  121. package/src/main.ts +1 -1
@@ -16,12 +16,12 @@ import { ConnectorOptions } from "./RaftSystemType";
16
16
  import RaftUtils from "./RaftUtils";
17
17
 
18
18
  export default class RaftChannelBLE implements RaftChannel {
19
- // BLE UUIDS
20
- public static RICServiceUUID = "aa76677e-9cfd-4626-a510-0d305be57c8d";
21
- public static CogServiceUUID = "da903f65-d5c2-4f4d-a065-d1aade7af874";
22
- public static CmdUUID = "aa76677e-9cfd-4626-a510-0d305be57c8e";
23
- public static RespUUID = "aa76677e-9cfd-4626-a510-0d305be57c8f";
24
19
 
20
+ // Default command and response UUIDs
21
+ _cmdUUID = 'aa76677e-9cfd-4626-a510-0d305be57c8e';
22
+ _respUUID = 'aa76677e-9cfd-4626-a510-0d305be57c8f';
23
+ _serviceUUIDs = ['aa76677e-9cfd-4626-a510-0d305be57c8d', 'da903f65-d5c2-4f4d-a065-d1aade7af874'];
24
+
25
25
  // Device and characteristics
26
26
  private _bleDevice: BluetoothDevice | null = null;
27
27
  private _characteristicTx: BluetoothRemoteGATTCharacteristic | null = null;
@@ -143,7 +143,7 @@ export default class RaftChannelBLE implements RaftChannel {
143
143
  try {
144
144
  let service: BluetoothRemoteGATTService | null = null;
145
145
  // iterate over known services
146
- for (const serviceUUID of [RaftChannelBLE.CogServiceUUID, RaftChannelBLE.RICServiceUUID]) {
146
+ for (const serviceUUID of this._serviceUUIDs) {
147
147
  try {
148
148
  service = await this._bleDevice.gatt.getPrimaryService(serviceUUID);
149
149
  if (service) {
@@ -169,13 +169,13 @@ export default class RaftChannelBLE implements RaftChannel {
169
169
  try {
170
170
  // Get Tx and Rx characteristics
171
171
  this._characteristicTx = await service.getCharacteristic(
172
- RaftChannelBLE.CmdUUID
172
+ this._cmdUUID
173
173
  );
174
174
  RaftLog.debug(
175
175
  `RaftChannelBLE.connect - found char ${this._characteristicTx.uuid}`
176
176
  );
177
177
  this._characteristicRx = await service.getCharacteristic(
178
- RaftChannelBLE.RespUUID
178
+ this._respUUID
179
179
  );
180
180
  RaftLog.debug(
181
181
  `RaftChannelBLE.connect - found char ${this._characteristicRx.uuid}`
@@ -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,19 @@ 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,
155
148
  );
156
- this._discoveredRICs.push(newDiscoveredRic);
149
+ this._discoveredDevices.push(newDiscoveredDevice);
157
150
  // send the newly found ric to the state so it can pop-up on the front-end
158
151
  this._eventCallback(RaftConnEvent.BLE_DEVICE_FOUND, {
159
- discoveredRIC: newDiscoveredRic
152
+ discoveredDevice: newDiscoveredDevice
160
153
  });
161
154
  }
162
- RaftLog.debug(`🤖 Scanned RICs >> ${this._discoveredRICs}`);
155
+ RaftLog.debug(`🤖 Scanned RICs >> ${this._discoveredDevices}`);
163
156
  }
164
157
 
165
158
  // Time-limit on device scanning
@@ -169,22 +162,22 @@ export default class RICBLEScanner {
169
162
  this._bleManager.stopDeviceScan();
170
163
 
171
164
  // Check we were scanning
172
- if (RICBLEScanner._scanInProgress) {
165
+ if (RaftChannelBLEScanner._scanInProgress) {
173
166
  // Sort by signal strength
174
- // this._discoveredRICs.sort((a, b) => {
167
+ // this._discoveredDevices.sort((a, b) => {
175
168
  // return b!.rssi! - a!.rssi!;
176
169
  // });
177
170
 
178
171
  // Debug
179
- const msg = `🤖 ${this._discoveredRICs.length} RICs found! Choose one to connect`;
172
+ const msg = `🤖 ${this._discoveredDevices.length} RICs found! Choose one to connect`;
180
173
  RaftLog.debug(msg);
181
174
 
182
175
  // Finished event
183
176
  this._eventCallback(RaftConnEvent.BLE_SCANNING_FINISHED, {
184
- discoveredRICs: this._discoveredRICs,
177
+ discoveredDevices: this._discoveredDevices,
185
178
  });
186
179
  }
187
- RICBLEScanner._scanInProgress = false;
180
+ RaftChannelBLEScanner._scanInProgress = false;
188
181
  }, timeLimitMs);
189
182
  }
190
183
  }
@@ -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
  }
@@ -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) {