1、完善代码;
2、补全RTU状态采集(阀门状态)。
| | |
| | | } |
| | | @Override |
| | | public void notify(NotifyInfo ...infos) { |
| | | notify.notify(rtuAddr, ProtocolConstantV206V1.protocolName, ProtocolConstantV206V1.protocolVer, infos); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | isFail = true ; |
| | | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1.protocolName, rtuAddr, "严重错误,分析Rtu数据出错!数据为:" + upHex + (e.getMessage() == null?"":(",出错信息:" + e.getMessage())), e))} ; |
| | |
| | | package com.dy.common.mw.protocol.p206V2; |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1.ProtocolConstantV206V1; |
| | | import com.dy.common.util.DateTime; |
| | | |
| | | @AnnotationDriver(enable = true, |
| | |
| | | } |
| | | @Override |
| | | public void notify(NotifyInfo ...infos) { |
| | | notify.notify(rtuAddr, ProtocolConstantV206V1.protocolName, ProtocolConstantV206V1.protocolVer, infos); |
| | | } |
| | | }); |
| | | } |
| | |
| | | if(crcStr != null){ |
| | | return new MidResult[]{(new MidResultError(ProtocolConstantV206V202404.protocolName, rtuAddr, "严重错误,上行数据CRC检查失败," + crcStr, null))} ; |
| | | } |
| | | rtuAddr = cp.parseRtuAddr(upBuffer) ; |
| | | upCode = cp.parseCode(upBuffer) ; |
| | | if(upCode == null){ |
| | | return new MidResult[]{(new MidResultError(ProtocolConstantV206V202404.protocolName, rtuAddr, "严重错误,未能从上行数据中解析出功能码!", null))} ; |
| | |
| | | } |
| | | @Override |
| | | public void notify(NotifyInfo ...infos) { |
| | | notify.notify(rtuAddr, ProtocolConstantV206V1.protocolName, ProtocolConstantV206V1.protocolVer, infos); |
| | | } |
| | | }); |
| | | } |
| | |
| | | import com.dy.rtuMw.server.forTcp.MidResultActionError; |
| | | import com.dy.rtuMw.server.forTcp.MidResultActionFromRtu; |
| | | import com.dy.rtuMw.server.forTcp.MidResultActionToRtu; |
| | | import com.dy.rtuMw.server.protocolDriver.RtuInfoNotify; |
| | | import com.dy.rtuMw.server.rtuStatus.RtuInfoNotify; |
| | | |
| | | public class AdapterImp_ProtocolUnit implements ProtocolUnitAdapter { |
| | | |
| | |
| | | this.valveCloseLastDt = DateTime.yyyy_MM_dd_HH_mm_ss() ; |
| | | this.valveStatusLastTimeStamp = System.currentTimeMillis() ; |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | * 得到部分状态 |
| | | * @return |
| | | */ |
| | | public static Map<String, RtuStatus> partStatus(String[] rtuAddrArrGrp){ |
| | | public static Map<String, RtuStatus> someStatus(String[] rtuAddrArrGrp){ |
| | | synchronized (map){ |
| | | Map<String, RtuStatus> map = new HashMap<>(); |
| | | Map<String, RtuStatus> rsMap = new HashMap<>(); |
| | | for(String rtuAddr : rtuAddrArrGrp){ |
| | | RtuStatus status = map.get(rtuAddr) ; |
| | | if(status != null){ |
| | | map.put(rtuAddr, status) ; |
| | | rsMap.put(rtuAddr, status) ; |
| | | } |
| | | } |
| | | return map ; |
| | | return rsMap ; |
| | | } |
| | | } |
| | | /** |
| | | * 得到一个RTU的状态 |
| | | * @return |
| | | */ |
| | | public static RtuStatus oneStatus(String rtuAddr){ |
| | | return map.get(rtuAddr) ; |
| | | } |
| | | |
| | | |
| | | public static void onLine(String rtuAddr, String ip, Integer port, String protocolName, Short protocolVersion){ |
| | | RtuStatus vo = map.get(rtuAddr) ; |
| | | if(vo == null) { |
| | |
| | | * 得到Tcp通信协议名称 |
| | | * @param rtuAddr |
| | | * @return |
| | | public static String getTcpProtocolName(String rtuAddr){ |
| | | TcpSession tcpSe = sessionTable.get(rtuAddr) ; |
| | | if(tcpSe != null){ |
| | | return tcpSe.protocolName ; |
| | | }else{ |
| | | return null ; |
| | | } |
| | | } |
| | | */ |
| | | /** |
| | | * 得到Tcp通信协议名称 |
| | | * @param rtuAddr |
| | | * @return |
| | | * */ |
| | | public static Object[] getTcpProtocolNameVersion(String rtuAddr){ |
| | | TcpSession tcpSe = map.get(rtuAddr) ; |
| | |
| | | return map ; |
| | | } |
| | | } |
| | | // |
| | | // /** |
| | | // * 得到所有RTU连接状态情况 |
| | | // * @return |
| | | // */ |
| | | // public static List<RtuSessionStatus> allConnectStatus(){ |
| | | // synchronized (sessionTable){ |
| | | // List<RtuSessionStatus> list = new ArrayList<RtuSessionStatus>(); |
| | | // Iterator<Entry<String, TcpSession>> it = sessionTable.entrySet().iterator() ; |
| | | // Entry<String, TcpSession> entry = null ; |
| | | // while(it.hasNext()){ |
| | | // entry = it.next() ; |
| | | // RtuSessionStatus vo = new RtuSessionStatus() ; |
| | | // vo.rtuAddr = entry.getKey() ; |
| | | // IoSession se = entry.getValue().ioSession ; |
| | | // vo.onTrueOffLine = se.isConnected() ; |
| | | // InetSocketAddress sa = (InetSocketAddress)se.getRemoteAddress() ; |
| | | // if(sa != null){ |
| | | // InetAddress inetAddr = sa.getAddress() ; |
| | | // if(inetAddr != null){ |
| | | // vo.ip = inetAddr.getHostAddress() ; |
| | | // vo.port = sa.getPort() ; |
| | | // } |
| | | // } |
| | | // list.add(vo) ; |
| | | // } |
| | | // return list ; |
| | | // } |
| | | // } |
| | | // |
| | | |
| | | /** |
| | | * 得到IoSession |
| | | * @param rtuAddr |
| | | * @return |
| | | */ |
| | | // public IoSession getIoSession(String rtuAddr){ |
| | | // TcpSession tcpSe = sessionMap.get(rtuAddr) ; |
| | | // if(tcpSe != null){ |
| | | // return tcpSe.ioSession ; |
| | | // } |
| | | // return null ; |
| | | // } |
| | | |
| | | |
| | | /** |
| | | * 网络是否连接 |
| | | * @param rtuAddr |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | // public static void updateRtuStatus(Long now){ |
| | | // synchronized (sessionTable){ |
| | | // Iterator<TcpSession> it = sessionTable.values().iterator() ; |
| | | // TcpSession tcpSe ; |
| | | // while(it.hasNext()){ |
| | | // tcpSe = it.next() ; |
| | | // if(tcpSe.lastUpDataTime != null){ |
| | | // if(now - tcpSe.lastUpDataTime > ServerProperties.lastUpDataTimeLive){ |
| | | // tcpSe.lastUpDataTime = null ; |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | |
| | | } |
| | |
| | | }else if(code.equals(CodeLocal.allRtuStates)){ |
| | | return this.allRtuStates(com) ; |
| | | }else if(code.equals(CodeLocal.partRtuStates)){ |
| | | return this.partRtuStates(com) ; |
| | | return this.someRtuStates(com) ; |
| | | }else if(code.equals(CodeLocal.oneRtuStates)){ |
| | | return this.oneRtuStates(com) ; |
| | | }else if(code.equals(CodeLocal.allProtocols)){ |
| | | return this.allProtocols(com) ; |
| | | }else if(code.equals(CodeLocal.stopTcpSv)){ |
| | |
| | | * 查询部分RTU状态 |
| | | * @throws Exception |
| | | */ |
| | | private Command partRtuStates(Command command) throws Exception{ |
| | | private Command someRtuStates(Command command) throws Exception{ |
| | | if(command.param != null && command.param instanceof String && !command.param.equals("")){ |
| | | String[] rtuAddrGrp = ((String)command.param).split(","); |
| | | Map<String, RtuStatus> map = new RtuStatusDeal().dealPart(rtuAddrGrp) ; |
| | | Map<String, RtuStatus> map = new RtuStatusDeal().dealSome(rtuAddrGrp) ; |
| | | return ReturnCommand.successed("查询部分RTU状态结果", command.getId(), command.getCode(), map) ; |
| | | }else{ |
| | | return ReturnCommand.errored("出错,命令参数应该是所查询RTU的地址串", command.getId(), command.getCode()) ; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 查询部分RTU状态 |
| | | * @throws Exception |
| | | */ |
| | | private Command oneRtuStates(Command command) throws Exception{ |
| | | if(command.param != null && command.param instanceof String && !command.param.equals("")){ |
| | | String rtuAddr = (String)command.param; |
| | | RtuStatus rtuStatus = new RtuStatusDeal().dealOne(rtuAddr) ; |
| | | return ReturnCommand.successed("查询部分RTU状态结果", command.getId(), command.getCode(), rtuStatus) ; |
| | | }else{ |
| | | return ReturnCommand.errored("出错,命令参数应该是所查询RTU的地址", command.getId(), command.getCode()) ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询所有RTU协议配置 |
| | | * @throws Exception |
| | | */ |
| | |
| | | |
| | | public static final String partRtuStates = "LCD0011" ;//查询部分RTU状态 |
| | | |
| | | public static final String oneRtuStates = "LCD0012" ;//查询一个RTU状态 |
| | | |
| | | public static final String allProtocols = "LCD0100" ;//查询所有协议配置 |
| | | |
| | | public static final String stopTcpSv = "LCD0110" ;//停止TCP服务,不再接入新的TCP连接,已经TCP连接的全部断连接 |
| | |
| | | public class RtuStatusDeal { |
| | | |
| | | /** |
| | | * 查询在线与不在线情况 |
| | | * 查询状态 |
| | | */ |
| | | public Map<String, RtuStatus> dealAll(){ |
| | | return RtuStatusDealer.allStatus(); |
| | |
| | | |
| | | |
| | | /** |
| | | * 查询在线与不在线情况 |
| | | * 查询状态 |
| | | */ |
| | | public Map<String, RtuStatus> dealPart(String[] rtuAddrGrp){ |
| | | return RtuStatusDealer.partStatus(rtuAddrGrp) ; |
| | | public Map<String, RtuStatus> dealSome(String[] rtuAddrGrp){ |
| | | return RtuStatusDealer.someStatus(rtuAddrGrp) ; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 查询状态 |
| | | */ |
| | | public RtuStatus dealOne(String rtuAddr){ |
| | | return RtuStatusDealer.oneStatus(rtuAddr) ; |
| | | } |
| | | } |
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/protocolDriver/RtuInfoNotify.java |
| | |
| | | package com.dy.rtuMw.server.protocolDriver; |
| | | package com.dy.rtuMw.server.rtuStatus; |
| | | |
| | | import com.dy.common.mw.protocol.Notify; |
| | | import com.dy.common.mw.protocol.NotifyInfo; |