@7365admin1/core 3.122.3 → 3.122.5
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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +78 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/padbot.e2e.test.mjs +1 -1
- package/test/padbot-patrol-start.test.mjs +105 -0
- package/test/padbot.test.mjs +41 -7
package/dist/index.mjs
CHANGED
|
@@ -64708,6 +64708,12 @@ function padbotCurrentMap(maps, ids2, floor) {
|
|
|
64708
64708
|
const onFloor = Number.isInteger(floor) ? list.filter((m) => m.floor === floor) : [];
|
|
64709
64709
|
return onFloor.length === 1 ? onFloor[0] : null;
|
|
64710
64710
|
}
|
|
64711
|
+
function padbotChargingPoint(map) {
|
|
64712
|
+
const piles = (Array.isArray(map?.targetPoints) ? map.targetPoints : []).filter(
|
|
64713
|
+
(t) => Number(t?.targetPointType) === 10 && num(t?.worldX) !== null && num(t?.worldY) !== null
|
|
64714
|
+
);
|
|
64715
|
+
return piles.length === 1 ? { worldX: num(piles[0].worldX), worldY: num(piles[0].worldY), yaw: piles[0].yaw } : null;
|
|
64716
|
+
}
|
|
64711
64717
|
var PADBOT_OTHER_MAP_TEXT = "The robot must be on this map first.";
|
|
64712
64718
|
function padbotAlarmFault(alarm) {
|
|
64713
64719
|
if (!alarm?.alarmType)
|
|
@@ -64746,7 +64752,22 @@ function padbotPatrolPlan(paths, maps, states = {}) {
|
|
|
64746
64752
|
}
|
|
64747
64753
|
return null;
|
|
64748
64754
|
};
|
|
64749
|
-
const
|
|
64755
|
+
const routeMapId = (p) => {
|
|
64756
|
+
if (typeof p?.mapId === "string" && p.mapId)
|
|
64757
|
+
return p.mapId;
|
|
64758
|
+
const pointMaps = new Set((Array.isArray(p?.points) ? p.points : []).map((pt) => pt?.mapId).filter((id) => typeof id === "string" && id));
|
|
64759
|
+
if (pointMaps.size === 1)
|
|
64760
|
+
return [...pointMaps][0];
|
|
64761
|
+
const names = Array.isArray(p?.points) && p.points.length ? p.points.map((pt) => pt?.targetPointName) : Array.isArray(p?.pointNames) ? p.pointNames : [];
|
|
64762
|
+
if (!names.length)
|
|
64763
|
+
return p?.mapId;
|
|
64764
|
+
const holders = allMaps.filter((m) => names.every((n) => (m?.targetPoints ?? []).some((t) => t?.name === n)));
|
|
64765
|
+
if (holders.length === 1)
|
|
64766
|
+
return holders[0].mapId;
|
|
64767
|
+
return holders.find((m) => m?.mapId === currentMap)?.mapId ?? p?.mapId;
|
|
64768
|
+
};
|
|
64769
|
+
const routes = (Array.isArray(paths) ? paths : []).map((path5) => {
|
|
64770
|
+
const p = { ...path5, mapId: routeMapId(path5) };
|
|
64750
64771
|
const map = mapById.get(p?.mapId);
|
|
64751
64772
|
const raw = Array.isArray(p?.points) && p.points.length ? [...p.points].sort((a, b) => (a?.pointIndex ?? 0) - (b?.pointIndex ?? 0)).map((pt) => ({ id: pt?.targetPointId, name: pt?.targetPointName, mapId: pt?.mapId ?? p?.mapId })) : (Array.isArray(p?.pointNames) ? p.pointNames : []).map((n) => ({ name: n, mapId: p?.mapId }));
|
|
64752
64773
|
const placed = raw.map((pt) => {
|
|
@@ -64771,7 +64792,10 @@ function padbotPatrolPlan(paths, maps, states = {}) {
|
|
|
64771
64792
|
const r = candidates[0];
|
|
64772
64793
|
r.currentCheckpoint = r.checkpoints.findIndex((c) => c.name === next);
|
|
64773
64794
|
}
|
|
64774
|
-
|
|
64795
|
+
const here = (r) => Number(!!currentMap && r.mapId === currentMap);
|
|
64796
|
+
routes.sort(
|
|
64797
|
+
(a, b) => Number(b.currentCheckpoint !== null) - Number(a.currentCheckpoint !== null) || here(b) - here(a) || Number(b._default) - Number(a._default)
|
|
64798
|
+
);
|
|
64775
64799
|
for (const r of routes)
|
|
64776
64800
|
delete r._default;
|
|
64777
64801
|
return { routes, schedule: [], scheduleShared: false };
|
|
@@ -65022,6 +65046,13 @@ function createPadbotAdapter(credentials, options = {}) {
|
|
|
65022
65046
|
const mins = Math.floor((now() - last.at) / 6e4);
|
|
65023
65047
|
robot.statusName = `${robot.statusName} \xB7 Last reported position${mins >= 1 ? ` (${mins} min ago)` : ""}`;
|
|
65024
65048
|
}
|
|
65049
|
+
const onCharger = [1, 2].includes(st["1002"]?.chargingState);
|
|
65050
|
+
const pile = onCharger && !robot.position ? padbotChargingPoint(map) : null;
|
|
65051
|
+
if (pile) {
|
|
65052
|
+
robot.position = { x: pile.worldX, y: pile.worldY, theta: (num(pile.yaw) ?? 0) * Math.PI / 180 };
|
|
65053
|
+
robot.planPosition = padbotPlanShare(map, pile.worldX, pile.worldY);
|
|
65054
|
+
robot.statusName = `${robot.statusName} \xB7 At charger`;
|
|
65055
|
+
}
|
|
65025
65056
|
if (!robot.position)
|
|
65026
65057
|
robot.statusName = `${robot.statusName} \xB7 Position not reported`;
|
|
65027
65058
|
if (alarm)
|
|
@@ -65032,6 +65063,39 @@ function createPadbotAdapter(credentials, options = {}) {
|
|
|
65032
65063
|
const n = command?.options?.cleanTimes;
|
|
65033
65064
|
return Number.isInteger(n) && n >= 1 ? Math.min(n, 99) : 1;
|
|
65034
65065
|
};
|
|
65066
|
+
async function whereIs(robotSn) {
|
|
65067
|
+
const [st, all, loc] = await Promise.all([
|
|
65068
|
+
states(robotSn),
|
|
65069
|
+
maps(robotSn).catch(() => []),
|
|
65070
|
+
call(PADBOT_PATHS.location, { serialNumber: robotSn }).catch(() => null)
|
|
65071
|
+
]);
|
|
65072
|
+
const ids2 = [loc?.mapId, st?.["1007"]?.mapId];
|
|
65073
|
+
const map = padbotCurrentMap(all, ids2, st?.["1007"]?.floor);
|
|
65074
|
+
const mapId = map?.mapId ?? ids2.find((id) => typeof id === "string" && id) ?? null;
|
|
65075
|
+
return { st: st ?? {}, all: all ?? [], mapId };
|
|
65076
|
+
}
|
|
65077
|
+
const mapName = (all, id) => {
|
|
65078
|
+
const m = all.find((x) => x?.mapId === id);
|
|
65079
|
+
return String(m?.mapDisplayName || m?.mapName || "another");
|
|
65080
|
+
};
|
|
65081
|
+
async function checkedRoute(robotSn, routeId) {
|
|
65082
|
+
const [paths, where] = await Promise.all([call(PADBOT_PATHS.patrolRoutes, { serialNumber: robotSn }).then(asList), whereIs(robotSn)]);
|
|
65083
|
+
const rawRoute = routeId ? paths.find((p) => p?.pathId === routeId) : paths.find((p) => p?.isDefault);
|
|
65084
|
+
if (!rawRoute) {
|
|
65085
|
+
if (routeId)
|
|
65086
|
+
throw new BadRequestError135(padbotErrorText(2002));
|
|
65087
|
+
return null;
|
|
65088
|
+
}
|
|
65089
|
+
const plan = padbotPatrolPlan(paths, where.all, { ...where.st, "1007": { ...where.st["1007"] ?? {}, mapId: where.mapId } });
|
|
65090
|
+
const route = plan.routes.find((r) => r.id === String(rawRoute.pathId));
|
|
65091
|
+
const routeMap = route?.mapId;
|
|
65092
|
+
if (routeMap && where.mapId && !padbotCanReachMap(where.all, where.mapId, routeMap)) {
|
|
65093
|
+
throw new BadRequestError135(
|
|
65094
|
+
`"${rawRoute.pathName || "That route"}" is on the ${mapName(where.all, routeMap)} map, but the robot is on ${mapName(where.all, where.mapId)}. Pick a route on the robot's map.`
|
|
65095
|
+
);
|
|
65096
|
+
}
|
|
65097
|
+
return String(rawRoute.pathId);
|
|
65098
|
+
}
|
|
65035
65099
|
async function sendCommand2(robotSn, command) {
|
|
65036
65100
|
const sn = { serialNumber: robotSn };
|
|
65037
65101
|
const call2 = async (path5, body) => {
|
|
@@ -65053,14 +65117,18 @@ function createPadbotAdapter(credentials, options = {}) {
|
|
|
65053
65117
|
}
|
|
65054
65118
|
};
|
|
65055
65119
|
switch (command.kind) {
|
|
65056
|
-
case "full":
|
|
65057
|
-
|
|
65120
|
+
case "full": {
|
|
65121
|
+
const pathId = await checkedRoute(robotSn, null);
|
|
65122
|
+
await call2(PADBOT_PATHS.patrolStart, { ...sn, ...pathId ? { pathId } : {}, patrolCount: rounds(command) });
|
|
65058
65123
|
return;
|
|
65059
|
-
|
|
65124
|
+
}
|
|
65125
|
+
case "area": {
|
|
65060
65126
|
if (command.areas.length !== 1)
|
|
65061
65127
|
throw new BadRequestError135("Choose one patrol route to start.");
|
|
65062
|
-
await
|
|
65128
|
+
const pathId = await checkedRoute(robotSn, command.areas[0]);
|
|
65129
|
+
await call2(PADBOT_PATHS.patrolStart, { ...sn, pathId, patrolCount: rounds(command) });
|
|
65063
65130
|
return;
|
|
65131
|
+
}
|
|
65064
65132
|
case "patrol-resume":
|
|
65065
65133
|
await call2(PADBOT_PATHS.patrolResume, sn);
|
|
65066
65134
|
return;
|
|
@@ -65079,8 +65147,8 @@ function createPadbotAdapter(credentials, options = {}) {
|
|
|
65079
65147
|
await call2(PADBOT_PATHS.relocate, { ...sn, worldX: command.x, worldY: command.y });
|
|
65080
65148
|
return;
|
|
65081
65149
|
case "go-to-point": {
|
|
65082
|
-
const
|
|
65083
|
-
if (!padbotCanReachMap(all,
|
|
65150
|
+
const where = await whereIs(robotSn);
|
|
65151
|
+
if (!padbotCanReachMap(where.all, where.mapId, command.mapId))
|
|
65084
65152
|
throw new BadRequestError135(PADBOT_OTHER_MAP_TEXT);
|
|
65085
65153
|
await call2(PADBOT_PATHS.navigateTarget, { ...sn, mapId: command.mapId, targetPointId: command.targetPointId });
|
|
65086
65154
|
return;
|
|
@@ -105059,6 +105127,7 @@ export {
|
|
|
105059
105127
|
padbotAlarmPollEnabled,
|
|
105060
105128
|
padbotBaseUrl,
|
|
105061
105129
|
padbotCanReachMap,
|
|
105130
|
+
padbotChargingPoint,
|
|
105062
105131
|
padbotCheckpointVisit,
|
|
105063
105132
|
padbotCommandLog,
|
|
105064
105133
|
padbotCurrentMap,
|