| | |
| | | package com.dy.aceMw.server.forTcp; |
| | | |
| | | import com.dy.aceMw.server.busi.AboutRtuNode; |
| | | import com.dy.aceMw.server.busi.TcpUpDataCache; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | |
| | | //此处实现,与以前不一样, |
| | | //以前实现:匹配命令是从后向前匹配, |
| | | //当前实现,匹配命令是从前向后匹配,原因:举例,当批量下发补召命令,如果从后匹配,则前面命令会下发多次,即一个上报次数据会补召多次 |
| | | MidResultToRtu resToRtu = TcpDownCommandCache.matchFromHead(resFromRtu) ; |
| | | MidResultToRtu resToRtu = TcpDownCommandCach.matchFromHead(resFromRtu) ; |
| | | if(resToRtu != null){ |
| | | //匹配到下发的命令 |
| | | resFromRtu.setCommandId(resToRtu.commandId) ; |
| | | this.nextDeal(false, resFromRtu); |
| | | this.sendResult(false, resFromRtu); |
| | | }else{ |
| | | this.nextDeal(false, resFromRtu); |
| | | this.sendResult(false, resFromRtu); |
| | | //未匹配到下发的命令,命令在缓存因超时被清除了 |
| | | RtuStatusDealer.commandFail2Success(resFromRtu.rtuAddr) ; |
| | | } |
| | | }else{ |
| | | //主动上报数据 |
| | | this.nextDeal(true, resFromRtu); |
| | | this.sendResult(true, resFromRtu); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 进入多线程环境中运行 |
| | | * @param reportOrResponse_trueOrFalse |
| | | * @param resFromRtu |
| | | */ |
| | | private void nextDeal(boolean reportOrResponse_trueOrFalse, MidResultFromRtu resFromRtu){ |
| | | private void sendResult(boolean reportOrResponse_trueOrFalse, MidResultFromRtu resFromRtu){ |
| | | try{ |
| | | TcpUpDataCache.cacheRtuUpData(reportOrResponse_trueOrFalse, new AboutRtuNode(resFromRtu.data)); |
| | | String json = resFromRtu.data.toJson() ; |
| | | // if(reportOrResponse_trueOrFalse){ |
| | | // ToMqMessageCach.cachObj(MessageType.RtuAutoReport, json); |
| | | // }else{ |
| | | // ToMqMessageCach.cachObj(MessageType.RtuCmdResponse, json); |
| | | // } |
| | | }catch(Exception e){ |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | |
| | | } |
| | | } |