@ray-js/robot-data-stream 0.0.10-beta-11 → 0.0.10-beta-13
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/deleteMultipleMapFile.d.ts +1 -0
- package/lib/api/deleteMultipleMapFile.js +9 -0
- package/lib/api/request.d.ts +2 -0
- package/lib/api/request.js +29 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +4 -2
- package/lib/mqtt/createCommonOptions.d.ts +24 -0
- package/lib/mqtt/createCommonOptions.js +28 -0
- package/lib/mqtt/index.d.ts +17 -0
- package/lib/mqtt/index.js +17 -0
- package/lib/mqtt/mqttProvider.d.ts +6 -0
- package/lib/mqtt/mqttProvider.js +61 -0
- package/lib/mqtt/myError.d.ts +4 -0
- package/lib/mqtt/myError.js +6 -0
- package/lib/mqtt/promise.d.ts +13 -0
- package/lib/mqtt/promise.js +47 -0
- package/lib/mqtt/type/index.d.ts +26 -0
- package/lib/mqtt/type/index.js +11 -0
- package/lib/mqtt/type/requestType.d.ts +67 -0
- package/lib/mqtt/type/requestType.js +101 -0
- package/lib/mqtt/useDevInfo.d.ts +12 -0
- package/lib/mqtt/useDevInfo.js +23 -0
- package/lib/mqtt/useHistoryMap.d.ts +34 -0
- package/lib/mqtt/useHistoryMap.js +91 -0
- package/lib/mqtt/usePartDivision.d.ts +17 -0
- package/lib/mqtt/usePartDivision.js +38 -0
- package/lib/mqtt/usePartMerge.d.ts +16 -0
- package/lib/mqtt/usePartMerge.js +41 -0
- package/lib/mqtt/usePassword.d.ts +17 -0
- package/lib/mqtt/usePassword.js +56 -0
- package/lib/mqtt/useQuiteHours.d.ts +55 -0
- package/lib/mqtt/useQuiteHours.js +71 -0
- package/lib/mqtt/useResetMap.d.ts +11 -0
- package/lib/mqtt/useResetMap.js +17 -0
- package/lib/mqtt/useRoomProperty.d.ts +11 -0
- package/lib/mqtt/useRoomProperty.js +66 -0
- package/lib/mqtt/useSchedule.d.ts +16 -0
- package/lib/mqtt/useSchedule.js +38 -0
- package/lib/mqtt/useSelectRoomClean.d.ts +26 -0
- package/lib/mqtt/useSelectRoomClean.js +70 -0
- package/lib/mqtt/useSpotClean.d.ts +18 -0
- package/lib/mqtt/useSpotClean.js +81 -0
- package/lib/mqtt/useVirtualArea.d.ts +24 -0
- package/lib/mqtt/useVirtualArea.js +79 -0
- package/lib/mqtt/useVirtualWall.d.ts +22 -0
- package/lib/mqtt/useVirtualWall.js +65 -0
- package/lib/mqtt/useVoice.d.ts +27 -0
- package/lib/mqtt/useVoice.js +66 -0
- package/lib/mqtt/useZoneClean.d.ts +27 -0
- package/lib/mqtt/useZoneClean.js +81 -0
- package/lib/utils/index.d.ts +8 -0
- package/lib/utils/index.js +47 -0
- package/package.json +5 -2
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RoomPreference } from './type';
|
|
2
|
+
type Response = Partial<Pick<RoomPreference, 'suctions' | 'cisterns' | 'cleanCounts' | 'yMops' | 'sweepMopModes'>> & {
|
|
3
|
+
polygons: string[];
|
|
4
|
+
names?: string[];
|
|
5
|
+
};
|
|
6
|
+
type TSetSpotClean = (message: Partial<Pick<RoomPreference, 'suctions' | 'cisterns' | 'cleanCounts' | 'yMops' | 'sweepMopModes'>> & {
|
|
7
|
+
polygons: string[];
|
|
8
|
+
names?: string[];
|
|
9
|
+
}) => Promise<Response>;
|
|
10
|
+
/**
|
|
11
|
+
* 定点清扫
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export declare const useSpotClean: (devId: string) => {
|
|
15
|
+
requestSpotClean: () => Promise<Response>;
|
|
16
|
+
setSpotClean: TSetSpotClean;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// 定点清扫
|
|
2
|
+
|
|
3
|
+
import { isArray } from 'lodash-es';
|
|
4
|
+
import { createSetCommonParams } from './createCommonOptions';
|
|
5
|
+
import { normalResolve } from './promise';
|
|
6
|
+
import { SpotCleanEnum } from './type';
|
|
7
|
+
/**
|
|
8
|
+
* 定点清扫
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export const useSpotClean = devId => {
|
|
12
|
+
// 请求定点清扫数据
|
|
13
|
+
|
|
14
|
+
// 设置定点清扫
|
|
15
|
+
// 定点清扫的清扫属性,使用全局的清扫属性
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
requestSpotClean: () => {
|
|
19
|
+
const params = createSetCommonParams({
|
|
20
|
+
deviceId: devId,
|
|
21
|
+
reqType: SpotCleanEnum.query
|
|
22
|
+
});
|
|
23
|
+
ty.device.sendMqttMessage(params);
|
|
24
|
+
return normalResolve(SpotCleanEnum.query, params.message.taskId);
|
|
25
|
+
},
|
|
26
|
+
setSpotClean: message => {
|
|
27
|
+
const {
|
|
28
|
+
polygons
|
|
29
|
+
} = message;
|
|
30
|
+
if (!isArray(polygons) || isArray(polygons) && polygons.length === 0) {
|
|
31
|
+
return Promise.reject(new Error('message is required'));
|
|
32
|
+
}
|
|
33
|
+
const num = polygons.length;
|
|
34
|
+
const {
|
|
35
|
+
suctions = new Array(num).fill(''),
|
|
36
|
+
cisterns = new Array(num).fill(''),
|
|
37
|
+
cleanCounts = new Array(num).fill(1),
|
|
38
|
+
yMops = new Array(num).fill(-1),
|
|
39
|
+
sweepMopModes = new Array(num).fill('only_sweep'),
|
|
40
|
+
names = new Array(num).fill('')
|
|
41
|
+
} = message;
|
|
42
|
+
if (suctions && !isArray(suctions)) {
|
|
43
|
+
return Promise.reject(new Error('suctions is illegal'));
|
|
44
|
+
}
|
|
45
|
+
if (cisterns && !isArray(cisterns)) {
|
|
46
|
+
return Promise.reject(new Error('cisterns is illegal'));
|
|
47
|
+
}
|
|
48
|
+
if (cleanCounts && !isArray(cleanCounts)) {
|
|
49
|
+
return Promise.reject(new Error('cleanCounts is illegal'));
|
|
50
|
+
}
|
|
51
|
+
if (yMops && !isArray(yMops)) {
|
|
52
|
+
return Promise.reject(new Error('yMops is illegal'));
|
|
53
|
+
}
|
|
54
|
+
if (sweepMopModes && !isArray(sweepMopModes)) {
|
|
55
|
+
return Promise.reject(new Error('sweepMopModes is illegal'));
|
|
56
|
+
}
|
|
57
|
+
if (names && !isArray(names)) {
|
|
58
|
+
return Promise.reject(new Error('names is illegal'));
|
|
59
|
+
}
|
|
60
|
+
if (num !== suctions.length || num !== cisterns.length || num !== cleanCounts.length || num !== yMops.length || num !== sweepMopModes.length || num !== names.length) {
|
|
61
|
+
return Promise.reject(new Error('The length of the parameters is inconsistent'));
|
|
62
|
+
}
|
|
63
|
+
const params = createSetCommonParams({
|
|
64
|
+
deviceId: devId,
|
|
65
|
+
reqType: SpotCleanEnum.set,
|
|
66
|
+
message: {
|
|
67
|
+
num,
|
|
68
|
+
polygons,
|
|
69
|
+
suctions,
|
|
70
|
+
cisterns,
|
|
71
|
+
cleanCounts,
|
|
72
|
+
yMops,
|
|
73
|
+
sweepMopModes,
|
|
74
|
+
names
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
ty.device.sendMqttMessage(params);
|
|
78
|
+
return normalResolve(SpotCleanEnum.query, params.message.taskId);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type Response = {
|
|
2
|
+
reqType: 'restrictedAreaQry';
|
|
3
|
+
version: string;
|
|
4
|
+
num: number;
|
|
5
|
+
modes: number[];
|
|
6
|
+
polygons: string[];
|
|
7
|
+
names: string[];
|
|
8
|
+
mapId: number;
|
|
9
|
+
success: boolean;
|
|
10
|
+
errCode: number;
|
|
11
|
+
taskId: string;
|
|
12
|
+
};
|
|
13
|
+
type TSetVirtualArea = (message: {
|
|
14
|
+
polygons: string[];
|
|
15
|
+
names?: string[];
|
|
16
|
+
modes: number[];
|
|
17
|
+
num?: number;
|
|
18
|
+
}) => Promise<Response>;
|
|
19
|
+
type TRequestVirtualArea = () => Promise<Response>;
|
|
20
|
+
export declare const useVirtualArea: (devId: string) => {
|
|
21
|
+
requestVirtualArea: TRequestVirtualArea;
|
|
22
|
+
setVirtualArea: TSetVirtualArea;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// 添加禁区
|
|
2
|
+
import { createSetCommonParams } from './createCommonOptions';
|
|
3
|
+
import { normalResolve } from './promise';
|
|
4
|
+
import { VirtualAreaEnum } from './type';
|
|
5
|
+
import { isArray } from 'lodash-es';
|
|
6
|
+
// 禁区
|
|
7
|
+
|
|
8
|
+
export const useVirtualArea = devId => {
|
|
9
|
+
/**
|
|
10
|
+
* 请求虚拟区域数据
|
|
11
|
+
* @returns Promise<VirtualAreaResponse> 响应结果
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 设置虚拟区域数据
|
|
16
|
+
* @param message 包含虚拟区域设置参数的对象
|
|
17
|
+
* @param message.polygons 多边形数组,每个元素为一个多边形的坐标字符串
|
|
18
|
+
* @param message.names 名称数组,每个元素为一个区域的名称
|
|
19
|
+
* @param message.modes 模式数组,每个元素为一个区域的模式,0:全禁,1:禁扫,2:禁拖
|
|
20
|
+
* @param message.num 虚拟区域的数量
|
|
21
|
+
* @returns Promise<VirtualAreaResponse> 响应结果
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
requestVirtualArea: () => {
|
|
26
|
+
const params = createSetCommonParams({
|
|
27
|
+
deviceId: devId,
|
|
28
|
+
reqType: VirtualAreaEnum.query
|
|
29
|
+
});
|
|
30
|
+
ty.device.sendMqttMessage(params);
|
|
31
|
+
return normalResolve(VirtualAreaEnum.query, params.message.taskId);
|
|
32
|
+
},
|
|
33
|
+
setVirtualArea: message => {
|
|
34
|
+
const {
|
|
35
|
+
polygons,
|
|
36
|
+
num,
|
|
37
|
+
modes,
|
|
38
|
+
names
|
|
39
|
+
} = message || {};
|
|
40
|
+
if (!isArray(polygons) || isArray(polygons) && polygons.length === 0) {
|
|
41
|
+
return Promise.reject(new Error('message polygons is required'));
|
|
42
|
+
}
|
|
43
|
+
const len = polygons.length;
|
|
44
|
+
if (!isArray(message.modes) || isArray(message.modes) && message.modes.length === 0) {
|
|
45
|
+
return Promise.reject(new Error('message modes is required'));
|
|
46
|
+
}
|
|
47
|
+
if (num && !Number.isInteger(num)) {
|
|
48
|
+
return Promise.reject(new Error('num is illegal'));
|
|
49
|
+
}
|
|
50
|
+
if (num && num !== len) {
|
|
51
|
+
return Promise.reject(new Error('num is not equal to points length'));
|
|
52
|
+
}
|
|
53
|
+
if (modes && !isArray(modes)) {
|
|
54
|
+
return Promise.reject(new Error('mode is illegal'));
|
|
55
|
+
}
|
|
56
|
+
if (modes && modes.length !== len) {
|
|
57
|
+
return Promise.reject(new Error('mode length is not equal to points length'));
|
|
58
|
+
}
|
|
59
|
+
if (names && !isArray(names)) {
|
|
60
|
+
return Promise.reject(new Error('names is illegal'));
|
|
61
|
+
}
|
|
62
|
+
if (names && names.length !== len) {
|
|
63
|
+
return Promise.reject(new Error('names length is not equal to points length'));
|
|
64
|
+
}
|
|
65
|
+
const params = createSetCommonParams({
|
|
66
|
+
deviceId: devId,
|
|
67
|
+
reqType: VirtualAreaEnum.set,
|
|
68
|
+
message: {
|
|
69
|
+
polygons,
|
|
70
|
+
num: num || len,
|
|
71
|
+
modes: modes || new Array(len).fill(0),
|
|
72
|
+
names: names || new Array(len).fill('')
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
ty.device.sendMqttMessage(params);
|
|
76
|
+
return normalResolve(VirtualAreaEnum.query, params.message.taskId);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type Response = {
|
|
2
|
+
modes: number[];
|
|
3
|
+
success: boolean;
|
|
4
|
+
errCode: number;
|
|
5
|
+
num: number;
|
|
6
|
+
reqType: 'virtualWallQry';
|
|
7
|
+
mapId: number;
|
|
8
|
+
version: string;
|
|
9
|
+
taskId: string;
|
|
10
|
+
points: string[];
|
|
11
|
+
};
|
|
12
|
+
type TRequestVirtualWall = () => Promise<Response>;
|
|
13
|
+
type TSetVirtualWall = (message: {
|
|
14
|
+
points: string[];
|
|
15
|
+
num?: number;
|
|
16
|
+
mode?: number[];
|
|
17
|
+
}) => Promise<Response>;
|
|
18
|
+
export declare const useVirtualWall: (devId: string) => {
|
|
19
|
+
requestVirtualWall: TRequestVirtualWall;
|
|
20
|
+
setVirtualWall: TSetVirtualWall;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
// 虚拟墙数据
|
|
3
|
+
|
|
4
|
+
import { createSetCommonParams } from './createCommonOptions';
|
|
5
|
+
import { normalResolve } from './promise';
|
|
6
|
+
import { VirtualWallEnum } from './type';
|
|
7
|
+
import { isArray } from 'lodash-es';
|
|
8
|
+
export const useVirtualWall = devId => {
|
|
9
|
+
// 请求虚拟墙数据
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 设置虚拟墙数据
|
|
13
|
+
* @param message 包含虚拟墙设置参数的对象
|
|
14
|
+
* @param message.points 虚拟墙的点数组
|
|
15
|
+
* @param message.num 虚拟墙的数量(可选)
|
|
16
|
+
* @param message.mode 虚拟墙的模式数组(可选)
|
|
17
|
+
* @returns Promise<Response> 响应结果
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
requestVirtualWall: () => {
|
|
22
|
+
const params = createSetCommonParams({
|
|
23
|
+
deviceId: devId,
|
|
24
|
+
reqType: VirtualWallEnum.query
|
|
25
|
+
});
|
|
26
|
+
ty.device.sendMqttMessage(params);
|
|
27
|
+
return normalResolve(VirtualWallEnum.query, params.message.taskId);
|
|
28
|
+
},
|
|
29
|
+
setVirtualWall: message => {
|
|
30
|
+
const requestParams = _objectSpread({}, message);
|
|
31
|
+
if (!isArray(requestParams.points) || requestParams.points.length === 0) {
|
|
32
|
+
return Promise.reject(new Error('points is illegal'));
|
|
33
|
+
}
|
|
34
|
+
const len = requestParams.points.length;
|
|
35
|
+
if (requestParams.num && !Number.isInteger(requestParams.num)) {
|
|
36
|
+
return Promise.reject(new Error('num is illegal'));
|
|
37
|
+
}
|
|
38
|
+
if (requestParams.num && requestParams.num !== len) {
|
|
39
|
+
return Promise.reject(new Error('num is not equal to points length'));
|
|
40
|
+
}
|
|
41
|
+
if (requestParams.mode && !isArray(requestParams.mode)) {
|
|
42
|
+
return Promise.reject(new Error('mode is illegal'));
|
|
43
|
+
}
|
|
44
|
+
if (requestParams.mode && requestParams.mode.length !== len) {
|
|
45
|
+
return Promise.reject(new Error('mode length is not equal to points length'));
|
|
46
|
+
}
|
|
47
|
+
const {
|
|
48
|
+
points,
|
|
49
|
+
num,
|
|
50
|
+
mode
|
|
51
|
+
} = requestParams;
|
|
52
|
+
const params = createSetCommonParams({
|
|
53
|
+
deviceId: devId,
|
|
54
|
+
reqType: VirtualWallEnum.set,
|
|
55
|
+
message: {
|
|
56
|
+
points,
|
|
57
|
+
num: num || len,
|
|
58
|
+
mode: mode || new Array(len).fill(-1)
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
ty.device.sendMqttMessage(params);
|
|
62
|
+
return normalResolve(VirtualWallEnum.query, params.message.taskId);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface VoiceLanguageResponse {
|
|
2
|
+
reqType: string;
|
|
3
|
+
version: string;
|
|
4
|
+
id: number;
|
|
5
|
+
schedule: number;
|
|
6
|
+
status: number;
|
|
7
|
+
success: boolean;
|
|
8
|
+
errCode: number;
|
|
9
|
+
taskId: string;
|
|
10
|
+
}
|
|
11
|
+
type TSetVoice = (message: {
|
|
12
|
+
id: number;
|
|
13
|
+
url: string;
|
|
14
|
+
md5: string;
|
|
15
|
+
}) => Promise<VoiceLanguageResponse>;
|
|
16
|
+
type TRequestVoiceInUse = () => Promise<VoiceLanguageResponse>;
|
|
17
|
+
/**
|
|
18
|
+
* 自定义 Hook,用于语音语言设置
|
|
19
|
+
* @param devId 设备ID
|
|
20
|
+
* @returns 包含 requestAllVoices, requestVoiceInUse 和 setVoice 函数的对象
|
|
21
|
+
*/
|
|
22
|
+
export declare const useVoice: (devId: string) => {
|
|
23
|
+
requestAllVoices: () => Promise<ty.GetVoiceListResponse>;
|
|
24
|
+
requestVoiceInUse: TRequestVoiceInUse;
|
|
25
|
+
setVoice: TSetVoice;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import { getVoiceList } from '@ray-js/ray';
|
|
3
|
+
import { createSetCommonParams } from './createCommonOptions';
|
|
4
|
+
import { normalResolve } from './promise';
|
|
5
|
+
import { VoiceLanguageEnum } from './type';
|
|
6
|
+
|
|
7
|
+
// 设置语音语言函数类型定义
|
|
8
|
+
|
|
9
|
+
// 请求当前使用的机器语音
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 自定义 Hook,用于语音语言设置
|
|
13
|
+
* @param devId 设备ID
|
|
14
|
+
* @returns 包含 requestAllVoices, requestVoiceInUse 和 setVoice 函数的对象
|
|
15
|
+
*/
|
|
16
|
+
export const useVoice = devId => {
|
|
17
|
+
/**
|
|
18
|
+
* 请求所有语音语言
|
|
19
|
+
* @returns Promise<any> 响应结果
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 请求当前使用的语音语言
|
|
24
|
+
* @returns Promise<any> 响应结果
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 设置语音语言
|
|
29
|
+
* @param message 包含语音语言设置参数的对象
|
|
30
|
+
* @returns Promise<Response> 响应结果
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
requestAllVoices: async () => {
|
|
35
|
+
const res = await getVoiceList({
|
|
36
|
+
devId: devId,
|
|
37
|
+
offset: 0,
|
|
38
|
+
limit: 100
|
|
39
|
+
});
|
|
40
|
+
return res;
|
|
41
|
+
},
|
|
42
|
+
requestVoiceInUse: () => {
|
|
43
|
+
const params = createSetCommonParams({
|
|
44
|
+
deviceId: devId,
|
|
45
|
+
reqType: VoiceLanguageEnum.query
|
|
46
|
+
});
|
|
47
|
+
const {
|
|
48
|
+
taskId
|
|
49
|
+
} = params.message;
|
|
50
|
+
ty.device.sendMqttMessage(params);
|
|
51
|
+
return normalResolve(VoiceLanguageEnum.query, taskId);
|
|
52
|
+
},
|
|
53
|
+
setVoice: message => {
|
|
54
|
+
const sendData = _objectSpread(_objectSpread({}, message), {}, {
|
|
55
|
+
urlLen: message.url.length
|
|
56
|
+
});
|
|
57
|
+
const params = createSetCommonParams({
|
|
58
|
+
deviceId: devId,
|
|
59
|
+
reqType: VoiceLanguageEnum.set,
|
|
60
|
+
message: sendData
|
|
61
|
+
});
|
|
62
|
+
ty.device.sendMqttMessage(params);
|
|
63
|
+
return normalResolve(VoiceLanguageEnum.query, params.message.taskId);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { RoomPreference } from './type';
|
|
2
|
+
type Response = {
|
|
3
|
+
reqType: string;
|
|
4
|
+
version: string;
|
|
5
|
+
success: boolean;
|
|
6
|
+
errCode: number;
|
|
7
|
+
taskId: string;
|
|
8
|
+
polygons: string[];
|
|
9
|
+
suctions?: string[];
|
|
10
|
+
cisterns?: string[];
|
|
11
|
+
cleanCounts?: number[];
|
|
12
|
+
yMops?: number[];
|
|
13
|
+
sweepMopModes?: string[];
|
|
14
|
+
};
|
|
15
|
+
type TSetZoneClean = (message: Partial<Pick<RoomPreference, 'suctions' | 'cisterns' | 'cleanCounts' | 'yMops' | 'sweepMopModes'>> & {
|
|
16
|
+
polygons: string[];
|
|
17
|
+
names?: string[];
|
|
18
|
+
}) => Promise<Response>;
|
|
19
|
+
/**
|
|
20
|
+
* 划区清扫
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export declare const useZoneClean: (devId: string) => {
|
|
24
|
+
requestZoneClean: () => Promise<Response>;
|
|
25
|
+
setZoneClean: TSetZoneClean;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// 划区清扫
|
|
2
|
+
|
|
3
|
+
import { isArray } from 'lodash-es';
|
|
4
|
+
import { createSetCommonParams } from './createCommonOptions';
|
|
5
|
+
import { normalResolve } from './promise';
|
|
6
|
+
import { ZoneCleanEnum } from './type';
|
|
7
|
+
/**
|
|
8
|
+
* 划区清扫
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export const useZoneClean = devId => {
|
|
12
|
+
// 请求划区清扫信息
|
|
13
|
+
|
|
14
|
+
// 设置划区清扫
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
requestZoneClean: () => {
|
|
18
|
+
const params = createSetCommonParams({
|
|
19
|
+
deviceId: devId,
|
|
20
|
+
reqType: ZoneCleanEnum.query
|
|
21
|
+
});
|
|
22
|
+
ty.device.sendMqttMessage(params);
|
|
23
|
+
return normalResolve(ZoneCleanEnum.query, params.message.taskId);
|
|
24
|
+
},
|
|
25
|
+
setZoneClean: message => {
|
|
26
|
+
const {
|
|
27
|
+
polygons
|
|
28
|
+
} = message;
|
|
29
|
+
if (!isArray(polygons) || isArray(polygons) && polygons.length === 0) {
|
|
30
|
+
return Promise.reject(new Error('message is required'));
|
|
31
|
+
}
|
|
32
|
+
const num = polygons.length;
|
|
33
|
+
const {
|
|
34
|
+
suctions = new Array(num).fill(''),
|
|
35
|
+
cisterns = new Array(num).fill(''),
|
|
36
|
+
cleanCounts = new Array(num).fill(1),
|
|
37
|
+
yMops = new Array(num).fill(-1),
|
|
38
|
+
sweepMopModes = new Array(num).fill('only_sweep'),
|
|
39
|
+
names = new Array(num).fill('')
|
|
40
|
+
} = message;
|
|
41
|
+
if (suctions && !isArray(suctions)) {
|
|
42
|
+
return Promise.reject(new Error('suctions is illegal'));
|
|
43
|
+
}
|
|
44
|
+
if (cisterns && !isArray(cisterns)) {
|
|
45
|
+
return Promise.reject(new Error('cisterns is illegal'));
|
|
46
|
+
}
|
|
47
|
+
if (cleanCounts && !isArray(cleanCounts)) {
|
|
48
|
+
return Promise.reject(new Error('cleanCounts is illegal'));
|
|
49
|
+
}
|
|
50
|
+
if (yMops && !isArray(yMops)) {
|
|
51
|
+
return Promise.reject(new Error('yMops is illegal'));
|
|
52
|
+
}
|
|
53
|
+
if (sweepMopModes && !isArray(sweepMopModes)) {
|
|
54
|
+
return Promise.reject(new Error('sweepMopModes is illegal'));
|
|
55
|
+
}
|
|
56
|
+
if (names && !isArray(names)) {
|
|
57
|
+
return Promise.reject(new Error('names is illegal'));
|
|
58
|
+
}
|
|
59
|
+
if (num !== suctions.length || num !== cisterns.length || num !== cleanCounts.length || num !== yMops.length || num !== sweepMopModes.length || num !== names.length) {
|
|
60
|
+
return Promise.reject(new Error('The length of the parameters is inconsistent'));
|
|
61
|
+
}
|
|
62
|
+
const params = createSetCommonParams({
|
|
63
|
+
deviceId: devId,
|
|
64
|
+
reqType: ZoneCleanEnum.set,
|
|
65
|
+
message: {
|
|
66
|
+
num: polygons.length,
|
|
67
|
+
switchGo: true,
|
|
68
|
+
polygons,
|
|
69
|
+
suctions,
|
|
70
|
+
cisterns,
|
|
71
|
+
cleanCounts,
|
|
72
|
+
yMops,
|
|
73
|
+
sweepMopModes,
|
|
74
|
+
names
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
ty.device.sendMqttMessage(params);
|
|
78
|
+
return normalResolve(ZoneCleanEnum.query, params.message.taskId);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type Point = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
};
|
|
5
|
+
export declare const emitter: import("mitt").Emitter<Record<import("mitt").EventType, unknown>>;
|
|
6
|
+
export declare const pointsToString: (points: Point[], origin: Point) => string;
|
|
7
|
+
export declare const isJSONString: (str: any) => boolean;
|
|
8
|
+
export declare const parseJSON: (str: any) => any;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import mitt from 'mitt';
|
|
2
|
+
import { floor, join, map } from 'lodash-es';
|
|
3
|
+
export const emitter = mitt();
|
|
4
|
+
const pointToString = point => {
|
|
5
|
+
return `${point.x},${point.y}`;
|
|
6
|
+
};
|
|
7
|
+
export const pointsToString = (points, origin) => {
|
|
8
|
+
let newPoints = [];
|
|
9
|
+
const ox = origin.x;
|
|
10
|
+
const oy = origin.y;
|
|
11
|
+
newPoints = map(points, i => {
|
|
12
|
+
return {
|
|
13
|
+
x: floor(i.x - ox, 0),
|
|
14
|
+
y: floor(-(i.y - oy), 0)
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
return join(map(newPoints, pointToString), ',');
|
|
18
|
+
};
|
|
19
|
+
export const isJSONString = str => {
|
|
20
|
+
if (typeof str !== 'string') {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
JSON.parse(str);
|
|
25
|
+
return true;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export const parseJSON = str => {
|
|
31
|
+
let rst;
|
|
32
|
+
if (str && {}.toString.call(str) === '[object String]') {
|
|
33
|
+
try {
|
|
34
|
+
rst = JSON.parse(str);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
try {
|
|
37
|
+
// eslint-disable-next-line
|
|
38
|
+
rst = eval(`(${str})`);
|
|
39
|
+
} catch (e2) {
|
|
40
|
+
rst = str;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
rst = typeof str === 'undefined' ? {} : str;
|
|
45
|
+
}
|
|
46
|
+
return rst;
|
|
47
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/robot-data-stream",
|
|
3
|
-
"version": "0.0.10-beta-
|
|
3
|
+
"version": "0.0.10-beta-13",
|
|
4
4
|
"description": "扫地机P2P数据流标准化组件",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"files": [
|
|
@@ -38,7 +38,10 @@
|
|
|
38
38
|
"clsx": "^1.2.1",
|
|
39
39
|
"lodash-es": "^4.17.21",
|
|
40
40
|
"mitt": "^3.0.1",
|
|
41
|
-
"moment": "^2.30.1"
|
|
41
|
+
"moment": "^2.30.1",
|
|
42
|
+
"react": "^17.0.2",
|
|
43
|
+
"react-dom": "^17.0.2",
|
|
44
|
+
"crypto-js": "^4.2.0"
|
|
42
45
|
},
|
|
43
46
|
"devDependencies": {
|
|
44
47
|
"@commitlint/cli": "^7.2.1",
|