|
@@ -1,13 +1,27 @@
|
|
|
package com.its.dsrc.xnettcp.center.handler;
|
|
|
|
|
|
+import com.beanit.asn1dsrc.enums.eControlCommand;
|
|
|
+import com.beanit.asn1dsrc.enums.eControlDeviceId;
|
|
|
+import com.its.app.AppUtils;
|
|
|
import com.its.app.utils.NettyUtils;
|
|
|
+import com.its.dsrc.dao.mapper.RseCtlrMapper;
|
|
|
+import com.its.dsrc.entity.TbRseCtlr;
|
|
|
+import com.its.dsrc.entity.TbRseCtrlHs;
|
|
|
+import com.its.dsrc.global.AppRepository;
|
|
|
+import com.its.dsrc.vo.NET;
|
|
|
+import com.its.dsrc.xnettcp.center.protocol.CenterProtocol;
|
|
|
import com.its.dsrc.xnettcp.center.protocol.CenterReqFramePacket;
|
|
|
+import com.its.dsrc.xnettcp.center.protocol.CenterResProtocol;
|
|
|
+import com.its.dsrc.xnettcp.dsrc.process.service.ControlDeviceService;
|
|
|
+import io.netty.channel.ChannelFuture;
|
|
|
import io.netty.channel.ChannelHandler;
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.nio.ByteBuffer;
|
|
|
+
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
@ChannelHandler.Sharable
|
|
@@ -15,87 +29,101 @@ public class CenterTcpServerInboundHandler extends ChannelInboundHandlerAdapter
|
|
|
|
|
|
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
|
|
|
|
|
+ RseCtlrMapper mapper = (RseCtlrMapper) AppUtils.getBean(RseCtlrMapper.class);
|
|
|
String ipAddress = NettyUtils.getRemoteIpAddress(ctx.channel());
|
|
|
if (!(msg instanceof CenterReqFramePacket)) {
|
|
|
log.error("[{}] | Received Data is not CenterReqFramePacket Object", NettyUtils.getRemoteIpAddress(ctx.channel()));
|
|
|
return;
|
|
|
}
|
|
|
-// CenterReqFramePacket centerReqHead = (CenterReqFramePacket)msg;
|
|
|
-// VdsReqFrameHead vdsReqHead = new VdsReqFrameHead(centerReqHead.getBody());
|
|
|
-// short groupNo = vdsReqHead.getGroupNo();
|
|
|
-// short ctlrNo = vdsReqHead.getControllerNo();
|
|
|
-// byte opCode = vdsReqHead.getOpCode();
|
|
|
-//
|
|
|
-// TbVdsCtlr obj = null;
|
|
|
-// for (Map.Entry<String, TbVdsCtlr> e : AppRepository.getInstance().getCtlrMap().entrySet()) {
|
|
|
-// TbVdsCtlr tmp = e.getValue();
|
|
|
-// if (tmp.getVDS_CTLR_LOCAL_NO() == ctlrNo) {
|
|
|
-// obj = tmp;
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if (obj == null) {
|
|
|
-// log.error("CenterTcpServerInboundHandler: Center Request Unknown VDS: [{}]", ctlrNo);
|
|
|
-// ByteBuffer sendBuffer = CenterResProtocol.getResponse(opCode, (byte)(0xFF));
|
|
|
-// ChannelFuture f = ctx.channel().writeAndFlush(sendBuffer);
|
|
|
-// f.awaitUninterruptibly();
|
|
|
-// if (f.isDone() || f.isSuccess()) {
|
|
|
-// log.info("CenterTcpServerInboundHandler: Response OK. Center Request Unknown VDS: [{}]", ctlrNo);
|
|
|
-// } else {
|
|
|
-// log.error("CenterTcpServerInboundHandler: Response Failed. Center Request Unknown VDS: [{}]", ctlrNo);
|
|
|
-// }
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// if (obj.getChannel() == null || obj.getNetState() == NET.CLOSED) {
|
|
|
-// log.error("CenterTcpServerInboundHandler: Center Request VDS Not Connect: [{}]", obj);
|
|
|
-// ByteBuffer sendBuffer = CenterResProtocol.getResponse(opCode, (byte)(0xFE));
|
|
|
-// ChannelFuture f = ctx.channel().writeAndFlush(sendBuffer);
|
|
|
-// f.awaitUninterruptibly();
|
|
|
-// if (f.isDone() || f.isSuccess()) {
|
|
|
-// log.info("CenterTcpServerInboundHandler: Response OK. Center Not Connect VDS: [{}]", ctlrNo);
|
|
|
-// } else {
|
|
|
-// log.error("CenterTcpServerInboundHandler: Response Failed. Center Not Connect VDS: [{}]", ctlrNo);
|
|
|
-// }
|
|
|
-// return;
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (opCode == VdsProtocol.vds_Reset) {
|
|
|
-// ByteBuffer resultBuffer;
|
|
|
-// VdsReqReset reqReset = new VdsReqReset((short)obj.getGROUP_NO(), (short)obj.getVDS_CTLR_LOCAL_NO());
|
|
|
-// reqReset.makeCRC();
|
|
|
-// ByteBuffer sendBuffer = reqReset.getByteBuffer();
|
|
|
-// if (!obj.sendData(sendBuffer, 0, "vds_Reset")) {
|
|
|
-// log.error("CenterTcpServerInboundHandler: Center Request VDS Reset Data Send Failed: [{}]", obj);
|
|
|
-// resultBuffer = CenterResProtocol.getResponse(opCode, (byte)(0xFD));
|
|
|
-// } else {
|
|
|
-// resultBuffer = CenterResProtocol.getResponse(opCode, (byte)(0x00));
|
|
|
-// }
|
|
|
-// ChannelFuture f = ctx.channel().writeAndFlush(resultBuffer);
|
|
|
-// f.awaitUninterruptibly();
|
|
|
-// if (f.isDone() || f.isSuccess()) {
|
|
|
-// log.info("CenterTcpServerInboundHandler: Response OK. VDS Reset: [{}]", ctlrNo);
|
|
|
-// } else {
|
|
|
-// log.error("CenterTcpServerInboundHandler: Response Failed. VDS Reset: [{}]", ctlrNo);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// else if (opCode == VdsProtocol.vds_Image) {
|
|
|
-// int frameNo = 0; // first image request
|
|
|
-// byte cameraNo = (centerReqHead.getBody()[9] == (byte)0x00) ? (byte)0x01 : centerReqHead.getBody()[9];
|
|
|
-// obj.setStopImageRequest(ctx.channel(), cameraNo, frameNo);
|
|
|
-// VdsReqImage reqImage = new VdsReqImage((short)obj.getGROUP_NO(), (short)obj.getVDS_CTLR_LOCAL_NO());
|
|
|
-// reqImage.setCameraNo(cameraNo);
|
|
|
-// reqImage.setFrameNo(frameNo);
|
|
|
-// reqImage.makeCRC();
|
|
|
-// ByteBuffer sendBuffer = reqImage.getByteBuffer();
|
|
|
-// if (!obj.sendData(sendBuffer, 0, "vds_Image")) {
|
|
|
-// obj.setStopImageResponse();
|
|
|
-// log.error("CenterTcpServerInboundHandler: Center Request VDS Image Data Send Failed: [{}]", obj);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// else {
|
|
|
-// log.error("CenterTcpServerInboundHandler: Center Request Not Support: [{}]", opCode);
|
|
|
-// return;
|
|
|
-// }
|
|
|
+ CenterReqFramePacket centerReqHead = (CenterReqFramePacket)msg;
|
|
|
+ byte opCode = centerReqHead.getHead().getOpCode();
|
|
|
+ byte[] body = centerReqHead.getBody();
|
|
|
+ if (body == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ByteBuffer msgBuffer = ByteBuffer.wrap(body);
|
|
|
+ msgBuffer.order(CenterProtocol.byteOrder);
|
|
|
+ if (opCode == CenterProtocol.INT_OP_DSRC_CONTROL_REQ) {
|
|
|
+ long ctlrNmbr = msgBuffer.getLong();
|
|
|
+ long ctrlSeq = msgBuffer.getLong();
|
|
|
+ int devcType = msgBuffer.getInt();
|
|
|
+ int cntlType = msgBuffer.getInt();
|
|
|
+
|
|
|
+ TbRseCtrlHs cntl = new TbRseCtrlHs();
|
|
|
+ cntl.setCtrlSeq(ctrlSeq);
|
|
|
+ cntl.setDevcType(String.valueOf(devcType));
|
|
|
+ cntl.setCntlType(String.valueOf(cntlType));
|
|
|
+ cntl.setRspsType("0");
|
|
|
+
|
|
|
+ TbRseCtlr obj = AppRepository.getInstance().getCtlrMap().get(String.valueOf(ctlrNmbr));
|
|
|
+ if (obj == null) {
|
|
|
+ log.error("CenterTcpServerInboundHandler: Center Request Unknown RSE: [{}]", ctlrNmbr);
|
|
|
+ cntl.setRspsType("9"); // 알수없는제어기
|
|
|
+ ByteBuffer sendBuffer = CenterResProtocol.getResponse(opCode, (byte)(0xFF));
|
|
|
+ ChannelFuture f = ctx.channel().writeAndFlush(sendBuffer);
|
|
|
+ f.awaitUninterruptibly();
|
|
|
+ if (f.isDone() || f.isSuccess()) {
|
|
|
+ log.info("CenterTcpServerInboundHandler: Response OK. Center Request Unknown VDS: [{}]", ctlrNmbr);
|
|
|
+ } else {
|
|
|
+ log.error("CenterTcpServerInboundHandler: Response Failed. Center Request Unknown VDS: [{}]", ctlrNmbr);
|
|
|
+ }
|
|
|
+ mapper.updateRseCtrlHs(cntl);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (obj.getChannel() == null || obj.getNetState() == NET.CLOSED) {
|
|
|
+ log.error("CenterTcpServerInboundHandler: Center Request VDS Not Connect: [{}]", obj);
|
|
|
+ ByteBuffer sendBuffer = CenterResProtocol.getResponse(opCode, (byte)(0xFE));
|
|
|
+ cntl.setRspsType("8"); // 통신불량
|
|
|
+ ChannelFuture f = ctx.channel().writeAndFlush(sendBuffer);
|
|
|
+ f.awaitUninterruptibly();
|
|
|
+ if (f.isDone() || f.isSuccess()) {
|
|
|
+ log.info("CenterTcpServerInboundHandler: Response OK. Center Not Connect VDS: [{}]", ctlrNmbr);
|
|
|
+ } else {
|
|
|
+ log.error("CenterTcpServerInboundHandler: Response Failed. Center Not Connect VDS: [{}]", ctlrNmbr);
|
|
|
+ }
|
|
|
+ mapper.updateRseCtrlHs(cntl);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 제어요청 패킷을 만든다
|
|
|
+ eControlDeviceId controlDeviceId = eControlDeviceId.getByValue(devcType);
|
|
|
+ eControlCommand commandType = eControlCommand.getByValue(cntlType);
|
|
|
+ if (controlDeviceId == null || commandType == null) {
|
|
|
+ log.error("RSE REQ RESET CONTROL Value Error: [{}] [{},{}]", ctlrNmbr, devcType, cntlType);
|
|
|
+ ByteBuffer sendBuffer = CenterResProtocol.getResponse(opCode, (byte)(0xFD));
|
|
|
+ cntl.setRspsType("7"); // 통신불량
|
|
|
+ ChannelFuture f = ctx.channel().writeAndFlush(sendBuffer);
|
|
|
+ f.awaitUninterruptibly();
|
|
|
+ if (f.isDone() || f.isSuccess()) {
|
|
|
+ log.info("CenterTcpServerInboundHandler: Response OK. Center Not Connect VDS: [{}]", ctlrNmbr);
|
|
|
+ } else {
|
|
|
+ log.error("CenterTcpServerInboundHandler: Response Failed. Center Not Connect VDS: [{}]", ctlrNmbr);
|
|
|
+ }
|
|
|
+ mapper.updateRseCtrlHs(cntl);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ log.warn("[{}] [{},{}], controlDeviceId: {}, commandType: {}", ctlrNmbr, devcType, cntlType, controlDeviceId.toString(), commandType.toString());
|
|
|
+ boolean res = ControlDeviceService.getInstance().requestSubscriptionDeviceCommand(true, obj, obj.getChannel(), controlDeviceId.getValue(), commandType.getValue(), cntl);
|
|
|
+ if (res) {
|
|
|
+ log.info("RSE REQ CONTROL SEND OK: [{}] [{},{}]", ctlrNmbr, devcType, cntlType);
|
|
|
+ cntl.setRspsType("0"); // 성공, 리셋응답없을수 있으므로 먼저 성공으로 입력한다.
|
|
|
+ } else {
|
|
|
+ log.error("RSE REQ CONTROL SEND Error: [{}] [{},{}]", ctlrNmbr, devcType, cntlType);
|
|
|
+ ByteBuffer sendBuffer = CenterResProtocol.getResponse(opCode, (byte)(0xFC));
|
|
|
+ cntl.setRspsType("6"); // 데이터전송실패
|
|
|
+ ChannelFuture f = ctx.channel().writeAndFlush(sendBuffer);
|
|
|
+ f.awaitUninterruptibly();
|
|
|
+ if (f.isDone() || f.isSuccess()) {
|
|
|
+ log.info("CenterTcpServerInboundHandler: Response OK. Center Not Connect VDS: [{}]", ctlrNmbr);
|
|
|
+ } else {
|
|
|
+ log.error("CenterTcpServerInboundHandler: Response Failed. Center Not Connect VDS: [{}]", ctlrNmbr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mapper.updateRseCtrlHs(cntl);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|