罗广辉
2025-06-19 f27ca082eb0a839449dd50c49007b58e5ed6946f
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
/*
 * @Author: GuLiMmo 2820890765@qq.com
 * @Date: 2024-03-12 17:59:03
 * @LastEditors: GuLiMmo 2820890765@qq.com
 * @LastEditTime: 2024-08-27 17:10:11
 * @FilePath: /drone-web/src/api/drc.ts
 * @Description:
 * Copyright (c) 2024 by GuLiMmo, All Rights Reserved.
 */
import request, { IWorkspaceResponse } from '/@/api/http/request'
import { ELocalStorageKey } from '/@/types'
 
// DRC 链路
const DRC_API_PREFIX = '/control/api/v1'
 
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 workspaceId: string = localStorage.getItem(ELocalStorageKey.WorkspaceId) || ''
  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 workspaceId: string = localStorage.getItem(ELocalStorageKey.WorkspaceId) || ''
  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 workspaceId: string = localStorage.getItem(ELocalStorageKey.WorkspaceId) || ''
  const resp = await request.post(`${DRC_API_PREFIX}/workspaces/${workspaceId}/drc/exit`, body)
  return resp.data
}