This commit is contained in:
wxs 2026-03-11 18:45:18 +08:00
commit e18c6212af
5 changed files with 37 additions and 35 deletions

View File

@ -28,7 +28,6 @@ import com.zhangy.skyeye.publics.consts.UavAirlineUploadEnum;
import com.zhangy.skyeye.publics.consts.WebSocketKey;
import com.zhangy.skyeye.publics.service.SysFileTypeService;
import com.zhangy.skyeye.publics.utils.CoordUtil;
import com.zhangy.skyeye.py.service.IPyAirlineService;
import com.zhangy.skyeye.quartz.service.QuartzService;
import com.zhangy.skyeye.sar.consts.SarImageModeEnum;
import com.zhangy.skyeye.sar.dto.SarControlParamDTO;
@ -377,6 +376,7 @@ public class JmJobServiceImpl implements JmJobService {
// 4.任务状态放入缓存
jobStatusService.add(job);
} catch (Throwable ex) {
log.warn("{}", ex.getMessage(), ex);
jobStatusService.remove(job.getId());
throw ex;
}

View File

@ -129,7 +129,7 @@ public class JmTaskScheduler {
controlInfoService.sendUdp(sar.getIp(), SarControlTypeEnum.CONNECT);
} catch (SarConnectException ex) {
// sar可能没通电连接失败不做处理
log.warn("连接雷达[" + sar.getIp() + "]失败:" + ex.getMessage());
// log.warn("连接雷达[" + sar.getIp() + "]失败:" + ex.getMessage());
}
}
});

View File

@ -24,6 +24,7 @@ import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
@ -78,9 +79,11 @@ public class SarControlContext {
* @param param
*/
public void execute(SarControlParamDTO param) {
log.info("execute :{}",JSON.toJSONString(param));
List<ISarControlStrategy> matchedStrategys = strategies.stream()
.filter(strategy -> strategy.supports(param))
.collect(Collectors.toList());
log.info("matchedStrategys :{}",JSON.toJSONString(matchedStrategys));
if (ObjectUtil.isEmpty(matchedStrategys)) {
throw ServiceException.errorLog("无效的控制指令!");
}
@ -109,36 +112,20 @@ public class SarControlContext {
private void sendUdp(SarControlDTO control) {
SarControlTypeEnum controlType = control.getControlType();
String ip = control.getIp();
// log.debug("开始发送雷达控制指令[" + controlType + "]----------------------");
log.debug("send control:\n{}", JSON.toJSONString(control));
log.trace("send control:{}", JSON.toJSONString(control));
try (DatagramSocket socket = new DatagramSocket()) {
byte[] content = pack(control);
socket.connect(new InetSocketAddress(ip, PORT));
DatagramPacket packet = new DatagramPacket(content, content.length);
int failCount = 0;
SarErrorDTO info = null;
int failCount = 0;
while (info == null && failCount < RETRY_MAX) { // 失败重试
log.info("发送雷达控制指令 [{}] -> {} (第{}次)", controlType, ip, failCount + 1);
socket.send(packet);
// 每0.1秒取回执1秒后超时
long startTime = System.currentTimeMillis();
String cacheKey = CacheKey.getSarControlBack(ip);
while (System.currentTimeMillis() - startTime < ANSWER_TIMEOUT) {
if (redisUtil.hasKey(cacheKey)) {
info = (SarErrorDTO) redisUtil.get(cacheKey);
redisUtil.del(cacheKey);
break;
} else {
try {
Thread.sleep(POLLING_INTERVAL);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
if (info == null) { // 超时未收到回执
info = waitForReply(ip);
if (info == null) {
failCount++;
log.warn("雷达 [{}] 未返回回执,第{}次重试", ip, failCount);
} else if (info.getExecStatus() == 1) {
// 只有发送的数据结构错误时才会返回错误状态并不会因为业务不允许返回错误
throw new ServiceException("控制指令[" + controlType + "]执行状态错误,请重试");
@ -146,9 +133,8 @@ public class SarControlContext {
}
if (info == null) {
throw new SarConnectException("控制指令[" + controlType + "]发送失败,雷达[" + ip + "]无应答,请重试");
} else {
log.info("雷达控制指令[" + controlType + "]发送完毕----------------------");
}
log.info("雷达控制指令 [{}] 发送成功 -> {}", controlType, ip);
} catch (RedisConnectionFailureException ex) {
throw ServiceException.errorLog("无法连接到Redis服务");
} catch (IOException ex) {
@ -156,6 +142,26 @@ public class SarControlContext {
}
}
private SarErrorDTO waitForReply(String ip) {
String cacheKey = CacheKey.getSarControlBack(ip);
// 每0.1秒取回执1秒后超时
long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime < ANSWER_TIMEOUT) {
if (redisUtil.hasKey(cacheKey)) {
SarErrorDTO info = (SarErrorDTO) redisUtil.get(cacheKey);
redisUtil.del(cacheKey);
log.info("收到雷达回执 ip={}", ip);
return info;
}
try {
Thread.sleep(POLLING_INTERVAL);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
return null;
}
/**
* 封包
* @param sarControl

View File

@ -75,11 +75,10 @@ public class SarStatusListener extends SarAbstractListener {
if (packet.getLength() != 100) {
return;
}
log.debug("接收到状态包----------------------");
String ip = packet.getAddress().getHostAddress();
// 处理接收到的数据
SarStatusPackDTO packDTO = SarStatusPackDTO.parse(ip, packet.getData());
log.debug("recv status:\n{}", JSON.toJSONString(packDTO));
log.trace("recv status:\n{}", JSON.toJSONString(packDTO));
if (packDTO == null) {
if (running)
log.warn("[" + packDTO.getPayloadIp() + "]状态包校验失败,已丢弃。错误包=" +
@ -91,7 +90,6 @@ public class SarStatusListener extends SarAbstractListener {
if (errorStatus == 1) {
SarErrorDTO info = packDTO.getDeviceErrorInfo();
if (info.getErrorPacketType() == SarErrorTypeEnum.RESULT) {
log.debug("收到回执包:" + ip);
redisUtil.set(CacheKey.getSarControlBack(ip), info, answerTimeout, TimeUnit.SECONDS);
}
}
@ -99,11 +97,8 @@ public class SarStatusListener extends SarAbstractListener {
int deviceStatus = packDTO.getDevicePacketStatus();
if (deviceStatus == 1) {
JmSarStatusDTO info = packDTO.getDeviceStatusInfo();
log.debug("sar开机状态" + info.getIsBoot());
sarJobStatusService.update(ip, info);
redisUtil.set(CacheKey.getSarConnect(ip), info, answerTimeout, TimeUnit.SECONDS);
//System.out.println(info);
}
log.debug("----------------------状态包解析完毕");
}
}
}

View File

@ -1,11 +1,11 @@
package com.zhangy.skyeye.sar.service.impl;
import com.alibaba.fastjson2.JSON;
import com.zhangy.skyeye.common.extend.exception.ServiceException;
import com.zhangy.skyeye.common.extend.util.JsonUtil;
import com.zhangy.skyeye.jm.dto.JmJobDTO;
import com.zhangy.skyeye.jm.dto.JmSarStatusDTO;
import com.zhangy.skyeye.jm.entity.JmJobPayload;
import com.zhangy.skyeye.jm.entity.JmJobUav;
import com.zhangy.skyeye.publics.consts.CacheKey;
import com.zhangy.skyeye.redis.utils.RedisUtil;
import com.zhangy.skyeye.sar.control.SarControlContext;
@ -36,6 +36,7 @@ public class SarControlServiceImpl implements ISarControlService {
@Override
public void sendUdp(JmJobDTO job) {
log.info("sendUdp{}", JSON.toJSONString(job));
if (job == null || job.getUavList() == null) return;
job.getUavList().forEach(uav -> {
JmJobPayload sar = uav.getSar0();
@ -48,7 +49,7 @@ public class SarControlServiceImpl implements ISarControlService {
param.setImageBit(sar.getImageBit());
param.setResolution(sar.getResolution());
if (job.getMode().equals(CRUISE.getCode())) {
param.setControlType(SarControlTypeEnum.TURNON);
param.setControlType(SarControlTypeEnum.UPLOAD);
} else {
param.setControlType(SarControlTypeEnum.AUTO);
}