index.ts
3.56 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import type { DeviceAttributeItemType, DeviceItemType, DeviceProfileItemType, OrganizationItemType, RpcCommandType, SendValue, ThingsModel, ThingsModelItemType } from './model'
import type { CommandWayEnum } from '@/enums/commandEnum'
import type { DeviceTypeEnum } from '@/enums/datasource'
import { defHttp } from '@/utils/http'
enum Api {
GET_DEVICE_PROFILE = '/device_profile/me/list',
GET_ORG = '/organization/me/list',
GET_DEVICE_LIST = '/device/list',
GET_DEVICE_ATTRIBUTES = '/device/attributes/',
GET_DEVICE_BY_DEVICE_PROFILED_IDS = '/device/getListByDeviceProfileIds',
GET_THINGS_MODEL_SERVICES = '/things_model/get_services/',
RPC_COMMAND = '/rpc/',
GET_DEVICE_ACTIVE = 'plugins/telemetry/DEVICE/',
RPC_ONEWAY = '/rpc/oneway',
GEN_MODBUS_COMMAND = '/js/modbus',
GET_DEVICE = '/device/', // 获取设备详情
}
export interface GenModbusCommandType {
crc: string
deviceCode: string
method: string
registerAddress: string
registerNumber?: number
registerValues?: number[]
}
export const getDeviceProfile = (deviceType?: DeviceTypeEnum) => {
return defHttp.get<DeviceProfileItemType[]>({
url: Api.GET_DEVICE_PROFILE,
params: { deviceType },
})
}
export const getOrganization = (organizationId?: string) => {
return defHttp.get<OrganizationItemType[]>({
url: Api.GET_ORG,
params: { organizationId },
})
}
export const getDevice = ({ deviceProfileId, deviceType, organizationId }: { deviceType?: DeviceTypeEnum; deviceProfileId?: string; organizationId?: string }) => {
return defHttp.get<DeviceItemType[]>({
url: Api.GET_DEVICE_LIST,
params: { deviceProfileId, deviceType, organizationId },
})
}
export const getDeviceAttributes = (deviceProfileId: string) => {
return defHttp.get<ThingsModelItemType[]>({
url: `${Api.GET_DEVICE_ATTRIBUTES}${deviceProfileId}`,
})
}
export const getListByDeviceProfileIds = (deviceProfileIds: string[]) => {
return defHttp.post<DeviceItemType[]>({
url: Api.GET_DEVICE_BY_DEVICE_PROFILED_IDS,
data: deviceProfileIds,
})
}
export const getThingsModelServices = (deviceProfileId: string) => {
return defHttp.get<ThingsModel>({
url: `${Api.GET_THINGS_MODEL_SERVICES}${deviceProfileId}`,
})
}
export const doCommandDelivery = ({ way, deviceId, command }: { way: CommandWayEnum; deviceId: string; command: RpcCommandType }) => {
return defHttp.post<Record<'rpcId', string>>({
url: `${Api.RPC_COMMAND}/${way}/${deviceId}`,
data: command,
},
{
joinPrefix: false,
},
)
}
export const getDeviceActive = (deviceId: string) => {
return defHttp.get<DeviceAttributeItemType[]>({
url: `${Api.GET_DEVICE_ACTIVE}/${deviceId}/values/attributes?keys=active`,
}, { joinPrefix: false })
}
// 命令下发
export const sendRpcOneway = (param: SendValue | any, deviceId?: string) => {
return defHttp.post({
url: `${Api.RPC_ONEWAY}/${deviceId}`,
data: param,
},
{
joinPrefix: false,
})
}
/**
* @description 生成modbus指令
* @param data
* @returns {string}
*/
export const genModbusCommand = (data: GenModbusCommandType) => {
return defHttp.post<string>({
url: Api.GEN_MODBUS_COMMAND,
data,
})
}
// 获取设备状态,在线 or 离线时间 entityId:设备id
export const getDeviceActiveTime = (entityId: string) => {
return defHttp.get(
{
url: `/plugins/telemetry/DEVICE/${entityId}/values/attributes?keys=active`,
},
{
joinPrefix: false,
},
)
}
// 获取设备详情
export const getDeviceInfo = (deviceId: string) => {
return defHttp.get(
{
url: `${Api.GET_DEVICE}${deviceId}`,
},
)
}