config.ts
1.94 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
import { ref, unref } from 'vue';
import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const';
import { CommandTypeEnum } from '/@/views/rule/linkedge/config/config.data';
import { TaskTypeEnum } from '/@/views/task/center/config';
import { genModbusCommand } from '/@/api/task';
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();
//判断是不是TCP类型设备
if (transportType === TransportTypeEnum.TCP) {
if (
//判断TCP下发类型是否是自定义还是服务
commandType === CommandTypeEnum.CUSTOM.toString() ||
commandType == CommandTypeEnum.SERVICE.toString()
) {
values.customCommand.command = checked ? openCommand : closeCommand;
}
if (
//判断命令下发类型是不是属性
commandType === CommandTypeEnum.ATTRIBUTE.toString() &&
codeType === TaskTypeEnum.MODBUS_RTU
) {
isModbusCommand.value = true;
modBUS.value = {
crc: 'CRC_16_LOWER',
deviceCode: deviceCode,
method: actionType == '16' ? '10' : actionType,
registerAddress,
registerNumber: 1,
registerValues: [Number(checked)],
};
sendValue.value = await genModbusCommand(unref(modBUS));
}
}
return { values, sendValue: unref(sendValue), isModbusCommand: unref(isModbusCommand) };
};
export const CommandTypeEnumLIst = {
'0': { CUSTOM: 0, name: '自定义' },
'1': { CUSTOM: 0, name: '服务' },
'2': { CUSTOM: 0, name: '属性' },
};