@ray-js/robot-data-stream 0.0.14 → 0.0.15-beta.10
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.js +1 -1
- package/lib/mqtt/createCommonOptions.d.ts +4 -2
- package/lib/mqtt/createCommonOptions.js +10 -5
- package/lib/mqtt/hooks/useStructuredMessage.d.ts +17 -0
- package/lib/mqtt/hooks/useStructuredMessage.js +206 -0
- package/lib/mqtt/mqttProvider.d.ts +28 -1
- package/lib/mqtt/mqttProvider.js +72 -9
- package/lib/mqtt/promise.d.ts +57 -4
- package/lib/mqtt/promise.js +115 -36
- package/lib/mqtt/type/fun.d.ts +233 -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 +21 -0
- package/lib/mqtt/type/protocols/base.js +32 -0
- package/lib/mqtt/type/protocols/carpetCleanProtocol.d.ts +14 -0
- package/lib/mqtt/type/protocols/carpetCleanProtocol.js +14 -0
- package/lib/mqtt/type/protocols/carpetProtocol.d.ts +102 -0
- package/lib/mqtt/type/protocols/carpetProtocol.js +202 -0
- package/lib/mqtt/type/protocols/devInfoProtocol.d.ts +11 -0
- package/lib/mqtt/type/protocols/devInfoProtocol.js +10 -0
- package/lib/mqtt/type/protocols/deviceModelProtocol.d.ts +31 -0
- package/lib/mqtt/type/protocols/deviceModelProtocol.js +32 -0
- package/lib/mqtt/type/protocols/furnitureModelProtocol.d.ts +27 -0
- package/lib/mqtt/type/protocols/furnitureModelProtocol.js +27 -0
- package/lib/mqtt/type/protocols/historyMapProtocol.d.ts +39 -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 +20 -0
- package/lib/mqtt/type/protocols/partDivisionProtocol.js +12 -0
- package/lib/mqtt/type/protocols/partMergeProtocol.d.ts +13 -0
- package/lib/mqtt/type/protocols/partMergeProtocol.js +12 -0
- package/lib/mqtt/type/protocols/passwordProtocol.d.ts +24 -0
- package/lib/mqtt/type/protocols/passwordProtocol.js +25 -0
- package/lib/mqtt/type/protocols/quietHoursProtocol.d.ts +29 -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 +42 -0
- package/lib/mqtt/type/protocols/roomPropertyProtocol.js +113 -0
- package/lib/mqtt/type/protocols/scheduleProtocol.d.ts +62 -0
- package/lib/mqtt/type/protocols/scheduleProtocol.js +100 -0
- package/lib/mqtt/type/protocols/selectRoomCleanProtocol.d.ts +27 -0
- package/lib/mqtt/type/protocols/selectRoomCleanProtocol.js +40 -0
- package/lib/mqtt/type/protocols/spotCleanProtocol.d.ts +38 -0
- package/lib/mqtt/type/protocols/spotCleanProtocol.js +72 -0
- package/lib/mqtt/type/protocols/virtualAreaProtocol.d.ts +32 -0
- package/lib/mqtt/type/protocols/virtualAreaProtocol.js +36 -0
- package/lib/mqtt/type/protocols/virtualWallProtocol.d.ts +27 -0
- package/lib/mqtt/type/protocols/virtualWallProtocol.js +25 -0
- package/lib/mqtt/type/protocols/voiceProtocol.d.ts +21 -0
- package/lib/mqtt/type/protocols/voiceProtocol.js +23 -0
- package/lib/mqtt/type/protocols/wifiMapProtocol.d.ts +16 -0
- package/lib/mqtt/type/protocols/wifiMapProtocol.js +14 -0
- package/lib/mqtt/type/protocols/zoneCleanProtocol.d.ts +47 -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 +26 -50
- 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 +31 -42
- package/lib/mqtt/useFurnitureModel.d.ts +6 -18
- package/lib/mqtt/useFurnitureModel.js +31 -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 +530 -0
- package/lib/myLib/zod/src/v4/mini/index.js +30 -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
|
@@ -1,60 +1,49 @@
|
|
|
1
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
2
|
-
import { normalResolve } from './promise';
|
|
3
1
|
import { DeviceModelEnum } from './type/requestType';
|
|
2
|
+
import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
|
|
3
|
+
import { validator } from './type/fun';
|
|
4
|
+
/**
|
|
5
|
+
* 自定义 Hook,用于设备模型管理
|
|
6
|
+
* @returns 包含 requestDeviceList 和 setDeviceModel 函数的对象
|
|
7
|
+
*/
|
|
8
|
+
export const useDeviceModel = () => {
|
|
9
|
+
const {
|
|
10
|
+
sendStructuredMessage
|
|
11
|
+
} = useStructuredMessage();
|
|
4
12
|
|
|
5
|
-
// 请求设备列表函数定义
|
|
6
|
-
|
|
7
|
-
// 设置设备模型函数定义
|
|
8
|
-
|
|
9
|
-
export const useDeviceModel = devId => {
|
|
10
13
|
/**
|
|
11
14
|
* 请求设备列表
|
|
15
|
+
* @param data 可选参数(目前为空对象)
|
|
12
16
|
* @returns Promise<DeviceModelResponse> 响应结果
|
|
13
17
|
*/
|
|
14
18
|
|
|
15
19
|
/**
|
|
16
20
|
* 设置设备模型
|
|
17
|
-
* @param
|
|
21
|
+
* @param data 包含设备模型信息数组的对象
|
|
18
22
|
* @returns Promise<DeviceModelResponse> 响应结果
|
|
19
23
|
*/
|
|
20
24
|
|
|
21
25
|
return {
|
|
22
26
|
requestDeviceList: () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} = params.message;
|
|
31
|
-
ty.device.sendMqttMessage(params);
|
|
32
|
-
return normalResolve(DeviceModelEnum.query, taskId);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
return Promise.reject(error instanceof Error ? error : new Error('Failed to request device list'));
|
|
35
|
-
}
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
try {
|
|
29
|
+
sendStructuredMessage(DeviceModelEnum.query, {}, resolve, error => reject(handleMqttError(error, 'Failed to request device list')));
|
|
30
|
+
} catch (error) {
|
|
31
|
+
reject(handleMqttError(error, 'Failed to request device list'));
|
|
32
|
+
}
|
|
33
|
+
});
|
|
36
34
|
},
|
|
37
|
-
setDeviceModel:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
ty.device.sendMqttMessage(params);
|
|
51
|
-
const {
|
|
52
|
-
taskId
|
|
53
|
-
} = params.message;
|
|
54
|
-
return normalResolve(DeviceModelEnum.query, taskId);
|
|
55
|
-
} catch (error) {
|
|
56
|
-
throw error instanceof Error ? error : new Error('Failed to set device model');
|
|
57
|
-
}
|
|
35
|
+
setDeviceModel: data => {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
try {
|
|
38
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
39
|
+
const validatedData = validator.validate('set_device_model', data);
|
|
40
|
+
sendStructuredMessage(DeviceModelEnum.set, {
|
|
41
|
+
modelInfos: validatedData
|
|
42
|
+
}, resolve, error => reject(handleMqttError(error, 'Failed to set device model')), DeviceModelEnum.query);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
reject(handleMqttError(error, 'Failed to set device model'));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
58
47
|
}
|
|
59
48
|
};
|
|
60
49
|
};
|
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
size: [number, number, number];
|
|
8
|
-
rotation: [number, number, number];
|
|
9
|
-
position: [number, number, number];
|
|
10
|
-
}
|
|
11
|
-
interface FurnitureModelResponse extends BaseResponse {
|
|
12
|
-
reqType: FurnitureModelEnum.query;
|
|
13
|
-
modelInfo: FurnitureModelInfo[];
|
|
14
|
-
}
|
|
15
|
-
type TRequestFurnitureList = () => Promise<FurnitureModelResponse>;
|
|
16
|
-
type TSetFurnitureModel = (modelInfos: FurnitureModelInfo[]) => Promise<FurnitureModelResponse>;
|
|
17
|
-
export declare const useFurnitureModel: (devId: string) => {
|
|
1
|
+
import { type TRequestFurnitureList, type TSetFurnitureModel } from './type/protocols';
|
|
2
|
+
/**
|
|
3
|
+
* 自定义 Hook,用于家具模型管理
|
|
4
|
+
* @returns 包含 requestFurnitureList 和 setFurnitureModel 函数的对象
|
|
5
|
+
*/
|
|
6
|
+
export declare const useFurnitureModel: () => {
|
|
18
7
|
requestFurnitureList: TRequestFurnitureList;
|
|
19
8
|
setFurnitureModel: TSetFurnitureModel;
|
|
20
9
|
};
|
|
21
|
-
export {};
|
|
@@ -1,61 +1,49 @@
|
|
|
1
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
2
|
-
import { normalResolve } from './promise';
|
|
3
1
|
import { FurnitureModelEnum } from './type/requestType';
|
|
2
|
+
import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
|
|
3
|
+
import { validator } from './type/fun';
|
|
4
|
+
/**
|
|
5
|
+
* 自定义 Hook,用于家具模型管理
|
|
6
|
+
* @returns 包含 requestFurnitureList 和 setFurnitureModel 函数的对象
|
|
7
|
+
*/
|
|
8
|
+
export const useFurnitureModel = () => {
|
|
9
|
+
const {
|
|
10
|
+
sendStructuredMessage
|
|
11
|
+
} = useStructuredMessage();
|
|
4
12
|
|
|
5
|
-
// 请求家具列表函数定义
|
|
6
|
-
|
|
7
|
-
// 设置家具模型函数定义
|
|
8
|
-
|
|
9
|
-
export const useFurnitureModel = devId => {
|
|
10
13
|
/**
|
|
11
14
|
* 请求家具列表
|
|
15
|
+
* @param data 可选参数(目前为空对象)
|
|
12
16
|
* @returns Promise<FurnitureModelResponse> 响应结果
|
|
13
17
|
*/
|
|
14
18
|
|
|
15
19
|
/**
|
|
16
20
|
* 设置家具模型
|
|
17
|
-
* @param
|
|
21
|
+
* @param data 包含家具模型信息数组的对象
|
|
18
22
|
* @returns Promise<FurnitureModelResponse> 响应结果
|
|
19
23
|
*/
|
|
20
24
|
|
|
21
25
|
return {
|
|
22
26
|
requestFurnitureList: () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} = params.message;
|
|
31
|
-
ty.device.sendMqttMessage(params);
|
|
32
|
-
return normalResolve(FurnitureModelEnum.query, taskId);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
return Promise.reject(error instanceof Error ? error : new Error('Failed to request furniture list'));
|
|
35
|
-
}
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
try {
|
|
29
|
+
sendStructuredMessage(FurnitureModelEnum.query, {}, resolve, error => reject(handleMqttError(error, 'Failed to request furniture list')));
|
|
30
|
+
} catch (error) {
|
|
31
|
+
reject(handleMqttError(error, 'Failed to request furniture list'));
|
|
32
|
+
}
|
|
33
|
+
});
|
|
36
34
|
},
|
|
37
|
-
setFurnitureModel:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
console.log('========================params', params);
|
|
51
|
-
ty.device.sendMqttMessage(params);
|
|
52
|
-
const {
|
|
53
|
-
taskId
|
|
54
|
-
} = params.message;
|
|
55
|
-
return normalResolve(FurnitureModelEnum.query, taskId);
|
|
56
|
-
} catch (error) {
|
|
57
|
-
throw error instanceof Error ? error : new Error('Failed to set furniture model');
|
|
58
|
-
}
|
|
35
|
+
setFurnitureModel: data => {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
try {
|
|
38
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
39
|
+
const validatedData = validator.validate('set_furniture_model', data);
|
|
40
|
+
sendStructuredMessage(FurnitureModelEnum.set, {
|
|
41
|
+
modelInfos: validatedData
|
|
42
|
+
}, resolve, error => reject(handleMqttError(error, 'Failed to set furniture model')), FurnitureModelEnum.query);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
reject(handleMqttError(error, 'Failed to set furniture model'));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
59
47
|
}
|
|
60
48
|
};
|
|
61
49
|
};
|
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
interface DeleteMapResponse extends BaseResponse {
|
|
3
|
-
reqType: DeleteMapEnum.rst;
|
|
4
|
-
}
|
|
5
|
-
interface SaveMapResponse extends BaseResponse {
|
|
6
|
-
reqType: SaveCurrentMapEnum.query;
|
|
7
|
-
mapId: number;
|
|
8
|
-
}
|
|
9
|
-
interface UseMapResponse extends BaseResponse {
|
|
10
|
-
reqType: UseMapEnum.query;
|
|
11
|
-
mapId: number;
|
|
12
|
-
}
|
|
13
|
-
type TDeleteHistoryMap = (mapId: number) => Promise<DeleteMapResponse>;
|
|
14
|
-
type TSaveMap = () => Promise<SaveMapResponse>;
|
|
15
|
-
type TChangeCurrentMap = (mapId: number, url: string) => Promise<UseMapResponse>;
|
|
1
|
+
import { type TDeleteHistoryMap, type TSaveMap, type TChangeCurrentMap } from './type/protocols/historyMapProtocol';
|
|
16
2
|
/**
|
|
17
3
|
* 自定义 Hook,用于管理历史地图
|
|
18
|
-
* @param devId 设备ID
|
|
19
4
|
* @returns 包含删除历史地图、更改当前地图和保存地图的函数
|
|
20
5
|
*/
|
|
21
|
-
export declare const useHistoryMap: (
|
|
6
|
+
export declare const useHistoryMap: () => {
|
|
22
7
|
deleteHistoryMap: TDeleteHistoryMap;
|
|
23
8
|
changeCurrentMap: TChangeCurrentMap;
|
|
24
9
|
saveMap: TSaveMap;
|
|
25
10
|
};
|
|
26
|
-
export {};
|
|
@@ -1,35 +1,26 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
import { deleteMultipleMapFile } from '../api/deleteMultipleMapFile';
|
|
3
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
4
|
-
import { normalResolve } from './promise';
|
|
5
3
|
import { DeleteMapEnum, SaveCurrentMapEnum, UseMapEnum } from './type';
|
|
6
4
|
import { SingletonContext } from './mqttProvider';
|
|
7
5
|
import { encodeDeleteMap0x2c, encodeSaveMap0x2a, encodeUseMap0x2e } from '@ray-js/robot-protocol';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// 保存地图响应类型
|
|
12
|
-
|
|
13
|
-
// 更改当前地图响应类型
|
|
14
|
-
|
|
15
|
-
// 删除历史地图函数类型定义
|
|
16
|
-
|
|
17
|
-
// 保存当前地图函数类型定义
|
|
18
|
-
|
|
19
|
-
// 更改当前使用的地图函数类型定义
|
|
20
|
-
|
|
6
|
+
import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
|
|
7
|
+
import { validator } from './type/fun';
|
|
21
8
|
/**
|
|
22
9
|
* 自定义 Hook,用于管理历史地图
|
|
23
|
-
* @param devId 设备ID
|
|
24
10
|
* @returns 包含删除历史地图、更改当前地图和保存地图的函数
|
|
25
11
|
*/
|
|
26
|
-
export const useHistoryMap =
|
|
12
|
+
export const useHistoryMap = () => {
|
|
27
13
|
const {
|
|
28
14
|
useMqtt,
|
|
29
15
|
devices,
|
|
30
16
|
commandVersion
|
|
31
17
|
} = useContext(SingletonContext);
|
|
32
|
-
|
|
18
|
+
const {
|
|
19
|
+
sendStructuredMessage
|
|
20
|
+
} = useStructuredMessage();
|
|
21
|
+
const {
|
|
22
|
+
devId
|
|
23
|
+
} = devices.common.getDevInfo();
|
|
33
24
|
/**
|
|
34
25
|
* 删除历史地图
|
|
35
26
|
* @param mapId 地图ID
|
|
@@ -38,6 +29,7 @@ export const useHistoryMap = devId => {
|
|
|
38
29
|
|
|
39
30
|
/**
|
|
40
31
|
* 保存当前地图
|
|
32
|
+
* @param data 包含操作类型的参数对象(可选,默认为 oper: 0)
|
|
41
33
|
* @returns Promise<SaveMapResponse> 响应结果
|
|
42
34
|
*/
|
|
43
35
|
|
|
@@ -50,119 +42,110 @@ export const useHistoryMap = devId => {
|
|
|
50
42
|
|
|
51
43
|
return {
|
|
52
44
|
deleteHistoryMap: async mapId => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// 先删除地图文件
|
|
59
|
-
await deleteMultipleMapFile(mapId, devId);
|
|
60
|
-
if (useMqtt) {
|
|
61
|
-
const params = createSetCommonParams({
|
|
62
|
-
deviceId: devId,
|
|
63
|
-
reqType: DeleteMapEnum.set,
|
|
64
|
-
message: {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
(async () => {
|
|
47
|
+
try {
|
|
48
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
49
|
+
const validatedData = validator.validate('delete_history_map', {
|
|
65
50
|
mapId
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// 先删除地图文件
|
|
54
|
+
await deleteMultipleMapFile(validatedData.mapId, devId);
|
|
55
|
+
if (useMqtt) {
|
|
56
|
+
sendStructuredMessage(DeleteMapEnum.set, {
|
|
57
|
+
mapId: validatedData.mapId
|
|
58
|
+
}, resolve, error => reject(handleMqttError(error, 'Failed to delete history map')), DeleteMapEnum.rst // 响应类型是 rst,不是 set
|
|
59
|
+
);
|
|
60
|
+
return;
|
|
66
61
|
}
|
|
67
|
-
});
|
|
68
|
-
ty.device.sendMqttMessage(params);
|
|
69
|
-
const {
|
|
70
|
-
taskId
|
|
71
|
-
} = params.message;
|
|
72
|
-
return normalResolve(DeleteMapEnum.rst, taskId);
|
|
73
|
-
}
|
|
74
62
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
63
|
+
// 非 MQTT 模式:使用命令传输
|
|
64
|
+
const command = encodeDeleteMap0x2c({
|
|
65
|
+
id: validatedData.mapId
|
|
66
|
+
});
|
|
67
|
+
devices.common.model.actions.command_trans.set(command);
|
|
68
|
+
resolve({
|
|
69
|
+
success: true,
|
|
70
|
+
errCode: 0,
|
|
71
|
+
reqType: DeleteMapEnum.rst,
|
|
72
|
+
version: commandVersion,
|
|
73
|
+
taskId: `${Date.now()}`
|
|
74
|
+
});
|
|
75
|
+
} catch (error) {
|
|
76
|
+
reject(handleMqttError(error, 'Failed to delete history map'));
|
|
77
|
+
}
|
|
78
|
+
})();
|
|
79
|
+
});
|
|
90
80
|
},
|
|
91
81
|
changeCurrentMap: async (mapId, url) => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
throw new Error('url is required and must be a string');
|
|
98
|
-
}
|
|
99
|
-
try {
|
|
100
|
-
if (useMqtt) {
|
|
101
|
-
const params = createSetCommonParams({
|
|
102
|
-
deviceId: devId,
|
|
103
|
-
reqType: UseMapEnum.set,
|
|
104
|
-
message: {
|
|
82
|
+
return new Promise((resolve, reject) => {
|
|
83
|
+
(async () => {
|
|
84
|
+
try {
|
|
85
|
+
// 构建符合 Schema 的数据
|
|
86
|
+
const mapData = {
|
|
105
87
|
mapId,
|
|
106
88
|
url,
|
|
107
|
-
urlLen: url.length
|
|
89
|
+
urlLen: url.length
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
93
|
+
const validatedData = validator.validate('change_current_map', mapData);
|
|
94
|
+
if (useMqtt) {
|
|
95
|
+
sendStructuredMessage(UseMapEnum.set, validatedData, resolve, error => reject(handleMqttError(error, 'Failed to change current map')), UseMapEnum.query // 响应类型是 query,不是 set
|
|
96
|
+
);
|
|
97
|
+
return;
|
|
108
98
|
}
|
|
109
|
-
});
|
|
110
|
-
ty.device.sendMqttMessage(params);
|
|
111
|
-
const {
|
|
112
|
-
taskId
|
|
113
|
-
} = params.message;
|
|
114
|
-
return normalResolve(UseMapEnum.query, taskId);
|
|
115
|
-
}
|
|
116
99
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
100
|
+
// 非 MQTT 模式:使用命令传输
|
|
101
|
+
const command = encodeUseMap0x2e({
|
|
102
|
+
mapId: validatedData.mapId,
|
|
103
|
+
url: validatedData.url
|
|
104
|
+
});
|
|
105
|
+
devices.common.model.actions.command_trans.set(command);
|
|
106
|
+
resolve({
|
|
107
|
+
success: true,
|
|
108
|
+
errCode: 0,
|
|
109
|
+
reqType: UseMapEnum.query,
|
|
110
|
+
version: commandVersion,
|
|
111
|
+
taskId: `${Date.now()}`,
|
|
112
|
+
mapId: validatedData.mapId
|
|
113
|
+
});
|
|
114
|
+
} catch (error) {
|
|
115
|
+
reject(handleMqttError(error, 'Failed to change current map'));
|
|
116
|
+
}
|
|
117
|
+
})();
|
|
118
|
+
});
|
|
134
119
|
},
|
|
135
|
-
saveMap: ()
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
120
|
+
saveMap: function () {
|
|
121
|
+
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
122
|
+
oper: 0
|
|
123
|
+
};
|
|
124
|
+
return new Promise((resolve, reject) => {
|
|
125
|
+
try {
|
|
126
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
127
|
+
const validatedData = validator.validate('save_map', data);
|
|
128
|
+
if (useMqtt) {
|
|
129
|
+
sendStructuredMessage(SaveCurrentMapEnum.set, validatedData, resolve, error => reject(handleMqttError(error, 'Failed to save current map')), SaveCurrentMapEnum.query // 响应类型是 query,不是 set
|
|
130
|
+
);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// 非 MQTT 模式:使用命令传输
|
|
135
|
+
const command = encodeSaveMap0x2a(1);
|
|
136
|
+
devices.common.model.actions.command_trans.set(command);
|
|
137
|
+
resolve({
|
|
138
|
+
success: true,
|
|
139
|
+
errCode: 0,
|
|
140
|
+
reqType: SaveCurrentMapEnum.query,
|
|
141
|
+
version: commandVersion,
|
|
142
|
+
taskId: `${Date.now()}`,
|
|
143
|
+
mapId: 0 // 非 MQTT 模式下无法获取 mapId
|
|
144
144
|
});
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
taskId
|
|
148
|
-
} = params.message;
|
|
149
|
-
return normalResolve(SaveCurrentMapEnum.query, taskId);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
reject(handleMqttError(error, 'Failed to save current map'));
|
|
150
147
|
}
|
|
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
|
|
162
|
-
});
|
|
163
|
-
} catch (error) {
|
|
164
|
-
throw error instanceof Error ? error : new Error('Failed to save current map');
|
|
165
|
-
}
|
|
148
|
+
});
|
|
166
149
|
}
|
|
167
150
|
};
|
|
168
151
|
};
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
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>;
|
|
1
|
+
import { type TSetPartDivision } from './type/protocols';
|
|
7
2
|
/**
|
|
8
3
|
* 自定义 Hook,用于房间分隔
|
|
9
|
-
* @param devId 设备ID
|
|
10
4
|
* @returns 包含 setPartDivision 函数的对象
|
|
11
5
|
*/
|
|
12
|
-
export declare const usePartDivision: (
|
|
6
|
+
export declare const usePartDivision: () => {
|
|
13
7
|
setPartDivision: TSetPartDivision;
|
|
14
8
|
};
|
|
15
|
-
export {};
|
|
@@ -1,86 +1,77 @@
|
|
|
1
1
|
// 房间分隔
|
|
2
|
+
import { encodePartitionDivision0x1c } from '@ray-js/robot-protocol';
|
|
2
3
|
import { useContext } from 'react';
|
|
3
4
|
import { pointsToString } from '../utils';
|
|
4
|
-
import {
|
|
5
|
-
import { normalResolve } from './promise';
|
|
6
|
-
import { PartDivisionEnum } from './type';
|
|
5
|
+
import { handleMqttError, useStructuredMessage } from './hooks/useStructuredMessage';
|
|
7
6
|
import { SingletonContext } from './mqttProvider';
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
// 房间分隔响应类型
|
|
11
|
-
|
|
12
|
-
// 设置房间分隔函数类型定义
|
|
13
|
-
|
|
7
|
+
import { PartDivisionEnum } from './type';
|
|
8
|
+
import { validator } from './type/fun';
|
|
14
9
|
/**
|
|
15
10
|
* 自定义 Hook,用于房间分隔
|
|
16
|
-
* @param devId 设备ID
|
|
17
11
|
* @returns 包含 setPartDivision 函数的对象
|
|
18
12
|
*/
|
|
19
|
-
export const usePartDivision =
|
|
13
|
+
export const usePartDivision = () => {
|
|
20
14
|
const {
|
|
21
15
|
useMqtt,
|
|
22
16
|
devices,
|
|
23
17
|
commandVersion
|
|
24
18
|
} = useContext(SingletonContext);
|
|
19
|
+
const {
|
|
20
|
+
sendStructuredMessage
|
|
21
|
+
} = useStructuredMessage();
|
|
25
22
|
|
|
26
23
|
/**
|
|
27
24
|
* 设置房间分隔
|
|
28
|
-
* @param points
|
|
29
|
-
* @param roomId 房间ID
|
|
25
|
+
* @param points 分隔点数组
|
|
26
|
+
* @param roomId 房间ID,当前要分隔的房间(可以是 int 或 string)
|
|
30
27
|
* @param origin 地图原点坐标
|
|
31
28
|
* @returns Promise<PartDivisionResponse> 响应结果
|
|
32
29
|
*/
|
|
33
30
|
|
|
34
31
|
return {
|
|
35
32
|
setPartDivision: (points, roomId, origin) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const pointStr = pointsToString(points, origin);
|
|
50
|
-
const params = createSetCommonParams({
|
|
51
|
-
deviceId: devId,
|
|
52
|
-
reqType: PartDivisionEnum.set,
|
|
53
|
-
message: {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
try {
|
|
35
|
+
// 使用验证器验证三个独立参数
|
|
36
|
+
const validatedData = validator.validateSetPartDivision(points, roomId, origin);
|
|
37
|
+
const {
|
|
38
|
+
points: validatedPoints,
|
|
39
|
+
roomId: validatedRoomId,
|
|
40
|
+
origin: validatedOrigin
|
|
41
|
+
} = validatedData;
|
|
42
|
+
if (useMqtt) {
|
|
43
|
+
// 将点数组转换为字符串格式
|
|
44
|
+
const pointStr = pointsToString(validatedPoints, validatedOrigin);
|
|
45
|
+
sendStructuredMessage(PartDivisionEnum.set, {
|
|
54
46
|
lines: [pointStr],
|
|
55
47
|
// 分隔线数组
|
|
56
|
-
ids: [
|
|
57
|
-
}
|
|
48
|
+
ids: [validatedRoomId] // 房间ID数组
|
|
49
|
+
}, resolve, error => reject(handleMqttError(error, 'Failed to set part division')), PartDivisionEnum.query // 响应类型是 query,不是 set
|
|
50
|
+
);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 非 MQTT 模式:使用命令传输
|
|
55
|
+
// 将 roomId 转换为数字(如果它是字符串)
|
|
56
|
+
const roomIdNumber = typeof validatedRoomId === 'string' ? Number(validatedRoomId) : validatedRoomId;
|
|
57
|
+
const command = encodePartitionDivision0x1c({
|
|
58
|
+
version: commandVersion,
|
|
59
|
+
origin: validatedOrigin,
|
|
60
|
+
points: validatedPoints,
|
|
61
|
+
roomId: roomIdNumber
|
|
58
62
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
devices.common.model.actions.command_trans.set(command);
|
|
64
|
+
resolve({
|
|
65
|
+
success: true,
|
|
66
|
+
errCode: 0,
|
|
67
|
+
reqType: PartDivisionEnum.query,
|
|
68
|
+
version: commandVersion,
|
|
69
|
+
taskId: `${Date.now()}`
|
|
70
|
+
});
|
|
71
|
+
} catch (error) {
|
|
72
|
+
reject(handleMqttError(error, 'Failed to set part division'));
|
|
64
73
|
}
|
|
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');
|
|
83
|
-
}
|
|
74
|
+
});
|
|
84
75
|
}
|
|
85
76
|
};
|
|
86
77
|
};
|