| | |
| | | import axios from 'axios' |
| | | import axios from 'axios' |
| | | import type { |
| | | InstanceListItem, |
| | | InstanceState, |
| | | InstanceConfig, |
| | | ProtocolTemplate |
| | | ProtocolTemplate, |
| | | RobotClientStartRequest, |
| | | RobotClientSendRequest, |
| | | RobotClientStatusResponse |
| | | } from '../types' |
| | | |
| | | const api = axios.create({ |
| | |
| | | return response.data |
| | | } |
| | | |
| | | // 获取指定实例状态 |
| | | // 获取实例状态 |
| | | export async function getInstance(id: string): Promise<InstanceState | null> { |
| | | try { |
| | | const response = await api.get<InstanceState>('/SimulatorInstances/GetInstance', { |
| | |
| | | } |
| | | } |
| | | |
| | | // 获取机械手服务端运行状态(包含多实例和接收消息日志) |
| | | export async function getRobotClientStatus(): Promise<RobotClientStatusResponse> { |
| | | const response = await api.get<RobotClientStatusResponse>('/RobotClients/status') |
| | | return response.data |
| | | } |
| | | |
| | | // 启动一个机械手服务端实例 |
| | | export async function startRobotClients(request: RobotClientStartRequest): Promise<RobotClientStatusResponse> { |
| | | const response = await api.post<RobotClientStatusResponse>('/RobotClients/start', request) |
| | | return response.data |
| | | } |
| | | |
| | | // 停止机械手服务端,serverId 为空时停止全部 |
| | | export async function stopRobotClients(serverId?: string): Promise<void> { |
| | | await api.post('/RobotClients/stop', null, { |
| | | params: { serverId } |
| | | }) |
| | | } |
| | | |
| | | // 发送机械手消息(按服务端实例广播或单发) |
| | | export async function sendRobotClientMessage(request: RobotClientSendRequest): Promise<void> { |
| | | await api.post('/RobotClients/send', request) |
| | | } |
| | | |
| | | // 清空指定服务端实例的接收消息日志 |
| | | export async function clearRobotClientReceivedMessages(serverId: string): Promise<void> { |
| | | await api.post('/RobotClients/clear-received', null, { |
| | | params: { serverId } |
| | | }) |
| | | } |
| | | |
| | | export default api |