@ray-js/robot-data-stream 0.0.13-beta-1 → 0.0.13-beta-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/lib/api/sweeperP2p.d.ts +1 -0
- package/lib/api/sweeperP2p.js +15 -1
- package/package.json +1 -1
package/lib/api/sweeperP2p.d.ts
CHANGED
|
@@ -62,6 +62,7 @@ export declare class SweeperP2p extends P2pApi {
|
|
|
62
62
|
exitFiles: Array<string>;
|
|
63
63
|
packetDataCacheMap: Map<keyof typeof FILE_NAME_MAP, Map<number, string>>;
|
|
64
64
|
packetSerialNumberCacheMap: Map<keyof typeof FILE_NAME_MAP, number>;
|
|
65
|
+
fileLengthCacheMap: Map<keyof typeof FILE_NAME_MAP, number>;
|
|
65
66
|
packetTotalMap: Map<keyof typeof FILE_NAME_MAP, number>;
|
|
66
67
|
firstPackageTime: number;
|
|
67
68
|
onReceiveMapData: (data: string) => void;
|
package/lib/api/sweeperP2p.js
CHANGED
|
@@ -63,6 +63,7 @@ export class SweeperP2p extends P2pApi {
|
|
|
63
63
|
this.firstPackageTime = Date.now();
|
|
64
64
|
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]]);
|
|
65
65
|
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]]);
|
|
66
|
+
this.fileLengthCacheMap = 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]]);
|
|
66
67
|
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()]]);
|
|
67
68
|
}
|
|
68
69
|
setStreamFilePath = () => {
|
|
@@ -386,6 +387,9 @@ export class SweeperP2p extends P2pApi {
|
|
|
386
387
|
[...this.packetSerialNumberCacheMap.keys()].forEach(key => {
|
|
387
388
|
this.packetSerialNumberCacheMap.set(key, -1);
|
|
388
389
|
});
|
|
390
|
+
[...this.fileLengthCacheMap.keys()].forEach(key => {
|
|
391
|
+
this.fileLengthCacheMap.set(key, -1);
|
|
392
|
+
});
|
|
389
393
|
[...this.packetTotalMap.keys()].forEach(key => {
|
|
390
394
|
this.packetTotalMap.set(key, -1);
|
|
391
395
|
});
|
|
@@ -431,6 +435,7 @@ export class SweeperP2p extends P2pApi {
|
|
|
431
435
|
p2pStreamPacketReceiveCallback = data => {
|
|
432
436
|
const {
|
|
433
437
|
packetData,
|
|
438
|
+
fileLength,
|
|
434
439
|
fileSerialNumber,
|
|
435
440
|
packetIndex,
|
|
436
441
|
packetType
|
|
@@ -465,6 +470,7 @@ export class SweeperP2p extends P2pApi {
|
|
|
465
470
|
// 说明收到了新的整包数据
|
|
466
471
|
if (fileSerialNumber > cacheSerialNumber) {
|
|
467
472
|
this.packetSerialNumberCacheMap.set(fileName, fileSerialNumber);
|
|
473
|
+
this.fileLengthCacheMap.set(fileName, fileLength);
|
|
468
474
|
this.packetTotalMap.set(fileName, -1);
|
|
469
475
|
cachePacketMap.clear();
|
|
470
476
|
}
|
|
@@ -485,6 +491,13 @@ export class SweeperP2p extends P2pApi {
|
|
|
485
491
|
let [index, data] = _ref;
|
|
486
492
|
return data;
|
|
487
493
|
}).join('');
|
|
494
|
+
const cacheFileLength = this.fileLengthCacheMap.get(fileName);
|
|
495
|
+
if (cacheFileLength > 0 && hexValue.length !== cacheFileLength * 2) {
|
|
496
|
+
logger('warn', {
|
|
497
|
+
msg: `p2pStreamPacketReceiveCallback: fileName : ${fileName} length mismatch, expected: ${cacheFileLength * 2}, received: ${hexValue.length}`
|
|
498
|
+
}, this.onLogger);
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
488
501
|
if (this.firstPackageTime > 0 && fileName.indexOf('map') !== -1) {
|
|
489
502
|
const packageTime = Date.now() - this.firstPackageTime;
|
|
490
503
|
logger('info', {
|
|
@@ -502,12 +515,14 @@ export class SweeperP2p extends P2pApi {
|
|
|
502
515
|
if (this.cacheData[type] !== hexValue) {
|
|
503
516
|
if (type === 0 || type === 6) {
|
|
504
517
|
this.onReceiveMapData(hexValue);
|
|
518
|
+
this.cacheData[type] = hexValue;
|
|
505
519
|
}
|
|
506
520
|
if (type === 1) {
|
|
507
521
|
logger('info', {
|
|
508
522
|
msg: `push new path data`
|
|
509
523
|
}, this.onLogger);
|
|
510
524
|
this.onReceivePathData(hexValue);
|
|
525
|
+
this.cacheData[type] = hexValue;
|
|
511
526
|
}
|
|
512
527
|
if (type === 4) {
|
|
513
528
|
this.onReceiveAIPicData(hexValue);
|
|
@@ -515,7 +530,6 @@ export class SweeperP2p extends P2pApi {
|
|
|
515
530
|
if (type === 5) {
|
|
516
531
|
this.onReceiveAIPicHDData(hexValue);
|
|
517
532
|
}
|
|
518
|
-
this.cacheData[type] = hexValue;
|
|
519
533
|
}
|
|
520
534
|
}
|
|
521
535
|
}
|