config.ts
2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { ref, unref } from 'vue';
import { TaskTypeEnum } from '/@/views/task/center/config';
import { genModbusCommand } from '/@/api/task';
import { useMessage } from '/@/hooks/web/useMessage';
import { SingleToHex } from '/@/views/device/list/cpns/tabs/ObjectModelCommandDeliveryModal/config';
import { CommandTypeEnum } from '/@/enums/linkedgeEnum';
import { TransportTypeEnum } from '/@/enums/deviceEnum';
const getArray = (values) => {
const str = values.replace(/\s+/g, '');
const array: any = [];
for (let i = 0; i < str.length; i += 4) {
const chunk = parseInt(str.substring(i, i + 4), 16);
array.push(chunk);
}
return array;
};
export const getSendValues = async (option, getDesign, checked) => {
const values: any = option;
const isModbusCommand = ref<boolean>(false); //判断是否是TCP设备-> 且设备标识符是modeBUs,切选择是下发命令类型是属性
const { extensionDesc, commandType, codeType, deviceCode, customCommand } = getDesign || {};
const { registerAddress, actionType } = extensionDesc || {};
const { openCommand, closeCommand, transportType } = customCommand || {};
const modBUS = ref<any>({});
const sendValue = ref();
const { createMessage } = useMessage();
//判断是不是TCP类型设备
if (transportType === TransportTypeEnum.TCP) {
if (
//判断TCP下发类型是否是自定义还是服务
commandType === CommandTypeEnum.CUSTOM.toString() ||
commandType == CommandTypeEnum.SERVICE.toString()
) {
values.customCommand.command = checked ? openCommand : closeCommand;
values.customCommand.command = values.customCommand.command
.replaceAll(/\s/g, '')
.toUpperCase();
}
if (
//判断命令下发类型是不是属性 且是modbus
commandType === CommandTypeEnum.ATTRIBUTE.toString() &&
codeType === TaskTypeEnum.MODBUS_RTU
) {
if (!deviceCode) {
createMessage.warning('当前设备没有设置地址码');
return;
}
if (!actionType) {
createMessage.warning('当前物模型扩展描述没有填写');
return;
}
isModbusCommand.value = true;
modBUS.value = {
crc: 'CRC_16_LOWER',
deviceCode: deviceCode,
method: actionType == '16' ? '10' : actionType,
registerAddress,
registerNumber: 1,
registerValues: [Number(checked)],
};
if (actionType == '16' || actionType == '10') {
const newValue = Number(checked) == 0 ? [0, 0] : getArray(SingleToHex(Number(checked)));
modBUS.value.registerValues = newValue;
modBUS.value.registerNumber = 2;
modBUS.value.method = '10';
}
sendValue.value = await genModbusCommand(unref(modBUS));
}
}
return { values, sendValue: unref(sendValue), isModbusCommand: unref(isModbusCommand) };
};
export const CommandTypeEnumLIst = {
'0': { CUSTOM: 0, name: '自定义' },
'1': { CUSTOM: 1, name: '服务' },
'2': { CUSTOM: 2, name: '属性' },
};