|  |  |  | 
|---|
|  |  |  | * 得到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 [0]=在线数量,[2]上线过,但当前离线的数量 | 
|---|
|  |  |  | * @return [0]=在线数量,[1]上线过,但当前离线的数量 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static Integer[] allOnLineStateStatistics(){ | 
|---|
|  |  |  | synchronized (map){ | 
|---|
|  |  |  | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 设置上行数据时刻 | 
|---|
|  |  |  | * 当有上行数据时 | 
|---|
|  |  |  | * @param rtuAddr | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static void cacheUpDataTime(String rtuAddr){ | 
|---|
|  |  |  | public static void whenUpData(String rtuAddr){ | 
|---|
|  |  |  | TcpSession tcpSe = map.get(rtuAddr) ; | 
|---|
|  |  |  | if(tcpSe != null){ | 
|---|
|  |  |  | tcpSe.lastDownComTime = 0L ;//置0,使等待lastUpDataTimeLive(见config.xml配置文件)时长后,即刻下发缓存中的命令 | 
|---|
|  |  |  | tcpSe.lastUpDataTime = System.currentTimeMillis() ; | 
|---|
|  |  |  | tcpSe.lastUpDataTimeForOnlineCtrl = System.currentTimeMillis() ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //   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 ; | 
|---|
|  |  |  | //               } | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //         } | 
|---|
|  |  |  | //      } | 
|---|
|  |  |  | //   } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|