| | |
| | | */ |
| | | public class TcpIoSessionAttrIdIsRtuAddr { |
| | | |
| | | public static final String sessionArrIdKey = "key_rtuAddr" ; //è¿ä¸ªkeyåå¨çæ¯IMEIå· |
| | | public static final String sessionArrIdKey = "key_rtuAddr" ; //è¿ä¸ªkeyåå¨çæ¯Rtuå°å |
| | | } |
| | |
| | | int onLineDataMinLength; |
| | | int headMinLength ; |
| | | |
| | | HashMap<String, AnnotationDriverVo> driverMap = ProtocolCach.getDriverMap() ; |
| | | HashMap<String, AnnotationPrefixedDataAvailableVo> prefixedDataAvailableMap = ProtocolCach.getPrefixedDataAvailableMap() ; |
| | | HashMap<String, AnnotationOnLineVo> onLineMap = ProtocolCach.getOnLineMap() ; |
| | | HashMap<String, AnnotationDriverVo> driverMap = ProtocolCache.getDriverMap() ; |
| | | HashMap<String, AnnotationPrefixedDataAvailableVo> prefixedDataAvailableMap = ProtocolCache.getPrefixedDataAvailableMap() ; |
| | | HashMap<String, AnnotationOnLineVo> onLineMap = ProtocolCache.getOnLineMap() ; |
| | | |
| | | for(String cName : classNames){ |
| | | String className = cName.substring(0, cName.lastIndexOf('.')) ; |
| | |
| | | * RTU å°å |
| | | */ |
| | | public String rtuAddr ; |
| | | |
| | | /** |
| | | * æ°´è¡¨å· |
| | | * åºç¨çµä¿¡å¹³å°æ¶ææ |
| | | */ |
| | | public String meterNo ; |
| | | |
| | | /** |
| | | * çµä¿¡å¹³å°ä¸ç产åIDï¼å½ä¸å¨çµä¿¡å¹³å°ä¸è¿è¡æ¶ï¼ä¸ºnull |
| | | * åºç¨çµä¿¡å¹³å°æ¶ææ |
| | | */ |
| | | public Integer productId ; |
| | | |
| | | /** |
| | | * çµä¿¡å¹³å°ä¸ç设å¤IDï¼å½ä¸å¨çµä¿¡å¹³å°ä¸è¿è¡æ¶ï¼ä¸ºnull |
| | | * åºç¨çµä¿¡å¹³å°æ¶ææ |
| | | */ |
| | | public String deviceId ; |
| | | |
| | | |
| | | /** |
| | | * å½ä»¤ç±»å:Rtuå½ä»¤ãéå¯¹çæ§ä¸é´ä»¶çå½ä»¤ |
| | | * ç±com.dy.common.mw.protocol.CommandTypeç±»å®ä¹ |
| | |
| | | public String toString(){ |
| | | String s = "å½ä»¤id=" + id + "\n" ; |
| | | s += (protocol == null ? "" : ("åè®®=" + protocol + "\n")); |
| | | s += (rtuAddr == null ? "" : ("IMEIå·=" + rtuAddr + "\n")); |
| | | s += (meterNo == null ? "" : ("水表å·=" + meterNo + "\n")); |
| | | if(productId != null){ |
| | | s += "çµä¿¡å¹³å°äº§åID=" + productId + "\n" ; |
| | | } |
| | | if(deviceId != null && !deviceId.trim().equals("")){ |
| | | s += "çµä¿¡å¹³å°è®¾å¤ID=" + deviceId + "\n" ; |
| | | } |
| | | s += (rtuAddr == null ? "" : ("Rtuå°å=" + rtuAddr + "\n")); |
| | | s += "å½ä»¤ç±»å=" + (type.equals(CommandType.innerCommand)?"å
é¨å½ä»¤":"ç»ç«¯å½ä»¤") + "\n" ; |
| | | s += (code == null ? "" : ("åè½ç =" + code + "\n")) ; |
| | | s += "è¿åä¸é´ä»¶å¯¹å½ä»¤å¤çç»æ=" + (noRtMwDealRes == null?"è¿å":(noRtMwDealRes?"ä¸è¿å":"è¿å") + "\n") ; |
| | |
| | | } |
| | | public void setProtocol(String protocol) { |
| | | this.protocol = protocol; |
| | | } |
| | | public String getMeterNo() { |
| | | return meterNo; |
| | | } |
| | | public void setMeterNo(String meterNo) { |
| | | this.meterNo = meterNo; |
| | | } |
| | | public Integer getProductId() { |
| | | return productId; |
| | | } |
| | | public void setProductId(Integer productId) { |
| | | this.productId = productId; |
| | | } |
| | | public String getDeviceId() { |
| | | return deviceId; |
| | | } |
| | | public void setDeviceId(String deviceId) { |
| | | this.deviceId = deviceId; |
| | | } |
| | | public String getType() { |
| | | return type; |
| | |
| | | |
| | | /** |
| | | * æ°æ®æ ¹ |
| | | * @author Administrator |
| | | * |
| | | */ |
| | | public class Data implements java.io.Serializable{ |
| | |
| | | |
| | | private String commandId ;//å½ä»¤IDï¼å¯è½ä¸ºnull |
| | | private String rtuAddr ;//ç»ç«¯å°å |
| | | private String meterNo ;//æ°´è¡¨å· |
| | | private String protocol ;//æ°æ®æå¯¹åºçåè®®åç§° |
| | | private String code ;//æ°æ®æå¯¹åºçåè½ç : |
| | | private Object subData ;//对åºå个åè½ç çå
·ä½æ°æ® |
| | |
| | | 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("æ°´è¡¨å· : ").append((meterNo==null?"":meterNo)).append("\n") ; |
| | | sb.append("Rtuå°å : ").append((rtuAddr==null?"":rtuAddr)).append("\n") ; |
| | | if(commandId != null){ |
| | | sb.append("å½ä»¤ID : ").append(commandId).append("\n") ; //å½ä»¤ID |
| | | } |
| | |
| | | public void setRtuAddr(String rtuAddr) { |
| | | this.rtuAddr = rtuAddr; |
| | | } |
| | | |
| | | public String getMeterNo() { |
| | | return meterNo; |
| | | } |
| | | public void setMeterNo(String meterNo) { |
| | | this.meterNo = meterNo; |
| | | } |
| | | |
| | | public String getCode() { |
| | | return code; |
| | | } |
| | |
| | | return codeParse ; |
| | | } |
| | | /** |
| | | * è§£æä¸è¡æ°æ® |
| | | * è§£æRTUä¸è¡æ°æ® |
| | | * @param isLowPower æ¯å¦å¨ä½åèç¯å¢ä¸è¿è¡ |
| | | * @param rtuAddr æ§å¶å¨å°å |
| | | * @param upBuffer åèæ°ç» |
| | |
| | | * @return MidResult[] |
| | | */ |
| | | public abstract MidResult[] parseData(Boolean isLowPower, String rtuAddr, byte[] upBuffer, String upHex, DriverParserDataCallback callback, Object... params) ; |
| | | /** |
| | | * è§£æçµä¿¡å¹³å°ä¸è¡æ°æ® |
| | | * @param isLowPower æ¯å¦å¨ä½åèç¯å¢ä¸è¿è¡ |
| | | * @param rtuAddr æ§å¶å¨å°å |
| | | * @param productId çµä¿¡å¹³å°äº§åIDï¼å½ä¸å¨çµä¿¡å¹³å°ä¸è¿è¡æ¶ï¼ä¸ºnull |
| | | * @param deviceId çµä¿¡å¹³å°è®¾å¤IDï¼å½ä¸å¨çµä¿¡å¹³å°ä¸è¿è¡æ¶ï¼ä¸ºnull |
| | | * @param upBuffer åèæ°ç» |
| | | * @param upHex åèæ°ç»16è¿å¶å½¢å¼ |
| | | * @param callback åè° |
| | | * @return MidResult[] |
| | | */ |
| | | public abstract MidResult[] parseData(Boolean isLowPower, String rtuAddr, Integer productId, String deviceId, byte[] upBuffer, String upHex, DriverParserDataCallback callback, Object... params) ; |
| | | |
| | | /** |
| | | * æé ä¸è¡æ°æ®ï¼å½ä»¤ï¼ |
| | |
| | | |
| | | /** |
| | | * è§£æä¸è¡æ°æ®ååè° |
| | | * @param rtuAddr ä¸è¡æ°æ®å议头ä¸çIMEIå· |
| | | * @param meterNo ä¸è¡æ°æ®å议头ä¸çæ°´è¡¨å· |
| | | * @param rtuAddr ä¸è¡æ°æ®å议头ä¸RtuAddr |
| | | * @param code ä¸è¡æ°æ® åè½ç |
| | | * @param upHex ä¸è¡æ°æ® |
| | | * @param reportOrResponse_trueOrFalse ä¸è¡æ°æ®æ¯ä¸»å¨ä¸æ¥è¿æ¯å½ä»¤ç»æ |
| | | * @param parseFail ä¸è¡æ°æ®è§£ææ¯å¦å¤±è´¥ |
| | | * @param rtuAddrInData ä¸è¡æ°æ®ä¸å¨åè®®æ°æ®ä¸çIMEIå·ï¼ |
| | | * @param meterNoInData ä¸è¡æ°æ®ä¸å¨åè®®æ°æ®ä¸ç水表å·ï¼ |
| | | * âä¿®æ¹RTUç»ç«¯ç®¡çé
ç½®åæ°âå½ä»¤çè¿åæ°æ®ï¼å
¶å议头ä¸çIMEIå·ä¸æ°æ®ä¸çIMEIå·ä¸ä¸æ ·ï¼ |
| | | * 妿RTUä¸è½å
³éç½ç»ï¼é£ä¹sessionCachä¸çIMEIå·æ»æ¯ç¨ä¿®æ¹åçIMEIå·ï¼ä½¿å¾ä»¥åä¸è¡æ°æ®çä¸è½æ¾å°ç¼åä¸çSession |
| | | * @param rtuAddrInData ä¸è¡æ°æ®ä¸å¨åè®®æ°æ®ä¸çRtuå°åï¼ |
| | | * âä¿®æ¹RTUç»ç«¯ç®¡çé
ç½®åæ°âå½ä»¤çè¿åæ°æ®ï¼å
¶å议头ä¸çRtuå°å䏿°æ®ä¸çRtuå°åä¸ä¸æ ·ï¼ |
| | | * 妿RTUä¸è½å
³éç½ç»ï¼é£ä¹sessionCachä¸çRtuå°åæ»æ¯ç¨ä¿®æ¹åçRtuå°åï¼ä½¿å¾ä»¥åä¸è¡æ°æ®çä¸è½æ¾å°ç¼åä¸çSession |
| | | */ |
| | | void callback(String rtuAddr, |
| | | String meterNo, |
| | | String code, |
| | | String code, |
| | | String upHex, |
| | | Boolean reportOrResponse_trueOrFalse, |
| | | boolean parseFail, |
| | | String rtuAddrInData, |
| | | String meterNoInData) ; |
| | | String rtuAddrInData) ; |
| | | } |
| | |
| | | } |
| | | |
| | | public String protocolName ;//åè®®åç§° |
| | | public String rtuAddr ;//IMEIå·ï¼æ³¨ærtuAddrå¯è½ä¸ºnull |
| | | public String meterNo ;//水表å·ï¼æ³¨æmeterNoå¯è½ä¸ºnull |
| | | public String rtuAddr ;//Rtuå°åï¼æ³¨ærtuAddrå¯è½ä¸ºnull |
| | | public String message ;//åºéæ¶æ¯ |
| | | public Exception e ;//å¼å¸¸ |
| | | |
| | | public MidResultError(String protocolName, String rtuAddr, String meterNo, String message, Exception e){ |
| | | public MidResultError(String protocolName, String rtuAddr, String message, Exception e){ |
| | | this.protocolName = protocolName ; |
| | | this.rtuAddr = rtuAddr ; |
| | | this.meterNo = meterNo ; |
| | | this.message = message ; |
| | | this.e = e ; |
| | | } |
| | |
| | | public String commandId ;//åéå½ä»¤çIDï¼å¦ææ¯å½ä»¤ç»æï¼å¹¶ä¸å¹é
äºä¸åå½ä»¤ï¼æ¤å¼ä¸ä¸ºç©º |
| | | |
| | | public String protocolName ;//åè®®åç§° |
| | | public String rtuAddr ;//IMEIå· |
| | | public String meterNo ;//æ°´è¡¨å· |
| | | public Integer productId ;//çµä¿¡å¹³å°äº§åIDï¼å½ä¸å¨çµä¿¡å¹³å°è¿è¡æ¶ï¼ä¸ºnull |
| | | public String deviceId ;//çµä¿¡å¹³å°è®¾å¤IDï¼å½ä¸å¨çµä¿¡å¹³å°è¿è¡æ¶ï¼ä¸ºnull |
| | | public String rtuAddr ;//Rtuå°å |
| | | public String upCode ;//ä¸è¡æ°æ®ä¸çåè½ç |
| | | public String upHex ;//ä¸è¡æ°æ®åå
è¿å¶å½¢å¼ |
| | | public byte[] upBuffer ;//ä¸è¡æ°æ®åèæ°ç» |
| | |
| | | } |
| | | |
| | | public String protocolName ;//åè®®åç§° |
| | | public String rtuAddr ;//IMEIå·(çµä¿¡å¹³å°IMEI) |
| | | public String meterNo ;//æ°´è¡¨å· |
| | | public Integer productId ;//çµä¿¡å¹³å°äº§åID |
| | | public String deviceId ;//çµä¿¡å¹³å°è®¾å¤ID |
| | | 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 meterNo ;//æ°´è¡¨å· |
| | | public String rtuAddr ;//Rtuå°å |
| | | public byte[] remoteData;//éè¦åRtuååçæ°æ® |
| | | public OnLineResult(){ |
| | | result = OnLineAction_fail ; |
| | | rtuAddr = null ; |
| | | meterNo = null ; |
| | | remoteData = null ; |
| | | } |
| | | } |
| | | |
| | | 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ååæ°æ® |
| | | |
| | |
| | | public class OnLineHandle { |
| | | |
| | | /** |
| | | * è§£æä¸çº¿æ°æ®ï¼å¾å°IMEIå· |
| | | * è§£æä¸çº¿æ°æ®ï¼å¾å°RtuAddr |
| | | * @param bs åèæ°ç» |
| | | * @return OnLine.OnLineResult |
| | | */ |
| | | public OnLine.OnLineResult parse(byte[] bs)throws Exception{ |
| | | OnLine.OnLineResult rs = null ; |
| | | HashMap<String, AnnotationOnLineVo> onLineMap = ProtocolCach.getOnLineMap() ; |
| | | HashMap<String, AnnotationOnLineVo> onLineMap = ProtocolCache.getOnLineMap() ; |
| | | Collection<AnnotationOnLineVo> set = onLineMap.values() ; |
| | | if(set.size() == 0){ |
| | | throw new Exception("å¤çä¸çº¿æ¶ï¼å¾å°çåè®®éå为空ã") ; |
| | |
| | | try{ |
| | | PrefixedDataAvailableStatus pds = null ; |
| | | |
| | | HashMap<String, AnnotationPrefixedDataAvailableVo> prefixedDataAvailableMap = ProtocolCach.getPrefixedDataAvailableMap() ; |
| | | HashMap<String, AnnotationPrefixedDataAvailableVo> prefixedDataAvailableMap = ProtocolCache.getPrefixedDataAvailableMap() ; |
| | | Collection<AnnotationPrefixedDataAvailableVo> set = prefixedDataAvailableMap.values() ; |
| | | if(set.size() == 0){ |
| | | throw new Exception("ä¸çº¿æ°æ®å®æ´æ§æ£æ¥æ¶ï¼å¾å°çåè®®å®æ´æ§æ£æ¥ç±»éå为空ã") ; |
| | | } |
| | | int prority = ProtocolConstant.firstPriority ; |
| | | int priority = ProtocolConstant.firstPriority ; |
| | | |
| | | while(true){ |
| | | Object[] objs = this.getClassObjAndAnnotationVo(prority, set) ; |
| | | Object[] objs = this.getClassObjAndAnnotationVo(priority, set) ; |
| | | PrefixedDataAvailable pda = (PrefixedDataAvailable)objs[0] ; |
| | | if(pda == null && prority == ProtocolConstant.firstPriority){ |
| | | throw new Exception("ä¸çº¿æ°æ®å®æ´æ§æ£æ¥æ¶ï¼æªå¾å°ä¼å
级为" + prority + "ä¸çº¿æ°æ®å®æ´æ§æ£æ¥ç±»ï¼") ; |
| | | if(pda == null && priority == ProtocolConstant.firstPriority){ |
| | | throw new Exception("ä¸çº¿æ°æ®å®æ´æ§æ£æ¥æ¶ï¼æªå¾å°ä¼å
级为" + priority + "ä¸çº¿æ°æ®å®æ´æ§æ£æ¥ç±»ï¼") ; |
| | | }else if(pda == null){ |
| | | //说æä¸çº¿æ°æ®å®æ´æ§æ£æ¥ç±»éåå·²ç»éåå®äºã |
| | | break ; |
| | |
| | | if(pds == null){ |
| | | //说æä¸æ¯å¯¹åºçåè®®æ°æ®ï¼éè¦å¦å¤çåè®®æ¥å¤çä¸çº¿ |
| | | //循ç¯ç»§ç» |
| | | prority++ ; |
| | | priority++ ; |
| | | }else{ |
| | | //åæ¢å¾ªç¯ï¼è¿åç»æ |
| | | break ; |
| | |
| | | try{ |
| | | PrefixedDataAvailableStatus pds = null ; |
| | | |
| | | HashMap<String, AnnotationPrefixedDataAvailableVo> prefixedDataAvailableMap = ProtocolCach.getPrefixedDataAvailableMap() ; |
| | | HashMap<String, AnnotationPrefixedDataAvailableVo> prefixedDataAvailableMap = ProtocolCache.getPrefixedDataAvailableMap() ; |
| | | Collection<AnnotationPrefixedDataAvailableVo> set = prefixedDataAvailableMap.values() ; |
| | | if(set.size() == 0){ |
| | | throw new Exception("ä¸çº¿æ°æ®å®æ´æ§æ£æ¥æ¶ï¼å¾å°çåè®®éå为空ã") ; |
New file |
| | |
| | | package com.dy.common.mw.protocol; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | public class ProtocolCache { |
| | | |
| | | //æ¬ç³»ç»ä¸ï¼Driverå¨å线ç¨ä¸è¿è¡ï¼æä»¥åªç¨ä¸ä¸ªå®ä¾ |
| | | private static final HashMap<String, Driver> drivers = new HashMap<>() ; |
| | | //注解ä¸å¤çç±»çæ å° |
| | | private static final HashMap<String, AnnotationDriverVo> driverMap = new HashMap<>() ; |
| | | private static final HashMap<String, AnnotationPrefixedDataAvailableVo> prefixedDataAvailableMap = new HashMap<>() ; |
| | | private static final HashMap<String, AnnotationOnLineVo> onLineMap = new HashMap<>() ; |
| | | |
| | | |
| | | /** |
| | | * å¨å线ç¨ç¯å¢ä¸è¿è¡ |
| | | * éè¿å议驱å¨çç±»åï¼å¾å°ç±»åä¾ |
| | | * @param protocolName åè®®åç§° |
| | | * @return é©±å¨ |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static Driver getDriver(String protocolName) throws Exception{ |
| | | Driver dri = drivers.get(protocolName); |
| | | if(dri == null){ |
| | | AnnotationDriverVo vo = driverMap.get(protocolName) ; |
| | | if(vo != null && vo.clazz != null){ |
| | | dri = (Driver)vo.clazz.getDeclaredConstructor().newInstance(); |
| | | //dri = (Driver)vo.clazz.newInstance() ; |
| | | drivers.put(protocolName, dri) ; |
| | | } |
| | | } |
| | | return dri ; |
| | | } |
| | | |
| | | /** |
| | | * å¾å°é©±å¨çæ°éï¼å³ä¸é´ä»¶æ¯æçåè®®æ°é |
| | | * @return 驱卿»æ° |
| | | */ |
| | | public static int driverCount(){ |
| | | if(drivers.size() == 0){ |
| | | return 0 ; |
| | | }else{ |
| | | return drivers.size() ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¾å°ç¬¬ä¸ä¸ªé©±å¨ |
| | | * @return é©±å¨ |
| | | */ |
| | | public static Driver getFirstDriver(){ |
| | | Driver dri = null ; |
| | | if(drivers.size() > 0){ |
| | | Map.Entry<String, Driver> ent = drivers.entrySet().iterator().next() ; |
| | | dri = ent.getValue(); |
| | | } |
| | | return dri ; |
| | | } |
| | | |
| | | /** |
| | | * å¾å°ææåè®®åç§° |
| | | * @return åè®®åç§°éå |
| | | */ |
| | | @SuppressWarnings("unused") |
| | | public static List<String> getProtocolList() { |
| | | return new ArrayList<>(driverMap.keySet()) ; |
| | | } |
| | | |
| | | protected static HashMap<String, AnnotationDriverVo> getDriverMap() { |
| | | return driverMap; |
| | | } |
| | | protected static HashMap<String, AnnotationPrefixedDataAvailableVo> getPrefixedDataAvailableMap() { |
| | | return prefixedDataAvailableMap; |
| | | } |
| | | protected static HashMap<String, AnnotationOnLineVo> getOnLineMap() { |
| | | return onLineMap; |
| | | } |
| | | |
| | | /* |
| | | public static void main(String[] args){ |
| | | HashMap<String, Integer> mp = new HashMap<>() ; |
| | | mp.put("a1", 1) ; |
| | | mp.put("a2", 2) ; |
| | | List<String> list = new ArrayList<>(mp.keySet()) ; |
| | | System.out.println(list); |
| | | } |
| | | */ |
| | | } |
| | |
| | | AnnotationScan.getIntance() ; |
| | | |
| | | //å个å议驱å¨ç±»æ«æèªå·±çåè½ç 注解 |
| | | HashMap<String, AnnotationDriverVo> drivers = ProtocolCach.getDriverMap() ; |
| | | HashMap<String, AnnotationDriverVo> drivers = ProtocolCache.getDriverMap() ; |
| | | Collection<String> colDrivers = drivers.keySet() ; |
| | | StringBuilder totalProtocols = new StringBuilder() ; |
| | | for(String protocolName : colDrivers){ |
| | |
| | | totalProtocols.append("ï¼") ; |
| | | } |
| | | totalProtocols.append(protocolName) ; |
| | | Driver dri = ProtocolCach.getDriver(protocolName) ; |
| | | Driver dri = ProtocolCache.getDriver(protocolName) ; |
| | | if(dri != null){ |
| | | dri.scanAnnotationCode(); |
| | | } |
| | |
| | | */ |
| | | @SuppressWarnings("unused") |
| | | public boolean isOnlyOneProtocol(){ |
| | | HashMap<String, AnnotationDriverVo> drivers = ProtocolCach.getDriverMap() ; |
| | | HashMap<String, AnnotationDriverVo> drivers = ProtocolCache.getDriverMap() ; |
| | | return drivers.size() == 1 ; |
| | | } |
| | | |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0; |
| | | |
| | | public class CodeV1_0_1 { |
| | | //åè½ç 为å符串ï¼åå
è¿å¶æ°æ® |
| | | 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_71 = "71" ;//æ¥è¯¢éé¨ç¶æ |
| | | |
| | | public static String getCodeName(String code) { |
| | | String name = (code.equals(cd_02) ? "é¾è·¯æ£æµ" : |
| | | (code.equals(cd_C0) ? "èªæ¥å®æ¶æ°æ®" : |
| | | (code.equals(cd_83) ? "å¼å
³éèªæ¥" : |
| | | (code.equals(cd_84) ? "å¼é工使¥" : |
| | | (code.equals(cd_71) ? "æ¥è¯¢éé¨ç¶æ" : |
| | | ""))))) ; |
| | | return name ; |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦ä¸ºææåè½ç |
| | | * @param code åè½ç |
| | | * @return æætrueï¼æ æfalse |
| | | */ |
| | | public static boolean isValid(String code){ |
| | | String name = getCodeName(code) ; |
| | | if(name != null && !name.equals("")){ |
| | | return true ; |
| | | } |
| | | return false ; |
| | | } |
| | | } |
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 DataCd02Vo { |
| | | |
| | | public String status ;//F0 ç»å½ï¼F1 éåºç»å½ï¼F2 å¨çº¿ä¿æ |
| | | |
| | | public String toString(){ |
| | | StringBuffer sb = new StringBuffer() ; |
| | | sb.append(" é¾è·¯æ£æµ : \n") ; |
| | | sb.append(" 请æ±ç¶æ : ") ; |
| | | sb.append(status == null?"":(status.equals("F0")?"ç»å½":(status.equals("F1")?"éåºç»å½":(status.equals("F2")?"å¨çº¿ä¿æ":status)))) ; |
| | | sb.append("\n") ; |
| | | return sb.toString() ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class DataCd71Vo { |
| | | |
| | | public Byte state ;//éé¨ç¶æç ï¼0ï¼éé¨å
³éç¶æï¼1ï¼é鍿å¼ç¶æï¼ |
| | | public String stateName ; |
| | | |
| | | public String toString(){ |
| | | StringBuilder sb = new StringBuilder() ; |
| | | sb.append(" æ¥è¯¢è®¾å¤éé¨ç¶æåºç:\n"); |
| | | sb.append(" éé¨ç¶æï¼"); |
| | | sb.append(state==null?"":state); |
| | | sb.append(stateName==null?"":("(" + stateName + ")")); |
| | | sb.append("\n"); |
| | | |
| | | return sb.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() ; |
| | | } |
| | | } |
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() ; |
| | | } |
| | | } |
| | |
| | | callback.callback(rtuAddr, upCode, upHex, reportOrResponse_trueOrFalse, isFail, rtuAddrInData); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æé ä¸è¡æ°æ®ï¼å½ä»¤ï¼ |
| | | * @param isLowPower æ¯å¦å¨ä½åèç¯å¢ä¸è¿è¡ |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0; |
| | | |
| | | import com.dy.common.mw.protocol.AnnotationOnLine; |
| | | import com.dy.common.mw.protocol.OnLine; |
| | | |
| | | @AnnotationOnLine( |
| | | protocolName = ProtocolConstantV206V1_0_0.protocolName, |
| | | priority = ProtocolConstantV206V1_0_0.priority) |
| | | @SuppressWarnings("unused") |
| | | public class OnLineV1_0_1 implements OnLine{ |
| | | |
| | | /** |
| | | * 对ä¸çº¿æ°æ®è¿è¡åæ |
| | | * @param upBuf ä¸è¡æ°æ® |
| | | * @return |
| | | */ |
| | | @Override |
| | | public OnLineResult parse(byte[] upBuf)throws Exception { |
| | | OnLineResult olr = new OnLineResult() ; |
| | | CommonV1_0_1 cp = new CommonV1_0_1() ; |
| | | Boolean flag = cp.isThisProtocolHead(upBuf) ; |
| | | if(flag == null){ |
| | | //åºé |
| | | olr.result = OnLine.OnLineAction_fail ; |
| | | olr.rtuAddr = null ; |
| | | }else if(!flag.booleanValue()){ |
| | | //䏿¯æ¬åè®®æ°æ® |
| | | olr.result = OnLine.OnLineAction_success_noMe ; |
| | | olr.rtuAddr = null ; |
| | | }else{ |
| | | //æ¯æ¬åè®®æ°æ® |
| | | olr.result = OnLine.OnLineAction_success ; |
| | | olr.rtuAddr = cp.parseRtuAddr(upBuf) ; |
| | | olr.protocolName = ProtocolConstantV206V1_0_0.protocolName ; |
| | | } |
| | | return olr; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0; |
| | | |
| | | import com.dy.common.mw.protocol.CodeParseParams; |
| | | |
| | | public class ParseParamsForDownV1_0_1 implements CodeParseParams{ |
| | | |
| | | public String protocolName ; |
| | | public String rtuAddr ;//æ§å¶å¨å°å |
| | | public String commandId ; |
| | | public String commandCode ; |
| | | public Object param ; |
| | | public Object attachment ; |
| | | |
| | | public ParseParamsForDownV1_0_1(){} |
| | | |
| | | public void clear(){ |
| | | this.protocolName = null ; |
| | | this.rtuAddr = null ; |
| | | this.commandId = null ; |
| | | this.commandCode = null ; |
| | | this.param = null ; |
| | | this.attachment = null ; |
| | | } |
| | | |
| | | public void setValue( |
| | | String protocolName, |
| | | String rtuAddr, |
| | | String commandId, |
| | | String commandCode, |
| | | Object param, |
| | | Object attachment ){ |
| | | this.protocolName = protocolName ; |
| | | this.rtuAddr = rtuAddr ; |
| | | this.commandId = commandId ; |
| | | this.commandCode = commandCode ; |
| | | this.param = param ; |
| | | this.attachment = attachment ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0; |
| | | |
| | | import com.dy.common.mw.protocol.CodeParseParams; |
| | | import com.dy.common.mw.protocol.Data; |
| | | |
| | | public class ParseParamsForUpV1_0_1 implements CodeParseParams{ |
| | | |
| | | public String protocolName ;//åè®®åç§° |
| | | public String rtuAddr ;//æ§å¶å¨å |
| | | public String upCode ;//ä¸è¡æ¥ææ°æ®ä¸çåè½ç |
| | | public String upHex ;//è¡æ¥ææ°æ®åå
è¿å¶å½¢å¼ |
| | | public byte[] upBuffer ;//è¡æ¥ææ°æ®åèæ°ç» |
| | | public Data data ;//è§£æåçæ°æ® |
| | | |
| | | public ParseParamsForUpV1_0_1(){} |
| | | |
| | | public void clear(){ |
| | | this.protocolName = null ; |
| | | this.rtuAddr = null ; |
| | | this.upCode = null ; |
| | | this.upHex = null ; |
| | | this.upBuffer = null ; |
| | | this.data = null ; |
| | | } |
| | | |
| | | public void setValue(String protocolName, |
| | | String rtuAddr, |
| | | String upCode, |
| | | String upHex, |
| | | byte[] upBuffer, |
| | | Data data){ |
| | | this.protocolName = protocolName ; |
| | | this.rtuAddr = rtuAddr ; |
| | | this.upCode = upCode ; |
| | | this.upHex = upHex ; |
| | | this.upBuffer = upBuffer ; |
| | | this.data = data ; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse; |
| | | |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.util.ByteUtil; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | import com.dy.common.mw.protocol.p206V1_0_0.*; |
| | | |
| | | @AnnotationCodeUp(ifAny={ |
| | | CodeV1_0_1.cd_02 |
| | | }) |
| | | @SuppressWarnings("unused") |
| | | public class Cd_02_Up implements CodeParse{ |
| | | |
| | | private static final Logger log = LogManager.getLogger(Cd_02_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 = para.upCode ; |
| | | 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.isCachForOffLine = false ;//RTUä¸å¨çº¿ï¼å½ä»¤æ¯å¦ç¼å |
| | | |
| | | confirmCommand.isSendFirst = true ;//确认å½ä»¤ï¼ä¼å
åé |
| | | if(isLowPower != null && isLowPower.booleanValue()){ |
| | | //ä½åèæ¶ï¼å°½å¿«åé |
| | | confirmCommand.isQuickSend = true ; |
| | | } |
| | | 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() ; |
| | | DataCd02Vo cdData = new DataCd02Vo() ; |
| | | dV1.dataCd02Vo = cdData ; |
| | | cdData.status = ByteUtil.bytes2Hex(bs, false, ProtocolConstantV206V1_0_0.dataIndex, 1) ; |
| | | } |
| | | } |
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 org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | @AnnotationCodeUp(ifAny={ |
| | | CodeV1_0_1.cd_71 |
| | | }) |
| | | @SuppressWarnings("unused") |
| | | public class Cd_71_Up implements CodeParse { |
| | | |
| | | private static final Logger log = LogManager.getLogger(Cd_71_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 = false ;//主å¨ä¸æ¥ |
| | | |
| | | callback.callback(midRs.reportOrResponse_trueOrFalse); |
| | | return new MidResult[]{midRs} ; |
| | | } |
| | | /** |
| | | * æ§è¡åæ |
| | | * @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() ; |
| | | DataCd71Vo cdData = new DataCd71Vo() ; |
| | | dV1.dataCd71Vo = cdData ; |
| | | cdData.state = bs[ProtocolConstantV206V1_0_0.dataIndex] ; |
| | | if(cdData.state == 0){ |
| | | cdData.stateName = "éé¨å
³é" ; |
| | | }else if(cdData.state == 1){ |
| | | cdData.stateName = "é鍿å¼" ; |
| | | }else{ |
| | | cdData.stateName = "æªç¥" ; |
| | | } |
| | | } |
| | | } |
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 = para.upCode ; |
| | | 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.isCachForOffLine = false ;//RTUä¸å¨çº¿ï¼å½ä»¤æ¯å¦ç¼å |
| | | |
| | | confirmCommand.isSendFirst = true ;//确认å½ä»¤ï¼ä¼å
åé |
| | | if(isLowPower != null && isLowPower.booleanValue()){ |
| | | //ä½åèæ¶ï¼å°½å¿«åé |
| | | confirmCommand.isQuickSend = true ; |
| | | } |
| | | |
| | | 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/100.0 ; |
| | | 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 ; |
| | | |
| | | //ç¨æ°´æ·æ¬æ¬¡æ¶è´¹éé¢ï¼ç¨æ·ä½é¢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.*; |
| | | 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_84 |
| | | }) |
| | | @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 = para.upCode ; |
| | | 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.isCachForOffLine = false ;//RTUä¸å¨çº¿ï¼å½ä»¤æ¯å¦ç¼å |
| | | |
| | | confirmCommand.isSendFirst = true ;//确认å½ä»¤ï¼ä¼å
åé |
| | | if(isLowPower != null && isLowPower.booleanValue()){ |
| | | //ä½åèæ¶ï¼å°½å¿«åé |
| | | confirmCommand.isQuickSend = true ; |
| | | } |
| | | |
| | | 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.*; |
| | | 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 = para.upCode ; |
| | | 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.isCachForOffLine = false ;//RTUä¸å¨çº¿ï¼å½ä»¤æ¯å¦ç¼å |
| | | |
| | | confirmCommand.isSendFirst = true ;//确认å½ä»¤ï¼ä¼å
åé |
| | | if(isLowPower != null && isLowPower.booleanValue()){ |
| | | //ä½åèæ¶ï¼å°½å¿«åé |
| | | confirmCommand.isQuickSend = true ; |
| | | } |
| | | |
| | | 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) ; |
| | | |
| | | } |
| | | } |
| | |
| | | public void start(UnitStartedCallbackInterface callback) throws Exception { |
| | | if(!started){ |
| | | started = true ; |
| | | if(confVo.enableThreadPool){ |
| | | TreadPoolFactory.initThreadPoolShort("çä»»å¡å·¥ä½çº¿ç¨æ± ", |
| | | this.confVo.short_maxThread, |
| | | this.confVo.short_minThread, |
| | | this.confVo.short_freeTimeout, |
| | | if(confVo.enableShortThreadPool) { |
| | | TreadPoolFactory.initThreadPoolShort("çä»»å¡å·¥ä½çº¿ç¨æ± ", |
| | | this.confVo.short_maxThread, |
| | | this.confVo.short_minThread, |
| | | this.confVo.short_freeTimeout, |
| | | this.confVo.short_busyTimeout); |
| | | TreadPoolFactory.initThreadPoolLong("é¿ä»»å¡å·¥ä½çº¿ç¨æ± ", |
| | | this.confVo.long_maxThread, |
| | | this.confVo.long_minThread, |
| | | this.confVo.long_freeTimeout, |
| | | this.confVo.long_busyTimeout); |
| | | |
| | | if(this.confVo.showStartInfo){ |
| | | System.out.println("çº¿ç¨æ± 模åæåå¯å¨"); |
| | | } |
| | | }else{ |
| | | System.out.println("ççº¿ç¨æ± é
ç½®ä¸å¯å¨"); |
| | | } |
| | | callback.call(null); |
| | | if(confVo.enableLongThreadPool) { |
| | | TreadPoolFactory.initThreadPoolLong("é¿ä»»å¡å·¥ä½çº¿ç¨æ± ", |
| | | this.confVo.long_maxThread, |
| | | this.confVo.long_minThread, |
| | | this.confVo.long_freeTimeout, |
| | | this.confVo.long_busyTimeout); |
| | | }else{ |
| | | System.out.println("é¿çº¿ç¨æ± é
ç½®ä¸å¯å¨"); |
| | | } |
| | | if(this.confVo.showStartInfo){ |
| | | System.out.println("çº¿ç¨æ± 模åæåå¯å¨"); |
| | | } |
| | | } |
| | | callback.call(null); |
| | | } |
| | | |
| | | @Override |
| | | public void stop(UnitStartedCallbackInterface callback) throws Exception { |
| | | public void stop(UnitStartedCallbackInterface callback) { |
| | | } |
| | | |
| | | |
| | | /* |
| | | public static void main(String[] args) throws Exception{ |
| | | SupportUnitConfigVo supVo = new SupportUnitConfigVo() ; |
| | | //ç工使¶é¿çº¿ç¨æ± ï¼çº¿ç¨è´è´£ç¨æ¶è¾ççå·¥ä½ä»»å¡ |
| | |
| | | public void setConfig(SupportUnitConfigVo configVo) { |
| | | this.configVo = configVo; |
| | | } |
| | | |
| | | |
| | | } |
| | | */ |
| | | } |
| | |
| | | package com.dy.common.mw.support; |
| | | |
| | | public class SupportUnitConfigVo { |
| | | |
| | | public boolean enableThreadPool ; |
| | | |
| | | public boolean enableShortThreadPool ; |
| | | |
| | | public boolean enableLongThreadPool ; |
| | | |
| | | //çä»»å¡çº¿ç¨æ± |
| | | public int short_maxThread ; |
| | |
| | | * å°åèæ°ç»åå¹¶å°åèæ°ç»ä¸ |
| | | * @param bGroup1 被åå¹¶æ°ç» |
| | | * @param bGroup2 åå¹¶æ°ç» |
| | | * @return åå¹¶åæ°ç» |
| | | * @return è¿å åå¹¶åæ°ç» |
| | | */ |
| | | public static byte[] bytesMerge(byte[] bGroup1, byte[] bGroup2){ |
| | | if(bGroup1 == null && bGroup2 == null){ |
| | |
| | | |
| | | /** |
| | | * 夿ææåèæ¯å¦ä¸º0xFF |
| | | * @param bs |
| | | * @param index |
| | | * @param len |
| | | * @return |
| | | * @throws Exception |
| | | * @param bs åèæ°ç» |
| | | * @param index 䏿 ä½ |
| | | * @param len é¿åº¦ |
| | | * @return è¿å è¿å |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static boolean bytesIsAll0xFF(byte[] bs, int index, int len)throws Exception { |
| | | int count = 0 ; |
| | |
| | | count++ ; |
| | | } |
| | | } |
| | | return count==len?true:false ; |
| | | return count == len; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * äºè¿å¶è½¬åè¿å¶æ° |
| | | * @param str |
| | | * @return |
| | | * @throws Exception |
| | | * @return è¿å |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static int binary2Int(String str) throws Exception { |
| | | int cnt=0; |
| | |
| | | return sum; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * åè转åäºè¿å¶ |
| | | * |
| | | * |
| | | * @param b byte |
| | | * @throws Exception |
| | | * @return String |
| | | * @throws Exception å¼å¸¸ |
| | | * @return è¿å String |
| | | */ |
| | | public static String byte2Binary(byte b) throws Exception { |
| | | int n = (b + 256) % 256 + 256; |
| | |
| | | } |
| | | /** |
| | | * åè转å8ä½äºè¿å¶ |
| | | * |
| | | * |
| | | * @param b |
| | | * byte |
| | | * @throws Exception |
| | | * @return String |
| | | * @throws Exception å¼å¸¸ |
| | | * @return è¿å String |
| | | */ |
| | | public static String byte2bit8Binary(byte b) throws Exception { |
| | | String s = byte2Binary(b); |
| | |
| | | } |
| | | return s; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * åèåbit |
| | | * @param b |
| | | * @param index |
| | | * @throws Exception |
| | | * @return String |
| | | * @param b |
| | | * @throws Exception å¼å¸¸ |
| | | * @return è¿å String |
| | | */ |
| | | public static byte[] getBit(byte b) throws Exception { |
| | | byte[] bs = new byte[8] ; |
| | |
| | | /** |
| | | * åèåbit |
| | | * @param b |
| | | * @param index |
| | | * @throws Exception |
| | | * @return String |
| | | * @param index 䏿 ä½ |
| | | * @throws Exception å¼å¸¸ |
| | | * @return è¿å String |
| | | */ |
| | | public static byte getBit(byte b, byte index) throws Exception { |
| | | if(index == 0){ |
| | |
| | | |
| | | /** |
| | | * ä¸ä¸ªåèè½¬æ£æ´æ° |
| | | * |
| | | * |
| | | * @param b |
| | | * byte |
| | | * @throws Exception |
| | | * @return String |
| | | * @throws Exception å¼å¸¸ |
| | | * @return è¿å String |
| | | */ |
| | | public static Short byte2PlusInt(byte b) throws Exception { |
| | | short v = b ; |
| | |
| | | return v ; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 大端模å¼ãæ°æ®ä½ä½å¨æ°ç»é«åèã |
| | | * double转æ¢byte |
| | | * @param bs byte[] |
| | | * @param bs åèæ°ç» byte[] |
| | | * @param value double doubleç±»åçåæ° |
| | | * @param from int |
| | | * @param from å¼å§ä½ int |
| | | */ |
| | | public static void double2Bytes_BE(byte[] bs, double value, int from)throws Exception { |
| | | boolean b = isOutOfArrLength(bs.length, (from - 1) + 8); |
| | |
| | | /** |
| | | * å°ç«¯æ¨¡å¼ãæ°æ®ä½ä½å¨æ°ç»ä½åèã |
| | | * double转æ¢byteï¼åèé¡ºåºæ¯åç |
| | | * @param bs byte[] |
| | | * @param bs åèæ°ç» byte[] |
| | | * @param value double doubleç±»åçåæ° |
| | | * @param from int |
| | | * @param from å¼å§ä½ int |
| | | */ |
| | | public static void double2Bytes_LE(byte[] bs, double value, int from)throws Exception { |
| | | boolean b = isOutOfArrLength(bs.length, (from - 1) + 8); |
| | |
| | | /** |
| | | * 大端模å¼ãæ°æ®ä½ä½å¨æ°ç»é«åèã |
| | | * byte转æ¢double |
| | | * @param bs byte[] |
| | | * @param from int |
| | | * @param bs åèæ°ç» byte[] |
| | | * @param from å¼å§ä½ int |
| | | */ |
| | | public static double bytes2Double_BE(byte[] bs, int from) throws Exception { |
| | | long l = bytes2Long_BE(bs, from); |
| | |
| | | /** |
| | | * å°ç«¯æ¨¡å¼ãæ°æ®ä½ä½å¨æ°ç»ä½åèã |
| | | * byte转æ¢doubleï¼åèé¡ºåºæ¯åç |
| | | * @param bs byte[] |
| | | * @param from int |
| | | * @param bs åèæ°ç» byte[] |
| | | * @param from å¼å§ä½ int |
| | | */ |
| | | public static double bytes2Double_LE(byte[] bs, int from) throws Exception { |
| | | long l = bytes2Long_LE(bs, from); |
| | |
| | | |
| | | /** |
| | | * å°ç«¯æ¨¡å¼ãæ°æ®ä½ä½å¨æ°ç»ä½åèã |
| | | * 转æ¢longå为byteæ°ç» |
| | | * 转æ¢longå为byteæ°ç» |
| | | * @value bs byte[] |
| | | * @value value long |
| | | * @value from int |
| | |
| | | boolean b = isOutOfArrLength(bs.length, (from - 1) + 8); |
| | | if (b) { |
| | | for (int i = 0; i < 8; i++) { |
| | | bs[from + i] = Long.valueOf(value & 0xff).byteValue(); |
| | | value = value >> 8; |
| | | bs[from + i] = Long.valueOf(value & 0xff).byteValue(); |
| | | value = value >> 8; |
| | | if(value == 0){ |
| | | break ; |
| | | } |
| | |
| | | throw new Exception("long2Bytesæ¶æ°ç»è¶ç"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 大端模å¼ãæ°æ®ä½ä½å¨æ°ç»é«åèã |
| | | * 8ä½åèæ°ç»è½¬æ¢ä¸ºé¿æ´å |
| | | * @param bs byte[] |
| | | * @return |
| | | * @param bs åèæ°ç» byte[] |
| | | * @return è¿å |
| | | */ |
| | | public static long bytes2Long_BE(byte[] bs) { |
| | | int len = bs.length ; |
| | |
| | | l = l | ls[i] ; |
| | | } |
| | | return l; |
| | | } |
| | | } |
| | | return 0L ; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 大端模å¼ãæ°æ®ä½ä½å¨æ°ç»é«åèã |
| | | * 8ä½åèæ°ç»è½¬æ¢ä¸ºé¿æ´å |
| | | * @param bs byte[] |
| | | * @param from int |
| | | * @return |
| | | * @param bs åèæ°ç» byte[] |
| | | * @param from å¼å§ä½ int |
| | | * @return è¿å |
| | | */ |
| | | public static long bytes2Long_BE(byte[] bs, int from) throws Exception { |
| | | boolean b = isOutOfArrLength(bs.length, (from - 1) + 8); |
| | |
| | | /** |
| | | * 大端模å¼ãæ°æ®ä½ä½å¨æ°ç»é«åèã |
| | | * 8ä½åèæ°ç»è½¬æ¢ä¸ºé¿æ´å |
| | | * @param bs byte[] |
| | | * @param from int |
| | | * @param bs åèæ°ç» byte[] |
| | | * @param from å¼å§ä½ int |
| | | * @param end int |
| | | * @return |
| | | * @return è¿å |
| | | */ |
| | | public static long bytes2Long_BE(byte[] bs, int from, int end) throws Exception { |
| | | boolean b = isOutOfArrLength(bs.length, end); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * å°ç«¯æ¨¡å¼ãæ°æ®ä½ä½å¨æ°ç»ä½åèã |
| | | * 8ä½åèæ°ç»è½¬æ¢ä¸ºé¿æ´å |
| | | * @param bs byte[] |
| | | * @return |
| | | * @param bs åèæ°ç» byte[] |
| | | * @return è¿å |
| | | */ |
| | | public static long bytes2Long_LE(byte[] bs) { |
| | | int len = bs.length ; |
| | |
| | | l = l | ls[i] ; |
| | | } |
| | | return l; |
| | | } |
| | | } |
| | | return 0L ; |
| | | } |
| | | |
| | | /** |
| | | * å°ç«¯æ¨¡å¼ãæ°æ®ä½ä½å¨æ°ç»ä½åèã |
| | | * 8ä½åèæ°ç»è½¬æ¢ä¸ºé¿æ´å |
| | | * @param bs byte[] |
| | | * @param from int |
| | | * @return |
| | | * 8ä½åèæ°ç»è½¬æ¢ä¸ºé¿æ´å |
| | | * @param bs åèæ°ç» byte[] |
| | | * @param from å¼å§ä½ int |
| | | * @return è¿å |
| | | */ |
| | | public static long bytes2Long_LE(byte[] bs, int from) throws Exception { |
| | | boolean b = isOutOfArrLength(bs.length, (from - 1) + 8); |
| | |
| | | /** |
| | | * å°ç«¯æ¨¡å¼ãæ°æ®ä½ä½å¨æ°ç»ä½åèã |
| | | * 8ä½åèæ°ç»è½¬æ¢ä¸ºé¿æ´å |
| | | * @param bs byte[] |
| | | * @param from int |
| | | * @param bs åèæ°ç» byte[] |
| | | * @param from å¼å§ä½ int |
| | | * @param end int |
| | | * @return |
| | | * @return è¿å |
| | | */ |
| | | public static long bytes2Long_LE(byte[] bs, int from, int end) throws Exception { |
| | | boolean b = isOutOfArrLength(bs.length, end); |
| | |
| | | /** |
| | | * 大端模å¼ãæ°æ®ä½ä½å¨æ°ç»é«åèã |
| | | * 4ä½åèæ°ç»è½¬æ¢ä¸ºæ´å |
| | | * @param b |
| | | * @return |
| | | * @param bs åèæ°ç» |
| | | * @param from å¼å§ä½ |
| | | * @return è¿å |
| | | */ |
| | | public static int bytes2Int_BE(byte[] bs, int from) throws Exception { |
| | | boolean b = isOutOfArrLength(bs.length, (from - 1) + 4); |
| | |
| | | throw new Exception("byte2Intæ¶æ°ç»è¶ç"); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * å°ç«¯æ¨¡å¼ãæ°æ®ä½ä½å¨æ°ç»ä½åèã |
| | | * 4ä½åèæ°ç»è½¬æ¢ä¸ºæ´åï¼åèé¡ºåºæ¯åç |
| | | * @param b |
| | | * @return |
| | | * @param bs åèæ°ç» åèæ°ç» |
| | | * @return è¿å |
| | | */ |
| | | public static int bytes2Int_LE(byte[] bs, int from) throws Exception { |
| | | boolean b = isOutOfArrLength(bs.length, (from - 1) + 4); |
| | |
| | | throw new Exception("byte2Intæ¶æ°ç»è¶ç"); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 大端模å¼ãæ°æ®ä½ä½å¨æ°ç»é«åèã |
| | |
| | | /** |
| | | * 大端模å¼ãæ°æ®ä½ä½å¨æ°ç»é«åèã |
| | | * 2ä½åèæ°ç»è½¬æ¢ä¸ºçæ´å |
| | | * @param b |
| | | * @return |
| | | * @param bs åèæ°ç» åèæ°ç» |
| | | * @return è¿å |
| | | */ |
| | | public static short bytes2Short_BE(byte[] bs, int from) throws Exception { |
| | | boolean b = isOutOfArrLength(bs.length, (from - 1) + 2); |
| | | if (b) { |
| | | int s = 0; |
| | | int s0 = bs[from + 0] ; |
| | | int s0 = bs[from + 0] ; |
| | | int s1 = bs[from + 1] ; |
| | | |
| | | // s1ä¸å |
| | |
| | | /** |
| | | * å°ç«¯æ¨¡å¼ãæ°æ®ä½ä½å¨æ°ç»ä½åèã |
| | | * 2ä½åèæ°ç»è½¬æ¢ä¸ºçæ´åï¼åèé¡ºåºæ¯åç |
| | | * @param b |
| | | * @return |
| | | * @param bs åèæ°ç» åèæ°ç» |
| | | * @return è¿å |
| | | */ |
| | | public static short bytes2Short_LE(byte[] bs, int from) throws Exception { |
| | | boolean b = isOutOfArrLength(bs.length, (from - 1) + 2); |
| | | if (b) { |
| | | int s = 0; |
| | | int s0 = bs[from + 0] ; |
| | | int s0 = bs[from + 0] ; |
| | | int s1 = bs[from + 1] ; |
| | | |
| | | // s0ä¸å |
| | |
| | | } |
| | | /** |
| | | * å符å°ä¸åèè½¬æ¢ |
| | | * |
| | | * |
| | | * @value bs byte[] |
| | | * @value ch char charç±»åçåæ° |
| | | * @value index int |
| | | * @return |
| | | * @return è¿å |
| | | */ |
| | | public static void char2Bytes(byte[] bs, char ch, int index)throws Exception { |
| | | boolean b = isOutOfArrLength(bs.length, index); |
| | |
| | | |
| | | /** |
| | | * ä¸åè转æ¢ä¸ºå符 |
| | | * |
| | | * @param b |
| | | * @param bs åèæ°ç» åèæ°ç» |
| | | * @value index int |
| | | * @return |
| | | * @return è¿å |
| | | */ |
| | | public static char bytes2Char(byte[] bs, int index) throws Exception { |
| | | boolean b = isOutOfArrLength(bs.length, index); |
| | |
| | | |
| | | /** |
| | | * åç¬¦ä¸²åæ°å转æbyte |
| | | * |
| | | * |
| | | * @param s |
| | | * @return |
| | | * @throws Exception |
| | | * @return è¿å |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static byte string2byte(String s) throws Exception { |
| | | int n = 0; |
| | | int n ; |
| | | try { |
| | | n = Integer.parseInt(s); |
| | | } catch (Exception e) { |
| | |
| | | * @value bs byte[] |
| | | * @value str String |
| | | * @value from int |
| | | * @return |
| | | * @return è¿å |
| | | * @throws java.io.UnsupportedEncodingException |
| | | */ |
| | | public static int string2Bytes_BE(byte[] bs, String str, int from, int end)throws Exception { |
| | |
| | | * @value bs byte[] |
| | | * @value str String |
| | | * @value from int |
| | | * @return |
| | | * @return è¿å |
| | | * @throws java.io.UnsupportedEncodingException |
| | | */ |
| | | public static int string2Bytes_LE(byte[] bs, String str, int from, int end)throws Exception { |
| | |
| | | * @value bs byte[] |
| | | * @value str String |
| | | * @value from int |
| | | * @return |
| | | * @return è¿å |
| | | * @throws java.io.UnsupportedEncodingException |
| | | */ |
| | | public static int string2Bytes_BE(byte[] bs, String str, int from)throws Exception { |
| | |
| | | * @value bs byte[] |
| | | * @value str String |
| | | * @value from int |
| | | * @return |
| | | * @return è¿å |
| | | * @throws java.io.UnsupportedEncodingException |
| | | */ |
| | | public static int string2Bytes_LE(byte[] bs, String str, int from)throws Exception { |
| | |
| | | |
| | | /** |
| | | * 夿æ°ç»ä¸æ æ¯å¦è¶ç |
| | | * |
| | | * |
| | | * @value bsLength æ°ç»æ»é¿åº¦ |
| | | * @value toSite æ°ç»åç§»é |
| | | * @return |
| | | * @return è¿å |
| | | */ |
| | | private static boolean isOutOfArrLength(int bsLength, int toSite) { |
| | | if (bsLength > toSite) { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * åèæ°ç»è½¬æ¢æåå
è¿å¶çå符串 |
| | | * |
| | | * @param b byte[] |
| | | * åèæ°ç»è½¬æ¢æåå
è¿å¶çå符串 |
| | | * |
| | | * @param src byte[] |
| | | * @param hasBlank 16è¿å¶æ¯å¦ç¨ç©ºæ ¼åé |
| | | * @return String |
| | | * @return è¿å String |
| | | */ |
| | | public static String bytes2Hex(byte[] src, boolean hasBlank){ |
| | | StringBuilder stringBuilder = new StringBuilder(""); |
| | | if (src == null || src.length <= 0) { |
| | | return null; |
| | | } |
| | | for (int i = 0; i < src.length; i++) { |
| | | int v = src[i] & 0xFF; |
| | | String str = Integer.toHexString(v); |
| | | if (str.length() < 2) { |
| | | public static String bytes2Hex(byte[] src, boolean hasBlank){ |
| | | StringBuilder stringBuilder = new StringBuilder(""); |
| | | if (src == null || src.length <= 0) { |
| | | return null; |
| | | } |
| | | for (int i = 0; i < src.length; i++) { |
| | | int v = src[i] & 0xFF; |
| | | String str = Integer.toHexString(v); |
| | | if (str.length() < 2) { |
| | | str = "0" + str; |
| | | } |
| | | } |
| | | if (hasBlank) { |
| | | if (i == 0) { |
| | | stringBuilder.append(str); |
| | | stringBuilder.append(str); |
| | | } else { |
| | | stringBuilder.append(" " + str); |
| | | stringBuilder.append(" " + str); |
| | | } |
| | | } else { |
| | | stringBuilder.append(str); |
| | | stringBuilder.append(str); |
| | | } |
| | | } |
| | | } |
| | | return stringBuilder.toString().toUpperCase(Locale.US); |
| | | } |
| | | } |
| | | /** |
| | | * åèæ°ç»è½¬æ¢æåå
è¿å¶çå符串 |
| | | * |
| | | * @param b byte[] |
| | | * åèæ°ç»è½¬æ¢æåå
è¿å¶çå符串 |
| | | * |
| | | * @param src byte[] |
| | | * @param hasBlank 16è¿å¶æ¯å¦ç¨ç©ºæ ¼åé |
| | | * @param from |
| | | * @param len |
| | | * @return String |
| | | * @param from å¼å§ä½ |
| | | * @param len é¿åº¦ |
| | | * @return è¿å String |
| | | */ |
| | | public static String bytes2Hex(byte[] src, boolean hasBlank, int from, int len){ |
| | | if (src == null || src.length <= 0 || src.length < from + len) { |
| | | return null; |
| | | } |
| | | public static String bytes2Hex(byte[] src, boolean hasBlank, int from, int len){ |
| | | if (src == null || src.length <= 0 || src.length < from + len) { |
| | | return null; |
| | | } |
| | | byte[] bb = new byte[len]; |
| | | for (int i = 0 ; i < len; i++) { |
| | | bb[i] = src[from + i]; |
| | | } |
| | | return bytes2Hex(bb, hasBlank) ; |
| | | } |
| | | /** |
| | | } |
| | | /** |
| | | * åå
è¿å¶è½¬åèæ°ç» |
| | | * @param hexString the hex string |
| | | * @return byte[] |
| | | */ |
| | | public static byte[] hex2Bytes(String hex) { |
| | | if (hex == null || hex.equals("")) { |
| | | return null; |
| | | } |
| | | hex = hex.toUpperCase(Locale.ENGLISH); |
| | | int length = hex.length() / 2; |
| | | char[] hexChars = hex.toCharArray(); |
| | | byte[] d = new byte[length]; |
| | | for (int i = 0; i < length; i++) { |
| | | int pos = i * 2; |
| | | d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1])); |
| | | } |
| | | return d; |
| | | } |
| | | /** |
| | | * @param hex the hex string |
| | | * @return è¿å byte[] |
| | | */ |
| | | public static byte[] hex2Bytes(String hex) { |
| | | if (hex == null || hex.equals("")) { |
| | | return null; |
| | | } |
| | | hex = hex.toUpperCase(Locale.ENGLISH); |
| | | int length = hex.length() / 2; |
| | | char[] hexChars = hex.toCharArray(); |
| | | byte[] d = new byte[length]; |
| | | for (int i = 0; i < length; i++) { |
| | | int pos = i * 2; |
| | | d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1])); |
| | | } |
| | | return d; |
| | | } |
| | | /** |
| | | * åå
è¿å¶è½¬åèæ°ç» |
| | | * @param hexString the hex string |
| | | * @return byte[] |
| | | */ |
| | | public static int hex2Bytes(String hex, byte[] bs, int fromIndex) { |
| | | if (hex == null || hex.equals("")) { |
| | | return fromIndex; |
| | | } |
| | | hex = hex.toUpperCase(Locale.ENGLISH); |
| | | int length = hex.length() / 2; |
| | | char[] hexChars = hex.toCharArray(); |
| | | byte[] d = new byte[length]; |
| | | for (int i = 0; i < length; i++) { |
| | | int pos = i * 2; |
| | | d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1])); |
| | | * @param hex the hex string |
| | | * @return è¿å byte[] |
| | | */ |
| | | public static int hex2Bytes(String hex, byte[] bs, int fromIndex) { |
| | | if (hex == null || hex.equals("")) { |
| | | return fromIndex; |
| | | } |
| | | hex = hex.toUpperCase(Locale.ENGLISH); |
| | | int length = hex.length() / 2; |
| | | char[] hexChars = hex.toCharArray(); |
| | | byte[] d = new byte[length]; |
| | | for (int i = 0; i < length; i++) { |
| | | int pos = i * 2; |
| | | d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1])); |
| | | } |
| | | for(int i = 0 ; i < d.length; i++){ |
| | | bs[fromIndex++] = d[i] ; |
| | | } |
| | | return fromIndex ; |
| | | } |
| | | return fromIndex ; |
| | | } |
| | | |
| | | private static final char[] HEX_CHAR = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; |
| | | /** |
| | | * å°byte[]转æ¢ä¸º16è¿å¶å符串 |
| | | * |
| | | * @param bytes å¾
转æ¢byte[] |
| | | * @return 转æ¢åçå符串 |
| | | * @return è¿å 转æ¢åçå符串 |
| | | */ |
| | | public static String bytesToHex(byte[] bytes) { |
| | | //ä¸ä¸ªbyte为8ä½ï¼å¯ç¨ä¸¤ä¸ªåå
è¿å¶ä½æ è¯ |
| | |
| | | } |
| | | 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[] |
| | | * |
| | | * @param str å¾
转æ¢å符串 |
| | | * @return 转æ¢åçbyte[] |
| | | * @return è¿å 转æ¢åçbyte[] |
| | | */ |
| | | public static byte[] hexToBytes(String str) { |
| | | if (str == null || "".equals(str.trim())) { |
| | |
| | | /** |
| | | * Convert char to byte |
| | | * @param c char |
| | | * @return byte |
| | | * @return è¿å byte |
| | | */ |
| | | private static byte charToByte(char c) { |
| | | return (byte) "0123456789ABCDEF".indexOf(c); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 大端模å¼ãæ°æ®ä½ä½å¨æ°ç»é«åèã |
| | | * æ´å½¢è½¬æBCDç¼ç |
| | | * @param l |
| | | * @return |
| | | * @param i |
| | | * @return è¿å |
| | | */ |
| | | public static byte[] int2BCD_BE(int i)throws Exception { |
| | | String str = "" + i; |
| | |
| | | /** |
| | | * å°ç«¯æ¨¡å¼ãæ°æ®ä½ä½å¨æ°ç»ä½åèã |
| | | * æ´å½¢è½¬æBCDç¼ç ï¼åèé¡ºåºæ¯åç |
| | | * @param l |
| | | * @return |
| | | * @param i |
| | | * @return è¿å |
| | | */ |
| | | public static byte[] int2BCD_LE(int i)throws Exception { |
| | | String str = "" + i; |
| | |
| | | * 大端模å¼ãæ°æ®ä½ä½å¨æ°ç»é«åèã |
| | | * é¿æ´å½¢è½¬æBCDç¼ç |
| | | * @param l |
| | | * @return |
| | | * @return è¿å |
| | | */ |
| | | public static byte[] long2BCD_BE(long l)throws Exception { |
| | | String str = "" + l; |
| | |
| | | * å°ç«¯æ¨¡å¼ãæ°æ®ä½ä½å¨æ°ç»ä½åèã |
| | | * é¿æ´å½¢è½¬æBCDç¼ç ï¼åèé¡ºåºæ¯åç |
| | | * @param l |
| | | * @return |
| | | * @return è¿å |
| | | */ |
| | | public static byte[] long2BCD_LE(long l) throws Exception { |
| | | String str = "" + l; |
| | |
| | | * 大端模å¼ãæ°æ®ä½ä½å¨æ°ç»é«åèã |
| | | * åç¬¦ä¸²åæ°å转æBCDç¼ç |
| | | * @param s |
| | | * @return |
| | | * @throws Exception |
| | | * @return è¿å |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static byte[] string2BCD_BE(String s) throws Exception { |
| | | byte[] b = null; |
| | | byte[] b ; |
| | | if (s.length() % 2 == 0) { |
| | | b = new byte[s.length() / 2]; |
| | | } else { |
| | | b = new byte[(s.length() / 2) + 1]; |
| | | } |
| | | |
| | | |
| | | encodeBCD_BE(s, b, 0, b.length); |
| | | |
| | | return b ; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 大端模å¼ãæ°æ®ä½ä½å¨æ°ç»é«åèã |
| | | * åç¬¦ä¸²è½¬æ¢æbyteæ°ç» |
| | | * @value bs byte[] |
| | | * @value str String |
| | | * @value fromIndex int |
| | | * @return |
| | | * @throws java.io.Exception |
| | | * @return è¿å |
| | | * @throws Exception å¼å¸¸ å¼å¸¸ |
| | | */ |
| | | public static int string2BCD_BE(byte[] bs, String str, int fromIndex)throws Exception { |
| | | byte[] bb = string2BCD_BE(str); |
| | |
| | | * å°ç«¯æ¨¡å¼ãæ°æ®ä½ä½å¨æ°ç»ä½åèã |
| | | * åç¬¦ä¸²åæ°å转æBCDç¼ç ï¼åèé¡ºåºæ¯åç |
| | | * @param s |
| | | * @return |
| | | * @throws Exception |
| | | * @return è¿å |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static byte[] string2BCD_LE(String s) throws Exception { |
| | | byte[] b = null; |
| | |
| | | |
| | | return b; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 大端模å¼ãæ°æ®ä½ä½å¨æ°ç»é«åèã |
| | | * åç¬¦ä¸²è½¬æ¢æbyteæ°ç» |
| | | * @value bs byte[] |
| | | * @value str String |
| | | * @value fromIndex int |
| | | * @return |
| | | * @throws java.io.Exception |
| | | * @return è¿å |
| | | * @throws Exception å¼å¸¸ å¼å¸¸ |
| | | */ |
| | | public static int string2BCD_LE(byte[] bs, String str, int fromIndex)throws Exception { |
| | | byte[] bb = string2BCD_LE(str); |
| | |
| | | * 大端模å¼ãæ°æ®ä½ä½å¨æ°ç»é«åèã |
| | | * BCDç¼ç è½¬ææ´å |
| | | * @param b |
| | | * @param startIndex |
| | | * @param endIndex |
| | | * @return |
| | | * @throws Exception |
| | | * @return è¿å |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static int BCD2Int_BE(byte b) throws Exception { |
| | | String str = ""; |
| | |
| | | * å°ç«¯æ¨¡å¼ãæ°æ®ä½ä½å¨æ°ç»ä½åèã |
| | | * BCDç¼ç è½¬ææ´åï¼åèé¡ºåºæ¯åç |
| | | * @param b |
| | | * @param startIndex |
| | | * @param endIndex |
| | | * @return |
| | | * @throws Exception |
| | | * @return è¿å |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static int BCD2Int_LE(byte b) throws Exception { |
| | | String str = ""; |
| | |
| | | * @param b |
| | | * @param startIndex |
| | | * @param endIndex |
| | | * @return |
| | | * @throws Exception |
| | | * @return è¿å |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static int BCD2Int_BE(byte[] b, int startIndex, int endIndex)throws Exception { |
| | | String str = ""; |
| | |
| | | * @param b |
| | | * @param startIndex |
| | | * @param endIndex |
| | | * @return |
| | | * @throws Exception |
| | | * @return è¿å |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static int BCD2Int_LE(byte[] b, int startIndex, int endIndex)throws Exception { |
| | | String str = ""; |
| | |
| | | * @param b |
| | | * @param startIndex |
| | | * @param endIndex |
| | | * @return |
| | | * @throws Exception |
| | | * @return è¿å |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static long BCD2Long_BE(byte[] b, int startIndex, int endIndex)throws Exception { |
| | | String str = ""; |
| | |
| | | * @param b |
| | | * @param startIndex |
| | | * @param endIndex |
| | | * @return |
| | | * @throws Exception |
| | | * @return è¿å |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static long BCD2Long_LE(byte[] b, int startIndex, int endIndex)throws Exception { |
| | | String str = ""; |
| | |
| | | * @param b |
| | | * @param startIndex |
| | | * @param endIndex |
| | | * @return |
| | | * @throws Exception |
| | | * @return è¿å |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static String BCD2String_BE(byte[] b, int startIndex, int endIndex) throws Exception { |
| | | return decodeBCD_BE(b, startIndex, endIndex - startIndex + 1); |
| | |
| | | * @param b |
| | | * @param startIndex |
| | | * @param endIndex |
| | | * @return |
| | | * @throws Exception |
| | | * @return è¿å |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static String BCD2String_LE(byte[] b, int startIndex, int endIndex) throws Exception { |
| | | return decodeBCD_LE(b, startIndex, endIndex - startIndex + 1); |
| | |
| | | |
| | | /** |
| | | * 大端模å¼ãæ°æ®ä½ä½å¨æ°ç»é«åèã |
| | | * ç¼ç BCDï¼ä¾å¦1387ç¼ç æ 13 87ï¼é¡ºåºæ¯æ£ç |
| | | * ç¼ç BCDï¼ä¾å¦1387ç¼ç æ 13 87ï¼é¡ºåºæ¯æ£ç |
| | | * @param value |
| | | * @param dest |
| | | * @param startIndex |
| | | * @param length |
| | | * @param length é¿åº¦ |
| | | */ |
| | | private static void encodeBCD_BE(String value, byte[] dest, int startIndex, int length)throws Exception { |
| | | if (value == null || !value.matches("\\d*")) { |
| | | throw new Exception("æ°å转æBCDç¼ç æ¶åºéï¼ä¸æ¯åæ³æ°å:" + value, null); |
| | | } |
| | | |
| | | |
| | | int[] tmpInts = new int[2 * length]; |
| | | int index = value.length() - 1; |
| | | for (int i = tmpInts.length - 1; i >= 0 && index >= 0; i--, index--) { |
| | |
| | | dest[i] = (byte) (tmpInts[2 * j] * 16 + tmpInts[2 * j + 1]); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * å°ç«¯æ¨¡å¼ãæ°æ®ä½ä½å¨æ°ç»ä½åèã |
| | | * ç¼ç BCDï¼ä¾å¦1387ç¼ç æ 87 13ï¼é¡ºåºæ¯åç |
| | | * ç¼ç BCDï¼ä¾å¦1387ç¼ç æ 87 13ï¼é¡ºåºæ¯åç |
| | | * @param value |
| | | * @param dest |
| | | * @param startIndex |
| | | * @param length |
| | | * @param length é¿åº¦ |
| | | */ |
| | | private static void encodeBCD_LE(String value, byte[] dest, int startIndex, int length)throws Exception { |
| | | if (value == null || !value.matches("\\d*")) { |
| | | throw new Exception("æ°å转æBCDç¼ç æ¶åºéï¼ä¸æ¯åæ³æ°å:" + value, null); |
| | | } |
| | | |
| | | |
| | | int[] tmpInts = new int[2 * length]; |
| | | int index = value.length() - 1; |
| | | for (int i = 0; i <= tmpInts.length - 1 && index >= 0; i++, index--) { |
| | |
| | | * è§£ç BCDï¼é¡ºåºæ¯æ£ç |
| | | * @param src |
| | | * @param startIndex |
| | | * @param length |
| | | * @return |
| | | * @param length é¿åº¦ |
| | | * @return è¿å |
| | | */ |
| | | private static String decodeBCD_BE(byte[] src, int startIndex, int length)throws Exception { |
| | | StringBuilder sb = new StringBuilder(); |
| | |
| | | * ç¼ç BCDï¼é¡ºåºæ¯åç |
| | | * @param src |
| | | * @param startIndex |
| | | * @param length |
| | | * @return |
| | | * @param length é¿åº¦ |
| | | * @return è¿å |
| | | */ |
| | | private static String decodeBCD_LE(byte[] src, int startIndex, int length)throws Exception { |
| | | StringBuilder sb = new StringBuilder(); |
| | |
| | | // System.out.println(v5); |
| | | // |
| | | // } |
| | | /* |
| | | public static void main(String[] args) throws Exception { |
| | | byte[] bs = new byte[]{0x38, 0x36, 0x39, 0x31} ; |
| | | String s = bytes2String_BE(bs, 0, 3) ; |
| | |
| | | } |
| | | System.out.println(v); |
| | | } |
| | | |
| | | */ |
| | | |
| | | } |
| | |
| | | ServerProperties.lastUpDataTimeLive = conf.getSetAttrPlusInt(doc, "config.base", "lastUpDataTimeLive", null, 0, 5, null) * 1000L ; |
| | | //æ°æ®åºæ°æ®idçæå¨çidåç¼ï¼0æ¯é»è®¤çåç¼ï¼ä¸è¬webç³»ç»åºç¨ï¼æ°æ®ä¸é´ä»¶idåç¼å¤§äºçäº1 |
| | | ServerProperties.dbDataIdSuffix = conf.getSetAttrInt(doc, "config.base", "dbDataIdSuffix", null, 0, 99, null); |
| | | //ä¸ä¸è¡æ°æ®ç¼åéåä¸ç¼åæ°æ®ä¸ªæ°çæ¥è¦éï¼è¿ä¸ªä¸ç°å®é¡¹ç®ææ¥æ°´è¡¨æ°ç¸å
³ |
| | | ServerProperties.cacheUpDownDataWarnCount = conf.getSetAttrPlusInt(doc, "config.base", "cacheUpDownDataWarnCount", null, 1, null, null) ; |
| | | //ä¸ä¸è¡æ°æ®ç¼åéåä¸ç¼åæ°æ®ä¸ªæ°çæå¤§å¼ï¼è¿ä¸ªä¸ç°å®é¡¹ç®ææ¥æ°´è¡¨æ°ç¸å
³ |
| | | ServerProperties.cacheUpDownDataMaxCount = conf.getSetAttrPlusInt(doc, "config.base", "cacheUpDownDataMaxCount", null, 1, null, null) ; |
| | | if(ServerProperties.cacheUpDownDataMaxCount <= ServerProperties.cacheUpDownDataWarnCount){ |
| | | throw new Exception("cacheUpDownDataMaxCountå¿
须大äºcacheUpDownDataWarnCount") ; |
| | | } |
| | | |
| | | //设置IDçæå¨çåç¼ |
| | | IDLongGenerator.setSuffix(ServerProperties.dbDataIdSuffix.intValue()); |
| | |
| | | public static Long lastUpDataTimeLive = 1000L ; |
| | | |
| | | //æ°æ®åºæ°æ®idçæå¨çidåç¼ï¼0æ¯é»è®¤çåç¼ï¼ä¸è¬webç³»ç»åºç¨ï¼æ°æ®ä¸é´ä»¶idåç¼å¤§äºçäº1 |
| | | public static Integer dbDataIdSuffix = 1 ; |
| | | public static Integer dbDataIdSuffix = 1 ; |
| | | |
| | | //ä¸ä¸è¡æ°æ®ç¼åéåä¸ç¼åæ°æ®ä¸ªæ°çæ¥è¦éï¼è¿ä¸ªä¸å®ä½é¡¹ç®ææ¥æ°´è¡¨æ°ç¸å
³ |
| | | public static Integer cacheUpDownDataWarnCount = 1000000 ; |
| | | |
| | | //ä¸ä¸è¡æ°æ®ç¼åéåä¸ç¼åæ°æ®ä¸ªæ°çæå¤§å¼ï¼è¿ä¸ªä¸å®ä½é¡¹ç®ææ¥æ°´è¡¨æ°ç¸å
³ |
| | | public static Integer cacheUpDownDataMaxCount = 1100000 ; |
| | | |
| | | } |
| | |
| | | if(result != null && result instanceof MidResultToRtu){ |
| | | try { |
| | | MidResultToRtu resToRtu = (MidResultToRtu)result ; |
| | | TcpDownCommandCach.cachCommand(resToRtu); |
| | | TcpDownCommandCache.cacheCommand(resToRtu); |
| | | log.info("ä¸è¡å½ä»¤(toRtu)" + resToRtu.downCode + "ä¸é´ç»æå·²ç»æ¾å
¥ä¸è¡å½ä»¤ç¼åä¸"); |
| | | } catch (Exception e) { |
| | | log.error(e); |
New file |
| | |
| | | package com.dy.aceMw.server.forTcp; |
| | | |
| | | |
| | | import com.dy.common.queue.Node; |
| | | import com.dy.common.queue.Queue; |
| | | import com.dy.common.mw.protocol.MidResultFromRtu; |
| | | import com.dy.common.mw.protocol.MidResultToRtu; |
| | | import com.dy.aceMw.server.ServerProperties; |
| | | |
| | | /** |
| | | * é线ç¨å®å
¨çï¼åªè½å¨å线ç¨ä¸è¿è¡ |
| | | */ |
| | | public class TcpDownCommandCache { |
| | | |
| | | //TCPä¸è¡å½ä»¤ç¼åéå |
| | | private static Queue cacheQueue = new Queue("tcpDownCommandQueue") ; |
| | | |
| | | private static TcpDownCommandCache instance = new TcpDownCommandCache() ; |
| | | |
| | | private TcpDownCommandCache(){ |
| | | cacheQueue.setLimit(ServerProperties.cacheUpDownDataWarnCount, ServerProperties.cacheUpDownDataMaxCount); |
| | | } |
| | | |
| | | public static TcpDownCommandCache getInstance(){ |
| | | return instance ; |
| | | } |
| | | |
| | | /** |
| | | * ç¼åå½ä»¤ |
| | | * @param result |
| | | * @throws Exception |
| | | */ |
| | | public static void cacheCommand(MidResultToRtu result) throws Exception{ |
| | | if(result != null){ |
| | | if(result.maxSendTimes == null){ |
| | | //设置æå¤§å鿬¡æ° |
| | | result.maxSendTimes = ServerProperties.downComandMaxResendTimes ; |
| | | } |
| | | if(result.isSendFirst){ |
| | | cacheQueue.pushHead(new TcpDownCommandObj(result)); |
| | | }else{ |
| | | cacheQueue.pushTail(new TcpDownCommandObj(result)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¹é
å½ä»¤ç»æ |
| | | * @param rsFromRtu |
| | | * @return |
| | | */ |
| | | public static MidResultToRtu matchFromHead(MidResultFromRtu rsFromRtu){ |
| | | MidResultToRtu res = null ; |
| | | TcpDownCommandObj obj = null ; |
| | | Node node = cacheQueue.getFirstNode() ; |
| | | while(node != null && node.obj != null){ |
| | | obj = (TcpDownCommandObj)node.obj; |
| | | res = obj.result ; |
| | | if(res != null |
| | | && res.rtuAddr.equals(rsFromRtu.rtuAddr) |
| | | && res.downCode.equals(rsFromRtu.upCode)){ |
| | | obj.onceReceivedResult = true ;//æ è¯å·²ç»æ¶å°å½ä»¤ç»æ |
| | | return res ; |
| | | }else{ |
| | | node = node.pre ; |
| | | } |
| | | } |
| | | |
| | | return null ; |
| | | } |
| | | |
| | | /** |
| | | * å¹é
å½ä»¤ç»æ |
| | | * @param rsFromRtu |
| | | * @return |
| | | */ |
| | | public static MidResultToRtu matchFromTail(MidResultFromRtu rsFromRtu){ |
| | | MidResultToRtu res = null ; |
| | | TcpDownCommandObj obj = null ; |
| | | Node node = cacheQueue.getLastNode() ; |
| | | while(node != null && node.obj != null){ |
| | | obj = (TcpDownCommandObj)node.obj; |
| | | res = obj.result ; |
| | | if(res != null |
| | | && res.rtuAddr.equals(rsFromRtu.rtuAddr) |
| | | && res.downCode.equals(rsFromRtu.upCode)){ |
| | | obj.onceReceivedResult = true ;//æ è¯å·²ç»æ¶å°å½ä»¤ç»æ |
| | | return res ; |
| | | }else{ |
| | | node = node.pre ; |
| | | } |
| | | } |
| | | |
| | | return null ; |
| | | } |
| | | |
| | | /** |
| | | * å¾å°ç¬¬ä¸ä¸ªèç¹ |
| | | * @return |
| | | */ |
| | | public static Node getFirstQueueNode(){ |
| | | return cacheQueue.getFirstNode() ; |
| | | } |
| | | |
| | | /** |
| | | * å¾å°æåä¸ä¸ªèç¹ |
| | | * @return |
| | | */ |
| | | public static Node getLastQueueNode(){ |
| | | return cacheQueue.getLastNode() ; |
| | | } |
| | | |
| | | /** |
| | | * ç§»é¤èç¹ |
| | | * @param node |
| | | */ |
| | | public static void removeNode(Node node){ |
| | | cacheQueue.remove(node); |
| | | } |
| | | |
| | | /** |
| | | * ç¼åçèç¹æ° |
| | | * @Return ç¼åèç¹æ° |
| | | */ |
| | | public static Integer size(){ |
| | | return cacheQueue.size() ; |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | Long lastSendStamp = tcpSe.lastDownComTime ; |
| | | if(lastSendStamp == null || (now - lastSendStamp >= ServerProperties.commandSendInterval)){ |
| | | //æªæ¶å°å½ä»¤ç»æï¼æªè¾¾å°æå¤§å鿬¡æ°ï¼RTUå¨çº¿ï¼è¶
è¿å½ä»¤é´ä¸åé´éï¼ä»¥ä¸æ»¡è¶³åéå½ä»¤æ¡ä»¶ï¼æ§è¡åéå½ä»¤ |
| | | if(this.result.isQuickSend || lastSendStamp == null || (now - lastSendStamp >= ServerProperties.commandSendInterval)){ |
| | | //æªæ¶å°å½ä»¤ç»æï¼æªè¾¾å°æå¤§å鿬¡æ°ï¼RTUå¨çº¿ï¼éåå½ä»¤æè¶
è¿å½ä»¤ä¸åé´éï¼ä»¥ä¸æ»¡è¶³åéå½ä»¤æ¡ä»¶ï¼æ§è¡åéå½ä»¤ |
| | | tcpSe.ioSession.write(this.result.downBuffer) ; |
| | | tcpSe.lastDownComTime = now ; |
| | | if(!this.result.hasResponse){ |
| | |
| | | if (c == null) { |
| | | throw new Exception("ä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶ä¸ä¸è½å®ä¾åclass=" + clazz + "ï¼"); |
| | | }else{ |
| | | Object o = c.newInstance(); |
| | | if(o instanceof Task){ |
| | | }else{ |
| | | Object o = c.getDeclaredConstructor().newInstance(); |
| | | //Object o = c.newInstance(); |
| | | if(!(o instanceof Task)){ |
| | | throw new Exception("ä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶ä¸class=" + clazz + "å¿
é¡»å®ç°Taskæ¥å£ï¼"); |
| | | } |
| | | } |
| | |
| | | import com.dy.common.mw.protocol.MidResult; |
| | | import com.dy.common.mw.protocol.Command; |
| | | import com.dy.common.mw.protocol.Driver; |
| | | import com.dy.common.mw.protocol.ProtocolCach; |
| | | import com.dy.common.mw.protocol.ProtocolCache; |
| | | import com.dy.aceMw.server.ServerProperties; |
| | | import com.dy.aceMw.server.forTcp.TcpSessionCach; |
| | | |
| | |
| | | |
| | | /** |
| | | * å¤çå½ä»¤ |
| | | * @param webJgroupName |
| | | * @param com |
| | | * @param com å½ä»¤ |
| | | * @throws Exception |
| | | */ |
| | | private void deal(Command com) throws Exception{ |
| | |
| | | String protocolName = TcpSessionCach.getTcpProtocolName(rtuAddr) ; |
| | | if(protocolName == null){ |
| | | //RTUæªæ¾ä¸çº¿ |
| | | int count = ProtocolCach.driverCount() ; |
| | | int count = ProtocolCache.driverCount() ; |
| | | if(count == 1){ |
| | | //åªæä¸ä¸ªåè®® |
| | | dri = ProtocolCach.getFirstDriver() ; |
| | | dri = ProtocolCache.getFirstDriver() ; |
| | | } |
| | | }else{ |
| | | dri = ProtocolCach.getDriver(protocolName) ; |
| | | dri = ProtocolCache.getDriver(protocolName) ; |
| | | } |
| | | if(dri == null){ |
| | | log.error("严ééè¯¯ï¼æªè½å¾å°åè®®" + protocolName + "驱å¨ç±»å®ä¾ï¼"); |
| | |
| | | import com.dy.common.mw.protocol.Driver; |
| | | import com.dy.common.mw.protocol.OnLine; |
| | | import com.dy.common.mw.protocol.OnLineHandle; |
| | | import com.dy.common.mw.protocol.ProtocolCach; |
| | | import com.dy.common.mw.protocol.ProtocolCache; |
| | | import com.dy.aceMw.server.ServerProperties; |
| | | import com.dy.aceMw.server.forTcp.RtuLogDealer; |
| | | import com.dy.aceMw.server.forTcp.RtuStatusDealer; |
| | |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | private void dealUpData(IoSession session, String rtuAddrAtHead, String protocolName, boolean isOnLine, byte[] upBuf, String upHex) throws Exception{ |
| | | Driver dri = ProtocolCach.getDriver(protocolName) ; |
| | | Driver dri = ProtocolCache.getDriver(protocolName) ; |
| | | if(dri == null){ |
| | | log.error("严ééè¯¯ï¼æªè½å¾å°åè®®" + protocolName + "驱å¨ç±»å®ä¾ï¼"); |
| | | }else{ |
| | | MidResult[] midRs = dri.parseData(ServerProperties.isLowPower, rtuAddrAtHead, upBuf, upHex, new DriverParserDataCallback(){ |
| | | @Override |
| | | public void callback(String rtuAddrAtHead, String meterNoAtHead, String code, String upHex, Boolean reportOrResponse_trueOrFalse, boolean parseFail, String rtuAddrInData, String meterNoInData) { |
| | | public void callback(String rtuAddrAtHead, String code, String upHex, Boolean reportOrResponse_trueOrFalse, boolean parseFail, String rtuAddrInData) { |
| | | //æ´æ°ç»ç«¯ç¶æ |
| | | if(rtuAddrInData != null && !rtuAddrInData.equals(rtuAddrAtHead)){ |
| | | //æ°æ®å¤´ä¸çRTUå°å䏿°æ®ä¸çRTUå°åä¸ä¸è´ï¼æ´æ¢ææ°æ®ä¸çRTUå°å |
| | |
| | | |
| | | import com.dy.common.queue.Node; |
| | | import com.dy.common.mw.core.CoreTask; |
| | | import com.dy.aceMw.server.forTcp.TcpDownCommandCach; |
| | | import com.dy.aceMw.server.forTcp.TcpDownCommandCache; |
| | | import com.dy.aceMw.server.forTcp.TcpDownCommandObj; |
| | | import com.dy.aceMw.server.forTcp.TcpSessionCach; |
| | | |
| | |
| | | * å¤çä¸è¡å½ä»¤ |
| | | */ |
| | | public Integer dealDownCommand(Long now) { |
| | | try{ |
| | | Node first = TcpDownCommandCach.getFirstQueueNode() ; |
| | | if(first != null){ |
| | | Integer count = TcpDownCommandCach.size() ; |
| | | Node last = TcpDownCommandCach.getLastQueueNode() ; |
| | | this.doDealDownCommand(now, first, last); |
| | | return count ; |
| | | } |
| | | }catch(Exception e){ |
| | | log.error(e); |
| | | Node first = TcpDownCommandCache.getFirstQueueNode() ; |
| | | if(first != null){ |
| | | Integer count = TcpDownCommandCache.size() ; |
| | | Node last = TcpDownCommandCache.getLastQueueNode() ; |
| | | this.doDealDownCommand(now, first, last); |
| | | return count ; |
| | | } |
| | | return null ; |
| | | } |
| | |
| | | * å¤çç¼åçä¸è¡å½ä»¤èç¹ |
| | | * @param now å½åæ¶å» |
| | | * @param first 第ä¸ä¸ªèç¹ |
| | | * @param last æ¯åä¸ä¸ªèç¹ |
| | | * @param last æåä¸ä¸ªèç¹ |
| | | */ |
| | | private void doDealDownCommand(Long now, Node first, Node last){ |
| | | private void doDealDownCommand1(Long now, Node first, Node last){ |
| | | if(first != null){ |
| | | //å¨dealNodeæ¹æ³ä¸ï¼å¯è½è¦æfirstä»éåä¸ç§»é¤ï¼è¿æ¶first.nextä¸ºç©ºï¼æä»¥æåæfirst.nextååºæ¥ |
| | | Node next = first.next ; |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * å¤çç¼åçä¸è¡å½ä»¤èç¹ |
| | | * @param now å½åæ¶å» |
| | | * @param first 第ä¸ä¸ªèç¹ |
| | | * @param last æåä¸ä¸ªèç¹ |
| | | */ |
| | | private void doDealDownCommand(Long now, Node first, Node last){ |
| | | if(last != null){ |
| | | //å¨dealNodeæ¹æ³ä¸ï¼å¯è½è¦ælastä»éåä¸ç§»é¤ï¼è¿æ¶last.preä¸ºç©ºï¼æä»¥æåælast.preååºæ¥ |
| | | Node pre = last.pre ; |
| | | dealNode(now, last) ; |
| | | if(first != null && first != last){ |
| | | doDealDownCommand(now, first, pre) ; |
| | | }else if(first != null && first == last){ |
| | | //忢 |
| | | }else if(first == null){ |
| | | //è¿ç§æ
åµä¸ä¼åå¨ |
| | | doDealDownCommand(now, null, pre) ; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¤çä¸ä¸ªèç¹ |
| | | * @param now ç°å¨æ¶å» |
| | |
| | | TcpDownCommandObj obj = (TcpDownCommandObj)node.obj ; |
| | | boolean removeNode = obj.dealSelf(now) ; |
| | | if(removeNode){ |
| | | TcpDownCommandCach.removeNode(node); |
| | | TcpDownCommandCache.removeNode(node); |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | package com.dy.testServer; |
| | | |
| | | import com.dy.common.mw.channel.rmi.RmiConfigVo; |
| | | import com.dy.common.mw.channel.rmi.RmiRequestCallback; |
| | | import com.dy.common.mw.channel.rmi.RmiUnitAdapter; |
| | | import com.dy.testServer.forRmi.RmiRequestedCallback; |
| | | |
| | | public class AdapterImp_RmiUnit implements RmiUnitAdapter { |
| | | |
| | | private RmiConfigVo configVo ; |
| | | |
| | | @Override |
| | | public RmiConfigVo getConfig() { |
| | | return configVo; |
| | | } |
| | | |
| | | public void setConfig(RmiConfigVo configVo){ |
| | | this.configVo = configVo ; |
| | | } |
| | | |
| | | @Override |
| | | public RmiRequestCallback newRequestCallback() { |
| | | return new RmiRequestedCallback(); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.testServer.forRmi; |
| | | |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | |
| | | public class ResRegisterVo { |
| | | |
| | | public String token ; |
| | | |
| | | /** |
| | | * 对象转æjson |
| | | * @return json |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public String toJson()throws Exception{ |
| | | try{ |
| | | return JSON.toJSONString(this) ; |
| | | //return new JSONSerializer().exclude(new String[]{"class", "*.class"}).deepSerialize(this); |
| | | }catch(Exception e){ |
| | | throw new Exception(e.getMessage() , e ) ; |
| | | } |
| | | } |
| | | /** |
| | | * json转æå¯¹è±¡ |
| | | * @param json åæ° |
| | | * @return 对象 |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static ResRegisterVo jsonToObject(String json)throws Exception{ |
| | | try{ |
| | | return JSON.parseObject(json, ResRegisterVo.class) ; |
| | | //return new JSONDeserializer<ResRegisterVo>().deserialize(json, ResRegisterVo.class) ; |
| | | }catch(Exception e){ |
| | | throw new Exception(e.getMessage() , e ) ; |
| | | } |
| | | } |
| | | |
| | | public String getToken() { |
| | | return token; |
| | | } |
| | | |
| | | public void setToken(String id) { |
| | | this.token = id; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.testServer.forRmi; |
| | | |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | |
| | | public class ResStartVo { |
| | | |
| | | public boolean success = true ; |
| | | |
| | | public String errorInfo ; |
| | | |
| | | public boolean start ; |
| | | |
| | | |
| | | /** |
| | | * 对象转æjson |
| | | * @return json |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public String toJson()throws Exception{ |
| | | try{ |
| | | return JSON.toJSONString(this) ; |
| | | //return new JSONSerializer().exclude(new String[]{"class", "*.class"}).deepSerialize(this); |
| | | }catch(Exception e){ |
| | | throw new Exception(e.getMessage() , e ) ; |
| | | } |
| | | } |
| | | /** |
| | | * json转æå¯¹è±¡ |
| | | * @param json åæ° |
| | | * @return 对象 |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static ResStartVo jsonToObject(String json)throws Exception{ |
| | | try{ |
| | | return JSON.parseObject(json, ResStartVo.class) ; |
| | | //return new JSONDeserializer<ResStartVo>().deserialize(json, ResStartVo.class) ; |
| | | }catch(Exception e){ |
| | | throw new Exception(e.getMessage() , e ) ; |
| | | } |
| | | } |
| | | |
| | | public boolean isSuccess() { |
| | | return success; |
| | | } |
| | | public void setSuccess(boolean success) { |
| | | this.success = success; |
| | | } |
| | | public String getErrorInfo() { |
| | | return errorInfo; |
| | | } |
| | | public void setErrorInfo(String errorInfo) { |
| | | this.errorInfo = errorInfo; |
| | | } |
| | | public boolean isStart() { |
| | | return start; |
| | | } |
| | | |
| | | public void setStart(boolean start) { |
| | | this.start = start; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.testServer.forRmi; |
| | | |
| | | import java.rmi.RemoteException; |
| | | |
| | | import com.dy.common.mw.channel.rmi.RmiRequestCallback; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | public class RmiRequestedCallback implements RmiRequestCallback { |
| | | |
| | | @SuppressWarnings("unused") |
| | | private static Logger log = LogManager.getLogger(RmiRequestedCallback.class.getName()) ; |
| | | |
| | | @Override |
| | | public Object syncRequest(Object obj) throws RemoteException { |
| | | String json ; |
| | | try { |
| | | json = Manager.dealRequest(obj); |
| | | } catch (Exception e) { |
| | | throw new RemoteException("æå¡ç«¯å¼å¸¸" , e) ; |
| | | } |
| | | return json ; |
| | | } |
| | | |
| | | @Override |
| | | public String asyncRequest(Object obj) throws RemoteException { |
| | | String json ; |
| | | try { |
| | | json = Manager.dealRequest(obj); |
| | | } catch (Exception e) { |
| | | throw new RemoteException("æå¡ç«¯å¼å¸¸" , e) ; |
| | | } |
| | | return json ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | pushä¹åå
pull |
| | | pullåè¦å
commit |