|
@@ -1,50 +1,137 @@
|
|
|
package com.its.vms.api.service;
|
|
|
|
|
|
import com.its.app.utils.ItsUtils;
|
|
|
+import com.its.app.utils.SysUtils;
|
|
|
import com.its.vms.api.dto.VmsControlDto;
|
|
|
+import com.its.vms.dao.mapper.VmsCtlrMapper;
|
|
|
import com.its.vms.domain.NET;
|
|
|
import com.its.vms.dto.TbVmsCtlrDto;
|
|
|
import com.its.vms.entity.TbVmsCtrlHs;
|
|
|
import com.its.vms.service.AppRepositoryService;
|
|
|
+import com.its.vms.xnettcp.vms.process.TcpServerSendData;
|
|
|
+import com.its.vms.xnettcp.vms.protocol.enums.*;
|
|
|
+import com.its.vms.xnettcp.vms.protocol.impl.VmsReqStatusControl;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@Slf4j
|
|
|
@RequiredArgsConstructor
|
|
|
@Service
|
|
|
public class VmsControlService {
|
|
|
|
|
|
+ private final VmsCtlrMapper mapper;
|
|
|
private final AppRepositoryService repoService;
|
|
|
- //제어유형(V01:전광판ON,V02:전광판OFF,V03:제어기리셋,V04:함체환경설정,V05:전광판ON/OFF시각설정)
|
|
|
-// if (sCtlType == "V01") sCtlType = lblV01->Caption;//"전광판ON";
|
|
|
-// else if (sCtlType == "V02") sCtlType = lblV02->Caption;//"전광판OFF";
|
|
|
-// else if (sCtlType == "V03") sCtlType = lblV03->Caption;//"제어기리셋";
|
|
|
-// else if (sCtlType == "V04") sCtlType = lblV04->Caption;//"함체환경설정";
|
|
|
-// else if (sCtlType == "V05") sCtlType = lblV05->Caption;//"전광판ON/OFF시각설정";
|
|
|
-// else if (sCtlType == "V06") sCtlType = lblV06->Caption;//"운영모드변경";
|
|
|
-// else if (sCtlType == "V07") sCtlType = lblV07->Caption;//"휘도제어";
|
|
|
-// else if (sCtlType == "V08") sCtlType = lblV08->Caption;//"기본메시지다운로드";
|
|
|
-// else if (sCtlType == "V09") sCtlType = lblV09->Caption;//"폼 표출주기";
|
|
|
-// else if (sCtlType == "V10") sCtlType = lblV10->Caption;//"폼 즉시 다운로드";
|
|
|
|
|
|
/**
|
|
|
- * VMS 제어 이력 저장
|
|
|
- * @param dto
|
|
|
+ * 잘못된 제어기 관리번호로 요청이 들어온 경우
|
|
|
+ * @param command
|
|
|
+ * @param userId
|
|
|
+ * @param vmsCtlrNmbr
|
|
|
+ * @return
|
|
|
*/
|
|
|
- @Transactional
|
|
|
- public void saveCtrlHs(TbVmsCtrlHs dto) {
|
|
|
- //this.repoCtrlHs.insertHs(dto.getCtrlDt(), dto.getVmsCtlrNmbr(), dto.getCtrlType(), dto.getCtrlVal(), dto.getCtrlResult(), dto.getUserId());
|
|
|
+ public VmsControlDto.VmsControlRes unknownControlNmbr(eVmsStatusControl command, String userId, Long vmsCtlrNmbr) {
|
|
|
+ String ctrlType = String.format("V%02X", command.getByteValue());
|
|
|
+ return saveControlResult(8, "알수 없는 제어기 관리번호 입니다.", userId, vmsCtlrNmbr, ctrlType, "Unknown Nmbr: " + vmsCtlrNmbr);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * VMS 정보를 메모리에서 찾는다.
|
|
|
+ * VMS 제어 유형별 유형 타입이 잘못된 경우
|
|
|
+ * @param command
|
|
|
+ * @param type
|
|
|
+ * @param userId
|
|
|
* @param vmsCtlrNmbr
|
|
|
* @return
|
|
|
*/
|
|
|
- public TbVmsCtlrDto findVms(Long vmsCtlrNmbr) {
|
|
|
- return this.repoService.getCtlrMap(vmsCtlrNmbr);
|
|
|
+ public VmsControlDto.VmsControlRes unknownControlType(eVmsStatusControl command, int type, String userId, Long vmsCtlrNmbr) {
|
|
|
+ String ctrlType = String.format("V%02X", command.getByteValue());
|
|
|
+ return saveControlResult(7, "알수 없는 제어유형 입니다.", userId, vmsCtlrNmbr, ctrlType, "Unknown Type: " + type);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * VMS 제어 이력 저장 및 결과 리튼
|
|
|
+ * @param error
|
|
|
+ * @param message
|
|
|
+ * @param userId
|
|
|
+ * @param vmsCtlrNmbr
|
|
|
+ * @param ctrlType
|
|
|
+ * @param ctrlVal
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public VmsControlDto.VmsControlRes saveControlResult(int error, String message, String userId, Long vmsCtlrNmbr, String ctrlType, String ctrlVal) {
|
|
|
+ this.mapper.insertVmsCtrlHs(TbVmsCtrlHs.builder()
|
|
|
+ .ctrlDt(ItsUtils.getSysTime())
|
|
|
+ .vmsCtlrNmbr(vmsCtlrNmbr)
|
|
|
+ .ctrlType(ctrlType)
|
|
|
+ .ctrlVal(ctrlVal)
|
|
|
+ .ctrlResult(error)
|
|
|
+ .userId(userId)
|
|
|
+ .build());
|
|
|
+
|
|
|
+ return new VmsControlDto.VmsControlRes(error, message);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * VMS 제어기 상태 제어
|
|
|
+ * @param userId
|
|
|
+ * @param controlType
|
|
|
+ * @param controlData
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public VmsControlDto.VmsControlRes statusControlReq(String userId, eVmsStatusControl controlType, VmsReqStatusControl controlData) {
|
|
|
+ byte[] body = controlData.getBody();
|
|
|
+ String ctrlType = String.format("V%02X", body[0]);
|
|
|
+ String ctrlVal = "";
|
|
|
+ switch(controlType) {
|
|
|
+ case CONTROL_SIGNBOARD_POWER: // (0x01, "0x00.전광판 전원제어"),
|
|
|
+ ctrlVal = (body[1] == (byte)(eVmsReqBoardPower.vms_req_board_power_on.getValue() & 0xFF)) ? "Board Panel Power ON" : "Board Panel Power OFF";
|
|
|
+ break;
|
|
|
+ case CONTROL_RESET: // (0x02, "0x02.제어기 리셋트"),
|
|
|
+ ctrlVal = "Controller Reset";
|
|
|
+ break;
|
|
|
+ case CONTROL_RETRY_COUNT: // (0x03, "0x03.통신 재시도 횟수"),
|
|
|
+ ctrlVal = String.format("Retry Count 0x%02X", body[1]);
|
|
|
+ break;
|
|
|
+ case CONTROL_SYSTEM_TIME: // (0x04, "0x04.제어기 시간 설정"),
|
|
|
+ byte[] sysTimeArr = new byte[14];
|
|
|
+ System.arraycopy(body, 1, sysTimeArr, 0, 14);
|
|
|
+ ctrlVal = "System Time " + SysUtils.byteArrayToString(sysTimeArr);
|
|
|
+ break;
|
|
|
+ case CONTROL_BLINK_CYCLE: // (0x05, "0x05.점멸시간 주기"),
|
|
|
+ ctrlVal = String.format("Blink Cycle 0x%02X", body[1]);
|
|
|
+ break;
|
|
|
+ case CONTROL_BRIGHT: // (0x06, "0x06.밝기 제어"),
|
|
|
+ ctrlVal = String.format("Bright 0x%02X, 0x%02X", body[1], body[2]);
|
|
|
+ break;
|
|
|
+ case CONTROL_FAN: // (0x07, "0x07.Fan 제어"),
|
|
|
+ ctrlVal = String.format("Fan Control 0x%02X, 0x%02X", body[1], body[2]);
|
|
|
+ break;
|
|
|
+ case CONTROL_HEATER: // (0x08, "0x08.Heater 제어"),
|
|
|
+ ctrlVal = String.format("Heater Control 0x%02X, 0x%02X", body[1], body[2]);
|
|
|
+ break;
|
|
|
+ case CONTROL_SCREEN_COLOR: // (0x09, "0x09.화면 배색 제어"),
|
|
|
+ ctrlVal = String.format("Screen Color 0x%02X", body[1]);
|
|
|
+ break;
|
|
|
+ case CONTROL_MODULE_ERROR_RATIO: // (0x0A, "0x0A.장애 모듈비율(%)"),
|
|
|
+ ctrlVal = String.format("Module Error Ratio 0x%02X", body[1]);
|
|
|
+ break;
|
|
|
+ case CONTROL_DEFAULT_SCENARIO_RUN_TIME: // (0x0B, "0x0B.디폴트 시나리오 동작 시간")
|
|
|
+ ctrlVal = String.format("Default Scenario Run Time 0x%02X", body[1]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ TbVmsCtlrDto vmsObj = controlData.getVmsObj();
|
|
|
+ if (vmsObj.getNetState() == NET.CLOSED) {
|
|
|
+ return saveControlResult(1, "통신이 연결되어 있지 않습니다.", userId, vmsObj.getVmsCtlrNmbr(), ctrlType, ctrlVal);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ /**
|
|
|
+ * 제어기로 상태제어 명령을 요청
|
|
|
+ */
|
|
|
+ vmsObj.addRequestData(new TcpServerSendData(eVmsOpCode.OP_VMS_STATUS_CONTROL, controlData));
|
|
|
+ }
|
|
|
+
|
|
|
+ return saveControlResult(0, "success: 명령을 정상적으로 전송하였습니다.", userId, vmsObj.getVmsCtlrNmbr(), ctrlType, ctrlVal);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -53,38 +140,160 @@ public class VmsControlService {
|
|
|
* @param req
|
|
|
* @return
|
|
|
*/
|
|
|
- public VmsControlDto.VmsControlRes controlReset(Long vmsCtlrNmbr, VmsControlDto.VmsControlReq req) {
|
|
|
- log.warn("controlReset: VMS {}, controlReset {}.", vmsCtlrNmbr, req);
|
|
|
- TbVmsCtlrDto vmsObj = findVms(vmsCtlrNmbr);
|
|
|
- Integer error = 0;
|
|
|
- String message = "success";
|
|
|
+ public VmsControlDto.VmsControlRes controlReset(Long vmsCtlrNmbr, VmsControlDto.VmsControlResetReq req) {
|
|
|
+ log.warn("VmsControlService.controlReset: VMS {}, {}.", vmsCtlrNmbr, req);
|
|
|
+ eVmsStatusControl command = eVmsStatusControl.CONTROL_RESET;
|
|
|
+ TbVmsCtlrDto vmsObj = this.repoService.getCtlrMap(vmsCtlrNmbr);
|
|
|
+ if (vmsObj == null) {
|
|
|
+ return unknownControlNmbr(command, req.getUserId(), vmsCtlrNmbr);
|
|
|
+ }
|
|
|
+
|
|
|
+ VmsReqStatusControl controlData = new VmsReqStatusControl(vmsObj);
|
|
|
+ controlData.controlReset();
|
|
|
+ return statusControlReq(req.getUserId(), command, controlData);
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * VMS 제어기 리셋
|
|
|
+ * @param vmsCtlrNmbr
|
|
|
+ * @param req
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public VmsControlDto.VmsControlRes controlPanlOnOff(Long vmsCtlrNmbr, VmsControlDto.VmsControlPanlOnOfReq req) {
|
|
|
+ log.warn("VmsControlService.controlPanlOnOff: VMS {}, {}.", vmsCtlrNmbr, req);
|
|
|
+ eVmsStatusControl command = eVmsStatusControl.CONTROL_SIGNBOARD_POWER;
|
|
|
+ TbVmsCtlrDto vmsObj = this.repoService.getCtlrMap(vmsCtlrNmbr);
|
|
|
if (vmsObj == null) {
|
|
|
- error = 8;
|
|
|
- message = "알수 없는 제어기 입니다.";
|
|
|
+ return unknownControlNmbr(command, req.getUserId(), vmsCtlrNmbr);
|
|
|
}
|
|
|
- else {
|
|
|
- if (vmsObj.getNetState() == NET.CLOSED) {
|
|
|
- error = 1;
|
|
|
- message = "통신이 연결되어 있지 않습니다.";
|
|
|
- }
|
|
|
- else {
|
|
|
- if (!vmsObj.reset()) {
|
|
|
- error = 2;
|
|
|
- message = "데이터 전송 중 오류가 발생 했습니다.";
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ byte onOff = req.getOnOff() == 0 ? eVmsReqBoardPower.vms_req_board_power_off.getByteValue() : eVmsReqBoardPower.vms_req_board_power_on.getByteValue();
|
|
|
+ VmsReqStatusControl controlData = new VmsReqStatusControl(vmsObj);
|
|
|
+ controlData.controlSignboardPower(onOff);
|
|
|
+ return statusControlReq(req.getUserId(), command, controlData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * VMS 제어기 시간동기
|
|
|
+ * @param vmsCtlrNmbr
|
|
|
+ * @param req
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public VmsControlDto.VmsControlRes controlTimeSync(Long vmsCtlrNmbr, VmsControlDto.VmsControlTimeSyncReq req) {
|
|
|
+ log.warn("VmsControlService.controlTimeSync: VMS {}, {}.", vmsCtlrNmbr, req);
|
|
|
+ eVmsStatusControl command = eVmsStatusControl.CONTROL_SYSTEM_TIME;
|
|
|
+ TbVmsCtlrDto vmsObj = this.repoService.getCtlrMap(vmsCtlrNmbr);
|
|
|
+ if (vmsObj == null) {
|
|
|
+ return unknownControlNmbr(command, req.getUserId(), vmsCtlrNmbr);
|
|
|
}
|
|
|
|
|
|
- saveCtrlHs(TbVmsCtrlHs.builder()
|
|
|
- .ctrlDt(ItsUtils.getSysTime())
|
|
|
- .vmsCtlrNmbr(vmsCtlrNmbr)
|
|
|
- .ctrlType("V03")
|
|
|
- .ctrlVal("Reset")
|
|
|
- .ctrlResult(error)
|
|
|
- .userId(req.getUserId())
|
|
|
- .build());
|
|
|
- return new VmsControlDto.VmsControlRes(error, message);
|
|
|
+ VmsReqStatusControl controlData = new VmsReqStatusControl(vmsObj);
|
|
|
+ controlData.controlSystemTime();
|
|
|
+ return statusControlReq(req.getUserId(), command, controlData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * VMS 제어기 밝기 제어
|
|
|
+ * @param vmsCtlrNmbr
|
|
|
+ * @param req
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public VmsControlDto.VmsControlRes controlBright(Long vmsCtlrNmbr, VmsControlDto.VmsControlBrightReq req) {
|
|
|
+ log.warn("VmsControlService.controlBright: VMS {}, {}.", vmsCtlrNmbr, req);
|
|
|
+ eVmsStatusControl command = eVmsStatusControl.CONTROL_BRIGHT;
|
|
|
+ TbVmsCtlrDto vmsObj = this.repoService.getCtlrMap(vmsCtlrNmbr);
|
|
|
+ if (vmsObj == null) {
|
|
|
+ return unknownControlNmbr(command, req.getUserId(), vmsCtlrNmbr);
|
|
|
+ }
|
|
|
+
|
|
|
+ eVmsReqBrightControl controlType = eVmsReqBrightControl.getValue(req.getType());
|
|
|
+ if (controlType == null) {
|
|
|
+ return unknownControlType(command, req.getType(), req.getUserId(), vmsCtlrNmbr);
|
|
|
+ }
|
|
|
+
|
|
|
+ VmsReqStatusControl controlData = new VmsReqStatusControl(vmsObj);
|
|
|
+ controlData.controlBright(controlType.getByteValue(), (byte)(req.getValue() & 0xFF));
|
|
|
+ return statusControlReq(req.getUserId(), command, controlData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * VMS 제어기 FAN 제어
|
|
|
+ * @param vmsCtlrNmbr
|
|
|
+ * @param req
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public VmsControlDto.VmsControlRes controlFan(Long vmsCtlrNmbr, VmsControlDto.VmsControlFanReq req) {
|
|
|
+ log.warn("VmsControlService.controlFan: VMS {}, {}.", vmsCtlrNmbr, req);
|
|
|
+ eVmsStatusControl command = eVmsStatusControl.CONTROL_FAN;
|
|
|
+ TbVmsCtlrDto vmsObj = this.repoService.getCtlrMap(vmsCtlrNmbr);
|
|
|
+ if (vmsObj == null) {
|
|
|
+ return unknownControlNmbr(command, req.getUserId(), vmsCtlrNmbr);
|
|
|
+ }
|
|
|
+
|
|
|
+ eVmsReqFanControl controlType = eVmsReqFanControl.getValue(req.getType());
|
|
|
+ if (controlType == null) {
|
|
|
+ return unknownControlType(command, req.getType(), req.getUserId(), vmsCtlrNmbr);
|
|
|
+ }
|
|
|
+
|
|
|
+ VmsReqStatusControl controlData = new VmsReqStatusControl(vmsObj);
|
|
|
+ controlData.controlFan(controlType.getByteValue(), (byte)(req.getValue() & 0xFF));
|
|
|
+ return statusControlReq(req.getUserId(), command, controlData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * VMS 제어기 HEATER 제어
|
|
|
+ * @param vmsCtlrNmbr
|
|
|
+ * @param req
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public VmsControlDto.VmsControlRes controlHeater(Long vmsCtlrNmbr, VmsControlDto.VmsControlHeaterReq req) {
|
|
|
+ log.warn("VmsControlService.controlHeater: VMS {}, {}.", vmsCtlrNmbr, req);
|
|
|
+ eVmsStatusControl command = eVmsStatusControl.CONTROL_HEATER;
|
|
|
+ TbVmsCtlrDto vmsObj = this.repoService.getCtlrMap(vmsCtlrNmbr);
|
|
|
+ if (vmsObj == null) {
|
|
|
+ return unknownControlNmbr(command, req.getUserId(), vmsCtlrNmbr);
|
|
|
+ }
|
|
|
+
|
|
|
+ eVmsReqHeaterControl controlType = eVmsReqHeaterControl.getValue(req.getType());
|
|
|
+ if (controlType == null) {
|
|
|
+ return unknownControlType(command, req.getType(), req.getUserId(), vmsCtlrNmbr);
|
|
|
+ }
|
|
|
+
|
|
|
+ VmsReqStatusControl controlData = new VmsReqStatusControl(vmsObj);
|
|
|
+ controlData.controlHeater(controlType.getByteValue(), (byte)(req.getValue() & 0xFF));
|
|
|
+ return statusControlReq(req.getUserId(), command, controlData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * VMS 제어기 동작온도 설정
|
|
|
+ * @param vmsCtlrNmbr
|
|
|
+ * @param req
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public VmsControlDto.VmsControlRes controlRunTemp(Long vmsCtlrNmbr, VmsControlDto.VmsControlRunTempReq req) {
|
|
|
+ log.warn("VmsControlService.controlRunTemp: VMS {}, {}.", vmsCtlrNmbr, req);
|
|
|
+ eVmsStatusControl command = eVmsStatusControl.CONTROL_FAN;
|
|
|
+ TbVmsCtlrDto vmsObj = this.repoService.getCtlrMap(vmsCtlrNmbr);
|
|
|
+ if (vmsObj == null) {
|
|
|
+ return unknownControlNmbr(command, req.getUserId(), vmsCtlrNmbr);
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO: VMS 파라미터 제어 명령이 없어서 상태제어 명령으로 처리하고 있음.
|
|
|
+ // 제어기 업체와 협의하여 상태제어 명령으로 처리하는 것이 맞는지 확인 필요함.
|
|
|
+ // 필요할 경우 파라미터 설정(다운로드) 명령을 새롭게 추가해서 처리해야 함.
|
|
|
+ VmsReqStatusControl controlFan = new VmsReqStatusControl(vmsObj);
|
|
|
+ controlFan.controlFan(eVmsReqFanControl.vms_req_fan_auto.getByteValue(), (byte)(req.getFanRunTemp() & 0xFF));
|
|
|
+ statusControlReq(req.getUserId(), command, controlFan);
|
|
|
+
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ log.error("{}", e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ VmsReqStatusControl controlHeater = new VmsReqStatusControl(vmsObj);
|
|
|
+ controlHeater.controlHeater(eVmsReqHeaterControl.vms_req_heater_auto.getByteValue(), (byte)(req.getHeaterRunTemp() & 0xFF));
|
|
|
+ return statusControlReq(req.getUserId(), command, controlHeater);
|
|
|
}
|
|
|
|
|
|
}
|