|
@@ -13,8 +13,6 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.io.OutputStream;
|
|
|
import java.net.Socket;
|
|
|
import java.nio.ByteBuffer;
|
|
|
import java.nio.ByteOrder;
|
|
@@ -28,7 +26,7 @@ public class RseControlService {
|
|
|
private final RseMapper mapper;
|
|
|
|
|
|
public ByteBuffer getResetCommand(Long ctlrNmbr, Long ctrlSeq, Integer devcType, Integer cntlType) {
|
|
|
- int length = 16;
|
|
|
+ int length = 8+8+4+4;
|
|
|
byte opCode = CenterProtocol.INT_OP_DSRC_CONTROL_REQ;
|
|
|
|
|
|
// Center packet
|
|
@@ -37,10 +35,10 @@ public class RseControlService {
|
|
|
// command message packet
|
|
|
ByteBuffer msgBuffer = ByteBuffer.allocate(length);
|
|
|
msgBuffer.order(ByteOrder.BIG_ENDIAN);
|
|
|
- msgBuffer.putLong(ctlrNmbr);
|
|
|
- msgBuffer.putLong(ctrlSeq);
|
|
|
- msgBuffer.putInt(devcType);
|
|
|
- msgBuffer.putInt(cntlType);
|
|
|
+ msgBuffer.putLong(ctlrNmbr); // 8 Byte
|
|
|
+ msgBuffer.putLong(ctrlSeq); // 8 Byte
|
|
|
+ msgBuffer.putInt(devcType); // 4 Byte
|
|
|
+ msgBuffer.putInt(cntlType); // 4 Byte
|
|
|
|
|
|
ByteBuffer cmdBuffer = ByteBuffer.allocate(center.length + length);
|
|
|
cmdBuffer.order(ByteOrder.BIG_ENDIAN);
|
|
@@ -74,49 +72,48 @@ public class RseControlService {
|
|
|
|
|
|
String ipAddress = this.config.getIpAddress();
|
|
|
int port = this.config.getPort();
|
|
|
- int connTimeout = 3000; // milli-seconds
|
|
|
- int readTimeout = 2000; // milli-seconds
|
|
|
+ int connTimeout = 5000; // milli-seconds
|
|
|
+ int readTimeout = 5000; // milli-seconds
|
|
|
|
|
|
Socket socket = null;
|
|
|
try {
|
|
|
socket = CenterProtocol.connectServer(ipAddress, port, connTimeout, readTimeout);
|
|
|
- try {
|
|
|
- byte[] data = cmdBuffer.array();
|
|
|
- OutputStream os = socket.getOutputStream();
|
|
|
- os.write(data);
|
|
|
- os.flush();
|
|
|
- InputStream recvStream = socket.getInputStream();
|
|
|
+ if (CenterProtocol.sendData(socket, cmdBuffer.array())) {
|
|
|
try {
|
|
|
while (true) {
|
|
|
- byte[] head = CenterProtocol.receiveBytes(recvStream, 10);
|
|
|
- if (head[0] == (byte)0x24 && head[1] == (byte)0x04 && head[5] == (byte)0x0C) {
|
|
|
- log.info("RECV RESPONSE HEAD: 10 Bytes. {}", SysUtils.byteArrayToHex(head));
|
|
|
+ byte[] head = CenterProtocol.receiveBytes(socket, 10);
|
|
|
+ log.info("RECV RESPONSE HEAD: 10 Bytes. {}", SysUtils.byteArrayToHex(head));
|
|
|
+ if (head[0] == (byte)CenterProtocol.INT_ID_RSE_SERVER &&
|
|
|
+ head[1] == (byte)CenterProtocol.INT_ID_RSE_OPER &&
|
|
|
+ head[5] == (byte)CenterProtocol.INT_OP_DSRC_CONTROL_REQ) {
|
|
|
if (head[4] == (byte) 0xFF) {
|
|
|
- result.setResult(9, "RSE 서버에서 알수 없는 RSE 제어기 입니다.");
|
|
|
+ result.setResult(9, "알수 없는 RSE 제어기 입니다.");
|
|
|
} else if (head[4] == (byte) 0xFE) {
|
|
|
- result.setResult(8, "RSE 서버에서 RSE 제어기 통신 상태가 비정상 입니다.");
|
|
|
+ result.setResult(8, "RSE 제어기 통신 상태가 비정상 입니다.");
|
|
|
} else if (head[4] == (byte) 0xFD) {
|
|
|
- result.setResult(7, "제어기 제어값 오류.");
|
|
|
+ result.setResult(7, "RSE 제어기 제어기 제어값 오류.");
|
|
|
} else if (head[4] == (byte) 0xFC) {
|
|
|
- result.setResult(6, "RSE 서버에서 RSE 제어기로 리셋 명령을 전송하지 못하였습니다.");
|
|
|
+ result.setResult(6, "RSE 제어기로 리셋 명령을 전송하지 못하였습니다.");
|
|
|
} else {
|
|
|
- result.setResult(0, "RSE 서버에 제어기 리셋명령을 정상적으로 전송하였습니다.");
|
|
|
+ result.setResult(0, "RSE 제어기 리셋명령을 정상적으로 전송하였습니다.");
|
|
|
}
|
|
|
} else {
|
|
|
- result.setResult(0, "RSE 서버에 제어기 리셋명령을 정상적으로 전송하였습니다.");
|
|
|
+ result.setResult(4, "RSE 서버로 부터 비정상 데이터를 수신하였습니다.");
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
- // 이전 VDS 통신 서버에서는 응답을 주지 않기 때문에 타임아웃 걸린 경우 정상적으로 처리하도록 함
|
|
|
- result.setResult(0, "RSE 서버에 제어기 리셋명령을 정상적으로 전송하였습니다.");
|
|
|
+ // 타임아웃
|
|
|
+ log.error("{}", e.getMessage());
|
|
|
+ result.setResult(1, "RSE 서버로 부터 응답수신시각이 초과되었습니다.(명령응답 타임아웃)");
|
|
|
}
|
|
|
- } catch (IOException e) {
|
|
|
+ }
|
|
|
+ else {
|
|
|
result.setResult(3, "RSE 서버에 제어기 리셋명령을 정상적으로 전송하지 못하였습니다.");
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
log.error("Reset Request. {}, {}, IOException", ipAddress, port);
|
|
|
- String errMsg = "[VDS 서버: " + ipAddress + "." + port + "]";
|
|
|
+ String errMsg = "[RSE 서버: " + ipAddress + "." + port + "]";
|
|
|
result.setResult(2, "RSE 서버와 통신이 실패하였습니다.\r\n" + errMsg);
|
|
|
return result;
|
|
|
}
|