@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.
- package/dist/react-native/RaftAttributeHandler.d.ts +1 -1
- package/dist/react-native/RaftAttributeHandler.js +19 -11
- package/dist/react-native/RaftAttributeHandler.js.map +1 -1
- package/dist/react-native/RaftChannelBLE.native.d.ts +9 -11
- package/dist/react-native/RaftChannelBLE.native.js +34 -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 +3 -3
- 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/RaftDeviceManager.d.ts +15 -10
- package/dist/react-native/RaftDeviceManager.js +164 -45
- 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.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 +207 -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 +2 -2
- package/dist/react-native/RaftTypes.js +3 -3
- 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 +1 -0
- package/dist/react-native/main.js +3 -1
- package/dist/react-native/main.js.map +1 -1
- package/dist/web/RaftAttributeHandler.d.ts +1 -1
- package/dist/web/RaftAttributeHandler.js +19 -11
- 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 +3 -3
- 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/RaftDeviceManager.d.ts +15 -10
- package/dist/web/RaftDeviceManager.js +164 -45
- 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.js +1 -2
- package/dist/web/RaftMsgHandler.js.map +1 -1
- package/dist/web/RaftStruct.d.ts +3 -0
- package/dist/web/RaftStruct.js +207 -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 +2 -2
- package/dist/web/RaftTypes.js +3 -3
- 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 +1 -0
- package/dist/web/main.js +3 -1
- package/dist/web/main.js.map +1 -1
- package/examples/dashboard/package.json +5 -14
- package/examples/dashboard/src/ConnManager.ts +13 -16
- package/examples/dashboard/src/DeviceLineChart.tsx +40 -20
- package/examples/dashboard/src/DevicePanel.tsx +33 -2
- package/examples/dashboard/src/DevicesPanel.tsx +5 -4
- package/examples/dashboard/src/LatencyTest.ts +119 -0
- package/examples/dashboard/src/LatencyTestPanel.tsx +81 -0
- package/examples/dashboard/src/Main.tsx +185 -73
- package/examples/dashboard/src/SettingsManager.ts +65 -0
- package/examples/dashboard/src/SettingsScreen.tsx +125 -0
- package/examples/dashboard/src/SystemTypeCog/CogStateInfo.ts +13 -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/RICCommsStats.ts +0 -0
- package/examples/dashboard/src/SystemTypeMarty/RICStateInfo.ts +23 -4
- package/examples/dashboard/src/SystemTypeMarty/SystemTypeMarty.ts +4 -1
- package/examples/dashboard/src/index.tsx +0 -2
- package/examples/dashboard/src/styles.css +14 -0
- package/package.json +4 -13
- package/src/RaftAttributeHandler.ts +24 -15
- package/src/RaftChannelBLE.native.ts +44 -52
- package/src/RaftChannelBLE.web.ts +8 -8
- package/src/RaftChannelBLEScanner.native.ts +37 -44
- package/src/RaftConnector.ts +3 -3
- package/src/RaftCustomAttrHandler.ts +5 -5
- package/src/RaftDeviceManager.ts +195 -59
- package/src/RaftDeviceMgrIF.ts +11 -6
- package/src/RaftDeviceStates.ts +7 -3
- package/src/RaftMsgHandler.ts +1 -2
- package/src/RaftStruct.ts +208 -0
- package/src/RaftSysTypeManager.ts +60 -0
- package/src/RaftSystemType.ts +3 -0
- package/src/RaftTypes.ts +3 -3
- package/src/RaftUpdateManager.ts +6 -3
- package/src/RaftUtils.ts +14 -4
- 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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
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,19 @@ 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,
|
|
155
148
|
);
|
|
156
|
-
this.
|
|
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
|
-
|
|
152
|
+
discoveredDevice: newDiscoveredDevice
|
|
160
153
|
});
|
|
161
154
|
}
|
|
162
|
-
RaftLog.debug(`🤖 Scanned RICs >> ${this.
|
|
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 (
|
|
165
|
+
if (RaftChannelBLEScanner._scanInProgress) {
|
|
173
166
|
// Sort by signal strength
|
|
174
|
-
// this.
|
|
167
|
+
// this._discoveredDevices.sort((a, b) => {
|
|
175
168
|
// return b!.rssi! - a!.rssi!;
|
|
176
169
|
// });
|
|
177
170
|
|
|
178
171
|
// Debug
|
|
179
|
-
const msg = `🤖 ${this.
|
|
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
|
-
|
|
177
|
+
discoveredDevices: this._discoveredDevices,
|
|
185
178
|
});
|
|
186
179
|
}
|
|
187
|
-
|
|
180
|
+
RaftChannelBLEScanner._scanInProgress = false;
|
|
188
181
|
}, timeLimitMs);
|
|
189
182
|
}
|
|
190
183
|
}
|
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
|
}
|
|
@@ -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) {
|