1、修改rtuAddr注释
2、实现开关阀自报协议
3、实现开阀工作报
4、《编码设计》
| | |
| | | */ |
| | | public class TcpIoSessionAttrIdIsRtuAddr { |
| | | |
| | | public static final String sessionArrIdKey = "key_rtuAddr" ; //è¿ä¸ªkeyåå¨çæ¯IMEIå· |
| | | public static final String sessionArrIdKey = "key_rtuAddr" ; //è¿ä¸ªkeyåå¨çæ¯Rtuå°å |
| | | } |
| | |
| | | public String toString(){ |
| | | String s = "å½ä»¤id=" + id + "\n" ; |
| | | s += (protocol == null ? "" : ("åè®®=" + protocol + "\n")); |
| | | s += (rtuAddr == null ? "" : ("IMEIå·=" + rtuAddr + "\n")); |
| | | s += (rtuAddr == null ? "" : ("Rtuå°å=" + rtuAddr + "\n")); |
| | | s += "å½ä»¤ç±»å=" + (type.equals(CommandType.innerCommand)?"å
é¨å½ä»¤":"ç»ç«¯å½ä»¤") + "\n" ; |
| | | s += (code == null ? "" : ("åè½ç =" + code + "\n")) ; |
| | | s += "è¿åä¸é´ä»¶å¯¹å½ä»¤å¤çç»æ=" + (noRtMwDealRes == null?"è¿å":(noRtMwDealRes?"ä¸è¿å":"è¿å") + "\n") ; |
| | |
| | | public String toString() { |
| | | StringBuilder sb = new StringBuilder() ; |
| | | sb.append("ä¸è¡æ¥æ(åå
è¿å¶): ").append((hex == null?"":hex)).append("\n") ; // |
| | | sb.append("IMEIå· : ").append((rtuAddr==null?"":rtuAddr)).append("\n") ; |
| | | sb.append("Rtuå°å : ").append((rtuAddr==null?"":rtuAddr)).append("\n") ; |
| | | if(commandId != null){ |
| | | sb.append("å½ä»¤ID : ").append(commandId).append("\n") ; //å½ä»¤ID |
| | | } |
| | |
| | | * @param upHex ä¸è¡æ°æ® |
| | | * @param reportOrResponse_trueOrFalse ä¸è¡æ°æ®æ¯ä¸»å¨ä¸æ¥è¿æ¯å½ä»¤ç»æ |
| | | * @param parseFail ä¸è¡æ°æ®è§£ææ¯å¦å¤±è´¥ |
| | | * @param rtuAddrInData ä¸è¡æ°æ®ä¸å¨åè®®æ°æ®ä¸çIMEIå·ï¼ |
| | | * âä¿®æ¹RTUç»ç«¯ç®¡çé
ç½®åæ°âå½ä»¤çè¿åæ°æ®ï¼å
¶å议头ä¸çIMEIå·ä¸æ°æ®ä¸çIMEIå·ä¸ä¸æ ·ï¼ |
| | | * 妿RTUä¸è½å
³éç½ç»ï¼é£ä¹sessionCachä¸çIMEIå·æ»æ¯ç¨ä¿®æ¹åçIMEIå·ï¼ä½¿å¾ä»¥åä¸è¡æ°æ®çä¸è½æ¾å°ç¼åä¸çSession |
| | | * @param rtuAddrInData ä¸è¡æ°æ®ä¸å¨åè®®æ°æ®ä¸çRtuå°åï¼ |
| | | * âä¿®æ¹RTUç»ç«¯ç®¡çé
ç½®åæ°âå½ä»¤çè¿åæ°æ®ï¼å
¶å议头ä¸çRtuå°å䏿°æ®ä¸çRtuå°åä¸ä¸æ ·ï¼ |
| | | * 妿RTUä¸è½å
³éç½ç»ï¼é£ä¹sessionCachä¸çRtuå°åæ»æ¯ç¨ä¿®æ¹åçRtuå°åï¼ä½¿å¾ä»¥åä¸è¡æ°æ®çä¸è½æ¾å°ç¼åä¸çSession |
| | | */ |
| | | void callback(String rtuAddr, |
| | | String code, |
| | |
| | | } |
| | | |
| | | public String protocolName ;//åè®®åç§° |
| | | public String rtuAddr ;//IMEIå·ï¼æ³¨ærtuAddrå¯è½ä¸ºnull |
| | | public String rtuAddr ;//Rtuå°åï¼æ³¨ærtuAddrå¯è½ä¸ºnull |
| | | public String message ;//åºéæ¶æ¯ |
| | | public Exception e ;//å¼å¸¸ |
| | | |
| | |
| | | public String commandId ;//åéå½ä»¤çIDï¼å¦ææ¯å½ä»¤ç»æï¼å¹¶ä¸å¹é
äºä¸åå½ä»¤ï¼æ¤å¼ä¸ä¸ºç©º |
| | | |
| | | public String protocolName ;//åè®®åç§° |
| | | public String rtuAddr ;//IMEIå· |
| | | public String rtuAddr ;//Rtuå°å |
| | | public String upCode ;//ä¸è¡æ°æ®ä¸çåè½ç |
| | | public String upHex ;//ä¸è¡æ°æ®åå
è¿å¶å½¢å¼ |
| | | public byte[] upBuffer ;//ä¸è¡æ°æ®åèæ°ç» |
| | |
| | | } |
| | | |
| | | public String protocolName ;//åè®®åç§° |
| | | public String rtuAddr ;//IMEIå·(çµä¿¡å¹³å°IMEI) |
| | | public String rtuAddr ;//Rtuå°å |
| | | public String commandId ;//å½ä»¤IDï¼åèµ·å½ä»¤ç客æ·ç«¯(web端)çæï¼ä»¥å¹é
å½ä»¤ç»æ |
| | | public String downCode ;//ä¸è¡å½ä»¤åè½ç ; |
| | | public byte[] downBuffer ;//ä¸è¡å½ä»¤æ°æ® |
| | |
| | | class OnLineResult{ |
| | | public int result ;//åæç»æ |
| | | public String protocolName ;//åè®®åç§° |
| | | public String rtuAddr ;//IMEIå· |
| | | public String rtuAddr ;//Rtuå°å |
| | | public byte[] remoteData;//éè¦åRtuååçæ°æ® |
| | | public OnLineResult(){ |
| | | result = OnLineAction_fail ; |
| | |
| | | } |
| | | |
| | | int OnLineAction_fail = 0; //åæä¸çº¿æ°æ®å¤±è´¥ï¼å¦æä¾çæ°æ®ä¸ºnullçåå |
| | | int OnLineAction_success = 1; //åæä¸çº¿æ°æ®æåï¼å¹¶è½å¾å°IMEIå· |
| | | int OnLineAction_success = 1; //åæä¸çº¿æ°æ®æåï¼å¹¶è½å¾å°Rtuå°å |
| | | int OnLineAction_success_noMe = 2; //åæä¸çº¿æ°æ®æåï¼è¯å«åºä¸æ¯æ¬åè®®æ°æ® |
| | | int OnLineAction_success_response = 3; //åæä¸çº¿æ°æ®æåï¼å¹¶éè¦åRtuååæ°æ® |
| | | |
| | |
| | | } |
| | | } |
| | | if(rs == null){ |
| | | throw new Exception("å¤çä¸çº¿æ¶åºéï¼æªè½æååæåºIMEIå·ï¼") ; |
| | | throw new Exception("å¤çä¸çº¿æ¶åºéï¼æªè½æååæåºRtuå°åï¼") ; |
| | | } |
| | | return rs ; |
| | | } |
| | |
| | | |
| | | public class CodeV1_0_1 { |
| | | //åè½ç 为å符串ï¼åå
è¿å¶æ°æ® |
| | | public static final String cd_02 = "02" ;//é¾è·¯æ£æµ |
| | | public static final String cd_03 = "03" ;//äºä»¶ä¸æ¥ |
| | | public static final String cd_04 = "04" ;//å¼é |
| | | public static final String cd_05 = "05" ;//å
³é |
| | | public static final String cd_02 = "02" ;//饿µç«é¾è·¯æ£æµ |
| | | public static final String cd_C0 = "C0" ;//饿µç«èªæ¥å®æ¶æ°æ® |
| | | public static final String cd_83 = "83" ;//饿µç«å¼å
³éèªæ¥ |
| | | public static final String cd_84 = "84" ;//å¼é工使¥ |
| | | public static final String cd_06 = "06" ;//éé¨å¨ä½ç»æ |
| | | |
| | | public static String getCodeName(String code) { |
| | | String name = (code.equals(cd_02) ? "é¾è·¯æ£æµ" : |
| | | (code.equals(cd_03) ? "äºä»¶ä¸æ¥" : |
| | | (code.equals(cd_04) ? "å¼é" : |
| | | (code.equals(cd_05) ? "å
³é" : |
| | | (code.equals(cd_C0) ? "èªæ¥å®æ¶æ°æ®" : |
| | | (code.equals(cd_83) ? "å¼å
³éèªæ¥" : |
| | | (code.equals(cd_84) ? "å¼é工使¥" : |
| | | (code.equals(cd_06) ? "éé¨å¨ä½ç»æ" : |
| | | ""))))) ; |
| | | return name ; |
| | |
| | | |
| | | |
| | | /** |
| | | * åæIMEIå· |
| | | * åæRtuå°å |
| | | * @param bs ä¸è¡åèæ°ç» |
| | | * @return æ§å¶å¨å°å |
| | | * @throws Exception å¼å¸¸ |
| | |
| | | //DIR = 0 |
| | | return b ; |
| | | } |
| | | |
| | | /** |
| | | * å¾å°å
³å¼éç±»ååç§° |
| | | * @param type åè |
| | | * @return åç§° |
| | | */ |
| | | public static String openCloseValveType(byte type){ |
| | | return switch (type) { |
| | | case 1 -> "å·å¡å¼é"; |
| | | case 2 -> "å·å¡å
³é"; |
| | | case 3 -> "ä¸å¿ç«å¼é"; |
| | | case 4 -> "ä¸å¿ç«å
³é"; |
| | | case 5 -> "æ¬ è´¹å
³é"; |
| | | case 6 -> "æµé计æ
éå
³é"; |
| | | case 7 -> "ç´§æ¥å
³é"; |
| | | case 8 -> "ç¨æ·è¿ç¨å¼é"; |
| | | case 9 -> "ç¨æ·è¿ç¨å
³é"; |
| | | default -> "æªç¥"; |
| | | }; |
| | | } |
| | | |
| | | /* |
| | | * åæçæ¬å· |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class DataAlarmVo { |
| | | public Byte batteryVolt ;// èçµæ± çµå |
| | | public Byte loss ;//æ¼æ |
| | | public Byte meter ;//仪表 |
| | | public Byte valve ;//éé¨ |
| | | |
| | | public String toString(){ |
| | | StringBuilder str = new StringBuilder() ; |
| | | str.append(" æ¥è¦:\n"); |
| | | str.append(" èçµæ± çµåï¼"); |
| | | str.append(batteryVolt==null?"":(batteryVolt==1?"æ¥è¦":"æ£å¸¸")); |
| | | str.append("\n"); |
| | | str.append(" æ¼æï¼"); |
| | | str.append(loss==null?"":(loss==1?"æ¥è¦":"æ£å¸¸")); |
| | | str.append("\n"); |
| | | str.append(" 仪表ï¼"); |
| | | str.append(meter==null?"":(meter==1?"æ¥è¦":"æ£å¸¸")); |
| | | str.append("\n"); |
| | | str.append(" éé¨ï¼"); |
| | | str.append(valve==null?"":(valve==1?"æ¥è¦":"æ£å¸¸")); |
| | | return str.toString() ; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class DataCd83CloseVo { |
| | | // å¼å
³éç±»åï¼ |
| | | // 1ãå·å¡å¼éï¼2å·å¡å
³éï¼3ãä¸å¿ç«å¼éï¼4ãä¸å¿ç«å
³éï¼5ãæ¬ è´¹å
³éï¼ |
| | | // 6ãæµé计æ
éå
³éï¼7ãç´§æ¥å
³éï¼8ãç¨æ·è¿ç¨å¼éï¼9ãç¨æ·è¿ç¨å
³éï¼ |
| | | public Byte type ; |
| | | public Double totalAmount; //累计æµéï¼5åèBCDç ï¼åå¼èå´0~9999999999ï¼åä½ä¸ºm3ã |
| | | public String clientNum ;//åæ·ç¼å· |
| | | public String icAddr ;//icå¡å°å |
| | | public Double remainMoney ;//å©ä½éé¢ï¼ç¨æ·ä½é¢4åèBCDç ï¼åå¼èå´0.00~999999.99ï¼åä½ä¸ºå
|
| | | public String openDt ;//ç¨æ°´æ·ç¨æ°´å¼å§æ¶é´ï¼6åèBCDç ï¼é¡ºåºæ¯å¹´ææ¥æ¶åç§ï¼å
¶ä¸å
Œ
å¹´=2000+å¹´ã |
| | | public String closeDt ;//ç¨æ°´æ·ç¨æ°´ç»ææ¶é´ï¼6åèBCDç ï¼é¡ºåºæ¯å¹´ææ¥æ¶åç§ï¼å
¶ä¸å
Œ
å¹´=2000+å¹´ã |
| | | public Double thisAmount ;//ç¨æ°´æ·æ¬æ¬¡ç¨æ°´éï¼ç´¯è®¡æµé5åèBCDç ï¼åå¼èå´0~9999999999ï¼åä½ä¸ºm3ã |
| | | public Double thisMoney ;//ç¨æ°´æ·æ¬æ¬¡æ¶è´¹éé¢ï¼ç¨æ·ä½é¢4åèBCDç ï¼åå¼èå´0.00~999999.99ï¼åä½ä¸ºå
ã |
| | | public Integer thisTime ;//ç¨æ°´æ·æ¬æ¬¡ç¨æ°´æ¶é¿ï¼ç¨æ°´æ¶é¿2åèBCDç ï¼åå¼èå´0~9999ï¼åä½ä¸ºåéã |
| | | public String rtuDt ;//æ§å¶å¨æ¶é |
| | | |
| | | public String toString(){ |
| | | StringBuilder sb = new StringBuilder() ; |
| | | sb.append(" ç»ç«¯å
³éèªæ¥:\n"); |
| | | sb.append(" å
³éç±»åï¼"); |
| | | sb.append(CommonV1_0_1.openCloseValveType(type)) ; |
| | | sb.append("\n"); |
| | | sb.append(" 累计æµéï¼"); |
| | | sb.append(totalAmount==null?"":totalAmount); |
| | | sb.append("\n"); |
| | | sb.append(" åæ·ç¼å·ï¼"); |
| | | sb.append(clientNum); |
| | | sb.append("\n"); |
| | | sb.append(" icå¡å°åï¼"); |
| | | sb.append(icAddr); |
| | | sb.append("\n"); |
| | | sb.append(" å©ä½éé¢ï¼å
ï¼ï¼"); |
| | | sb.append(remainMoney ==null?"": remainMoney); |
| | | sb.append("\n"); |
| | | sb.append(" å¼éæ¶é´ï¼"); |
| | | sb.append(openDt); |
| | | sb.append("\n"); |
| | | sb.append(" å
³éæ¶é´ï¼"); |
| | | sb.append(closeDt); |
| | | sb.append("\n"); |
| | | sb.append(" æ¬æ¬¡ç¨æ°´éï¼"); |
| | | sb.append(thisAmount==null?"":thisAmount); |
| | | sb.append("\n"); |
| | | sb.append(" æ¬æ¬¡è±è´¹éé¢ï¼å
ï¼ï¼"); |
| | | sb.append(thisMoney==null?"":thisMoney); |
| | | sb.append("\n"); |
| | | sb.append(" æ¬æ¬¡ç¨æ°´æ¶é¿ï¼åéï¼ï¼"); |
| | | sb.append(thisTime==null?"":thisTime); |
| | | sb.append("\n"); |
| | | sb.append(" æ§å¶å¨æ¶éï¼"); |
| | | sb.append(rtuDt==null?"":rtuDt); |
| | | sb.append("\n"); |
| | | |
| | | return sb.toString() ; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0; |
| | | |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class DataCd83OpenVo { |
| | | // å¼å
³éç±»åï¼ |
| | | // 1ãå·å¡å¼éï¼2å·å¡å
³éï¼3ãä¸å¿ç«å¼éï¼4ãä¸å¿ç«å
³éï¼5ãæ¬ è´¹å
³éï¼ |
| | | // 6ãæµé计æ
éå
³éï¼7ãç´§æ¥å
³éï¼8ãç¨æ·è¿ç¨å¼éï¼9ãç¨æ·è¿ç¨å
³éï¼ |
| | | public Byte type ; |
| | | public Double totalAmount; //累计æµéï¼5åèBCDç ï¼åå¼èå´0~9999999999ï¼åä½ä¸ºm3ã |
| | | public String clientNum ;//åæ·ç¼å· |
| | | public String icAddr ;//icå¡å°å |
| | | public Double remainMoney;//å©ä½éé¢ï¼ç¨æ·ä½é¢4åèBCDç ï¼åå¼èå´0.00~999999.99ï¼åä½ä¸ºå
|
| | | public String openDt ;//ç¨æ°´æ·å¼éæ¶é´ï¼6åèBCDç ï¼é¡ºåºæ¯å¹´ææ¥æ¶åç§ï¼å
¶ä¸å
Œ
å¹´=2000+å¹´ã |
| | | public String rtuDt ;//æ§å¶å¨æ¶é |
| | | |
| | | public String toString(){ |
| | | StringBuilder sb = new StringBuilder() ; |
| | | sb.append(" ç»ç«¯å¼éèªæ¥:\n"); |
| | | sb.append(" å¼éç±»åï¼"); |
| | | sb.append(CommonV1_0_1.openCloseValveType(type)) ; |
| | | sb.append("\n"); |
| | | sb.append(" 累计æµéï¼"); |
| | | sb.append(totalAmount==null?"":totalAmount); |
| | | sb.append("\n"); |
| | | sb.append(" åæ·ç¼å·ï¼"); |
| | | sb.append(clientNum); |
| | | sb.append("\n"); |
| | | sb.append(" icå¡å°åï¼"); |
| | | sb.append(icAddr); |
| | | sb.append("\n"); |
| | | sb.append(" å©ä½éé¢ï¼å
ï¼ï¼"); |
| | | sb.append(remainMoney ==null?"": remainMoney); |
| | | sb.append("\n"); |
| | | sb.append(" å¼éæ¶é´ï¼"); |
| | | sb.append(openDt); |
| | | sb.append("\n"); |
| | | sb.append(" æ§å¶å¨æ¶éï¼"); |
| | | sb.append(rtuDt==null?"":rtuDt); |
| | | sb.append("\n"); |
| | | |
| | | return sb.toString() ; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class DataCd84Vo { |
| | | public String clientNum ;//åæ·ç¼å· |
| | | public Double remainMoney ;//å©ä½éé¢ï¼ç¨æ·ä½é¢4åèBCDç ï¼åå¼èå´0.00~999999.99ï¼åä½ä¸ºå
|
| | | public Double totalAmount; //累计æµéï¼5åèBCDç ï¼åå¼èå´0~9999999999ï¼åä½ä¸ºm3ã |
| | | public Double instantAmount; //ç¬æ¶æµéï¼5åèBCDç ï¼åå¼èå´0~9999999.999ï¼åä½ä¸ºm3/hã |
| | | public String rtuDt ;//æ§å¶å¨æ¶é |
| | | |
| | | public String toString(){ |
| | | StringBuilder sb = new StringBuilder() ; |
| | | sb.append(" ç»ç«¯å¼é工使¥:\n"); |
| | | sb.append(" åæ·ç¼å·ï¼"); |
| | | sb.append(clientNum); |
| | | sb.append("\n"); |
| | | sb.append(" å©ä½éé¢ï¼å
ï¼ï¼"); |
| | | sb.append(remainMoney==null?"":remainMoney); |
| | | sb.append("\n"); |
| | | sb.append(" 累计æµéï¼"); |
| | | sb.append(totalAmount==null?"":totalAmount); |
| | | sb.append("\n"); |
| | | sb.append(" ç¬æ¶æµéï¼"); |
| | | sb.append(instantAmount==null?"":instantAmount); |
| | | sb.append("\n"); |
| | | sb.append(" æ§å¶å¨æ¶éï¼"); |
| | | sb.append(rtuDt==null?"":rtuDt); |
| | | sb.append("\n"); |
| | | return sb.toString() ; |
| | | } |
| | | } |
| | |
| | | |
| | | @Data |
| | | public class DataCdC0Vo { |
| | | public Double instantAmount; //ç¬æ¶æµéï¼5åèBCDç ï¼åå¼èå´0~9999999.999ï¼åä½ä¸ºm3/hã |
| | | public Double totalAmount; //累计æµéï¼5åèBCDç ï¼åå¼èå´0~9999999999ï¼åä½ä¸ºm3ã |
| | | public Double lossAmount; //æå¤±æµéï¼5åèBCDç ï¼åå¼èå´0~9999999999ï¼åä½ä¸ºm3ã |
| | | public Double waterPress; //æ°´åï¼4åèBCDç ï¼åå¼èå´0~999999.99ï¼åä½ä¸ºKPaã |
| | | public Double batteryVolt;//èçµæ± çµå:4åèBCDç ï¼åå¼èå´0~99.99ï¼åä½ä¸ºVã |
| | | public Double sunVolt ;//太é³è½çµå:4åèBCDç ï¼åå¼èå´0~99.99ï¼åä½ä¸ºVã |
| | | public Integer signal; //ä¿¡å·å¼ºåº¦ï¼1åèBCDç ï¼åå¼èå´0~99ã |
| | | public String rtuDt ;//æ§å¶å¨æ¶é |
| | | public DataAlarmVo alarmVo ;//æ¥è¦ |
| | | public DataStateVo stateVo ;//ç¶æ |
| | | public String toString(){ |
| | | StringBuilder sb = new StringBuilder() ; |
| | | sb.append(" ç»ç«¯èªæ¥å®æ¶æ°æ®:\n"); |
| | | sb.append(" ç¬æ¶æµéï¼"); |
| | | sb.append(instantAmount==null?"":instantAmount); |
| | | sb.append("\n"); |
| | | sb.append(" 累计æµéï¼"); |
| | | sb.append(totalAmount==null?"":totalAmount); |
| | | sb.append("\n"); |
| | | sb.append(" æå¤±æµéï¼"); |
| | | sb.append(lossAmount==null?"":lossAmount); |
| | | sb.append("\n"); |
| | | sb.append(" æ°´åï¼"); |
| | | sb.append(waterPress==null?"":waterPress); |
| | | sb.append("\n"); |
| | | sb.append(" èçµæ± çµåï¼"); |
| | | sb.append(batteryVolt==null?"":batteryVolt); |
| | | sb.append("\n"); |
| | | sb.append(" 太é³è½çµåï¼"); |
| | | sb.append(sunVolt==null?"":sunVolt); |
| | | sb.append("\n"); |
| | | sb.append(" ä¿¡å·å¼ºåº¦ï¼"); |
| | | sb.append(signal==null?"":signal); |
| | | sb.append("\n"); |
| | | sb.append(" æ§å¶å¨æ¶éï¼"); |
| | | sb.append(rtuDt==null?"":rtuDt); |
| | | sb.append("\n"); |
| | | sb.append(alarmVo==null?"":alarmVo.toString()); |
| | | sb.append("\n"); |
| | | sb.append(stateVo==null?"":stateVo.toString()); |
| | | sb.append("\n"); |
| | | |
| | | return sb.toString() ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class DataStateVo { |
| | | public Byte idCard ;// èçµæ± çµå |
| | | public Byte work;//å·¥ä½ç¶æ |
| | | public Byte valve ;//éé¨ |
| | | |
| | | public String toString(){ |
| | | StringBuilder str = new StringBuilder() ; |
| | | str.append(" ç¶æ:\n"); |
| | | str.append(" IC å¡åè½ï¼"); |
| | | str.append(idCard==null?"":(idCard==1?"ææ":"æ æ")); |
| | | str.append("\n"); |
| | | str.append(" å·¥ä½ç¶æï¼"); |
| | | str.append(work ==null?"":(work==1?"å¯å¨":"忢")); |
| | | str.append("\n"); |
| | | str.append(" éé¨ï¼"); |
| | | str.append(valve==null?"":(valve==1?"æå¼":"å
³é")); |
| | | return str.toString() ; |
| | | } |
| | | } |
| | |
| | | |
| | | public DataCd02Vo dataCd02Vo;//é¾è·¯æ£æµ |
| | | public DataCdC0Vo dataCdC0Vo;//ç»ç«¯èªæ¥å®æ¶æ°æ® |
| | | public DataCd83OpenVo dataCd83OpenVo;//å¼éèªæ¥ |
| | | public DataCd83CloseVo dataCd83CloseVo;//å
³éèªæ¥ |
| | | public DataCd84Vo dataCd84Vo;//å¼é工使¥ |
| | | |
| | | public String dt ;//éä¿¡ä¸é´ä»¶äº§ç忥æ¶é´(yyyy-MM-dd hh:mm:ss) |
| | | |
| | |
| | | public MidResult[] createCommand(Boolean isLowPower, Command command, Object... params) { |
| | | String rtuAddr = command.getRtuAddr() ; |
| | | if(rtuAddr == null){ |
| | | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1_0_0.protocolName, null, "严éé误ï¼å½ä»¤ä¸IMEIå·ä¸ºç©ºï¼ä¸è½æå»ºä»»ä½å½ä»¤ï¼", null))} ; |
| | | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1_0_0.protocolName, null, "严éé误ï¼å½ä»¤ä¸Rtuå°å为空ï¼ä¸è½æå»ºä»»ä½å½ä»¤ï¼", null))} ; |
| | | } |
| | | try { |
| | | String commandCode = command.getCode() ; |
| | |
| | | public static final byte P_Head_Byte = (byte)0x68 ; |
| | | public static final byte P_Tail_Byte = (byte)0x16 ; |
| | | |
| | | public static final byte P_Default_mode = (byte)0x0F ;//é»è®¤å·¥ä½æ¨¡å¼ |
| | | |
| | | public static final String P_Head_Hex = "68" ; |
| | | public static final String P_Tail_Hex = "16" ; |
| | | |
| | |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | import com.dy.common.util.ByteUtilUnsigned; |
| | | import com.dy.common.util.CRC8_for_2_0; |
| | | import com.dy.common.util.DateTime; |
| | | |
| | | @AnnotationCodeDown(ifAny={ |
| | | CodeV1_0_1.cd_06 |
| | | }) |
| | | public class Cd_02_Down implements CodeParse { |
| | | |
| | | //private static Logger log = LogManager.getLogger(Cd_XY_Down.class); |
| | | //private static Logger log = LogManager.getLogger(Cd_02_Down.class); |
| | | |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback) throws Exception { |
| | |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.protocolName = para.protocolName ;//åè®®åç§° |
| | | midRs.rtuAddr = para.rtuAddr ;//IMEIå·ï¼çµä¿¡å¹³å°è®¾å¤IMEIï¼ |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtuå°åï¼çµä¿¡å¹³å°è®¾å¤IMEIï¼ |
| | | midRs.commandId = para.commandId ;//å½ä»¤IDï¼åèµ·å½ä»¤ç客æ·ç«¯(web端)çæï¼ä»¥å¹é
å½ä»¤ç»æ |
| | | midRs.downCode = para.commandCode ;//ä¸è¡å½ä»¤åè½ç ; |
| | | midRs.downBuffer = bs ;//ä¸è¡å½ä»¤æ°æ® |
| | |
| | | } |
| | | /** |
| | | * æé ä¸è¡æ°æ® |
| | | * @param para |
| | | * @return |
| | | * @throws Exception |
| | | * @param para åæ° |
| | | * @return åèæ°ç» |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public byte[] doParse(ParseParamsForDownV1_0_1 para) throws Exception { |
| | | CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1() ; |
| | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0) ; |
| | | |
| | | String rtuAddr = para.rtuAddr ; |
| | | String rtuAddr1 = rtuAddr.substring(0, 6) ; |
| | | String rtuAddr2 = rtuAddr.substring(6) ; |
| | | |
| | | index++ ; |
| | | ByteUtil.string2BCD_BE(bsHead, rtuAddr1, index) ; |
| | | index += 3 ; |
| | | |
| | | Integer rtuAddr2Int = Integer.parseInt(rtuAddr2) ; |
| | | ByteUtilUnsigned.short2Bytes_BE(bsHead, rtuAddr2Int.shortValue(), index); |
| | | index += 2 ; |
| | | GlCreate.createRtuAddr(para.rtuAddr, bsHead, index); |
| | | index += 5 ; |
| | | |
| | | ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; |
| | | |
| | | byte[] bs = new byte[7] ; |
| | | bs[0] = (byte)0xF2 ; |
| | | ByteUtil.string2BCD_BE(bs, DateTime.yyMMddhhmmss(), 1) ; |
| | | bs[0] = (byte)0xF2 ;//æ°æ®åï¼ 1 个åèï¼F0 ç»å½ï¼ F1 éåºç»å½ï¼F2 å¨çº¿ä¿æã |
| | | GlCreate.createTp(bs, 1); |
| | | |
| | | bytes = ByteUtil.bytesMerge(bsHead, bs) ; |
| | | |
| | | int len = bytes.length + ProtocolConstantV206V1_0_0.lenTail; |
| | | bytes[ProtocolConstantV206V1_0_0.dataLenIndex] = (byte)len ; |
| | | GlCreate.createLen(bytes);//é¿åº¦æ¾åèæ°ç»ä¸ |
| | | |
| | | int crc = new CRC8_for_2_0().CRC8(bytes, ProtocolConstantV206V1_0_0.ctrlIndex, bytes.length -1) ; |
| | | bs = new byte[ProtocolConstantV206V1_0_0.lenTail] ; |
| | | bs[0] = (byte)crc ; |
| | | bs[1] = ProtocolConstantV206V1_0_0.P_Tail_Byte ; |
| | | bytes = ByteUtil.bytesMerge(bytes, bs) ; |
| | | bytes = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | |
| | | return bytes ; |
| | | } |
| | |
| | | @SuppressWarnings("unused") |
| | | public class Cd_02_Up implements CodeParse{ |
| | | |
| | | private static Logger log = LogManager.getLogger(Cd_02_Up.class); |
| | | private static final Logger log = LogManager.getLogger(Cd_02_Up.class); |
| | | |
| | | /** |
| | | * åæä¸è¡æ°æ® |
| | |
| | | |
| | | MidResultFromRtu midRs = new MidResultFromRtu() ; |
| | | midRs.protocolName = para.protocolName ;//åè®®åç§° |
| | | midRs.rtuAddr = para.rtuAddr ;//IMEIå· |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtuå°å |
| | | midRs.upCode = para.upCode ;//ä¸è¡æ°æ®ä¸çåè½ç |
| | | midRs.upHex = para.upHex ;//ä¸è¡æ°æ®åå
è¿å¶å½¢å¼ |
| | | midRs.upBuffer = para.upBuffer ;//ä¸è¡æ°æ®åèæ°ç» |
| | |
| | | |
| | | MidResultToRtu confirmCommand = new MidResultToRtu() ; |
| | | confirmCommand.protocolName = para.protocolName ;//åè®®åç§° |
| | | confirmCommand.rtuAddr = para.rtuAddr ;//IMEIå· |
| | | confirmCommand.rtuAddr = para.rtuAddr ;//Rtuå°å |
| | | confirmCommand.commandId = Command.defaultId ;//å½ä»¤IDï¼åèµ·å½ä»¤ç客æ·ç«¯(web端)çæï¼ä»¥å¹é
å½ä»¤ç»æ |
| | | confirmCommand.downCode = confirmComCode ;//ä¸è¡å½ä»¤åè½ç ; |
| | | confirmCommand.downBuffer = data ;//ä¸è¡å½ä»¤æ°æ® |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse; |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.CodeV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.CommonV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ParseParamsForDownV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | |
| | | @AnnotationCodeDown(ifAny={ |
| | | CodeV1_0_1.cd_83 |
| | | }) |
| | | public class Cd_83_Down implements CodeParse { |
| | | |
| | | //private static Logger log = LogManager.getLogger(Cd_C0_Down.class); |
| | | |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback) throws Exception { |
| | | ParseParamsForDownV1_0_1 para = (ParseParamsForDownV1_0_1) params ; |
| | | byte[] bs = this.doParse(para) ; |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.protocolName = para.protocolName ;//åè®®åç§° |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtuå°åï¼çµä¿¡å¹³å°è®¾å¤IMEIï¼ |
| | | midRs.commandId = para.commandId ;//å½ä»¤IDï¼åèµ·å½ä»¤ç客æ·ç«¯(web端)çæï¼ä»¥å¹é
å½ä»¤ç»æ |
| | | midRs.downCode = para.commandCode ;//ä¸è¡å½ä»¤åè½ç ; |
| | | midRs.downBuffer = bs ;//ä¸è¡å½ä»¤æ°æ® |
| | | midRs.downBufHex = ByteUtil.bytes2Hex(bs, true) ;//ä¸è¡å½ä»¤æ°æ®åå
è¿å¶å½¢å¼ |
| | | midRs.hasResponse = true ;//æ¯å¦æåºç |
| | | midRs.maxSendTimes = null ;//å½ä»¤æå¤§å鿬¡æ°(彿¶ä¸å°åºçæ¶ï¼å°éå)ï¼å¦æä¸è®¾ç½®ï¼å½ä»¤ç¼åå¨è¿è¡è¡¥å
设置 |
| | | midRs.isCachForOffLine = true ;//RTUä¸å¨çº¿ï¼å½ä»¤æ¯å¦ç¼åï¼ä½åèæ¶ä¸ºtrue |
| | | |
| | | //对RTUä¸è¡æ°æ®çåºç |
| | | midRs.hasResponse = false ;//æ¯å¦æåºç |
| | | midRs.maxSendTimes = 1 ;//对RTUä¸è¡æ°æ®åºçï¼æä»¥åªéå䏿¬¡ |
| | | if(isLowPower != null && isLowPower.booleanValue()){ |
| | | //ä½åèæ¶ |
| | | midRs.isQuickSend = true ; |
| | | } |
| | | |
| | | return new MidResult[]{midRs} ; |
| | | } |
| | | |
| | | /** |
| | | * æé ä¸è¡æ°æ® |
| | | * @param para åæ° |
| | | * @return åèæ°ç» |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public byte[] doParse(ParseParamsForDownV1_0_1 para) throws Exception { |
| | | CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1() ; |
| | | byte[] bytes ; |
| | | byte[] bsHead = new byte[ProtocolConstantV206V1_0_0.lenHead2Code] ; |
| | | byte index = 0 ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = 0 ;//帧é¿åº¦ |
| | | |
| | | index++ ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0) ; |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr(para.rtuAddr, bsHead, index); |
| | | index += 5 ; |
| | | |
| | | ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; |
| | | |
| | | byte[] bs = new byte[7] ; |
| | | //ç¡®è®¤å¸§çæ°æ®åç¨äºé¥æµç»ç«¯å·¥ä½æ¨¡å¼ç确认æè½¬æ¢ãæ°æ®ä¸º 1 个åè HEXï¼00H æ¶é¥æµç» |
| | | //端å¨å
¼å®¹å·¥ä½ç¶æï¼ 01H æ¶é¥æµç»ç«¯å¨èªæ¥å·¥ä½ç¶æï¼ 02H æ¶é¥æµç»ç«¯å¨æ¥è¯¢/åºçå·¥ä½ |
| | | //ç¶æï¼ 03H æ¶é¥æµç»ç«¯å¨è°è¯/ç»´ä¿®ç¶æã |
| | | bs[0] = ProtocolConstantV206V1_0_0.P_Default_mode;//æ°æ®å |
| | | GlCreate.createTp(bs, 1); |
| | | |
| | | bytes = ByteUtil.bytesMerge(bsHead, bs) ; |
| | | |
| | | GlCreate.createLen(bytes);//é¿åº¦æ¾åèæ°ç»ä¸ |
| | | |
| | | bytes = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | |
| | | return bytes ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse; |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlParse; |
| | | import com.dy.common.util.ByteUtil; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | @AnnotationCodeUp(ifAny={ |
| | | CodeV1_0_1.cd_83 |
| | | }) |
| | | @SuppressWarnings("unused") |
| | | public class Cd_83_Up implements CodeParse { |
| | | |
| | | private static final Logger log = LogManager.getLogger(Cd_83_Up.class); |
| | | |
| | | /** |
| | | * åæä¸è¡æ°æ® |
| | | */ |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback)throws Exception { |
| | | ParseParamsForUpV1_0_1 para = (ParseParamsForUpV1_0_1)params ; |
| | | int bsLen = new CommonV1_0_1().parseDataLen(para.upBuffer) ; |
| | | if(bsLen > 0){ |
| | | this.doParse(para.upBuffer, |
| | | bsLen, |
| | | para.upCode, |
| | | para.data) ; |
| | | } |
| | | log.info("åæä¸è¡æ°æ®<" + CodeV1_0_1.getCodeName(para.upCode) + " RTUå°å=" + para.rtuAddr + ">:\n" + para.data.toString()); |
| | | |
| | | MidResultFromRtu midRs = new MidResultFromRtu() ; |
| | | midRs.protocolName = para.protocolName ;//åè®®åç§° |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtuå°å |
| | | midRs.upCode = para.upCode ;//ä¸è¡æ°æ®ä¸çåè½ç |
| | | midRs.upHex = para.upHex ;//ä¸è¡æ°æ®åå
è¿å¶å½¢å¼ |
| | | midRs.upBuffer = para.upBuffer ;//ä¸è¡æ°æ®åèæ°ç» |
| | | midRs.data = para.data ;//è§£æåçæ°æ® |
| | | |
| | | midRs.reportOrResponse_trueOrFalse = true ;//主å¨ä¸æ¥ |
| | | |
| | | String confirmComCode = CodeV1_0_1.cd_C0 ; |
| | | ParseParamsForDownV1_0_1 downCpParams = new ParseParamsForDownV1_0_1() ; |
| | | downCpParams.setValue( |
| | | ProtocolConstantV206V1_0_0.protocolName, |
| | | para.rtuAddr, |
| | | Command.defaultId, |
| | | confirmComCode, |
| | | null, |
| | | null); |
| | | //æé åºç |
| | | byte[] data = new Cd_83_Down().doParse(downCpParams) ; |
| | | |
| | | MidResultToRtu confirmCommand = new MidResultToRtu() ; |
| | | confirmCommand.protocolName = para.protocolName ;//åè®®åç§° |
| | | confirmCommand.rtuAddr = para.rtuAddr ;//Rtuå°å |
| | | confirmCommand.commandId = Command.defaultId ;//å½ä»¤IDï¼åèµ·å½ä»¤ç客æ·ç«¯(web端)çæï¼ä»¥å¹é
å½ä»¤ç»æ |
| | | confirmCommand.downCode = confirmComCode ;//ä¸è¡å½ä»¤åè½ç ; |
| | | confirmCommand.downBuffer = data ;//ä¸è¡å½ä»¤æ°æ® |
| | | confirmCommand.downBufHex = ByteUtil.bytes2Hex(data, true) ;//ä¸è¡å½ä»¤æ°æ®åå
è¿å¶å½¢å¼ |
| | | confirmCommand.hasResponse = false ;//æ¯å¦æåºç |
| | | confirmCommand.maxSendTimes = 1 ;//å½ä»¤æå¤§å鿬¡æ°(彿¶ä¸å°åºçæ¶ï¼å°éå2次)ï¼å¦æä¸è®¾ç½®ï¼å½ä»¤ç¼åå¨è¿è¡è¡¥å
设置 |
| | | confirmCommand.isSendFirst = true ;//确认å½ä»¤ï¼ä¼å
åé |
| | | confirmCommand.isCachForOffLine = false ;//RTUä¸å¨çº¿ï¼å½ä»¤æ¯å¦ç¼å |
| | | |
| | | callback.callback(midRs.reportOrResponse_trueOrFalse); |
| | | return new MidResult[]{midRs, confirmCommand} ; |
| | | } |
| | | /** |
| | | * æ§è¡åæ |
| | | * @param bs åèæ°ç» |
| | | * @param bsLen åèé¿åº¦ï¼æ»å
é¿ï¼å
æ¬å
头åå
å°¾ï¼ |
| | | * @param dataCode åè½ç |
| | | * @param data æ°æ® |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | protected void doParse(byte[] bs, int bsLen, String dataCode, Data data) throws Exception { |
| | | short index = ProtocolConstantV206V1_0_0.dataIndex ; |
| | | byte opType = bs[ProtocolConstantV206V1_0_0.dataIndex]; |
| | | if(opType == 1 || opType == 3 || opType == 8){ |
| | | this.doParseOpen(opType, bs, bsLen, dataCode, data); |
| | | }else{ |
| | | this.doParseClose(opType, bs, bsLen, dataCode, data); |
| | | } |
| | | } |
| | | private void doParseOpen(byte opType, byte[] bs, int bsLen, String dataCode, Data data) throws Exception { |
| | | DataV1_0_1 dV1 = (DataV1_0_1)data.getSubData() ; |
| | | DataCd83OpenVo cdData = new DataCd83OpenVo() ; |
| | | dV1.dataCd83OpenVo = cdData ; |
| | | |
| | | cdData.type = opType ; |
| | | |
| | | short index = ProtocolConstantV206V1_0_0.dataIndex + 1 ; |
| | | //累计æµéï¼5åèBCDç ï¼åå¼èå´0~9999999999ï¼åä½ä¸ºm3ã |
| | | cdData.totalAmount = 0.0D ; |
| | | int tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt * 100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt * 10000.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt * 1000000.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt * 100000000.0 ; |
| | | |
| | | //ç¨æ°´æ·å·æ°æ®æ ¼å¼ï¼5åèBCDç ä½ä½å¨åé«ä½å¨åã |
| | | cdData.clientNum = ByteUtil.BCD2String_LE(bs, index, index + 4) ; |
| | | index += 5 ; |
| | | |
| | | //ICå¡å·æ ¼å¼ï¼4åèHEXç ä½ä½å¨åé«ä½å¨åã |
| | | cdData.clientNum = ByteUtil.bytesToHex(bs, index, index + 3) ; |
| | | index += 4 ; |
| | | |
| | | //ç¨æ°´æ·ä½é¢ï¼ç¨æ·ä½é¢4åèBCDç ï¼åå¼èå´0.00~999999.99ï¼åä½ä¸ºå
ã |
| | | cdData.remainMoney = 0.0D ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.remainMoney += tpInt/100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.remainMoney += tpInt; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.remainMoney += tpInt * 100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.remainMoney += tpInt * 10000.0 ; |
| | | |
| | | //ç¨æ°´æ·ç¨æ°´å¼å§æ¶é´ï¼6åèBCDç ï¼é¡ºåºæ¯å¹´ææ¥æ¶åç§ï¼å
¶ä¸å
Œ
å¹´=2000+å¹´ã |
| | | cdData.openDt = GlParse.parseTp(bs, index) ; |
| | | index += 6 ; |
| | | |
| | | //æ§å¶å¨æ¶é |
| | | cdData.rtuDt = GlParse.parseTp(bs, index) ; |
| | | //index += 6 ; |
| | | } |
| | | |
| | | private void doParseClose(byte opType, byte[] bs, int bsLen, String dataCode, Data data) throws Exception { |
| | | DataV1_0_1 dV1 = (DataV1_0_1)data.getSubData() ; |
| | | DataCd83CloseVo cdData = new DataCd83CloseVo() ; |
| | | dV1.dataCd83CloseVo = cdData ; |
| | | |
| | | cdData.type = opType ; |
| | | |
| | | short index = ProtocolConstantV206V1_0_0.dataIndex + 1 ; |
| | | //累计æµéï¼5åèBCDç ï¼åå¼èå´0~9999999999ï¼åä½ä¸ºm3ã |
| | | cdData.totalAmount = 0.0D ; |
| | | int tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt * 100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt * 10000.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt * 1000000.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt * 100000000.0 ; |
| | | |
| | | //ç¨æ°´æ·å·æ°æ®æ ¼å¼ï¼5åèBCDç ä½ä½å¨åé«ä½å¨åã |
| | | cdData.clientNum = ByteUtil.BCD2String_LE(bs, index, index + 4) ; |
| | | index += 5 ; |
| | | |
| | | //ICå¡å·æ ¼å¼ï¼4åèHEXç ä½ä½å¨åé«ä½å¨åã |
| | | cdData.clientNum = ByteUtil.bytesToHex(bs, index, index + 3) ; |
| | | index += 4 ; |
| | | |
| | | //ç¨æ°´æ·ä½é¢ï¼ç¨æ·ä½é¢4åèBCDç ï¼åå¼èå´0.00~999999.99ï¼åä½ä¸ºå
ã |
| | | cdData.remainMoney = 0.0D ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.remainMoney += tpInt/100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.remainMoney += tpInt; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.remainMoney += tpInt * 100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.remainMoney += tpInt * 10000.0 ; |
| | | |
| | | //ç¨æ°´æ·ç¨æ°´å¼å§æ¶é´ï¼6åèBCDç ï¼é¡ºåºæ¯å¹´ææ¥æ¶åç§ï¼å
¶ä¸å
Œ
å¹´=2000+å¹´ã |
| | | cdData.openDt = GlParse.parseTp(bs, index) ; |
| | | index += 6 ; |
| | | |
| | | //ç¨æ°´æ·ç¨æ°´ç»ææ¶é´ï¼6åèBCDç ï¼é¡ºåºæ¯å¹´ææ¥æ¶åç§ï¼å
¶ä¸å
Œ
å¹´=2000+å¹´ã |
| | | cdData.closeDt = GlParse.parseTp(bs, index) ; |
| | | index += 6 ; |
| | | |
| | | //ç¨æ°´æ·æ¬æ¬¡ç¨æ°´éï¼ç´¯è®¡æµé5åèBCDç ï¼åå¼èå´0~9999999999ï¼åä½ä¸ºm3ã |
| | | cdData.thisAmount = 0.0D ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.thisAmount += tpInt; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.thisAmount += tpInt * 100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.thisAmount += tpInt * 10000.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.thisAmount += tpInt * 1000000.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.thisAmount += tpInt * 100000000.0 ; |
| | | |
| | | //ç¨æ°´æ·æ¬æ¬¡æ¶è´¹éé¢ï¼ç¨æ·ä½é¢4åèBCDç ï¼åå¼èå´0.00~999999.99ï¼åä½ä¸ºå
ã |
| | | cdData.thisMoney = 0.0D ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.thisMoney += tpInt/100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.thisMoney += tpInt; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.thisMoney += tpInt * 100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.thisMoney += tpInt * 10000.0 ; |
| | | |
| | | //ç¨æ°´æ·æ¬æ¬¡ç¨æ°´æ¶é¿ï¼ç¨æ°´æ¶é¿2åèBCDç ï¼åå¼èå´0~9999ï¼åä½ä¸ºåéã |
| | | cdData.thisTime = 0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.thisTime += tpInt; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.thisTime += tpInt * 100 ; |
| | | |
| | | //æ§å¶å¨æ¶é |
| | | cdData.rtuDt = GlParse.parseTp(bs, index) ; |
| | | //index += 6 ; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse; |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.CodeV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.CommonV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ParseParamsForDownV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | |
| | | @AnnotationCodeDown(ifAny={ |
| | | CodeV1_0_1.cd_83 |
| | | }) |
| | | public class Cd_84_Down implements CodeParse { |
| | | |
| | | //private static Logger log = LogManager.getLogger(Cd_C0_Down.class); |
| | | |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback) throws Exception { |
| | | ParseParamsForDownV1_0_1 para = (ParseParamsForDownV1_0_1) params ; |
| | | byte[] bs = this.doParse(para) ; |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.protocolName = para.protocolName ;//åè®®åç§° |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtuå°åï¼çµä¿¡å¹³å°è®¾å¤IMEIï¼ |
| | | midRs.commandId = para.commandId ;//å½ä»¤IDï¼åèµ·å½ä»¤ç客æ·ç«¯(web端)çæï¼ä»¥å¹é
å½ä»¤ç»æ |
| | | midRs.downCode = para.commandCode ;//ä¸è¡å½ä»¤åè½ç ; |
| | | midRs.downBuffer = bs ;//ä¸è¡å½ä»¤æ°æ® |
| | | midRs.downBufHex = ByteUtil.bytes2Hex(bs, true) ;//ä¸è¡å½ä»¤æ°æ®åå
è¿å¶å½¢å¼ |
| | | midRs.hasResponse = true ;//æ¯å¦æåºç |
| | | midRs.maxSendTimes = null ;//å½ä»¤æå¤§å鿬¡æ°(彿¶ä¸å°åºçæ¶ï¼å°éå)ï¼å¦æä¸è®¾ç½®ï¼å½ä»¤ç¼åå¨è¿è¡è¡¥å
设置 |
| | | midRs.isCachForOffLine = true ;//RTUä¸å¨çº¿ï¼å½ä»¤æ¯å¦ç¼åï¼ä½åèæ¶ä¸ºtrue |
| | | |
| | | //对RTUä¸è¡æ°æ®çåºç |
| | | midRs.hasResponse = false ;//æ¯å¦æåºç |
| | | midRs.maxSendTimes = 1 ;//对RTUä¸è¡æ°æ®åºçï¼æä»¥åªéå䏿¬¡ |
| | | if(isLowPower != null && isLowPower.booleanValue()){ |
| | | //ä½åèæ¶ |
| | | midRs.isQuickSend = true ; |
| | | } |
| | | |
| | | return new MidResult[]{midRs} ; |
| | | } |
| | | |
| | | /** |
| | | * æé ä¸è¡æ°æ® |
| | | * @param para åæ° |
| | | * @return åèæ°ç» |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public byte[] doParse(ParseParamsForDownV1_0_1 para) throws Exception { |
| | | CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1() ; |
| | | byte[] bytes ; |
| | | byte[] bsHead = new byte[ProtocolConstantV206V1_0_0.lenHead2Code] ; |
| | | byte index = 0 ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = 0 ;//帧é¿åº¦ |
| | | |
| | | index++ ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0) ; |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr(para.rtuAddr, bsHead, index); |
| | | index += 5 ; |
| | | |
| | | ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; |
| | | |
| | | byte[] bs = new byte[7] ; |
| | | //ç¡®è®¤å¸§çæ°æ®åç¨äºé¥æµç»ç«¯å·¥ä½æ¨¡å¼ç确认æè½¬æ¢ãæ°æ®ä¸º 1 个åè HEXï¼00H æ¶é¥æµç» |
| | | //端å¨å
¼å®¹å·¥ä½ç¶æï¼ 01H æ¶é¥æµç»ç«¯å¨èªæ¥å·¥ä½ç¶æï¼ 02H æ¶é¥æµç»ç«¯å¨æ¥è¯¢/åºçå·¥ä½ |
| | | //ç¶æï¼ 03H æ¶é¥æµç»ç«¯å¨è°è¯/ç»´ä¿®ç¶æã |
| | | bs[0] = ProtocolConstantV206V1_0_0.P_Default_mode;//æ°æ®å |
| | | GlCreate.createTp(bs, 1); |
| | | |
| | | bytes = ByteUtil.bytesMerge(bsHead, bs) ; |
| | | |
| | | GlCreate.createLen(bytes);//é¿åº¦æ¾åèæ°ç»ä¸ |
| | | |
| | | bytes = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | |
| | | return bytes ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse; |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlParse; |
| | | import com.dy.common.util.ByteUtil; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | @AnnotationCodeUp(ifAny={ |
| | | CodeV1_0_1.cd_83 |
| | | }) |
| | | @SuppressWarnings("unused") |
| | | public class Cd_84_Up implements CodeParse { |
| | | |
| | | private static final Logger log = LogManager.getLogger(Cd_84_Up.class); |
| | | |
| | | /** |
| | | * åæä¸è¡æ°æ® |
| | | */ |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback)throws Exception { |
| | | ParseParamsForUpV1_0_1 para = (ParseParamsForUpV1_0_1)params ; |
| | | int bsLen = new CommonV1_0_1().parseDataLen(para.upBuffer) ; |
| | | if(bsLen > 0){ |
| | | this.doParse(para.upBuffer, |
| | | bsLen, |
| | | para.upCode, |
| | | para.data) ; |
| | | } |
| | | log.info("åæä¸è¡æ°æ®<" + CodeV1_0_1.getCodeName(para.upCode) + " RTUå°å=" + para.rtuAddr + ">:\n" + para.data.toString()); |
| | | |
| | | MidResultFromRtu midRs = new MidResultFromRtu() ; |
| | | midRs.protocolName = para.protocolName ;//åè®®åç§° |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtuå°å |
| | | midRs.upCode = para.upCode ;//ä¸è¡æ°æ®ä¸çåè½ç |
| | | midRs.upHex = para.upHex ;//ä¸è¡æ°æ®åå
è¿å¶å½¢å¼ |
| | | midRs.upBuffer = para.upBuffer ;//ä¸è¡æ°æ®åèæ°ç» |
| | | midRs.data = para.data ;//è§£æåçæ°æ® |
| | | |
| | | midRs.reportOrResponse_trueOrFalse = true ;//主å¨ä¸æ¥ |
| | | |
| | | String confirmComCode = CodeV1_0_1.cd_C0 ; |
| | | ParseParamsForDownV1_0_1 downCpParams = new ParseParamsForDownV1_0_1() ; |
| | | downCpParams.setValue( |
| | | ProtocolConstantV206V1_0_0.protocolName, |
| | | para.rtuAddr, |
| | | Command.defaultId, |
| | | confirmComCode, |
| | | null, |
| | | null); |
| | | //æé åºç |
| | | byte[] data = new Cd_84_Down().doParse(downCpParams) ; |
| | | |
| | | MidResultToRtu confirmCommand = new MidResultToRtu() ; |
| | | confirmCommand.protocolName = para.protocolName ;//åè®®åç§° |
| | | confirmCommand.rtuAddr = para.rtuAddr ;//Rtuå°å |
| | | confirmCommand.commandId = Command.defaultId ;//å½ä»¤IDï¼åèµ·å½ä»¤ç客æ·ç«¯(web端)çæï¼ä»¥å¹é
å½ä»¤ç»æ |
| | | confirmCommand.downCode = confirmComCode ;//ä¸è¡å½ä»¤åè½ç ; |
| | | confirmCommand.downBuffer = data ;//ä¸è¡å½ä»¤æ°æ® |
| | | confirmCommand.downBufHex = ByteUtil.bytes2Hex(data, true) ;//ä¸è¡å½ä»¤æ°æ®åå
è¿å¶å½¢å¼ |
| | | confirmCommand.hasResponse = false ;//æ¯å¦æåºç |
| | | confirmCommand.maxSendTimes = 1 ;//å½ä»¤æå¤§å鿬¡æ°(彿¶ä¸å°åºçæ¶ï¼å°éå2次)ï¼å¦æä¸è®¾ç½®ï¼å½ä»¤ç¼åå¨è¿è¡è¡¥å
设置 |
| | | confirmCommand.isSendFirst = true ;//确认å½ä»¤ï¼ä¼å
åé |
| | | confirmCommand.isCachForOffLine = false ;//RTUä¸å¨çº¿ï¼å½ä»¤æ¯å¦ç¼å |
| | | |
| | | callback.callback(midRs.reportOrResponse_trueOrFalse); |
| | | return new MidResult[]{midRs, confirmCommand} ; |
| | | } |
| | | /** |
| | | * æ§è¡åæ |
| | | * @param bs åèæ°ç» |
| | | * @param bsLen åèé¿åº¦ï¼æ»å
é¿ï¼å
æ¬å
头åå
å°¾ï¼ |
| | | * @param dataCode åè½ç |
| | | * @param data æ°æ® |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | protected void doParse(byte[] bs, int bsLen, String dataCode, Data data) throws Exception { |
| | | DataV1_0_1 dV1 = (DataV1_0_1)data.getSubData() ; |
| | | DataCd84Vo cdData = new DataCd84Vo() ; |
| | | dV1.dataCd84Vo = cdData ; |
| | | |
| | | short index = ProtocolConstantV206V1_0_0.dataIndex ; |
| | | //ç¨æ°´æ·å·æ°æ®æ ¼å¼ï¼5åèBCDç ä½ä½å¨åé«ä½å¨åã |
| | | cdData.clientNum = ByteUtil.BCD2String_LE(bs, index, index + 4) ; |
| | | index += 5 ; |
| | | |
| | | //ç¨æ°´æ·ä½é¢ï¼ç¨æ·ä½é¢4åèBCDç ï¼åå¼èå´0.00~999999.99ï¼åä½ä¸ºå
ã |
| | | cdData.remainMoney = 0.0D ; |
| | | int tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.remainMoney += tpInt/100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.remainMoney += tpInt; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.remainMoney += tpInt * 100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.remainMoney += tpInt * 10000.0 ; |
| | | |
| | | //累计æµéï¼5åèBCDç ï¼åå¼èå´0~9999999999ï¼åä½ä¸ºm3ã |
| | | cdData.totalAmount = 0.0D ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt * 100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt * 10000.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt * 1000000.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt * 100000000.0 ; |
| | | |
| | | //ç¬æ¶æµéï¼5åèBCDç ï¼åå¼èå´0~9999999.999ï¼åä½ä¸ºm3/hã |
| | | cdData.instantAmount = 0.0D ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.instantAmount += tpInt/1000.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.instantAmount += tpInt/10.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.instantAmount += tpInt * 10.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.instantAmount += tpInt * 1000.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.instantAmount += tpInt * 100000.0 ; |
| | | |
| | | //æ§å¶å¨æ¶é |
| | | cdData.rtuDt = GlParse.parseTp(bs, index) ; |
| | | //index += 6 ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse; |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.CodeV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.CommonV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ParseParamsForDownV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | |
| | | @AnnotationCodeDown(ifAny={ |
| | | CodeV1_0_1.cd_C0 |
| | | }) |
| | | public class Cd_C0_Down implements CodeParse { |
| | | |
| | | //private static Logger log = LogManager.getLogger(Cd_C0_Down.class); |
| | | |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback) throws Exception { |
| | | ParseParamsForDownV1_0_1 para = (ParseParamsForDownV1_0_1) params ; |
| | | byte[] bs = this.doParse(para) ; |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.protocolName = para.protocolName ;//åè®®åç§° |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtuå°åï¼çµä¿¡å¹³å°è®¾å¤IMEIï¼ |
| | | midRs.commandId = para.commandId ;//å½ä»¤IDï¼åèµ·å½ä»¤ç客æ·ç«¯(web端)çæï¼ä»¥å¹é
å½ä»¤ç»æ |
| | | midRs.downCode = para.commandCode ;//ä¸è¡å½ä»¤åè½ç ; |
| | | midRs.downBuffer = bs ;//ä¸è¡å½ä»¤æ°æ® |
| | | midRs.downBufHex = ByteUtil.bytes2Hex(bs, true) ;//ä¸è¡å½ä»¤æ°æ®åå
è¿å¶å½¢å¼ |
| | | midRs.hasResponse = true ;//æ¯å¦æåºç |
| | | midRs.maxSendTimes = null ;//å½ä»¤æå¤§å鿬¡æ°(彿¶ä¸å°åºçæ¶ï¼å°éå)ï¼å¦æä¸è®¾ç½®ï¼å½ä»¤ç¼åå¨è¿è¡è¡¥å
设置 |
| | | midRs.isCachForOffLine = true ;//RTUä¸å¨çº¿ï¼å½ä»¤æ¯å¦ç¼åï¼ä½åèæ¶ä¸ºtrue |
| | | |
| | | //对RTUä¸è¡æ°æ®çåºç |
| | | midRs.hasResponse = false ;//æ¯å¦æåºç |
| | | midRs.maxSendTimes = 1 ;//对RTUä¸è¡æ°æ®åºçï¼æä»¥åªéå䏿¬¡ |
| | | if(isLowPower != null && isLowPower.booleanValue()){ |
| | | //ä½åèæ¶ |
| | | midRs.isQuickSend = true ; |
| | | } |
| | | |
| | | return new MidResult[]{midRs} ; |
| | | } |
| | | |
| | | /** |
| | | * æé ä¸è¡æ°æ® |
| | | * @param para åæ° |
| | | * @return åèæ°ç» |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public byte[] doParse(ParseParamsForDownV1_0_1 para) throws Exception { |
| | | CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1() ; |
| | | byte[] bytes ; |
| | | byte[] bsHead = new byte[ProtocolConstantV206V1_0_0.lenHead2Code] ; |
| | | byte index = 0 ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = 0 ;//帧é¿åº¦ |
| | | |
| | | index++ ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0) ; |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr(para.rtuAddr, bsHead, index); |
| | | index += 5 ; |
| | | |
| | | ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; |
| | | |
| | | byte[] bs = new byte[7] ; |
| | | //ç¡®è®¤å¸§çæ°æ®åç¨äºé¥æµç»ç«¯å·¥ä½æ¨¡å¼ç确认æè½¬æ¢ãæ°æ®ä¸º 1 个åè HEXï¼00H æ¶é¥æµç» |
| | | //端å¨å
¼å®¹å·¥ä½ç¶æï¼ 01H æ¶é¥æµç»ç«¯å¨èªæ¥å·¥ä½ç¶æï¼ 02H æ¶é¥æµç»ç«¯å¨æ¥è¯¢/åºçå·¥ä½ |
| | | //ç¶æï¼ 03H æ¶é¥æµç»ç«¯å¨è°è¯/ç»´ä¿®ç¶æã |
| | | bs[0] = ProtocolConstantV206V1_0_0.P_Default_mode;//æ°æ®å |
| | | GlCreate.createTp(bs, 1); |
| | | |
| | | bytes = ByteUtil.bytesMerge(bsHead, bs) ; |
| | | |
| | | GlCreate.createLen(bytes);//é¿åº¦æ¾åèæ°ç»ä¸ |
| | | |
| | | bytes = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | |
| | | return bytes ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse; |
| | | |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlParse; |
| | | import com.dy.common.util.ByteUtil; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | @AnnotationCodeUp(ifAny={ |
| | | CodeV1_0_1.cd_C0 |
| | | }) |
| | | @SuppressWarnings("unused") |
| | | public class Cd_C0_Up implements CodeParse { |
| | | |
| | | private static final Logger log = LogManager.getLogger(Cd_C0_Up.class); |
| | | |
| | | /** |
| | | * åæä¸è¡æ°æ® |
| | | */ |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback)throws Exception { |
| | | ParseParamsForUpV1_0_1 para = (ParseParamsForUpV1_0_1)params ; |
| | | int bsLen = new CommonV1_0_1().parseDataLen(para.upBuffer) ; |
| | | if(bsLen > 0){ |
| | | this.doParse(para.upBuffer, |
| | | bsLen, |
| | | para.upCode, |
| | | para.data) ; |
| | | } |
| | | log.info("åæä¸è¡æ°æ®<" + CodeV1_0_1.getCodeName(para.upCode) + " RTUå°å=" + para.rtuAddr + ">:\n" + para.data.toString()); |
| | | |
| | | MidResultFromRtu midRs = new MidResultFromRtu() ; |
| | | midRs.protocolName = para.protocolName ;//åè®®åç§° |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtuå°å |
| | | midRs.upCode = para.upCode ;//ä¸è¡æ°æ®ä¸çåè½ç |
| | | midRs.upHex = para.upHex ;//ä¸è¡æ°æ®åå
è¿å¶å½¢å¼ |
| | | midRs.upBuffer = para.upBuffer ;//ä¸è¡æ°æ®åèæ°ç» |
| | | midRs.data = para.data ;//è§£æåçæ°æ® |
| | | |
| | | midRs.reportOrResponse_trueOrFalse = true ;//主å¨ä¸æ¥ |
| | | |
| | | String confirmComCode = CodeV1_0_1.cd_C0 ; |
| | | ParseParamsForDownV1_0_1 downCpParams = new ParseParamsForDownV1_0_1() ; |
| | | downCpParams.setValue( |
| | | ProtocolConstantV206V1_0_0.protocolName, |
| | | para.rtuAddr, |
| | | Command.defaultId, |
| | | confirmComCode, |
| | | null, |
| | | null); |
| | | //æé åºç |
| | | byte[] data = new Cd_02_Down().doParse(downCpParams) ; |
| | | |
| | | MidResultToRtu confirmCommand = new MidResultToRtu() ; |
| | | confirmCommand.protocolName = para.protocolName ;//åè®®åç§° |
| | | confirmCommand.rtuAddr = para.rtuAddr ;//Rtuå°å |
| | | confirmCommand.commandId = Command.defaultId ;//å½ä»¤IDï¼åèµ·å½ä»¤ç客æ·ç«¯(web端)çæï¼ä»¥å¹é
å½ä»¤ç»æ |
| | | confirmCommand.downCode = confirmComCode ;//ä¸è¡å½ä»¤åè½ç ; |
| | | confirmCommand.downBuffer = data ;//ä¸è¡å½ä»¤æ°æ® |
| | | confirmCommand.downBufHex = ByteUtil.bytes2Hex(data, true) ;//ä¸è¡å½ä»¤æ°æ®åå
è¿å¶å½¢å¼ |
| | | confirmCommand.hasResponse = false ;//æ¯å¦æåºç |
| | | confirmCommand.maxSendTimes = 1 ;//å½ä»¤æå¤§å鿬¡æ°(彿¶ä¸å°åºçæ¶ï¼å°éå2次)ï¼å¦æä¸è®¾ç½®ï¼å½ä»¤ç¼åå¨è¿è¡è¡¥å
设置 |
| | | confirmCommand.isSendFirst = true ;//确认å½ä»¤ï¼ä¼å
åé |
| | | confirmCommand.isCachForOffLine = false ;//RTUä¸å¨çº¿ï¼å½ä»¤æ¯å¦ç¼å |
| | | |
| | | callback.callback(midRs.reportOrResponse_trueOrFalse); |
| | | return new MidResult[]{midRs, confirmCommand} ; |
| | | } |
| | | /** |
| | | * æ§è¡åæ |
| | | * @param bs åèæ°ç» |
| | | * @param bsLen åèé¿åº¦ï¼æ»å
é¿ï¼å
æ¬å
头åå
å°¾ï¼ |
| | | * @param dataCode åè½ç |
| | | * @param data æ°æ® |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | protected void doParse(byte[] bs, int bsLen, String dataCode, Data data) throws Exception { |
| | | DataV1_0_1 dV1 = (DataV1_0_1)data.getSubData() ; |
| | | DataCdC0Vo cdData = new DataCdC0Vo() ; |
| | | dV1.dataCdC0Vo = cdData ; |
| | | |
| | | boolean hasWaterAmount = false ;//æ¯å¦ææµéæ°æ® |
| | | boolean hasWaterPress = false ;//æ¯å¦ææ°´åæ°æ® |
| | | boolean hasEleVolt = false ;//æ¯å¦æçµåæ°æ® |
| | | boolean hasSignal = false ;//æ¯å¦æä¿¡å·å¼ºåº¦æ°æ® |
| | | boolean hasAlarmStatus = false ;//æ¯å¦ææ°æ® |
| | | |
| | | short index = ProtocolConstantV206V1_0_0.dataIndex ; |
| | | |
| | | byte tmpBt1 = bs[index] ; |
| | | index++ ; |
| | | if(((tmpBt1 & 4) >> 2) == 1){ |
| | | hasWaterAmount = true ; |
| | | } |
| | | |
| | | byte tmpBt2 = bs[index] ; |
| | | index++ ; |
| | | if(((tmpBt2 & 0x10) >> 4) == 1){ |
| | | hasAlarmStatus = true ; |
| | | } |
| | | if(((tmpBt2 & 0x20) >> 5) == 1){ |
| | | hasWaterPress = true ; |
| | | } |
| | | if(((tmpBt2 & 0x40) >> 6) == 1){ |
| | | hasEleVolt = true ; |
| | | } |
| | | if(((tmpBt2 & 0x80) >> 7) == 1){ |
| | | hasSignal = true ; |
| | | } |
| | | |
| | | if(hasWaterAmount){ |
| | | //ç¬æ¶æµéï¼5åèBCDç ï¼åå¼èå´0~9999999.999ï¼åä½ä¸ºm3/hã |
| | | cdData.instantAmount = 0.0D ; |
| | | int tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.instantAmount += tpInt/1000.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.instantAmount += tpInt/10.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.instantAmount += tpInt * 10.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.instantAmount += tpInt * 1000.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.instantAmount += tpInt * 100000.0 ; |
| | | |
| | | //累计æµéï¼5åèBCDç ï¼åå¼èå´0~9999999999ï¼åä½ä¸ºm3ã |
| | | cdData.totalAmount = 0.0D ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt * 100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt * 10000.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt * 1000000.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.totalAmount += tpInt * 100000000.0 ; |
| | | |
| | | //æå¤±æµéï¼5åèBCDç ï¼åå¼èå´0~9999999999ï¼åä½ä¸ºm3ã |
| | | cdData.lossAmount = 0.0D ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.lossAmount += tpInt; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.lossAmount += tpInt * 100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.lossAmount += tpInt * 10000.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.lossAmount += tpInt * 1000000.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.lossAmount += tpInt * 100000000.0 ; |
| | | } |
| | | if(hasWaterPress){ |
| | | //æ°´åï¼4åèBCDç ï¼åå¼èå´0~999999.99ï¼åä½ä¸ºKPaã |
| | | cdData.waterPress = 0.0D ; |
| | | int tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.waterPress += tpInt/100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.waterPress += tpInt; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.waterPress += tpInt * 100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.waterPress += tpInt * 10000.0 ; |
| | | } |
| | | if(hasEleVolt){ |
| | | //çµæ± çµåï¼4åèBCDç ï¼åå¼èå´0~99.99ï¼åä½ä¸ºVã |
| | | cdData.batteryVolt = 0.0D ;//èçµæ± çµå |
| | | cdData.sunVolt = 0.0D ;//太é³è½çµå |
| | | int tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.batteryVolt += tpInt/100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.batteryVolt += tpInt; |
| | | //太é³è½çµåï¼4åèBCDç ï¼åå¼èå´0~99.99ï¼åä½ä¸ºVã |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.sunVolt += tpInt/100.0 ; |
| | | tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.sunVolt += tpInt; |
| | | } |
| | | if(hasSignal){ |
| | | //ä¿¡å·å¼ºåº¦ï¼1åèBCDç ï¼åå¼èå´0~99ã |
| | | cdData.signal = 0 ; |
| | | int tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; |
| | | index++ ; |
| | | cdData.signal += tpInt ; |
| | | } |
| | | if(hasAlarmStatus){ |
| | | //æ¥è¦æ°æ® |
| | | cdData.alarmVo = GlParse.parseAlarm(bs, index) ; |
| | | index += 2 ; |
| | | //ç¶ææ°æ® |
| | | cdData.stateVo = GlParse.parseState(bs, index) ; |
| | | index += 2 ; |
| | | } |
| | | cdData.rtuDt = GlParse.parseTp(bs, index) ; |
| | | |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse.global; |
| | | |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0; |
| | | import com.dy.common.util.ByteUtil; |
| | | import com.dy.common.util.ByteUtilUnsigned; |
| | | import com.dy.common.util.CRC8_for_2_0; |
| | | import com.dy.common.util.DateTime; |
| | | |
| | | public class GlCreate { |
| | | |
| | | public static void createRtuAddr(String rtuAddr, byte[] bs, int index) throws Exception { |
| | | String rtuAddr1 = rtuAddr.substring(0, 6) ; |
| | | String rtuAddr2 = rtuAddr.substring(6) ; |
| | | |
| | | index++ ; |
| | | ByteUtil.string2BCD_BE(bs, rtuAddr1, index) ; |
| | | index += 3 ; |
| | | |
| | | Integer rtuAddr2Int = Integer.parseInt(rtuAddr2) ; |
| | | ByteUtilUnsigned.short2Bytes_BE(bs, rtuAddr2Int.shortValue(), index); |
| | | } |
| | | |
| | | public static void createTp(byte[] bs, int index) throws Exception { |
| | | ByteUtil.string2BCD_BE(bs, DateTime.yyMMddhhmmss(), index) ; |
| | | } |
| | | |
| | | public static void createLen(byte[] bs) throws Exception { |
| | | int len = bs.length + ProtocolConstantV206V1_0_0.lenTail; |
| | | bs[ProtocolConstantV206V1_0_0.dataLenIndex] = (byte)len ; |
| | | } |
| | | |
| | | public static byte[] createCrcTail(byte[] bs) throws Exception { |
| | | int crc = new CRC8_for_2_0().CRC8(bs, ProtocolConstantV206V1_0_0.ctrlIndex, bs.length -1) ; |
| | | bs = new byte[ProtocolConstantV206V1_0_0.lenTail] ; |
| | | bs[0] = (byte)crc ; |
| | | bs[1] = ProtocolConstantV206V1_0_0.P_Tail_Byte ; |
| | | return ByteUtil.bytesMerge(bs, bs) ; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse.global; |
| | | |
| | | import com.dy.common.mw.protocol.p206V1_0_0.DataAlarmVo; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.DataStateVo; |
| | | import com.dy.common.util.ByteUtil; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | public class GlParse { |
| | | |
| | | private static final Logger log = LogManager.getLogger(GlParse.class); |
| | | |
| | | public static DataAlarmVo parseAlarm(byte[] bs, short index){ |
| | | DataAlarmVo avo = new DataAlarmVo() ; |
| | | byte b = bs[index] ; |
| | | index++ ; |
| | | avo.batteryVolt = (byte)(b & 0x2) ; |
| | | avo.loss = (byte)(b & 0x8) ; |
| | | avo.meter = (byte)(b & 0x20) ; |
| | | |
| | | b = bs[index] ; |
| | | avo.valve = (byte)(b & 0x20) ; |
| | | return avo ; |
| | | } |
| | | |
| | | public static DataStateVo parseState(byte[] bs, short index){ |
| | | DataStateVo avo = new DataStateVo() ; |
| | | byte b = bs[index] ; |
| | | index++ ; |
| | | avo.idCard = (byte)(b & 0x4) ; |
| | | avo.work = (byte)(b & 0x8) ; |
| | | avo.valve = (byte)(b & 0x20) ; |
| | | return avo ; |
| | | } |
| | | |
| | | public static String parseTp(byte[] bs, short index){ |
| | | String dt = "" ; |
| | | try{ |
| | | dt = dt + ByteUtil.BCD2String_BE(bs, index, index) ;//ç§ |
| | | index++ ; |
| | | dt = ByteUtil.BCD2String_BE(bs, index, index) + ":" + dt ;//å |
| | | index++ ; |
| | | dt = ByteUtil.BCD2String_BE(bs, index, index) + " " + dt ;//æ¶ |
| | | index++ ; |
| | | dt = ByteUtil.BCD2String_BE(bs, index, index) + "-" + dt ;//æ¥ |
| | | index++ ; |
| | | bs[index] = (byte)(bs[index] & 0x10); |
| | | dt = ByteUtil.BCD2String_BE(bs, index, index) + "-" + dt ;//æ |
| | | index++ ; |
| | | dt = "20" + ByteUtil.BCD2String_BE(bs, index, index) + "-" + dt ;//å¹´ |
| | | }catch (Exception e){ |
| | | log.error("è§£ææ§å¶å¨æ¶éæ¶å¼å¸¸ï¼" + e.getMessage(), e); |
| | | } |
| | | return dt ; |
| | | } |
| | | } |
| | |
| | | } |
| | | return new String(buf); |
| | | } |
| | | /** |
| | | * å°byte[]转æ¢ä¸º16è¿å¶å符串 |
| | | * |
| | | * @param bytes å¾
转æ¢byte[] |
| | | * @return è¿å 转æ¢åçå符串 |
| | | */ |
| | | public static String bytesToHex(byte[] bytes, int startIndex, int endIndex) { |
| | | byte[] bs = new byte[endIndex - startIndex + 1] ; |
| | | byte j = 0 ; |
| | | for(int i = startIndex; i <= endIndex; i++){ |
| | | bs[j++] = bytes[i] ; |
| | | } |
| | | //ä¸ä¸ªbyte为8ä½ï¼å¯ç¨ä¸¤ä¸ªåå
è¿å¶ä½æ è¯ |
| | | char[] buf = new char[bs.length * 2]; |
| | | int a = 0; |
| | | int index = 0; |
| | | for (byte b : bs) { // 使ç¨é¤ä¸åä½è¿è¡è½¬æ¢ |
| | | if (b < 0) { |
| | | a = 256 + b; |
| | | } else { |
| | | a = b; |
| | | } |
| | | |
| | | buf[index++] = HEX_CHAR[a / 16]; |
| | | buf[index++] = HEX_CHAR[a % 16]; |
| | | } |
| | | return new String(buf); |
| | | } |
| | | |
| | | /** |
| | | * å°16è¿å¶å符串转æ¢ä¸ºbyte[] |
New file |
| | |
| | | package com.dy.aceMw.server.busi.deal.dbSv; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | @Service |
| | | public class RtuSv { |
| | | } |
New file |
| | |
| | | springboot容å¨ä¸çServer bean |