#update
This commit is contained in:
@@ -32,5 +32,5 @@ public class Constant {
|
||||
// ==================== 远程控制 ====================
|
||||
public static final String protocol_version = "1.4.7";
|
||||
public static final String remote_control_msg_prefix = "remote-msg";
|
||||
public static final String remote_control_cmd_prefix = "remote-cmd";
|
||||
public static final String remote_control_cmd_prefix = "remote-cmd_";
|
||||
}
|
||||
|
||||
@@ -70,4 +70,7 @@ public class DevicePlanTask extends OrgBaseDO {
|
||||
|
||||
private String failedReason;
|
||||
|
||||
|
||||
private String canceledReason;
|
||||
|
||||
}
|
||||
|
||||
@@ -9,10 +9,12 @@ import com.maibu.core.business.path.RoutePlanSendEntity;
|
||||
import com.maibu.core.enums.ConnectorType;
|
||||
import com.maibu.core.enums.DeviceTaskStaus;
|
||||
import com.maibu.core.enums.RouteType;
|
||||
import com.maibu.core.host.DeviceRemoteControlDTO;
|
||||
import com.maibu.core.host.HostEstopChangeDTO;
|
||||
import com.maibu.core.host.HostModeChangeDTO;
|
||||
import com.maibu.core.host.HostWorkRecordCreateDTO;
|
||||
import com.maibu.core.host.MutiPointEntity;
|
||||
import com.maibu.core.host.ParamDetail;
|
||||
import com.maibu.core.host.PointEntity;
|
||||
import com.maibu.core.ota.DeviceOtaFirmware;
|
||||
import com.maibu.mapper.DevicePlanTaskMapper;
|
||||
@@ -226,12 +228,12 @@ public class NettyDevice extends Connector {
|
||||
return true;
|
||||
}
|
||||
|
||||
public synchronized Long canceledTask() {
|
||||
public synchronized Long canceledTask(String canceledReason) {
|
||||
if (task != null) {
|
||||
Long taskId = task.getId();
|
||||
task.setTaskStaus(DeviceTaskStaus.CANCELED);
|
||||
task.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
task.setCanceledReason(canceledReason);
|
||||
// 更新累计里程
|
||||
updateWorkArea();
|
||||
devicePlanTaskMapper.saveOrUpdate(task);
|
||||
@@ -600,6 +602,33 @@ public class NettyDevice extends Connector {
|
||||
JsonUtils.toJsonString(payload));
|
||||
}
|
||||
|
||||
public void sendResetCommand(String deviceId, String key) throws MqttException {
|
||||
|
||||
// todo 转换 原先的报文重新组装成上位机的报文格式
|
||||
DeviceRemoteControlDTO deviceRemoteControlDTO = new DeviceRemoteControlDTO();
|
||||
|
||||
ParamDetail data = new ParamDetail();
|
||||
|
||||
data.setLinear_x(0d);
|
||||
data.setAngular_z(0d);
|
||||
data.setChassis_lift(2);
|
||||
data.setCutter(0);
|
||||
data.setIgnition(0);
|
||||
data.setValid_for_ms(250); // 间隔 可调整
|
||||
deviceRemoteControlDTO.setData(data);
|
||||
deviceRemoteControlDTO.setCommand_id(key);
|
||||
deviceRemoteControlDTO.setSn(deviceId);
|
||||
deviceRemoteControlDTO.setTimestamp(System.currentTimeMillis());
|
||||
deviceRemoteControlDTO
|
||||
.setMessage_id(Constant.remote_control_msg_prefix + System.currentTimeMillis());
|
||||
deviceRemoteControlDTO.setProtocol_version(Constant.protocol_version);
|
||||
|
||||
GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
|
||||
String.format(MqttTopic.MOWER_CONTROL_SET, deviceId),
|
||||
JsonUtils.toJsonString(deviceRemoteControlDTO));
|
||||
log.debug("切换自动前复位{},发送遥控指令:{}", deviceId, JsonUtils.toJsonString(deviceRemoteControlDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 急停更新
|
||||
*
|
||||
@@ -623,4 +652,27 @@ public class NettyDevice extends Connector {
|
||||
JsonUtils.toJsonString(payload));
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启视频推理
|
||||
*
|
||||
* @param deviceId
|
||||
* @throws MqttException
|
||||
*/
|
||||
public void startVideoStream(String deviceId) throws MqttException {
|
||||
HostEstopChangeDTO payload = new HostEstopChangeDTO();
|
||||
payload.setSn(deviceId);
|
||||
payload.setTimestamp(System.currentTimeMillis());
|
||||
payload.setMessage_id("startVideoStream_" + System.currentTimeMillis());
|
||||
payload.setCommand_id("startVideoStreamCommand_ " + System.currentTimeMillis());
|
||||
payload.setProtocol_version(Constant.protocol_version);
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("start", 1);
|
||||
payload.setData(data);
|
||||
|
||||
GlobalMemory.customMqttDeviceMonitor.publish(
|
||||
mqttClientId,
|
||||
String.format(MqttTopic.MOWER_VIDEO_STREAM_SET, deviceId),
|
||||
JsonUtils.toJsonString(payload));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.maibu.core.host;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class HostRemoteControlReplyDTO extends HostBase {
|
||||
|
||||
private String command_id;// 指令唯一编号
|
||||
private Boolean accepted;// 是否接收
|
||||
private String code;// 任务动作 OK|INVALID|BUSY|ERROR
|
||||
|
||||
private String message;
|
||||
|
||||
}
|
||||
@@ -15,5 +15,7 @@ public class HostTaskStatusDTO extends HostBase{
|
||||
|
||||
private HostTaskStatusDetailDTO data;
|
||||
|
||||
private String message;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ public class GlobalMemory {
|
||||
public static ConcurrentHashMap<String, CompletableFuture<Boolean>> modeFutureMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static ConcurrentHashMap<String, CompletableFuture<Boolean>> eStopFutureMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static ConcurrentHashMap<String, CompletableFuture<Boolean>> remoteControlFutureMap = new ConcurrentHashMap<>();
|
||||
// public static MqttClientUtil mqttClientUtil;
|
||||
|
||||
public static CustomMqttDeviceMonitor customMqttDeviceMonitor = null; // 这里面包含了 连我们自己的mqtt 和外部的一些设备,自己的用clientId
|
||||
@@ -122,8 +124,8 @@ public class GlobalMemory {
|
||||
MqttTopic.MOWER_MODE_REPLY, // 模式切换回复
|
||||
MqttTopic.MOWER_FAULT_POST, // 故障上报
|
||||
MqttTopic.MOWER_FAULT_RECOVERY_REPLY, // 故障恢复回复
|
||||
MqttTopic.MOWER_ESTOP_REPLY // 急停的回复
|
||||
));
|
||||
MqttTopic.MOWER_ESTOP_REPLY, // 急停的回复
|
||||
MqttTopic.MOWER_CONTROL_Reply));
|
||||
deviceConfig.setHandlerType(Constant.mqttHandleKey); // 唯一的 用于处理上位机mqtt的
|
||||
customMqttDeviceMonitor.registerDevice(deviceConfig);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.maibu.core.business.RegionConsecutiveTaskRecord;
|
||||
import com.maibu.core.business.alarm_center.AlarmMessage;
|
||||
import com.maibu.core.business.dto.ConsecutiveTaskDTO;
|
||||
import com.maibu.core.business.dto.DeviceMapPushDTO;
|
||||
import com.maibu.core.domain.AjaxResult;
|
||||
import com.maibu.core.domain.entity.SysSite;
|
||||
import com.maibu.core.domain.rule.IotAutoRule;
|
||||
import com.maibu.core.enums.DeviceTaskStaus;
|
||||
@@ -202,6 +203,14 @@ public class SiteMemory {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Integer getDeviceSystemMode(String deviceId) {
|
||||
VehicleMessage v = getVehicleMessage(deviceId);
|
||||
if (v != null) {
|
||||
return v.getSystem_mode();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public VehicleMessage getVehicleMessage(String deviceId) {
|
||||
return vehicleMessageMap.get(deviceId);
|
||||
}
|
||||
@@ -508,4 +517,25 @@ public class SiteMemory {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean canReceiveAutoTask(String deviceId) {
|
||||
|
||||
Integer controlMode = getDeviceControlMode(deviceId);
|
||||
Integer systemMode = getDeviceSystemMode(deviceId);
|
||||
|
||||
if (controlMode == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (controlMode == 0) {
|
||||
return Objects.equals(systemMode, 2);
|
||||
}
|
||||
|
||||
if (controlMode == 2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// controlMode == 1、3 或未知值,均不允许
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.maibu.core.host.HeartBeatDTO;
|
||||
import com.maibu.core.host.HostLocationRelTimeDTO;
|
||||
import com.maibu.core.host.HostModeChangeReplyDTO;
|
||||
import com.maibu.core.host.HostNavigationReplyDTO;
|
||||
import com.maibu.core.host.HostRemoteControlReplyDTO;
|
||||
import com.maibu.core.host.HostTaskStatusDTO;
|
||||
import com.maibu.core.host.HostVehicleRelTimeDTO;
|
||||
import com.maibu.core.host.LocationMessage;
|
||||
@@ -513,7 +514,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
|
||||
if (siteMemory != null) {
|
||||
|
||||
// siteMemory.saveVehicleMessage(deviceId, vehicleRelTimeDTO.getData());
|
||||
siteMemory.saveVehicleMessage(deviceId, vehicleRelTimeDTO.getData());
|
||||
|
||||
// systemMode = siteMemory.getVehicleMessage(deviceId).getSystemMode();
|
||||
// Integer oldSystemMode =
|
||||
@@ -544,8 +545,6 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
siteMemory.saveVehicleMessage(deviceId, vehicleRelTimeDTO.getData());
|
||||
|
||||
// 故障处理
|
||||
Long errorCode = vehicleRelTimeDTO.getData().getError_code();
|
||||
if (errorCode != null && errorCode != 0) {
|
||||
@@ -801,7 +800,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
task.setTotalTaskDistance(dto.getData().getTotal_distance_m());
|
||||
task.setTotalTaskTime(dto.getData().getExecution_time_s());
|
||||
}
|
||||
Long taskId = nettyDevice.canceledTask();
|
||||
Long taskId = nettyDevice.canceledTask(dto.getMessage());
|
||||
pushTaskChangeMessage(deviceId, taskId, DeviceTaskStaus.CANCELED.toString());
|
||||
|
||||
}
|
||||
@@ -907,10 +906,21 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理控制指令响应
|
||||
* 处理远程遥控指令响应
|
||||
*/
|
||||
private void handleControlReply(String deviceId, String topic, String payload) {
|
||||
log.debug("【控制响应】deviceId={}, payload={}", deviceId, payload);
|
||||
log.debug("【远程遥控响应】deviceId={}, payload={}", deviceId, payload);
|
||||
|
||||
HostRemoteControlReplyDTO replyDTO = JsonUtils.parseObject(payload, HostRemoteControlReplyDTO.class);
|
||||
|
||||
if (replyDTO != null && !StringUtils.isEmpty(replyDTO.getCommand_id())) {
|
||||
CompletableFuture<Boolean> future = GlobalMemory.remoteControlFutureMap.get(replyDTO.getCommand_id());
|
||||
|
||||
if (future != null && replyDTO != null) {
|
||||
future.complete(replyDTO.getAccepted());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1132,13 +1142,11 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
return "heartbeat_post";
|
||||
if (remaining.equals("event/error/post"))
|
||||
return "error_post";
|
||||
// if (remaining.equals("task/route/post")) return "route_post";
|
||||
// if (remaining.equals("task/point/post")) return "point_post";
|
||||
if (remaining.equals("task/status/post"))
|
||||
return "task_status_post";
|
||||
if (remaining.equals("action/config/reply"))
|
||||
return "config_reply";
|
||||
if (remaining.equals("action/control/reply"))
|
||||
if (remaining.equals("control/remote/reply"))
|
||||
return "control_reply";
|
||||
if (remaining.equals("task/target/reply"))
|
||||
return "route_reply";
|
||||
|
||||
@@ -51,6 +51,8 @@ public class MqttTopic {
|
||||
/** 远程控制指令下发:前进/后退/转向/割草等(平台->设备),对应 TCP 0x00 remoteControl */
|
||||
public static final String MOWER_CONTROL_SET = "mower/%s/control/remote/set";
|
||||
|
||||
public static final String MOWER_CONTROL_Reply = "mower/+/control/remote/reply";
|
||||
|
||||
// ==================== 任务管理 ====================
|
||||
/** 路径规划下发(平台->设备),对应 TCP 0x01 path */
|
||||
// public static final String MOWER_TASK_ROUTE_SET = "mower/%s/task/route/set";
|
||||
@@ -133,6 +135,9 @@ public class MqttTopic {
|
||||
/** 设置无遥控器时候的急停回复(设备->平台) */
|
||||
public static final String MOWER_ESTOP_REPLY = "mower/+/control/emergency_stop/reply";
|
||||
|
||||
/** 开启推流(平台->设备) */
|
||||
public static final String MOWER_VIDEO_STREAM_SET = "mower/%s/video/stream/set";
|
||||
|
||||
/**
|
||||
* 格式化 Topic 模板,将 %s 替换为设备ID
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user