Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1.parse; |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1.CodeV1; |
| | | import com.dy.common.mw.protocol.p206V1.CommonV1; |
| | | import com.dy.common.mw.protocol.p206V1.ParseParamsForDownV1; |
| | | import com.dy.common.mw.protocol.p206V1.ProtocolConstantV206V1; |
| | | import com.dy.common.mw.protocol.p206V1.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | |
| | | /** |
| | | * @Author liurunyu |
| | | * @Date 2025/5/8 10:36 |
| | | * @LastEditTime 2025/5/8 10:36 |
| | | * @Description |
| | | */ |
| | | @AnnotationCodeDown(ifAny={ |
| | | CodeV1.cd_50 |
| | | }) |
| | | public class Cd_50_Down implements CodeParse { |
| | | |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback) throws Exception { |
| | | ParseParamsForDownV1 para = (ParseParamsForDownV1) params ; |
| | | byte[] bs = this.doParse(para) ; |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.rtuResultSendWebUrl = para.rtuResultSendWebUrl ;//rtu返回命令结果 发向目的地web URL |
| | | midRs.protocolName = para.protocolName ;//协议名称 |
| | | midRs.protocolVersion = para.protocolVersion ;//协议版本号 |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtu地址 |
| | | midRs.commandId = para.commandId ;//命令ID,发起命令的客户端(web端)生成,以匹配命令结果 |
| | | midRs.downCode = para.commandCode ;//下行命令功能码; |
| | | midRs.downCodeName = CodeV1.getCodeName(para.commandCode) ;//下行命令功能码名称; |
| | | midRs.downBuffer = bs ;//下行命令数据 |
| | | midRs.downBufHex = ByteUtil.bytes2Hex(bs, true) ;//下行命令数据十六进制形式 |
| | | midRs.hasResponse = true ;//是否有应答 |
| | | midRs.maxSendTimes = null ;//命令最大发送次数(当收不到应答时,将重发),如果不设置,命令缓存器进行补充设置 |
| | | midRs.isCachForOffLine = false ;//RTU不在线,命令是否缓存,低功耗时为true |
| | | |
| | | if(isLowPower != null && isLowPower.booleanValue()){ |
| | | //低功耗时,尽快发送 |
| | | midRs.isQuickSend = true ; |
| | | } |
| | | |
| | | return new MidResult[]{midRs} ; |
| | | } |
| | | |
| | | /** |
| | | * 构造下行数据 |
| | | * @param para 参数 |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public byte[] doParse(ParseParamsForDownV1 para) throws Exception { |
| | | CommonV1 commonV_1 = new CommonV1() ; |
| | | byte[] bytes ; |
| | | byte[] bsHead = new byte[ProtocolConstantV206V1.lenHead2Code] ; |
| | | byte index = 0 ; |
| | | bsHead[index] = ProtocolConstantV206V1.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = 0 ;//帧长度 |
| | | |
| | | index++ ; |
| | | bsHead[index] = ProtocolConstantV206V1.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV_1.createCtrl((byte)0, (byte)0) ; |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr4P206(para.rtuAddr, bsHead, index); |
| | | index += 5 ; |
| | | |
| | | ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; |
| | | |
| | | bytes = bsHead ; |
| | | |
| | | GlCreate.createLen(bytes);//长度放字节数组中 |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC和尾叠加字节数组中 |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1.parse; |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1.*; |
| | | import com.dy.common.mw.protocol.p206V1.upVos.DataCd50Vo; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | /** |
| | | * @Author liurunyu |
| | | * @Date 2025/5/8 10:37 |
| | | * @LastEditTime 2025/5/8 10:37 |
| | | * @Description |
| | | */ |
| | | @AnnotationCodeUp(ifAny={ |
| | | CodeV1.cd_50 |
| | | }) |
| | | public class Cd_50_Up implements CodeParse { |
| | | |
| | | private static final Logger log = LogManager.getLogger(Cd_50_Up.class); |
| | | |
| | | /** |
| | | * 分析上行数据 |
| | | */ |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback)throws Exception { |
| | | ParseParamsForUpV1 para = (ParseParamsForUpV1)params ; |
| | | int bsLen = new CommonV1().parseDataLen4P206(para.upBuffer) ; |
| | | if(bsLen > 0){ |
| | | this.doParse(para.upBuffer, |
| | | bsLen, |
| | | para.upCode, |
| | | para.data) ; |
| | | } |
| | | log.info("\n分析命令应答数据<" + CodeV1.getCodeName(para.upCode) + " RTU地址=" + para.rtuAddr + ">:\n" + para.data.toString()); |
| | | |
| | | MidResultFromRtu midRs = new MidResultFromRtu() ; |
| | | midRs.protocolName = para.protocolName ;//协议名称 |
| | | midRs.protocolVersion = para.protocolVersion ;//协议版本号 |
| | | 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, para.data.subData==null?null:((DataV1)(para.data.subData)).subData); |
| | | 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 dV1 = (DataV1)data.getSubData() ; |
| | | DataCd50Vo cdData = new DataCd50Vo() ; |
| | | dV1.subData = cdData ; |
| | | cdData.rtuAddr = new CommonV1().parseRtuAddr(bs, ProtocolConstantV206V1.dataIndex, true) ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1.upVos; |
| | | |
| | | import com.dy.common.mw.protocol.UpComResVo; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @Author liurunyu |
| | | * @Date 2025/5/8 10:37 |
| | | * @LastEditTime 2025/5/8 10:37 |
| | | * @Description |
| | | */ |
| | | @Data |
| | | public class DataCd50Vo implements UpComResVo { |
| | | public String rtuAddr ; |
| | | |
| | | public String toString(){ |
| | | StringBuilder sb = new StringBuilder() ; |
| | | sb.append(" 查询RTU地址应答:\n"); |
| | | sb.append(" 新地址:"); |
| | | sb.append(rtuAddr); |
| | | sb.append("\n"); |
| | | |
| | | return sb.toString() ; |
| | | } |
| | | |
| | | public String comLog(){ |
| | | StringBuilder sb = new StringBuilder() ; |
| | | sb.append("查询RTU地址命令回复:\n"); |
| | | sb.append(" 地址:"); |
| | | sb.append(rtuAddr); |
| | | sb.append("\n"); |
| | | return sb.toString() ; |
| | | } |
| | | |
| | | @Override |
| | | public String comLog(String code) { |
| | | return null; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V2.parse; |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V2.CodeV2; |
| | | import com.dy.common.mw.protocol.p206V2.CommonV2; |
| | | import com.dy.common.mw.protocol.p206V2.ParseParamsForDownV2; |
| | | import com.dy.common.mw.protocol.p206V2.ProtocolConstantV206V2; |
| | | import com.dy.common.mw.protocol.p206V2.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | |
| | | /** |
| | | * @Author liurunyu |
| | | * @Date 2025/5/8 10:36 |
| | | * @LastEditTime 2025/5/8 10:36 |
| | | * @Description |
| | | */ |
| | | @AnnotationCodeDown(ifAny={ |
| | | CodeV2.cd_50 |
| | | }) |
| | | public class Cd_50_Down implements CodeParse { |
| | | |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback) throws Exception { |
| | | ParseParamsForDownV2 para = (ParseParamsForDownV2) params ; |
| | | byte[] bs = this.doParse(para) ; |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.rtuResultSendWebUrl = para.rtuResultSendWebUrl ;//rtu返回命令结果 发向目的地web URL |
| | | midRs.protocolName = para.protocolName ;//协议名称 |
| | | midRs.protocolVersion = para.protocolVersion ;//协议版本号 |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtu地址 |
| | | midRs.commandId = para.commandId ;//命令ID,发起命令的客户端(web端)生成,以匹配命令结果 |
| | | midRs.downCode = para.commandCode ;//下行命令功能码; |
| | | midRs.downCodeName = CodeV2.getCodeName(para.commandCode) ;//下行命令功能码名称; |
| | | midRs.downBuffer = bs ;//下行命令数据 |
| | | midRs.downBufHex = ByteUtil.bytes2Hex(bs, true) ;//下行命令数据十六进制形式 |
| | | midRs.hasResponse = true ;//是否有应答 |
| | | midRs.maxSendTimes = null ;//命令最大发送次数(当收不到应答时,将重发),如果不设置,命令缓存器进行补充设置 |
| | | midRs.isCachForOffLine = false ;//RTU不在线,命令是否缓存,低功耗时为true |
| | | |
| | | if(isLowPower != null && isLowPower.booleanValue()){ |
| | | //低功耗时,尽快发送 |
| | | midRs.isQuickSend = true ; |
| | | } |
| | | |
| | | return new MidResult[]{midRs} ; |
| | | } |
| | | |
| | | /** |
| | | * 构造下行数据 |
| | | * @param para 参数 |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public byte[] doParse(ParseParamsForDownV2 para) throws Exception { |
| | | CommonV2 commonV_1 = new CommonV2() ; |
| | | byte[] bytes ; |
| | | byte[] bsHead = new byte[ProtocolConstantV206V2.lenHead2Code] ; |
| | | byte index = GlCreate.createHead(para.protocolVersion, bsHead); |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV_1.createCtrl((byte)0, (byte)0) ; |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr4P206(para.rtuAddr, bsHead, index); |
| | | index += 5 ; |
| | | |
| | | ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; |
| | | |
| | | bytes = bsHead ; |
| | | |
| | | GlCreate.createLen(bytes);//长度放字节数组中 |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC和尾叠加字节数组中 |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V2.parse; |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V2.*; |
| | | import com.dy.common.mw.protocol.p206V2.upVos.DataCd10Vo; |
| | | import com.dy.common.mw.protocol.p206V2.upVos.DataCd50Vo; |
| | | import com.dy.common.mw.protocol.p206V2.upVos.DataCd51Vo; |
| | | import com.dy.common.mw.protocol.p206V202404.parse.global.GlParse; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | /** |
| | | * @Author liurunyu |
| | | * @Date 2025/5/8 10:37 |
| | | * @LastEditTime 2025/5/8 10:37 |
| | | * @Description |
| | | */ |
| | | @AnnotationCodeUp(ifAny={ |
| | | CodeV2.cd_50 |
| | | }) |
| | | public class Cd_50_Up implements CodeParse { |
| | | |
| | | private static final Logger log = LogManager.getLogger(Cd_50_Up.class); |
| | | |
| | | /** |
| | | * 分析上行数据 |
| | | */ |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback)throws Exception { |
| | | ParseParamsForUpV2 para = (ParseParamsForUpV2)params ; |
| | | int bsLen = new CommonV2().parseDataLen4P206(para.upBuffer) ; |
| | | if(bsLen > 0){ |
| | | this.doParse(para.upBuffer, |
| | | bsLen, |
| | | para.upCode, |
| | | para.data) ; |
| | | } |
| | | log.info("\n分析命令应答数据<" + CodeV2.getCodeName(para.upCode) + " RTU地址=" + para.rtuAddr + ">:\n" + para.data.toString()); |
| | | |
| | | MidResultFromRtu midRs = new MidResultFromRtu() ; |
| | | midRs.protocolName = para.protocolName ;//协议名称 |
| | | midRs.protocolVersion = para.protocolVersion ;//协议版本号 |
| | | 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, para.data.subData==null?null:((DataV2)(para.data.subData)).subData); |
| | | 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 { |
| | | DataV2 dV2 = (DataV2)data.getSubData() ; |
| | | DataCd50Vo cdData = new DataCd50Vo() ; |
| | | dV2.subData = cdData ; |
| | | cdData.rtuAddr = new CommonV2().parseRtuAddr(bs, ProtocolConstantV206V2.dataIndex) ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V2.upVos; |
| | | |
| | | import com.dy.common.mw.protocol.UpComResVo; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @Author liurunyu |
| | | * @Date 2025/5/8 10:37 |
| | | * @LastEditTime 2025/5/8 10:37 |
| | | * @Description |
| | | */ |
| | | @Data |
| | | public class DataCd50Vo implements UpComResVo { |
| | | public String rtuAddr ; |
| | | |
| | | public String toString(){ |
| | | StringBuilder sb = new StringBuilder() ; |
| | | sb.append(" 查询RTU地址应答:\n"); |
| | | sb.append(" 新地址:"); |
| | | sb.append(rtuAddr); |
| | | sb.append("\n"); |
| | | |
| | | return sb.toString() ; |
| | | } |
| | | |
| | | public String comLog(){ |
| | | StringBuilder sb = new StringBuilder() ; |
| | | sb.append("查询RTU地址命令回复:\n"); |
| | | sb.append(" 地址:"); |
| | | sb.append(rtuAddr); |
| | | sb.append("\n"); |
| | | return sb.toString() ; |
| | | } |
| | | |
| | | @Override |
| | | public String comLog(String code) { |
| | | return null; |
| | | } |
| | | } |
| | |
| | | char[] password = console.readPassword(">>Password: "); |
| | | String passwordStr = String.valueOf(password) ; |
| | | if (passwordStr.equals("help")) { |
| | | console.printf("密码是%1$s.\n", myPassword); |
| | | console.printf("密码是%1$s\n", myPassword); |
| | | // 使用后应立即将数组清空,以减少其在内存中占用的时间,增强安全性 |
| | | password = null; |
| | | } else if(passwordStr.equals(myPassword)){ |
| | |
| | | |
| | | protected static final byte CTRL = (byte)0xB0 ;//控制域 |
| | | |
| | | /** |
| | | * 检查命令参数 |
| | | * @return 信息 |
| | | */ |
| | | public abstract String checkParams(String ...params) ; |
| | | /** |
| | | * 命令帮助信息 |
| | | * @return 信息 |
| | | */ |
| | | public abstract String helpInfo() ; |
| | | /** |
| | | * 构造命令数据(十六进制) |
| | | * @return 字符串 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public abstract String hex(String rtuAddr, String ...params) throws Exception ; |
| | | /** |
| | | * 构造命令数据(字节数组) |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public abstract byte[] bs(String rtuAddr, String ...params) throws Exception ; |
| | | |
| | | public byte[] createHead(String rtuAddr, String code, byte ctrl)throws Exception { |
| | |
| | | return ComCode + "[Enter](心跳命令应答(链路维持报应答))" ; |
| | | } |
| | | /** |
| | | * 构造心跳数据 |
| | | * @return 字节数组 |
| | | * 构造命令数据(十六进制) |
| | | * @return 字符串 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public String hex(String rtuAddr, String ...params) throws Exception { |
| | | byte[] bytes = bs(rtuAddr, params) ; |
| | | String hex = ByteUtil.bytes2Hex(bytes, false) ; |
| | | return hex ; |
| | | return ByteUtil.bytes2Hex(bytes, false) ; |
| | | } |
| | | |
| | | /** |
| | | * 构造心跳数据 |
| | | * 构造命令数据(字节数组) |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | |
| | | return ComCode + " *...*[Enter](设置控制器地址)" ; |
| | | } |
| | | /** |
| | | * 构造心跳数据 |
| | | * @return 字节数组 |
| | | * 构造命令数据(十六进制) |
| | | * @return 字符串 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public String hex(String rtuAddr, String ...params) throws Exception { |
| | | byte[] bytes = bs(rtuAddr, params) ; |
| | | String hex = ByteUtil.bytes2Hex(bytes, false) ; |
| | | return hex ; |
| | | return ByteUtil.bytes2Hex(bytes, false) ; |
| | | } |
| | | |
| | | /** |
| | | * 构造心跳数据 |
| | | * 构造命令数据(字节数组) |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | |
| | | return ComCode + " *...* *...*[Enter](设置服务端IP和端口)" ; |
| | | } |
| | | /** |
| | | * 构造心跳数据 |
| | | * @return 字节数组 |
| | | * 构造命令数据(十六进制) |
| | | * @return 字符串 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public String hex(String rtuAddr, String ...params) throws Exception { |
| | | byte[] bytes = bs(rtuAddr, params) ; |
| | | String hex = ByteUtil.bytes2Hex(bytes, false) ; |
| | | return hex ; |
| | | return ByteUtil.bytes2Hex(bytes, false) ; |
| | | } |
| | | |
| | | /** |
| | | * 构造心跳数据 |
| | | * 构造命令数据(字节数组) |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | |
| | | return ComCode + " *...*[Enter](设置流量采集周期)" ; |
| | | } |
| | | /** |
| | | * 构造心跳数据 |
| | | * @return 字节数组 |
| | | * 构造命令数据(十六进制) |
| | | * @return 字符串 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public String hex(String rtuAddr, String ...params) throws Exception { |
| | | byte[] bytes = bs(rtuAddr, params) ; |
| | | String hex = ByteUtil.bytes2Hex(bytes, false) ; |
| | | return hex ; |
| | | return ByteUtil.bytes2Hex(bytes, false) ; |
| | | } |
| | | |
| | | /** |
| | | * 构造心跳数据 |
| | | * 构造命令数据(字节数组) |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | |
| | | return ComCode + " *...*[Enter](设置自报周期)" ; |
| | | } |
| | | /** |
| | | * 构造心跳数据 |
| | | * @return 字节数组 |
| | | * 构造命令数据(十六进制) |
| | | * @return 字符串 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public String hex(String rtuAddr, String ...params) throws Exception { |
| | | byte[] bytes = bs(rtuAddr, params) ; |
| | | String hex = ByteUtil.bytes2Hex(bytes, false) ; |
| | | return hex ; |
| | | return ByteUtil.bytes2Hex(bytes, false) ; |
| | | } |
| | | |
| | | /** |
| | | * 构造心跳数据 |
| | | * 构造命令数据(字节数组) |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | |
| | | return ComCode + "[Enter](查询控制器地址)" ; |
| | | } |
| | | /** |
| | | * 构造心跳数据 |
| | | * @return 字节数组 |
| | | * 构造命令数据(十六进制) |
| | | * @return 字符串 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public String hex(String rtuAddr, String ...params) throws Exception { |
| | | byte[] bytes = bs(rtuAddr, params) ; |
| | | String hex = ByteUtil.bytes2Hex(bytes, false) ; |
| | | return hex ; |
| | | return ByteUtil.bytes2Hex(bytes, false) ; |
| | | } |
| | | |
| | | /** |
| | | * 构造心跳数据 |
| | | * 构造命令数据(字节数组) |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | |
| | | return ComCode + "[Enter](查询自报周期)" ; |
| | | } |
| | | /** |
| | | * 构造心跳数据 |
| | | * @return 字节数组 |
| | | * 构造命令数据(十六进制) |
| | | * @return 字符串 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public String hex(String rtuAddr, String ...params) throws Exception { |
| | | byte[] bytes = bs(rtuAddr, params) ; |
| | | String hex = ByteUtil.bytes2Hex(bytes, false) ; |
| | | return hex ; |
| | | return ByteUtil.bytes2Hex(bytes, false) ; |
| | | } |
| | | |
| | | /** |
| | | * 构造心跳数据 |
| | | * 构造命令数据(字节数组) |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | |
| | | return ComCode + "[Enter](查询服务端IP和端口)" ; |
| | | } |
| | | /** |
| | | * 构造心跳数据 |
| | | * @return 字节数组 |
| | | * 构造命令数据(十六进制) |
| | | * @return 字符串 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public String hex(String rtuAddr, String ...params) throws Exception { |
| | | byte[] bytes = bs(rtuAddr, params) ; |
| | | String hex = ByteUtil.bytes2Hex(bytes, false) ; |
| | | return hex ; |
| | | return ByteUtil.bytes2Hex(bytes, false) ; |
| | | } |
| | | |
| | | /** |
| | | * 构造心跳数据 |
| | | * 构造命令数据(字节数组) |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | |
| | | return ComCode + "[Enter](查询查询流量采集周期)" ; |
| | | } |
| | | /** |
| | | * 构造心跳数据 |
| | | * @return 字节数组 |
| | | * 构造命令数据(十六进制) |
| | | * @return 字符串 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public String hex(String rtuAddr, String ...params) throws Exception { |
| | | byte[] bytes = bs(rtuAddr, params) ; |
| | | String hex = ByteUtil.bytes2Hex(bytes, false) ; |
| | | return hex ; |
| | | return ByteUtil.bytes2Hex(bytes, false) ; |
| | | } |
| | | |
| | | /** |
| | | * 构造心跳数据 |
| | | * 构造命令数据(字节数组) |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | |
| | | return ComCode + "[Enter](清空历史记录)" ; |
| | | } |
| | | /** |
| | | * 构造心跳数据 |
| | | * @return 字节数组 |
| | | * 构造命令数据(十六进制) |
| | | * @return 字符串 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public String hex(String rtuAddr, String ...params) throws Exception { |
| | | byte[] bytes = bs(rtuAddr, params) ; |
| | | String hex = ByteUtil.bytes2Hex(bytes, false) ; |
| | | return hex ; |
| | | return ByteUtil.bytes2Hex(bytes, false) ; |
| | | } |
| | | |
| | | /** |
| | | * 构造心跳数据 |
| | | * 构造命令数据(字节数组) |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | |
| | | return ComCode + "[Enter](平台远程开启阀门)" ; |
| | | } |
| | | /** |
| | | * 构造心跳数据 |
| | | * @return 字节数组 |
| | | * 构造命令数据(十六进制) |
| | | * @return 字符串 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public String hex(String rtuAddr, String ...params) throws Exception { |
| | | byte[] bytes = bs(rtuAddr,params) ; |
| | | String hex = ByteUtil.bytes2Hex(bytes, false) ; |
| | | return hex ; |
| | | byte[] bytes = bs(rtuAddr, params) ; |
| | | return ByteUtil.bytes2Hex(bytes, false) ; |
| | | } |
| | | |
| | | /** |
| | | * 构造心跳数据 |
| | | * 构造命令数据(字节数组) |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | |
| | | return ComCode + "[Enter](平台远程关闭阀门)" ; |
| | | } |
| | | /** |
| | | * 构造心跳数据 |
| | | * @return 字节数组 |
| | | * 构造命令数据(十六进制) |
| | | * @return 字符串 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public String hex(String rtuAddr, String ...params) throws Exception { |
| | | byte[] bytes = bs(rtuAddr, params) ; |
| | | String hex = ByteUtil.bytes2Hex(bytes, false) ; |
| | | return hex ; |
| | | return ByteUtil.bytes2Hex(bytes, false) ; |
| | | } |
| | | |
| | | /** |
| | | * 构造心跳数据 |
| | | * 构造命令数据(字节数组) |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | |
| | | } |
| | | } |
| | | |
| | | private static void cd02(List<String> comList, PrintWriter prtWrt)throws Exception{ |
| | | P206V1Cd cd = new P206V1Cd02() ; |
| | | if(comList.size() > 1){ |
| | | String p = comList.get(1); |
| | | if(p.equals("-h")){ |
| | | prtWrt.println(cd.helpInfo()); |
| | | }else{ |
| | | Command.outNoIdentify(prtWrt) ; |
| | | } |
| | | }else{ |
| | | Command.out(cd.hex(ServerProperties.rtuAddr), prtWrt); |
| | | } |
| | | } |
| | | |
| | | private static void cdWithoutParam(P206V1Cd cd, List<String> comList, PrintWriter prtWrt)throws Exception{ |
| | | if(comList.size() > 1){ |
| | | String p = comList.get(1); |
| | |
| | | devtools: |
| | | livereload: |
| | | enabled: false |
| | | |
| | | #禁输出springboot标志信息 |
| | | management: |
| | | endpoints: |
| | | info: |
| | | enabled: false |
| | | web: |
| | | exposure: |
| | | include: "*" |
| | | main: |
| | | banner-mode: off #Spring Boot启动时禁输出Banner |
| | |
| | | "com.dy.common.aop..*", |
| | | "com.dy.common.apiDoc..*", |
| | | "com.dy.common.multiDataSource..*", |
| | | "com.dy.common.mybatis..*", |
| | | "com.dy.common.singleDataSource..*", |
| | | "com.dy.common.mybatis..*", |
| | | "com.dy.common.webFilter..*", |
| | | "com.dy.common.webListener..*", |
| | | "com.dy.pipIrrGlobal.config..*", |
| | | "com.dy.pipIrrGlobal.webCtrls..*" |
| | | }) |
| | | } |
| | |
| | | } |
| | | } |
| | | private void dealP206V1(byte[] bs){ |
| | | //应该是链路检测数据 |
| | | String cdPre = ByteUtil.bytes2Hex(bs, false, ProtocolConstantV206V1.codeIndex, 1); |
| | | if(cdPre.equals("50")){ |
| | | UpCd50.upData() ; |
| | | }else if(cdPre.equals("66")){ |
| | | UpCd66.upData() ; |
| | | }else if(cdPre.equals("91")){ |
| | | UpCd91.upData() ; |
| | | }else if(cdPre.equals("92")){ |
| | | UpCd92.upData() ; |
| | | } |
| | | } |
| | | private void dealUpgrade(byte[] bs){ |
| | | String cdPre = ByteUtil.bytes2Hex(bs, false, ProtocolConstantV206V1.UG_codeIndex, 1); |
New file |
| | |
| | | package com.dy.simRtu.tcpClient.upData; |
| | | |
| | | import com.dy.common.mw.protocol.p206V1.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | import com.dy.common.util.ByteUtilUnsigned; |
| | | import com.dy.simRtu.ServerProperties; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2025/5/8 11:14 |
| | | * @Description |
| | | */ |
| | | public class UpCd50 extends UpData { |
| | | |
| | | private static final Logger log = LogManager.getLogger(UpCd66.class); |
| | | |
| | | public static void upData() { |
| | | try { |
| | | if (UpData.session != null && UpData.session.isConnected()) { |
| | | byte[] bs = createData(ServerProperties.rtuAddr); |
| | | UpData.upSend(bs); |
| | | } else { |
| | | log.error("未连接通信中间件,不能发送数据"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("向通信中间件发送数据产生异常", e); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 构造数据 |
| | | * |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | | private static byte[] createData(String rtuAddr) throws Exception { |
| | | byte[] bytes = creatHead(rtuAddr, "50",(byte)0xB0); |
| | | |
| | | byte[] bs = new byte[6]; |
| | | GlCreate.createRtuAddr4P206(rtuAddr, bs, 0); |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bs); |
| | | |
| | | GlCreate.createLen(bytes);//长度放字节数组中 |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail4P206(bytes);//CRC和尾叠加字节数组中 |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail); |
| | | |
| | | return bytes; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.simRtu.tcpClient.upData; |
| | | |
| | | import com.dy.common.mw.protocol.p206V1.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | import com.dy.common.util.ByteUtilUnsigned; |
| | | import com.dy.simRtu.ServerProperties; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2025/5/8 8:29 |
| | | * @Description |
| | | */ |
| | | public class UpCd66 extends UpData { |
| | | |
| | | private static final Logger log = LogManager.getLogger(UpCd66.class); |
| | | |
| | | public static void upData() { |
| | | try { |
| | | if (UpData.session != null && UpData.session.isConnected()) { |
| | | byte[] bs = createData(ServerProperties.rtuAddr); |
| | | UpData.upSend(bs); |
| | | } else { |
| | | log.error("未连接通信中间件,不能发送数据"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("向通信中间件发送数据产生异常", e); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 构造数据 |
| | | * |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | | private static byte[] createData(String rtuAddr) throws Exception { |
| | | byte[] bytes = creatHead(rtuAddr, "66",(byte)0xB0); |
| | | |
| | | byte[] bs = new byte[6]; |
| | | bs[0] = (byte) 100; |
| | | bs[1] = (byte) 101; |
| | | bs[2] = (byte) 102; |
| | | bs[3] = (byte) 103; |
| | | |
| | | ByteUtilUnsigned.short2Bytes_BE(bs,1234, 4); |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bs); |
| | | |
| | | GlCreate.createLen(bytes);//长度放字节数组中 |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail4P206(bytes);//CRC和尾叠加字节数组中 |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail); |
| | | |
| | | return bytes; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.simRtu.tcpClient.upData; |
| | | |
| | | import com.dy.common.mw.protocol.p206V1.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | import com.dy.simRtu.ServerProperties; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2025/5/8 10:58 |
| | | * @Description |
| | | */ |
| | | public class UpCd91 extends UpData { |
| | | |
| | | private static final Logger log = LogManager.getLogger(UpCd91.class); |
| | | |
| | | public static void upData() { |
| | | try { |
| | | if (UpData.session != null && UpData.session.isConnected()) { |
| | | byte[] bs = createData(ServerProperties.rtuAddr); |
| | | UpData.upSend(bs); |
| | | } else { |
| | | log.error("未连接通信中间件,不能发送数据"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("向通信中间件发送数据产生异常", e); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 构造数据 |
| | | * |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | | private static byte[] createData(String rtuAddr) throws Exception { |
| | | byte[] bytes = creatHead(rtuAddr, "91",(byte)0xB0); |
| | | |
| | | GlCreate.createLen(bytes);//长度放字节数组中 |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail4P206(bytes);//CRC和尾叠加字节数组中 |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail); |
| | | |
| | | return bytes; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.simRtu.tcpClient.upData; |
| | | |
| | | import com.dy.common.mw.protocol.p206V1.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | import com.dy.simRtu.ServerProperties; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2025/5/7 15:05 |
| | | * @Description |
| | | */ |
| | | public class UpCd92 extends UpData { |
| | | |
| | | private static final Logger log = LogManager.getLogger(UpCd92.class); |
| | | |
| | | public static void upData() { |
| | | try { |
| | | if (UpData.session != null && UpData.session.isConnected()) { |
| | | byte[] bs = createData(ServerProperties.rtuAddr); |
| | | UpData.upSend(bs); |
| | | } else { |
| | | log.error("未连接通信中间件,不能发送数据"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("向通信中间件发送数据产生异常", e); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 构造数据 |
| | | * |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | | private static byte[] createData(String rtuAddr) throws Exception { |
| | | byte[] bytes = creatHead(rtuAddr, "92",(byte)0xB0); |
| | | |
| | | byte[] bs = new byte[1]; |
| | | bs[0] = (byte) 0xAA;//0xAA表示命令接收成功,0x00表示命令不能执行 |
| | | bytes = ByteUtil.bytesMerge(bytes, bs); |
| | | |
| | | GlCreate.createLen(bytes);//长度放字节数组中 |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail4P206(bytes);//CRC和尾叠加字节数组中 |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail); |
| | | |
| | | return bytes; |
| | | } |
| | | } |
| | |
| | | "com.dy.common.aop..*", |
| | | "com.dy.common.apiDoc..*", |
| | | "com.dy.common.multiDataSource..*", |
| | | "com.dy.common.mybatis..*", |
| | | "com.dy.common.singleDataSource..*", |
| | | "com.dy.common.mybatis..*", |
| | | "com.dy.common.webFilter..*", |
| | | "com.dy.common.webListener..*", |
| | | "com.dy.pipIrrGlobal.config..*", |
| | | "com.dy.pipIrrGlobal.webCtrls..*" |
| | | }) |
| | | } |
| | |
| | | public class CommandResultCtrl extends ComSupport { |
| | | @PostMapping(path = "receive", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | public void receive(@RequestBody Data data) { |
| | | JSONObject job_data = (JSONObject) JSON.toJSON(data); |
| | | //String job_dataS = job_data.toJSONString(); |
| | | JSONObject job_subData = job_data.getJSONObject("subData").getJSONObject("subData"); |
| | | JSONObject protocolData = data == null ? null : (JSONObject)data.subData ; //协议数据 |
| | | JSONObject codeData = protocolData == null ? null : (protocolData.getJSONObject("subData")) ; //协议功能码数据 |
| | | |
| | | JSONObject job_response = new JSONObject(); |
| | | job_response.put("data", job_subData); |
| | | job_response.put("commandCode", job_data.getString("code")); |
| | | job_response.put("commandId", job_data.getString("commandId")); |
| | | job_response.put("data", codeData==null?protocolData:codeData); |
| | | job_response.put("commandCode", data.code); |
| | | job_response.put("commandId", data.commandId); |
| | | |
| | | CompletableFuture<JSONObject> feature = (CompletableFuture<JSONObject>) ComResultWait.get(job_data.getLong("commandId")); |
| | | CompletableFuture<JSONObject> feature = (CompletableFuture<JSONObject>) ComResultWait.get(Long.parseLong(data.commandId)); |
| | | if(feature != null) { |
| | | feature.complete(job_response); |
| | | }//else{ |
| | | // feature.complete(new JSONObject()); |
| | | //} |
| | | }else{ |
| | | //超时,feature被清除了 |
| | | } |
| | | } |
| | | } |
| | |
| | | * @Date: 2025/4/30 16:08 |
| | | * @Description |
| | | */ |
| | | |
| | | @Slf4j |
| | | @Tag(name = "远程透传命令", description = "远程透传命令") |
| | | @RestController |
| | | @RequestMapping(path = "comTrans") |
| | | @RequiredArgsConstructor |
| | | public class ComTransCtrl { |
| | | |
| | | private static final String RtuSuccessMsg = "控制器接收并执行命令成功"; |
| | | |
| | | @Autowired |
| | | private Environment env ; |
| | |
| | | try{ |
| | | //等待通信中间件通知控制器执行命令上行数据(命令结果) |
| | | JSONObject resultData = feature.get(waitMwRtnResultTimeout, TimeUnit.SECONDS); |
| | | Long commandId = resultData.getLong("commandId"); |
| | | if (commandId.equals(comId)) { |
| | | return BaseResponseUtils.buildSuccess(resultData); |
| | | } else { |
| | | return BaseResponseUtils.buildSuccess("控制器执行命令成功"); |
| | | } |
| | | return BaseResponseUtils.buildSuccess(this.createRtnMsg(dto.comCode, resultData)); |
| | | }catch (Exception e){ |
| | | return BaseResponseUtils.buildFail("等待通信中间件通知命令结果超时或异常"); |
| | | return BaseResponseUtils.buildFail("等待通信中间件通知命令结果超时"); |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | |
| | | return null ; |
| | | } |
| | | |
| | | private String createRtnMsg(String code, JSONObject resultData){ |
| | | String msg; |
| | | if(resultData != null){ |
| | | JSONObject codeData = resultData.getJSONObject("data") ; |
| | | switch (code){ |
| | | case "3C": msg = createCd3CRtnMsg(codeData); break; |
| | | case "10": msg = createCd10RtnMsg(codeData); break; |
| | | case "21": msg = createCd21RtnMsg(codeData); break; |
| | | case "37": msg = createCd37RtnMsg(codeData); break; |
| | | case "50": msg = createCd50RtnMsg(codeData); break; |
| | | case "65": msg = createCd65RtnMsg(codeData); break; |
| | | case "66": msg = createCd66RtnMsg(codeData); break; |
| | | case "67": msg = createCd67RtnMsg(codeData); break; |
| | | case "91": msg = createCd91RtnMsg(codeData); break; |
| | | case "92": msg = createCd92RtnMsg(codeData); break; |
| | | case "93": msg = createCd93RtnMsg(codeData); break; |
| | | default: msg = RtuSuccessMsg; break; |
| | | } |
| | | }else{ |
| | | msg = RtuSuccessMsg ; |
| | | } |
| | | return msg; |
| | | } |
| | | private String createCd3CRtnMsg(JSONObject codeData){ |
| | | if(codeData == null){ |
| | | return RtuSuccessMsg ; |
| | | }else{ |
| | | Integer minute = codeData.getInteger("minute"); |
| | | return "设置成功,自报周期:" + minute + "分钟" ; |
| | | } |
| | | } |
| | | private String createCd10RtnMsg(JSONObject codeData){ |
| | | if(codeData == null){ |
| | | return RtuSuccessMsg ; |
| | | }else { |
| | | String newRtuAddr = codeData.getString("newRtuAddr"); |
| | | return "设置成功,控制器地址:" + newRtuAddr; |
| | | } |
| | | } |
| | | private String createCd21RtnMsg(JSONObject codeData){ |
| | | if(codeData == null){ |
| | | return RtuSuccessMsg ; |
| | | }else { |
| | | String ip = codeData.getString("ip"); |
| | | Integer port = codeData.getInteger("port"); |
| | | return "设置成功,IP地址:" + ip + ",端口号:" + port; |
| | | } |
| | | } |
| | | private String createCd37RtnMsg(JSONObject codeData){ |
| | | if(codeData == null){ |
| | | return RtuSuccessMsg ; |
| | | }else { |
| | | Integer second = codeData.getInteger("second"); |
| | | return "设置成功,流量采集周期:" + second + "秒"; |
| | | } |
| | | } |
| | | private String createCd50RtnMsg(JSONObject codeData){ |
| | | if(codeData == null){ |
| | | return RtuSuccessMsg ; |
| | | }else { |
| | | String rtuAddr = codeData.getString("rtuAddr"); |
| | | return "查询成功,控制器地址:" + rtuAddr; |
| | | } |
| | | } |
| | | private String createCd65RtnMsg(JSONObject codeData){ |
| | | if(codeData == null){ |
| | | return RtuSuccessMsg ; |
| | | }else { |
| | | Integer minute = codeData.getInteger("minute"); |
| | | return "查询成功,自报周期:" + minute + "分钟"; |
| | | } |
| | | } |
| | | private String createCd66RtnMsg(JSONObject codeData){ |
| | | if(codeData == null){ |
| | | return RtuSuccessMsg ; |
| | | }else { |
| | | String ip = codeData.getString("ip"); |
| | | Integer port = codeData.getInteger("port"); |
| | | return "查询成功,IP地址:" + ip + ",端口号:" + port; |
| | | } |
| | | } |
| | | private String createCd67RtnMsg(JSONObject codeData){ |
| | | if(codeData == null){ |
| | | return RtuSuccessMsg ; |
| | | }else { |
| | | Integer second = codeData.getInteger("second"); |
| | | return "查询成功,流量采集周期:" + second + "秒"; |
| | | } |
| | | } |
| | | private String createCd91RtnMsg(JSONObject codeData){ |
| | | //此命令的codeData是null |
| | | return "控制器清空历史记录成功" ; |
| | | } |
| | | private String createCd92RtnMsg(JSONObject codeData){ |
| | | if(codeData == null){ |
| | | return RtuSuccessMsg ; |
| | | }else { |
| | | Boolean success = codeData.getBoolean("success"); |
| | | return success ? "控制器已执行遥控开阀命令" : "控制器拒绝执行遥控开阀命令"; |
| | | } |
| | | } |
| | | private String createCd93RtnMsg(JSONObject codeData){ |
| | | if(codeData == null){ |
| | | return RtuSuccessMsg ; |
| | | }else { |
| | | Boolean success = codeData.getBoolean("success"); |
| | | return success ? "控制器已执行遥控关阀命令" : "控制器拒绝执行遥控关阀命令"; |
| | | } |
| | | } |
| | | |
| | | } |