TbVdsCtlr.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package com.its.vds.entity;
  2. import com.its.app.utils.SysUtils;
  3. import com.its.vds.domain.NET;
  4. import com.its.vds.xnettcp.vds.protocol.VdsReqData;
  5. import com.its.vds.xnettcp.vds.protocol.VdsReqSynchronize;
  6. import com.its.vds.xnettcp.vds.protocol.VdsReqTemperature;
  7. import io.netty.channel.Channel;
  8. import lombok.Getter;
  9. import lombok.Setter;
  10. import lombok.ToString;
  11. import java.net.InetSocketAddress;
  12. import java.util.Collections;
  13. import java.util.HashMap;
  14. import java.util.Map;
  15. @Getter
  16. @Setter
  17. @ToString
  18. public class TbVdsCtlr {
  19. private String VDS_CTLR_NMBR;
  20. private String VDS_CTLR_ID;
  21. private String VDS_NM;
  22. private String VDS_TYPE_CD;
  23. private String VDS_CTLR_IP;
  24. private int VDS_CTLR_PORT;
  25. private int GROUP_NO;
  26. private int VDS_CTLR_LOCAL_NO;
  27. private int FAN_MODE;
  28. private int FAN_RUN_TMPR;
  29. private int HETR_MODE;
  30. private int HETR_RUN_TMPR;
  31. private int DETECT_LANES;
  32. private int TRAF_CLCT_CYCL;
  33. private int STTS_CLCT_CYCL;
  34. private String VALD_YN;
  35. private String DEL_YN;
  36. private Map<String, TbVdsDtct> vdsDtctMap;
  37. private int netState;
  38. private boolean isDupCon;
  39. private boolean isDupLogin;
  40. private String dstIpAddr;
  41. private TbVdsCtlrStts stts;
  42. private Channel channel;
  43. private Channel dupChannel;
  44. private long syncTime;
  45. private InetSocketAddress cliReq;
  46. private int connectCount;
  47. private String connectTm;
  48. private String disConnectTm;
  49. VdsReqSynchronize reqSynchronize = null;
  50. VdsReqData reqData = null;
  51. VdsReqTemperature reqTemperature = null;
  52. public TbVdsCtlr() {
  53. this.vdsDtctMap = Collections.synchronizedMap(new HashMap<String, TbVdsDtct>());
  54. this.stts = new TbVdsCtlrStts();
  55. this.connectCount = 0;
  56. this.connectTm = "";
  57. this.disConnectTm = "";
  58. initNet();
  59. }
  60. public String getLogKey() {
  61. return this.VDS_CTLR_ID;
  62. }
  63. public void resetConnectCount() {
  64. if (this.netState == NET.CLOSED)
  65. this.connectCount = 0;
  66. else
  67. this.connectCount = 1;
  68. }
  69. public void setConnectTm() {
  70. this.connectTm = SysUtils.getSysTimeStr();
  71. this.connectCount++;
  72. }
  73. public void setDisConnectTm() {
  74. this.disConnectTm = SysUtils.getSysTimeStr();
  75. }
  76. void initNet() {
  77. this.netState = NET.CLOSED;
  78. this.isDupCon = false;
  79. this.isDupLogin = false;
  80. this.dstIpAddr = "";
  81. this.channel = null;
  82. this.dupChannel = null;
  83. this.cliReq = null;
  84. this.syncTime = 0;
  85. }
  86. public synchronized void channelOpen(Channel channel) {
  87. this.netState = NET.LOGIN_REQ;
  88. this.channel = channel;
  89. getStts().initStts(true);
  90. setConnectTm();
  91. }
  92. public synchronized void channelLogin(Channel channel) {
  93. this.netState = NET.LOGINED;
  94. this.channel = channel;
  95. getStts().initStts(true);
  96. setConnectTm();
  97. }
  98. public synchronized void channelClosed() {
  99. this.netState = NET.CLOSED;
  100. this.channel = null;
  101. getStts().initStts(false);
  102. setDisConnectTm();
  103. }
  104. /**
  105. * 통신 패킷 초기화
  106. */
  107. public void initReqPacket() {
  108. if (this.reqSynchronize == null) {
  109. this.reqSynchronize = new VdsReqSynchronize((short)this.GROUP_NO, (short)this.VDS_CTLR_LOCAL_NO);
  110. this.reqData.makeCRC();
  111. }
  112. if (this.reqData == null) {
  113. this.reqData = new VdsReqData((short)this.GROUP_NO, (short)this.VDS_CTLR_LOCAL_NO);
  114. this.reqData.makeCRC();
  115. }
  116. if (this.reqTemperature == null) {
  117. this.reqTemperature = new VdsReqTemperature((short)this.GROUP_NO, (short)this.VDS_CTLR_LOCAL_NO);
  118. this.reqData.makeCRC();
  119. }
  120. }
  121. }