guoshilong
2023-11-13 54849757852f6ab40eb17afbd03d1d839b60a38d
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
import request, { IWorkspaceResponse } from '/@/api/http/request'
import { ELocalStorageKey } from '/@/types'
 
// DRC 链路
const DRC_API_PREFIX = '/control/api/v1'
const workspaceId: string = localStorage.getItem(ELocalStorageKey.WorkspaceId) || ''
 
export interface PostDrcBody {
  client_id?: string // token过期时,用于续期则必填
  expire_sec?: number // 过期时间,单位秒,默认3600
}
 
export interface DrcParams {
  address: string
  username: string
  password: string
  client_id: string
  expire_time: number // 过期时间
  enable_tls: boolean // 是否开启tls
}
 
// 获取 mqtt 连接认证
export async function postDrc (body: PostDrcBody): Promise<IWorkspaceResponse<DrcParams>> {
  const resp = await request.post(`${DRC_API_PREFIX}/workspaces/${workspaceId}/drc/connect`, body)
  return resp.data
}
 
export interface DrcEnterBody {
  client_id: string
  dock_sn: string
  expire_sec?: number // 过期时间,单位秒,默认3600
  device_info?: {
    osd_frequency?: number
    hsi_frequency?: number
  }
}
 
export interface DrcEnterResp {
  sub: string[] // 需要订阅接收的topic
  pub: string[] // 推送的topic地址
}
 
// 进入飞行控制 (建立drc连接&获取云控控制权)
export async function postDrcEnter (body: DrcEnterBody): Promise<IWorkspaceResponse<DrcEnterResp>> {
  const resp = await request.post(`${DRC_API_PREFIX}/workspaces/${workspaceId}/drc/enter`, body)
  return resp.data
}
 
export interface DrcExitBody {
  client_id: string
  dock_sn: string
}
 
// 退出飞行控制 (退出drc连接&退出云控控制权)
export async function postDrcExit (body: DrcExitBody): Promise<IWorkspaceResponse<null>> {
  const resp = await request.post(`${DRC_API_PREFIX}/workspaces/${workspaceId}/drc/exit`, body)
  return resp.data
}