@robdobsn/raftjs 1.1.1 → 1.3.1
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/react-native/RaftAttributeHandler.js.map +1 -0
- package/dist/react-native/RaftChannel.js.map +1 -0
- package/dist/react-native/RaftChannelBLE.native.d.ts +95 -0
- package/dist/react-native/RaftChannelBLE.native.js +458 -0
- package/dist/react-native/RaftChannelBLE.native.js.map +1 -0
- package/dist/{RaftChannelWebBLE.d.ts → react-native/RaftChannelBLE.web.d.ts} +1 -1
- package/dist/{RaftChannelWebBLE.js → react-native/RaftChannelBLE.web.js} +31 -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 +139 -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} +112 -210
- 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} +3 -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 +38 -0
- package/dist/web/RaftChannelBLE.web.js +277 -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 +352 -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 +24 -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 +2 -2
- 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 +137 -119
- package/examples/dashboard/src/SystemTypeCog/SystemTypeCog.ts +15 -8
- package/examples/dashboard/src/SystemTypeMarty/RICStateInfo.ts +47 -1
- package/examples/dashboard/src/SystemTypeMarty/SystemTypeMarty.ts +4 -1
- package/examples/dashboard/src/styles.css +262 -9
- package/package.json +57 -48
- package/src/RaftChannelBLE.native.ts +586 -0
- package/src/{RaftChannelWebBLE.ts → RaftChannelBLE.web.ts} +26 -23
- package/src/RaftChannelBLEFactory.ts +13 -0
- package/src/RaftChannelBLEScanner.native.ts +185 -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 +138 -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 +3 -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/{RaftAttributeHandler.js → react-native/RaftAttributeHandler.js} +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,7 +15,7 @@ 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
20
|
public static ServiceUUID = "aa76677e-9cfd-4626-a510-0d305be57c8d";
|
|
21
21
|
public static CmdUUID = "aa76677e-9cfd-4626-a510-0d305be57c8e";
|
|
@@ -66,7 +66,10 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
66
66
|
|
|
67
67
|
// RICREST command before disconnect
|
|
68
68
|
ricRestCmdBeforeDisconnect(): string | null {
|
|
69
|
-
|
|
69
|
+
// NT: Sending blerestart *before* disconnecting results in timeout issues as the device is no longer connected when we try to actually disconnect
|
|
70
|
+
// suggested fix: allow callaback command to be sent after disconnect on the fw side
|
|
71
|
+
// return "blerestart";
|
|
72
|
+
return null;
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
// isEnabled
|
|
@@ -96,7 +99,7 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
96
99
|
// Disconnection event
|
|
97
100
|
onDisconnected(event: Event): void {
|
|
98
101
|
const device = event.target as BluetoothDevice;
|
|
99
|
-
RaftLog.debug(`
|
|
102
|
+
RaftLog.debug(`RaftChannelBLE.onDisconnected ${device.name}`);
|
|
100
103
|
if (this._bleDevice) {
|
|
101
104
|
this._bleDevice.removeEventListener(
|
|
102
105
|
"gattserverdisconnected",
|
|
@@ -126,7 +129,7 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
126
129
|
const connTimeoutMs = _connectorOptions.connTimeoutMs || 5000;
|
|
127
130
|
await RaftUtils.withTimeout(connTimeoutMs, this._bleDevice.gatt.connect());
|
|
128
131
|
RaftLog.debug(
|
|
129
|
-
`
|
|
132
|
+
`RaftChannelBLE.connect - ${
|
|
130
133
|
this._bleDevice.gatt.connected ? "OK" : "FAILED"
|
|
131
134
|
} attempt ${connRetry+1} connection to device ${this._bleDevice.name}`
|
|
132
135
|
);
|
|
@@ -140,32 +143,32 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
140
143
|
try {
|
|
141
144
|
|
|
142
145
|
const service = await this._bleDevice.gatt.getPrimaryService(
|
|
143
|
-
|
|
146
|
+
RaftChannelBLE.ServiceUUID
|
|
144
147
|
);
|
|
145
148
|
RaftLog.debug(
|
|
146
|
-
`
|
|
149
|
+
`RaftChannelBLE.connect - found service: ${service.uuid}`
|
|
147
150
|
);
|
|
148
151
|
|
|
149
152
|
try {
|
|
150
153
|
// Get Tx and Rx characteristics
|
|
151
154
|
this._characteristicTx = await service.getCharacteristic(
|
|
152
|
-
|
|
155
|
+
RaftChannelBLE.CmdUUID
|
|
153
156
|
);
|
|
154
157
|
RaftLog.debug(
|
|
155
|
-
`
|
|
158
|
+
`RaftChannelBLE.connect - found char ${this._characteristicTx.uuid}`
|
|
156
159
|
);
|
|
157
160
|
this._characteristicRx = await service.getCharacteristic(
|
|
158
|
-
|
|
161
|
+
RaftChannelBLE.RespUUID
|
|
159
162
|
);
|
|
160
163
|
RaftLog.debug(
|
|
161
|
-
`
|
|
164
|
+
`RaftChannelBLE.connect - found char ${this._characteristicRx.uuid}`
|
|
162
165
|
);
|
|
163
166
|
|
|
164
167
|
// Notifications of received messages
|
|
165
168
|
try {
|
|
166
169
|
await this._characteristicRx.startNotifications();
|
|
167
170
|
RaftLog.debug(
|
|
168
|
-
"
|
|
171
|
+
"RaftChannelBLE.connect - notifications started"
|
|
169
172
|
);
|
|
170
173
|
this._characteristicRx.addEventListener(
|
|
171
174
|
"characteristicvaluechanged",
|
|
@@ -173,12 +176,12 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
173
176
|
);
|
|
174
177
|
} catch (error) {
|
|
175
178
|
RaftLog.debug(
|
|
176
|
-
"
|
|
179
|
+
"RaftChannelBLE.connnect - addEventListener failed " + error
|
|
177
180
|
);
|
|
178
181
|
}
|
|
179
182
|
|
|
180
183
|
// Connected ok
|
|
181
|
-
RaftLog.debug(`
|
|
184
|
+
RaftLog.debug(`RaftChannelBLE.connect ${this._bleDevice.name}`);
|
|
182
185
|
|
|
183
186
|
// Add disconnect listener
|
|
184
187
|
this._eventListenerFn = this.onDisconnected.bind(this);
|
|
@@ -192,24 +195,24 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
192
195
|
return true;
|
|
193
196
|
} catch (error) {
|
|
194
197
|
RaftLog.error(
|
|
195
|
-
`
|
|
198
|
+
`RaftChannelBLE.connect - cannot find characteristic: ${error}`
|
|
196
199
|
);
|
|
197
200
|
}
|
|
198
201
|
} catch (error) {
|
|
199
202
|
if (connRetry === this._maxConnRetries - 1) {
|
|
200
203
|
RaftLog.error(
|
|
201
|
-
`
|
|
204
|
+
`RaftChannelBLE.connect - cannot get primary service ${error} - attempt #${connRetry+1} - giving up`
|
|
202
205
|
);
|
|
203
206
|
} else {
|
|
204
207
|
RaftLog.debug(
|
|
205
|
-
`
|
|
208
|
+
`RaftChannelBLE.connect - cannot get primary service - attempt #${connRetry+1} ${error}`
|
|
206
209
|
);
|
|
207
210
|
}
|
|
208
211
|
}
|
|
209
212
|
}
|
|
210
213
|
}
|
|
211
214
|
} catch (error: unknown) {
|
|
212
|
-
RaftLog.warn(`
|
|
215
|
+
RaftLog.warn(`RaftChannelBLE.connect - cannot connect ${error}`);
|
|
213
216
|
}
|
|
214
217
|
|
|
215
218
|
// Disconnect
|
|
@@ -221,7 +224,7 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
221
224
|
try {
|
|
222
225
|
await this._bleDevice.gatt.disconnect();
|
|
223
226
|
} catch (error) {
|
|
224
|
-
RaftLog.warn(`
|
|
227
|
+
RaftLog.warn(`RaftChannelBLE.connect - cannot disconnect ${error}`);
|
|
225
228
|
}
|
|
226
229
|
}
|
|
227
230
|
}
|
|
@@ -233,10 +236,10 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
233
236
|
async disconnect(): Promise<void> {
|
|
234
237
|
if (this._bleDevice && this._bleDevice.gatt) {
|
|
235
238
|
try {
|
|
236
|
-
RaftLog.debug(`
|
|
239
|
+
RaftLog.debug(`RaftChannelBLE.disconnect GATT`);
|
|
237
240
|
await this._bleDevice.gatt.disconnect();
|
|
238
241
|
} catch (error) {
|
|
239
|
-
RaftLog.debug(`
|
|
242
|
+
RaftLog.debug(`RaftChannelBLE.disconnect ${error}`);
|
|
240
243
|
}
|
|
241
244
|
}
|
|
242
245
|
}
|
|
@@ -263,7 +266,7 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
263
266
|
try {
|
|
264
267
|
this._raftMsgHandler.handleNewRxMsg(msg);
|
|
265
268
|
} catch (error) {
|
|
266
|
-
RaftLog.debug(`
|
|
269
|
+
RaftLog.debug(`RaftChannelBLE.onMsgRx ${error}`);
|
|
267
270
|
}
|
|
268
271
|
}
|
|
269
272
|
}
|
|
@@ -302,7 +305,7 @@ export default class RaftChannelWebBLE implements RaftChannel {
|
|
|
302
305
|
} catch (error) {
|
|
303
306
|
if (retryIdx === this.maxRetries - 1) {
|
|
304
307
|
RaftLog.info(
|
|
305
|
-
`
|
|
308
|
+
`RaftChannelBLE.sendTxMsg ${error} retried ${retryIdx} times`
|
|
306
309
|
);
|
|
307
310
|
}
|
|
308
311
|
}
|
|
@@ -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,185 @@
|
|
|
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(): Promise<boolean> {
|
|
56
|
+
|
|
57
|
+
// Handle discovery
|
|
58
|
+
RaftLog.debug('Starting Scanning...');
|
|
59
|
+
|
|
60
|
+
// Clear list
|
|
61
|
+
this._discoveredRICs = [];
|
|
62
|
+
|
|
63
|
+
// Disconnect any connections
|
|
64
|
+
RICBLEScanner._scanInProgress = true;
|
|
65
|
+
|
|
66
|
+
// Start scan
|
|
67
|
+
try {
|
|
68
|
+
this._bleManager.startDeviceScan(
|
|
69
|
+
this._uuidsOfServicesToScanFor,
|
|
70
|
+
{ allowDuplicates: true },
|
|
71
|
+
(error: BleError | null, device: Device | null) => {
|
|
72
|
+
// RaftLog.debug(`discoveryFoundCB error ${error}`);
|
|
73
|
+
this._discoveryFoundCB(error, device);
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
RaftLog.warn(`Error starting scan ${e}`);
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Set a time limit
|
|
82
|
+
this._discoverySetTimeLimit(this._discoveryTimeMs);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
scanningStop(): void {
|
|
87
|
+
|
|
88
|
+
RaftLog.debug('scanningStop');
|
|
89
|
+
|
|
90
|
+
// Emit finished if we were scanning
|
|
91
|
+
RaftLog.debug(`IS SCANNING IN PROGRESS: ${RICBLEScanner._scanInProgress}`);
|
|
92
|
+
if (RICBLEScanner._scanInProgress) {
|
|
93
|
+
RaftLog.debug(`sending BLE_SCANNING_FINISHED event`);
|
|
94
|
+
this._eventCallback(RaftConnEvent.BLE_SCANNING_FINISHED, { discoveredRICs: this._discoveredRICs });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Cancel scanning
|
|
98
|
+
this._bleManager.stopDeviceScan();
|
|
99
|
+
RICBLEScanner._scanInProgress = false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Callback from BLE-PLX library on device discovered
|
|
103
|
+
_discoveryFoundCB(
|
|
104
|
+
error: BleError | null,
|
|
105
|
+
scannedDevice: Device | null,
|
|
106
|
+
): void {
|
|
107
|
+
if (error) {
|
|
108
|
+
//RaftLog.warn(`⚠️ Scan Error >> ${error.toString()}`);
|
|
109
|
+
RaftLog.warn(`⚠️ Scan Error >> ${JSON.stringify(error)}`);
|
|
110
|
+
// Event if we were scanning
|
|
111
|
+
if (RICBLEScanner._scanInProgress) {
|
|
112
|
+
this._eventCallback(RaftConnEvent.BLE_SCANNING_FINISHED, {
|
|
113
|
+
discoveredRICs: this._discoveredRICs,
|
|
114
|
+
});
|
|
115
|
+
RICBLEScanner._scanInProgress = false;
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// See if already in the list
|
|
121
|
+
const ricAlreadyFound = this._discoveredRICs.find(
|
|
122
|
+
item => item.id === scannedDevice!.id,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
RaftLog.debug(`✅ Scanning... >> ${scannedDevice}`);
|
|
126
|
+
|
|
127
|
+
if (ricAlreadyFound) {
|
|
128
|
+
// update the rssi value if it's not 127
|
|
129
|
+
if (scannedDevice!.rssi !== null && scannedDevice!.rssi !== 127) {
|
|
130
|
+
ricAlreadyFound._rssi = scannedDevice!.rssi;
|
|
131
|
+
this._eventCallback(RaftConnEvent.BLE_DEVICE_FOUND, {
|
|
132
|
+
discoveredRIC: ricAlreadyFound
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (scannedDevice !== null) {
|
|
139
|
+
if (!scannedDevice.localName) {
|
|
140
|
+
// if the name of the device is null, don't add this device
|
|
141
|
+
// the first time round. Second time this device comes up
|
|
142
|
+
// will have all the needed info
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const newDiscoveredRic = new DiscoveredRIC(
|
|
146
|
+
scannedDevice.localName !== null ? scannedDevice.localName : '',
|
|
147
|
+
scannedDevice.name !== null ? scannedDevice.name : '',
|
|
148
|
+
scannedDevice.id,
|
|
149
|
+
scannedDevice.rssi !== null ? scannedDevice.rssi : -150,
|
|
150
|
+
);
|
|
151
|
+
this._discoveredRICs.push(newDiscoveredRic);
|
|
152
|
+
// send the newly found ric to the state so it can pop-up on the front-end
|
|
153
|
+
this._eventCallback(RaftConnEvent.BLE_DEVICE_FOUND, {
|
|
154
|
+
discoveredRIC: newDiscoveredRic
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
RaftLog.debug(`🤖 Scanned RICs >> ${this._discoveredRICs}`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Time-limit on device scanning
|
|
161
|
+
_discoverySetTimeLimit(timeLimitMs: number) {
|
|
162
|
+
setTimeout(() => {
|
|
163
|
+
// Stop scanning
|
|
164
|
+
this._bleManager.stopDeviceScan();
|
|
165
|
+
|
|
166
|
+
// Check we were scanning
|
|
167
|
+
if (RICBLEScanner._scanInProgress) {
|
|
168
|
+
// Sort by signal strength
|
|
169
|
+
// this._discoveredRICs.sort((a, b) => {
|
|
170
|
+
// return b!.rssi! - a!.rssi!;
|
|
171
|
+
// });
|
|
172
|
+
|
|
173
|
+
// Debug
|
|
174
|
+
const msg = `🤖 ${this._discoveredRICs.length} RICs found! Choose one to connect`;
|
|
175
|
+
RaftLog.debug(msg);
|
|
176
|
+
|
|
177
|
+
// Finished event
|
|
178
|
+
this._eventCallback(RaftConnEvent.BLE_SCANNING_FINISHED, {
|
|
179
|
+
discoveredRICs: this._discoveredRICs,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
RICBLEScanner._scanInProgress = false;
|
|
183
|
+
}, timeLimitMs);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -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;
|
package/src/RaftConnector.ts
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
10
10
|
|
|
11
11
|
import RaftChannel from "./RaftChannel";
|
|
12
|
-
import RaftChannelWebBLE from "./RaftChannelWebBLE";
|
|
13
12
|
import RaftMsgHandler, { RaftMsgResultCode } from "./RaftMsgHandler";
|
|
14
13
|
import RaftChannelWebSocket from "./RaftChannelWebSocket";
|
|
15
14
|
import RaftChannelWebSerial from "./RaftChannelWebSerial";
|
|
@@ -23,6 +22,8 @@ import { RaftConnEvent, RaftConnEventNames } from "./RaftConnEvents";
|
|
|
23
22
|
import { RaftGetSystemTypeCBType, RaftSystemType } from "./RaftSystemType";
|
|
24
23
|
import { RaftUpdateEvent, RaftUpdateEventNames } from "./RaftUpdateEvents";
|
|
25
24
|
import RaftUpdateManager from "./RaftUpdateManager";
|
|
25
|
+
import { createBLEChannel } from "./RaftChannelBLEFactory";
|
|
26
|
+
|
|
26
27
|
|
|
27
28
|
export default class RaftConnector {
|
|
28
29
|
|
|
@@ -155,10 +156,10 @@ export default class RaftConnector {
|
|
|
155
156
|
return this._channelConnMethod;
|
|
156
157
|
}
|
|
157
158
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Get connection locator
|
|
161
|
+
* @returns string | object - connection locator
|
|
162
|
+
* */
|
|
162
163
|
getConnLocator(): any | null {
|
|
163
164
|
return this._raftChannel ? this._raftChannel.getConnectedLocator() : null;
|
|
164
165
|
}
|
|
@@ -204,51 +205,27 @@ export default class RaftConnector {
|
|
|
204
205
|
}
|
|
205
206
|
|
|
206
207
|
/**
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
* @param {string} method - can be "WebBLE", "WebSocket" or "WebSerial"
|
|
210
|
-
* @param {string | object} locator - either a string (WebSocket URL or serial port) or an object (WebBLE)
|
|
211
|
-
* @returns Promise<boolean>
|
|
212
|
-
*
|
|
208
|
+
* Initialize the Raft channel
|
|
213
209
|
*/
|
|
214
|
-
async
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
// Ignore
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// Check connection method
|
|
225
|
-
let connMethod = "";
|
|
226
|
-
if (method === 'WebBLE' && typeof locator === 'object' && locator !== null) {
|
|
227
|
-
|
|
228
|
-
// Create channel
|
|
229
|
-
this._raftChannel = new RaftChannelWebBLE();
|
|
230
|
-
connMethod = 'WebBLE';
|
|
231
|
-
|
|
232
|
-
} else if (((method === 'WebSocket') || (method === 'wifi')) && (typeof locator === 'string')) {
|
|
233
|
-
|
|
234
|
-
// Create channel
|
|
210
|
+
async initializeChannel(method: string): Promise<boolean> {
|
|
211
|
+
// Initialize raft channel
|
|
212
|
+
if (method === 'WebBLE' || method === 'PhoneBLE') {
|
|
213
|
+
const RaftChannelBLE = createBLEChannel();
|
|
214
|
+
this._raftChannel = new RaftChannelBLE();
|
|
215
|
+
this._channelConnMethod = method;
|
|
216
|
+
} else if (method === 'WebSocket' || method === 'wifi') {
|
|
235
217
|
this._raftChannel = new RaftChannelWebSocket();
|
|
236
|
-
|
|
237
|
-
} else if (
|
|
218
|
+
this._channelConnMethod = 'WebSocket';
|
|
219
|
+
} else if (method === 'WebSerial') {
|
|
238
220
|
this._raftChannel = new RaftChannelWebSerial();
|
|
239
|
-
|
|
221
|
+
this._channelConnMethod = 'WebSerial';
|
|
222
|
+
} else {
|
|
223
|
+
RaftLog.error('Unknown method: ' + method);
|
|
224
|
+
return false;
|
|
240
225
|
}
|
|
241
226
|
|
|
242
|
-
RaftLog.debug(`connecting with connMethod ${connMethod}`);
|
|
243
|
-
|
|
244
227
|
// Check channel established
|
|
245
|
-
let connOk = false;
|
|
246
228
|
if (this._raftChannel !== null) {
|
|
247
|
-
|
|
248
|
-
// Connection method and locator
|
|
249
|
-
this._channelConnMethod = connMethod;
|
|
250
|
-
this._channelConnLocator = locator;
|
|
251
|
-
|
|
252
229
|
// Set message handler
|
|
253
230
|
this._raftChannel.setMsgHandler(this._raftMsgHandler);
|
|
254
231
|
this._raftChannel.setOnConnEvent(this.onConnEvent.bind(this));
|
|
@@ -257,62 +234,79 @@ export default class RaftConnector {
|
|
|
257
234
|
this._raftMsgHandler.registerForResults(this);
|
|
258
235
|
this._raftMsgHandler.registerMsgSender(this._raftChannel);
|
|
259
236
|
|
|
260
|
-
|
|
261
|
-
|
|
237
|
+
return true;
|
|
238
|
+
} else {
|
|
239
|
+
this._channelConnMethod = "";
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Connect to a Raft device
|
|
246
|
+
*
|
|
247
|
+
* @param {string | object} locator - either a string (WebSocket URL or serial port) or an object (WebBLE)
|
|
248
|
+
* @returns Promise<boolean>
|
|
249
|
+
*
|
|
250
|
+
*/
|
|
251
|
+
async connect(locator: string | object): Promise<boolean> {
|
|
252
|
+
if (!this._raftChannel) {
|
|
253
|
+
RaftLog.error('Raft channel is not initialized.');
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
262
256
|
|
|
263
|
-
|
|
264
|
-
|
|
257
|
+
// Store locator
|
|
258
|
+
this._channelConnLocator = locator;
|
|
265
259
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
260
|
+
// Connect
|
|
261
|
+
let connOk = false;
|
|
262
|
+
try {
|
|
263
|
+
// Event
|
|
264
|
+
this.onConnEvent(RaftConnEvent.CONN_CONNECTING);
|
|
271
265
|
|
|
272
|
-
//
|
|
273
|
-
|
|
266
|
+
// Connect
|
|
267
|
+
connOk = await this._connectToChannel();
|
|
268
|
+
} catch (err) {
|
|
269
|
+
RaftLog.error('RaftConnector.connect - error: ' + err);
|
|
270
|
+
}
|
|
274
271
|
|
|
272
|
+
if (connOk) {
|
|
273
|
+
// Get system type
|
|
274
|
+
if (this._getSystemTypeCB) {
|
|
275
275
|
// Get system type
|
|
276
|
-
|
|
277
|
-
// Get system type
|
|
278
|
-
this._systemType = await this._getSystemTypeCB(this._raftSystemUtils);
|
|
276
|
+
this._systemType = await this._getSystemTypeCB(this._raftSystemUtils);
|
|
279
277
|
|
|
280
|
-
|
|
281
|
-
if (this._systemType) {
|
|
282
|
-
this._raftSystemUtils.setDefaultWiFiHostname(this._systemType.defaultWiFiHostname);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// Setup system type
|
|
278
|
+
// Set defaults
|
|
287
279
|
if (this._systemType) {
|
|
288
|
-
this.
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// Check if subscription required
|
|
292
|
-
if (this._systemType &&
|
|
293
|
-
this._systemType.subscribeForUpdates &&
|
|
294
|
-
this._raftChannel.requiresSubscription()) {
|
|
295
|
-
try {
|
|
296
|
-
// Subscription
|
|
297
|
-
await this._systemType.subscribeForUpdates(this._raftSystemUtils, true);
|
|
298
|
-
RaftLog.info(`connect subscribed for updates`);
|
|
299
|
-
} catch (error: unknown) {
|
|
300
|
-
RaftLog.warn(`connect subscribe for updates failed ${error}`)
|
|
301
|
-
}
|
|
280
|
+
this._raftSystemUtils.setDefaultWiFiHostname(this._systemType.defaultWiFiHostname);
|
|
302
281
|
}
|
|
282
|
+
}
|
|
303
283
|
|
|
304
|
-
|
|
305
|
-
|
|
284
|
+
// Setup system type
|
|
285
|
+
if (this._systemType) {
|
|
286
|
+
this._systemType.setup(this._raftSystemUtils, this._onEventFn);
|
|
287
|
+
}
|
|
306
288
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
this.
|
|
289
|
+
// Check if subscription required
|
|
290
|
+
if (this._systemType &&
|
|
291
|
+
this._systemType.subscribeForUpdates &&
|
|
292
|
+
this._raftChannel.requiresSubscription()) {
|
|
293
|
+
try {
|
|
294
|
+
// Subscription
|
|
295
|
+
await this._systemType.subscribeForUpdates(this._raftSystemUtils, true);
|
|
296
|
+
RaftLog.info(`connect subscribed for updates`);
|
|
297
|
+
} catch (error: unknown) {
|
|
298
|
+
RaftLog.warn(`connect subscribe for updates failed ${error}`)
|
|
299
|
+
}
|
|
310
300
|
}
|
|
311
301
|
|
|
302
|
+
// Send connected event
|
|
303
|
+
this.onConnEvent(RaftConnEvent.CONN_CONNECTED);
|
|
304
|
+
|
|
305
|
+
} else {
|
|
306
|
+
// Failed Event
|
|
307
|
+
this.onConnEvent(RaftConnEvent.CONN_CONNECTION_FAILED);
|
|
312
308
|
// configure file handler
|
|
313
309
|
this.configureFileHandler(this._raftChannel.fhFileBlockSize(), this._raftChannel.fhBatchAckSize());
|
|
314
|
-
} else {
|
|
315
|
-
this._channelConnMethod = "";
|
|
316
310
|
}
|
|
317
311
|
|
|
318
312
|
return connOk;
|
|
@@ -565,7 +559,6 @@ export default class RaftConnector {
|
|
|
565
559
|
* @returns void
|
|
566
560
|
*/
|
|
567
561
|
onConnEvent(eventEnum: RaftConnEvent, data: object | string | null | undefined = undefined): void {
|
|
568
|
-
|
|
569
562
|
// Handle information clearing on disconnect
|
|
570
563
|
switch (eventEnum) {
|
|
571
564
|
case RaftConnEvent.CONN_DISCONNECTED:
|
|
@@ -598,7 +591,6 @@ export default class RaftConnector {
|
|
|
598
591
|
}
|
|
599
592
|
break;
|
|
600
593
|
}
|
|
601
|
-
|
|
602
594
|
// Notify
|
|
603
595
|
if (this._onEventFn) {
|
|
604
596
|
this._onEventFn("conn", eventEnum, RaftConnEventNames[eventEnum], data);
|
|
@@ -741,5 +733,5 @@ export default class RaftConnector {
|
|
|
741
733
|
firmwareBaseURL,
|
|
742
734
|
this._raftChannel
|
|
743
735
|
);
|
|
744
|
-
}
|
|
736
|
+
}
|
|
745
737
|
}
|
package/src/RaftDeviceInfo.ts
CHANGED
|
@@ -90,15 +90,9 @@ export interface DeviceTypeInfoRecs {
|
|
|
90
90
|
[devType: string]: DeviceTypeInfo;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
export
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
[devType: string]: DeviceTypeInfoTestJsonRec;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface DeviceTypeInfoTestJsonFile {
|
|
103
|
-
devTypes: DeviceTypeInfoTestJsonElem;
|
|
104
|
-
}
|
|
93
|
+
export type RaftDevTypeInfoResponse = {
|
|
94
|
+
req: string;
|
|
95
|
+
rslt: string;
|
|
96
|
+
devinfo: DeviceTypeInfo;
|
|
97
|
+
};
|
|
98
|
+
|