@robotical/raftjs 1.4.7 → 2.0.3
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 +2 -0
- package/dist/react-native/RaftAttributeHandler.js +136 -10
- package/dist/react-native/RaftAttributeHandler.js.map +1 -1
- package/dist/react-native/RaftChannel.d.ts +2 -0
- package/dist/react-native/RaftChannelBLE.native.d.ts +2 -0
- package/dist/react-native/RaftChannelBLE.native.js +14 -7
- package/dist/react-native/RaftChannelBLE.native.js.map +1 -1
- package/dist/react-native/RaftChannelBLE.web.d.ts +2 -0
- package/dist/react-native/RaftChannelBLE.web.js +24 -15
- package/dist/react-native/RaftChannelBLE.web.js.map +1 -1
- package/dist/react-native/RaftChannelSimulated.d.ts +32 -0
- package/dist/react-native/RaftChannelSimulated.js +418 -0
- package/dist/react-native/RaftChannelSimulated.js.map +1 -0
- package/dist/react-native/RaftChannelWebSerial.d.ts +2 -0
- package/dist/react-native/RaftChannelWebSerial.js +18 -9
- package/dist/react-native/RaftChannelWebSerial.js.map +1 -1
- package/dist/react-native/RaftChannelWebSocket.d.ts +2 -0
- package/dist/react-native/RaftChannelWebSocket.js +10 -0
- package/dist/react-native/RaftChannelWebSocket.js.map +1 -1
- package/dist/react-native/RaftConnector.js +13 -6
- package/dist/react-native/RaftConnector.js.map +1 -1
- package/dist/react-native/RaftCustomAttrHandler.js +15 -0
- package/dist/react-native/RaftCustomAttrHandler.js.map +1 -1
- package/dist/react-native/RaftDeviceInfo.d.ts +8 -1
- package/dist/react-native/RaftDeviceManager.d.ts +3 -0
- package/dist/react-native/RaftDeviceManager.js +123 -43
- package/dist/react-native/RaftDeviceManager.js.map +1 -1
- package/dist/react-native/RaftFileHandler.js +8 -8
- package/dist/react-native/RaftFileHandler.js.map +1 -1
- package/dist/react-native/RaftLog.js +1 -1
- package/dist/react-native/RaftLog.js.map +1 -1
- package/dist/react-native/RaftMsgHandler.d.ts +5 -0
- package/dist/react-native/RaftMsgHandler.js +32 -0
- package/dist/react-native/RaftMsgHandler.js.map +1 -1
- package/dist/react-native/RaftStreamHandler.js +6 -5
- package/dist/react-native/RaftStreamHandler.js.map +1 -1
- package/dist/react-native/RaftStruct.js +1 -1
- package/dist/react-native/RaftStruct.js.map +1 -1
- package/dist/react-native/RaftSysTypeManager.d.ts +2 -0
- package/dist/react-native/RaftSysTypeManager.js +25 -0
- package/dist/react-native/RaftSysTypeManager.js.map +1 -1
- package/dist/react-native/RaftSystemType.d.ts +9 -7
- package/dist/react-native/RaftSystemUtils.js +3 -1
- package/dist/react-native/RaftSystemUtils.js.map +1 -1
- package/dist/react-native/RaftUpdateManager.js +2 -2
- package/dist/react-native/RaftUpdateManager.js.map +1 -1
- package/dist/react-native/RaftUtils.d.ts +2 -0
- package/dist/react-native/RaftUtils.js +22 -2
- package/dist/react-native/RaftUtils.js.map +1 -1
- package/dist/react-native/main.d.ts +2 -0
- package/dist/react-native/main.js +4 -1
- package/dist/react-native/main.js.map +1 -1
- package/dist/web/RaftAttributeHandler.d.ts +2 -0
- package/dist/web/RaftAttributeHandler.js +136 -10
- package/dist/web/RaftAttributeHandler.js.map +1 -1
- package/dist/web/RaftChannel.d.ts +2 -0
- package/dist/web/RaftChannelBLE.web.d.ts +2 -0
- package/dist/web/RaftChannelBLE.web.js +24 -15
- package/dist/web/RaftChannelBLE.web.js.map +1 -1
- package/dist/web/RaftChannelSimulated.d.ts +32 -0
- package/dist/web/RaftChannelSimulated.js +418 -0
- package/dist/web/RaftChannelSimulated.js.map +1 -0
- package/dist/web/RaftChannelWebSerial.d.ts +2 -0
- package/dist/web/RaftChannelWebSerial.js +18 -9
- package/dist/web/RaftChannelWebSerial.js.map +1 -1
- package/dist/web/RaftChannelWebSocket.d.ts +2 -0
- package/dist/web/RaftChannelWebSocket.js +10 -0
- package/dist/web/RaftChannelWebSocket.js.map +1 -1
- package/dist/web/RaftConnector.js +13 -6
- package/dist/web/RaftConnector.js.map +1 -1
- package/dist/web/RaftCustomAttrHandler.js +15 -0
- package/dist/web/RaftCustomAttrHandler.js.map +1 -1
- package/dist/web/RaftDeviceInfo.d.ts +8 -1
- package/dist/web/RaftDeviceManager.d.ts +3 -0
- package/dist/web/RaftDeviceManager.js +123 -43
- package/dist/web/RaftDeviceManager.js.map +1 -1
- package/dist/web/RaftFileHandler.js +8 -8
- package/dist/web/RaftFileHandler.js.map +1 -1
- package/dist/web/RaftLog.js +1 -1
- package/dist/web/RaftLog.js.map +1 -1
- package/dist/web/RaftMsgHandler.d.ts +5 -0
- package/dist/web/RaftMsgHandler.js +32 -0
- package/dist/web/RaftMsgHandler.js.map +1 -1
- package/dist/web/RaftStreamHandler.js +6 -5
- package/dist/web/RaftStreamHandler.js.map +1 -1
- package/dist/web/RaftStruct.js +1 -1
- package/dist/web/RaftStruct.js.map +1 -1
- package/dist/web/RaftSysTypeManager.d.ts +2 -0
- package/dist/web/RaftSysTypeManager.js +25 -0
- package/dist/web/RaftSysTypeManager.js.map +1 -1
- package/dist/web/RaftSystemType.d.ts +9 -7
- package/dist/web/RaftSystemUtils.js +3 -1
- package/dist/web/RaftSystemUtils.js.map +1 -1
- package/dist/web/RaftUpdateManager.js +2 -2
- package/dist/web/RaftUpdateManager.js.map +1 -1
- package/dist/web/RaftUtils.d.ts +2 -0
- package/dist/web/RaftUtils.js +22 -2
- package/dist/web/RaftUtils.js.map +1 -1
- package/dist/web/main.d.ts +2 -0
- package/dist/web/main.js +4 -1
- package/dist/web/main.js.map +1 -1
- package/examples/dashboard/package.json +1 -1
- package/examples/dashboard/src/CommandPanel.tsx +3 -3
- package/examples/dashboard/src/ConnManager.ts +83 -6
- package/examples/dashboard/src/DeviceActionsForm.tsx +2 -2
- package/examples/dashboard/src/DevicePanel.tsx +2 -2
- package/examples/dashboard/src/Main.tsx +14 -4
- package/examples/dashboard/src/SystemTypeMarty/RICSystemUtils.ts +4 -4
- package/examples/dashboard/src/styles.css +8 -0
- package/examples/dashboard/tsconfig.json +1 -1
- package/package.json +10 -11
- package/src/RaftAttributeHandler.ts +163 -11
- package/src/RaftChannel.ts +2 -0
- package/src/RaftChannelBLE.native.ts +17 -8
- package/src/RaftChannelBLE.web.ts +28 -16
- package/src/RaftChannelSimulated.ts +482 -0
- package/src/RaftChannelWebSerial.ts +18 -7
- package/src/RaftChannelWebSocket.ts +13 -0
- package/src/RaftConnector.ts +13 -7
- package/src/RaftCustomAttrHandler.ts +17 -0
- package/src/RaftDeviceInfo.ts +8 -2
- package/src/RaftDeviceManager.ts +155 -47
- package/src/RaftFileHandler.ts +8 -8
- package/src/RaftLog.ts +1 -1
- package/src/RaftMsgHandler.ts +36 -0
- package/src/RaftStreamHandler.ts +48 -47
- package/src/RaftStruct.ts +1 -1
- package/src/RaftSysTypeManager.ts +27 -0
- package/src/RaftSystemType.ts +9 -7
- package/src/RaftSystemUtils.ts +3 -1
- package/src/RaftUpdateManager.ts +2 -2
- package/src/RaftUtils.ts +25 -5
- package/src/main.ts +2 -0
package/src/RaftMsgHandler.ts
CHANGED
|
@@ -60,6 +60,8 @@ export interface RaftMessageSender {
|
|
|
60
60
|
msg: Uint8Array,
|
|
61
61
|
sendWithResponse: boolean,
|
|
62
62
|
): Promise<boolean>;
|
|
63
|
+
sendTxMsgRaw(msg: string): boolean;
|
|
64
|
+
sendTxMsgRawAndWaitForReply<T>(msgPayload: Uint8Array): T;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
export default class RaftMsgHandler {
|
|
@@ -87,6 +89,9 @@ export default class RaftMsgHandler {
|
|
|
87
89
|
// RaftMiniHDLC - handles part of RICSerial protocol
|
|
88
90
|
private _miniHDLC: RaftMiniHDLC;
|
|
89
91
|
|
|
92
|
+
// Raw message mode
|
|
93
|
+
private _rawMsgMode = false;
|
|
94
|
+
|
|
90
95
|
// Constructor
|
|
91
96
|
constructor(commsStats: RaftCommsStats) {
|
|
92
97
|
this._commsStats = commsStats;
|
|
@@ -120,6 +125,22 @@ export default class RaftMsgHandler {
|
|
|
120
125
|
// RaftLog.verbose(`handleNewRxMsg len ${rxMsg.length} ${RaftUtils.bufferToHex(rxMsg)}`)
|
|
121
126
|
}
|
|
122
127
|
|
|
128
|
+
// This is currently only for testing and simulated channels
|
|
129
|
+
handleNewRxMsgRaw(rxMsg: Uint8Array, rxMsgType: RaftCommsMsgTypeCode, rxMsgNum: number, rxMsgTimeMs: number): void {
|
|
130
|
+
// Check message types
|
|
131
|
+
if (rxMsgType == RaftCommsMsgTypeCode.MSG_TYPE_RESPONSE) {
|
|
132
|
+
// Convert raw Uint8Array to string assuming UTF-8
|
|
133
|
+
const restStr = new TextDecoder('utf-8').decode(rxMsg);
|
|
134
|
+
this._handleResponseMessages(restStr, rxMsgNum);
|
|
135
|
+
} else if (rxMsgType == RaftCommsMsgTypeCode.MSG_TYPE_REPORT) {
|
|
136
|
+
// Convert raw Uint8Array to string assuming UTF-8
|
|
137
|
+
const restStr = new TextDecoder('utf-8').decode(rxMsg);
|
|
138
|
+
this._handleReportMessages(restStr);
|
|
139
|
+
} else {
|
|
140
|
+
this._msgResultHandler?.onRxOtherMsgType(rxMsg, rxMsgTimeMs);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
123
144
|
reportMsgCallbacksSet(callbackName: string, callback: (report: RaftReportMsg) => Promise<void>): void {
|
|
124
145
|
this._reportMsgCallbacks.set(callbackName, callback);
|
|
125
146
|
}
|
|
@@ -128,6 +149,11 @@ export default class RaftMsgHandler {
|
|
|
128
149
|
this._reportMsgCallbacks.delete(callbackName);
|
|
129
150
|
}
|
|
130
151
|
|
|
152
|
+
setRawMsgMode(isRawMode: boolean): void {
|
|
153
|
+
this._rawMsgMode = isRawMode;
|
|
154
|
+
RaftLog.debug(`setRawMsgMode ${isRawMode}`);
|
|
155
|
+
}
|
|
156
|
+
|
|
131
157
|
_onHDLCFrameDecode(rxMsg: Uint8Array, frameTimeMs: number): void {
|
|
132
158
|
// Add to stats
|
|
133
159
|
this._commsStats.msgRx();
|
|
@@ -336,6 +362,11 @@ export default class RaftMsgHandler {
|
|
|
336
362
|
return false;
|
|
337
363
|
}
|
|
338
364
|
|
|
365
|
+
// Check for raw message mode (used for testing and simulated channels)
|
|
366
|
+
if (this._rawMsgMode) {
|
|
367
|
+
return this._msgSender.sendTxMsgRaw(cmdStr);
|
|
368
|
+
}
|
|
369
|
+
|
|
339
370
|
// Put cmdStr into buffer
|
|
340
371
|
const cmdBytes = new Uint8Array(cmdStr.length + 1);
|
|
341
372
|
RaftUtils.addStringToBuffer(cmdBytes, cmdStr, 0);
|
|
@@ -406,6 +437,11 @@ export default class RaftMsgHandler {
|
|
|
406
437
|
throw new Error('sendMsgAndWaitForReply failed no sender');
|
|
407
438
|
}
|
|
408
439
|
|
|
440
|
+
// Check for raw message mode (used for testing and simulated channels)
|
|
441
|
+
if (this._rawMsgMode) {
|
|
442
|
+
return this._msgSender.sendTxMsgRawAndWaitForReply(msgPayload);
|
|
443
|
+
}
|
|
444
|
+
|
|
409
445
|
// Frame the message
|
|
410
446
|
let framedMsg = this.frameCommsMsg(msgPayload, msgDirection, msgProtocol, true);
|
|
411
447
|
|
package/src/RaftStreamHandler.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { RaftOKFail, RaftStreamStartResp, RaftStreamType } from './RaftTypes';
|
|
|
15
15
|
import RaftConnector from './RaftConnector';
|
|
16
16
|
import { RaftConnEvent } from './RaftConnEvents';
|
|
17
17
|
import { RICRESTElemCode } from './RaftProtocolDefs'
|
|
18
|
+
import RaftUtils from './RaftUtils';
|
|
18
19
|
|
|
19
20
|
export default class RaftStreamHandler {
|
|
20
21
|
|
|
@@ -49,7 +50,7 @@ export default class RaftStreamHandler {
|
|
|
49
50
|
|
|
50
51
|
private _isStreaming = false;
|
|
51
52
|
private _isPaused = false;
|
|
52
|
-
private _streamBuffer = new Uint8Array();
|
|
53
|
+
private _streamBuffer: Uint8Array<ArrayBuffer> = new Uint8Array();
|
|
53
54
|
private _audioDuration = 0;
|
|
54
55
|
private _audioByteRate = 0;
|
|
55
56
|
private _streamPos = 0;
|
|
@@ -67,11 +68,11 @@ export default class RaftStreamHandler {
|
|
|
67
68
|
this.onSoktoMsg = this.onSoktoMsg.bind(this);
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
setNumBlocksWithoutPause(numBlocks: number){
|
|
71
|
+
setNumBlocksWithoutPause(numBlocks: number) {
|
|
71
72
|
this._numBlocksWithoutPause = numBlocks;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
setLegacySoktoMode(legacyMode: boolean){
|
|
75
|
+
setLegacySoktoMode(legacyMode: boolean) {
|
|
75
76
|
RaftLog.debug(`Setting legacy sokto mode to ${legacyMode}`);
|
|
76
77
|
this._legacySoktoMode = legacyMode;
|
|
77
78
|
}
|
|
@@ -83,7 +84,7 @@ export default class RaftStreamHandler {
|
|
|
83
84
|
|
|
84
85
|
// TODO - if clearExisting is not set, form a queue
|
|
85
86
|
if (this._streamIsStarting || this._lastStreamStartTime > (Date.now() - 500)) {
|
|
86
|
-
RaftLog.
|
|
87
|
+
RaftLog.warn(`Unable to start sound, too soon since last request`);
|
|
87
88
|
return;
|
|
88
89
|
}
|
|
89
90
|
|
|
@@ -94,9 +95,9 @@ export default class RaftStreamHandler {
|
|
|
94
95
|
this._soktoReceived = false;
|
|
95
96
|
this._soktoPos = 0;
|
|
96
97
|
this._streamPos = 0;
|
|
97
|
-
this._streamBuffer = streamContents;
|
|
98
|
+
this._streamBuffer = RaftUtils.toArrayBufferView(streamContents);
|
|
98
99
|
this._audioDuration = audioDuration;
|
|
99
|
-
this._audioByteRate = (streamContents.length / audioDuration)*1000;
|
|
100
|
+
this._audioByteRate = (streamContents.length / audioDuration) * 1000;
|
|
100
101
|
|
|
101
102
|
this.clearFinishPointTimeout();
|
|
102
103
|
|
|
@@ -104,12 +105,12 @@ export default class RaftStreamHandler {
|
|
|
104
105
|
(result: boolean) => {
|
|
105
106
|
this._isPaused = false;
|
|
106
107
|
this._streamIsStarting = false;
|
|
107
|
-
if (!result){
|
|
108
|
-
RaftLog.
|
|
108
|
+
if (!result) {
|
|
109
|
+
RaftLog.warn(`Unable to start stream. ufStart message send failed`);
|
|
109
110
|
return;
|
|
110
111
|
}
|
|
111
112
|
//this.streamingPerformanceChecker();
|
|
112
|
-
if (!this._isStreaming){
|
|
113
|
+
if (!this._isStreaming) {
|
|
113
114
|
this._isStreaming = true;
|
|
114
115
|
this._sendStreamBuffer();
|
|
115
116
|
}
|
|
@@ -127,7 +128,7 @@ export default class RaftStreamHandler {
|
|
|
127
128
|
return this._streamIsStarting;
|
|
128
129
|
}
|
|
129
130
|
|
|
130
|
-
|
|
131
|
+
|
|
131
132
|
clearFinishPointTimeout() {
|
|
132
133
|
if (this.soundFinishPoint) {
|
|
133
134
|
clearTimeout(this.soundFinishPoint);
|
|
@@ -172,7 +173,7 @@ export default class RaftStreamHandler {
|
|
|
172
173
|
RICRESTElemCode.RICREST_ELEM_CODE_COMMAND_FRAME,
|
|
173
174
|
);
|
|
174
175
|
} catch (err) {
|
|
175
|
-
RaftLog.
|
|
176
|
+
RaftLog.warn(`sendStreamStartMsg error ${err}`);
|
|
176
177
|
return false;
|
|
177
178
|
}
|
|
178
179
|
|
|
@@ -191,11 +192,11 @@ export default class RaftStreamHandler {
|
|
|
191
192
|
return true;
|
|
192
193
|
}
|
|
193
194
|
|
|
194
|
-
get maxBlockSize
|
|
195
|
+
get maxBlockSize() {
|
|
195
196
|
return this._maxBlockSize;
|
|
196
197
|
}
|
|
197
198
|
|
|
198
|
-
set maxBlockSize
|
|
199
|
+
set maxBlockSize(maxBlockSize: number) {
|
|
199
200
|
this._maxBlockSize = maxBlockSize;
|
|
200
201
|
this.DEFAULT_MAX_BLOCK_SIZE = maxBlockSize;
|
|
201
202
|
}
|
|
@@ -220,43 +221,43 @@ export default class RaftStreamHandler {
|
|
|
220
221
|
RICRESTElemCode.RICREST_ELEM_CODE_COMMAND_FRAME,
|
|
221
222
|
);
|
|
222
223
|
} catch (err) {
|
|
223
|
-
RaftLog.
|
|
224
|
+
RaftLog.warn(`sendStreamEndMsg error ${err}`);
|
|
224
225
|
return false;
|
|
225
226
|
}
|
|
226
227
|
return streamEndResp.rslt === 'ok';
|
|
227
228
|
}
|
|
228
229
|
|
|
229
|
-
/*
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
*/
|
|
230
|
+
/*
|
|
231
|
+
private async _sendAudioStopMsg(): Promise<RaftOKFail> {
|
|
232
|
+
const cmdMsg = `{"cmdName":"audio/stop"}`;
|
|
233
|
+
|
|
234
|
+
// Debug
|
|
235
|
+
RaftLog.debug(`sendAudioStopMsg ${cmdMsg}`);
|
|
236
|
+
|
|
237
|
+
// Send
|
|
238
|
+
return this._msgHandler.sendRICREST<RaftOKFail>(
|
|
239
|
+
cmdMsg,
|
|
240
|
+
RICRESTElemCode.RICREST_ELEM_CODE_COMMAND_FRAME,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
private async _sendStreamCancelMsg(): Promise<RaftOKFail> {
|
|
246
|
+
// File cancel command message
|
|
247
|
+
const cmdMsg = `{"cmdName":"ufCancel","reqStr":"ufCancel","streamID":${this._streamID}}`;
|
|
248
|
+
|
|
249
|
+
// Debug
|
|
250
|
+
RaftLog.debug(`sendStreamCancelMsg ${cmdMsg}`);
|
|
251
|
+
|
|
252
|
+
// Send
|
|
253
|
+
return this._msgHandler.sendRICREST<RaftOKFail>(
|
|
254
|
+
cmdMsg,
|
|
255
|
+
RICRESTElemCode.RICREST_ELEM_CODE_COMMAND_FRAME,
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
*/
|
|
258
259
|
|
|
259
|
-
private async _sendStreamBuffer(): Promise<boolean> {
|
|
260
|
+
private async _sendStreamBuffer(): Promise<boolean> {
|
|
260
261
|
const streamStartTime = Date.now();
|
|
261
262
|
|
|
262
263
|
// Check streamID is valid
|
|
@@ -267,7 +268,7 @@ private async _sendStreamBuffer(): Promise<boolean> {
|
|
|
267
268
|
let blockNum = 0;
|
|
268
269
|
// Send stream blocks
|
|
269
270
|
while (this._soktoPos < this._streamBuffer.length || this._isPaused) {
|
|
270
|
-
if (this._isPaused){
|
|
271
|
+
if (this._isPaused) {
|
|
271
272
|
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
272
273
|
continue;
|
|
273
274
|
}
|
|
@@ -301,8 +302,8 @@ private async _sendStreamBuffer(): Promise<boolean> {
|
|
|
301
302
|
this._streamPos += blockSize;
|
|
302
303
|
blockNum += 1;
|
|
303
304
|
|
|
304
|
-
if (this._audioByteRate && blockNum > this._numBlocksWithoutPause){
|
|
305
|
-
const pauseTime = ((blockSize / this._audioByteRate)*1000) - 10;
|
|
305
|
+
if (this._audioByteRate && blockNum > this._numBlocksWithoutPause) {
|
|
306
|
+
const pauseTime = ((blockSize / this._audioByteRate) * 1000) - 10;
|
|
306
307
|
RaftLog.verbose(`Pausing for ${pauseTime} ms between audio packets. Bit rate ${this._audioByteRate * 8}`)
|
|
307
308
|
await new Promise((resolve) => setTimeout(resolve, pauseTime));
|
|
308
309
|
}
|
package/src/RaftStruct.ts
CHANGED
|
@@ -134,7 +134,7 @@ export function structPack(format: string, values: number[]): Uint8Array {
|
|
|
134
134
|
let offset = 0;
|
|
135
135
|
let littleEndian = false;
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
const valIdx = 0;
|
|
138
138
|
for (let i = 0; i < format.length; i++) {
|
|
139
139
|
const char = format[i];
|
|
140
140
|
const value = values[valIdx];
|
|
@@ -53,8 +53,35 @@ export default class RaftSysTypeManager {
|
|
|
53
53
|
const serviceUUIDs = new Set<string>();
|
|
54
54
|
this._sysTypes.forEach((factory) => {
|
|
55
55
|
const sysType = factory();
|
|
56
|
+
if (!sysType.BLEServiceUUIDs) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
56
59
|
sysType.BLEServiceUUIDs.forEach((uuid) => serviceUUIDs.add(uuid));
|
|
57
60
|
});
|
|
58
61
|
return Array.from(serviceUUIDs);
|
|
59
62
|
}
|
|
63
|
+
|
|
64
|
+
// Get a list of all device name prefixes to filter on
|
|
65
|
+
getAllNamePrefixes(): string[] {
|
|
66
|
+
const deviceNames = new Set<string>();
|
|
67
|
+
this._sysTypes.forEach((factory) => {
|
|
68
|
+
const sysType = factory();
|
|
69
|
+
if (!sysType.BLEDeviceNames) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
sysType.BLEDeviceNames.forEach((name) => deviceNames.add(name));
|
|
73
|
+
});
|
|
74
|
+
return Array.from(deviceNames);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Find the system type for a given BLE device name prefix
|
|
78
|
+
getSystemTypeByBLENamePrefix(name: string): RaftSystemType | null {
|
|
79
|
+
for (const factory of this._sysTypes.values()) {
|
|
80
|
+
const sysType = factory();
|
|
81
|
+
if (sysType.BLEDeviceNames && sysType.BLEDeviceNames.some((prefix) => name.startsWith(prefix))) {
|
|
82
|
+
return sysType;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
60
87
|
}
|
package/src/RaftSystemType.ts
CHANGED
|
@@ -15,18 +15,20 @@ export interface ConnectorOptions {
|
|
|
15
15
|
|
|
16
16
|
export interface RaftSystemType {
|
|
17
17
|
nameForDialogs: string;
|
|
18
|
-
defaultWiFiHostname
|
|
19
|
-
BLEServiceUUIDs
|
|
20
|
-
BLECmdUUID
|
|
21
|
-
BLERespUUID
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
defaultWiFiHostname?: string;
|
|
19
|
+
BLEServiceUUIDs?: string[];
|
|
20
|
+
BLECmdUUID?: string;
|
|
21
|
+
BLERespUUID?: string;
|
|
22
|
+
BLEDeviceNames?: string[];
|
|
23
|
+
firmwareDestName?: string;
|
|
24
|
+
normalFileDestName?: string;
|
|
24
25
|
connectorOptions: ConnectorOptions;
|
|
25
26
|
setup: (systemUtils: RaftSystemUtils, onEvent: RaftEventFn | null) => void;
|
|
26
27
|
subscribeForUpdates: RaftSubscribeForUpdatesCBType | null;
|
|
27
28
|
stateIsInvalid: RaftStateIsInvalidCBType | null;
|
|
28
29
|
rxOtherMsgType: RaftRxOtherMsgType | null;
|
|
29
|
-
deviceMgrIF
|
|
30
|
+
deviceMgrIF?: RaftDeviceMgrIF;
|
|
31
|
+
nonRaftTypeCode?: string;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
export type RaftGetSystemTypeCBType = (systemUtils: RaftSystemUtils) => Promise<RaftSystemType | null>;
|
package/src/RaftSystemUtils.ts
CHANGED
|
@@ -61,7 +61,9 @@ export default class RaftSystemUtils {
|
|
|
61
61
|
* @param defaultWiFiHostname
|
|
62
62
|
*/
|
|
63
63
|
setDefaultWiFiHostname(defaultWiFiHostname: string) {
|
|
64
|
-
|
|
64
|
+
if (defaultWiFiHostname) {
|
|
65
|
+
this._defaultWiFiHostname = defaultWiFiHostname;
|
|
66
|
+
}
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
/**
|
package/src/RaftUpdateManager.ts
CHANGED
|
@@ -762,9 +762,9 @@ export default class RICUpdateManager {
|
|
|
762
762
|
): Promise<boolean> {
|
|
763
763
|
|
|
764
764
|
// Get the destination
|
|
765
|
-
let fileDest = this._systemType ? this._systemType.normalFileDestName : "fs";
|
|
765
|
+
let fileDest = this._systemType && this._systemType.normalFileDestName ? this._systemType.normalFileDestName : "fs";
|
|
766
766
|
if (fileType === RaftFileSendType.FIRMWARE_UPDATE) {
|
|
767
|
-
fileDest = this._systemType ? this._systemType.firmwareDestName : "fw";
|
|
767
|
+
fileDest = this._systemType && this._systemType.firmwareDestName ? this._systemType.firmwareDestName : "fw";
|
|
768
768
|
}
|
|
769
769
|
return await this._raftFileHandler.fileSend(
|
|
770
770
|
fileName,
|
package/src/RaftUtils.ts
CHANGED
|
@@ -29,7 +29,7 @@ export default class RaftUtils {
|
|
|
29
29
|
): void {
|
|
30
30
|
// Check valid
|
|
31
31
|
if (buffer.length < startPos + strToAdd.length + 1) {
|
|
32
|
-
RaftLog.
|
|
32
|
+
RaftLog.warn("addStringToBuffer buffer too short");
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
35
|
let curPos = startPos;
|
|
@@ -471,7 +471,7 @@ export default class RaftUtils {
|
|
|
471
471
|
return v1 === v2;
|
|
472
472
|
} catch (e) {
|
|
473
473
|
// one of the two versions is invalid, return false
|
|
474
|
-
RaftLog.
|
|
474
|
+
RaftLog.warn(`isVersionEqual - invalid version ${v1} or ${v2} ${e}`);
|
|
475
475
|
return false;
|
|
476
476
|
}
|
|
477
477
|
}
|
|
@@ -481,14 +481,34 @@ export default class RaftUtils {
|
|
|
481
481
|
const timeout = new Promise((_, reject) => {
|
|
482
482
|
id = setTimeout(() => {
|
|
483
483
|
clearTimeout(id);
|
|
484
|
-
reject('Timed out in '+ ms + 'ms.')
|
|
484
|
+
reject('Timed out in ' + ms + 'ms.')
|
|
485
485
|
}, ms)
|
|
486
486
|
})
|
|
487
|
-
|
|
487
|
+
|
|
488
488
|
return Promise.race([
|
|
489
489
|
promise,
|
|
490
490
|
timeout
|
|
491
491
|
])
|
|
492
492
|
}
|
|
493
|
-
|
|
493
|
+
|
|
494
|
+
static toBufferSource(u8: Uint8Array<ArrayBufferLike>): BufferSource {
|
|
495
|
+
if (u8.buffer instanceof ArrayBuffer) {
|
|
496
|
+
// Respect byteOffset/byteLength
|
|
497
|
+
return u8.buffer.slice(u8.byteOffset, u8.byteOffset + u8.byteLength);
|
|
498
|
+
}
|
|
499
|
+
// e.g., SharedArrayBuffer -> copy into a real ArrayBuffer
|
|
500
|
+
const ab = new ArrayBuffer(u8.byteLength);
|
|
501
|
+
new Uint8Array(ab).set(u8);
|
|
502
|
+
return ab;
|
|
503
|
+
}
|
|
504
|
+
static toArrayBufferView(u8: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBuffer> {
|
|
505
|
+
if (u8.buffer instanceof ArrayBuffer) {
|
|
506
|
+
// keep the same bytes/offset/length, but the return type is now locked to ArrayBuffer
|
|
507
|
+
return new Uint8Array(u8.buffer, u8.byteOffset, u8.byteLength);
|
|
508
|
+
}
|
|
509
|
+
// e.g., SharedArrayBuffer → copy into a real ArrayBuffer
|
|
510
|
+
const ab = new ArrayBuffer(u8.byteLength);
|
|
511
|
+
new Uint8Array(ab).set(u8);
|
|
512
|
+
return new Uint8Array(ab);
|
|
513
|
+
}
|
|
494
514
|
}
|
package/src/main.ts
CHANGED
|
@@ -16,6 +16,7 @@ export { default as RaftCommsStats } from './RaftCommsStats';
|
|
|
16
16
|
export { default as RaftConnector } from './RaftConnector';
|
|
17
17
|
export { default as RaftChannel } from './RaftChannel';
|
|
18
18
|
export { default as RaftChannelWebSocket } from './RaftChannelWebSocket';
|
|
19
|
+
export { default as RaftChannelSimulated } from './RaftChannelSimulated';
|
|
19
20
|
export { default as RaftFileHandler } from './RaftFileHandler';
|
|
20
21
|
export { default as RaftLog } from './RaftLog';
|
|
21
22
|
export { default as RaftMiniHDLC } from './RaftMiniHDLC';
|
|
@@ -34,3 +35,4 @@ export * from './RaftConnEvents';
|
|
|
34
35
|
export * from './RaftUpdateEvents';
|
|
35
36
|
export * from "./RaftProtocolDefs";
|
|
36
37
|
export * from "./RaftDeviceStates";
|
|
38
|
+
export * from "./RaftDeviceInfo";
|