|  |  |  | 
|---|
|  |  |  | *    org.apache.mina.filter.codec.ProtocolDecoderOutput) | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) { | 
|---|
|  |  |  | String meterNo = (String)session.getAttribute(TcpIoSessionAttrIdIsRtuAddr.sessionArrIdKey) ; | 
|---|
|  |  |  | if(meterNo == null){ | 
|---|
|  |  |  | String rtuAddr = (String)session.getAttribute(TcpIoSessionAttrIdIsRtuAddr.sessionArrIdKey) ; | 
|---|
|  |  |  | if(rtuAddr == null){ | 
|---|
|  |  |  | //会话未被管理 | 
|---|
|  |  |  | //会话管理器中不存在此会话,说明刚建立网络连接, | 
|---|
|  |  |  | return this.doDecode_onLineData(session, in, out) ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | //会话已被管理 | 
|---|
|  |  |  | //会话管理器中存在此会话,说明已经上线了, | 
|---|
|  |  |  | return this.doDecode_data(session, in, out, meterNo) ; | 
|---|
|  |  |  | return this.doDecode_data(session, in, out, rtuAddr) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param session IO会话 | 
|---|
|  |  |  | * @param in 输入Buffer | 
|---|
|  |  |  | * @param out 协议输出编码 | 
|---|
|  |  |  | * @param meterNo 控制器编号 | 
|---|
|  |  |  | * @param rtuAddr 控制器地址 | 
|---|
|  |  |  | * @return 是否正好或粘包 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @SuppressWarnings("unused") | 
|---|
|  |  |  | private boolean doDecode_data(IoSession session, IoBuffer in, ProtocolDecoderOutput out, String meterNo) { | 
|---|
|  |  |  | private boolean doDecode_data(IoSession session, IoBuffer in, ProtocolDecoderOutput out, String rtuAddr) { | 
|---|
|  |  |  | //非上线数据,可能会出现断包或粘包现象 | 
|---|
|  |  |  | PrefixedDataAvailableStatus dataStatus = this.pdaHandle.forUpData(in) ; | 
|---|
|  |  |  | if(dataStatus == null){ | 
|---|
|  |  |  | //不可能发生 | 
|---|
|  |  |  | log.error("严重错误,Rtu (水表号为" + meterNo + ")上行数据完整性检查时,返回的对象为空。") ; | 
|---|
|  |  |  | log.error("严重错误,Rtu (RTU" + rtuAddr + ")上行数据完整性检查时,返回的对象为空。") ; | 
|---|
|  |  |  | this.nextDeal(in, null, out) ; | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | 
|---|
|  |  |  | this.nextDeal(in, dataStatus.getDataLen(), out) ; | 
|---|
|  |  |  | if(dataStatus.isAdjoined()){ | 
|---|
|  |  |  | //说明粘包了,还有数据,需要对这些数据再次执行doDecode_方法. | 
|---|
|  |  |  | return this.doDecode_data(session, in, out, meterNo) ;//加上递归 | 
|---|
|  |  |  | return this.doDecode_data(session, in, out, rtuAddr) ;//加上递归 | 
|---|
|  |  |  | }else if(dataStatus.isCompleted()){ | 
|---|
|  |  |  | //数据不断不粘 | 
|---|
|  |  |  | return true; | 
|---|