Optimize some code and logs
This commit is contained in:
parent
1ee68c6f9b
commit
2839793fec
@ -28,7 +28,6 @@ import com.zhangy.skyeye.publics.consts.UavAirlineUploadEnum;
|
|||||||
import com.zhangy.skyeye.publics.consts.WebSocketKey;
|
import com.zhangy.skyeye.publics.consts.WebSocketKey;
|
||||||
import com.zhangy.skyeye.publics.service.SysFileTypeService;
|
import com.zhangy.skyeye.publics.service.SysFileTypeService;
|
||||||
import com.zhangy.skyeye.publics.utils.CoordUtil;
|
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.quartz.service.QuartzService;
|
||||||
import com.zhangy.skyeye.sar.consts.SarImageModeEnum;
|
import com.zhangy.skyeye.sar.consts.SarImageModeEnum;
|
||||||
import com.zhangy.skyeye.sar.dto.SarControlParamDTO;
|
import com.zhangy.skyeye.sar.dto.SarControlParamDTO;
|
||||||
@ -377,6 +376,7 @@ public class JmJobServiceImpl implements JmJobService {
|
|||||||
// 4.任务状态放入缓存
|
// 4.任务状态放入缓存
|
||||||
jobStatusService.add(job);
|
jobStatusService.add(job);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
|
log.warn("{}", ex.getMessage(), ex);
|
||||||
jobStatusService.remove(job.getId());
|
jobStatusService.remove(job.getId());
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -129,7 +129,7 @@ public class JmTaskScheduler {
|
|||||||
controlInfoService.sendUdp(sar.getIp(), SarControlTypeEnum.CONNECT);
|
controlInfoService.sendUdp(sar.getIp(), SarControlTypeEnum.CONNECT);
|
||||||
} catch (SarConnectException ex) {
|
} catch (SarConnectException ex) {
|
||||||
// sar可能没通电,连接失败不做处理
|
// sar可能没通电,连接失败不做处理
|
||||||
log.warn("连接雷达[" + sar.getIp() + "]失败:" + ex.getMessage());
|
// log.warn("连接雷达[" + sar.getIp() + "]失败:" + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import java.net.DatagramPacket;
|
|||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,9 +79,11 @@ public class SarControlContext {
|
|||||||
* @param param
|
* @param param
|
||||||
*/
|
*/
|
||||||
public void execute(SarControlParamDTO param) {
|
public void execute(SarControlParamDTO param) {
|
||||||
|
log.info("execute :{}",JSON.toJSONString(param));
|
||||||
List<ISarControlStrategy> matchedStrategys = strategies.stream()
|
List<ISarControlStrategy> matchedStrategys = strategies.stream()
|
||||||
.filter(strategy -> strategy.supports(param))
|
.filter(strategy -> strategy.supports(param))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
log.info("matchedStrategys :{}",JSON.toJSONString(matchedStrategys));
|
||||||
if (ObjectUtil.isEmpty(matchedStrategys)) {
|
if (ObjectUtil.isEmpty(matchedStrategys)) {
|
||||||
throw ServiceException.errorLog("无效的控制指令!");
|
throw ServiceException.errorLog("无效的控制指令!");
|
||||||
}
|
}
|
||||||
@ -109,36 +112,20 @@ public class SarControlContext {
|
|||||||
private void sendUdp(SarControlDTO control) {
|
private void sendUdp(SarControlDTO control) {
|
||||||
SarControlTypeEnum controlType = control.getControlType();
|
SarControlTypeEnum controlType = control.getControlType();
|
||||||
String ip = control.getIp();
|
String ip = control.getIp();
|
||||||
// log.debug("开始发送雷达控制指令[" + controlType + "]----------------------");
|
log.trace("send control:{}", JSON.toJSONString(control));
|
||||||
log.debug("send control:\n{}", JSON.toJSONString(control));
|
|
||||||
try (DatagramSocket socket = new DatagramSocket()) {
|
try (DatagramSocket socket = new DatagramSocket()) {
|
||||||
byte[] content = pack(control);
|
byte[] content = pack(control);
|
||||||
socket.connect(new InetSocketAddress(ip, PORT));
|
socket.connect(new InetSocketAddress(ip, PORT));
|
||||||
DatagramPacket packet = new DatagramPacket(content, content.length);
|
DatagramPacket packet = new DatagramPacket(content, content.length);
|
||||||
|
|
||||||
int failCount = 0;
|
|
||||||
SarErrorDTO info = null;
|
SarErrorDTO info = null;
|
||||||
|
int failCount = 0;
|
||||||
while (info == null && failCount < RETRY_MAX) { // 失败重试
|
while (info == null && failCount < RETRY_MAX) { // 失败重试
|
||||||
|
log.info("发送雷达控制指令 [{}] -> {} (第{}次)", controlType, ip, failCount + 1);
|
||||||
socket.send(packet);
|
socket.send(packet);
|
||||||
// 每0.1秒取回执,1秒后超时
|
info = waitForReply(ip);
|
||||||
long startTime = System.currentTimeMillis();
|
if (info == null) {
|
||||||
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) { // 超时未收到回执
|
|
||||||
failCount++;
|
failCount++;
|
||||||
|
log.warn("雷达 [{}] 未返回回执,第{}次重试", ip, failCount);
|
||||||
} else if (info.getExecStatus() == 1) {
|
} else if (info.getExecStatus() == 1) {
|
||||||
// 只有发送的数据结构错误时才会返回错误状态,并不会因为业务不允许返回错误
|
// 只有发送的数据结构错误时才会返回错误状态,并不会因为业务不允许返回错误
|
||||||
throw new ServiceException("控制指令[" + controlType + "]执行状态错误,请重试");
|
throw new ServiceException("控制指令[" + controlType + "]执行状态错误,请重试");
|
||||||
@ -146,9 +133,8 @@ public class SarControlContext {
|
|||||||
}
|
}
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
throw new SarConnectException("控制指令[" + controlType + "]发送失败,雷达[" + ip + "]无应答,请重试");
|
throw new SarConnectException("控制指令[" + controlType + "]发送失败,雷达[" + ip + "]无应答,请重试");
|
||||||
} else {
|
|
||||||
log.info("雷达控制指令[" + controlType + "]发送完毕----------------------");
|
|
||||||
}
|
}
|
||||||
|
log.info("雷达控制指令 [{}] 发送成功 -> {}", controlType, ip);
|
||||||
} catch (RedisConnectionFailureException ex) {
|
} catch (RedisConnectionFailureException ex) {
|
||||||
throw ServiceException.errorLog("无法连接到Redis服务!");
|
throw ServiceException.errorLog("无法连接到Redis服务!");
|
||||||
} catch (IOException ex) {
|
} 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
|
* @param sarControl
|
||||||
|
|||||||
@ -75,11 +75,10 @@ public class SarStatusListener extends SarAbstractListener {
|
|||||||
if (packet.getLength() != 100) {
|
if (packet.getLength() != 100) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.debug("接收到状态包----------------------");
|
|
||||||
String ip = packet.getAddress().getHostAddress();
|
String ip = packet.getAddress().getHostAddress();
|
||||||
// 处理接收到的数据
|
// 处理接收到的数据
|
||||||
SarStatusPackDTO packDTO = SarStatusPackDTO.parse(ip, packet.getData());
|
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 (packDTO == null) {
|
||||||
if (running)
|
if (running)
|
||||||
log.warn("[" + packDTO.getPayloadIp() + "]状态包校验失败,已丢弃。错误包=" +
|
log.warn("[" + packDTO.getPayloadIp() + "]状态包校验失败,已丢弃。错误包=" +
|
||||||
@ -91,7 +90,6 @@ public class SarStatusListener extends SarAbstractListener {
|
|||||||
if (errorStatus == 1) {
|
if (errorStatus == 1) {
|
||||||
SarErrorDTO info = packDTO.getDeviceErrorInfo();
|
SarErrorDTO info = packDTO.getDeviceErrorInfo();
|
||||||
if (info.getErrorPacketType() == SarErrorTypeEnum.RESULT) {
|
if (info.getErrorPacketType() == SarErrorTypeEnum.RESULT) {
|
||||||
log.debug("收到回执包:" + ip);
|
|
||||||
redisUtil.set(CacheKey.getSarControlBack(ip), info, answerTimeout, TimeUnit.SECONDS);
|
redisUtil.set(CacheKey.getSarControlBack(ip), info, answerTimeout, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,11 +97,8 @@ public class SarStatusListener extends SarAbstractListener {
|
|||||||
int deviceStatus = packDTO.getDevicePacketStatus();
|
int deviceStatus = packDTO.getDevicePacketStatus();
|
||||||
if (deviceStatus == 1) {
|
if (deviceStatus == 1) {
|
||||||
JmSarStatusDTO info = packDTO.getDeviceStatusInfo();
|
JmSarStatusDTO info = packDTO.getDeviceStatusInfo();
|
||||||
log.debug("sar开机状态:" + info.getIsBoot());
|
|
||||||
sarJobStatusService.update(ip, info);
|
sarJobStatusService.update(ip, info);
|
||||||
redisUtil.set(CacheKey.getSarConnect(ip), info, answerTimeout, TimeUnit.SECONDS);
|
redisUtil.set(CacheKey.getSarConnect(ip), info, answerTimeout, TimeUnit.SECONDS);
|
||||||
//System.out.println(info);
|
}
|
||||||
}
|
|
||||||
log.debug("----------------------状态包解析完毕");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,11 +1,11 @@
|
|||||||
package com.zhangy.skyeye.sar.service.impl;
|
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.exception.ServiceException;
|
||||||
import com.zhangy.skyeye.common.extend.util.JsonUtil;
|
import com.zhangy.skyeye.common.extend.util.JsonUtil;
|
||||||
import com.zhangy.skyeye.jm.dto.JmJobDTO;
|
import com.zhangy.skyeye.jm.dto.JmJobDTO;
|
||||||
import com.zhangy.skyeye.jm.dto.JmSarStatusDTO;
|
import com.zhangy.skyeye.jm.dto.JmSarStatusDTO;
|
||||||
import com.zhangy.skyeye.jm.entity.JmJobPayload;
|
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.publics.consts.CacheKey;
|
||||||
import com.zhangy.skyeye.redis.utils.RedisUtil;
|
import com.zhangy.skyeye.redis.utils.RedisUtil;
|
||||||
import com.zhangy.skyeye.sar.control.SarControlContext;
|
import com.zhangy.skyeye.sar.control.SarControlContext;
|
||||||
@ -36,6 +36,7 @@ public class SarControlServiceImpl implements ISarControlService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendUdp(JmJobDTO job) {
|
public void sendUdp(JmJobDTO job) {
|
||||||
|
log.info("sendUdp:{}", JSON.toJSONString(job));
|
||||||
if (job == null || job.getUavList() == null) return;
|
if (job == null || job.getUavList() == null) return;
|
||||||
job.getUavList().forEach(uav -> {
|
job.getUavList().forEach(uav -> {
|
||||||
JmJobPayload sar = uav.getSar0();
|
JmJobPayload sar = uav.getSar0();
|
||||||
@ -48,7 +49,7 @@ public class SarControlServiceImpl implements ISarControlService {
|
|||||||
param.setImageBit(sar.getImageBit());
|
param.setImageBit(sar.getImageBit());
|
||||||
param.setResolution(sar.getResolution());
|
param.setResolution(sar.getResolution());
|
||||||
if (job.getMode().equals(CRUISE.getCode())) {
|
if (job.getMode().equals(CRUISE.getCode())) {
|
||||||
param.setControlType(SarControlTypeEnum.TURNON);
|
param.setControlType(SarControlTypeEnum.UPLOAD);
|
||||||
} else {
|
} else {
|
||||||
param.setControlType(SarControlTypeEnum.AUTO);
|
param.setControlType(SarControlTypeEnum.AUTO);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user