merge-requests/3/head
qiushui 4 years ago
parent 62614e21d3
commit e1ec51ee08

@ -94,7 +94,7 @@
<repository> <repository>
<id>nexus</id> <id>nexus</id>
<name>Nexus</name> <name>Nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url> <url>http://47.99.98.250:28888/repository/maven-public/</url>
<snapshots> <snapshots>
<enabled>false</enabled> <enabled>false</enabled>
</snapshots> </snapshots>

@ -28,6 +28,7 @@ public class CacheConfig {
caches.add(new ConcurrentMapCache("street")); caches.add(new ConcurrentMapCache("street"));
caches.add(new ConcurrentMapCache("ptz")); caches.add(new ConcurrentMapCache("ptz"));
caches.add(new ConcurrentMapCache("streetByPlcId")); caches.add(new ConcurrentMapCache("streetByPlcId"));
caches.add(new ConcurrentMapCache("streetByPlc"));
caches.add(new ConcurrentMapCache("getStreetCount")); caches.add(new ConcurrentMapCache("getStreetCount"));
simpleCacheManager.setCaches(caches); simpleCacheManager.setCaches(caches);
//把各个cache注册到cacheManager中GuavaCache实现了org.springframework.cache.Cache接口 //把各个cache注册到cacheManager中GuavaCache实现了org.springframework.cache.Cache接口

@ -2,9 +2,11 @@ package com.zhehekeji.web.controller;
import com.zhehekeji.core.pojo.Result; import com.zhehekeji.core.pojo.Result;
import com.zhehekeji.core.util.Assert; import com.zhehekeji.core.util.Assert;
import com.zhehekeji.web.config.ConfigProperties;
import com.zhehekeji.web.entity.Street; import com.zhehekeji.web.entity.Street;
import com.zhehekeji.web.mapper.StreetMapper; import com.zhehekeji.web.mapper.StreetMapper;
import com.zhehekeji.web.service.*; import com.zhehekeji.web.service.*;
import com.zhehekeji.web.service.ksec.KsecNettyClient;
import com.zhehekeji.web.service.robotic.NettyClient; import com.zhehekeji.web.service.robotic.NettyClient;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -25,21 +27,35 @@ public class PLCController {
private StreetMapper streetMapper; private StreetMapper streetMapper;
@Resource @Resource
private NettyClient nettyClient; private NettyClient nettyClient;
@Resource
private ConfigProperties configProperties;
@Resource
private KsecNettyClient ksecNettyClient;
@GetMapping("/tcp") @GetMapping("/tcp")
@ApiOperation(value = "连接plc,发起请求") @ApiOperation(value = "连接plc,发起请求")
public Result heart(@RequestParam Integer id){ public Result tcp(@RequestParam Integer id){
Street street = streetMapper.selectById(id); if(configProperties.getServerMode() == 1){
Assert.isTrue(street!= null && street.getPlcIp() != null && street.getPlcPort() != null,"未配置IP");
//先判断该链接是否正常
if(!StreetConn.checkStreetConn(id)){
try { try {
nettyClient.createClient(street); ksecNettyClient.createClient(configProperties.getKsec());
}catch (Exception e){ }catch (Exception e){
Assert.isTrue(false,"连接失败ip"+street.getPlcIp()+",port:"+street.getPlcPort()); Assert.isTrue(false,"连接失败ip"+configProperties.getKsec().getIp()+",port:"+configProperties.getKsec().getPort());
}
}else {
Street street = streetMapper.selectById(id);
Assert.isTrue(street!= null && street.getPlcIp() != null && street.getPlcPort() != null,"未配置IP");
//先判断该链接是否正常
if(!StreetConn.checkStreetConn(id)){
try {
nettyClient.createClient(street);
}catch (Exception e){
Assert.isTrue(false,"连接失败ip"+street.getPlcIp()+",port:"+street.getPlcPort());
}
} }
} }
return Result.success(); return Result.success();
} }
@Resource @Resource

@ -20,18 +20,18 @@ public class CallBack {
} }
} }
// /** /**
// * mp4下载回调 * mp4
// */ */
// public static class Mp4ReceiveCB implements NetSDKLib.fTimeDownLoadPosCallBack { public static class Mp4ReceiveCB implements NetSDKLib.fTimeDownLoadPosCallBack {
//
// @Override @Override
// public void invoke(NetSDKLib.LLong lPlayHandle, int dwTotalSize, int dwDownLoadSize, int index, NetSDKLib.NET_RECORDFILE_INFO.ByValue recordfileinfo, Pointer dwUser) { public void invoke(NetSDKLib.LLong lPlayHandle, int dwTotalSize, int dwDownLoadSize, int index, NetSDKLib.NET_RECORDFILE_INFO.ByValue recordfileinfo, Pointer dwUser) {
// if(dwDownLoadSize == -1) { if(dwDownLoadSize == -1) {
// JoywareLoginModuleImpl.netsdk.CLIENT_StopDownload(lPlayHandle); JoywareLoginModuleImpl.netsdk.CLIENT_StopDownload(lPlayHandle);
// } }
// } }
// } }
public static class HaveReConnect implements NetSDKLib.fHaveReConnect { public static class HaveReConnect implements NetSDKLib.fHaveReConnect {
@Override @Override

@ -243,8 +243,7 @@ public class JoywareCameraControlModuleImpl implements CameraControlModule {
} }
public void downloadMp4(Integer cameraId, String path, LocalDateTime start, LocalDateTime end) { public void downloadMp4(Integer cameraId, String path, LocalDateTime start, LocalDateTime end) {
//视频结束时间加上5s
end = end.plusSeconds(5);
PathUtil.checkDirc(path); PathUtil.checkDirc(path);
NetSDKLib.NET_TIME startTime = new NetSDKLib.NET_TIME(); NetSDKLib.NET_TIME startTime = new NetSDKLib.NET_TIME();
startTime.setTime(start.getYear(), start.getMonthValue(), start.getDayOfMonth(), start.getHour(), start.getMinute(), start.getSecond()); startTime.setTime(start.getYear(), start.getMonthValue(), start.getDayOfMonth(), start.getHour(), start.getMinute(), start.getSecond());
@ -260,8 +259,8 @@ public class JoywareCameraControlModuleImpl implements CameraControlModule {
download_by_data_type.write(); download_by_data_type.write();
NetSDKLib.NET_OUT_DOWNLOAD_BY_DATA_TYPE net_out_download_by_data_type = new NetSDKLib.NET_OUT_DOWNLOAD_BY_DATA_TYPE(); NetSDKLib.NET_OUT_DOWNLOAD_BY_DATA_TYPE net_out_download_by_data_type = new NetSDKLib.NET_OUT_DOWNLOAD_BY_DATA_TYPE();
net_out_download_by_data_type.write(); net_out_download_by_data_type.write();
log.info("start download mp4 path:{},startTime:{} ,endTime:{},now:{}", path, startTime.toString(), endTime.toString(), LocalDateTime.now());
NetSDKLib.LLong l = JoywareLoginModuleImpl.netsdk.CLIENT_DownloadByDataType(CameraConnMap.getConnId(cameraId), download_by_data_type.getPointer(), net_out_download_by_data_type.getPointer(), 8000); NetSDKLib.LLong l = JoywareLoginModuleImpl.netsdk.CLIENT_DownloadByDataType(CameraConnMap.getConnId(cameraId), download_by_data_type.getPointer(), net_out_download_by_data_type.getPointer(), 8000);
log.info("start download mp4 path:{},startTime:{} ,endTime:{},now:{}status:{}", path, startTime.toString(), endTime.toString(), LocalDateTime.now(),l.longValue());
if (l.longValue() == 0) { if (l.longValue() == 0) {
log.error("download mp4 error :{},cameraId:{}", ToolKits.getErrorCodePrint(),cameraId); log.error("download mp4 error :{},cameraId:{}", ToolKits.getErrorCodePrint(),cameraId);
} }

@ -124,12 +124,18 @@ public class PlcService {
update.setLeftRight2(plcCmdInfo.getLeftRight2()); update.setLeftRight2(plcCmdInfo.getLeftRight2());
update.setColumn2(plcCmdInfo.getColumn2()); update.setColumn2(plcCmdInfo.getColumn2());
update.setRow2(plcCmdInfo.getRow2()); update.setRow2(plcCmdInfo.getRow2());
//todo 延迟队列
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (street.getCamera1Id() != null) { if (street.getCamera1Id() != null) {
String path = cameraVideo(street.getCamera1Id(),order.getStartTime(),endTime); String path = cameraVideo(street.getCamera1Id(),order.getStartTime(),endTime.plusSeconds(2));
update.setVideoPath1(path); update.setVideoPath1(path);
} }
if (street.getCamera2Id() != null) { if (street.getCamera2Id() != null) {
String path = cameraVideo(street.getCamera2Id(),order.getStartTime(),endTime); String path = cameraVideo(street.getCamera2Id(),order.getStartTime(),endTime.plusSeconds(2));
update.setVideoPath2(path); update.setVideoPath2(path);
} }
orderMapper.updateById(update); orderMapper.updateById(update);
@ -189,11 +195,25 @@ public class PlcService {
if (orderInfo.getLeftRight() == 1) { if (orderInfo.getLeftRight() == 1) {
gyrateCameraByCode(street.getCamera1Id(), code); gyrateCameraByCode(street.getCamera1Id(), code);
if (needCapture) { if (needCapture) {
if(code.startsWith("C1") || code.startsWith("C3")){
try {
Thread.sleep(1200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
path = cameraCapture(street.getCamera1Id()); path = cameraCapture(street.getCamera1Id());
} }
} else { } else {
gyrateCameraByCode(street.getCamera2Id(), code); gyrateCameraByCode(street.getCamera2Id(), code);
if (needCapture) { if (needCapture) {
if(code.startsWith("C1") || code.startsWith("C3")){
try {
Thread.sleep(1200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
path = cameraCapture(street.getCamera2Id()); path = cameraCapture(street.getCamera2Id());
} }
} }
@ -210,6 +230,25 @@ public class PlcService {
if (path != null && needCapture) { if (path != null && needCapture) {
captureUpdateOrderAndStock(orderInfo, path); captureUpdateOrderAndStock(orderInfo, path);
} }
if(times == 2){
if(street.getCamera2Id() != null){
gyrateCameraByCode(street.getCamera2Id(),"C5");
}
if(street.getCamera1Id() != null){
gyrateCameraByCode(street.getCamera1Id(),"C5");
}
}
}
public void gyrateCamera(PlcCmdInfo plcCmdInfo,String code){
Street street = streetService.getStreetByPlcId(plcCmdInfo.getPlcId());
if(street.getCamera1Id() != null){
gyrateCameraByCode(street.getCamera1Id(),code);
}
if(street.getCamera2Id() != null){
gyrateCameraByCode(street.getCamera2Id(),code);
}
} }
public void warnAction(PlcCmdInfo plcCmdInfo,String warnCode){ public void warnAction(PlcCmdInfo plcCmdInfo,String warnCode){
@ -338,7 +377,7 @@ public class PlcService {
warn.setVideoPath1(path); warn.setVideoPath1(path);
} }
if (street.getCamera2Id() != null) { if (street.getCamera2Id() != null) {
String path = cameraVideo(street.getCamera1Id(),warn.getStartTime(),LocalDateTime.now()); String path = cameraVideo(street.getCamera2Id(),warn.getStartTime(),LocalDateTime.now());
warn.setVideoPath2(path); warn.setVideoPath2(path);
} }
warnMapper.updateById(warn); warnMapper.updateById(warn);
@ -432,7 +471,6 @@ public class PlcService {
* *
* *
* @param plcCmdInfo * @param plcCmdInfo
* @param plcId
* @param barCodeSys * @param barCodeSys
* @param boxNumSys * @param boxNumSys
* @param boxNumAlgo * @param boxNumAlgo

@ -70,7 +70,7 @@ public class StreetService {
return street; return street;
} }
@Cacheable(value = "streetByPlc",key = "#plcId") @Cacheable(value = "streetByPlcId",key = "#plcId")
public Street getStreetByPlcId(String plcId) { public Street getStreetByPlcId(String plcId) {
Street street = streetMapper.getStreetByPlcId(plcId); Street street = streetMapper.getStreetByPlcId(plcId);
if (street == null) { if (street == null) {

@ -10,6 +10,7 @@ import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -31,13 +32,15 @@ public class KsecDecoder extends DelimiterBasedFrameDecoder {
@Override @Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
in = (ByteBuf) super.decode(ctx, in); in = (ByteBuf) super.decode(ctx, in);
if(in == null){
log.info("no data");
return null;
}
String body = in.toString(Charset.forName("UTF-8")); String body = in.toString(Charset.forName("UTF-8"));
if (body.startsWith("<")){ if (body.startsWith("<")){
// 去掉首尾标识符 // 去掉首尾标识符
body = body.substring(1, body.length()); body = body.substring(1, body.length());
KsecInfo ksecInfo = JSONObject.parseObject(body, KsecInfo.class); KsecInfo ksecInfo = JSONObject.parseObject(body, KsecInfo.class);
tcpLogger.info("info:{}",body);
log.info("receieve info:{}", ksecInfo);
KsecDataInfo dataInfo = ksecInfo.getData(); KsecDataInfo dataInfo = ksecInfo.getData();
PlcCmdInfo plcCmdInfo = null; PlcCmdInfo plcCmdInfo = null;
String srmNumber = null; String srmNumber = null;
@ -50,14 +53,19 @@ public class KsecDecoder extends DelimiterBasedFrameDecoder {
if ("A".equals(ksecInfo.getType())) { if ("A".equals(ksecInfo.getType())) {
//心跳 //心跳
log.debug("receieve heart ");
} else if ("B".equals(ksecInfo.getType())) { } else if ("B".equals(ksecInfo.getType())) {
tcpLogger.info("info:{}",body);
//任务 //任务
if ("B1".equals(cmdName)) { if ("B1".equals(cmdName)) {
plcService.gyrateCamera(plcCmdInfo,"C5");
plcService.orderStart(plcCmdInfo); plcService.orderStart(plcCmdInfo);
} else if ("B2".equals(cmdName)) { } else if ("B2".equals(cmdName)) {
plcService.gyrateCamera(plcCmdInfo,"C5");
plcService.orderStop(plcCmdInfo); plcService.orderStop(plcCmdInfo);
} }
} else if ("C".equals(ksecInfo.getType())) { } else if ("C".equals(ksecInfo.getType())) {
tcpLogger.info("info:{}",body);
//动作 //动作
String code = dataInfo.getCmdName(); String code = dataInfo.getCmdName();
log.info("action code,{},orderInfo:{}", code, plcCmdInfo.toString()); log.info("action code,{},orderInfo:{}", code, plcCmdInfo.toString());
@ -71,11 +79,16 @@ public class KsecDecoder extends DelimiterBasedFrameDecoder {
log.info("other C code :{}",code); log.info("other C code :{}",code);
} }
} else if ("D".equals(ksecInfo.getType())) { } else if ("D".equals(ksecInfo.getType())) {
tcpLogger.info("info:{}",body);
String code = dataInfo.getCmdName(); String code = dataInfo.getCmdName();
if(code.equals("D1")){ if(code.equals("D1")){
log.info("plcId:{},warn start",plcCmdInfo.getPlcId()); log.info("plcId:{},warn start",plcCmdInfo.getPlcId());
//根据告警code转动camera //根据告警code转动camera
plcService.warnAction(plcCmdInfo,dataInfo.getWarnCode()); String warnCode = dataInfo.getWarnCode();
if(!StringUtils.isEmpty(warnCode)){
String warnCode0 = "D1-"+warnCode.split(",")[0];
plcService.warnAction(plcCmdInfo,warnCode0);
}
plcService.warnStart(plcCmdInfo.getPlcId(),dataInfo.getWarnCode()); plcService.warnStart(plcCmdInfo.getPlcId(),dataInfo.getWarnCode());
}else if(code.equals("D2")){ }else if(code.equals("D2")){
log.info("plcId:{},warn stop",plcCmdInfo.getPlcId()); log.info("plcId:{},warn stop",plcCmdInfo.getPlcId());
@ -84,6 +97,7 @@ public class KsecDecoder extends DelimiterBasedFrameDecoder {
log.info("other D code :{}",code); log.info("other D code :{}",code);
} }
} else if ("E".equals(ksecInfo.getType())) { } else if ("E".equals(ksecInfo.getType())) {
tcpLogger.info("info:{}",body);
//盘点 //盘点
//找到该货位的最后一张照片与现在的照片比照 //找到该货位的最后一张照片与现在的照片比照
plcService.recordStock(plcCmdInfo, dataInfo.getCode(), 0, 0); plcService.recordStock(plcCmdInfo, dataInfo.getCode(), 0, 0);

@ -27,11 +27,11 @@ public class KsecNettyClient {
/** /**
* *
*/ */
private static int RECONNECT_NUM = 5; private static int RECONNECT_NUM = Integer.MAX_VALUE;
private static Channel channel; private static Channel channel;
public void createClient(ConfigProperties.KSEC ksec){ public void createClient(ConfigProperties.KSEC ksec) throws InterruptedException {
if (StringUtils.isEmpty(ksec.getIp()) || ksec.getPort() == null) { if (StringUtils.isEmpty(ksec.getIp()) || ksec.getPort() == null) {
return; return;
} }
@ -41,13 +41,7 @@ public class KsecNettyClient {
KsecInfo heart = KsecInfo.heart(); KsecInfo heart = KsecInfo.heart();
client.handler(new KescFilter(heart, plcService,this)); client.handler(new KescFilter(heart, plcService,this));
// 连接服务端 // 连接服务端
try { channel = client.connect(ksec.getIp(), ksec.getPort()).sync().channel();
channel = client.connect(ksec.getIp(), ksec.getPort()).sync().channel();
} catch (InterruptedException e) {
channel = null;
e.printStackTrace();
throw new RuntimeException("");
}
} }
/** /**
@ -63,6 +57,11 @@ public class KsecNettyClient {
log.error("reconnect ,upPc is null ,id:{}", upId); log.error("reconnect ,upPc is null ,id:{}", upId);
return; return;
} }
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
while (num < RECONNECT_NUM && !isConnected) { while (num < RECONNECT_NUM && !isConnected) {
try { try {
createClient(ksec); createClient(ksec);

@ -41,8 +41,9 @@ savePath:
# ------------服务端类型 0TCP(罗伯泰克) 1:KSEC(JSON)(昆船) # ------------服务端类型 0TCP(罗伯泰克) 1:KSEC(JSON)(昆船)
serverMode: 1 serverMode: 1
ksec: ksec:
ip: 127.0.0.1 ip: 192.168.43.46
port: 3000 #ip: 192.168.43.77
port: 9000
# ------------ 实时视频流 全部页面的格式 行列数量 # ------------ 实时视频流 全部页面的格式 行列数量
videoStyleConfig: videoStyleConfig:
videoStyleRow: 1 videoStyleRow: 1

Loading…
Cancel
Save