|  |  |  | 
|---|
|  |  |  | public Boolean isThisProtocolHead(byte[] bs) throws Exception{ | 
|---|
|  |  |  | if(bs == null){ | 
|---|
|  |  |  | return null ; | 
|---|
|  |  |  | }else if(bs.length >= (ProtocolConstantV206V202404.ctrlIndex - 1) | 
|---|
|  |  |  | }else if(bs.length >= ProtocolConstantV206V202404.ctrlIndex | 
|---|
|  |  |  | && bs[0] == ProtocolConstantV206V202404.P_Head_Byte){ | 
|---|
|  |  |  | if(bs[2] == ProtocolConstantV206V202404.P_Head_Byte){ | 
|---|
|  |  |  | return true ; | 
|---|
|  |  |  | if(bs[3] == (byte)0x80 || bs[3] == (byte)0x81){ | 
|---|
|  |  |  | return true ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return false ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else if((byte)(bs[2] & 0xF8) == ProtocolConstantV206V202404.P_Head_Byte){ | 
|---|
|  |  |  | //如果控制域、地址域、用户数据域(应用层)的字节总数大于255,则通过扩展第二个开始字符0x68的低3位作为长L的高位扩展 | 
|---|
|  |  |  | //0xF8二进制: 11111000 | 
|---|
|  |  |  | return true ; | 
|---|
|  |  |  | if(bs[3] == (byte)0x80 || bs[3] == (byte)0x81){ | 
|---|
|  |  |  | return true ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return false ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return false ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 检查头 | 
|---|
|  |  |  | * @param bs 上行字节数组 | 
|---|
|  |  |  | * @throws Exception 异常 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void checkHead(byte[] bs) throws Exception{ | 
|---|
|  |  |  | if(bs.length < ProtocolConstantV206V202404.lenHead2Code | 
|---|
|  |  |  | || bs[0] != ProtocolConstantV206V202404.P_Head_Byte){ | 
|---|
|  |  |  | throw new Exception("上行数据帧头不正确!") ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | if(bs.length >= ProtocolConstantV206V202404.lenHead2Code){ | 
|---|
|  |  |  | if(bs[2] != ProtocolConstantV206V202404.P_Head_Byte | 
|---|
|  |  |  | && (byte)(bs[2] & 0xF8) != ProtocolConstantV206V202404.P_Head_Byte){ | 
|---|
|  |  |  | throw new Exception("上行数据帧头不正确!") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | throw new Exception("上行数据帧头不正确!") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 检查尾 | 
|---|
|  |  |  | 
|---|
|  |  |  | public byte createCtrl(byte dir, byte funcCode){ | 
|---|
|  |  |  | byte b = dir;//DIR = 1(0x80),表示此帧报文是由终端发出的上行报文; | 
|---|
|  |  |  | b = (byte)(b | funcCode) ; | 
|---|
|  |  |  | //DIV = 1(0x40),表示此报文已被拆分为若干帧 | 
|---|
|  |  |  | //FCB = 1(0x08),表示只发一次 | 
|---|
|  |  |  | b = (byte)(b |0x08) ; | 
|---|
|  |  |  | //DIV = 1(0x20),表示此报文已被拆分为若干帧 | 
|---|
|  |  |  | //FCB = 1(0x10),表示只发一次 | 
|---|
|  |  |  | b = (byte)(b |0x10) ; | 
|---|
|  |  |  | //DIR = 0 下行,则功能码采用0 | 
|---|
|  |  |  | return b ; | 
|---|
|  |  |  | } | 
|---|