1、common模块优化代码,Command命令中增加RTU命令结果返回webRul;
2、通信中间件增加了接收http下发RTU命令和内部命令的Controler;
3、RTU模拟器和控制器增加了上报完数据是否关闭TCP连接的控制。
1 文件已复制
1 文件已重命名
33个文件已修改
13个文件已添加
| | |
| | | .queryParam("token", token) |
| | | .build() |
| | | .toUriString(); |
| | | // 由于获取student接口咱们设置了basicauth,所以需要在请求时配置 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | HttpEntity<?> httpEntity = new HttpEntity<>(headers); |
| | | ResponseEntity<SsoVo> response = null; |
| | |
| | | .queryParam("anyPower", (Object) anyPower) |
| | | .build() |
| | | .toUriString(); |
| | | // 由于获取student接口咱们设置了basicauth,所以需要在请求时配置 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | HttpEntity<?> httpEntity = new HttpEntity<>(headers); |
| | | ResponseEntity<SsoVo> response = null; |
| | |
| | | import java.io.Serializable; |
| | | |
| | | import com.alibaba.fastjson2.JSON ; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | |
| | | public class Command implements Serializable{ |
| | | |
| | |
| | | public Boolean noRtMwDealRes ; |
| | | |
| | | /** |
| | | * rtu返回命令结果 发向目的地web URL |
| | | */ |
| | | public String rtuResultSendWebUrl ; |
| | | |
| | | /** |
| | | * 具体参数数据 |
| | | */ |
| | | public Object param ; |
| | |
| | | String s = "命令id=" + id + "\n" ; |
| | | s += (protocol == null ? "" : ("协议=" + protocol + "\n")); |
| | | s += (rtuAddr == null ? "" : ("Rtu地址=" + rtuAddr + "\n")); |
| | | s += "命令类型=" + (type.equals(CommandType.innerCommand)?"内部命令":"终端命令") + "\n" ; |
| | | s += "命令类型=" + (type.equals(CommandType.innerCommand)?"内部命令":"RTU命令") + "\n" ; |
| | | s += (code == null ? "" : ("功能码=" + code + "\n")) ; |
| | | s += "返回中间件对命令处理结果=" + (noRtMwDealRes == null?"返回":(noRtMwDealRes?"不返回":"返回") + "\n") ; |
| | | s += "是否返回中间件对命令处理结果=" + (noRtMwDealRes == null?"是":(noRtMwDealRes?"是":"否") + "\n") ; |
| | | if(param != null){ |
| | | s += "参数:" + param ; |
| | | } |
| | |
| | | @SuppressWarnings("unused") |
| | | public String toJson()throws Exception{ |
| | | try{ |
| | | return JSON.toJSONString(this) ; |
| | | String json = JSON.toJSONString(this) ; |
| | | return json ; |
| | | }catch(Exception e){ |
| | | throw new Exception(e.getMessage() , e ) ; |
| | | } |
| | |
| | | @SuppressWarnings("unused") |
| | | public static Command jsonToObject(String json)throws Exception{ |
| | | try{ |
| | | return JSON.parseObject(json, Command.class) ; |
| | | JSONObject jsonObject = JSON.parseObject(json); |
| | | Command command = jsonObject.to(Command.class) ; |
| | | //command.param = jsonObject.getObject("param", class); |
| | | return command ; |
| | | }catch(Exception e){ |
| | | throw new Exception(e.getMessage() , e ) ; |
| | | } |
| | |
| | | this.rtuAddr = rtuAddr; |
| | | return this ; |
| | | } |
| | | |
| | | |
| | | public String getRtuResultSendWebUrl() { |
| | | return rtuResultSendWebUrl; |
| | | } |
| | | |
| | | public void setRtuResultSendWebUrl(String rtuResultSendWebUrl) { |
| | | this.rtuResultSendWebUrl = rtuResultSendWebUrl; |
| | | } |
| | | |
| | | public String getProtocol() { |
| | | return protocol; |
| | | } |
| | |
| | | * 针对Rtu外部命令 |
| | | * 只能是异步,命令结果通过相关的信息发布通道发布出去 |
| | | */ |
| | | @SuppressWarnings("unused") |
| | | public static final String outerCommand = "outerCommand" ; |
| | | |
| | | /** |
| | |
| | | @Serial |
| | | private static final long serialVersionUID = 20160805192500101L; |
| | | |
| | | public String rtuResultSendWebUrl ;//rtu返回命令结果 发向目的地web URL |
| | | private String commandId ;//命令ID,可能为null |
| | | private String rtuAddr ;//终端地址 |
| | | private String protocol ;//数据所对应的协议名称 |
| | |
| | | StringBuilder sb = new StringBuilder() ; |
| | | sb.append("上行报文(十六进制): ").append((hex == null?"":hex)).append("\n") ; // |
| | | sb.append("Rtu地址 : ").append((rtuAddr==null?"":rtuAddr)).append("\n") ; |
| | | if(rtuResultSendWebUrl != null){ |
| | | sb.append("命令结果发往 : ").append(rtuResultSendWebUrl).append("\n") ; //rtu返回命令结果 发向目的地web URL |
| | | } |
| | | if(commandId != null){ |
| | | sb.append("命令ID : ").append(commandId).append("\n") ; //命令ID |
| | | } |
| | |
| | | this.hex = hex; |
| | | } |
| | | |
| | | public String getRtuResultSendWebUrl() { |
| | | return rtuResultSendWebUrl; |
| | | } |
| | | /** |
| | | * 得到rtu返回命令结果 发向目的地web URL |
| | | * 如果是主动上报数据,则此web URL为空 |
| | | * @return rtuResultSendWebUrl |
| | | */ |
| | | public void setRtuResultSendWebUrl(String rtuResultSendWebUrl) { |
| | | this.rtuResultSendWebUrl = rtuResultSendWebUrl; |
| | | } |
| | | |
| | | public void setCommandId(String commandId) { |
| | | this.commandId = commandId; |
| | | } |
| | |
| | | } |
| | | |
| | | public String commandId ;//发送命令的ID,如果是命令结果,并且匹配了下发命令,此值不为空 |
| | | |
| | | |
| | | public String rtuResultSendWebUrl ;//rtu返回命令结果 发向目的地web URL |
| | | public String protocolName ;//协议名称 |
| | | public String rtuAddr ;//Rtu地址 |
| | | public String upCode ;//上行数据中的功能码 |
| | |
| | | ProtocolUnit.getInstance().adapter.getSingleActionFromRtu(this.protocolName).doAction(this); |
| | | } |
| | | |
| | | public void setCommandId(String commandId){ |
| | | public void matchedCommand(String commandId, String rtuResultSendWebUrl){ |
| | | this.commandId = commandId ; |
| | | if(this.data != null){ |
| | | this.data.setCommandId(commandId); |
| | | } |
| | | this.rtuResultSendWebUrl = rtuResultSendWebUrl ; |
| | | if(this.data != null){ |
| | | this.data.setRtuResultSendWebUrl(rtuResultSendWebUrl); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | serialVersionUID = 201606271057003L; |
| | | } |
| | | |
| | | public String rtuResultSendWebUrl ;//rtu返回命令结果 发向目的地web URL |
| | | public String protocolName ;//协议名称 |
| | | public String rtuAddr ;//Rtu地址 |
| | | public String commandId ;//命令ID,发起命令的客户端(web端)生成,以匹配命令结果 |
| | |
| | | public class CodeV1_0_1 { |
| | | //功能码为字符串,十六进制数据 |
| | | public static final String cd_02 = "02" ;//遥测站链路检测 |
| | | public static final String cd_71 = "71" ;//查询阀门状态(李天赐制定的协议,当前未实现) |
| | | public static final String cd_71 = "71" ;//设置工作模式(李天赐制定的协议,当前未实现) |
| | | public static final String cd_83 = "83" ;//遥测站开关阀自报 |
| | | public static final String cd_84 = "84" ;//开阀工作报 |
| | | public static final String cd_C0 = "C0" ;//遥测站自报实时数据 |
| | |
| | | */ |
| | | @Override |
| | | public MidResult[] createCommand(Boolean isLowPower, Command command, Object... params) { |
| | | String RtuResultSendWebUrl = command.getRtuResultSendWebUrl() ; |
| | | if(RtuResultSendWebUrl == null || RtuResultSendWebUrl.trim().equals("")){ |
| | | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1_0_0.protocolName, null, "严重错误,命令中rtu返回命令结果发向目的地web URL为空,不能构建任何命令!", null))} ; |
| | | } |
| | | String rtuAddr = command.getRtuAddr() ; |
| | | if(rtuAddr == null){ |
| | | if(rtuAddr == null || rtuAddr.trim().equals("")){ |
| | | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1_0_0.protocolName, null, "严重错误,命令中Rtu地址为空,不能构建任何命令!", null))} ; |
| | | } |
| | | try { |
| | |
| | | |
| | | this.downCpParams.clear(); |
| | | this.downCpParams.setValue( |
| | | RtuResultSendWebUrl, |
| | | ProtocolConstantV206V1_0_0.protocolName, |
| | | rtuAddr, |
| | | command.getId(), |
| | |
| | | import com.dy.common.mw.protocol.CodeParseParams; |
| | | |
| | | public class ParseParamsForDownV1_0_1 implements CodeParseParams{ |
| | | |
| | | |
| | | public String rtuResultSendWebUrl ;//rtu返回命令结果 发向目的地web URL |
| | | public String protocolName ; |
| | | public String rtuAddr ;//控制器地址 |
| | | public String commandId ; |
| | |
| | | } |
| | | |
| | | public void setValue( |
| | | String protocolName, |
| | | String rtuAddr, |
| | | String rtuResultSendWebUrl, |
| | | String protocolName, |
| | | String rtuAddr, |
| | | String commandId, |
| | | String commandCode, |
| | | Object param, |
| | | Object attachment ){ |
| | | this.protocolName = protocolName ; |
| | | this.rtuAddr = rtuAddr ; |
| | | this.rtuResultSendWebUrl = rtuResultSendWebUrl ; |
| | | this.protocolName = protocolName ; |
| | | this.rtuAddr = rtuAddr ; |
| | | this.commandId = commandId ; |
| | | this.commandCode = commandCode ; |
| | | this.param = param ; |
| | |
| | | String confirmComCode = para.upCode ; |
| | | ParseParamsForDownV1_0_1 downCpParams = new ParseParamsForDownV1_0_1() ; |
| | | downCpParams.setValue( |
| | | null, |
| | | ProtocolConstantV206V1_0_0.protocolName, |
| | | para.rtuAddr, |
| | | Command.defaultId, |
| | |
| | | byte[] bs = this.doParse(para) ; |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.rtuResultSendWebUrl = para.rtuResultSendWebUrl ;////rtu返回命令结果 发向目的地web URL |
| | | midRs.protocolName = para.protocolName ;//协议名称 |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtu地址(电信平台设备IMEI) |
| | | midRs.commandId = para.commandId ;//命令ID,发起命令的客户端(web端)生成,以匹配命令结果 |
| | |
| | | |
| | | ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; |
| | | |
| | | byte[] bs = new byte[0] ; |
| | | byte[] bs = new byte[1] ; |
| | | //确认帧的数据域用于遥测终端工作模式的确认或转换。数据为 1 个字节 HEX,00H 时遥测终 |
| | | //端在兼容工作状态; 01H 时遥测终端在自报工作状态; 02H 时遥测终端在查询/应答工作 |
| | | //状态; 03H 时遥测终端在调试/维修状态。 |
| | |
| | | byte[] bs = this.doParse(para) ; |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.rtuResultSendWebUrl = para.rtuResultSendWebUrl ;////rtu返回命令结果 发向目的地web URL |
| | | midRs.protocolName = para.protocolName ;//协议名称 |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtu地址(电信平台设备IMEI) |
| | | midRs.commandId = para.commandId ;//命令ID,发起命令的客户端(web端)生成,以匹配命令结果 |
| | |
| | | String confirmComCode = para.upCode ; |
| | | ParseParamsForDownV1_0_1 downCpParams = new ParseParamsForDownV1_0_1() ; |
| | | downCpParams.setValue( |
| | | null, |
| | | ProtocolConstantV206V1_0_0.protocolName, |
| | | para.rtuAddr, |
| | | Command.defaultId, |
| | |
| | | byte[] bs = this.doParse(para) ; |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.rtuResultSendWebUrl = para.rtuResultSendWebUrl ;////rtu返回命令结果 发向目的地web URL |
| | | midRs.protocolName = para.protocolName ;//协议名称 |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtu地址(电信平台设备IMEI) |
| | | midRs.commandId = para.commandId ;//命令ID,发起命令的客户端(web端)生成,以匹配命令结果 |
| | |
| | | String confirmComCode = para.upCode ; |
| | | ParseParamsForDownV1_0_1 downCpParams = new ParseParamsForDownV1_0_1() ; |
| | | downCpParams.setValue( |
| | | null, |
| | | ProtocolConstantV206V1_0_0.protocolName, |
| | | para.rtuAddr, |
| | | Command.defaultId, |
| | |
| | | byte[] bs = this.doParse(para) ; |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.rtuResultSendWebUrl = para.rtuResultSendWebUrl ;////rtu返回命令结果 发向目的地web URL |
| | | midRs.protocolName = para.protocolName ;//协议名称 |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtu地址(电信平台设备IMEI) |
| | | midRs.commandId = para.commandId ;//命令ID,发起命令的客户端(web端)生成,以匹配命令结果 |
| | |
| | | String confirmComCode = para.upCode ; |
| | | ParseParamsForDownV1_0_1 downCpParams = new ParseParamsForDownV1_0_1() ; |
| | | downCpParams.setValue( |
| | | null, |
| | | ProtocolConstantV206V1_0_0.protocolName, |
| | | para.rtuAddr, |
| | | Command.defaultId, |
| | |
| | | return buildResult(ResultCodeMsg.RsCode.ERROR_CODE,ResultCodeMsg.RsMsg.ERROR_MESSAGE, message); |
| | | } |
| | | |
| | | public static BaseResponse buildError(Object obj){ |
| | | return buildResult(ResultCodeMsg.RsCode.ERROR_CODE,ResultCodeMsg.RsMsg.ERROR_MESSAGE, obj); |
| | | } |
| | | |
| | | public static BaseResponse buildResult(String code, String msg, Object data){ |
| | | return BaseResponse.builder() |
| | | .code((code == null || "".equals(code)) ? ResultCodeMsg.RsCode.SUCCESS_CODE : code) |
| | |
| | | import com.dy.aceMw.server.*; |
| | | import com.dy.aceMw.server.rtuData.RtuDataUnit; |
| | | import com.dy.aceMw.server.rtuData.RtuDataUnitConfigVo; |
| | | import com.dy.aceMw.server.tasks.FromRtuConstantTask; |
| | | import com.dy.aceMw.server.tasks.FromRtuComResultConstantTask; |
| | | import com.dy.aceMw.server.tasks.FromRtuDataConstantTask; |
| | | import com.dy.common.mw.UnitInterface; |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | import com.dy.common.mw.channel.rmi.RmiConfigVo; |
| | | import com.dy.common.mw.channel.rmi.RmiUnit; |
| | | import com.dy.common.mw.channel.tcp.TcpConfigVo; |
| | |
| | | CoreUnit coreUnit = CoreUnit.getInstance(); |
| | | coreUnit.setAdapter(coreAdap); |
| | | CoreUnit.addConstantTask(new ToRtuConstantTask()); |
| | | CoreUnit.addConstantTask(new FromRtuConstantTask()); |
| | | CoreUnit.addConstantTask(new FromRtuDataConstantTask()); |
| | | CoreUnit.addConstantTask(new FromRtuComResultConstantTask()); |
| | | coreUnit.start(obj -> { |
| | | }); |
| | | units.add(coreUnit) ; |
| | |
| | | package com.dy.aceMw.server.forTcp; |
| | | |
| | | import com.dy.aceMw.server.rtuData.RtuComResultCache; |
| | | import com.dy.aceMw.server.rtuData.RtuComResultNode; |
| | | import com.dy.aceMw.server.rtuData.RtuDataNode; |
| | | import com.dy.aceMw.server.rtuData.RtuDataCache; |
| | | import org.apache.logging.log4j.LogManager; |
| | |
| | | MidResultToRtu resToRtu = TcpDownCommandCache.matchFromHead(resFromRtu) ; |
| | | if(resToRtu != null){ |
| | | //匹配到下发的命令 |
| | | resFromRtu.setCommandId(resToRtu.commandId) ; |
| | | this.nextDeal(false, resFromRtu); |
| | | resFromRtu.matchedCommand(resToRtu.rtuResultSendWebUrl, resToRtu.commandId) ; |
| | | this.nextDealRtuData(false, resFromRtu); |
| | | this.nextDealRtuComResult(resFromRtu); |
| | | }else{ |
| | | this.nextDeal(false, resFromRtu); |
| | | this.nextDealRtuData(false, resFromRtu); |
| | | //未匹配到下发的命令,命令在缓存因超时被清除了 |
| | | RtuStatusDealer.commandFail2Success(resFromRtu.rtuAddr) ; |
| | | } |
| | | }else{ |
| | | //主动上报数据 |
| | | this.nextDeal(true, resFromRtu); |
| | | this.nextDealRtuData(true, resFromRtu); |
| | | } |
| | | } |
| | | } |
| | |
| | | * @param reportOrResponse_trueOrFalse |
| | | * @param resFromRtu |
| | | */ |
| | | private void nextDeal(boolean reportOrResponse_trueOrFalse, MidResultFromRtu resFromRtu){ |
| | | private void nextDealRtuData(boolean reportOrResponse_trueOrFalse, MidResultFromRtu resFromRtu){ |
| | | try{ |
| | | RtuDataCache.cacheRtuUpData(reportOrResponse_trueOrFalse, new RtuDataNode(resFromRtu.data)); |
| | | }catch(Exception e){ |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 进入单线程环境中运行 |
| | | * @param resFromRtu |
| | | */ |
| | | private void nextDealRtuComResult(MidResultFromRtu resFromRtu){ |
| | | try{ |
| | | RtuComResultCache.cacheRtuComResult(new RtuComResultNode(resFromRtu.data)); |
| | | }catch(Exception e){ |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.local; |
| | | |
| | | import com.dy.aceMw.server.local.localProtocol.*; |
| | | import com.dy.common.mw.protocol.Command; |
| | | |
| | | /** |
| | | * @Author liurunyu |
| | | * @Date 2023/12/21 15:56 |
| | | * @LastEditTime 2023/12/21 15:56 |
| | | * @Description |
| | | */ |
| | | public class CommandInnerDeaLer { |
| | | /** |
| | | * 处理内部命令 |
| | | * @param com |
| | | * @return |
| | | */ |
| | | public Command deal(Command com) throws Exception{ |
| | | String code = com.getCode() ; |
| | | if(code.equals(CodeLocal.clock)){ |
| | | return this.clock(com) ; |
| | | }else if(code.equals(CodeLocal.onLine)){ |
| | | return this.onLine(com) ; |
| | | }else if(code.equals(CodeLocal.allProtocols)){ |
| | | return this.allProtocols(com) ; |
| | | } |
| | | return ReturnCommand.errored("出错,收到内部命令的功能码不能识别!", com.getId(), com.getCode()) ; |
| | | } |
| | | |
| | | /** |
| | | * 查询通信中间件时钟 |
| | | * @throws Exception |
| | | */ |
| | | private Command clock(Command command) throws Exception{ |
| | | ClockVo c = new ClockDeal().deal() ; |
| | | return ReturnCommand.successed("查询通信中间件时钟", command.getId(), command.getCode(), c) ; |
| | | } |
| | | |
| | | /** |
| | | * 查询所有RTU在线情况 |
| | | * @throws Exception |
| | | */ |
| | | private Command onLine(Command command) throws Exception{ |
| | | RtuOnLineVo ol = new RtuOnLineDeal().deal() ; |
| | | return ReturnCommand.successed("查询所有测站在线情况结果", command.getId(), command.getCode(), ol) ; |
| | | } |
| | | |
| | | /** |
| | | * 查询所有RTU协议配置 |
| | | * @throws Exception |
| | | */ |
| | | private Command allProtocols(Command command) throws Exception{ |
| | | RtuProtocolVo mc = new RtuProtocolsDeal().deal() ; |
| | | return ReturnCommand.successed("查询所有通信协议配置", command.getId(), command.getCode(), mc) ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.local; |
| | | |
| | | |
| | | import com.dy.common.mw.protocol.Command; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | /** |
| | | * @Author liurunyu |
| | | * @Date 2023/12/21 15:17 |
| | | * @LastEditTime 2023/12/21 15:17 |
| | | * @Description |
| | | */ |
| | | public class ReturnCommand { |
| | | |
| | | private static Logger log = LogManager.getLogger(ReturnCommand.class) ; |
| | | |
| | | /** |
| | | * 处理命令成功 |
| | | * @param message |
| | | */ |
| | | public static Command successed(String message, String commandId, String code, Object attachment){ |
| | | log.info(message) ; |
| | | Command command = new Command().createReturnSuccessCommand(message, commandId, code) ; |
| | | command.setAttachment(attachment) ; |
| | | return command ; |
| | | } |
| | | /** |
| | | * 处理命令成功 |
| | | * @param message |
| | | */ |
| | | public static Command successed(String message, String commandId, String code){ |
| | | log.info(message) ; |
| | | return new Command().createReturnSuccessCommand(message, commandId, code) ; |
| | | } |
| | | /** |
| | | * 处理命令发生错误 |
| | | * @param message |
| | | */ |
| | | public static Command errored(String message, String commandId, String code){ |
| | | log.error(message) ; |
| | | return new Command().createReturnErrorCommand(message, commandId, code) ; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.local.localProtocol; |
| | | |
| | | import com.dy.common.util.DateTime; |
| | | |
| | | public class ClockDeal { |
| | | /** |
| | | * 查询通信中间件时钟 |
| | | */ |
| | | public ClockVo deal(){ |
| | | ClockVo c = new ClockVo() ; |
| | | c.setClock(DateTime.yyyy_MM_dd_HH_mm_ss()) ; |
| | | c.setYear(Integer.parseInt(DateTime.yyyy())) ; |
| | | c.setMonth(Integer.parseInt(DateTime.MM())) ; |
| | | c.setDate(Integer.parseInt(DateTime.dd())) ; |
| | | c.setHour(Integer.parseInt(DateTime.HH())) ; |
| | | c.setMinute(Integer.parseInt(DateTime.mm())) ; |
| | | c.setSecond(Integer.parseInt(DateTime.ss())) ; |
| | | return c ; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.local.localProtocol; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | public class ClockVo implements Serializable{ |
| | | |
| | | private static final long serialVersionUID = 201606251603001L; |
| | | |
| | | public String clock ; |
| | | public Integer year ; |
| | | public Integer month ; |
| | | public Integer date ; |
| | | public Integer hour ; |
| | | public Integer minute ; |
| | | public Integer second ; |
| | | |
| | | public String toString(){ |
| | | return clock ; |
| | | } |
| | | |
| | | public String getClock() { |
| | | return clock; |
| | | } |
| | | public void setClock(String clock) { |
| | | this.clock = clock; |
| | | } |
| | | public Integer getYear() { |
| | | return year; |
| | | } |
| | | public void setYear(Integer year) { |
| | | this.year = year; |
| | | } |
| | | public Integer getMonth() { |
| | | return month; |
| | | } |
| | | public void setMonth(Integer month) { |
| | | this.month = month; |
| | | } |
| | | public Integer getDate() { |
| | | return date; |
| | | } |
| | | public void setDate(Integer date) { |
| | | this.date = date; |
| | | } |
| | | public Integer getHour() { |
| | | return hour; |
| | | } |
| | | public void setHour(Integer hour) { |
| | | this.hour = hour; |
| | | } |
| | | public Integer getMinute() { |
| | | return minute; |
| | | } |
| | | public void setMinute(Integer minute) { |
| | | this.minute = minute; |
| | | } |
| | | public Integer getSecond() { |
| | | return second; |
| | | } |
| | | public void setSecond(Integer second) { |
| | | this.second = second; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.local.localProtocol; |
| | | |
| | | public class CodeLocal { |
| | | |
| | | public static final String clock = "LCD0000" ;//查询监控中间件时钟 |
| | | |
| | | public static final String onLine = "LCD0001" ;//查询所有RTU在线情况 |
| | | |
| | | public static final String allProtocols = "LCD0100" ;//查询所有协议配置 |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.local.localProtocol; |
| | | |
| | | import com.dy.aceMw.server.forTcp.TcpSessionCache; |
| | | |
| | | public class RtuOnLineDeal { |
| | | |
| | | /** |
| | | * 查询在线与不在线情况 |
| | | */ |
| | | public RtuOnLineVo deal(){ |
| | | return (new RtuOnLineVo()).setOnLine(TcpSessionCache.allOnLine()); |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.local.localProtocol; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.Map.Entry; |
| | | |
| | | public class RtuOnLineVo implements Serializable{ |
| | | |
| | | private static final long serialVersionUID = 202312211559001L; |
| | | |
| | | private HashMap<String , Boolean> onLineMap ; |
| | | |
| | | public String toString(){ |
| | | String s = "" ; |
| | | if(onLineMap != null){ |
| | | Iterator<Entry<String, Boolean>> it = onLineMap.entrySet().iterator() ; |
| | | Entry<String, Boolean> entry = null ; |
| | | while(it.hasNext()){ |
| | | entry = it.next() ; |
| | | s += entry.getKey() + ": " + (entry.getValue().booleanValue()?"在线":"离线") + "\n"; |
| | | } |
| | | } |
| | | return s ; |
| | | } |
| | | /** |
| | | * 存入RTU在线情况 |
| | | * @param onLineMap 在线集合 |
| | | */ |
| | | public RtuOnLineVo setOnLine(HashMap<String , Boolean> onLineMap){ |
| | | this.onLineMap = onLineMap ; |
| | | return this ; |
| | | } |
| | | |
| | | public HashMap<String, Boolean> getOnLineMap() { |
| | | return onLineMap; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.local.localProtocol; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class RtuProtocolVo implements Serializable{ |
| | | |
| | | private static final long serialVersionUID = 202312211601001001L; |
| | | |
| | | private List<String> protocolList ; |
| | | |
| | | public RtuProtocolVo(){ |
| | | this.protocolList = new ArrayList<String>() ; |
| | | } |
| | | public String toString(){ |
| | | String s = "" ; |
| | | if(protocolList != null){ |
| | | for(String str : protocolList){ |
| | | s += str + "\n"; |
| | | } |
| | | } |
| | | return s ; |
| | | } |
| | | /** |
| | | * 存入RTU在线情况 |
| | | * @param protocolList 协议集合 |
| | | */ |
| | | public RtuProtocolVo setRtuProtocolList(List<String> protocolList){ |
| | | this.protocolList = protocolList ; |
| | | return this ; |
| | | } |
| | | |
| | | public List<String> getRtuProtocolList() { |
| | | return protocolList; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.local.localProtocol; |
| | | |
| | | |
| | | import com.dy.common.mw.protocol.ProtocolCache; |
| | | |
| | | public class RtuProtocolsDeal { |
| | | /** |
| | | * 查询所有协议 |
| | | */ |
| | | public RtuProtocolVo deal(){ |
| | | return (new RtuProtocolVo()).setRtuProtocolList(ProtocolCache.getProtocolList()); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | import com.dy.aceMw.server.ServerProperties; |
| | | import com.dy.common.queue.Node; |
| | | import com.dy.common.queue.Queue; |
| | | |
| | | public class RtuComResultCache { |
| | | |
| | | //TCP下行命令缓存队列 |
| | | private static Queue cacheQueue = new Queue("RtuComResultCache") ; |
| | | |
| | | private static RtuComResultCache instance = new RtuComResultCache() ; |
| | | |
| | | private RtuComResultCache(){ |
| | | cacheQueue.setLimit(ServerProperties.cacheUpDownDataWarnCount, ServerProperties.cacheUpDownDataMaxCount); |
| | | } |
| | | |
| | | public static RtuComResultCache getInstance(){ |
| | | return instance ; |
| | | } |
| | | |
| | | /** |
| | | * 缓存节点 |
| | | * @param node node |
| | | * @throws Exception 异常 |
| | | */ |
| | | public static void cacheRtuComResult(RtuComResultNode node) throws Exception{ |
| | | if(node != null && node.obj != null){ |
| | | cacheQueue.pushHead(node); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 得到第一个节点 |
| | | * @return Node |
| | | */ |
| | | public static Node getFirstQueueNode(){ |
| | | return cacheQueue.getFirstNode() ; |
| | | } |
| | | |
| | | /** |
| | | * 得到最后一个节点 |
| | | * @return Node |
| | | */ |
| | | 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() ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | import com.dy.aceMw.server.rtuData.dbSv.RtuSv; |
| | | import com.dy.aceMw.web.comResult.CommandResultDeal; |
| | | import com.dy.common.mw.protocol.Data; |
| | | import com.dy.common.queue.NodeObj; |
| | | import com.dy.common.springUtil.SpringContextUtil; |
| | | import com.dy.common.threadPool.ThreadPool; |
| | | import com.dy.common.threadPool.TreadPoolFactory; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | public class RtuComResultNode implements NodeObj { |
| | | |
| | | private static final Logger log = LogManager.getLogger(RtuComResultNode.class.getName()); |
| | | |
| | | public Object obj ;//数据 |
| | | |
| | | public RtuComResultNode(Object obj){ |
| | | this.obj = obj ; |
| | | } |
| | | /** |
| | | * 自己处理自己 |
| | | * @return |
| | | */ |
| | | public boolean dealSelf(){ |
| | | try { |
| | | ThreadPool.Pool pool = TreadPoolFactory.getThreadPoolLong() ; |
| | | pool.putJob(new ThreadPool.Job() { |
| | | public void execute() { |
| | | if(obj != null){ |
| | | if(obj instanceof Data){ |
| | | CommandResultDeal deal = (CommandResultDeal) SpringContextUtil.getBean(CommandResultDeal.class) ; |
| | | deal.deal((Data)obj); |
| | | } |
| | | } |
| | | } |
| | | @Override |
| | | public void destroy(){ |
| | | } |
| | | @Override |
| | | public boolean isDestroy(){ |
| | | return false ; |
| | | } |
| | | |
| | | }); |
| | | } catch (Exception e) { |
| | | log.error("在RtuComResultNode内发生异常", e); |
| | | } |
| | | return true ; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | pool.putJob(new ThreadPool.Job() { |
| | | public void execute() { |
| | | if(obj != null){ |
| | | TaskSurpport t = null ; |
| | | TaskSurpport task = null ; |
| | | try{ |
| | | t = TaskPool.popTask() ; |
| | | if(t != null){ |
| | | t.execute(obj); |
| | | task = TaskPool.popTask() ; |
| | | if(task != null){ |
| | | task.execute(obj); |
| | | }else{ |
| | | log.error("未得到RTU主动上报数据处理任务!"); |
| | | } |
| | | }catch(Exception e){ |
| | | if(t != null){ |
| | | if(task != null){ |
| | | //当有异常时,try catch中的代码可没有执行freeAndCleanTask |
| | | TaskPool.freeAndCleanTask(t); |
| | | TaskPool.freeAndCleanTask(task); |
| | | } |
| | | } |
| | | } |
copy from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/tasks/FromRtuConstantTask.java
copy to pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/tasks/FromRtuComResultConstantTask.java
File was copied from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/tasks/FromRtuConstantTask.java |
| | |
| | | package com.dy.aceMw.server.tasks; |
| | | |
| | | import com.dy.aceMw.server.rtuData.RtuDataNode; |
| | | import com.dy.aceMw.server.rtuData.RtuDataCache; |
| | | import com.dy.aceMw.server.rtuData.RtuComResultNode; |
| | | import com.dy.aceMw.server.rtuData.RtuComResultCache; |
| | | import com.dy.common.mw.core.CoreTask; |
| | | import com.dy.common.queue.Node; |
| | | import org.apache.logging.log4j.LogManager; |
| | |
| | | /** |
| | | * 对RTU上行数据进行业务处理 |
| | | */ |
| | | public class FromRtuConstantTask extends CoreTask { |
| | | private static final Logger log = LogManager.getLogger(FromRtuConstantTask.class.getName()); |
| | | public class FromRtuComResultConstantTask extends CoreTask { |
| | | private static final Logger log = LogManager.getLogger(FromRtuComResultConstantTask.class.getName()); |
| | | |
| | | /** |
| | | * 在单线程环境中运行 |
| | |
| | | @Override |
| | | public Integer execute() { |
| | | try{ |
| | | dealRtuUpData() ; |
| | | dealRtuComResult() ; |
| | | }catch(Exception e){ |
| | | log.error(e); |
| | | } |
| | | return RtuDataCache.size()>0?0:1 ; |
| | | return RtuComResultCache.size()>0?0:1 ; |
| | | } |
| | | /** |
| | | * 处理上行数据 |
| | | * 处理上行命令结果 |
| | | */ |
| | | public void dealRtuUpData() { |
| | | Node first = RtuDataCache.getFirstQueueNode() ; |
| | | public void dealRtuComResult() { |
| | | Node first = RtuComResultCache.getFirstQueueNode() ; |
| | | if(first != null){ |
| | | Node last = RtuDataCache.getLastQueueNode() ; |
| | | Node last = RtuComResultCache.getLastQueueNode() ; |
| | | while (last != null){ |
| | | last = this.doDealRtuUpData(first, last); |
| | | last = this.doDealRtuComResult(first, last); |
| | | } |
| | | } |
| | | } |
| | |
| | | * @param first 第一个节点 |
| | | * @param last 最后一个节点 |
| | | */ |
| | | private Node doDealRtuUpData(Node first, Node last){ |
| | | private Node doDealRtuComResult(Node first, Node last){ |
| | | if(last != null){ |
| | | //在dealNode方法中,可能要把last从队列中移除,这时last.pre为空,所以提前把last.pre取出来 |
| | | Node pre = last.pre ; |
| | |
| | | /** |
| | | * 处理上行数据 |
| | | */ |
| | | public Integer dealRtuUpData_() { |
| | | Node first = RtuDataCache.getFirstQueueNode() ; |
| | | public Integer dealRtuComResult_() { |
| | | Node first = RtuComResultCache.getFirstQueueNode() ; |
| | | if(first != null){ |
| | | Integer count = RtuDataCache.size() ; |
| | | Node last = RtuDataCache.getLastQueueNode() ; |
| | | this.doDealRtuUpData_(first, last); |
| | | Integer count = RtuComResultCache.size() ; |
| | | Node last = RtuComResultCache.getLastQueueNode() ; |
| | | this.doDealRtuComResult_(first, last); |
| | | return count ; |
| | | } |
| | | return null ; |
| | |
| | | * @param first 第一个节点 |
| | | * @param last 最后一个节点 |
| | | */ |
| | | private void doDealRtuUpData_(Node first, Node last){ |
| | | private void doDealRtuComResult_(Node first, Node last){ |
| | | if(last != null){ |
| | | //在dealNode方法中,可能要把last从队列中移除,这时last.pre为空,所以提前把last.pre取出来 |
| | | Node pre = last.pre ; |
| | | dealNode(last) ; |
| | | if(first != last){ |
| | | doDealRtuUpData(first, pre) ; |
| | | doDealRtuComResult_(first, pre) ; |
| | | }else{ |
| | | //停止 |
| | | } |
| | |
| | | */ |
| | | private void dealNode(Node node){ |
| | | if(node != null && node.obj != null){ |
| | | RtuDataNode obj = (RtuDataNode)node.obj ; |
| | | RtuComResultNode obj = (RtuComResultNode)node.obj ; |
| | | obj.dealSelf() ; |
| | | RtuDataCache.removeNode(node); |
| | | RtuComResultCache.removeNode(node); |
| | | } |
| | | } |
| | | |
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/tasks/FromRtuConstantTask.java |
| | |
| | | /** |
| | | * 对RTU上行数据进行业务处理 |
| | | */ |
| | | public class FromRtuConstantTask extends CoreTask { |
| | | private static final Logger log = LogManager.getLogger(FromRtuConstantTask.class.getName()); |
| | | public class FromRtuDataConstantTask extends CoreTask { |
| | | private static final Logger log = LogManager.getLogger(FromRtuDataConstantTask.class.getName()); |
| | | |
| | | /** |
| | | * 在单线程环境中运行 |
| | |
| | | package com.dy.aceMw.web.com; |
| | | |
| | | import com.dy.aceMw.server.forTcp.TcpSessionCache; |
| | | import com.dy.aceMw.server.local.CommandInnerDeaLer; |
| | | import com.dy.aceMw.server.local.ReturnCommand; |
| | | import com.dy.aceMw.server.tasks.RtuDownTask; |
| | | import com.dy.common.mw.core.CoreUnit; |
| | | import com.dy.common.mw.protocol.Command; |
| | | import com.dy.common.mw.protocol.CommandType; |
| | | import com.dy.common.webUtil.BaseResponse; |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | * @Author liurunyu |
| | | * @Date 2023/12/21 13:58 |
| | | * @LastEditTime 2023/12/21 13:58 |
| | | * @Description |
| | | * @Description 命令接收 |
| | | */ |
| | | @Slf4j |
| | | @RestController |
| | |
| | | |
| | | @PostMapping(path = "send", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | public BaseResponse<Command> send(@RequestBody Command com) { |
| | | return BaseResponseUtils.buildSuccess(com); |
| | | log.info("收到web系统发来的命令:\n" + com.toString()) ; |
| | | |
| | | String commandType = com.getType() ; |
| | | if(commandType == null){ |
| | | return BaseResponseUtils.buildError(ReturnCommand.errored("出错,收到命令的命令类型为空!", com.getId(), com.getCode())); |
| | | } |
| | | String commandId = com.getId() ; |
| | | if(commandId == null){ |
| | | return BaseResponseUtils.buildError(ReturnCommand.errored("出错,收到命令的命令ID为空!",null, com.getCode())); |
| | | } |
| | | |
| | | String code = com.getCode() ; |
| | | if(code == null){ |
| | | return BaseResponseUtils.buildError(ReturnCommand.errored("出错,收到命令的命令功能码为空!", com.getId(), null)); |
| | | } |
| | | |
| | | if(commandType.equals(CommandType.innerCommand)){ |
| | | //通信中间件内部命令,例如查询监控中间件时钟,查询RTU在线情况等 |
| | | try{ |
| | | Command reCom = new CommandInnerDeaLer().deal(com) ; |
| | | /* |
| | | boolean error = false ; |
| | | if(reCom.param != null && reCom.param != null){ |
| | | CommandBackParam cbp = (CommandBackParam)reCom.param ; |
| | | if(cbp.getSuccess() != null && !cbp.getSuccess().booleanValue()){ |
| | | error = true ; |
| | | return BaseResponseUtils.buildError(ReturnCommand.errored(cbp.getMessage(), com.getId(), null)); |
| | | } |
| | | } |
| | | if(!error){ |
| | | return BaseResponseUtils.buildError(ReturnCommand.errored(cbp.getMessage(), com.getId(), null)); |
| | | } |
| | | */ |
| | | return BaseResponseUtils.buildSuccess(reCom); |
| | | }catch(Exception e){ |
| | | return BaseResponseUtils.buildError(ReturnCommand.errored("处理内部命令出错" + (e.getMessage() == null?"":("," + e.getMessage())), com.getId(), com.getCode()) ); |
| | | } |
| | | |
| | | }else if(commandType.equals(CommandType.outerCommand)){ |
| | | //发向RTU的外部命令,异步处理,web端jroups成员同步得到命令处理结果,但构造命令及下发命令和命令结果接收要异步得到 |
| | | try{ |
| | | return this.dealOuterCommand(com) ; |
| | | }catch(Exception e){ |
| | | return BaseResponseUtils.buildError(ReturnCommand.errored("处理发向RTU的外部命令出错" + (e.getMessage() == null?"":("," + e.getMessage())), com.getId(), com.getCode()) ); |
| | | } |
| | | }else if(commandType.equals(CommandType.resultCommand)){ |
| | | return BaseResponseUtils.buildError(ReturnCommand.errored("出错,通信中间件不接结果类型的命令!", com.getId(), com.getCode())); |
| | | }else{ |
| | | return BaseResponseUtils.buildError(ReturnCommand.errored("出错,收到命令的命令功能码为空!", com.getId(), com.getCode())); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理发向RTU的外部命令 |
| | | * @return 结果 |
| | | */ |
| | | private BaseResponse<Command> dealOuterCommand(Command command){ |
| | | String rtuAddr = command.getRtuAddr() ; |
| | | if(rtuAddr == null || rtuAddr.trim().equals("")){ |
| | | return BaseResponseUtils.buildError(ReturnCommand.errored("出错,RTU地址为空!", command.getId(), command.getCode())) ; |
| | | } |
| | | rtuAddr = rtuAddr.trim() ; |
| | | Boolean onLine = TcpSessionCache.isConnect(rtuAddr); |
| | | if(onLine == null){ |
| | | return BaseResponseUtils.buildError(ReturnCommand.errored("出错,RTU(地址=" + rtuAddr + ")未上线!", command.getId(), command.getCode())) ; |
| | | }else if(!onLine.booleanValue()){ |
| | | return BaseResponseUtils.buildError(ReturnCommand.errored("出错,RTU(地址=" + rtuAddr + ")离线!", command.getId(), command.getCode())) ; |
| | | } |
| | | |
| | | //生成异步任务 |
| | | RtuDownTask task = new RtuDownTask() ; |
| | | task.data = command ; |
| | | try{ |
| | | log.info("构造下发远程命令" + command.getCode() + "的核心任务,并放入任务队列中"); |
| | | CoreUnit.getInstance().pushCoreTask(task); |
| | | }catch(Exception e){ |
| | | log.error(e.getMessage(), e); |
| | | return BaseResponseUtils.buildError(ReturnCommand.successed("命令处理失败" + e.getMessage(), command.getId(), command.getCode())) ; |
| | | } |
| | | |
| | | return BaseResponseUtils.buildSuccess(ReturnCommand.successed("命令已接受,即将构造并下发命令。", command.getId(), command.getCode())); |
| | | } |
| | | |
| | | /** |
| | | * 收到命令结果 |
| | | * @param command |
| | | private void dealCommandResult(String jgSenderName, Command command){ |
| | | Object obj = command.getParam() ; |
| | | if(obj != null){ |
| | | CommandBackParam p = (CommandBackParam)obj ; |
| | | if(p.getSuccess()){ |
| | | log.info("命令" + (command.getId().equals(Command.defaultId)?"":("(id=" + command.getId() + ")")) + "执行成功" |
| | | + (p.getMessage() == null?"":(p.getMessage().equals("")?"":("," + p.getMessage())))); |
| | | }else{ |
| | | log.error("命令" + (command.getId().equals(Command.defaultId)?"":("(id=" + command.getId() + ")")) + "执行失败" |
| | | + (p.getMessage() == null?"":(p.getMessage().equals("")?"":("," + p.getMessage())))); |
| | | } |
| | | } |
| | | } |
| | | */ |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.web.comResult; |
| | | |
| | | import com.dy.common.mw.protocol.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.springframework.web.util.UriComponentsBuilder; |
| | | |
| | | /** |
| | | * @Author liurunyu |
| | | * @Date 2023/12/21 20:28 |
| | | * @LastEditTime 2023/12/21 20:28 |
| | | * @Description |
| | | */ |
| | | @Slf4j |
| | | @Component() |
| | | public class CommandResultDeal { |
| | | |
| | | private RestTemplate restTemplate; |
| | | |
| | | @Autowired |
| | | public void setRestTemplate(RestTemplate restTemplate){ |
| | | this.restTemplate = restTemplate ; |
| | | } |
| | | |
| | | |
| | | public void deal(Data data) { |
| | | if (data.rtuResultSendWebUrl != null && data.rtuResultSendWebUrl.trim().equals("")) { |
| | | String url = UriComponentsBuilder.fromUriString(data.rtuResultSendWebUrl) |
| | | .build() |
| | | .toUriString(); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | HttpEntity<?> httpEntity = new HttpEntity<>(data, headers); |
| | | ResponseEntity<WebResponseVo> response = null; |
| | | try { |
| | | // 通过Post方式调用接口 |
| | | response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, WebResponseVo.class); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | assert response != null; |
| | | } else { |
| | | log.error("严重错误,在com.dy.aceMw.web.comResult.CommandResultDeal里,处理的是RTU命令结果Node,但数据中rtuResultSendWebUrl为空"); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.web.comResult; |
| | | |
| | | /** |
| | | * @Author liurunyu |
| | | * @Date 2023/12/21 20:43 |
| | | * @LastEditTime 2023/12/21 20:43 |
| | | * @Description |
| | | */ |
| | | public class WebResponseVo { |
| | | public boolean result ; |
| | | |
| | | public boolean isResult() { |
| | | return result; |
| | | } |
| | | |
| | | public void setResult(boolean result) { |
| | | this.result = result; |
| | | } |
| | | } |
| | |
| | | public static Integer heartbeatTimes = 3 ; |
| | | //发送数据次数 |
| | | public static Integer sendTimes = 0 ; |
| | | |
| | | //发送完数据后,是否关闭TCP连接,1是,0否 |
| | | public static Integer sendOverThenCloseConnect = 0 ; |
| | | |
| | | |
| | | public static boolean startTcpConnectWork = false ; |
| | | |
| | | //mwTestServer |
| | |
| | | public Integer heartbeatTimes = 3 ; |
| | | //发送数据次数 |
| | | public Integer sendTimes = 0 ; |
| | | //发送完数据后,是否关闭TCP连接,1是,0否 |
| | | public Integer sendOverThenCloseConnect = 0 ; |
| | | |
| | | /** |
| | | * 对象转成json |
| | |
| | | public void setSendTimes(Integer sendTimes) { |
| | | this.sendTimes = sendTimes; |
| | | } |
| | | |
| | | public Integer getSendOverThenCloseConnect() { |
| | | return sendOverThenCloseConnect; |
| | | } |
| | | |
| | | public void setSendOverThenCloseConnect(Integer sendOverThenCloseConnect) { |
| | | this.sendOverThenCloseConnect = sendOverThenCloseConnect; |
| | | } |
| | | } |
| | |
| | | ServerProperties.sendInterval = rVo.sendInterval ; |
| | | ServerProperties.heartbeatTimes = rVo.heartbeatTimes ; |
| | | ServerProperties.sendTimes = rVo.sendTimes ; |
| | | ServerProperties.sendOverThenCloseConnect = rVo.sendOverThenCloseConnect ; |
| | | log.info("得到配置成功"); |
| | | log.info(" 开始RtuAddr=" + ServerProperties.rtuAddrStart); |
| | | log.info(" 截止RtuAddr=" + ServerProperties.rtuAddrEnd); |
| | |
| | | log.info(" 发送数据间隔=" + ServerProperties.sendTimes); |
| | | log.info(" 每轮次发送心跳次数=" + ServerProperties.heartbeatTimes); |
| | | log.info(" 每RTU上报数据轮次=" + ServerProperties.sendTimes); |
| | | log.info(" 发送完数据后,是否关闭TCP连接(1是,0否)=" + ServerProperties.sendOverThenCloseConnect); |
| | | break ; |
| | | }else{ |
| | | log.error("rmi得到配置失败:json转ResConfigVo为null"); |
| | |
| | | byte[] preByte = new byte[remain]; |
| | | in.get(preByte) ; |
| | | in.position(0) ; |
| | | log.info("收到中心应答数据:" + ByteUtil.bytes2Hex(preByte, true)); |
| | | log.info("收到中心下行数据:" + ByteUtil.bytes2Hex(preByte, true)); |
| | | } |
| | | return true; |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void execute() throws Exception { |
| | | if(session != null){ |
| | | if(sendTimes <= ServerProperties.sendTimes){ |
| | | log.info("RTU" + rtuAddr + "开始任务"); |
| | | log.info("RTU" + rtuAddr + "将要执行" + ServerProperties.sendTimes + "轮次任务,当前轮次是" + sendTimes); |
| | | sendDataOfP206V1_0_0() ; |
| | | }else{ |
| | | log.info("RTU" + rtuAddr + "等待一会,以接收通信中间件下行数据"); |
| | | if(overStart == 0){ |
| | | overStart = System.currentTimeMillis() ; |
| | | if(!this.isOver){ |
| | | if(session != null){ |
| | | if(sendTimes <= ServerProperties.sendTimes){ |
| | | log.info("RTU" + rtuAddr + "开始任务"); |
| | | log.info("RTU" + rtuAddr + "将要执行" + ServerProperties.sendTimes + "轮次任务,当前轮次是" + sendTimes); |
| | | sendDataOfP206V1_0_0() ; |
| | | }else{ |
| | | long now = System.currentTimeMillis() ; |
| | | if(now - overStart >= 30 * 1000){ |
| | | if(ServerProperties.sendOverThenCloseConnect == 1){ |
| | | log.info("RTU" + rtuAddr + "等待一会,以接收通信中间件下行数据"); |
| | | if(overStart == 0){ |
| | | overStart = System.currentTimeMillis() ; |
| | | }else{ |
| | | long now = System.currentTimeMillis() ; |
| | | if(now - overStart >= 30 * 1000){ |
| | | this.jobOver() ; |
| | | } |
| | | } |
| | | }else{ |
| | | this.jobOver() ; |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | private void jobOver(){ |
| | | session.closeOnFlush() ; |
| | | if(ServerProperties.sendOverThenCloseConnect == 1){ |
| | | session.closeOnFlush() ; |
| | | } |
| | | this.isOver = true ; |
| | | TcpClUnit.clientOver() ; |
| | | } |
| | |
| | | ServerProperties.sendInterval = conf.getSetAttrPlusInt(doc, "config.base", "sendInterval", null, 1, null, null) ; |
| | | ServerProperties.heartbeatTimes = conf.getSetAttrPlusInt(doc, "config.base", "heartbeatTimes", null, 1, null, null) ; |
| | | ServerProperties.sendTimes = conf.getSetAttrPlusInt(doc, "config.base", "sendTimes", null, 1, null, null) ; |
| | | ServerProperties.sendOverThenCloseConnect = conf.getSetAttrPlusInt(doc, "config.base", "sendOverThenCloseConnect", null, 0, 1, null) ; |
| | | |
| | | |
| | | ///////////////// |
| | |
| | | public static Integer heartbeatTimes = 0 ; |
| | | //发送数据次数 |
| | | public static Integer sendTimes = 0 ; |
| | | //发送完数据后,是否关闭TCP连接,1是,0否 |
| | | public static Integer sendOverThenCloseConnect = 0 ; |
| | | |
| | | } |
| | |
| | | conVo.sendInterval = ServerProperties.sendInterval ; |
| | | conVo.heartbeatTimes = ServerProperties.heartbeatTimes ; |
| | | conVo.sendTimes = ServerProperties.sendTimes ; |
| | | conVo.sendOverThenCloseConnect = ServerProperties.sendOverThenCloseConnect ; |
| | | sta = new MwTestClientStatus() ; |
| | | sta.confVo = conVo ; |
| | | token2ClientMap.put("" + token, sta); |
| | |
| | | public Integer heartbeatTimes = 3 ; |
| | | //发送数据次数 |
| | | public Integer sendTimes = 0 ; |
| | | //发送完数据后,是否关闭TCP连接,1是,0否 |
| | | public Integer sendOverThenCloseConnect = 0 ; |
| | | |
| | | /** |
| | | * 对象转成json |
| | | * @return 返回 json |
| | |
| | | public void setSendTimes(Integer sendTimes) { |
| | | this.sendTimes = sendTimes; |
| | | } |
| | | |
| | | public Integer getSendOverThenCloseConnect() { |
| | | return sendOverThenCloseConnect; |
| | | } |
| | | |
| | | public void setSendOverThenCloseConnect(Integer sendOverThenCloseConnect) { |
| | | this.sendOverThenCloseConnect = sendOverThenCloseConnect; |
| | | } |
| | | } |
| | |
| | | sendInterval:发送数据间隔 秒 |
| | | heartbeatTimes:每一轮次发送数据,其中包括心跳发送次数 |
| | | sendTimes:发送数据次数 |
| | | sendOverThenCloseConnect:发送完数据后,是否关闭TCP连接,1是,0否 |
| | | --> |
| | | <base |
| | | rtuAddrStart="5323280000" |
| | |
| | | sendInterval="2" |
| | | heartbeatTimes="3" |
| | | sendTimes="1" |
| | | sendOverThenCloseConnect="0" |
| | | /> |
| | | |
| | | <!-- |