|
@@ -0,0 +1,256 @@
|
|
|
+package com.its.op.service.its.xprotocol;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.net.InetSocketAddress;
|
|
|
+import java.net.Socket;
|
|
|
+import java.net.SocketAddress;
|
|
|
+import java.nio.ByteBuffer;
|
|
|
+import java.nio.ByteOrder;
|
|
|
+
|
|
|
+public class CenterProtocol {
|
|
|
+
|
|
|
+ public static final ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
|
|
|
+ public static final int HEADER_SIZE = 10;
|
|
|
+
|
|
|
+ /*******************************************************************************
|
|
|
+ * 시스템 ID
|
|
|
+ *******************************************************************************/
|
|
|
+ public static final int INT_ID_TRAFFIC_SERVER = 0x01; /* 가공서버 */
|
|
|
+ public static final int INT_ID_SIGCTL_SERVER = 0x02; /* 신호제어서버 */
|
|
|
+ public static final int INT_ID_SIGCOM_SERVER = 0x03; /* 신호통신서버 */
|
|
|
+ public static final int INT_ID_VDS_SERVER = 0x04; /* VDS 서버 */
|
|
|
+ public static final int INT_ID_AVI_SERVER = 0x05; /* AVI 서버 */
|
|
|
+ public static final int INT_ID_DSRC_SERVER = 0x06; /* DSRC 서버 */
|
|
|
+ public static final int INT_ID_VMS_SERVER = 0x07; /* VMS 서버 */
|
|
|
+ public static final int INT_ID_CCTV_SERVER = 0x08; /* CCTV 서버 */
|
|
|
+ public static final int INT_ID_WEB_SERVER = 0x09; /* WEB 서버 */
|
|
|
+ public static final int INT_ID_UTIS_SERVER = 0x0A; /* UTIS 서버 */
|
|
|
+ public static final int INT_ID_KMA_SERVER = 0x0B; /* 기상청 연계 서버 */
|
|
|
+ public static final int INT_ID_WCAM_SERVER = 0x0C; /* 웹카메라 연계 서버 */
|
|
|
+ public static final int INT_ID_FCLT_SERVER = 0x0D; /* 시설물관리 서버 */
|
|
|
+ public static final int INT_ID_EXT01_SERVER = 0x0E; /* 연계 서버1 */
|
|
|
+ public static final int INT_ID_EXT02_SERVER = 0x0F; /* 연계 서버2 */
|
|
|
+ public static final int INT_ID_EXT03_SERVER = 0x10; /* 연계 서버3 */
|
|
|
+ public static final int INT_ID_CCAM_SERVER = 0x11; /* 교차로감시카메라 연계 서버 */
|
|
|
+ public static final int INT_ID_PARK_SERVER = 0x12; /* 주차장 연계 서버 */
|
|
|
+ public static final int INT_ID_RSE_SERVER = 0x13; /* RSE 연계 서버 */
|
|
|
+
|
|
|
+ public static final int INT_ID_MAIN_OPER = 0x21; /* 통합운영단말 */
|
|
|
+ public static final int INT_ID_WALL_OPER = 0x22; /* 상황판운영단말 */
|
|
|
+ public static final int INT_ID_SIG_OPER = 0x23; /* 신호운영단말 */
|
|
|
+ public static final int INT_ID_VDS_OPER = 0x24; /* VDS운영단말 */
|
|
|
+ public static final int INT_ID_AVI_OPER = 0x25; /* AVI운영단말 */
|
|
|
+ public static final int INT_ID_DSRC_OPER = 0x26; /* DSRC운영단말 */
|
|
|
+ public static final int INT_ID_VMS_OPER = 0x27; /* VMS운영단말 */
|
|
|
+ public static final int INT_ID_CCTV_OPER = 0x28; /* CCTV운영단말 */
|
|
|
+ public static final int INT_ID_FMS_OPER = 0x29; /* 시설물관리단말 */
|
|
|
+ public static final int INT_ID_UTIS_OPER = 0x2A; /* UTIS관리단말 */
|
|
|
+ public static final int INT_ID_WCAM_OPER = 0x2B; /* WCAM관리단말 */
|
|
|
+
|
|
|
+ public static final int INT_ID_OPER_MIN = INT_ID_MAIN_OPER ; /* 운영단말 최소값 */
|
|
|
+ public static final int INT_ID_OPER_MAX = INT_ID_WCAM_OPER ; /* 운영단말 최대값 */
|
|
|
+
|
|
|
+ /*******************************************************************************
|
|
|
+ * 프로토콜 OP CODE 정의
|
|
|
+ *******************************************************************************/
|
|
|
+ public static final int INT_OP_TRAFFIC_CHANGE = 0x10; /* 교통정보가공완료 */
|
|
|
+ public static final int INT_OP_NODELINK_CHANGE = 0x11; /* 노드링크 기반 정보 변경 */
|
|
|
+ public static final int INT_OP_FACILITY_CHANGE = 0x12; /* 시설물 기반 정보 변경 */
|
|
|
+ public static final int INT_OP_PG_STATE_REQ = 0x13; /* 공통사항, 프로그램 동작상태 요청 */
|
|
|
+ public static final int INT_OP_PG_STATE_RES = 0x14; /* 공통사항, 프로그램 동작상태 응답 */
|
|
|
+ public static final int INT_OP_CHANGE_EVENT = 0x15; /* 공통사항, 마스터정보 변경 알림 */
|
|
|
+ public static final int INT_OP_INC_EVENT = 0x16; /* 공통사항, 돌발정보 전송 */
|
|
|
+ public static final int INT_OP_ACK = 0x17; /* 공통사항, ACK(Acknowledge) */
|
|
|
+ public static final int INT_OP_NACK = 0x18; /* 공통사항, NACK(Negative Acknowledge) */
|
|
|
+ public static final int INT_OP_EXTENSION = 0x19; /* 공통사항, EXTENSION 요청/응답 */
|
|
|
+
|
|
|
+ /*******************************************************************************
|
|
|
+ * VMS Protocol OP Code
|
|
|
+ *******************************************************************************/
|
|
|
+ public static final int INT_OP_VMS_STATE_REQ = 0x21; /* VMS 통신 서버, VMS 시설물 상태정보 요청 */
|
|
|
+ public static final int INT_OP_VMS_STATE_RES = 0x22; /* VMS 통신 서버, VMS 시설물 상태정보 전송 */
|
|
|
+ public static final int INT_OP_VMS_POWER_CTL = 0x23; /* VMS 통신 서버, VMS 전광판 On/Off 제어 */
|
|
|
+ public static final int INT_OP_VMS_LUMINANCE_CTL = 0x24; /* VMS 통신 서버, VMS 휘도 제어 */
|
|
|
+
|
|
|
+ public static final int INT_OP_VMS_PARA_SET = 0x25; /* VMS 통신 서버, VMS 환경설정정보 전송 */
|
|
|
+ public static final int INT_OP_VMS_PARA_SET2 = 0x26; /* VMS 통신 서버, VMS 환경설정정보 전송(For Pasig) */
|
|
|
+ public static final int INT_OP_VMS_RESET = 0x27; /* VMS 통신 서버, VMS 제어기 리셋 전송 */
|
|
|
+ public static final int INT_OP_VMS_MODE = 0x28; /* VMS 통신 서버, VMS 운영모드 변경 */
|
|
|
+ public static final int INT_OP_VMS_FORM_SAVE = 0x29; /* VMS 통신 서버, 실시간 VMS 제공정보 저장 */
|
|
|
+ public static final int INT_OP_VMS_FORM_DOWNLOAD = 0x2A; /* VMS 통신 서버, 실시간 VMS 제공정보 저장 */
|
|
|
+ public static final int INT_OP_VMS_IMAGE_SYMBOL = 0x2B; /* VMS image symbol update */
|
|
|
+ public static final int INT_OP_VMS_IMAGE_TRAFFIC = 0x2C; /* VMS image traffic update */
|
|
|
+ public static final int INT_OP_VMS_FORM_UPDATE = 0x2D; /* VMS form update */
|
|
|
+ public static final int INT_OP_VMS_IFSC_UPDATE = 0x2E; /* VMS ifsc update */
|
|
|
+
|
|
|
+ public static final int INT_OP_VMS_PARAM_RES = 0x2F; /* VMS 통신 서버, VMS 시설물 파라미터정보 전송 ==> 목포시 싸인텔레콤 추가 */
|
|
|
+
|
|
|
+ public static final int INT_OP_VMS_COMMON = 0x30; /* 신규로 생성될 명령어를 처리하기 위한 OP Code */
|
|
|
+ public static final int INT_OP_VMS_COMMON_EXT = 0x31; /* 신규로 생성될 명령어를 처리하기 위한 OP Code */
|
|
|
+ public static final int INT_OP_VMS_IMMEDIATE_SCN_DNLD = 0x32; /* 폼 즉시 다운로드 OP Code */
|
|
|
+ public static final int INT_OP_VMS_PARAM_REQ = 0x33; /* VMS 파라미터 요청 */
|
|
|
+ public static final int INT_OP_VMS_DIRECT = 0x34; /* VMS Direct command */
|
|
|
+
|
|
|
+
|
|
|
+ /*******************************************************************************
|
|
|
+ * VDS Protocol OP Code
|
|
|
+ *******************************************************************************/
|
|
|
+ public static final int INT_OP_VDS_STOP_IMAGE_REQ = 0x50; /* VDS 통신 서버, VDS 정지영상 요청 */
|
|
|
+ public static final int INT_OP_VDS_STOP_IMAGE_RES = 0x51; /* VDS 통신 서버, VDS 정지영상 요청 응답 */
|
|
|
+ public static final int INT_OP_VDS_STATE_RES = 0x52; /* VDS 통신 서버, VDS 시설물 상태정보 전송 */
|
|
|
+ public static final int INT_OP_VDS_FAN_CONTROL = 0x54; /* VDS 통신 서버, VDS FAN 제어 */
|
|
|
+ public static final int INT_OP_VDS_RESET = 0x59; /* VDS 통신 서버, VDS 제어기 리셋 전송 */
|
|
|
+
|
|
|
+ public static final int INT_OP_VDS_PARAM_REQ = 0x55; /* VDS 통신 서버, VDS 파라미터 요청 */
|
|
|
+ public static final int INT_OP_VDS_PARAM_RES = 0x56; /* VDS 통신 서버, VDS 파라미터 요청 응답 */
|
|
|
+ public static final int INT_OP_VDS_PARAM_SET_REQ = 0x57; /* VDS 통신 서버, VDS 파라미터 설정 요청 */
|
|
|
+ public static final int INT_OP_VDS_PARAM_SET_RES = 0x58; /* VDS 통신 서버, VDS 파라미터 설정 요청 응답 */
|
|
|
+
|
|
|
+ /*******************************************************************************
|
|
|
+ * DSRC Protocol OP Code
|
|
|
+ *******************************************************************************/
|
|
|
+ public static final int INT_OP_DSRC_CONTROL_REQ = 0x60; /* DSRC 통신 서버, DSRC 제어 요청 */
|
|
|
+ public static final int INT_OP_DSRC_CONTROL_RES = 0x61; /* DSRC 통신 서버, DSRC 제어 요청 응답 */
|
|
|
+ public static final int INT_OP_DSRC_STATE_RES = 0x62; /* DSRC 통신 서버, DSRC 시설물 상태정보 전송 */
|
|
|
+
|
|
|
+
|
|
|
+ /*******************************************************************************
|
|
|
+ * WCAM Protocol OP Code
|
|
|
+ *******************************************************************************/
|
|
|
+ public static final int INT_OP_WCAM_STATE_RES = 0x70; /* WCAM 통신 서버, WCAM 시설물 상태정보 전송 */
|
|
|
+
|
|
|
+ /*******************************************************************************
|
|
|
+ * CCAM Protocol OP Code
|
|
|
+ *******************************************************************************/
|
|
|
+ public static final int INT_OP_CCAM_STATE_RES = 0x71; /* CCAM 통신 서버, CCAM 시설물 상태정보 전송 */
|
|
|
+
|
|
|
+ /*******************************************************************************
|
|
|
+ * PARK Protocol OP Code
|
|
|
+ *******************************************************************************/
|
|
|
+ public static final int INT_OP_PARK_STATE_RES = 0x81; /* PARK 통신 서버, PARK 시설물 상태정보 전송 */
|
|
|
+
|
|
|
+ /*******************************************************************************
|
|
|
+ * 프로세스 상태정보 요청/응답
|
|
|
+ *******************************************************************************/
|
|
|
+ public static final int INT_MAX_PG_STATE = 146; /* 최대 프로그램 상태정보 */
|
|
|
+
|
|
|
+ /*******************************************************************************
|
|
|
+ * 돌발 발생 통보
|
|
|
+ *******************************************************************************/
|
|
|
+ public static final int INT_INC_TIME_SIZE = 14; /* 'YYYYMMDDHH24MISS' */
|
|
|
+ public static final int INT_INC_ID_SIZE = 12; /* 돌발 ID */
|
|
|
+
|
|
|
+ /*******************************************************************************
|
|
|
+ * VMS
|
|
|
+ *******************************************************************************/
|
|
|
+ public static final int INT_VMS_MAX_ID = 15; /* VMS 제어기 ID */
|
|
|
+ public static final int INT_VMS_MAX_MODULE = 100; /* 최대 VMS 모듈 */
|
|
|
+ public static final int INT_VMS_MAX_POWER = 10; /* 최대 VMS 전원 */
|
|
|
+ public static final int INT_VMS_MAX_MODULE_BIT = 100; /* 최대 VMS 모듈 비트*/
|
|
|
+ public static final int INT_VMS_MAX_POWER_BIT = 10; /* 최대 VMS 전원 비트 */
|
|
|
+
|
|
|
+ public static final int INT_VMS_MAX_DATETIME = 14; /* YYYYMMDDHHMMSS */
|
|
|
+ public static final int INT_VMS_MAX_OPER_ID = 20;
|
|
|
+
|
|
|
+ public static final int INT_VMS_MAX_STATE = 80; /* 최대 VMS 시설물 상태정보 */
|
|
|
+ public static final int INT_VMS_MAX_PARAM = 100; /* 최대 VMS 파라미터 */
|
|
|
+ public static final int INT_VMS_MAX_PREP = 93; /* 최대 VMS 폼 갯수 정보 */
|
|
|
+ public static final int INT_VMS_MAX_FORM = 40; /* 최대 VMS 폼 */
|
|
|
+ public static final int INT_VMS_MAX_OBJECT = 64; /* 최대 VMS 오브젝트 */
|
|
|
+ public static final int INT_VMS_MAX_STRING_BUF = 64; /* 최대 VMS 문자열 데이터 버퍼 */
|
|
|
+ public static final int INT_VMS_MAX_FORM_DOWNLOAD = 100; /* 최대 VMS 제공정보 저장 (256개 까지 증가 가능) */
|
|
|
+ public static final int INT_VMS_MAX_MODE = 100; /* 최대 VMS 모드변경 갯수 */
|
|
|
+
|
|
|
+ /*******************************************************************************
|
|
|
+ * VDS
|
|
|
+ *******************************************************************************/
|
|
|
+ public static final int INT_VDS_MAX_DATETIME = 14; /* YYYYMMDDHHMMSS */
|
|
|
+ public static final int INT_VDS_MAX_OPER_ID = 20;
|
|
|
+ public static final int INT_VDS_MAX_STATE = 200; /* 최대 VDS 시설물 상태정보 */
|
|
|
+ public static final int INT_VDS_MAX_STOP_IMAGE = 65535; /* 정지영상 패킷 최대크기 */
|
|
|
+ /* VDS 정지영상 요청 응답 */
|
|
|
+ public static final int ERR_VDS_STOP_IMAGE_NORMAL = 0x00;
|
|
|
+ public static final int ERR_VDS_STOP_IMAGE_NOT_CONNECT = 0x01;
|
|
|
+ public static final int ERR_VDS_STOP_IMAGE_BUSY = 0x02;
|
|
|
+ public static final int ERR_VDS_STOP_IMAGE_UNKNOWN_ID = 0x03;
|
|
|
+ public static final int ERR_VDS_STOP_IMAGE_SIZE = 0x04;
|
|
|
+
|
|
|
+ /*******************************************************************************
|
|
|
+ * DSRC
|
|
|
+ *******************************************************************************/
|
|
|
+ public static final int INT_DSRC_MAX_DATETIME = 14; /* YYYYMMDDHHMMSS */
|
|
|
+ public static final int INT_DSRC_MAX_OPER_ID = 20;
|
|
|
+ public static final int INT_DSRC_MAX_STATE = 200; /* 최대 DSRC 시설물 상태정보 */
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 센터 내부 통신 헤더 패킷 생성
|
|
|
+ * @param sndSystem
|
|
|
+ * @param rcvSystem
|
|
|
+ * @param opCode
|
|
|
+ * @param length
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static byte[] getRequestHead(int sndSystem, int rcvSystem, byte opCode, int length) {
|
|
|
+
|
|
|
+ ByteBuffer byteBuffer = ByteBuffer.allocate(10);
|
|
|
+ byteBuffer.order(ByteOrder.BIG_ENDIAN);
|
|
|
+ byteBuffer.put((byte)sndSystem); // 송신시스템-운영단말
|
|
|
+ byteBuffer.put((byte)rcvSystem); // 수신시스템
|
|
|
+ byteBuffer.put((byte)0x01); // 전체프레임개수
|
|
|
+ byteBuffer.put((byte)0x01); // 현재프레임번호
|
|
|
+ byteBuffer.put((byte)0x00); // Reserved
|
|
|
+ byteBuffer.put(opCode); // OP Code
|
|
|
+ byteBuffer.putInt(length); // 데이터 길이
|
|
|
+
|
|
|
+ //log.error("HEAD: {}", SysUtils.byteArrayToHex(byteBuffer.array()));
|
|
|
+ return byteBuffer.array();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 통신 서버와 통신 연결
|
|
|
+ * @param ipAddress
|
|
|
+ * @param port
|
|
|
+ * @param connTimeout
|
|
|
+ * @param readTimeout
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public static Socket connectServer(String ipAddress, int port, int connTimeout, int readTimeout) throws IOException {
|
|
|
+ SocketAddress socketAddress = new InetSocketAddress(ipAddress, port);
|
|
|
+ Socket socket = null;
|
|
|
+ try {
|
|
|
+ socket = new Socket();
|
|
|
+ socket.setSoTimeout(readTimeout); /* InputStream 에서 데이터읽을때의 timeout */
|
|
|
+ socket.connect(socketAddress, connTimeout); /* socket 연결 자체에대한 timeout */
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ return socket;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 소켓 입력 버퍼로 부터 데이터 길이만큼 읽어 온다
|
|
|
+ * @param inStream
|
|
|
+ * @param buffSize
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public static byte[] receiveBytes(InputStream inStream, int buffSize) throws IOException {
|
|
|
+ byte[] buffer;
|
|
|
+ int bytesRead = 0;
|
|
|
+ int readThisTime;
|
|
|
+ buffer = new byte[buffSize];
|
|
|
+ while (bytesRead < buffSize)
|
|
|
+ {
|
|
|
+ readThisTime = inStream.read(buffer, bytesRead, buffSize - bytesRead);
|
|
|
+ if (readThisTime == -1)
|
|
|
+ {
|
|
|
+ throw new IOException("Socket.receive(): Socket closed unexpectedly");
|
|
|
+ }
|
|
|
+ bytesRead += readThisTime;
|
|
|
+ }
|
|
|
+ return buffer;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|