@ray-js/robot-data-stream 0.0.13-beta-5 → 0.0.13-beta-7
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/index.d.ts +12 -2
- package/lib/api/index.js +172 -1
- package/lib/api/p2pApi.d.ts +27 -8
- package/lib/api/p2pApi.js +169 -271
- package/lib/api/sweeperP2p.d.ts +23 -49
- package/lib/api/sweeperP2p.js +248 -311
- package/lib/constant.d.ts +52 -0
- package/lib/constant.js +54 -0
- package/lib/index.d.ts +1 -10
- package/lib/index.js +2 -165
- package/lib/mqtt/createCommonOptions.d.ts +56 -15
- package/lib/mqtt/createCommonOptions.js +44 -8
- package/lib/mqtt/index.d.ts +2 -1
- package/lib/mqtt/index.js +2 -1
- package/lib/mqtt/mqttProvider.d.ts +23 -15
- package/lib/mqtt/mqttProvider.js +63 -26
- package/lib/mqtt/promise.js +8 -3
- package/lib/mqtt/type/index.d.ts +14 -0
- package/lib/mqtt/type/index.js +14 -0
- package/lib/mqtt/type/requestType.d.ts +8 -0
- package/lib/mqtt/type/requestType.js +10 -0
- package/lib/mqtt/useDevInfo.d.ts +2 -7
- package/lib/mqtt/useDevInfo.js +25 -9
- package/lib/mqtt/useHistoryMap.d.ts +13 -21
- package/lib/mqtt/useHistoryMap.js +82 -32
- package/lib/mqtt/usePartDivision.d.ts +5 -7
- package/lib/mqtt/usePartDivision.js +41 -16
- package/lib/mqtt/usePartMerge.d.ts +5 -7
- package/lib/mqtt/usePartMerge.js +36 -18
- package/lib/mqtt/usePassword.js +59 -28
- package/lib/mqtt/useQuiteHours.d.ts +9 -24
- package/lib/mqtt/useQuiteHours.js +95 -52
- package/lib/mqtt/useResetMap.d.ts +10 -7
- package/lib/mqtt/useResetMap.js +40 -11
- package/lib/mqtt/useRoomProperty.js +23 -16
- package/lib/mqtt/useSchedule.d.ts +17 -4
- package/lib/mqtt/useSchedule.js +101 -49
- package/lib/mqtt/useSelectRoomClean.d.ts +20 -16
- package/lib/mqtt/useSelectRoomClean.js +145 -49
- package/lib/mqtt/useSpotClean.d.ts +3 -3
- package/lib/mqtt/useSpotClean.js +72 -50
- package/lib/mqtt/useVirtualArea.d.ts +6 -9
- package/lib/mqtt/useVirtualArea.js +112 -42
- package/lib/mqtt/useVirtualWall.d.ts +13 -10
- package/lib/mqtt/useVirtualWall.js +97 -34
- package/lib/mqtt/useVoice.d.ts +3 -6
- package/lib/mqtt/useVoice.js +73 -33
- package/lib/mqtt/useWifiMap.d.ts +8 -0
- package/lib/mqtt/useWifiMap.js +53 -0
- package/lib/mqtt/useZoneClean.d.ts +13 -13
- package/lib/mqtt/useZoneClean.js +149 -76
- package/lib/ttt/index.d.ts +153 -0
- package/lib/ttt/index.js +458 -0
- package/lib/utils/index.d.ts +20 -1
- package/lib/utils/index.js +19 -0
- package/package.json +1 -1
- package/lib/mqtt/myError.d.ts +0 -4
- package/lib/mqtt/myError.js +0 -6
package/lib/mqtt/type/index.d.ts
CHANGED
|
@@ -6,6 +6,15 @@ export interface BaseResponse {
|
|
|
6
6
|
version: string;
|
|
7
7
|
taskId: string;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* MQTT 协议号枚举
|
|
11
|
+
*/
|
|
12
|
+
export declare enum ProtocolEnum {
|
|
13
|
+
/** 面板下发 */
|
|
14
|
+
appToRobot = 64,
|
|
15
|
+
/** 设备上报 */
|
|
16
|
+
robotToApp = 65
|
|
17
|
+
}
|
|
9
18
|
export declare enum PasswordEnum {
|
|
10
19
|
query = "passwordQry",
|
|
11
20
|
set = "passwordSet",
|
|
@@ -13,6 +22,11 @@ export declare enum PasswordEnum {
|
|
|
13
22
|
check = "passwordCheck",
|
|
14
23
|
checkRst = "passwordCheckRst"
|
|
15
24
|
}
|
|
25
|
+
export declare enum WifiMapEnum {
|
|
26
|
+
query = "WifiMapQry",
|
|
27
|
+
set = "WifiMapSet",
|
|
28
|
+
rst = "WifiMapRst"
|
|
29
|
+
}
|
|
16
30
|
export type RoomPreference = {
|
|
17
31
|
suctions?: string[];
|
|
18
32
|
cisterns?: string[];
|
package/lib/mqtt/type/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
export * from './requestType';
|
|
2
2
|
// 设备接口响应的统一标准结构
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* MQTT 协议号枚举
|
|
6
|
+
*/
|
|
7
|
+
export let ProtocolEnum = /*#__PURE__*/function (ProtocolEnum) {
|
|
8
|
+
ProtocolEnum[ProtocolEnum["appToRobot"] = 64] = "appToRobot";
|
|
9
|
+
ProtocolEnum[ProtocolEnum["robotToApp"] = 65] = "robotToApp";
|
|
10
|
+
return ProtocolEnum;
|
|
11
|
+
}({});
|
|
4
12
|
export let PasswordEnum = /*#__PURE__*/function (PasswordEnum) {
|
|
5
13
|
PasswordEnum["query"] = "passwordQry";
|
|
6
14
|
PasswordEnum["set"] = "passwordSet";
|
|
@@ -8,4 +16,10 @@ export let PasswordEnum = /*#__PURE__*/function (PasswordEnum) {
|
|
|
8
16
|
PasswordEnum["check"] = "passwordCheck";
|
|
9
17
|
PasswordEnum["checkRst"] = "passwordCheckRst";
|
|
10
18
|
return PasswordEnum;
|
|
19
|
+
}({});
|
|
20
|
+
export let WifiMapEnum = /*#__PURE__*/function (WifiMapEnum) {
|
|
21
|
+
WifiMapEnum["query"] = "WifiMapQry";
|
|
22
|
+
WifiMapEnum["set"] = "WifiMapSet";
|
|
23
|
+
WifiMapEnum["rst"] = "WifiMapRst";
|
|
24
|
+
return WifiMapEnum;
|
|
11
25
|
}({});
|
|
@@ -21,6 +21,11 @@ export declare enum PasswordEnum {
|
|
|
21
21
|
check = "passwordCheck",
|
|
22
22
|
checkRst = "passwordCheckRst"
|
|
23
23
|
}
|
|
24
|
+
export declare enum WifiMapEnum {
|
|
25
|
+
query = "WifiMapQry",
|
|
26
|
+
set = "WifiMapSet",
|
|
27
|
+
rst = "WifiMapRst"
|
|
28
|
+
}
|
|
24
29
|
export declare enum RoomPropertyEnum {
|
|
25
30
|
set = "roomPropertySet",
|
|
26
31
|
query = "roomPropertyQry"
|
|
@@ -65,3 +70,6 @@ export declare enum UseMapEnum {
|
|
|
65
70
|
query = "useMapRst",
|
|
66
71
|
set = "useMapSet"
|
|
67
72
|
}
|
|
73
|
+
export declare enum DevInfoEnum {
|
|
74
|
+
query = "devInfoQry"
|
|
75
|
+
}
|
|
@@ -32,6 +32,12 @@ export let PasswordEnum = /*#__PURE__*/function (PasswordEnum) {
|
|
|
32
32
|
PasswordEnum["checkRst"] = "passwordCheckRst";
|
|
33
33
|
return PasswordEnum;
|
|
34
34
|
}({});
|
|
35
|
+
export let WifiMapEnum = /*#__PURE__*/function (WifiMapEnum) {
|
|
36
|
+
WifiMapEnum["query"] = "WifiMapQry";
|
|
37
|
+
WifiMapEnum["set"] = "WifiMapSet";
|
|
38
|
+
WifiMapEnum["rst"] = "WifiMapRst";
|
|
39
|
+
return WifiMapEnum;
|
|
40
|
+
}({});
|
|
35
41
|
export let RoomPropertyEnum = /*#__PURE__*/function (RoomPropertyEnum) {
|
|
36
42
|
RoomPropertyEnum["set"] = "roomPropertySet";
|
|
37
43
|
RoomPropertyEnum["query"] = "roomPropertyQry";
|
|
@@ -98,4 +104,8 @@ export let UseMapEnum = /*#__PURE__*/function (UseMapEnum) {
|
|
|
98
104
|
UseMapEnum["query"] = "useMapRst";
|
|
99
105
|
UseMapEnum["set"] = "useMapSet";
|
|
100
106
|
return UseMapEnum;
|
|
107
|
+
}({});
|
|
108
|
+
export let DevInfoEnum = /*#__PURE__*/function (DevInfoEnum) {
|
|
109
|
+
DevInfoEnum["query"] = "devInfoQry";
|
|
110
|
+
return DevInfoEnum;
|
|
101
111
|
}({});
|
package/lib/mqtt/useDevInfo.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
version?: string;
|
|
1
|
+
import { BaseResponse } from './type';
|
|
2
|
+
export interface DevInfoResponse extends BaseResponse {
|
|
4
3
|
info: string;
|
|
5
|
-
success?: boolean;
|
|
6
|
-
errCode?: number;
|
|
7
|
-
taskId?: string;
|
|
8
4
|
}
|
|
9
5
|
export declare const useDevInfo: (devId: string) => {
|
|
10
6
|
requestDevInfo: () => Promise<DevInfoResponse>;
|
|
11
7
|
};
|
|
12
|
-
export {};
|
package/lib/mqtt/useDevInfo.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { hexToUriDecodedString } from '@ray-js/robot-protocol';
|
|
1
2
|
import { useContext } from 'react';
|
|
2
3
|
import { createSetCommonParams } from './createCommonOptions';
|
|
3
4
|
import { SingletonContext } from './mqttProvider';
|
|
4
5
|
import { normalResolve } from './promise';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}(DevInfoEnum || {});
|
|
6
|
+
import { DevInfoEnum } from './type';
|
|
7
|
+
|
|
8
|
+
// 设备信息响应类型
|
|
9
|
+
|
|
10
10
|
// 请求设备信息
|
|
11
11
|
export const useDevInfo = devId => {
|
|
12
12
|
const {
|
|
@@ -27,10 +27,26 @@ export const useDevInfo = devId => {
|
|
|
27
27
|
} = params.message;
|
|
28
28
|
return normalResolve(DevInfoEnum.query, taskId);
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
|
|
31
|
+
// 非 MQTT 模式:从设备属性中获取设备信息
|
|
32
|
+
try {
|
|
33
|
+
var _devices$common$model;
|
|
34
|
+
const dpDevInfo = (_devices$common$model = devices.common.model.props) === null || _devices$common$model === void 0 ? void 0 : _devices$common$model.device_info;
|
|
35
|
+
if (!dpDevInfo) {
|
|
36
|
+
return Promise.reject(new Error('Device info is not available in device properties'));
|
|
37
|
+
}
|
|
38
|
+
const info = hexToUriDecodedString(dpDevInfo);
|
|
39
|
+
return Promise.resolve({
|
|
40
|
+
info,
|
|
41
|
+
success: true,
|
|
42
|
+
errCode: 0,
|
|
43
|
+
reqType: DevInfoEnum.query,
|
|
44
|
+
version: '1.0.0',
|
|
45
|
+
taskId: `${Date.now()}`
|
|
46
|
+
});
|
|
47
|
+
} catch (error) {
|
|
48
|
+
return Promise.reject(error instanceof Error ? error : new Error('Failed to get device info from device properties'));
|
|
49
|
+
}
|
|
34
50
|
}
|
|
35
51
|
};
|
|
36
52
|
};
|
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}>;
|
|
8
|
-
type TChangeCurrentMap = (mapId: number, url: string) => Promise<{
|
|
9
|
-
success: boolean;
|
|
10
|
-
errCode: number;
|
|
11
|
-
reqType: string;
|
|
1
|
+
import { BaseResponse, DeleteMapEnum, SaveCurrentMapEnum, UseMapEnum } from './type';
|
|
2
|
+
interface DeleteMapResponse extends BaseResponse {
|
|
3
|
+
reqType: DeleteMapEnum.rst;
|
|
4
|
+
}
|
|
5
|
+
interface SaveMapResponse extends BaseResponse {
|
|
6
|
+
reqType: SaveCurrentMapEnum.query;
|
|
12
7
|
mapId: number;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type TSaveMap = () => Promise<{
|
|
17
|
-
success: boolean;
|
|
18
|
-
errCode: number;
|
|
19
|
-
reqType: string;
|
|
8
|
+
}
|
|
9
|
+
interface UseMapResponse extends BaseResponse {
|
|
10
|
+
reqType: UseMapEnum.query;
|
|
20
11
|
mapId: number;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
}
|
|
13
|
+
type TDeleteHistoryMap = (mapId: number) => Promise<DeleteMapResponse>;
|
|
14
|
+
type TSaveMap = () => Promise<SaveMapResponse>;
|
|
15
|
+
type TChangeCurrentMap = (mapId: number, url: string) => Promise<UseMapResponse>;
|
|
24
16
|
/**
|
|
25
17
|
* 自定义 Hook,用于管理历史地图
|
|
26
18
|
* @param devId 设备ID
|
|
@@ -6,8 +6,16 @@ import { DeleteMapEnum, SaveCurrentMapEnum, UseMapEnum } from './type';
|
|
|
6
6
|
import { SingletonContext } from './mqttProvider';
|
|
7
7
|
import { encodeDeleteMap0x2c, encodeSaveMap0x2a, encodeUseMap0x2e } from '@ray-js/robot-protocol';
|
|
8
8
|
|
|
9
|
+
// 删除历史地图响应类型
|
|
10
|
+
|
|
11
|
+
// 保存地图响应类型
|
|
12
|
+
|
|
13
|
+
// 更改当前地图响应类型
|
|
14
|
+
|
|
9
15
|
// 删除历史地图函数类型定义
|
|
10
16
|
|
|
17
|
+
// 保存当前地图函数类型定义
|
|
18
|
+
|
|
11
19
|
// 更改当前使用的地图函数类型定义
|
|
12
20
|
|
|
13
21
|
/**
|
|
@@ -18,32 +26,36 @@ import { encodeDeleteMap0x2c, encodeSaveMap0x2a, encodeUseMap0x2e } from '@ray-j
|
|
|
18
26
|
export const useHistoryMap = devId => {
|
|
19
27
|
const {
|
|
20
28
|
useMqtt,
|
|
21
|
-
devices
|
|
29
|
+
devices,
|
|
30
|
+
commandVersion
|
|
22
31
|
} = useContext(SingletonContext);
|
|
32
|
+
|
|
23
33
|
/**
|
|
24
34
|
* 删除历史地图
|
|
25
35
|
* @param mapId 地图ID
|
|
26
|
-
* @returns Promise<
|
|
36
|
+
* @returns Promise<DeleteMapResponse> 响应结果
|
|
27
37
|
*/
|
|
28
38
|
|
|
29
39
|
/**
|
|
30
40
|
* 保存当前地图
|
|
31
|
-
* @returns Promise<
|
|
41
|
+
* @returns Promise<SaveMapResponse> 响应结果
|
|
32
42
|
*/
|
|
33
43
|
|
|
34
44
|
/**
|
|
35
45
|
* 更改当前使用的地图
|
|
36
46
|
* @param mapId 地图ID
|
|
37
47
|
* @param url 地图URL
|
|
38
|
-
* @returns Promise<
|
|
48
|
+
* @returns Promise<UseMapResponse> 响应结果
|
|
39
49
|
*/
|
|
40
50
|
|
|
41
51
|
return {
|
|
42
52
|
deleteHistoryMap: async mapId => {
|
|
53
|
+
// 参数验证
|
|
54
|
+
if (!mapId || typeof mapId !== 'number') {
|
|
55
|
+
throw new Error('mapId is required and must be a number');
|
|
56
|
+
}
|
|
43
57
|
try {
|
|
44
|
-
|
|
45
|
-
return Promise.reject(new Error('mapId is required'));
|
|
46
|
-
}
|
|
58
|
+
// 先删除地图文件
|
|
47
59
|
await deleteMultipleMapFile(mapId, devId);
|
|
48
60
|
if (useMqtt) {
|
|
49
61
|
const params = createSetCommonParams({
|
|
@@ -59,28 +71,41 @@ export const useHistoryMap = devId => {
|
|
|
59
71
|
} = params.message;
|
|
60
72
|
return normalResolve(DeleteMapEnum.rst, taskId);
|
|
61
73
|
}
|
|
74
|
+
|
|
75
|
+
// 非 MQTT 模式:使用命令传输
|
|
62
76
|
const command = encodeDeleteMap0x2c({
|
|
63
77
|
id: mapId
|
|
64
78
|
});
|
|
65
79
|
devices.common.model.actions.command_trans.set(command);
|
|
66
|
-
return Promise.resolve(
|
|
67
|
-
|
|
68
|
-
|
|
80
|
+
return Promise.resolve({
|
|
81
|
+
success: true,
|
|
82
|
+
errCode: 0,
|
|
83
|
+
reqType: DeleteMapEnum.rst,
|
|
84
|
+
version: commandVersion,
|
|
85
|
+
taskId: `${Date.now()}`
|
|
86
|
+
});
|
|
87
|
+
} catch (error) {
|
|
88
|
+
throw error instanceof Error ? error : new Error('Failed to delete history map');
|
|
69
89
|
}
|
|
70
90
|
},
|
|
71
91
|
changeCurrentMap: async (mapId, url) => {
|
|
92
|
+
// 参数验证
|
|
93
|
+
if (!mapId || typeof mapId !== 'number') {
|
|
94
|
+
throw new Error('mapId is required and must be a number');
|
|
95
|
+
}
|
|
96
|
+
if (!url || typeof url !== 'string') {
|
|
97
|
+
throw new Error('url is required and must be a string');
|
|
98
|
+
}
|
|
72
99
|
try {
|
|
73
100
|
if (useMqtt) {
|
|
74
|
-
const sendData = {
|
|
75
|
-
reqType: UseMapEnum.set,
|
|
76
|
-
mapId,
|
|
77
|
-
url,
|
|
78
|
-
urlLen: url.length
|
|
79
|
-
};
|
|
80
101
|
const params = createSetCommonParams({
|
|
81
102
|
deviceId: devId,
|
|
82
103
|
reqType: UseMapEnum.set,
|
|
83
|
-
message:
|
|
104
|
+
message: {
|
|
105
|
+
mapId,
|
|
106
|
+
url,
|
|
107
|
+
urlLen: url.length // URL 长度
|
|
108
|
+
}
|
|
84
109
|
});
|
|
85
110
|
ty.device.sendMqttMessage(params);
|
|
86
111
|
const {
|
|
@@ -88,31 +113,56 @@ export const useHistoryMap = devId => {
|
|
|
88
113
|
} = params.message;
|
|
89
114
|
return normalResolve(UseMapEnum.query, taskId);
|
|
90
115
|
}
|
|
116
|
+
|
|
117
|
+
// 非 MQTT 模式:使用命令传输
|
|
91
118
|
const command = encodeUseMap0x2e({
|
|
92
119
|
mapId,
|
|
93
120
|
url
|
|
94
121
|
});
|
|
95
122
|
devices.common.model.actions.command_trans.set(command);
|
|
96
|
-
return Promise.resolve(
|
|
97
|
-
|
|
98
|
-
|
|
123
|
+
return Promise.resolve({
|
|
124
|
+
success: true,
|
|
125
|
+
errCode: 0,
|
|
126
|
+
reqType: UseMapEnum.query,
|
|
127
|
+
version: commandVersion,
|
|
128
|
+
taskId: `${Date.now()}`,
|
|
129
|
+
mapId
|
|
130
|
+
});
|
|
131
|
+
} catch (error) {
|
|
132
|
+
throw error instanceof Error ? error : new Error('Failed to change current map');
|
|
99
133
|
}
|
|
100
134
|
},
|
|
101
135
|
saveMap: () => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
136
|
+
try {
|
|
137
|
+
if (useMqtt) {
|
|
138
|
+
const params = createSetCommonParams({
|
|
139
|
+
deviceId: devId,
|
|
140
|
+
reqType: SaveCurrentMapEnum.set,
|
|
141
|
+
message: {
|
|
142
|
+
oper: 0 // 操作类型:0 表示保存
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
ty.device.sendMqttMessage(params);
|
|
146
|
+
const {
|
|
147
|
+
taskId
|
|
148
|
+
} = params.message;
|
|
149
|
+
return normalResolve(SaveCurrentMapEnum.query, taskId);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// 非 MQTT 模式:使用命令传输
|
|
153
|
+
const command = encodeSaveMap0x2a(1);
|
|
154
|
+
devices.common.model.actions.command_trans.set(command);
|
|
155
|
+
return Promise.resolve({
|
|
156
|
+
success: true,
|
|
157
|
+
errCode: 0,
|
|
158
|
+
reqType: SaveCurrentMapEnum.query,
|
|
159
|
+
version: commandVersion,
|
|
160
|
+
taskId: `${Date.now()}`,
|
|
161
|
+
mapId: 0 // 非 MQTT 模式下无法获取 mapId
|
|
109
162
|
});
|
|
110
|
-
|
|
111
|
-
|
|
163
|
+
} catch (error) {
|
|
164
|
+
throw error instanceof Error ? error : new Error('Failed to save current map');
|
|
112
165
|
}
|
|
113
|
-
const command = encodeSaveMap0x2a(1);
|
|
114
|
-
devices.common.model.actions.command_trans.set(command);
|
|
115
|
-
return Promise.resolve();
|
|
116
166
|
}
|
|
117
167
|
};
|
|
118
168
|
};
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { Point } from '../utils';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
taskId: string;
|
|
8
|
-
} | void>;
|
|
2
|
+
import { BaseResponse, PartDivisionEnum } from './type';
|
|
3
|
+
interface PartDivisionResponse extends BaseResponse {
|
|
4
|
+
reqType: PartDivisionEnum.query;
|
|
5
|
+
}
|
|
6
|
+
type TSetPartDivision = (points: Point[], roomId: number, origin: Point) => Promise<PartDivisionResponse>;
|
|
9
7
|
/**
|
|
10
8
|
* 自定义 Hook,用于房间分隔
|
|
11
9
|
* @param devId 设备ID
|
|
@@ -7,6 +7,8 @@ import { PartDivisionEnum } from './type';
|
|
|
7
7
|
import { SingletonContext } from './mqttProvider';
|
|
8
8
|
import { encodePartitionDivision0x1c } from '@ray-js/robot-protocol';
|
|
9
9
|
|
|
10
|
+
// 房间分隔响应类型
|
|
11
|
+
|
|
10
12
|
// 设置房间分隔函数类型定义
|
|
11
13
|
|
|
12
14
|
/**
|
|
@@ -24,38 +26,61 @@ export const usePartDivision = devId => {
|
|
|
24
26
|
/**
|
|
25
27
|
* 设置房间分隔
|
|
26
28
|
* @param points 分隔点数组,SDK方法抛出来的坐标直接传入即可
|
|
27
|
-
* @param roomId 房间ID
|
|
29
|
+
* @param roomId 房间ID,当前要分隔的房间
|
|
28
30
|
* @param origin 地图原点坐标
|
|
29
|
-
* @returns Promise<
|
|
31
|
+
* @returns Promise<PartDivisionResponse> 响应结果
|
|
30
32
|
*/
|
|
31
33
|
|
|
32
34
|
return {
|
|
33
35
|
setPartDivision: (points, roomId, origin) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
// 参数验证
|
|
37
|
+
if (!Array.isArray(points) || points.length === 0) {
|
|
38
|
+
throw new Error('points is required and must be a non-empty array');
|
|
39
|
+
}
|
|
40
|
+
if (typeof roomId !== 'number' || isNaN(roomId)) {
|
|
41
|
+
throw new Error('roomId is required and must be a valid number');
|
|
42
|
+
}
|
|
43
|
+
if (!origin || typeof origin.x !== 'number' || typeof origin.y !== 'number') {
|
|
44
|
+
throw new Error('origin is required and must be a valid Point object with x and y properties');
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
if (useMqtt) {
|
|
48
|
+
// 将点数组转换为字符串格式
|
|
36
49
|
const pointStr = pointsToString(points, origin);
|
|
37
50
|
const params = createSetCommonParams({
|
|
38
51
|
deviceId: devId,
|
|
39
52
|
reqType: PartDivisionEnum.set,
|
|
40
53
|
message: {
|
|
41
54
|
lines: [pointStr],
|
|
42
|
-
|
|
55
|
+
// 分隔线数组
|
|
56
|
+
ids: [roomId] // 房间ID数组
|
|
43
57
|
}
|
|
44
58
|
});
|
|
45
59
|
ty.device.sendMqttMessage(params);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
const {
|
|
61
|
+
taskId
|
|
62
|
+
} = params.message;
|
|
63
|
+
return normalResolve(PartDivisionEnum.query, taskId);
|
|
49
64
|
}
|
|
65
|
+
|
|
66
|
+
// 非 MQTT 模式:使用命令传输
|
|
67
|
+
const command = encodePartitionDivision0x1c({
|
|
68
|
+
version: commandVersion,
|
|
69
|
+
origin,
|
|
70
|
+
points,
|
|
71
|
+
roomId
|
|
72
|
+
});
|
|
73
|
+
devices.common.model.actions.command_trans.set(command);
|
|
74
|
+
return Promise.resolve({
|
|
75
|
+
success: true,
|
|
76
|
+
errCode: 0,
|
|
77
|
+
reqType: PartDivisionEnum.query,
|
|
78
|
+
version: commandVersion,
|
|
79
|
+
taskId: `${Date.now()}`
|
|
80
|
+
});
|
|
81
|
+
} catch (error) {
|
|
82
|
+
throw error instanceof Error ? error : new Error('Failed to set part division');
|
|
50
83
|
}
|
|
51
|
-
const command = encodePartitionDivision0x1c({
|
|
52
|
-
version: commandVersion,
|
|
53
|
-
origin,
|
|
54
|
-
points,
|
|
55
|
-
roomId
|
|
56
|
-
});
|
|
57
|
-
devices.common.model.actions.command_trans.set(command);
|
|
58
|
-
return Promise.resolve();
|
|
59
84
|
}
|
|
60
85
|
};
|
|
61
86
|
};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
taskId: string;
|
|
7
|
-
} | void>;
|
|
1
|
+
import { BaseResponse, PartMergeEnum } from './type';
|
|
2
|
+
interface PartMergeResponse extends BaseResponse {
|
|
3
|
+
reqType: PartMergeEnum.query;
|
|
4
|
+
}
|
|
5
|
+
type TSetPartMerge = (ids: number[]) => Promise<PartMergeResponse>;
|
|
8
6
|
/**
|
|
9
7
|
* 自定义 Hook,用于分区合并
|
|
10
8
|
* @param devId 设备ID
|
package/lib/mqtt/usePartMerge.js
CHANGED
|
@@ -8,6 +8,8 @@ import { PartMergeEnum } from './type';
|
|
|
8
8
|
import { SingletonContext } from './mqttProvider';
|
|
9
9
|
import { encodePartitionMerge0x1e } from '@ray-js/robot-protocol';
|
|
10
10
|
|
|
11
|
+
// 分区合并响应类型
|
|
12
|
+
|
|
11
13
|
// 设置分区合并函数类型定义
|
|
12
14
|
|
|
13
15
|
/**
|
|
@@ -24,34 +26,50 @@ export const usePartMerge = devId => {
|
|
|
24
26
|
/**
|
|
25
27
|
* 设置分区合并
|
|
26
28
|
* @param ids 要合并的分区ID数组
|
|
27
|
-
* @returns Promise<
|
|
29
|
+
* @returns Promise<PartMergeResponse> 响应结果
|
|
28
30
|
*/
|
|
29
31
|
|
|
30
32
|
return {
|
|
31
33
|
setPartMerge: ids => {
|
|
34
|
+
// 参数验证
|
|
32
35
|
if (!ids || ids.length < 2) {
|
|
33
|
-
|
|
36
|
+
throw new Error('ids is required and length must be greater than 1');
|
|
34
37
|
}
|
|
35
38
|
if (ids.some(id => typeof id !== 'number')) {
|
|
36
|
-
|
|
39
|
+
throw new Error('ids must be an array of numbers');
|
|
37
40
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
try {
|
|
42
|
+
if (useMqtt) {
|
|
43
|
+
const params = createSetCommonParams({
|
|
44
|
+
deviceId: devId,
|
|
45
|
+
reqType: PartMergeEnum.set,
|
|
46
|
+
message: {
|
|
47
|
+
ids
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
ty.device.sendMqttMessage(params);
|
|
51
|
+
const {
|
|
52
|
+
taskId
|
|
53
|
+
} = params.message;
|
|
54
|
+
return normalResolve(PartMergeEnum.query, taskId);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 非 MQTT 模式:使用命令传输
|
|
58
|
+
const command = encodePartitionMerge0x1e({
|
|
59
|
+
version: commandVersion,
|
|
60
|
+
roomIds: ids
|
|
61
|
+
});
|
|
62
|
+
devices.common.model.actions.command_trans.set(command);
|
|
63
|
+
return Promise.resolve({
|
|
64
|
+
success: true,
|
|
65
|
+
errCode: 0,
|
|
66
|
+
reqType: PartMergeEnum.query,
|
|
67
|
+
version: commandVersion,
|
|
68
|
+
taskId: `${Date.now()}`
|
|
45
69
|
});
|
|
46
|
-
|
|
47
|
-
|
|
70
|
+
} catch (error) {
|
|
71
|
+
throw error instanceof Error ? error : new Error('Failed to set part merge');
|
|
48
72
|
}
|
|
49
|
-
const command = encodePartitionMerge0x1e({
|
|
50
|
-
version: commandVersion,
|
|
51
|
-
roomIds: ids
|
|
52
|
-
});
|
|
53
|
-
devices.common.model.actions.command_trans.set(command);
|
|
54
|
-
return Promise.resolve();
|
|
55
73
|
}
|
|
56
74
|
};
|
|
57
75
|
};
|