@robdobsn/raftjs 1.1.1 → 1.3.2
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/README.md +2 -0
- package/dist/{RaftAttributeHandler.js → react-native/RaftAttributeHandler.js} +1 -1
- package/dist/react-native/RaftAttributeHandler.js.map +1 -0
- package/dist/react-native/RaftChannel.js.map +1 -0
- package/dist/react-native/RaftChannelBLE.native.d.ts +93 -0
- package/dist/react-native/RaftChannelBLE.native.js +455 -0
- package/dist/react-native/RaftChannelBLE.native.js.map +1 -0
- package/dist/{RaftChannelWebBLE.d.ts → react-native/RaftChannelBLE.web.d.ts} +3 -2
- package/dist/{RaftChannelWebBLE.js → react-native/RaftChannelBLE.web.js} +48 -28
- package/dist/react-native/RaftChannelBLE.web.js.map +1 -0
- package/dist/react-native/RaftChannelBLEFactory.d.ts +10 -0
- package/dist/react-native/RaftChannelBLEFactory.js +17 -0
- package/dist/react-native/RaftChannelBLEFactory.js.map +1 -0
- package/dist/react-native/RaftChannelBLEScanner.native.d.ts +18 -0
- package/dist/react-native/RaftChannelBLEScanner.native.js +146 -0
- package/dist/react-native/RaftChannelBLEScanner.native.js.map +1 -0
- package/dist/{RaftChannelWebSerial.js → react-native/RaftChannelWebSerial.js} +3 -2
- package/dist/react-native/RaftChannelWebSerial.js.map +1 -0
- package/dist/react-native/RaftChannelWebSocket.js.map +1 -0
- package/dist/react-native/RaftCommsStats.js.map +1 -0
- package/dist/{RaftConnEvents.d.ts → react-native/RaftConnEvents.d.ts} +10 -2
- package/dist/{RaftConnEvents.js → react-native/RaftConnEvents.js} +10 -0
- package/dist/react-native/RaftConnEvents.js.map +1 -0
- package/dist/{RaftConnector.d.ts → react-native/RaftConnector.d.ts} +6 -3
- package/dist/{RaftConnector.js → react-native/RaftConnector.js} +75 -74
- package/dist/react-native/RaftConnector.js.map +1 -0
- package/dist/react-native/RaftCustomAttrHandler.js.map +1 -0
- package/dist/{RaftDeviceInfo.d.ts → react-native/RaftDeviceInfo.d.ts} +5 -10
- package/dist/react-native/RaftDeviceInfo.js.map +1 -0
- package/dist/{RaftDeviceManager.d.ts → react-native/RaftDeviceManager.d.ts} +14 -16
- package/dist/{RaftDeviceManager.js → react-native/RaftDeviceManager.js} +116 -213
- package/dist/react-native/RaftDeviceManager.js.map +1 -0
- package/dist/react-native/RaftDeviceMgrIF.d.ts +12 -0
- package/dist/react-native/RaftDeviceMgrIF.js +11 -0
- package/dist/react-native/RaftDeviceMgrIF.js.map +1 -0
- package/dist/react-native/RaftDeviceMsg.js.map +1 -0
- package/dist/{RaftDeviceStates.d.ts → react-native/RaftDeviceStates.d.ts} +1 -1
- package/dist/react-native/RaftDeviceStates.js.map +1 -0
- package/dist/react-native/RaftFileHandler.js.map +1 -0
- package/dist/react-native/RaftLog.js.map +1 -0
- package/dist/{RaftMiniHDLC.js → react-native/RaftMiniHDLC.js} +1 -1
- package/dist/react-native/RaftMiniHDLC.js.map +1 -0
- package/dist/{RaftMsgHandler.js → react-native/RaftMsgHandler.js} +2 -2
- package/dist/react-native/RaftMsgHandler.js.map +1 -0
- package/dist/react-native/RaftMsgTrackInfo.js.map +1 -0
- package/dist/react-native/RaftProtocolDefs.js.map +1 -0
- package/dist/react-native/RaftStreamHandler.js.map +1 -0
- package/dist/{RaftSystemType.d.ts → react-native/RaftSystemType.d.ts} +4 -0
- package/dist/{RaftSystemType.js.map → react-native/RaftSystemType.js.map} +1 -1
- package/dist/react-native/RaftSystemUtils.js.map +1 -0
- package/dist/{RaftTypes.d.ts → react-native/RaftTypes.d.ts} +11 -0
- package/dist/{RaftTypes.js → react-native/RaftTypes.js} +34 -1
- package/dist/react-native/RaftTypes.js.map +1 -0
- package/dist/react-native/RaftUpdateEvents.js.map +1 -0
- package/dist/react-native/RaftUpdateManager.js.map +1 -0
- package/dist/{RaftUtils.js → react-native/RaftUtils.js} +1 -1
- package/dist/react-native/RaftUtils.js.map +1 -0
- package/dist/react-native/RaftWifiTypes.js.map +1 -0
- package/dist/react-native/main.d.ts +21 -0
- package/dist/{main.js → react-native/main.js} +7 -3
- package/dist/react-native/main.js.map +1 -0
- package/dist/web/RaftAttributeHandler.d.ts +12 -0
- package/dist/web/RaftAttributeHandler.js +241 -0
- package/dist/web/RaftAttributeHandler.js.map +1 -0
- package/dist/web/RaftChannel.d.ts +18 -0
- package/dist/web/RaftChannel.js +12 -0
- package/dist/web/RaftChannel.js.map +1 -0
- package/dist/web/RaftChannelBLE.web.d.ts +39 -0
- package/dist/web/RaftChannelBLE.web.js +294 -0
- package/dist/web/RaftChannelBLE.web.js.map +1 -0
- package/dist/web/RaftChannelBLEFactory.d.ts +10 -0
- package/dist/web/RaftChannelBLEFactory.js +17 -0
- package/dist/web/RaftChannelBLEFactory.js.map +1 -0
- package/dist/web/RaftChannelWebSerial.d.ts +37 -0
- package/dist/web/RaftChannelWebSerial.js +320 -0
- package/dist/web/RaftChannelWebSerial.js.map +1 -0
- package/dist/web/RaftChannelWebSocket.d.ts +28 -0
- package/dist/web/RaftChannelWebSocket.js +197 -0
- package/dist/web/RaftChannelWebSocket.js.map +1 -0
- package/dist/web/RaftCommsStats.d.ts +39 -0
- package/dist/web/RaftCommsStats.js +128 -0
- package/dist/web/RaftCommsStats.js.map +1 -0
- package/dist/web/RaftConnEvents.d.ts +39 -0
- package/dist/web/RaftConnEvents.js +54 -0
- package/dist/web/RaftConnEvents.js.map +1 -0
- package/dist/web/RaftConnector.d.ts +245 -0
- package/dist/web/RaftConnector.js +614 -0
- package/dist/web/RaftConnector.js.map +1 -0
- package/dist/web/RaftCustomAttrHandler.d.ts +4 -0
- package/dist/web/RaftCustomAttrHandler.js +50 -0
- package/dist/web/RaftCustomAttrHandler.js.map +1 -0
- package/dist/web/RaftDeviceInfo.d.ts +59 -0
- package/dist/web/RaftDeviceInfo.js +36 -0
- package/dist/web/RaftDeviceInfo.js.map +1 -0
- package/dist/web/RaftDeviceManager.d.ts +35 -0
- package/dist/web/RaftDeviceManager.js +353 -0
- package/dist/web/RaftDeviceManager.js.map +1 -0
- package/dist/web/RaftDeviceMgrIF.d.ts +12 -0
- package/dist/web/RaftDeviceMgrIF.js +11 -0
- package/dist/web/RaftDeviceMgrIF.js.map +1 -0
- package/dist/web/RaftDeviceMsg.d.ts +9 -0
- package/dist/web/RaftDeviceMsg.js +11 -0
- package/dist/web/RaftDeviceMsg.js.map +1 -0
- package/dist/web/RaftDeviceStates.d.ts +33 -0
- package/dist/web/RaftDeviceStates.js +60 -0
- package/dist/web/RaftDeviceStates.js.map +1 -0
- package/dist/web/RaftFileHandler.d.ts +52 -0
- package/dist/web/RaftFileHandler.js +502 -0
- package/dist/web/RaftFileHandler.js.map +1 -0
- package/dist/web/RaftLog.d.ts +22 -0
- package/dist/web/RaftLog.js +63 -0
- package/dist/web/RaftLog.js.map +1 -0
- package/dist/web/RaftMiniHDLC.d.ts +18 -0
- package/dist/web/RaftMiniHDLC.js +383 -0
- package/dist/web/RaftMiniHDLC.js.map +1 -0
- package/dist/web/RaftMsgHandler.d.ts +57 -0
- package/dist/web/RaftMsgHandler.js +480 -0
- package/dist/web/RaftMsgHandler.js.map +1 -0
- package/dist/web/RaftMsgTrackInfo.d.ts +17 -0
- package/dist/web/RaftMsgTrackInfo.js +42 -0
- package/dist/web/RaftMsgTrackInfo.js.map +1 -0
- package/dist/web/RaftProtocolDefs.d.ts +30 -0
- package/dist/web/RaftProtocolDefs.js +48 -0
- package/dist/web/RaftProtocolDefs.js.map +1 -0
- package/dist/web/RaftStreamHandler.d.ts +38 -0
- package/dist/web/RaftStreamHandler.js +257 -0
- package/dist/web/RaftStreamHandler.js.map +1 -0
- package/dist/web/RaftSystemType.d.ts +25 -0
- package/dist/web/RaftSystemType.js +3 -0
- package/dist/web/RaftSystemType.js.map +1 -0
- package/dist/web/RaftSystemUtils.d.ts +136 -0
- package/dist/web/RaftSystemUtils.js +410 -0
- package/dist/web/RaftSystemUtils.js.map +1 -0
- package/dist/web/RaftTypes.d.ts +195 -0
- package/dist/web/RaftTypes.js +190 -0
- package/dist/web/RaftTypes.js.map +1 -0
- package/dist/web/RaftUpdateEvents.d.ts +33 -0
- package/dist/web/RaftUpdateEvents.js +46 -0
- package/dist/web/RaftUpdateEvents.js.map +1 -0
- package/dist/web/RaftUpdateManager.d.ts +61 -0
- package/dist/web/RaftUpdateManager.js +618 -0
- package/dist/web/RaftUpdateManager.js.map +1 -0
- package/dist/web/RaftUtils.d.ts +125 -0
- package/dist/web/RaftUtils.js +454 -0
- package/dist/web/RaftUtils.js.map +1 -0
- package/dist/web/RaftWifiTypes.d.ts +23 -0
- package/dist/web/RaftWifiTypes.js +43 -0
- package/dist/web/RaftWifiTypes.js.map +1 -0
- package/dist/{main.d.ts → web/main.d.ts} +4 -1
- package/dist/web/main.js +46 -0
- package/dist/web/main.js.map +1 -0
- package/examples/dashboard/package.json +4 -0
- package/examples/dashboard/src/CommandPanel.tsx +147 -0
- package/examples/dashboard/src/ConnManager.ts +11 -12
- package/examples/dashboard/src/DeviceActionsForm.tsx +133 -0
- package/examples/dashboard/src/DeviceAttrsForm.tsx +49 -0
- package/examples/dashboard/src/DeviceLineChart.tsx +139 -0
- package/examples/dashboard/src/DevicePanel.tsx +135 -0
- package/examples/dashboard/src/DevicesPanel.tsx +57 -0
- package/examples/dashboard/src/DispLedGrid.tsx +110 -0
- package/examples/dashboard/src/DispOneLed.tsx +20 -0
- package/examples/dashboard/src/Main.tsx +53 -47
- package/examples/dashboard/src/{StatusScreen.tsx → StatusPanel.tsx} +13 -14
- package/examples/dashboard/src/SystemTypeCog/CogStateInfo.ts +135 -122
- package/examples/dashboard/src/SystemTypeCog/SystemTypeCog.ts +15 -8
- package/examples/dashboard/src/SystemTypeMarty/RICCommsStats.ts +0 -0
- package/examples/dashboard/src/SystemTypeMarty/RICStateInfo.ts +47 -1
- package/examples/dashboard/src/SystemTypeMarty/SystemTypeMarty.ts +4 -1
- package/examples/dashboard/src/styles.css +274 -10
- package/package.json +57 -48
- package/src/RaftAttributeHandler.ts +1 -1
- package/src/RaftChannelBLE.native.ts +583 -0
- package/src/{RaftChannelWebBLE.ts → RaftChannelBLE.web.ts} +60 -40
- package/src/RaftChannelBLEFactory.ts +13 -0
- package/src/RaftChannelBLEScanner.native.ts +190 -0
- package/src/RaftChannelWebSerial.ts +1 -0
- package/src/RaftConnEvents.ts +14 -2
- package/src/RaftConnector.ts +80 -88
- package/src/RaftDeviceInfo.ts +6 -12
- package/src/RaftDeviceManager.ts +139 -245
- package/src/RaftDeviceMgrIF.ts +28 -0
- package/src/RaftDeviceStates.ts +1 -2
- package/src/RaftMiniHDLC.ts +1 -1
- package/src/RaftMsgHandler.ts +2 -2
- package/src/RaftSystemType.ts +4 -0
- package/src/RaftTypes.ts +48 -17
- package/src/RaftUtils.ts +1 -1
- package/src/main.ts +8 -1
- package/tsconfig.json +5 -2
- package/tsconfig.react-native.json +29 -0
- package/dist/RaftAttributeHandler.js.map +0 -1
- package/dist/RaftChannel.js.map +0 -1
- package/dist/RaftChannelWebBLE.js.map +0 -1
- package/dist/RaftChannelWebSerial.js.map +0 -1
- package/dist/RaftChannelWebSocket.js.map +0 -1
- package/dist/RaftCommsStats.js.map +0 -1
- package/dist/RaftConnEvents.js.map +0 -1
- package/dist/RaftConnector.js.map +0 -1
- package/dist/RaftCustomAttrHandler.js.map +0 -1
- package/dist/RaftDeviceInfo.js.map +0 -1
- package/dist/RaftDeviceManager.js.map +0 -1
- package/dist/RaftDeviceMsg.js.map +0 -1
- package/dist/RaftDeviceStates.js.map +0 -1
- package/dist/RaftFileHandler.js.map +0 -1
- package/dist/RaftLog.js.map +0 -1
- package/dist/RaftMiniHDLC.js.map +0 -1
- package/dist/RaftMsgHandler.js.map +0 -1
- package/dist/RaftMsgTrackInfo.js.map +0 -1
- package/dist/RaftProtocolDefs.js.map +0 -1
- package/dist/RaftStreamHandler.js.map +0 -1
- package/dist/RaftSystemUtils.js.map +0 -1
- package/dist/RaftTypes.js.map +0 -1
- package/dist/RaftUpdateEvents.js.map +0 -1
- package/dist/RaftUpdateManager.js.map +0 -1
- package/dist/RaftUtils.js.map +0 -1
- package/dist/RaftWifiTypes.js.map +0 -1
- package/dist/TestDataGen.d.ts +0 -7
- package/dist/TestDataGen.js +0 -133
- package/dist/TestDataGen.js.map +0 -1
- package/dist/main.js.map +0 -1
- package/src/TestDataGen.ts +0 -157
- /package/dist/{RaftAttributeHandler.d.ts → react-native/RaftAttributeHandler.d.ts} +0 -0
- /package/dist/{RaftChannel.d.ts → react-native/RaftChannel.d.ts} +0 -0
- /package/dist/{RaftChannel.js → react-native/RaftChannel.js} +0 -0
- /package/dist/{RaftChannelWebSerial.d.ts → react-native/RaftChannelWebSerial.d.ts} +0 -0
- /package/dist/{RaftChannelWebSocket.d.ts → react-native/RaftChannelWebSocket.d.ts} +0 -0
- /package/dist/{RaftChannelWebSocket.js → react-native/RaftChannelWebSocket.js} +0 -0
- /package/dist/{RaftCommsStats.d.ts → react-native/RaftCommsStats.d.ts} +0 -0
- /package/dist/{RaftCommsStats.js → react-native/RaftCommsStats.js} +0 -0
- /package/dist/{RaftCustomAttrHandler.d.ts → react-native/RaftCustomAttrHandler.d.ts} +0 -0
- /package/dist/{RaftCustomAttrHandler.js → react-native/RaftCustomAttrHandler.js} +0 -0
- /package/dist/{RaftDeviceInfo.js → react-native/RaftDeviceInfo.js} +0 -0
- /package/dist/{RaftDeviceMsg.d.ts → react-native/RaftDeviceMsg.d.ts} +0 -0
- /package/dist/{RaftDeviceMsg.js → react-native/RaftDeviceMsg.js} +0 -0
- /package/dist/{RaftDeviceStates.js → react-native/RaftDeviceStates.js} +0 -0
- /package/dist/{RaftFileHandler.d.ts → react-native/RaftFileHandler.d.ts} +0 -0
- /package/dist/{RaftFileHandler.js → react-native/RaftFileHandler.js} +0 -0
- /package/dist/{RaftLog.d.ts → react-native/RaftLog.d.ts} +0 -0
- /package/dist/{RaftLog.js → react-native/RaftLog.js} +0 -0
- /package/dist/{RaftMiniHDLC.d.ts → react-native/RaftMiniHDLC.d.ts} +0 -0
- /package/dist/{RaftMsgHandler.d.ts → react-native/RaftMsgHandler.d.ts} +0 -0
- /package/dist/{RaftMsgTrackInfo.d.ts → react-native/RaftMsgTrackInfo.d.ts} +0 -0
- /package/dist/{RaftMsgTrackInfo.js → react-native/RaftMsgTrackInfo.js} +0 -0
- /package/dist/{RaftProtocolDefs.d.ts → react-native/RaftProtocolDefs.d.ts} +0 -0
- /package/dist/{RaftProtocolDefs.js → react-native/RaftProtocolDefs.js} +0 -0
- /package/dist/{RaftStreamHandler.d.ts → react-native/RaftStreamHandler.d.ts} +0 -0
- /package/dist/{RaftStreamHandler.js → react-native/RaftStreamHandler.js} +0 -0
- /package/dist/{RaftSystemType.js → react-native/RaftSystemType.js} +0 -0
- /package/dist/{RaftSystemUtils.d.ts → react-native/RaftSystemUtils.d.ts} +0 -0
- /package/dist/{RaftSystemUtils.js → react-native/RaftSystemUtils.js} +0 -0
- /package/dist/{RaftUpdateEvents.d.ts → react-native/RaftUpdateEvents.d.ts} +0 -0
- /package/dist/{RaftUpdateEvents.js → react-native/RaftUpdateEvents.js} +0 -0
- /package/dist/{RaftUpdateManager.d.ts → react-native/RaftUpdateManager.d.ts} +0 -0
- /package/dist/{RaftUpdateManager.js → react-native/RaftUpdateManager.js} +0 -0
- /package/dist/{RaftUtils.d.ts → react-native/RaftUtils.d.ts} +0 -0
- /package/dist/{RaftWifiTypes.d.ts → react-native/RaftWifiTypes.d.ts} +0 -0
- /package/dist/{RaftWifiTypes.js → react-native/RaftWifiTypes.js} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
2
|
//
|
|
3
|
-
//
|
|
3
|
+
// RaftChannelBLE
|
|
4
4
|
// Part of RaftJS
|
|
5
5
|
//
|
|
6
6
|
// Rob Dobson & Chris Greening 2020-2024
|
|
@@ -15,9 +15,10 @@ import RaftMsgHandler from "./RaftMsgHandler";
|
|
|
15
15
|
import { ConnectorOptions } from "./RaftSystemType";
|
|
16
16
|
import RaftUtils from "./RaftUtils";
|
|
17
17
|
|
|
18
|
-
export default class
|
|
18
|
+
export default class RaftChannelBLE implements RaftChannel {
|
|
19
19
|
// BLE UUIDS
|
|
20
|
-
public static
|
|
20
|
+
public static RICServiceUUID = "aa76677e-9cfd-4626-a510-0d305be57c8d";
|
|
21
|
+
public static CogServiceUUID = "da903f65-d5c2-4f4d-a065-d1aade7af874";
|
|
21
22
|
public static CmdUUID = "aa76677e-9cfd-4626-a510-0d305be57c8e";
|
|
22
23
|
public static RespUUID = "aa76677e-9cfd-4626-a510-0d305be57c8f";
|
|
23
24
|
|
|
@@ -66,7 +67,10 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
66
67
|
|
|
67
68
|
// RICREST command before disconnect
|
|
68
69
|
ricRestCmdBeforeDisconnect(): string | null {
|
|
69
|
-
|
|
70
|
+
// NT: Sending blerestart *before* disconnecting results in timeout issues as the device is no longer connected when we try to actually disconnect
|
|
71
|
+
// suggested fix: allow callaback command to be sent after disconnect on the fw side
|
|
72
|
+
// return "blerestart";
|
|
73
|
+
return null;
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
// isEnabled
|
|
@@ -77,7 +81,7 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
77
81
|
} else {
|
|
78
82
|
window.alert(
|
|
79
83
|
"Web Bluetooth API is not available.\n" +
|
|
80
|
-
|
|
84
|
+
'Please make sure the "Experimental Web Platform features" flag is enabled.'
|
|
81
85
|
);
|
|
82
86
|
return false;
|
|
83
87
|
}
|
|
@@ -96,7 +100,7 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
96
100
|
// Disconnection event
|
|
97
101
|
onDisconnected(event: Event): void {
|
|
98
102
|
const device = event.target as BluetoothDevice;
|
|
99
|
-
RaftLog.debug(`
|
|
103
|
+
RaftLog.debug(`RaftChannelBLE.onDisconnected ${device.name}`);
|
|
100
104
|
if (this._bleDevice) {
|
|
101
105
|
this._bleDevice.removeEventListener(
|
|
102
106
|
"gattserverdisconnected",
|
|
@@ -126,9 +130,8 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
126
130
|
const connTimeoutMs = _connectorOptions.connTimeoutMs || 5000;
|
|
127
131
|
await RaftUtils.withTimeout(connTimeoutMs, this._bleDevice.gatt.connect());
|
|
128
132
|
RaftLog.debug(
|
|
129
|
-
`
|
|
130
|
-
|
|
131
|
-
} attempt ${connRetry+1} connection to device ${this._bleDevice.name}`
|
|
133
|
+
`RaftChannelBLE.connect - ${this._bleDevice.gatt.connected ? "OK" : "FAILED"
|
|
134
|
+
} attempt ${connRetry + 1} connection to device ${this._bleDevice.name}`
|
|
132
135
|
);
|
|
133
136
|
|
|
134
137
|
if (this._bleDevice.gatt.connected) {
|
|
@@ -138,52 +141,69 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
138
141
|
|
|
139
142
|
// Get service
|
|
140
143
|
try {
|
|
144
|
+
let service: BluetoothRemoteGATTService | null = null;
|
|
145
|
+
// iterate over known services
|
|
146
|
+
for (const serviceUUID of [RaftChannelBLE.CogServiceUUID, RaftChannelBLE.RICServiceUUID]) {
|
|
147
|
+
try {
|
|
148
|
+
service = await this._bleDevice.gatt.getPrimaryService(serviceUUID);
|
|
149
|
+
if (service) {
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
} catch (error) {
|
|
153
|
+
RaftLog.warn(
|
|
154
|
+
`RaftChannelBLE.connect - cannot get primary service ${error}`
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
141
158
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
159
|
+
if (!service) {
|
|
160
|
+
RaftLog.error(
|
|
161
|
+
`RaftChannelBLE.connect - cannot get primary service - giving up`
|
|
162
|
+
);
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
145
165
|
RaftLog.debug(
|
|
146
|
-
|
|
166
|
+
`RaftChannelBLE.connect - found service: ${service.uuid}`
|
|
147
167
|
);
|
|
148
168
|
|
|
149
169
|
try {
|
|
150
170
|
// Get Tx and Rx characteristics
|
|
151
171
|
this._characteristicTx = await service.getCharacteristic(
|
|
152
|
-
|
|
172
|
+
RaftChannelBLE.CmdUUID
|
|
153
173
|
);
|
|
154
174
|
RaftLog.debug(
|
|
155
|
-
`
|
|
175
|
+
`RaftChannelBLE.connect - found char ${this._characteristicTx.uuid}`
|
|
156
176
|
);
|
|
157
177
|
this._characteristicRx = await service.getCharacteristic(
|
|
158
|
-
|
|
178
|
+
RaftChannelBLE.RespUUID
|
|
159
179
|
);
|
|
160
180
|
RaftLog.debug(
|
|
161
|
-
|
|
181
|
+
`RaftChannelBLE.connect - found char ${this._characteristicRx.uuid}`
|
|
162
182
|
);
|
|
163
183
|
|
|
164
184
|
// Notifications of received messages
|
|
165
185
|
try {
|
|
166
186
|
await this._characteristicRx.startNotifications();
|
|
167
187
|
RaftLog.debug(
|
|
168
|
-
"
|
|
188
|
+
"RaftChannelBLE.connect - notifications started"
|
|
169
189
|
);
|
|
170
190
|
this._characteristicRx.addEventListener(
|
|
171
|
-
"characteristicvaluechanged",
|
|
191
|
+
"characteristicvaluechanged",
|
|
172
192
|
this._onMsgRx.bind(this)
|
|
173
193
|
);
|
|
174
194
|
} catch (error) {
|
|
175
195
|
RaftLog.debug(
|
|
176
|
-
"
|
|
196
|
+
"RaftChannelBLE.connnect - addEventListener failed " + error
|
|
177
197
|
);
|
|
178
198
|
}
|
|
179
199
|
|
|
180
200
|
// Connected ok
|
|
181
|
-
RaftLog.debug(`
|
|
201
|
+
RaftLog.debug(`RaftChannelBLE.connect ${this._bleDevice.name}`);
|
|
182
202
|
|
|
183
203
|
// Add disconnect listener
|
|
184
204
|
this._eventListenerFn = this.onDisconnected.bind(this);
|
|
185
205
|
this._bleDevice.addEventListener(
|
|
186
|
-
"gattserverdisconnected",
|
|
206
|
+
"gattserverdisconnected",
|
|
187
207
|
this._eventListenerFn
|
|
188
208
|
);
|
|
189
209
|
|
|
@@ -192,36 +212,36 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
192
212
|
return true;
|
|
193
213
|
} catch (error) {
|
|
194
214
|
RaftLog.error(
|
|
195
|
-
`
|
|
215
|
+
`RaftChannelBLE.connect - cannot find characteristic: ${error}`
|
|
196
216
|
);
|
|
197
217
|
}
|
|
198
218
|
} catch (error) {
|
|
199
219
|
if (connRetry === this._maxConnRetries - 1) {
|
|
200
220
|
RaftLog.error(
|
|
201
|
-
`
|
|
221
|
+
`RaftChannelBLE.connect - cannot get primary service ${error} - attempt #${connRetry + 1} - giving up`
|
|
202
222
|
);
|
|
203
223
|
} else {
|
|
204
224
|
RaftLog.debug(
|
|
205
|
-
|
|
225
|
+
`RaftChannelBLE.connect - cannot get primary service - attempt #${connRetry + 1} ${error}`
|
|
206
226
|
);
|
|
207
227
|
}
|
|
208
228
|
}
|
|
209
229
|
}
|
|
210
230
|
}
|
|
211
231
|
} catch (error: unknown) {
|
|
212
|
-
RaftLog.warn(`
|
|
232
|
+
RaftLog.warn(`RaftChannelBLE.connect - cannot connect ${error}`);
|
|
213
233
|
}
|
|
214
234
|
|
|
215
235
|
// Disconnect
|
|
216
236
|
if (
|
|
217
|
-
this._bleDevice &&
|
|
218
|
-
this._bleDevice.gatt &&
|
|
237
|
+
this._bleDevice &&
|
|
238
|
+
this._bleDevice.gatt &&
|
|
219
239
|
this._bleDevice.gatt.connected
|
|
220
240
|
) {
|
|
221
241
|
try {
|
|
222
242
|
await this._bleDevice.gatt.disconnect();
|
|
223
243
|
} catch (error) {
|
|
224
|
-
RaftLog.warn(`
|
|
244
|
+
RaftLog.warn(`RaftChannelBLE.connect - cannot disconnect ${error}`);
|
|
225
245
|
}
|
|
226
246
|
}
|
|
227
247
|
}
|
|
@@ -233,19 +253,19 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
233
253
|
async disconnect(): Promise<void> {
|
|
234
254
|
if (this._bleDevice && this._bleDevice.gatt) {
|
|
235
255
|
try {
|
|
236
|
-
RaftLog.debug(`
|
|
256
|
+
RaftLog.debug(`RaftChannelBLE.disconnect GATT`);
|
|
237
257
|
await this._bleDevice.gatt.disconnect();
|
|
238
258
|
} catch (error) {
|
|
239
|
-
RaftLog.debug(`
|
|
259
|
+
RaftLog.debug(`RaftChannelBLE.disconnect ${error}`);
|
|
240
260
|
}
|
|
241
261
|
}
|
|
242
262
|
}
|
|
243
263
|
|
|
244
|
-
pauseConnection(pause: boolean): void {
|
|
264
|
+
pauseConnection(pause: boolean): void {
|
|
245
265
|
RaftLog.verbose(
|
|
246
266
|
`pauseConnection ${pause} - no effect for this channel type`
|
|
247
|
-
);
|
|
248
|
-
return;
|
|
267
|
+
);
|
|
268
|
+
return;
|
|
249
269
|
}
|
|
250
270
|
|
|
251
271
|
// Handle notifications
|
|
@@ -263,7 +283,7 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
263
283
|
try {
|
|
264
284
|
this._raftMsgHandler.handleNewRxMsg(msg);
|
|
265
285
|
} catch (error) {
|
|
266
|
-
RaftLog.debug(`
|
|
286
|
+
RaftLog.debug(`RaftChannelBLE.onMsgRx ${error}`);
|
|
267
287
|
}
|
|
268
288
|
}
|
|
269
289
|
}
|
|
@@ -272,11 +292,11 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
272
292
|
// Send a message
|
|
273
293
|
async sendTxMsg(
|
|
274
294
|
msg: Uint8Array
|
|
275
|
-
// _sendWithResponse: boolean
|
|
295
|
+
// _sendWithResponse: boolean
|
|
276
296
|
): Promise<boolean> {
|
|
277
297
|
// Check valid
|
|
278
298
|
if (this._bleDevice === null) {
|
|
279
|
-
|
|
299
|
+
return false;
|
|
280
300
|
}
|
|
281
301
|
|
|
282
302
|
// Retry upto maxRetries
|
|
@@ -302,7 +322,7 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
302
322
|
} catch (error) {
|
|
303
323
|
if (retryIdx === this.maxRetries - 1) {
|
|
304
324
|
RaftLog.info(
|
|
305
|
-
`
|
|
325
|
+
`RaftChannelBLE.sendTxMsg ${error} retried ${retryIdx} times`
|
|
306
326
|
);
|
|
307
327
|
}
|
|
308
328
|
}
|
|
@@ -313,11 +333,11 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
313
333
|
// Send message without awaiting response
|
|
314
334
|
async sendTxMsgNoAwait(
|
|
315
335
|
msg: Uint8Array
|
|
316
|
-
// _sendWithResponse: boolean
|
|
336
|
+
// _sendWithResponse: boolean
|
|
317
337
|
): Promise<boolean> {
|
|
318
338
|
// Check valid
|
|
319
339
|
if (this._bleDevice === null) {
|
|
320
|
-
|
|
340
|
+
return false;
|
|
321
341
|
}
|
|
322
342
|
|
|
323
343
|
// Check for min time between messages
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* This file is used to create a new instance of the RaftChannelBLE class.
|
|
4
|
+
* RaftChannelBLE exists in 2 files: RaftChannelBLE.native.ts and RaftChannelBLE.web.ts
|
|
5
|
+
* each of these files contains the same class but with different implementations (native and web).
|
|
6
|
+
* The import statement at the top of the file will import the correct implementation based on the platform
|
|
7
|
+
* (depending on the build configuration).
|
|
8
|
+
*/
|
|
9
|
+
import RaftChannelBLE from './RaftChannelBLE';
|
|
10
|
+
|
|
11
|
+
export function createBLEChannel() {
|
|
12
|
+
return RaftChannelBLE;
|
|
13
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
//
|
|
3
|
+
// RICBLEScanner
|
|
4
|
+
// Communications Connector for RIC V2
|
|
5
|
+
//
|
|
6
|
+
// RIC V2
|
|
7
|
+
// Rob Dobson 2022
|
|
8
|
+
// (C) Robotical 2022
|
|
9
|
+
//
|
|
10
|
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
BleManager,
|
|
14
|
+
Device,
|
|
15
|
+
BleError,
|
|
16
|
+
} from 'react-native-ble-plx';
|
|
17
|
+
import { DiscoveredRIC } from './RaftTypes';
|
|
18
|
+
import RaftLog from './RaftLog';
|
|
19
|
+
import { RaftConnEvent, RaftConnEventFn } from './RaftConnEvents';
|
|
20
|
+
|
|
21
|
+
export default class RICBLEScanner {
|
|
22
|
+
|
|
23
|
+
// BleManager
|
|
24
|
+
_bleManager: BleManager;
|
|
25
|
+
|
|
26
|
+
// Services to scan for
|
|
27
|
+
_uuidsOfServicesToScanFor: Array<string> = [];
|
|
28
|
+
|
|
29
|
+
// Scanned devices found on BLE
|
|
30
|
+
_discoveredRICs: DiscoveredRIC[] = [];
|
|
31
|
+
static _scanInProgress = false;
|
|
32
|
+
|
|
33
|
+
// Time to scan for
|
|
34
|
+
_discoveryTimeMs = 10000;
|
|
35
|
+
|
|
36
|
+
// Event callback
|
|
37
|
+
_eventCallback: RaftConnEventFn;
|
|
38
|
+
|
|
39
|
+
constructor(bleManager: BleManager, uuidsOfServicesToScanFor: Array<string>, eventCallback: RaftConnEventFn) {
|
|
40
|
+
this._bleManager = bleManager;
|
|
41
|
+
this._uuidsOfServicesToScanFor = uuidsOfServicesToScanFor;
|
|
42
|
+
this._eventCallback = eventCallback;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Get discovered RICs
|
|
46
|
+
getDiscoveredRICs(): DiscoveredRIC[] {
|
|
47
|
+
return this._discoveredRICs;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Check is a scan is in progress
|
|
51
|
+
isScanInProgress(): boolean {
|
|
52
|
+
return RICBLEScanner._scanInProgress;
|
|
53
|
+
}
|
|
54
|
+
|
|
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
|
+
}
|
|
62
|
+
// Handle discovery
|
|
63
|
+
RaftLog.debug('Starting Scanning...');
|
|
64
|
+
|
|
65
|
+
// Clear list
|
|
66
|
+
this._discoveredRICs = [];
|
|
67
|
+
|
|
68
|
+
// Disconnect any connections
|
|
69
|
+
RICBLEScanner._scanInProgress = true;
|
|
70
|
+
|
|
71
|
+
// Start scan
|
|
72
|
+
try {
|
|
73
|
+
this._bleManager.startDeviceScan(
|
|
74
|
+
uuidsOfServicesToScanFor,
|
|
75
|
+
{ allowDuplicates: true },
|
|
76
|
+
(error: BleError | null, device: Device | null) => {
|
|
77
|
+
// RaftLog.debug(`discoveryFoundCB error ${error}`);
|
|
78
|
+
this._discoveryFoundCB(error, device);
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
} catch (e) {
|
|
82
|
+
RaftLog.warn(`Error starting scan ${e}`);
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Set a time limit
|
|
87
|
+
this._discoverySetTimeLimit(this._discoveryTimeMs);
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
scanningStop(): void {
|
|
92
|
+
|
|
93
|
+
RaftLog.debug('scanningStop');
|
|
94
|
+
|
|
95
|
+
// Emit finished if we were scanning
|
|
96
|
+
RaftLog.debug(`IS SCANNING IN PROGRESS: ${RICBLEScanner._scanInProgress}`);
|
|
97
|
+
if (RICBLEScanner._scanInProgress) {
|
|
98
|
+
RaftLog.debug(`sending BLE_SCANNING_FINISHED event`);
|
|
99
|
+
this._eventCallback(RaftConnEvent.BLE_SCANNING_FINISHED, { discoveredRICs: this._discoveredRICs });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Cancel scanning
|
|
103
|
+
this._bleManager.stopDeviceScan();
|
|
104
|
+
RICBLEScanner._scanInProgress = false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Callback from BLE-PLX library on device discovered
|
|
108
|
+
_discoveryFoundCB(
|
|
109
|
+
error: BleError | null,
|
|
110
|
+
scannedDevice: Device | null,
|
|
111
|
+
): void {
|
|
112
|
+
if (error) {
|
|
113
|
+
//RaftLog.warn(`⚠️ Scan Error >> ${error.toString()}`);
|
|
114
|
+
RaftLog.warn(`⚠️ Scan Error >> ${JSON.stringify(error)}`);
|
|
115
|
+
// Event if we were scanning
|
|
116
|
+
if (RICBLEScanner._scanInProgress) {
|
|
117
|
+
this._eventCallback(RaftConnEvent.BLE_SCANNING_FINISHED, {
|
|
118
|
+
discoveredRICs: this._discoveredRICs,
|
|
119
|
+
});
|
|
120
|
+
RICBLEScanner._scanInProgress = false;
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// See if already in the list
|
|
126
|
+
const ricAlreadyFound = this._discoveredRICs.find(
|
|
127
|
+
item => item.id === scannedDevice!.id,
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
RaftLog.debug(`✅ Scanning... >> ${scannedDevice}`);
|
|
131
|
+
|
|
132
|
+
if (ricAlreadyFound) {
|
|
133
|
+
// update the rssi value if it's not 127
|
|
134
|
+
if (scannedDevice!.rssi !== null && scannedDevice!.rssi !== 127) {
|
|
135
|
+
ricAlreadyFound._rssi = scannedDevice!.rssi;
|
|
136
|
+
this._eventCallback(RaftConnEvent.BLE_DEVICE_FOUND, {
|
|
137
|
+
discoveredRIC: ricAlreadyFound
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (scannedDevice !== null) {
|
|
144
|
+
if (!scannedDevice.localName) {
|
|
145
|
+
// if the name of the device is null, don't add this device
|
|
146
|
+
// the first time round. Second time this device comes up
|
|
147
|
+
// will have all the needed info
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const newDiscoveredRic = new DiscoveredRIC(
|
|
151
|
+
scannedDevice.localName !== null ? scannedDevice.localName : '',
|
|
152
|
+
scannedDevice.name !== null ? scannedDevice.name : '',
|
|
153
|
+
scannedDevice.id,
|
|
154
|
+
scannedDevice.rssi !== null ? scannedDevice.rssi : -150,
|
|
155
|
+
);
|
|
156
|
+
this._discoveredRICs.push(newDiscoveredRic);
|
|
157
|
+
// send the newly found ric to the state so it can pop-up on the front-end
|
|
158
|
+
this._eventCallback(RaftConnEvent.BLE_DEVICE_FOUND, {
|
|
159
|
+
discoveredRIC: newDiscoveredRic
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
RaftLog.debug(`🤖 Scanned RICs >> ${this._discoveredRICs}`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Time-limit on device scanning
|
|
166
|
+
_discoverySetTimeLimit(timeLimitMs: number) {
|
|
167
|
+
setTimeout(() => {
|
|
168
|
+
// Stop scanning
|
|
169
|
+
this._bleManager.stopDeviceScan();
|
|
170
|
+
|
|
171
|
+
// Check we were scanning
|
|
172
|
+
if (RICBLEScanner._scanInProgress) {
|
|
173
|
+
// Sort by signal strength
|
|
174
|
+
// this._discoveredRICs.sort((a, b) => {
|
|
175
|
+
// return b!.rssi! - a!.rssi!;
|
|
176
|
+
// });
|
|
177
|
+
|
|
178
|
+
// Debug
|
|
179
|
+
const msg = `🤖 ${this._discoveredRICs.length} RICs found! Choose one to connect`;
|
|
180
|
+
RaftLog.debug(msg);
|
|
181
|
+
|
|
182
|
+
// Finished event
|
|
183
|
+
this._eventCallback(RaftConnEvent.BLE_SCANNING_FINISHED, {
|
|
184
|
+
discoveredRICs: this._discoveredRICs,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
RICBLEScanner._scanInProgress = false;
|
|
188
|
+
}, timeLimitMs);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -13,6 +13,7 @@ import RaftMsgHandler from "./RaftMsgHandler";
|
|
|
13
13
|
import RaftLog from "./RaftLog";
|
|
14
14
|
import { RaftConnEvent, RaftConnEventFn } from "./RaftConnEvents";
|
|
15
15
|
import { ConnectorOptions } from "./RaftSystemType";
|
|
16
|
+
import { TextDecoder } from 'text-encoding';
|
|
16
17
|
|
|
17
18
|
type TWebParityType = 'none' | 'even' | 'odd';
|
|
18
19
|
type TWebFlowControlType = 'none' | 'hardware';
|
package/src/RaftConnEvents.ts
CHANGED
|
@@ -21,7 +21,13 @@ export enum RaftConnEvent {
|
|
|
21
21
|
CONN_GETTING_INFO,
|
|
22
22
|
CONN_GOT_INFO,
|
|
23
23
|
CONN_BLUETOOTH_STATE,
|
|
24
|
-
CONN_STREAMING_ISSUE
|
|
24
|
+
CONN_STREAMING_ISSUE,
|
|
25
|
+
|
|
26
|
+
// PHONE_BLE_ONLY
|
|
27
|
+
BLE_SCANNING_STARTED,
|
|
28
|
+
BLE_DEVICE_FOUND,
|
|
29
|
+
BLE_SCANNING_FINISHED,
|
|
30
|
+
BLE_BLUETOOTH_STATE,
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
export const RaftConnEventNames = {
|
|
@@ -38,9 +44,15 @@ export const RaftConnEventNames = {
|
|
|
38
44
|
[RaftConnEvent.CONN_GOT_INFO]: 'GOT_INFO',
|
|
39
45
|
[RaftConnEvent.CONN_BLUETOOTH_STATE]: 'BLUETOOTH_STATE',
|
|
40
46
|
[RaftConnEvent.CONN_STREAMING_ISSUE]: 'STREAMING_ISSUE',
|
|
47
|
+
|
|
48
|
+
// PHONE_BLE_ONLY
|
|
49
|
+
[RaftConnEvent.BLE_SCANNING_STARTED]: 'BLE_SCANNING_STARTED',
|
|
50
|
+
[RaftConnEvent.BLE_DEVICE_FOUND]: 'BLE_DEVICE_FOUND',
|
|
51
|
+
[RaftConnEvent.BLE_SCANNING_FINISHED]: 'BLE_SCANNING_FINISHED',
|
|
52
|
+
[RaftConnEvent.BLE_BLUETOOTH_STATE]: 'BLE_BLUETOOTH_STATE',
|
|
41
53
|
};
|
|
42
54
|
|
|
43
55
|
export type RaftConnEventFn = (
|
|
44
56
|
eventType: RaftConnEvent,
|
|
45
|
-
data?: string[] | string | null,
|
|
57
|
+
data?: any | string[] | string | null,
|
|
46
58
|
) => void;
|