|
|
@@ -1,261 +1,24 @@
|
|
|
package com.its.app;
|
|
|
|
|
|
-import com.google.common.primitives.Bytes;
|
|
|
-import com.its.app.utils.BcdConverter;
|
|
|
-import com.its.app.utils.SysUtils;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.its.pis.PisCommServerApplication;
|
|
|
-import com.its.pis.entity.TbVdsCtlr;
|
|
|
-import com.its.pis.global.AppRepository;
|
|
|
-import com.its.pis.xnettcp.vds.process.VdsData;
|
|
|
-import com.its.pis.xnettcp.vds.process.VdsDataProcess;
|
|
|
-import com.its.pis.xnettcp.vds.protocol.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
|
-import java.nio.ByteBuffer;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
@Slf4j
|
|
|
@SpringBootTest(classes = PisCommServerApplication.class)
|
|
|
public class PisCommServerApplicationTests {
|
|
|
|
|
|
+ private ObjectMapper mapper;
|
|
|
@Test
|
|
|
void test1() {
|
|
|
- byte[] sysdate = new byte[7];
|
|
|
- sysdate[0] = (byte)(('2' - '0') << 4 | ('0' - '0'));
|
|
|
- sysdate[1] = (byte)(('2' - '0') << 4 | ('2' - '0'));
|
|
|
- sysdate[2] = (byte)(('0' - '0') << 4 | ('7' - '0'));
|
|
|
- sysdate[3] = (byte)(('0' - '0') << 4 | ('8' - '0'));
|
|
|
- sysdate[4] = (byte)(('1' - '0') << 4 | ('2' - '0'));
|
|
|
- sysdate[5] = (byte)(('3' - '0') << 4 | ('4' - '0'));
|
|
|
- sysdate[6] = (byte)(('5' - '0') << 4 | ('6' - '0'));
|
|
|
-
|
|
|
- String bcdSysdate = BcdConverter.bcdToString(sysdate);
|
|
|
- log.error("bcdSysdate: {}", bcdSysdate);
|
|
|
-
|
|
|
- String now = SysUtils.getSysTime();
|
|
|
- log.error("-------now: {}", now);
|
|
|
- byte[] result = BcdConverter.stringToBcd(now);
|
|
|
- log.error("----result: {}, {} Bytes", SysUtils.byteArrayToHex(result), result.length);
|
|
|
- String res = BcdConverter.bcdToString(result);
|
|
|
- log.error("-------res: {}", res);
|
|
|
-
|
|
|
- String now1 = "1234567890123";
|
|
|
- log.error("------now1: {}", now1);
|
|
|
- byte[] result1 = BcdConverter.stringToBcd(now1);
|
|
|
- log.error("---result: {}, {} Bytes", SysUtils.byteArrayToHex(result1), result1.length);
|
|
|
- String res1 = BcdConverter.bcdToString(result1);
|
|
|
- log.error("------res: {}", res1);
|
|
|
- }
|
|
|
- @Test
|
|
|
- void Test2() {
|
|
|
- int readableBytes = 23;
|
|
|
- byte[] recvBytes = new byte[readableBytes];
|
|
|
- recvBytes[ 0] = (byte)0x10;
|
|
|
- recvBytes[ 1] = (byte)0x02;
|
|
|
- recvBytes[ 2] = (byte)0x10;
|
|
|
- recvBytes[ 3] = (byte)0x10;
|
|
|
- recvBytes[ 4] = (byte)0x00;
|
|
|
- recvBytes[ 5] = (byte)0x14;
|
|
|
- recvBytes[ 6] = (byte)0x01;
|
|
|
- recvBytes[ 7] = (byte)0x01;
|
|
|
- recvBytes[ 8] = (byte)0x10;
|
|
|
- recvBytes[ 9] = (byte)0x03;
|
|
|
- recvBytes[10] = (byte)0x54;
|
|
|
- recvBytes[11] = (byte)0x80;
|
|
|
- recvBytes[12] = (byte)0x10;
|
|
|
- recvBytes[13] = (byte)0x02;
|
|
|
- recvBytes[14] = (byte)0x00;
|
|
|
- recvBytes[15] = (byte)0x00;
|
|
|
- recvBytes[16] = (byte)0x00;
|
|
|
- recvBytes[17] = (byte)0x14;
|
|
|
- recvBytes[18] = (byte)0x01;
|
|
|
- recvBytes[19] = (byte)0x01;
|
|
|
- recvBytes[20] = (byte)0x10;
|
|
|
- recvBytes[21] = (byte)0x03;
|
|
|
- recvBytes[22] = (byte)0x54;
|
|
|
- //recvBytes[23] = (byte)0x80;
|
|
|
-
|
|
|
- byte[] packets = new byte[readableBytes];
|
|
|
-
|
|
|
- int readIdx = 0;
|
|
|
- int msgSize = 0; // 순수 데이터 사이즈
|
|
|
- int totalMsgSize = 0;
|
|
|
- boolean foundDle = false;
|
|
|
- boolean remainPacket = false;
|
|
|
- String ipAddress = "0.0.0.0";
|
|
|
- log.error("recvBytes: {}", SysUtils.byteArrayToHex(recvBytes));
|
|
|
-
|
|
|
- while (true) {
|
|
|
- if (VdsProtocol.MIN_PACKET_SIZE > (readableBytes-totalMsgSize)) {
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- msgSize = 0;
|
|
|
- foundDle = false;
|
|
|
- log.error("xxxxxxxxxxxxx: {}, {}, {}, {}", readIdx, readableBytes-totalMsgSize, totalMsgSize, readableBytes);
|
|
|
- for (readIdx = totalMsgSize; readIdx < readableBytes; readIdx++) {
|
|
|
- byte data = recvBytes[readIdx];
|
|
|
- if (foundDle) {
|
|
|
- foundDle = false;
|
|
|
- if (data == VdsProtocol.vds_DLE) {
|
|
|
- // Skip Data
|
|
|
- log.warn("RECV_0: [{}]. ReadableBytes: {} Bytes, ReadIndex: {}, DLE Stuffing Data Recv.", ipAddress, readableBytes, readIdx);
|
|
|
- } else if (data == VdsProtocol.vds_STX) {
|
|
|
- packets[msgSize++] = data;
|
|
|
- } else if (data == VdsProtocol.vds_ETX) {
|
|
|
- // 이전데이터가 DLE 이고 현재 데이터가 ETX 이면 패킷의 끝임.
|
|
|
- // 다음 2바이트는 CRC 데이터임, 남아 있는 데이터가 CRC 2바이트를 포함한 크기보다 작으면
|
|
|
- // 하나의 패킷을 완전히 수신하지 못한 것임
|
|
|
- log.error("LENGTH: {}, {}", (readIdx + 2), (readableBytes-totalMsgSize));
|
|
|
- if ((readIdx + 3) > (readableBytes)) {
|
|
|
- // 하나의 패킷을 읽지 못함
|
|
|
- log.warn("RECV_0: [{}]. ReadableBytes: {} Bytes, ReadIndex: {}, DLE Data Remain.", ipAddress, readableBytes, readIdx);
|
|
|
- remainPacket = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- packets[msgSize++] = data;
|
|
|
- packets[msgSize++] = recvBytes[readIdx+1]; // CRC1
|
|
|
- packets[msgSize++] = recvBytes[readIdx+2]; // CRC2
|
|
|
-
|
|
|
- // 하나의 패킷을 읽었음 ***************
|
|
|
- totalMsgSize += msgSize;
|
|
|
- log.error("OnePacket: {} Bytes, {} Bytes, {}", msgSize, totalMsgSize, SysUtils.byteArrayToHex(packets));
|
|
|
-
|
|
|
- VdsResFramePacket packet = new VdsResFramePacket(null, packets, msgSize);
|
|
|
- log.error("OnePacket: {} Bytes, {}", packet.getByteBuffer().array().length, SysUtils.byteArrayToHex(packet.getByteBuffer().array()));
|
|
|
- break;
|
|
|
- } else {
|
|
|
- // DLE 다음에 와야할 데이터가 들어오지 않았다. 패킷에 오류가 발생함.
|
|
|
- log.warn("RECV_0: [{}]. ReadableBytes: {} Bytes, ReadIndex: {}, DLE Next Data Recv Error.", ipAddress, readableBytes, readIdx);
|
|
|
- }
|
|
|
- } else {
|
|
|
- packets[msgSize++] = data;
|
|
|
- if (data == VdsProtocol.vds_DLE) {
|
|
|
- foundDle = true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- log.error("yyyyyyyyyyyyyyyyyyy: {}, {}, {}", totalMsgSize, readableBytes, remainPacket);
|
|
|
- if (totalMsgSize >= readableBytes || remainPacket) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void Test3() {
|
|
|
- int readableBytes = 10;
|
|
|
- byte[] recvBytes = new byte[readableBytes];
|
|
|
- recvBytes[ 0] = (byte)0x10;
|
|
|
- recvBytes[ 1] = (byte)0x02;
|
|
|
- recvBytes[ 2] = (byte)0x10;
|
|
|
- recvBytes[ 3] = (byte)0x10;
|
|
|
- recvBytes[ 4] = (byte)0x00;
|
|
|
- recvBytes[ 5] = (byte)0x14;
|
|
|
- recvBytes[ 6] = (byte)0x01;
|
|
|
- recvBytes[ 7] = (byte)0x01;
|
|
|
- recvBytes[ 8] = (byte)0x10;
|
|
|
- recvBytes[ 9] = (byte)0x03;
|
|
|
- log.error("{}", SysUtils.byteArrayToHex(recvBytes));
|
|
|
- List<Byte> list = new ArrayList<Byte>();
|
|
|
- for (byte b : recvBytes) {
|
|
|
- list.add(b);
|
|
|
- }
|
|
|
-
|
|
|
- log.error("LENGTH: {}", list.size());
|
|
|
-
|
|
|
- byte[] arr = Bytes.toArray(list);
|
|
|
- log.error("{}", SysUtils.byteArrayToHex(arr));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void Test4() {
|
|
|
- //10 02 00 00 00 1C 04 10 03 03 09
|
|
|
- byte[] packet = { (byte)0x10, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x1C, (byte)0x04, (byte)0x10, (byte)0x03, (byte)0x00, (byte)0x00};
|
|
|
- short crc = VdsProtocol.getCRC16ARC(packet, 2, packet.length - 6);
|
|
|
-
|
|
|
- // 제어기 통과 데이터 요청
|
|
|
- for (Map.Entry<String, TbVdsCtlr> e : AppRepository.getInstance().getCtlrMap().entrySet()) {
|
|
|
- TbVdsCtlr obj = e.getValue();
|
|
|
- ByteBuffer sendBuffer = obj.getReqData().getByteBuffer();
|
|
|
- //log.error("{}: {}", obj.getVDS_CTLR_LOCAL_NO(), SysUtils.byteArrayToHex(sendBuffer.array()));
|
|
|
- }
|
|
|
-
|
|
|
- // 제어기 SYC
|
|
|
- for (Map.Entry<String, TbVdsCtlr> e : AppRepository.getInstance().getCtlrMap().entrySet()) {
|
|
|
- TbVdsCtlr obj = e.getValue();
|
|
|
- ByteBuffer sendBuffer = obj.getReqSynchronize().getByteBuffer();
|
|
|
- //log.error("{}: {}", obj.getVDS_CTLR_LOCAL_NO(), SysUtils.byteArrayToHex(sendBuffer.array()));
|
|
|
- }
|
|
|
-
|
|
|
- // 제어기 온도 데이터 요청
|
|
|
- for (Map.Entry<String, TbVdsCtlr> e : AppRepository.getInstance().getCtlrMap().entrySet()) {
|
|
|
- TbVdsCtlr obj = e.getValue();
|
|
|
- ByteBuffer sendBuffer = obj.getReqTemperature().getByteBuffer();
|
|
|
- //log.error("{}: {}", obj.getVDS_CTLR_LOCAL_NO(), SysUtils.byteArrayToHex(sendBuffer.array()));
|
|
|
- }
|
|
|
-
|
|
|
- // 제어기 상태 RTC 변경
|
|
|
- for (Map.Entry<String, TbVdsCtlr> e : AppRepository.getInstance().getCtlrMap().entrySet()) {
|
|
|
- TbVdsCtlr obj = e.getValue();
|
|
|
- VdsReqRTC reqRTC = new VdsReqRTC((short)obj.getGROUP_NO(), (short)obj.getVDS_CTLR_LOCAL_NO());
|
|
|
- reqRTC.makeCRC();
|
|
|
- ByteBuffer sendBuffer = reqRTC.getByteBuffer();
|
|
|
- //log.error("{}: {}", obj.getVDS_CTLR_LOCAL_NO(), SysUtils.byteArrayToHex(sendBuffer.array()));
|
|
|
- }
|
|
|
-
|
|
|
- // 화상 이미지 요청
|
|
|
- for (int ii = 0; ii < 13; ii++) {
|
|
|
- VdsReqImage reqImage = new VdsReqImage((short)0, (short)2);
|
|
|
- reqImage.setCameraNo(1);
|
|
|
- reqImage.setFrameNo(ii);
|
|
|
- reqImage.makeCRC();
|
|
|
- ByteBuffer sendBuffer = reqImage.getByteBuffer();
|
|
|
- //log.error("{}, {}: {}", 2, ii, SysUtils.byteArrayToHex(sendBuffer.array()));
|
|
|
- }
|
|
|
-
|
|
|
- // 제어기 RESET
|
|
|
- for (Map.Entry<String, TbVdsCtlr> e : AppRepository.getInstance().getCtlrMap().entrySet()) {
|
|
|
- TbVdsCtlr obj = e.getValue();
|
|
|
- VdsReqReset reqReset = new VdsReqReset((short)obj.getGROUP_NO(), (short)obj.getVDS_CTLR_LOCAL_NO());
|
|
|
- reqReset.makeCRC();
|
|
|
- ByteBuffer sendBuffer = reqReset.getByteBuffer();
|
|
|
- log.error("{}: {}", obj.getVDS_CTLR_LOCAL_NO(), SysUtils.byteArrayToHex(sendBuffer.array()));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void Test5() {
|
|
|
- // 온도 수신
|
|
|
- byte[] recvBytes = { (byte)0x10, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x12, (byte)0x1E,
|
|
|
- (byte)0x8A, (byte)0x40, (byte)0x21, (byte)0x00, (byte)0xDF, (byte)0x10, (byte)0x03, (byte)0xF2, (byte)0xB9};
|
|
|
- //(byte)0x8A, (byte)0x00, (byte)0x21, (byte)0x00, (byte)0xDF, (byte)0x10, (byte)0x03, (byte)0xF2, (byte)0xB9};
|
|
|
- VdsDataProcess vdsDataProcess = (VdsDataProcess)AppUtils.getBean(VdsDataProcess.class);
|
|
|
- TbVdsCtlr obj = AppRepository.getInstance().getCtlrMap().get("00000018");
|
|
|
- VdsResFramePacket packet = new VdsResFramePacket(obj, recvBytes, recvBytes.length);
|
|
|
- vdsDataProcess.add(new VdsData(obj, obj.getVDS_CTLR_IP(), null, packet));
|
|
|
-
|
|
|
- VdsProtocol.sleep(6000);
|
|
|
- }
|
|
|
- //[2022-07-12 09:59:44] [22번 제어기 교통정보응답 수신] 10 02 00 00 00 16 04 88 40 01 00 00 00 00 00 00 00 00 00 00 00 00 00 0B 27 1A 61 3E 03 05 46 5A 08 32 0F 5D 40 04 03 29 47 06 35 0B 11 3F 03 02 25 42 10 03 E9 54
|
|
|
-
|
|
|
- @Test
|
|
|
- void Test6() {
|
|
|
- // 교통정보응답수신(22번 제어기)
|
|
|
- //byte[] recvBytes = { (byte)0x10, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x16, (byte)0x04, (byte)0x88, (byte)0x40, (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0B, (byte)0x27, (byte)0x1A, (byte)0x61, (byte)0x3E, (byte)0x03, (byte)0x05, (byte)0x46, (byte)0x5A, (byte)0x08, (byte)0x32, (byte)0x0F, (byte)0x5D, (byte)0x40, (byte)0x04, (byte)0x03, (byte)0x29, (byte)0x47, (byte)0x06, (byte)0x35, (byte)0x0B, (byte)0x11, (byte)0x3F, (byte)0x03, (byte)0x02, (byte)0x25, (byte)0x42, (byte)0x10, (byte)0x03, (byte)0xE9, (byte)0x54};
|
|
|
- // 교통정보응답수신(15번 제어기)
|
|
|
- byte[] recvBytes = {(byte)0x10, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0F, (byte)0x04, (byte)0x8A, (byte)0x40, (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x07, (byte)0x5E, (byte)0x05, (byte)0x48, (byte)0x2E, (byte)0x04, (byte)0x01, (byte)0x0E, (byte)0x26, (byte)0x0C, (byte)0x4B, (byte)0x0E, (byte)0x02, (byte)0x36, (byte)0x02, (byte)0x02, (byte)0x5D, (byte)0x2F, (byte)0x05, (byte)0x45, (byte)0x07, (byte)0x03, (byte)0x3C, (byte)0x06, (byte)0x01, (byte)0x2D, (byte)0x33, (byte)0x02, (byte)0x47, (byte)0x04, (byte)0x16, (byte)0x69, (byte)0x0A, (byte)0x00, (byte)0x62, (byte)0x32, (byte)0x07, (byte)0x40, (byte)0x0C, (byte)0x57, (byte)0x44, (byte)0x04, (byte)0x02, (byte)0x30, (byte)0x37, (byte)0x03, (byte)0x3C, (byte)0x06, (byte)0x41, (byte)0x5B, (byte)0x07, (byte)0x01, (byte)0x33, (byte)0x3B, (byte)0x10, (byte)0x03, (byte)0xB5, (byte)0x2C};
|
|
|
- //(byte)0x8A, (byte)0x00, (byte)0x21, (byte)0x00, (byte)0xDF, (byte)0x10, (byte)0x03, (byte)0xF2, (byte)0xB9};
|
|
|
- VdsDataProcess vdsDataProcess = (VdsDataProcess)AppUtils.getBean(VdsDataProcess.class);
|
|
|
- TbVdsCtlr obj = AppRepository.getInstance().getCtlrMap().get("00000015");
|
|
|
- VdsResFramePacket packet = new VdsResFramePacket(obj, recvBytes, recvBytes.length);
|
|
|
- vdsDataProcess.add(new VdsData(obj, obj.getVDS_CTLR_IP(), null, packet));
|
|
|
+ // Class to Json String
|
|
|
+ this.mapper = new ObjectMapper();
|
|
|
+ //String message = this.mapper.writeValueAsString(bisMessage);
|
|
|
|
|
|
- VdsProtocol.sleep(6000);
|
|
|
+ // Json String to Class
|
|
|
+ //CpuNodeStatusDTO status = this.mapper.readValue(message, CpuNodeStatusDTO.class);
|
|
|
}
|
|
|
|
|
|
}
|