@ray-js/robot-data-stream 0.0.8 → 0.0.10-beta-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/lib/api/sweeperP2p.d.ts +8 -1
- package/lib/api/sweeperP2p.js +32 -10
- package/lib/index.d.ts +1 -0
- package/lib/index.js +7 -6
- package/package.json +1 -1
package/lib/api/sweeperP2p.d.ts
CHANGED
|
@@ -15,12 +15,18 @@ declare const FILE_NAME_MAP: {
|
|
|
15
15
|
readonly 'map.bin': {
|
|
16
16
|
readonly type: 0;
|
|
17
17
|
};
|
|
18
|
+
readonly 'map_structured.bin': {
|
|
19
|
+
readonly type: 6;
|
|
20
|
+
};
|
|
18
21
|
readonly 'cleanPath.bin': {
|
|
19
22
|
readonly type: 1;
|
|
20
23
|
};
|
|
21
24
|
readonly 'map.bin.stream': {
|
|
22
25
|
readonly type: 0;
|
|
23
26
|
};
|
|
27
|
+
readonly 'map_structured.bin.stream': {
|
|
28
|
+
readonly type: 6;
|
|
29
|
+
};
|
|
24
30
|
readonly 'cleanPath.bin.stream': {
|
|
25
31
|
readonly type: 1;
|
|
26
32
|
};
|
|
@@ -46,6 +52,7 @@ export declare class SweeperP2p extends P2pApi {
|
|
|
46
52
|
streamFilePath: string;
|
|
47
53
|
dataFilePath: string;
|
|
48
54
|
downloadType: number;
|
|
55
|
+
useStructuredMode: boolean;
|
|
49
56
|
readingMap: boolean;
|
|
50
57
|
readingClean: boolean;
|
|
51
58
|
readingAI: boolean;
|
|
@@ -116,7 +123,7 @@ export declare class SweeperP2p extends P2pApi {
|
|
|
116
123
|
* @param downloadType
|
|
117
124
|
* 0: 下载断开 1: 持续下载
|
|
118
125
|
*/
|
|
119
|
-
startObserverSweeperDataByP2P: (downloadType: number, devId: string, onReceiveMapData: (data: string) => void, onReceivePathData: (data: string) => void, onReceiveAIPicData?: ((data: string) => void) | undefined, onReceiveAIPicHDData?: ((data: string) => void) | undefined) => Promise<void>;
|
|
126
|
+
startObserverSweeperDataByP2P: (downloadType: number, useStructuredMode: boolean, devId: string, onReceiveMapData: (data: string) => void, onReceivePathData: (data: string) => void, onReceiveAIPicData?: ((data: string) => void) | undefined, onReceiveAIPicHDData?: ((data: string) => void) | undefined) => Promise<void>;
|
|
120
127
|
/**
|
|
121
128
|
* 在下载过程中继续添加下载文件
|
|
122
129
|
* @param files
|
package/lib/api/sweeperP2p.js
CHANGED
|
@@ -14,12 +14,18 @@ const FILE_NAME_MAP = {
|
|
|
14
14
|
'map.bin': {
|
|
15
15
|
type: 0
|
|
16
16
|
},
|
|
17
|
+
'map_structured.bin': {
|
|
18
|
+
type: 6
|
|
19
|
+
},
|
|
17
20
|
'cleanPath.bin': {
|
|
18
21
|
type: 1
|
|
19
22
|
},
|
|
20
23
|
'map.bin.stream': {
|
|
21
24
|
type: 0
|
|
22
25
|
},
|
|
26
|
+
'map_structured.bin.stream': {
|
|
27
|
+
type: 6
|
|
28
|
+
},
|
|
23
29
|
'cleanPath.bin.stream': {
|
|
24
30
|
type: 1
|
|
25
31
|
},
|
|
@@ -44,6 +50,7 @@ export class SweeperP2p extends P2pApi {
|
|
|
44
50
|
super();
|
|
45
51
|
this.file = undefined;
|
|
46
52
|
this.downloadType = 1;
|
|
53
|
+
this.useStructuredMode = false;
|
|
47
54
|
this.fileIndex = -1; // -1 表示所有文件下载完成
|
|
48
55
|
this.albumName = 'ipc_sweeper_robot';
|
|
49
56
|
this.cacheDir = ty.env.USER_DATA_PATH;
|
|
@@ -51,9 +58,9 @@ export class SweeperP2p extends P2pApi {
|
|
|
51
58
|
this.readingClean = false;
|
|
52
59
|
this.cacheData = {};
|
|
53
60
|
this.exitFiles = [];
|
|
54
|
-
this.packetTotalMap = new Map([['map.bin', -1], ['cleanPath.bin', -1], ['ai.bin', -1], ['aiHD_XXXX_YYYY.bin', -1], ['map.bin.stream', -1], ['cleanPath.bin.stream', -1], ['ai.bin.stream', -1], ['aiHD_XXXX_YYYY.bin.stream', -1]]);
|
|
55
|
-
this.packetSerialNumberCacheMap = new Map([['map.bin', -1], ['cleanPath.bin', -1], ['ai.bin', -1], ['aiHD_XXXX_YYYY.bin', -1], ['map.bin.stream', -1], ['cleanPath.bin.stream', -1], ['ai.bin.stream', -1], ['aiHD_XXXX_YYYY.bin.stream', -1]]);
|
|
56
|
-
this.packetDataCacheMap = new Map([['map.bin', new Map()], ['cleanPath.bin', new Map()], ['ai.bin', new Map()], ['aiHD_XXXX_YYYY.bin', new Map()], ['map.bin.stream', new Map()], ['cleanPath.bin.stream', new Map()], ['ai.bin.stream', new Map()], ['aiHD_XXXX_YYYY.bin.stream', new Map()]]);
|
|
61
|
+
this.packetTotalMap = new Map([['map.bin', -1], ['map_structured.bin', -1], ['cleanPath.bin', -1], ['ai.bin', -1], ['aiHD_XXXX_YYYY.bin', -1], ['map.bin.stream', -1], ['map_structured.bin.stream', -1], ['cleanPath.bin.stream', -1], ['ai.bin.stream', -1], ['aiHD_XXXX_YYYY.bin.stream', -1]]);
|
|
62
|
+
this.packetSerialNumberCacheMap = new Map([['map.bin', -1], ['map_structured.bin', -1], ['cleanPath.bin', -1], ['ai.bin', -1], ['aiHD_XXXX_YYYY.bin', -1], ['map.bin.stream', -1], ['map_structured.bin.stream', -1], ['cleanPath.bin.stream', -1], ['ai.bin.stream', -1], ['aiHD_XXXX_YYYY.bin.stream', -1]]);
|
|
63
|
+
this.packetDataCacheMap = new Map([['map.bin', new Map()], ['map_structured.bin', new Map()], ['cleanPath.bin', new Map()], ['ai.bin', new Map()], ['aiHD_XXXX_YYYY.bin', new Map()], ['map.bin.stream', new Map()], ['map_structured.bin.stream', new Map()], ['cleanPath.bin.stream', new Map()], ['ai.bin.stream', new Map()], ['aiHD_XXXX_YYYY.bin.stream', new Map()]]);
|
|
57
64
|
}
|
|
58
65
|
setStreamFilePath = () => {
|
|
59
66
|
// this.streamFilePath = this.cacheDir + `/${this.albumName}/${devId}/stream`;
|
|
@@ -153,7 +160,10 @@ export class SweeperP2p extends P2pApi {
|
|
|
153
160
|
* @param filename
|
|
154
161
|
*/
|
|
155
162
|
getFileType = filename => {
|
|
156
|
-
if (filename.indexOf('
|
|
163
|
+
if (filename.indexOf('map_structured') !== -1) {
|
|
164
|
+
return 6;
|
|
165
|
+
}
|
|
166
|
+
if (filename.indexOf('map.') !== -1) {
|
|
157
167
|
return 0;
|
|
158
168
|
}
|
|
159
169
|
if (filename.indexOf('cleanPath') !== -1) {
|
|
@@ -183,7 +193,7 @@ export class SweeperP2p extends P2pApi {
|
|
|
183
193
|
if (!this.isConnecting) {
|
|
184
194
|
this.reconnectP2p(() => {
|
|
185
195
|
// 重连之后重新开启文件下载, 这里的成功不需要注册断开事件
|
|
186
|
-
this.startObserverSweeperDataByP2P(this.downloadType, this.devId, this.onReceiveMapData, this.onReceivePathData, this.onReceiveAIPicData, this.onReceiveAIPicHDData);
|
|
196
|
+
this.startObserverSweeperDataByP2P(this.downloadType, this.useStructuredMode, this.devId, this.onReceiveMapData, this.onReceivePathData, this.onReceiveAIPicData, this.onReceiveAIPicHDData);
|
|
187
197
|
});
|
|
188
198
|
} else {
|
|
189
199
|
log4js.warn('receive disconnect notice, but connectDevice is connecting');
|
|
@@ -197,7 +207,7 @@ export class SweeperP2p extends P2pApi {
|
|
|
197
207
|
* @param downloadType
|
|
198
208
|
* 0: 下载断开 1: 持续下载
|
|
199
209
|
*/
|
|
200
|
-
startObserverSweeperDataByP2P = async (downloadType, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData) => {
|
|
210
|
+
startObserverSweeperDataByP2P = async (downloadType, useStructuredMode, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData) => {
|
|
201
211
|
var _this$file$items;
|
|
202
212
|
if (![0, 1].some(item => item === downloadType)) {
|
|
203
213
|
log4js.warn('download type must be 0 or 1');
|
|
@@ -212,6 +222,7 @@ export class SweeperP2p extends P2pApi {
|
|
|
212
222
|
// do nothing
|
|
213
223
|
});
|
|
214
224
|
log4js.info('startObserverSweeperDataByP2P ==>');
|
|
225
|
+
this.useStructuredMode = useStructuredMode;
|
|
215
226
|
this.downloadType = downloadType;
|
|
216
227
|
this.setDataFilePath(devId);
|
|
217
228
|
this.setStreamFilePath(devId);
|
|
@@ -394,7 +405,7 @@ export class SweeperP2p extends P2pApi {
|
|
|
394
405
|
type
|
|
395
406
|
} = FILE_NAME_MAP[fileName];
|
|
396
407
|
if (this.cacheData[type] !== hexValue) {
|
|
397
|
-
if (type === 0) {
|
|
408
|
+
if (type === 0 || type === 6) {
|
|
398
409
|
this.onReceiveMapData(hexValue);
|
|
399
410
|
}
|
|
400
411
|
if (type === 1) {
|
|
@@ -450,7 +461,7 @@ export class SweeperP2p extends P2pApi {
|
|
|
450
461
|
log4js.warn('receive empty data');
|
|
451
462
|
return;
|
|
452
463
|
}
|
|
453
|
-
if (type === 0) {
|
|
464
|
+
if (type === 0 || type === 6) {
|
|
454
465
|
this.onReceiveMapData(hexValue);
|
|
455
466
|
}
|
|
456
467
|
if (type === 1) {
|
|
@@ -476,7 +487,12 @@ export class SweeperP2p extends P2pApi {
|
|
|
476
487
|
}
|
|
477
488
|
};
|
|
478
489
|
setReading = fileName => {
|
|
479
|
-
if (fileName.indexOf('
|
|
490
|
+
if (fileName.indexOf('map_structured') !== -1) {
|
|
491
|
+
if (this.readingMap === true) return false;
|
|
492
|
+
this.readingMap = true;
|
|
493
|
+
return true;
|
|
494
|
+
}
|
|
495
|
+
if (fileName.indexOf('map.') !== -1) {
|
|
480
496
|
if (this.readingMap === true) return false;
|
|
481
497
|
this.readingMap = true;
|
|
482
498
|
return true;
|
|
@@ -499,7 +515,9 @@ export class SweeperP2p extends P2pApi {
|
|
|
499
515
|
return true;
|
|
500
516
|
};
|
|
501
517
|
resetReading = fileName => {
|
|
502
|
-
if (fileName.indexOf('
|
|
518
|
+
if (fileName.indexOf('map_structured') !== -1) {
|
|
519
|
+
this.readingMap = false;
|
|
520
|
+
} else if (fileName.indexOf('map.') !== -1) {
|
|
503
521
|
this.readingMap = false;
|
|
504
522
|
} else if (fileName.indexOf('cleanPath') !== -1) {
|
|
505
523
|
this.readingClean = false;
|
|
@@ -529,6 +547,10 @@ export class SweeperP2p extends P2pApi {
|
|
|
529
547
|
}
|
|
530
548
|
}
|
|
531
549
|
});
|
|
550
|
+
// 如果是使用结构化的数据,则直接把map. 相关的文件过滤掉
|
|
551
|
+
if (this.useStructuredMode) {
|
|
552
|
+
return exitFiles.filter(item => item.indexOf('map.') === -1);
|
|
553
|
+
}
|
|
532
554
|
return exitFiles;
|
|
533
555
|
};
|
|
534
556
|
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
declare const useP2PDataStream: (devId: string, onReceiveMapData: (data: string) => void, onReceivePathData: (data: string) => void, opt?: {
|
|
2
2
|
logTag?: string | undefined;
|
|
3
|
+
useStructuredMode?: boolean | undefined;
|
|
3
4
|
onReceiveAIPicData?: ((data: string) => void) | undefined;
|
|
4
5
|
onReceiveAIPicHDData?: ((data: string) => void) | undefined;
|
|
5
6
|
} | undefined) => {
|
package/lib/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { getSystemInfoSync } from '@ray-js/ray';
|
|
|
8
8
|
const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
|
|
9
9
|
const {
|
|
10
10
|
logTag,
|
|
11
|
+
useStructuredMode = false,
|
|
11
12
|
onReceiveAIPicData,
|
|
12
13
|
onReceiveAIPicHDData
|
|
13
14
|
} = opt || {};
|
|
@@ -20,10 +21,6 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
|
|
|
20
21
|
if (logTag) {
|
|
21
22
|
log4js.setTag(logTag);
|
|
22
23
|
}
|
|
23
|
-
if (devId.startsWith('vdevo')) {
|
|
24
|
-
log4js.warn('virtual device cannot use p2p');
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
24
|
if (isIDE) {
|
|
28
25
|
log4js.warn(`You are using the IDE environment. To perform P2P and map debugging, please ensure the 'Robot Vacuum Debugger' plugin is installed.`);
|
|
29
26
|
SweeperP2pInstance.onReceiveMapData = onReceiveMapData;
|
|
@@ -33,6 +30,10 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
|
|
|
33
30
|
SweeperP2pInstance.removeP2pDownloadEvent();
|
|
34
31
|
};
|
|
35
32
|
}
|
|
33
|
+
if (devId.startsWith('vdevo')) {
|
|
34
|
+
log4js.warn('virtual device cannot use p2p');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
36
37
|
SweeperP2pInstance.initP2pSdk(devId).then(() => {
|
|
37
38
|
connectP2p();
|
|
38
39
|
});
|
|
@@ -53,12 +54,12 @@ const useP2PDataStream = (devId, onReceiveMapData, onReceivePathData, opt) => {
|
|
|
53
54
|
SweeperP2pInstance.isConnecting = true;
|
|
54
55
|
SweeperP2pInstance.connectDevice(() => {
|
|
55
56
|
isInit.current = true;
|
|
56
|
-
SweeperP2pInstance.startObserverSweeperDataByP2P(1, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData);
|
|
57
|
+
SweeperP2pInstance.startObserverSweeperDataByP2P(1, useStructuredMode, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData);
|
|
57
58
|
offSessionStatusChange.current = SweeperP2pInstance.onSessionStatusChange(SweeperP2pInstance.sessionStatusCallback);
|
|
58
59
|
}, () => {
|
|
59
60
|
SweeperP2pInstance.reconnectP2p(() => {
|
|
60
61
|
isInit.current = true;
|
|
61
|
-
SweeperP2pInstance.startObserverSweeperDataByP2P(1, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData);
|
|
62
|
+
SweeperP2pInstance.startObserverSweeperDataByP2P(1, useStructuredMode, devId, onReceiveMapData, onReceivePathData, onReceiveAIPicData, onReceiveAIPicHDData);
|
|
62
63
|
// 这里失败重连需要注册断开重连的事件
|
|
63
64
|
offSessionStatusChange.current = SweeperP2pInstance.onSessionStatusChange(SweeperP2pInstance.sessionStatusCallback);
|
|
64
65
|
});
|