pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/channel/tcp/DataCodecFactory.java
@@ -8,16 +8,32 @@ public class DataCodecFactory implements ProtocolCodecFactory { private TcpUnitAdapter adapter ; private boolean stop = false ;//为trueæ¶ï¼åæ¢TCPæå¡ï¼å¹¶æå·²ç»TCPè¿æ¥æè¿æ¥ public DataCodecFactory(TcpUnitAdapter adapter) { this.adapter = adapter ; } public void stop(){ stop = true ; } public void recover(){ this.stop = false ; } public ProtocolEncoder getEncoder(IoSession ioSession) { if(stop){ ioSession.closeNow() ; } return new DataEncoder(); } public ProtocolDecoder getDecoder(IoSession ioSession) { if(stop){ ioSession.closeNow() ; } return new DataDecoder(adapter.newPrefixedDataAvailableHandle()); } } pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/channel/tcp/TcpIoHandler.java
@@ -8,9 +8,18 @@ private TcpUnitAdapter adapter ; private boolean stop = false ;//为trueæ¶ï¼åæ¢TCPæå¡ï¼å¹¶æå·²ç»TCPè¿æ¥æè¿æ¥ public TcpIoHandler(TcpUnitAdapter adapter){ this.adapter = adapter ; } public void stop(){ stop = true ; } public void recover(){ this.stop = false ; } /** @@ -18,14 +27,22 @@ */ @Override public void sessionCreated(IoSession session) throws Exception { super.sessionCreated(session); if(stop){ session.closeNow() ; }else{ super.sessionCreated(session); } } /** * ä¼è¯openæ¶åè°çæ¹æ³ */ public void sessionOpened(IoSession session) throws Exception { this.adapter.newSessionEventCallback().sessionOpened(session); if(stop){ session.closeNow() ; }else{ this.adapter.newSessionEventCallback().sessionOpened(session); } } /** @@ -76,7 +93,11 @@ */ @Override public void messageReceived(IoSession session, Object message) throws Exception { this.adapter.newSessionEventCallback().messageReceived(session, message); if(stop){ session.closeNow() ; }else{ this.adapter.newSessionEventCallback().messageReceived(session, message); } } } pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/channel/tcp/TcpUnit.java
@@ -22,6 +22,8 @@ private static boolean started = false ; private TcpUnitAdapter adapter ; private TcpIoHandler tcpIoHandler ; private DataCodecFactory dataCodecFactory ; private TcpUnit(){} ; @@ -94,7 +96,8 @@ //å¾å°ç½ç» éä¿¡æ°æ®è¿æ»¤å¨é¾ DefaultIoFilterChainBuilder chain = acceptor.getFilterChain() ; //ç¼è§£ç è¿æ»¤å¨ chain.addLast("protocol", new ProtocolCodecFilter(new DataCodecFactory(this.adapter))); dataCodecFactory = new DataCodecFactory(this.adapter) ; chain.addLast("protocol", new ProtocolCodecFilter(dataCodecFactory)); /* * ä¸è¬ExecutorFilter é½è¦æ¾å¨ProtocolCodecFilter è¿æ»¤å¨çåé¢ï¼ @@ -106,7 +109,8 @@ chain.addLast("exceutor", new ExecutorFilter()); //ä¸å¡é»è¾å¤çå¨ï¼è´è´£å¤çç½ç»ä¼è¯åè¾å ¥è¾åºæ°æ® acceptor.setHandler(new TcpIoHandler(this.adapter)); tcpIoHandler = new TcpIoHandler(this.adapter) ; acceptor.setHandler(tcpIoHandler) ; boolean isException = false ; try { @@ -129,8 +133,26 @@ } } /** * åæ¢æ¨¡åè¿è¡ï¼å°ä¸åæ¥å ¥TCPç½ç»è¿æ¥ï¼å¹¶æå·²ç»tcpè¿æ¥çå ¨é¨æè¿æ¥ * @param callback * @throws Exception */ @Override public void stop(UnitStartedCallbackInterface callback) throws Exception { this.tcpIoHandler.stop(); this.dataCodecFactory.stop(); this.adapter.newUnitStopCallback().callback(); callback.call(null); } /** * è§£é¤åæ¢ï¼æ¢å¤TCPæå¡è¿è¡ * @throws Exception */ public void recover() throws Exception { this.tcpIoHandler.recover(); this.dataCodecFactory.recover(); } pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/channel/tcp/TcpUnitAdapter.java
@@ -22,5 +22,10 @@ * @return */ TcpIoSessionEventCallback newSessionEventCallback() ; /** * 模å忢æ¶çåè° */ TcpUnitStopCallback newUnitStopCallback() ; } pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/channel/tcp/TcpUnitStopCallback.java
New file @@ -0,0 +1,10 @@ package com.dy.common.mw.channel.tcp; /** * @Author: liurunyu * @Date: 2024/7/29 9:25 * @Description */ public interface TcpUnitStopCallback { void callback() ; } pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_A1_Down.java
@@ -103,7 +103,7 @@ if(cvo.year < 24 || cvo.year > 9999){ throw new Exception("计åå¼éæ¶é´---年䏿£ç¡®") ; } if(cvo.year > 24 && cvo.year < 2024){ if(cvo.year > 99 && cvo.year < 2024){ throw new Exception("计åå¼éæ¶é´---年䏿£ç¡®") ; } if(cvo.month == null){ pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_A2_Down.java
@@ -103,7 +103,7 @@ if(cvo.year < 24 || cvo.year > 9999){ throw new Exception("计åå¼éæ¶é´---年䏿£ç¡®") ; } if(cvo.year > 24 && cvo.year < 2024){ if(cvo.year > 99 && cvo.year < 2024){ throw new Exception("计åå¼éæ¶é´---年䏿£ç¡®") ; } if(cvo.month == null){ pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/BCDUtil.java
New file @@ -0,0 +1,273 @@ package com.dy.common.util; /** * @Author: liurunyu * @Date: 2024/7/27 15:50 * @Description */ public class BCDUtil { /** * * @param num * @return */ public static byte[] int2BCD_LE(int num){ int len = (int) Math.log10(num) + 1 ; byte[] bs = null ; if(len % 2 == 0){ bs = new byte[len / 2] ; }else{ bs = new byte[len / 2 + 1] ; } int index = 0 ; while(num > 0){ int yu = num % 100 ; bs[index++] = (byte)(((yu/10) << 4) + (yu%10)) ; num = num / 100 ; } return bs ; } /** * * @param num * @return */ public static byte[] int2BCD_BE(int num){ int len = (int) Math.log10(num) + 1 ; byte[] bs = null ; if(len % 2 == 0){ bs = new byte[len / 2] ; }else{ bs = new byte[len / 2 + 1] ; } int index = bs.length - 1 ; while(num > 0){ int yu = num % 100 ; bs[index--] = (byte)(((yu/10) << 4) + (yu%10)) ; num = num / 100 ; } return bs ; } /** * * @param num * @return */ public static byte[] long2BCD_LE(long num){ int len = (int) Math.log10(num) + 1 ; byte[] bs = null ; if(len % 2 == 0){ bs = new byte[len / 2] ; }else{ bs = new byte[len / 2 + 1] ; } int index = 0 ; while(num > 0){ long yu = num % 100 ; bs[index++] = (byte)(((yu/10) << 4) + (yu%10)) ; num = num / 100 ; } return bs ; } /** * * @param num * @return */ public static byte[] long2BCD_BE(long num){ int len = (int) Math.log10(num) + 1 ; byte[] bs = null ; if(len % 2 == 0){ bs = new byte[len / 2] ; }else{ bs = new byte[len / 2 + 1] ; } int index = bs.length - 1 ; while(num > 0){ long yu = num % 100 ; bs[index--] = (byte)(((yu/10) << 4) + (yu%10)) ; num = num / 100 ; } return bs ; } /** * * @param numStr * @return */ public static byte[] string2BCD_LE(String numStr) throws Exception{ if (numStr == null || !numStr.matches("\\d*")) { throw new Exception("æ°å转æBCDç¼ç æ¶åºéï¼ä¸æ¯åæ³æ°å:" + numStr, null); } int numLen = numStr.length() ; int byteLen = 0 ; if(numLen % 2 == 0){ byteLen = numLen / 2 ; }else{ byteLen = numLen / 2 + 1 ; } int[] tmpInts = new int[byteLen * 2]; int index = numStr.length() - 1; for (int i = 0; i <= tmpInts.length - 1 && index >= 0; i++, index--) { tmpInts[i] = numStr.charAt(index) - '0'; } byte[] bs = new byte[byteLen] ; for (int i = 0, j = 0; i < byteLen; i++, j++) { bs[i] = (byte) (tmpInts[2 * j + 1] * 16 + tmpInts[2 * j]); } return bs ; } /** * * @param numStr * @return */ public static byte[] string2BCD_BE(String numStr) throws Exception{ if (numStr == null || !numStr.matches("\\d*")) { throw new Exception("æ°å转æBCDç¼ç æ¶åºéï¼ä¸æ¯åæ³æ°å:" + numStr, null); } int numLen = numStr.length() ; int byteLen = 0 ; if(numLen % 2 == 0){ byteLen = numLen / 2 ; }else{ byteLen = numLen / 2 + 1 ; } int[] tmpInts = new int[byteLen * 2]; int index = numStr.length() - 1; for (int i = tmpInts.length - 1; i >= 0 && index >= 0; i--, index--) { tmpInts[i] = numStr.charAt(index) - '0'; } byte[] bs = new byte[byteLen] ; for (int i = 0, j = 0; i < byteLen; i++, j++) { bs[i] = (byte) (tmpInts[2 * j] * 16 + tmpInts[2 * j + 1]); } return bs ; } /** * * @param bs * @return */ public static int BCD2Int_LE(byte[] bs){ int num = 0 ; int multiple = 1 ; for(int i = 0; i < bs.length; i++){ num += (((bs[i] >> 4) * 10) + (bs[i] & 0xF)) * multiple ; multiple = multiple * 100 ; } return num ; } /** * * @param bs * @return */ public static int BCD2Int_BE(byte[] bs){ int num = 0 ; int multiple = 1 ; for(int i = bs.length-1; i >= 0 ; i--){ num += (((bs[i] >> 4) * 10) + (bs[i] & 0xF)) * multiple ; multiple = multiple * 100 ; } return num ; } /** * * @param bs * @return */ public static long BCD2Long_LE(byte[] bs){ long num = 0 ; long multiple = 1 ; for(int i = 0; i < bs.length; i++){ num += (((bs[i] >> 4) * 10) + (bs[i] & 0xF)) * multiple ; multiple = multiple * 100 ; } return num ; } /** * * @param bs * @return */ public static long BCD2Long_BE(byte[] bs){ long num = 0 ; long multiple = 1 ; for(int i = bs.length-1; i >= 0 ; i--){ num += (((bs[i] >> 4) * 10) + (bs[i] & 0xF)) * multiple ; multiple = multiple * 100 ; } return num ; } /** * * @param bs * @return */ public static String BCD2String_LE(byte[] bs) throws Exception{ StringBuilder sb = new StringBuilder(); for (int i = (bs.length - 1); i >= 0; i--) { int value = (bs[i] + 256) % 256; sb.append((char) (value / 16 + '0')).append((char) (value % 16 + '0')); } String result = sb.toString(); if (!result.matches("\\d*")) { throw new Exception("è§£ç BCDï¼ä½æ°æ®éBCDç ï¼"); } return result; } /** * * @param bs * @return */ public static String BCD2String_BE(byte[] bs) throws Exception{ StringBuilder sb = new StringBuilder(); for (int i = 0; i < bs.length ; i++) { int value = (bs[i] + 256) % 256; sb.append((char) (value / 16 + '0')).append((char) (value % 16 + '0')); value++; } String result = sb.toString(); if (!result.matches("\\d*")) { throw new Exception("è§£ç BCDï¼ä½æ°æ®ï¼" + result + "éBCDç ï¼"); } return result; } public static void main(String[] args) throws Exception { int num = 1234567; byte[] bs = int2BCD_LE(num) ; int num_ =BCD2Int_LE(bs) ; System.out.println(num_); bs = int2BCD_BE(num) ; num_ = BCD2Int_BE(bs); System.out.println(num_); String str = "12345678901234567890" ; bs = string2BCD_LE(str) ; String str_ = BCD2String_LE(bs) ; System.out.println(str_); bs = string2BCD_BE(str) ; str_ = BCD2String_BE(bs) ; System.out.println(str_); } } pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java
@@ -1059,109 +1059,6 @@ } 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 è¿å 转æ¢åçå符串 // */ // public static String bytesToHex(byte[] bytes) { // //ä¸ä¸ªbyte为8ä½ï¼å¯ç¨ä¸¤ä¸ªåå è¿å¶ä½æ è¯ // char[] buf = new char[bytes.length * 2]; // int a = 0; // int index = 0; // for (byte b : bytes) { // 使ç¨é¤ä¸åä½è¿è¡è½¬æ¢ // 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); // } // /** // * å°byte[]转æ¢ä¸º16è¿å¶å符串 // * // * @param bytes å¾ è½¬æ¢byte[] // * @return è¿å 转æ¢åçå符串 // */ // public static String bytesToHex_BE(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); // } // // /** // * å°byte[]转æ¢ä¸º16è¿å¶å符串 // * // * @param bytes å¾ è½¬æ¢byte[] // * @return è¿å 转æ¢åçå符串 // */ // public static String bytesToHex_LE(byte[] bytes, int startIndex, int endIndex) { // byte[] bs = new byte[endIndex - startIndex + 1] ; // byte j = 0 ; // for(int i = endIndex; i >= startIndex; 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[] // */ // public static byte[] hexToBytes(String str) { // if (str == null || "".equals(str.trim())) { // return new byte[0]; // } // // byte[] bytes = new byte[str.length() / 2]; // for (int i = 0; i < str.length() / 2; i++) { // String subStr = str.substring(i * 2, i * 2 + 2); // bytes[i] = (byte) Integer.parseInt(subStr, 16); // } // // return bytes; // } /** * Convert char to byte * @param c char pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/AdapterImp_TcpUnit.java
@@ -1,9 +1,6 @@ package com.dy.rtuMw.server; import com.dy.common.mw.channel.tcp.PrefixedDataAvailableHandle; import com.dy.common.mw.channel.tcp.TcpConfigVo; import com.dy.common.mw.channel.tcp.TcpIoSessionEventCallback; import com.dy.common.mw.channel.tcp.TcpUnitAdapter; import com.dy.common.mw.channel.tcp.*; import com.dy.common.mw.protocol.PrefixedDataAvailableHandleImp; import com.dy.rtuMw.server.forTcp.TcpIoSessionCallback; @@ -30,4 +27,11 @@ return new TcpIoSessionCallback() ; } /** * 模å忢æ¶çåè° */ @Override public TcpUnitStopCallback newUnitStopCallback() { return new com.dy.rtuMw.server.forTcp.TcpUnitStopCallback() ; } } pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/forTcp/RtuStatusDealer.java
@@ -13,11 +13,11 @@ public static void onOffLine(RtuSessionStatus sta){ StOnOffLine st = new StOnOffLine() ; st.rtuAddr = sta.rtuAddr ; st.onOff_trueFalse = sta.onTrueOffLine ; st.ip = sta.ip ; st.port = sta.port ; // StOnOffLine st = new StOnOffLine() ; // st.rtuAddr = sta.rtuAddr ; // st.onOff_trueFalse = sta.onTrueOffLine ; // st.ip = sta.ip ; // st.port = sta.port ; // if(member == null){ // log.error("åºéï¼æªè½å¾å°å¤çRTUï¼å°å为" + sta.rtuAddr + "ï¼ç¶ææ°æ®çæ°æ®ä¸é´ä»¶ï¼å¯è½æ°æ®ä¸é´ä»¶æªå¯å¨æè±ç¦»çé群ï¼"); @@ -28,11 +28,11 @@ } public static void onLine(String rtuAddr, String ip, Integer port){ StOnOffLine st = new StOnOffLine() ; st.rtuAddr = rtuAddr ; st.onOff_trueFalse = true ; st.ip = ip ; st.port = port ; // StOnOffLine st = new StOnOffLine() ; // st.rtuAddr = rtuAddr ; // st.onOff_trueFalse = true ; // st.ip = ip ; // st.port = port ; // Address member = JgUnit.getInstance().getJgMembers().getDataMwMemberByRtuAddr(rtuAddr) ; // if(member == null){ @@ -44,9 +44,9 @@ } public static void offLine(String rtuAddr){ StOnOffLine st = new StOnOffLine() ; st.rtuAddr = rtuAddr ; st.onOff_trueFalse = false ; // StOnOffLine st = new StOnOffLine() ; // st.rtuAddr = rtuAddr ; // st.onOff_trueFalse = false ; // Address member = JgUnit.getInstance().getJgMembers().getDataMwMemberByRtuAddr(rtuAddr) ; // if(member == null){ @@ -58,10 +58,10 @@ } public static void upData(String rtuAddr, Integer bufferLen){ StUpData st = new StUpData() ; st.rtuAddr = rtuAddr ; st.upBufferLen = bufferLen ; st.isReport = false ; // StUpData st = new StUpData() ; // st.rtuAddr = rtuAddr ; // st.upBufferLen = bufferLen ; // st.isReport = false ; // Address member = JgUnit.getInstance().getJgMembers().getDataMwMemberByRtuAddr(rtuAddr) ; // if(member == null){ @@ -73,10 +73,10 @@ } public static void upReport(String rtuAddr, Integer bufferLen){ StUpData st = new StUpData() ; st.rtuAddr = rtuAddr ; st.upBufferLen = bufferLen ; st.isReport = true ; // StUpData st = new StUpData() ; // st.rtuAddr = rtuAddr ; // st.upBufferLen = bufferLen ; // st.isReport = true ; // Address member = JgUnit.getInstance().getJgMembers().getDataMwMemberByRtuAddr(rtuAddr) ; // if(member == null){ @@ -88,9 +88,9 @@ } public static void downData(String rtuAddr, Integer bufferLen){ StDownData st = new StDownData() ; st.rtuAddr = rtuAddr ; st.downBufferLen = bufferLen ; // StDownData st = new StDownData() ; // st.rtuAddr = rtuAddr ; // st.downBufferLen = bufferLen ; // Address member = JgUnit.getInstance().getJgMembers().getDataMwMemberByRtuAddr(rtuAddr) ; // if(member == null){ @@ -102,9 +102,9 @@ } public static void commandSuccess(String rtuAddr){ StCommandResult st = new StCommandResult() ; st.rtuAddr = rtuAddr ; st.isSuccess = true ; // StCommandResult st = new StCommandResult() ; // st.rtuAddr = rtuAddr ; // st.isSuccess = true ; // Address member = JgUnit.getInstance().getJgMembers().getDataMwMemberByRtuAddr(rtuAddr) ; // if(member == null){ @@ -116,9 +116,9 @@ } public static void commandFailure(String rtuAddr){ StCommandResult st = new StCommandResult() ; st.rtuAddr = rtuAddr ; st.isSuccess = false ; // StCommandResult st = new StCommandResult() ; // st.rtuAddr = rtuAddr ; // st.isSuccess = false ; // Address member = JgUnit.getInstance().getJgMembers().getDataMwMemberByRtuAddr(rtuAddr) ; // if(member == null){ @@ -130,9 +130,9 @@ } public static void commandFail2Success(String rtuAddr){ StCommandResult st = new StCommandResult() ; st.rtuAddr = rtuAddr ; st.fail2Success = true ; // StCommandResult st = new StCommandResult() ; // st.rtuAddr = rtuAddr ; // st.fail2Success = true ; // Address member = JgUnit.getInstance().getJgMembers().getDataMwMemberByRtuAddr(rtuAddr) ; // if(member == null){ pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/forTcp/TcpSessionCache.java
@@ -23,7 +23,20 @@ * 2023-12-19宿µï¼åç°Hashtableå¹¶ä¸çº¿ç¨å®å ¨ï¼æä»¥åºç¨äºHashMapåsynchronized */ private static HashMap<String, TcpSession> sessionTable = new HashMap<String, TcpSession>() ; /** * å ³éææç½ç»è¿æ¥ */ public static void closeAllSessions(){ synchronized (sessionTable){ Collection<TcpSession> col = sessionTable.values() ; for(TcpSession se : col){ se.ioSession.closeNow() ; } sessionTable.clear(); } } /** * å å ¥æ°çIoSession * @param rtuAddr pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/forTcp/TcpUnitStopCallback.java
New file @@ -0,0 +1,13 @@ package com.dy.rtuMw.server.forTcp; /** * @Author: liurunyu * @Date: 2024/7/29 9:26 * @Description */ public class TcpUnitStopCallback implements com.dy.common.mw.channel.tcp.TcpUnitStopCallback{ @Override public void callback() { TcpSessionCache.closeAllSessions(); } } pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/CommandInnerDeaLer.java
@@ -1,5 +1,7 @@ package com.dy.rtuMw.server.local; import com.dy.common.mw.UnitStartedCallbackInterface; import com.dy.common.mw.channel.tcp.TcpUnit; import com.dy.common.mw.protocol.Command; import com.dy.rtuMw.server.local.localProtocol.*; @@ -23,6 +25,10 @@ return this.onLine(com) ; }else if(code.equals(CodeLocal.allProtocols)){ return this.allProtocols(com) ; }else if(code.equals(CodeLocal.stopTcpSv)){ return this.stopTcpSv(com) ; }else if(code.equals(CodeLocal.recoverTcpSv)){ return this.recoverTcpSv(com) ; } return ReturnCommand.errored("åºéï¼æ¶å°å é¨å½ä»¤çåè½ç ä¸è½è¯å«ï¼", com.getId(), com.getCode()) ; } @@ -54,4 +60,28 @@ return ReturnCommand.successed("æ¥è¯¢ææéä¿¡åè®®é ç½®", command.getId(), command.getCode(), mc) ; } /** * 忢TCPæå¡ï¼ä¸åæ¥å ¥æ°çTCPè¿æ¥ï¼å·²ç»TCPè¿æ¥çå ¨é¨æè¿æ¥ * @throws Exception */ private Command stopTcpSv(Command command) throws Exception{ TcpUnit.getInstance().stop(new UnitStartedCallbackInterface(){ public void call(Object obj) throws Exception { } }); return ReturnCommand.successed("å·²ç»å¯å¨åæ¢TCPæå¡", command.getId(), command.getCode(), null) ; } /** * æ¢å¤TCPæå¡ï¼æ¥å ¥æ°çTCPè¿æ¥ * @throws Exception */ private Command recoverTcpSv(Command command) throws Exception{ TcpUnit.getInstance().recover(); return ReturnCommand.successed("å·²ç»å¯å¨æ¢å¤TCPæå¡", command.getId(), command.getCode(), null) ; } } pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/local/localProtocol/CodeLocal.java
@@ -8,4 +8,7 @@ public static final String allProtocols = "LCD0100" ;//æ¥è¯¢ææåè®®é ç½® public static final String stopTcpSv = "LCD0110" ;//忢TCPæå¡ï¼ä¸åæ¥å ¥æ°çTCPè¿æ¥ï¼å·²ç»TCPè¿æ¥çå ¨é¨æè¿æ¥ public static final String recoverTcpSv = "LCD0112" ;//éå¯TCPæå¡ï¼æ¥å ¥æ°çTCPè¿æ¥ } pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/common/CodeLocal.java
@@ -8,4 +8,7 @@ public static final String allProtocols = "LCD0100" ;//æ¥è¯¢ææåè®®é ç½® public static final String stopTcpSv = "LCD0110" ;//忢TCPæå¡ï¼ä¸åæ¥å ¥æ°çTCPè¿æ¥ï¼å·²ç»TCPè¿æ¥çå ¨é¨æè¿æ¥ public static final String recoverTcpSv = "LCD0112" ;//æ¢å¤TCPæå¡ï¼æ¥å ¥æ°çTCPè¿æ¥ } pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/p206V1_0_0/ComSupportP206V1_0_0.java
@@ -34,7 +34,22 @@ private RestTemplate restTemplate; protected Command command(String code, Object param, String comId){ protected Command commandLocal(String code, Object param, String comId){ Command com = new Command() ; com.id = comId==null?Command.defaultId:(comId.trim().equals("")?Command.defaultId:comId) ;//å®é åºç¨ä¸ï¼æ¿æ¢ææ°æ®åºè®°å½id com.protocol = ProtocolConstantV206V1_0_0.protocolName ; com.code = code ; com.rtuAddr = rtuAddr ; com.type = CommandType.innerCommand ; com.rtuResultSendWebUrl = rtuResultSendWebUrl ; com.param = param ; return com ; } protected Command commandOuter(String code, Object param, String comId){ Command com = new Command() ; com.id = comId==null?Command.defaultId:(comId.trim().equals("")?Command.defaultId:comId) ;//å®é åºç¨ä¸ï¼æ¿æ¢ææ°æ®åºè®°å½id com.protocol = ProtocolConstantV206V1_0_0.protocolName ; @@ -48,6 +63,7 @@ return com ; } /** * è¿æ¥éä¿¡ä¸é´ä»¶æµè¯ * @return pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/p206V1_0_0/CommandP206V1_0_0Ctrl.java
@@ -31,7 +31,11 @@ rt = this.connect() ;//è¿æ¥éä¿¡ä¸é´ä»¶æµè¯ }else{ try{ if(com.equals("10")){ if(com.equals(CodeLocal.stopTcpSv)){ rt = this.stopTcpSv() ; }else if(com.equals(CodeLocal.recoverTcpSv)){ rt = this.recoverTcpSv() ; }else if(com.equals("10")){ rt = this.cd10() ; }else if(com.equals("21")){ rt = this.cd21() ; @@ -96,89 +100,97 @@ return this.sendTest() ; } private BaseResponse stopTcpSv(){ return this.sendCom2Mw(this.commandLocal(CodeLocal.stopTcpSv, null, null)) ; } private BaseResponse recoverTcpSv(){ return this.sendCom2Mw(this.commandLocal(CodeLocal.recoverTcpSv, null, null)) ; } private BaseResponse cd10(){ Com10Vo comVo = new Com10Vo() ; comVo.rtuAddr = "532328059995" ;//å6使¯è¡æ¿åºåç ï¼å6使¯åºå巿大æ¯065535 return this.sendCom2Mw(this.command(CodeV1_0_1.cd_10, comVo, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_10, comVo, null)) ; } private BaseResponse cd21(){ Com21Vo comVo = new Com21Vo() ; comVo.ip = "8.140.180.59" ;//IPï¼ä¾å¦ 125.235.35.89ï¼ comVo.port = 6001 ;///端å£å·ï¼0~65536ï¼ return this.sendCom2Mw(this.command(CodeV1_0_1.cd_21, comVo, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_21, comVo, null)) ; } private BaseResponse cd37(){ Com37Vo comVo = new Com37Vo() ; comVo.seconds = 20 ;//åä½ç§ return this.sendCom2Mw(this.command(CodeV1_0_1.cd_37, comVo, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_37, comVo, null)) ; } private BaseResponse cd67(){ Com37Vo comVo = new Com37Vo() ; return this.sendCom2Mw(this.command(CodeV1_0_1.cd_67, comVo, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_67, comVo, null)) ; } private BaseResponse cd38(){ Com38Vo comVo = new Com38Vo() ; comVo.remainMoneyAlarm = 10.0 ;//ç¨æ·ä½é¢æ¥è¦å¼(大äº1.0) return this.sendCom2Mw(this.command(CodeV1_0_1.cd_38, comVo, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_38, comVo, null)) ; } private BaseResponse cd68(){ return this.sendCom2Mw(this.command(CodeV1_0_1.cd_68, null, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_68, null, null)) ; } private BaseResponse cd39(){ Com39Vo comVo = new Com39Vo() ; comVo.batteryVoltAlarm = 7.0 ;//çµæ± çµåæ¥è¦å¼(大äº0.1) return this.sendCom2Mw(this.command(CodeV1_0_1.cd_39, comVo, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_39, comVo, null)) ; } private BaseResponse cd69(){ return this.sendCom2Mw(this.command(CodeV1_0_1.cd_69, null, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_69, null, null)) ; } private BaseResponse cd3A(){ Com3AVo comVo = new Com3AVo() ; comVo.current = 1.0 ;//éé¨å µè½¬çµæµ(大äº0) return this.sendCom2Mw(this.command(CodeV1_0_1.cd_3A, comVo, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_3A, comVo, null)) ; } private BaseResponse cd6A(){ return this.sendCom2Mw(this.command(CodeV1_0_1.cd_6A, null, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_6A, null, null)) ; } private BaseResponse cd3B(){ Com3BVo comVo = new Com3BVo() ; comVo.second = 120 ;//éé¨è¶ æ¶æ¶é´(ç§)(大äº1) return this.sendCom2Mw(this.command(CodeV1_0_1.cd_3B, comVo, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_3B, comVo, null)) ; } private BaseResponse cd6B(){ return this.sendCom2Mw(this.command(CodeV1_0_1.cd_6B, null, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_6B, null, null)) ; } private BaseResponse cd3C(){ Com3CVo comVo = new Com3CVo() ; comVo.minute = 5 ; return this.sendCom2Mw(this.command(CodeV1_0_1.cd_3C, comVo, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_3C, comVo, null)) ; } private BaseResponse cd65(){ return this.sendCom2Mw(this.command(CodeV1_0_1.cd_65, null, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_65, null, null)) ; } private BaseResponse<String> cd91() { return this.sendCom2Mw(this.command(CodeV1_0_1.cd_91, null, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_91, null, null)) ; } private BaseResponse cd92(){ return this.sendCom2Mw(this.command(CodeV1_0_1.cd_92, null, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_92, null, null)) ; } private BaseResponse cd93(){ return this.sendCom2Mw(this.command(CodeV1_0_1.cd_93, null, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_93, null, null)) ; } //APPè¿ç¨å¼é @@ -187,13 +199,13 @@ comVo.icCardNo = CommandP206V1_0_0Ctrl.vsIcCardNo; comVo.moneyRemain = 234.56 ; comVo.waterPrice = 1.2 ; return this.sendCom2Mw(this.command(CodeV1_0_1.cd_97, comVo, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_97, comVo, null)) ; } //APPè¿ç¨å ³é private BaseResponse cd98(){ Com98Vo comVo = new Com98Vo() ; comVo.icCardNo = CommandP206V1_0_0Ctrl.vsIcCardNo; return this.sendCom2Mw(this.command(CodeV1_0_1.cd_98, comVo, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_98, comVo, null)) ; } //宿¶å ³éå¼é @@ -203,7 +215,7 @@ comVo.moneyRemain = 234.56 ; comVo.waterPrice = 1.2 ; comVo.minutes = 3 ; return this.sendCom2Mw(this.command(CodeV1_0_1.cd_99, comVo, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_99, comVo, null)) ; } //å®éå ³éå¼é @@ -213,7 +225,7 @@ comVo.moneyRemain = 234.56 ; comVo.waterPrice = 1.2 ; comVo.waterAmount = 10 ; return this.sendCom2Mw(this.command(CodeV1_0_1.cd_A0, comVo, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_A0, comVo, null)) ; } @@ -231,7 +243,7 @@ comVo.day = nextDt[2] ; comVo.hour = nextDt[3] ; comVo.minute = nextDt[4] ; return this.sendCom2Mw(this.command(CodeV1_0_1.cd_A1, comVo, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_A1, comVo, null)) ; } //å®éå ³é计åå¼é @@ -248,12 +260,12 @@ comVo.day = nextDt[2] ; comVo.hour = nextDt[3] ; comVo.minute = nextDt[4] ; return this.sendCom2Mw(this.command(CodeV1_0_1.cd_A2, comVo, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_A2, comVo, null)) ; } private BaseResponse cdB0(){ return this.sendCom2Mw(this.command(CodeV1_0_1.cd_B0, null, null)) ; return this.sendCom2Mw(this.commandOuter(CodeV1_0_1.cd_B0, null, null)) ; } //å¨çº¿æ åµ pipIrr-platform/Îĵµ/MybatisCodeHelper²å¼þ¹ºÂò.docxBinary files differ