添加AirportSystemManager
This commit is contained in:
parent
a377485b23
commit
bf148084bf
|
|
@ -2,11 +2,17 @@ package com.tuoheng.status.machine.manager;
|
||||||
|
|
||||||
import com.tuoheng.status.machine.events.AirportEvent;
|
import com.tuoheng.status.machine.events.AirportEvent;
|
||||||
import com.tuoheng.status.machine.events.CoverEvent;
|
import com.tuoheng.status.machine.events.CoverEvent;
|
||||||
|
import com.tuoheng.status.machine.events.DroneEvent;
|
||||||
|
import com.tuoheng.status.machine.events.DrcEvent;
|
||||||
import com.tuoheng.status.machine.platform.PlatformType;
|
import com.tuoheng.status.machine.platform.PlatformType;
|
||||||
import com.tuoheng.status.machine.service.AirportMachineService;
|
import com.tuoheng.status.machine.service.AirportMachineService;
|
||||||
import com.tuoheng.status.machine.service.CoverMachineService;
|
import com.tuoheng.status.machine.service.CoverMachineService;
|
||||||
|
import com.tuoheng.status.machine.service.DroneMachineService;
|
||||||
|
import com.tuoheng.status.machine.service.DrcMachineService;
|
||||||
import com.tuoheng.status.machine.status.AirportState;
|
import com.tuoheng.status.machine.status.AirportState;
|
||||||
import com.tuoheng.status.machine.status.CoverState;
|
import com.tuoheng.status.machine.status.CoverState;
|
||||||
|
import com.tuoheng.status.machine.status.DroneState;
|
||||||
|
import com.tuoheng.status.machine.status.DrcState;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -27,6 +33,12 @@ public abstract class AbstractAirportSystemManager implements AirportSystemManag
|
||||||
@Autowired
|
@Autowired
|
||||||
protected CoverMachineService coverService;
|
protected CoverMachineService coverService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected DroneMachineService droneService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected DrcMachineService drcService;
|
||||||
|
|
||||||
|
|
||||||
public boolean sendEvent(String airportSn, AirportEvent event) {
|
public boolean sendEvent(String airportSn, AirportEvent event) {
|
||||||
return airportService.sendEvent(airportSn, event);
|
return airportService.sendEvent(airportSn, event);
|
||||||
|
|
@ -36,6 +48,14 @@ public abstract class AbstractAirportSystemManager implements AirportSystemManag
|
||||||
return coverService.sendEvent(airportSn, event);
|
return coverService.sendEvent(airportSn, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean sendEvent(String droneSn, DroneEvent event) {
|
||||||
|
return droneService.sendEvent(droneSn, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean sendEvent(String airportSn, DrcEvent event) {
|
||||||
|
return drcService.sendEvent(airportSn, event);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步机巢状态
|
* 同步机巢状态
|
||||||
* 仅在当前状态为 UNKNOWN 时才同步到目标状态
|
* 仅在当前状态为 UNKNOWN 时才同步到目标状态
|
||||||
|
|
@ -162,5 +182,144 @@ public abstract class AbstractAirportSystemManager implements AirportSystemManag
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步无人机状态
|
||||||
|
* 仅在当前状态为 UNKNOWN 时才同步到目标状态
|
||||||
|
*
|
||||||
|
* @param droneSn 无人机序列号
|
||||||
|
* @param targetState 目标状态
|
||||||
|
* @return 是否同步成功
|
||||||
|
*/
|
||||||
|
public boolean syncDroneState(String droneSn, DroneState targetState) {
|
||||||
|
DroneState currentState = droneService.getCurrentState(droneSn);
|
||||||
|
|
||||||
|
if (currentState == null) {
|
||||||
|
System.out.println(String.format("同步无人机状态失败 - 无人机: %s, 状态机不存在", droneSn));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentState != DroneState.UNKNOWN) {
|
||||||
|
System.out.println(String.format("同步无人机状态跳过 - 无人机: %s, 当前状态: %s (非UNKNOWN状态,无需同步)",
|
||||||
|
droneSn, currentState));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据目标状态发送相应的事件
|
||||||
|
DroneEvent event = getDroneEventForState(targetState);
|
||||||
|
if (event == null) {
|
||||||
|
System.out.println(String.format("同步无人机状态失败 - 无人机: %s, 无法为目标状态 %s 找到对应事件",
|
||||||
|
droneSn, targetState));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean result = droneService.sendEvent(droneSn, event);
|
||||||
|
if (result) {
|
||||||
|
System.out.println(String.format("同步无人机状态成功 - 无人机: %s, 从 UNKNOWN 同步到 %s",
|
||||||
|
droneSn, targetState));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步DRC状态
|
||||||
|
* 仅在当前状态为 UNKNOWN 时才同步到目标状态
|
||||||
|
*
|
||||||
|
* @param airportSn 机巢序列号
|
||||||
|
* @param targetState 目标状态
|
||||||
|
* @return 是否同步成功
|
||||||
|
*/
|
||||||
|
public boolean syncDrcState(String airportSn, DrcState targetState) {
|
||||||
|
DrcState currentState = drcService.getCurrentState(airportSn);
|
||||||
|
|
||||||
|
if (currentState == null) {
|
||||||
|
System.out.println(String.format("同步DRC状态失败 - 机巢: %s, 状态机不存在", airportSn));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentState != DrcState.UNKNOWN) {
|
||||||
|
System.out.println(String.format("同步DRC状态跳过 - 机巢: %s, 当前状态: %s (非UNKNOWN状态,无需同步)",
|
||||||
|
airportSn, currentState));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据目标状态发送相应的事件
|
||||||
|
DrcEvent event = getDrcEventForState(targetState);
|
||||||
|
if (event == null) {
|
||||||
|
System.out.println(String.format("同步DRC状态失败 - 机巢: %s, 无法为目标状态 %s 找到对应事件",
|
||||||
|
airportSn, targetState));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean result = drcService.sendEvent(airportSn, event);
|
||||||
|
if (result) {
|
||||||
|
System.out.println(String.format("同步DRC状态成功 - 机巢: %s, 从 UNKNOWN 同步到 %s",
|
||||||
|
airportSn, targetState));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据目标状态获取对应的无人机事件
|
||||||
|
* 子类可以重写此方法以提供自定义的状态到事件的映射
|
||||||
|
*
|
||||||
|
* @param targetState 目标状态
|
||||||
|
* @return 对应的事件,如果没有对应事件则返回null
|
||||||
|
*/
|
||||||
|
protected DroneEvent getDroneEventForState(DroneState targetState) {
|
||||||
|
switch (targetState) {
|
||||||
|
case OFFLINE:
|
||||||
|
return DroneEvent.DRONE_OFFLINE;
|
||||||
|
case PREPARING:
|
||||||
|
return DroneEvent.START_PREPARE;
|
||||||
|
case FLYING_PARENT:
|
||||||
|
case FLYING:
|
||||||
|
return DroneEvent.START_FLYING;
|
||||||
|
case EMERGENCY_STOP:
|
||||||
|
return DroneEvent.EMERGENCY_STOP;
|
||||||
|
case ARRIVED:
|
||||||
|
return DroneEvent.ARRIVE;
|
||||||
|
case RETURNING_PARENT:
|
||||||
|
case RETURNING:
|
||||||
|
return DroneEvent.START_RETURN;
|
||||||
|
case RETURN_EMERGENCY_STOP:
|
||||||
|
return DroneEvent.RETURN_EMERGENCY_STOP;
|
||||||
|
case RETURN_COMPLETED:
|
||||||
|
return DroneEvent.RETURN_COMPLETED;
|
||||||
|
case POINTING_PARENT:
|
||||||
|
case POINT_PREPARING:
|
||||||
|
return DroneEvent.START_POINTING;
|
||||||
|
case POINT_FLYING:
|
||||||
|
return DroneEvent.POINT_PREPARE_COMPLETED;
|
||||||
|
case POINT_COMPLETED:
|
||||||
|
return DroneEvent.POINT_FLYING_COMPLETED;
|
||||||
|
case POINT_CANCELLED:
|
||||||
|
return DroneEvent.CANCEL_POINT;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据目标状态获取对应的DRC事件
|
||||||
|
* 子类可以重写此方法以提供自定义的状态到事件的映射
|
||||||
|
*
|
||||||
|
* @param targetState 目标状态
|
||||||
|
* @return 对应的事件,如果没有对应事件则返回null
|
||||||
|
*/
|
||||||
|
protected DrcEvent getDrcEventForState(DrcState targetState) {
|
||||||
|
switch (targetState) {
|
||||||
|
case EXITED:
|
||||||
|
return DrcEvent.EXITED;
|
||||||
|
case ENTERING:
|
||||||
|
return DrcEvent.ENTER;
|
||||||
|
case ENTERED:
|
||||||
|
return DrcEvent.ENTERED;
|
||||||
|
case EXITING:
|
||||||
|
return DrcEvent.EXIT;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,13 @@ package com.tuoheng.status.machine.manager;
|
||||||
|
|
||||||
import com.tuoheng.status.machine.events.AirportEvent;
|
import com.tuoheng.status.machine.events.AirportEvent;
|
||||||
import com.tuoheng.status.machine.events.CoverEvent;
|
import com.tuoheng.status.machine.events.CoverEvent;
|
||||||
|
import com.tuoheng.status.machine.events.DroneEvent;
|
||||||
|
import com.tuoheng.status.machine.events.DrcEvent;
|
||||||
import com.tuoheng.status.machine.platform.PlatformType;
|
import com.tuoheng.status.machine.platform.PlatformType;
|
||||||
import com.tuoheng.status.machine.status.AirportState;
|
import com.tuoheng.status.machine.status.AirportState;
|
||||||
import com.tuoheng.status.machine.status.CoverState;
|
import com.tuoheng.status.machine.status.CoverState;
|
||||||
|
import com.tuoheng.status.machine.status.DroneState;
|
||||||
|
import com.tuoheng.status.machine.status.DrcState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 机巢系统管理器接口
|
* 机巢系统管理器接口
|
||||||
|
|
@ -21,9 +25,17 @@ public interface AirportSystemManager {
|
||||||
|
|
||||||
public boolean sendEvent(String airportSn, CoverEvent event);
|
public boolean sendEvent(String airportSn, CoverEvent event);
|
||||||
|
|
||||||
|
public boolean sendEvent(String droneSn, DroneEvent event);
|
||||||
|
|
||||||
|
public boolean sendEvent(String airportSn, DrcEvent event);
|
||||||
|
|
||||||
public boolean syncAirportState(String airportSn, AirportState targetState);
|
public boolean syncAirportState(String airportSn, AirportState targetState);
|
||||||
|
|
||||||
public boolean syncCoverState(String airportSn, CoverState targetState);
|
public boolean syncCoverState(String airportSn, CoverState targetState);
|
||||||
|
|
||||||
|
public boolean syncDroneState(String droneSn, DroneState targetState);
|
||||||
|
|
||||||
|
public boolean syncDrcState(String airportSn, DrcState targetState);
|
||||||
/**
|
/**
|
||||||
* 有心跳的时候调用
|
* 有心跳的时候调用
|
||||||
* @param airportSn
|
* @param airportSn
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue