| | |
| | | package com.dy.common.mw.protocol.p206V1; |
| | | |
| | | import com.dy.common.mw.channel.tcp.TcpIoSessionAttrIdIsRtuAddr; |
| | | import com.dy.common.util.ByteUtil; |
| | | import com.dy.common.util.ByteUtilUnsigned; |
| | | import com.dy.common.util.CRC16; |
| | | import com.dy.common.util.CRC8_for_2_0; |
| | | import org.apache.mina.core.session.IoSession; |
| | | |
| | | |
| | | public class CommonV1 { |
| | | |
| | | |
| | | /** |
| | | * 检查头 |
| | | * @param bs 上行字节数组 |
| | |
| | | int len = ByteUtilUnsigned.byte2Byte(bs, ProtocolConstantV206V1.dataLenIndex); |
| | | return len + ProtocolConstantV206V1.lenHead2ctrl + ProtocolConstantV206V1.lenTail; |
| | | }else{ |
| | | int len = ByteUtilUnsigned.bytes2Short_BE(bs, ProtocolConstantV206V1.UG_dataLenIndex_start); |
| | | int len = ByteUtilUnsigned.bytes2Short_LE(bs, ProtocolConstantV206V1.UG_dataLenIndex_start); |
| | | return len + ProtocolConstantV206V1.UG_lenHead2Cmd + ProtocolConstantV206V1.UG_lenTail; |
| | | } |
| | | } |
| | |
| | | return "计算CRC是:" + crcCompute + ",上传CRC是" + crcInBs ; |
| | | } |
| | | }else{ |
| | | int crcCompute = (byte)new CRC16().CRC(bs, ProtocolConstantV206V1.ctrlIndex, bs.length - 3) ; |
| | | int crcInBs = ByteUtilUnsigned.bytes2Short_BE(bs, bs.length - 3) ; |
| | | short crcCompute = new CRC16().CRC(bs, 0, bs.length - 4) ; |
| | | short crcInBs = ByteUtil.bytes2Short_BE(bs,bs.length - 3) ; |
| | | //int crcInBs = ByteUtilUnsigned.bytes2Short_BE(bs, bs.length - 3) ; |
| | | if(crcCompute == crcInBs){ |
| | | return null ; |
| | | }else{ |