@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.
- package/dist/react-native/RaftAttributeHandler.d.ts +1 -1
- package/dist/react-native/RaftAttributeHandler.js +18 -10
- package/dist/react-native/RaftAttributeHandler.js.map +1 -1
- package/dist/react-native/RaftChannelBLE.native.d.ts +11 -11
- package/dist/react-native/RaftChannelBLE.native.js +61 -41
- package/dist/react-native/RaftChannelBLE.native.js.map +1 -1
- package/dist/react-native/RaftChannelBLE.web.d.ts +3 -4
- package/dist/react-native/RaftChannelBLE.web.js +7 -8
- package/dist/react-native/RaftChannelBLE.web.js.map +1 -1
- package/dist/react-native/RaftChannelBLEScanner.native.d.ts +6 -6
- package/dist/react-native/RaftChannelBLEScanner.native.js +38 -46
- package/dist/react-native/RaftChannelBLEScanner.native.js.map +1 -1
- package/dist/react-native/RaftConnector.d.ts +3 -3
- package/dist/react-native/RaftConnector.js +4 -4
- package/dist/react-native/RaftConnector.js.map +1 -1
- package/dist/react-native/RaftCustomAttrHandler.d.ts +1 -1
- package/dist/react-native/RaftCustomAttrHandler.js +4 -4
- package/dist/react-native/RaftCustomAttrHandler.js.map +1 -1
- package/dist/react-native/RaftDeviceInfo.d.ts +3 -0
- package/dist/react-native/RaftDeviceManager.d.ts +16 -11
- package/dist/react-native/RaftDeviceManager.js +196 -50
- package/dist/react-native/RaftDeviceManager.js.map +1 -1
- package/dist/react-native/RaftDeviceMgrIF.d.ts +9 -6
- package/dist/react-native/RaftDeviceStates.d.ts +5 -1
- package/dist/react-native/RaftDeviceStates.js +3 -3
- package/dist/react-native/RaftDeviceStates.js.map +1 -1
- package/dist/react-native/RaftMsgHandler.d.ts +1 -1
- package/dist/react-native/RaftMsgHandler.js +1 -2
- package/dist/react-native/RaftMsgHandler.js.map +1 -1
- package/dist/react-native/RaftStruct.d.ts +3 -0
- package/dist/react-native/RaftStruct.js +208 -0
- package/dist/react-native/RaftStruct.js.map +1 -0
- package/dist/react-native/RaftSysTypeManager.d.ts +14 -0
- package/dist/react-native/RaftSysTypeManager.js +53 -0
- package/dist/react-native/RaftSysTypeManager.js.map +1 -0
- package/dist/react-native/RaftSystemType.d.ts +3 -0
- package/dist/react-native/RaftTypes.d.ts +14 -15
- package/dist/react-native/RaftTypes.js +13 -50
- package/dist/react-native/RaftTypes.js.map +1 -1
- package/dist/react-native/RaftUpdateManager.js +6 -3
- package/dist/react-native/RaftUpdateManager.js.map +1 -1
- package/dist/react-native/RaftUtils.d.ts +1 -0
- package/dist/react-native/RaftUtils.js +17 -4
- package/dist/react-native/RaftUtils.js.map +1 -1
- package/dist/react-native/main.d.ts +2 -1
- package/dist/react-native/main.js +4 -4
- package/dist/react-native/main.js.map +1 -1
- package/dist/web/RaftAttributeHandler.d.ts +1 -1
- package/dist/web/RaftAttributeHandler.js +18 -10
- package/dist/web/RaftAttributeHandler.js.map +1 -1
- package/dist/web/RaftChannelBLE.web.d.ts +3 -4
- package/dist/web/RaftChannelBLE.web.js +7 -8
- package/dist/web/RaftChannelBLE.web.js.map +1 -1
- package/dist/web/RaftConnector.d.ts +3 -3
- package/dist/web/RaftConnector.js +4 -4
- package/dist/web/RaftConnector.js.map +1 -1
- package/dist/web/RaftCustomAttrHandler.d.ts +1 -1
- package/dist/web/RaftCustomAttrHandler.js +4 -4
- package/dist/web/RaftCustomAttrHandler.js.map +1 -1
- package/dist/web/RaftDeviceInfo.d.ts +3 -0
- package/dist/web/RaftDeviceManager.d.ts +16 -11
- package/dist/web/RaftDeviceManager.js +196 -50
- package/dist/web/RaftDeviceManager.js.map +1 -1
- package/dist/web/RaftDeviceMgrIF.d.ts +9 -6
- package/dist/web/RaftDeviceStates.d.ts +5 -1
- package/dist/web/RaftDeviceStates.js +3 -3
- package/dist/web/RaftDeviceStates.js.map +1 -1
- package/dist/web/RaftMsgHandler.d.ts +1 -1
- package/dist/web/RaftMsgHandler.js +1 -2
- package/dist/web/RaftMsgHandler.js.map +1 -1
- package/dist/web/RaftStruct.d.ts +3 -0
- package/dist/web/RaftStruct.js +208 -0
- package/dist/web/RaftStruct.js.map +1 -0
- package/dist/web/RaftSysTypeManager.d.ts +14 -0
- package/dist/web/RaftSysTypeManager.js +53 -0
- package/dist/web/RaftSysTypeManager.js.map +1 -0
- package/dist/web/RaftSystemType.d.ts +3 -0
- package/dist/web/RaftTypes.d.ts +14 -15
- package/dist/web/RaftTypes.js +13 -50
- package/dist/web/RaftTypes.js.map +1 -1
- package/dist/web/RaftUpdateManager.js +6 -3
- package/dist/web/RaftUpdateManager.js.map +1 -1
- package/dist/web/RaftUtils.d.ts +1 -0
- package/dist/web/RaftUtils.js +17 -4
- package/dist/web/RaftUtils.js.map +1 -1
- package/dist/web/main.d.ts +2 -1
- package/dist/web/main.js +4 -4
- package/dist/web/main.js.map +1 -1
- package/examples/dashboard/package.json +8 -15
- package/examples/dashboard/src/ConnManager.ts +18 -14
- package/examples/dashboard/src/DeviceActionsForm.tsx +49 -49
- package/examples/dashboard/src/DeviceLineChart.tsx +44 -20
- package/examples/dashboard/src/DevicePanel.tsx +33 -2
- package/examples/dashboard/src/DevicesPanel.tsx +5 -4
- package/examples/dashboard/src/LatencyTest.ts +130 -0
- package/examples/dashboard/src/LatencyTestPanel.tsx +92 -0
- package/examples/dashboard/src/Main.tsx +191 -73
- package/examples/dashboard/src/SettingsManager.ts +67 -0
- package/examples/dashboard/src/SettingsScreen.tsx +174 -0
- package/examples/dashboard/src/SystemTypeCog/CogStateInfo.ts +14 -8
- package/examples/dashboard/src/SystemTypeCog/SystemTypeCog.ts +12 -5
- package/examples/dashboard/src/SystemTypeGeneric/StateInfoGeneric.ts +30 -0
- package/examples/dashboard/src/SystemTypeGeneric/SystemTypeGeneric.ts +91 -0
- package/examples/dashboard/src/SystemTypeMarty/RICStateInfo.ts +23 -4
- package/examples/dashboard/src/SystemTypeMarty/RICSystemUtils.ts +1 -1
- package/examples/dashboard/src/SystemTypeMarty/SystemTypeMarty.ts +5 -2
- package/examples/dashboard/src/index.html +2 -2
- package/examples/dashboard/src/index.tsx +0 -2
- package/examples/dashboard/src/styles.css +14 -0
- package/package.json +6 -14
- package/src/RaftAttributeHandler.ts +23 -14
- package/src/RaftChannelBLE.native.ts +77 -53
- package/src/RaftChannelBLE.web.ts +8 -8
- package/src/RaftChannelBLEScanner.native.ts +38 -44
- package/src/RaftConnector.ts +5 -5
- package/src/RaftCustomAttrHandler.ts +5 -5
- package/src/RaftDeviceInfo.ts +3 -0
- package/src/RaftDeviceManager.ts +236 -65
- package/src/RaftDeviceMgrIF.ts +11 -6
- package/src/RaftDeviceStates.ts +7 -3
- package/src/RaftMsgHandler.ts +1 -2
- package/src/RaftStruct.ts +209 -0
- package/src/RaftSysTypeManager.ts +60 -0
- package/src/RaftSystemType.ts +3 -0
- package/src/RaftTypes.ts +30 -33
- package/src/RaftUpdateManager.ts +6 -3
- package/src/RaftUtils.ts +14 -4
- package/src/main.ts +2 -2
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// Communications Connector for
|
|
3
|
+
// RaftChannelBLEScanner.native.ts
|
|
4
|
+
// Communications Connector for RaftJS
|
|
5
5
|
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
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 {
|
|
16
|
+
import { DiscoveredDevice } from './RaftTypes';
|
|
18
17
|
import RaftLog from './RaftLog';
|
|
19
18
|
import { RaftConnEvent, RaftConnEventFn } from './RaftConnEvents';
|
|
20
19
|
|
|
21
|
-
export default class
|
|
20
|
+
export default class RaftChannelBLEScanner {
|
|
22
21
|
|
|
23
22
|
// BleManager
|
|
24
23
|
_bleManager: BleManager;
|
|
25
24
|
|
|
26
25
|
// Services to scan for
|
|
27
|
-
|
|
26
|
+
_defaultUUIDsOfServicesToScanFor: Array<string> = [];
|
|
28
27
|
|
|
29
28
|
// Scanned devices found on BLE
|
|
30
|
-
|
|
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.
|
|
40
|
+
this._defaultUUIDsOfServicesToScanFor = uuidsOfServicesToScanFor;
|
|
42
41
|
this._eventCallback = eventCallback;
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
// Get discovered
|
|
46
|
-
|
|
47
|
-
return this.
|
|
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
|
|
51
|
+
return RaftChannelBLEScanner._scanInProgress;
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
async scanningStart(
|
|
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.
|
|
59
|
+
this._discoveredDevices = [];
|
|
67
60
|
|
|
68
61
|
// Disconnect any connections
|
|
69
|
-
|
|
62
|
+
RaftChannelBLEScanner._scanInProgress = true;
|
|
70
63
|
|
|
71
64
|
// Start scan
|
|
72
65
|
try {
|
|
73
66
|
this._bleManager.startDeviceScan(
|
|
74
|
-
|
|
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: ${
|
|
97
|
-
if (
|
|
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, {
|
|
92
|
+
this._eventCallback(RaftConnEvent.BLE_SCANNING_FINISHED, { discoveredDevices: this._discoveredDevices });
|
|
100
93
|
}
|
|
101
94
|
|
|
102
95
|
// Cancel scanning
|
|
103
96
|
this._bleManager.stopDeviceScan();
|
|
104
|
-
|
|
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 (
|
|
109
|
+
if (RaftChannelBLEScanner._scanInProgress) {
|
|
117
110
|
this._eventCallback(RaftConnEvent.BLE_SCANNING_FINISHED, {
|
|
118
|
-
|
|
111
|
+
discoveredDevices: this._discoveredDevices,
|
|
119
112
|
});
|
|
120
|
-
|
|
113
|
+
RaftChannelBLEScanner._scanInProgress = false;
|
|
121
114
|
}
|
|
122
115
|
return;
|
|
123
116
|
}
|
|
124
117
|
|
|
125
118
|
// See if already in the list
|
|
126
|
-
const
|
|
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 (
|
|
125
|
+
if (deviceAlreadyFound) {
|
|
133
126
|
// update the rssi value if it's not 127
|
|
134
127
|
if (scannedDevice!.rssi !== null && scannedDevice!.rssi !== 127) {
|
|
135
|
-
|
|
128
|
+
deviceAlreadyFound._rssi = scannedDevice!.rssi;
|
|
136
129
|
this._eventCallback(RaftConnEvent.BLE_DEVICE_FOUND, {
|
|
137
|
-
|
|
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
|
|
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.
|
|
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
|
-
|
|
153
|
+
discoveredDevice: newDiscoveredDevice
|
|
160
154
|
});
|
|
161
155
|
}
|
|
162
|
-
RaftLog.debug(`🤖 Scanned RICs >> ${this.
|
|
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 (
|
|
166
|
+
if (RaftChannelBLEScanner._scanInProgress) {
|
|
173
167
|
// Sort by signal strength
|
|
174
|
-
// this.
|
|
168
|
+
// this._discoveredDevices.sort((a, b) => {
|
|
175
169
|
// return b!.rssi! - a!.rssi!;
|
|
176
170
|
// });
|
|
177
171
|
|
|
178
172
|
// Debug
|
|
179
|
-
const msg = `🤖 ${this.
|
|
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
|
-
|
|
178
|
+
discoveredDevices: this._discoveredDevices,
|
|
185
179
|
});
|
|
186
180
|
}
|
|
187
|
-
|
|
181
|
+
RaftChannelBLEScanner._scanInProgress = false;
|
|
188
182
|
}, timeLimitMs);
|
|
189
183
|
}
|
|
190
184
|
}
|
package/src/RaftConnector.ts
CHANGED
|
@@ -157,9 +157,9 @@ export default class RaftConnector {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
/**
|
|
160
|
-
|
|
161
|
-
|
|
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
|
|
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:
|
|
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
|
-
|
|
20
|
+
const attrValueVecs: [][] = [];
|
|
21
21
|
|
|
22
22
|
// Reference to each vector by attribute name
|
|
23
|
-
|
|
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
|
-
|
|
35
|
+
const buf = msgBuffer.slice(msgBufIdx);
|
|
36
36
|
if (buf.length < numMsgBytes) {
|
|
37
37
|
return [];
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// Generated code ...
|
|
41
|
-
|
|
41
|
+
const N=(buf[0]+32-buf[2])%32;
|
|
42
42
|
let k=3;
|
|
43
43
|
let i=0;
|
|
44
44
|
while (i<N) {
|
package/src/RaftDeviceInfo.ts
CHANGED
|
@@ -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
|
|