|  |  |  | 
|---|
|  |  |  | *    org.apache.mina.core.buffer.IoBuffer, | 
|---|
|  |  |  | *    org.apache.mina.filter.codec.ProtocolDecoderOutput) | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) { | 
|---|
|  |  |  | String rtuAddr = (String)session.getAttribute(TcpIoSessionAttrIdIsRtuAddr.sessionArrIdKey) ; | 
|---|
|  |  |  | String rtuAddr = (String)session.getAttribute(TcpIoSessionAttrIdIsRtuAddr.sessionArrRtuAddr) ; | 
|---|
|  |  |  | if(rtuAddr == null){ | 
|---|
|  |  |  | //会话未被管理 | 
|---|
|  |  |  | //会话管理器中不存在此会话,说明刚建立网络连接, | 
|---|
|  |  |  | 
|---|
|  |  |  | //有一些协议,负责发上线数据,但上线(或心跳)数据中无 Rtu地址,所以这样的数据只能放行,而且不能产生有身份(Rtu地址)的网络会话,即不能把session放入会话缓存中 | 
|---|
|  |  |  | //有一些协议,Rtu负责发上线数据,上线数据中有 Rtu地址,所以这样的数据放行后,能产生有身份(Rtu地址)的网络会话,即能把session放入会话缓存中 | 
|---|
|  |  |  | //不论何种情形,上线数据的数据量不会很大,一般不会产生断包,所以这里只进行简单断包检查。 | 
|---|
|  |  |  | PrefixedDataAvailableStatus dataStatus = this.pdaHandle.forOnLine(in) ; | 
|---|
|  |  |  | PrefixedDataAvailableStatus dataStatus = this.pdaHandle.forOnLine(session, in) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(dataStatus.protocolName != null && dataStatus.protocolVersion != null){ | 
|---|
|  |  |  | session.setAttribute(TcpIoSessionAttrIdIsRtuAddr.sessionArrProtocolName, dataStatus.protocolName) ; | 
|---|
|  |  |  | session.setAttribute(TcpIoSessionAttrIdIsRtuAddr.sessionArrProtocolVersion, dataStatus.protocolVersion) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(dataStatus.isCompleted() || dataStatus.isAdjoined()){ | 
|---|
|  |  |  | //正好或粘包 | 
|---|
|  |  |  | this.nextDeal(in, dataStatus.getDataLen(), out) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | @SuppressWarnings("unused") | 
|---|
|  |  |  | private boolean doDecode_data(IoSession session, IoBuffer in, ProtocolDecoderOutput out, String rtuAddr) { | 
|---|
|  |  |  | //非上线数据,可能会出现断包或粘包现象 | 
|---|
|  |  |  | PrefixedDataAvailableStatus dataStatus = this.pdaHandle.forUpData(in) ; | 
|---|
|  |  |  | PrefixedDataAvailableStatus dataStatus = this.pdaHandle.forUpData(session, in) ; | 
|---|
|  |  |  | if(dataStatus == null){ | 
|---|
|  |  |  | //不可能发生 | 
|---|
|  |  |  | log.error("严重错误,Rtu (RTU" + rtuAddr + ")上行数据完整性检查时,返回的对象为空。") ; | 
|---|