开关机
This commit is contained in:
parent
02a6b3ecf8
commit
42e6643b52
|
|
@ -9,6 +9,11 @@ public enum CommandType {
|
|||
*/
|
||||
POWER_ON,
|
||||
|
||||
/**
|
||||
* 关机
|
||||
*/
|
||||
POWER_OFF,
|
||||
|
||||
/**
|
||||
* 起飞
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -53,6 +53,11 @@ public class TuohengVendorConfig implements VendorConfig {
|
|||
return airportState == AirportState.ONLINE
|
||||
&& droneState == DroneState.POWER_OFF;
|
||||
|
||||
case POWER_OFF:
|
||||
// 关机前置条件:机场在线、无人机在线(未飞行)
|
||||
return airportState == AirportState.ONLINE
|
||||
&& droneState == DroneState.ONLINE;
|
||||
|
||||
case TAKE_OFF:
|
||||
// 起飞前置条件:无人机已开机、机场在线
|
||||
return droneState == DroneState.ONLINE
|
||||
|
|
@ -87,9 +92,15 @@ public class TuohengVendorConfig implements VendorConfig {
|
|||
// 开机命令
|
||||
Transaction powerOnTransaction = new Transaction("开机", CommandType.POWER_ON)
|
||||
.root(new com.ruoyi.device.domain.impl.machine.vendor.tuoheng.instruction.TuohengPowerOnInstruction())
|
||||
.setTimeout(60000);
|
||||
.setTimeout(240000);
|
||||
transactionMap.put(powerOnTransaction.getCommandType(), powerOnTransaction);
|
||||
|
||||
// 关机命令
|
||||
Transaction powerOffTransaction = new Transaction("关机", CommandType.POWER_OFF)
|
||||
.root(new com.ruoyi.device.domain.impl.machine.vendor.tuoheng.instruction.TuohengPowerOffInstruction())
|
||||
.setTimeout(240000);
|
||||
transactionMap.put(powerOffTransaction.getCommandType(), powerOffTransaction);
|
||||
|
||||
log.info("拓恒厂家配置初始化完成,共配置{}个命令", transactionMap.size());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
package com.ruoyi.device.domain.impl.machine.vendor.tuoheng.instruction;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.device.domain.impl.machine.instruction.AbstractInstruction;
|
||||
import com.ruoyi.device.domain.impl.machine.instruction.CallbackConfig;
|
||||
import com.ruoyi.device.domain.impl.machine.instruction.InstructionContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 拓恒无人机关机指令
|
||||
*/
|
||||
@Slf4j
|
||||
public class TuohengPowerOffInstruction extends AbstractInstruction {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "TUOHENG_POWER_OFF";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeRemoteCall(InstructionContext context) throws Exception {
|
||||
String sn = context.getSn();
|
||||
log.info("发送拓恒无人机关机指令: sn={}", sn);
|
||||
// 构建MQTT消息
|
||||
JSONObject payload = new JSONObject();
|
||||
payload.put("messageID", System.currentTimeMillis());
|
||||
payload.put("timestamp", System.currentTimeMillis());
|
||||
payload.put("code", "DronePower");
|
||||
payload.put("value", "2"); // 1=开机, 2=关机
|
||||
payload.put("channel", 1);
|
||||
|
||||
String topic = "/topic/v1/airportNest/" + sn + "/control";
|
||||
|
||||
context.getMqttClient().sendMessage(topic, payload.toJSONString());
|
||||
log.info("拓恒关机指令发送成功: topic={}, payload={}", topic, payload.toJSONString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallbackConfig getMethodCallbackConfig(InstructionContext context) {
|
||||
String sn = context.getSn();
|
||||
|
||||
// 监听机场确认消息
|
||||
return CallbackConfig.builder()
|
||||
.topic("/topic/v1/airportNest/" + sn + "/control/confirm")
|
||||
.fieldPath("msg")
|
||||
.expectedValue("[综管]无人机关机指令接收成功")
|
||||
.timeoutMs(60000)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallbackConfig getStateCallbackConfig(InstructionContext context) {
|
||||
String sn = context.getSn();
|
||||
|
||||
// 监听无人机关机状态变化
|
||||
return CallbackConfig.builder()
|
||||
.topic("/topic/v1/airportNest/" + sn + "/realTime/data")
|
||||
.fieldPath("droneBattery.data.bPowerON")
|
||||
.expectedValue("2") // 2表示已关机
|
||||
.timeoutMs(180000)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimeoutMs() {
|
||||
return 240000; // 总超时时间60秒
|
||||
}
|
||||
}
|
||||
|
|
@ -41,9 +41,9 @@ public class TuohengPowerOnInstruction extends AbstractInstruction {
|
|||
// 监听机场确认消息
|
||||
return CallbackConfig.builder()
|
||||
.topic("/topic/v1/airportNest/" + sn + "/control/confirm")
|
||||
.fieldPath("code")
|
||||
.expectedValue("DronePower")
|
||||
.timeoutMs(10000)
|
||||
.fieldPath("msg")
|
||||
.expectedValue("[综管]无人机开机指令接收成功")
|
||||
.timeoutMs(60000)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
@ -54,14 +54,14 @@ public class TuohengPowerOnInstruction extends AbstractInstruction {
|
|||
// 监听无人机开机状态变化
|
||||
return CallbackConfig.builder()
|
||||
.topic("/topic/v1/airportNest/" + sn + "/realTime/data")
|
||||
.fieldPath("droneBattery.bPowerON")
|
||||
.expectedValue("2") // 2表示已开机
|
||||
.timeoutMs(60000)
|
||||
.fieldPath("droneBattery.data.bPowerON")
|
||||
.expectedValue("1") // 1表示已开机
|
||||
.timeoutMs(180000)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimeoutMs() {
|
||||
return 60000; // 总超时时间60秒
|
||||
return 240000; // 总超时时间60秒
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue