@ray-js/robot-data-stream 0.0.14 → 0.0.15-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/mqtt/createCommonOptions.d.ts +4 -2
- package/lib/mqtt/createCommonOptions.js +10 -5
- package/lib/mqtt/hooks/useStructuredMessage.d.ts +14 -0
- package/lib/mqtt/hooks/useStructuredMessage.js +131 -0
- package/lib/mqtt/mqttProvider.d.ts +19 -1
- package/lib/mqtt/mqttProvider.js +69 -8
- package/lib/mqtt/promise.d.ts +57 -4
- package/lib/mqtt/promise.js +115 -36
- package/lib/mqtt/type/fun.d.ts +49 -0
- package/lib/mqtt/type/fun.js +145 -0
- package/lib/mqtt/type/index.d.ts +0 -7
- package/lib/mqtt/type/index.js +0 -1
- package/lib/mqtt/type/protocols/base.d.ts +5 -0
- package/lib/mqtt/type/protocols/base.js +32 -0
- package/lib/mqtt/type/protocols/carpetCleanProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/carpetCleanProtocol.js +16 -0
- package/lib/mqtt/type/protocols/carpetProtocol.d.ts +41 -0
- package/lib/mqtt/type/protocols/carpetProtocol.js +202 -0
- package/lib/mqtt/type/protocols/devInfoProtocol.d.ts +5 -0
- package/lib/mqtt/type/protocols/devInfoProtocol.js +12 -0
- package/lib/mqtt/type/protocols/deviceModelProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/deviceModelProtocol.js +34 -0
- package/lib/mqtt/type/protocols/furnitureModelProtocol.d.ts +10 -0
- package/lib/mqtt/type/protocols/furnitureModelProtocol.js +35 -0
- package/lib/mqtt/type/protocols/historyMapProtocol.d.ts +17 -0
- package/lib/mqtt/type/protocols/historyMapProtocol.js +37 -0
- package/lib/mqtt/type/protocols/index.d.ts +20 -0
- package/lib/mqtt/type/protocols/index.js +20 -0
- package/lib/mqtt/type/protocols/partDivisionProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/partDivisionProtocol.js +12 -0
- package/lib/mqtt/type/protocols/partMergeProtocol.d.ts +7 -0
- package/lib/mqtt/type/protocols/partMergeProtocol.js +12 -0
- package/lib/mqtt/type/protocols/passwordProtocol.d.ts +11 -0
- package/lib/mqtt/type/protocols/passwordProtocol.js +25 -0
- package/lib/mqtt/type/protocols/quietHoursProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/quietHoursProtocol.js +35 -0
- package/lib/mqtt/type/protocols/resetMapProtocol.d.ts +4 -0
- package/lib/mqtt/type/protocols/resetMapProtocol.js +1 -0
- package/lib/mqtt/type/protocols/roomPropertyProtocol.d.ts +14 -0
- package/lib/mqtt/type/protocols/roomPropertyProtocol.js +113 -0
- package/lib/mqtt/type/protocols/scheduleProtocol.d.ts +18 -0
- package/lib/mqtt/type/protocols/scheduleProtocol.js +100 -0
- package/lib/mqtt/type/protocols/selectRoomCleanProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/selectRoomCleanProtocol.js +40 -0
- package/lib/mqtt/type/protocols/spotCleanProtocol.d.ts +9 -0
- package/lib/mqtt/type/protocols/spotCleanProtocol.js +72 -0
- package/lib/mqtt/type/protocols/virtualAreaProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/virtualAreaProtocol.js +36 -0
- package/lib/mqtt/type/protocols/virtualWallProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/virtualWallProtocol.js +25 -0
- package/lib/mqtt/type/protocols/voiceProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/voiceProtocol.js +23 -0
- package/lib/mqtt/type/protocols/wifiMapProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/wifiMapProtocol.js +14 -0
- package/lib/mqtt/type/protocols/zoneCleanProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/zoneCleanProtocol.js +49 -0
- package/lib/mqtt/useCarpet.d.ts +7 -67
- package/lib/mqtt/useCarpet.js +101 -181
- package/lib/mqtt/useCarpetClean.d.ts +2 -11
- package/lib/mqtt/useCarpetClean.js +24 -51
- package/lib/mqtt/useDevInfo.d.ts +8 -6
- package/lib/mqtt/useDevInfo.js +44 -36
- package/lib/mqtt/useDeviceModel.d.ts +6 -19
- package/lib/mqtt/useDeviceModel.js +29 -42
- package/lib/mqtt/useFurnitureModel.d.ts +6 -18
- package/lib/mqtt/useFurnitureModel.js +29 -43
- package/lib/mqtt/useHistoryMap.d.ts +2 -18
- package/lib/mqtt/useHistoryMap.js +102 -119
- package/lib/mqtt/usePartDivision.d.ts +2 -9
- package/lib/mqtt/usePartDivision.js +48 -57
- package/lib/mqtt/usePartMerge.d.ts +2 -8
- package/lib/mqtt/usePartMerge.js +34 -49
- package/lib/mqtt/usePassword.d.ts +6 -13
- package/lib/mqtt/usePassword.js +84 -74
- package/lib/mqtt/useQuiteHours.d.ts +4 -37
- package/lib/mqtt/useQuiteHours.js +66 -100
- package/lib/mqtt/useResetMap.d.ts +2 -8
- package/lib/mqtt/useResetMap.js +27 -34
- package/lib/mqtt/useRoomProperty.d.ts +8 -9
- package/lib/mqtt/useRoomProperty.js +67 -65
- package/lib/mqtt/useSchedule.d.ts +3 -23
- package/lib/mqtt/useSchedule.js +72 -101
- package/lib/mqtt/useSelectRoomClean.d.ts +3 -24
- package/lib/mqtt/useSelectRoomClean.js +107 -133
- package/lib/mqtt/useSpotClean.d.ts +5 -15
- package/lib/mqtt/useSpotClean.js +68 -121
- package/lib/mqtt/useVirtualArea.d.ts +6 -17
- package/lib/mqtt/useVirtualArea.js +109 -119
- package/lib/mqtt/useVirtualWall.d.ts +2 -18
- package/lib/mqtt/useVirtualWall.js +69 -90
- package/lib/mqtt/useVoice.d.ts +2 -16
- package/lib/mqtt/useVoice.js +48 -68
- package/lib/mqtt/useWifiMap.d.ts +6 -5
- package/lib/mqtt/useWifiMap.js +43 -42
- package/lib/mqtt/useZoneClean.d.ts +2 -21
- package/lib/mqtt/useZoneClean.js +125 -137
- package/lib/myLib/zod/mini/index.d.cts +1 -0
- package/lib/myLib/zod/mini/index.d.ts +1 -0
- package/lib/myLib/zod/mini/index.js +1 -0
- package/lib/myLib/zod/mini/package.json +6 -0
- package/lib/myLib/zod/src/mini/index.d.ts +1 -0
- package/lib/myLib/zod/src/mini/index.js +1 -0
- package/lib/myLib/zod/src/v4/core/api.d.ts +306 -0
- package/lib/myLib/zod/src/v4/core/api.js +1256 -0
- package/lib/myLib/zod/src/v4/core/checks.d.ts +278 -0
- package/lib/myLib/zod/src/v4/core/checks.js +816 -0
- package/lib/myLib/zod/src/v4/core/config.d.ts +9 -0
- package/lib/myLib/zod/src/v4/core/config.js +5 -0
- package/lib/myLib/zod/src/v4/core/core.d.ts +70 -0
- package/lib/myLib/zod/src/v4/core/core.js +95 -0
- package/lib/myLib/zod/src/v4/core/doc.d.ts +14 -0
- package/lib/myLib/zod/src/v4/core/doc.js +42 -0
- package/lib/myLib/zod/src/v4/core/errors.d.ts +220 -0
- package/lib/myLib/zod/src/v4/core/errors.js +232 -0
- package/lib/myLib/zod/src/v4/core/index.d.ts +15 -0
- package/lib/myLib/zod/src/v4/core/index.js +15 -0
- package/lib/myLib/zod/src/v4/core/json-schema-generator.d.ts +65 -0
- package/lib/myLib/zod/src/v4/core/json-schema-generator.js +120 -0
- package/lib/myLib/zod/src/v4/core/json-schema-processors.d.ts +49 -0
- package/lib/myLib/zod/src/v4/core/json-schema-processors.js +593 -0
- package/lib/myLib/zod/src/v4/core/json-schema.d.ts +88 -0
- package/lib/myLib/zod/src/v4/core/json-schema.js +1 -0
- package/lib/myLib/zod/src/v4/core/parse.d.ts +49 -0
- package/lib/myLib/zod/src/v4/core/parse.js +147 -0
- package/lib/myLib/zod/src/v4/core/regexes.d.ts +78 -0
- package/lib/myLib/zod/src/v4/core/regexes.js +146 -0
- package/lib/myLib/zod/src/v4/core/registries.d.ts +35 -0
- package/lib/myLib/zod/src/v4/core/registries.js +51 -0
- package/lib/myLib/zod/src/v4/core/schemas.d.ts +1136 -0
- package/lib/myLib/zod/src/v4/core/schemas.js +2745 -0
- package/lib/myLib/zod/src/v4/core/standard-schema.d.ts +126 -0
- package/lib/myLib/zod/src/v4/core/standard-schema.js +1 -0
- package/lib/myLib/zod/src/v4/core/to-json-schema.d.ts +114 -0
- package/lib/myLib/zod/src/v4/core/to-json-schema.js +488 -0
- package/lib/myLib/zod/src/v4/core/util.d.ts +199 -0
- package/lib/myLib/zod/src/v4/core/util.js +656 -0
- package/lib/myLib/zod/src/v4/core/versions.d.ts +5 -0
- package/lib/myLib/zod/src/v4/core/versions.js +5 -0
- package/lib/myLib/zod/src/v4/core/zsf.d.ts +91 -0
- package/lib/myLib/zod/src/v4/core/zsf.js +1 -0
- package/lib/myLib/zod/src/v4/mini/checks.d.ts +1 -0
- package/lib/myLib/zod/src/v4/mini/checks.js +1 -0
- package/lib/myLib/zod/src/v4/mini/coerce.d.ts +7 -0
- package/lib/myLib/zod/src/v4/mini/coerce.js +27 -0
- package/lib/myLib/zod/src/v4/mini/external.d.ts +11 -0
- package/lib/myLib/zod/src/v4/mini/external.js +16 -0
- package/lib/myLib/zod/src/v4/mini/index.d.ts +3 -0
- package/lib/myLib/zod/src/v4/mini/index.js +3 -0
- package/lib/myLib/zod/src/v4/mini/iso.d.ts +22 -0
- package/lib/myLib/zod/src/v4/mini/iso.js +46 -0
- package/lib/myLib/zod/src/v4/mini/parse.d.ts +1 -0
- package/lib/myLib/zod/src/v4/mini/parse.js +1 -0
- package/lib/myLib/zod/src/v4/mini/schemas.js +1244 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +2 -1
- package/package.json +5 -3
package/lib/mqtt/useSpotClean.js
CHANGED
|
@@ -1,123 +1,73 @@
|
|
|
1
1
|
import "core-js/modules/esnext.iterator.map.js";
|
|
2
2
|
// 定点清扫
|
|
3
3
|
|
|
4
|
-
import { isArray } from 'lodash-es';
|
|
5
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
6
|
-
import { normalResolve } from './promise';
|
|
7
|
-
import { SpotCleanEnum } from './type';
|
|
8
4
|
import { useContext } from 'react';
|
|
5
|
+
import { SpotCleanEnum } from './type';
|
|
9
6
|
import { SingletonContext } from './mqttProvider';
|
|
10
7
|
import { encodeSpotClean0x16 } from '@ray-js/robot-protocol';
|
|
11
8
|
import { pointsToString } from '../utils';
|
|
9
|
+
import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
|
|
10
|
+
import { validator } from './type/fun';
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @returns
|
|
12
|
+
* 自定义 Hook,用于定点清扫
|
|
13
|
+
* @returns 包含 requestSpotClean 和 setSpotClean 函数的对象
|
|
15
14
|
*/
|
|
16
|
-
export const useSpotClean =
|
|
15
|
+
export const useSpotClean = () => {
|
|
17
16
|
const {
|
|
18
17
|
useMqtt,
|
|
19
18
|
commandVersion,
|
|
20
19
|
devices
|
|
21
20
|
} = useContext(SingletonContext);
|
|
21
|
+
const {
|
|
22
|
+
sendStructuredMessage
|
|
23
|
+
} = useStructuredMessage();
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
/**
|
|
26
|
+
* 请求定点清扫数据
|
|
27
|
+
* @param data 可选参数(目前为空对象)
|
|
28
|
+
* @returns Promise<SpotCleanResponse> 响应结果
|
|
29
|
+
*/
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
/**
|
|
32
|
+
* 设置定点清扫
|
|
33
|
+
* 定点清扫的清扫属性,使用全局的清扫属性
|
|
34
|
+
* @param message 包含定点清扫设置参数的对象
|
|
35
|
+
* @param message.spots 定点清扫的点数组
|
|
36
|
+
* @param message.origin 原点坐标(可选)
|
|
37
|
+
* @returns Promise<SpotCleanResponse> 响应结果
|
|
38
|
+
*/
|
|
27
39
|
|
|
28
40
|
return {
|
|
29
41
|
requestSpotClean: () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
try {
|
|
44
|
+
sendStructuredMessage(SpotCleanEnum.query, {}, resolve, error => reject(handleMqttError(error, 'Failed to request spot clean')));
|
|
45
|
+
} catch (error) {
|
|
46
|
+
reject(handleMqttError(error, 'Failed to request spot clean'));
|
|
47
|
+
}
|
|
33
48
|
});
|
|
34
|
-
ty.device.sendMqttMessage(params);
|
|
35
|
-
return normalResolve(SpotCleanEnum.query, params.message.taskId);
|
|
36
49
|
},
|
|
37
50
|
setSpotClean: message => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const num = spots.length;
|
|
48
|
-
const {
|
|
49
|
-
suctions = new Array(num).fill(''),
|
|
50
|
-
cisterns = new Array(num).fill(''),
|
|
51
|
-
cleanCounts = new Array(num).fill(1),
|
|
52
|
-
yMops = new Array(num).fill(-1),
|
|
53
|
-
sweepMopModes = new Array(num).fill('only_sweep')
|
|
54
|
-
} = message;
|
|
55
|
-
if (suctions && !isArray(suctions)) {
|
|
56
|
-
return Promise.reject(new Error('suctions is illegal'));
|
|
57
|
-
}
|
|
58
|
-
if (cisterns && !isArray(cisterns)) {
|
|
59
|
-
return Promise.reject(new Error('cisterns is illegal'));
|
|
60
|
-
}
|
|
61
|
-
if (cleanCounts && !isArray(cleanCounts)) {
|
|
62
|
-
return Promise.reject(new Error('cleanCounts is illegal'));
|
|
63
|
-
}
|
|
64
|
-
if (yMops && !isArray(yMops)) {
|
|
65
|
-
return Promise.reject(new Error('yMops is illegal'));
|
|
66
|
-
}
|
|
67
|
-
if (sweepMopModes && !isArray(sweepMopModes)) {
|
|
68
|
-
return Promise.reject(new Error('sweepMopModes is illegal'));
|
|
69
|
-
}
|
|
70
|
-
if (num !== suctions.length || num !== cisterns.length || num !== cleanCounts.length || num !== yMops.length || num !== sweepMopModes.length) {
|
|
71
|
-
return Promise.reject(new Error('The length of the parameters is inconsistent'));
|
|
72
|
-
}
|
|
73
|
-
const params = createSetCommonParams({
|
|
74
|
-
deviceId: devId,
|
|
75
|
-
reqType: SpotCleanEnum.set,
|
|
76
|
-
message: {
|
|
77
|
-
num,
|
|
78
|
-
polygons: spots.map(spot => pointsToString([spot], origin)),
|
|
79
|
-
suctions,
|
|
80
|
-
cisterns,
|
|
81
|
-
cleanCounts,
|
|
82
|
-
yMops,
|
|
83
|
-
sweepMopModes
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
ty.device.sendMqttMessage(params);
|
|
87
|
-
return normalResolve(SpotCleanEnum.query, params.message.taskId);
|
|
88
|
-
}
|
|
89
|
-
try {
|
|
90
|
-
if (useMqtt) {
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
try {
|
|
53
|
+
// 使用 TypeBox Schema 进行参数验证(包含自定义验证逻辑)
|
|
54
|
+
const validatedData = validator.validate('set_spot_clean', message);
|
|
55
|
+
const {
|
|
56
|
+
spots,
|
|
57
|
+
origin
|
|
58
|
+
} = validatedData;
|
|
91
59
|
const num = spots.length;
|
|
60
|
+
|
|
61
|
+
// 为可选字段设置默认值
|
|
92
62
|
const {
|
|
93
63
|
suctions = new Array(num).fill(''),
|
|
94
64
|
cisterns = new Array(num).fill(''),
|
|
95
65
|
cleanCounts = new Array(num).fill(1),
|
|
96
66
|
yMops = new Array(num).fill(-1),
|
|
97
67
|
sweepMopModes = new Array(num).fill('only_sweep')
|
|
98
|
-
} =
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
if (cisterns && !isArray(cisterns)) {
|
|
103
|
-
throw new Error('cisterns is illegal');
|
|
104
|
-
}
|
|
105
|
-
if (cleanCounts && !isArray(cleanCounts)) {
|
|
106
|
-
throw new Error('cleanCounts is illegal');
|
|
107
|
-
}
|
|
108
|
-
if (yMops && !isArray(yMops)) {
|
|
109
|
-
throw new Error('yMops is illegal');
|
|
110
|
-
}
|
|
111
|
-
if (sweepMopModes && !isArray(sweepMopModes)) {
|
|
112
|
-
throw new Error('sweepMopModes is illegal');
|
|
113
|
-
}
|
|
114
|
-
if (num !== suctions.length || num !== cisterns.length || num !== cleanCounts.length || num !== yMops.length || num !== sweepMopModes.length) {
|
|
115
|
-
throw new Error('The length of the parameters is inconsistent');
|
|
116
|
-
}
|
|
117
|
-
const params = createSetCommonParams({
|
|
118
|
-
deviceId: devId,
|
|
119
|
-
reqType: SpotCleanEnum.set,
|
|
120
|
-
message: {
|
|
68
|
+
} = validatedData;
|
|
69
|
+
if (useMqtt) {
|
|
70
|
+
sendStructuredMessage(SpotCleanEnum.set, {
|
|
121
71
|
num,
|
|
122
72
|
polygons: spots.map(spot => pointsToString([spot], origin)),
|
|
123
73
|
suctions,
|
|
@@ -125,38 +75,35 @@ export const useSpotClean = devId => {
|
|
|
125
75
|
cleanCounts,
|
|
126
76
|
yMops,
|
|
127
77
|
sweepMopModes
|
|
128
|
-
}
|
|
78
|
+
}, resolve, error => reject(handleMqttError(error, 'Failed to set spot clean')), SpotCleanEnum.query // 响应类型是 query,不是 set
|
|
79
|
+
);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 非 MQTT 模式:使用命令传输
|
|
84
|
+
const command = encodeSpotClean0x16({
|
|
85
|
+
version: commandVersion,
|
|
86
|
+
origin,
|
|
87
|
+
point: spots[0]
|
|
129
88
|
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
89
|
+
devices.common.model.actions.command_trans.set(command);
|
|
90
|
+
resolve({
|
|
91
|
+
success: true,
|
|
92
|
+
errCode: 0,
|
|
93
|
+
reqType: SpotCleanEnum.query,
|
|
94
|
+
version: commandVersion,
|
|
95
|
+
taskId: `${Date.now()}`,
|
|
96
|
+
polygons: spots.map(spot => pointsToString([spot], origin)),
|
|
97
|
+
suctions,
|
|
98
|
+
cisterns,
|
|
99
|
+
cleanCounts,
|
|
100
|
+
yMops,
|
|
101
|
+
sweepMopModes
|
|
102
|
+
});
|
|
103
|
+
} catch (error) {
|
|
104
|
+
reject(handleMqttError(error, 'Failed to set spot clean'));
|
|
135
105
|
}
|
|
136
|
-
|
|
137
|
-
// 非 MQTT 模式:使用命令传输
|
|
138
|
-
const command = encodeSpotClean0x16({
|
|
139
|
-
version: commandVersion,
|
|
140
|
-
origin,
|
|
141
|
-
point: spots[0]
|
|
142
|
-
});
|
|
143
|
-
devices.common.model.actions.command_trans.set(command);
|
|
144
|
-
return Promise.resolve({
|
|
145
|
-
success: true,
|
|
146
|
-
errCode: 0,
|
|
147
|
-
reqType: SpotCleanEnum.query,
|
|
148
|
-
version: commandVersion,
|
|
149
|
-
taskId: `${Date.now()}`,
|
|
150
|
-
polygons: spots.map(spot => pointsToString([spot], origin)),
|
|
151
|
-
suctions: message.suctions,
|
|
152
|
-
cisterns: message.cisterns,
|
|
153
|
-
cleanCounts: message.cleanCounts,
|
|
154
|
-
yMops: message.yMops,
|
|
155
|
-
sweepMopModes: message.sweepMopModes
|
|
156
|
-
});
|
|
157
|
-
} catch (error) {
|
|
158
|
-
throw error instanceof Error ? error : new Error('Failed to set spot clean');
|
|
159
|
-
}
|
|
106
|
+
});
|
|
160
107
|
}
|
|
161
108
|
};
|
|
162
109
|
};
|
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
polygons: string[];
|
|
8
|
-
names: string[];
|
|
9
|
-
mapId: number;
|
|
10
|
-
}
|
|
11
|
-
type TSetVirtualArea = (message: {
|
|
12
|
-
data: VirtualArea[];
|
|
13
|
-
origin: Point;
|
|
14
|
-
}) => Promise<VirtualAreaResponse>;
|
|
15
|
-
type TRequestVirtualArea = () => Promise<VirtualAreaResponse>;
|
|
16
|
-
export declare const useVirtualArea: (devId: string) => {
|
|
1
|
+
import { type TRequestVirtualArea, type TSetVirtualArea } from './type/protocols';
|
|
2
|
+
/**
|
|
3
|
+
* 自定义 Hook,用于虚拟区域(禁区)管理
|
|
4
|
+
* @returns 包含 requestVirtualArea 和 setVirtualArea 函数的对象
|
|
5
|
+
*/
|
|
6
|
+
export declare const useVirtualArea: () => {
|
|
17
7
|
requestVirtualArea: TRequestVirtualArea;
|
|
18
8
|
setVirtualArea: TSetVirtualArea;
|
|
19
9
|
};
|
|
20
|
-
export {};
|
|
@@ -2,27 +2,32 @@ import "core-js/modules/esnext.iterator.constructor.js";
|
|
|
2
2
|
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
3
|
import "core-js/modules/esnext.iterator.map.js";
|
|
4
4
|
// 添加禁区
|
|
5
|
-
import { useContext } from 'react';
|
|
6
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
7
|
-
import { normalResolve } from './promise';
|
|
8
|
-
import { VirtualAreaEnum } from './type';
|
|
9
|
-
import { SingletonContext } from './mqttProvider';
|
|
10
5
|
import { encodeVirtualArea0x1a, requestVirtualArea0x1b } from '@ray-js/robot-protocol';
|
|
6
|
+
import { useContext } from 'react';
|
|
11
7
|
import { pointsToString } from '../utils';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
import { handleMqttError, useStructuredMessage } from './hooks/useStructuredMessage';
|
|
9
|
+
import { SingletonContext } from './mqttProvider';
|
|
10
|
+
import { VirtualAreaEnum } from './type';
|
|
11
|
+
import { validator } from './type/fun';
|
|
15
12
|
// 禁区
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
/**
|
|
15
|
+
* 自定义 Hook,用于虚拟区域(禁区)管理
|
|
16
|
+
* @returns 包含 requestVirtualArea 和 setVirtualArea 函数的对象
|
|
17
|
+
*/
|
|
18
|
+
export const useVirtualArea = () => {
|
|
18
19
|
const {
|
|
19
20
|
useMqtt,
|
|
20
21
|
commandVersion,
|
|
21
22
|
devices
|
|
22
23
|
} = useContext(SingletonContext);
|
|
24
|
+
const {
|
|
25
|
+
sendStructuredMessage
|
|
26
|
+
} = useStructuredMessage();
|
|
23
27
|
|
|
24
28
|
/**
|
|
25
29
|
* 请求虚拟区域数据
|
|
30
|
+
* @param data 可选参数(目前为空对象)
|
|
26
31
|
* @returns Promise<VirtualAreaResponse> 响应结果
|
|
27
32
|
*/
|
|
28
33
|
|
|
@@ -36,125 +41,110 @@ export const useVirtualArea = devId => {
|
|
|
36
41
|
|
|
37
42
|
return {
|
|
38
43
|
requestVirtualArea: () => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
ty.device.sendMqttMessage(params);
|
|
46
|
-
const {
|
|
47
|
-
taskId
|
|
48
|
-
} = params.message;
|
|
49
|
-
return normalResolve(VirtualAreaEnum.query, taskId);
|
|
50
|
-
}
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
try {
|
|
46
|
+
if (useMqtt) {
|
|
47
|
+
sendStructuredMessage(VirtualAreaEnum.query, {}, resolve, error => reject(handleMqttError(error, 'Failed to request virtual area')));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
// 非 MQTT 模式:使用命令传输
|
|
52
|
+
devices.common.model.actions.command_trans.set(requestVirtualArea0x1b({
|
|
53
|
+
version: commandVersion
|
|
54
|
+
}));
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
} catch (error) {
|
|
71
|
-
return Promise.reject(error instanceof Error ? error : new Error('Failed to request virtual area'));
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
setVirtualArea: _ref => {
|
|
75
|
-
let {
|
|
76
|
-
data,
|
|
77
|
-
origin
|
|
78
|
-
} = _ref;
|
|
79
|
-
// 参数验证
|
|
80
|
-
if (!Array.isArray(data)) {
|
|
81
|
-
throw new Error('data is required and must be a non-empty array');
|
|
82
|
-
}
|
|
83
|
-
if (!origin || typeof origin.x !== 'number' || typeof origin.y !== 'number') {
|
|
84
|
-
throw new Error('origin is required and must be a valid Point object with x and y properties');
|
|
85
|
-
}
|
|
86
|
-
try {
|
|
87
|
-
if (useMqtt) {
|
|
88
|
-
const names = [];
|
|
89
|
-
const modes = [];
|
|
90
|
-
const polygons = [];
|
|
91
|
-
data.forEach(_ref2 => {
|
|
92
|
-
let {
|
|
93
|
-
points,
|
|
94
|
-
name,
|
|
95
|
-
mode
|
|
96
|
-
} = _ref2;
|
|
97
|
-
names.push(name);
|
|
98
|
-
modes.push(mode);
|
|
99
|
-
polygons.push(pointsToString(points, origin));
|
|
56
|
+
// 非 MQTT 模式下无法立即获取响应数据,返回默认响应
|
|
57
|
+
resolve({
|
|
58
|
+
success: true,
|
|
59
|
+
errCode: 0,
|
|
60
|
+
reqType: VirtualAreaEnum.query,
|
|
61
|
+
version: commandVersion,
|
|
62
|
+
taskId: `${Date.now()}`,
|
|
63
|
+
num: 0,
|
|
64
|
+
modes: [],
|
|
65
|
+
polygons: [],
|
|
66
|
+
names: [],
|
|
67
|
+
mapId: 0
|
|
100
68
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
69
|
+
} catch (error) {
|
|
70
|
+
reject(handleMqttError(error, 'Failed to request virtual area'));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
setVirtualArea: message => {
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
try {
|
|
77
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
78
|
+
const validatedData = validator.validate('set_virtual_area', message);
|
|
79
|
+
const {
|
|
80
|
+
data,
|
|
81
|
+
origin
|
|
82
|
+
} = validatedData;
|
|
83
|
+
if (useMqtt) {
|
|
84
|
+
const names = [];
|
|
85
|
+
const modes = [];
|
|
86
|
+
const polygons = [];
|
|
87
|
+
data.forEach(_ref => {
|
|
88
|
+
let {
|
|
89
|
+
points,
|
|
90
|
+
name,
|
|
91
|
+
mode
|
|
92
|
+
} = _ref;
|
|
93
|
+
names.push(name);
|
|
94
|
+
modes.push(mode);
|
|
95
|
+
polygons.push(pointsToString(points, origin));
|
|
96
|
+
});
|
|
97
|
+
sendStructuredMessage(VirtualAreaEnum.set, {
|
|
105
98
|
polygons,
|
|
106
99
|
num: data.length,
|
|
107
100
|
modes: modes,
|
|
108
101
|
names: names
|
|
109
|
-
}
|
|
102
|
+
}, resolve, error => reject(handleMqttError(error, 'Failed to set virtual area')), VirtualAreaEnum.query // 响应类型是 query,不是 set
|
|
103
|
+
);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 非 MQTT 模式:使用命令传输
|
|
108
|
+
const command = encodeVirtualArea0x1a({
|
|
109
|
+
version: commandVersion,
|
|
110
|
+
origin,
|
|
111
|
+
virtualAreas: data
|
|
110
112
|
});
|
|
111
|
-
|
|
112
|
-
const {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
devices.common.model.actions.command_trans.set(command);
|
|
114
|
+
const names = data.map(_ref2 => {
|
|
115
|
+
let {
|
|
116
|
+
name
|
|
117
|
+
} = _ref2;
|
|
118
|
+
return name;
|
|
119
|
+
});
|
|
120
|
+
const modes = data.map(_ref3 => {
|
|
121
|
+
let {
|
|
122
|
+
mode
|
|
123
|
+
} = _ref3;
|
|
124
|
+
return mode;
|
|
125
|
+
});
|
|
126
|
+
const polygons = data.map(_ref4 => {
|
|
127
|
+
let {
|
|
128
|
+
points
|
|
129
|
+
} = _ref4;
|
|
130
|
+
return pointsToString(points, origin);
|
|
131
|
+
});
|
|
132
|
+
resolve({
|
|
133
|
+
success: true,
|
|
134
|
+
errCode: 0,
|
|
135
|
+
reqType: VirtualAreaEnum.query,
|
|
136
|
+
version: commandVersion,
|
|
137
|
+
taskId: `${Date.now()}`,
|
|
138
|
+
num: data.length,
|
|
139
|
+
modes,
|
|
140
|
+
polygons,
|
|
141
|
+
names,
|
|
142
|
+
mapId: 0
|
|
143
|
+
});
|
|
144
|
+
} catch (error) {
|
|
145
|
+
reject(handleMqttError(error, 'Failed to set virtual area'));
|
|
116
146
|
}
|
|
117
|
-
|
|
118
|
-
// 非 MQTT 模式:使用命令传输
|
|
119
|
-
const command = encodeVirtualArea0x1a({
|
|
120
|
-
version: commandVersion,
|
|
121
|
-
origin,
|
|
122
|
-
virtualAreas: data
|
|
123
|
-
});
|
|
124
|
-
devices.common.model.actions.command_trans.set(command);
|
|
125
|
-
const names = data.map(_ref3 => {
|
|
126
|
-
let {
|
|
127
|
-
name
|
|
128
|
-
} = _ref3;
|
|
129
|
-
return name;
|
|
130
|
-
});
|
|
131
|
-
const modes = data.map(_ref4 => {
|
|
132
|
-
let {
|
|
133
|
-
mode
|
|
134
|
-
} = _ref4;
|
|
135
|
-
return mode;
|
|
136
|
-
});
|
|
137
|
-
const polygons = data.map(_ref5 => {
|
|
138
|
-
let {
|
|
139
|
-
points
|
|
140
|
-
} = _ref5;
|
|
141
|
-
return pointsToString(points, origin);
|
|
142
|
-
});
|
|
143
|
-
return Promise.resolve({
|
|
144
|
-
success: true,
|
|
145
|
-
errCode: 0,
|
|
146
|
-
reqType: VirtualAreaEnum.query,
|
|
147
|
-
version: commandVersion,
|
|
148
|
-
taskId: `${Date.now()}`,
|
|
149
|
-
num: data.length,
|
|
150
|
-
modes,
|
|
151
|
-
polygons,
|
|
152
|
-
names,
|
|
153
|
-
mapId: 0
|
|
154
|
-
});
|
|
155
|
-
} catch (error) {
|
|
156
|
-
throw error instanceof Error ? error : new Error('Failed to set virtual area');
|
|
157
|
-
}
|
|
147
|
+
});
|
|
158
148
|
}
|
|
159
149
|
};
|
|
160
150
|
};
|
|
@@ -1,25 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Point } from '@ray-js/robot-protocol';
|
|
3
|
-
interface VirtualWallResponse extends BaseResponse {
|
|
4
|
-
reqType: VirtualWallEnum.query;
|
|
5
|
-
modes: number[];
|
|
6
|
-
num: number;
|
|
7
|
-
mapId: number;
|
|
8
|
-
points: string[];
|
|
9
|
-
}
|
|
10
|
-
interface SetVirtualWallParams {
|
|
11
|
-
data: Point[][];
|
|
12
|
-
origin: Point;
|
|
13
|
-
}
|
|
14
|
-
type TRequestVirtualWall = () => Promise<VirtualWallResponse>;
|
|
15
|
-
type TSetVirtualWall = (params: SetVirtualWallParams) => Promise<VirtualWallResponse>;
|
|
1
|
+
import { type TRequestVirtualWall, type TSetVirtualWall } from './type/protocols';
|
|
16
2
|
/**
|
|
17
3
|
* 自定义 Hook,用于虚拟墙管理
|
|
18
|
-
* @param devId 设备ID
|
|
19
4
|
* @returns 包含 requestVirtualWall 和 setVirtualWall 函数的对象
|
|
20
5
|
*/
|
|
21
|
-
export declare const useVirtualWall: (
|
|
6
|
+
export declare const useVirtualWall: () => {
|
|
22
7
|
requestVirtualWall: TRequestVirtualWall;
|
|
23
8
|
setVirtualWall: TSetVirtualWall;
|
|
24
9
|
};
|
|
25
|
-
export {};
|