| | |
| | | */ |
| | | public class RegisterMessage extends DriveExamProtocol { |
| | | |
| | | private static final int BODY_LENGTH = 4; |
| | | private static final int BODY_LENGTH = 2; |
| | | /** |
| | | * 构造函数 |
| | | * |
| | |
| | | @Override |
| | | protected byte[] createMessageBody() { |
| | | byte[] messageBody = new byte[BODY_LENGTH]; |
| | | messageBody[0] = 0x7E; |
| | | messageBody[1] = 0x66; |
| | | messageBody[0] = 0x65; |
| | | messageBody[1] = 0x67; |
| | | return messageBody; |
| | | } |
| | | } |
| | |
| | | Log.i(TAG,"转义过后:"+ ByteUtil.byte2hex(temp)); |
| | | return temp; |
| | | } |
| | | |
| | | /** |
| | | *接收消息时:转义还原 |
| | | * @param datas |
| | | * @return |
| | | */ |
| | | public static byte[] parseMsg(byte[] datas){ |
| | | byte[] temp = new byte[datas.length]; |
| | | int y =0 ; |
| | | for (int i = 0; i < datas.length; i++) { |
| | | if (datas[i]==0x7d && datas[i+1]==0x02 ){ |
| | | temp[y++] = 0x7e; |
| | | i++; |
| | | continue; |
| | | }else if (datas[i]==0x7d && datas[i+1]==0x01 ){ |
| | | |
| | | temp[y++] = 0x7d; |
| | | i++; |
| | | continue; |
| | | }else{ |
| | | temp[y++] = datas[i]; |
| | | } |
| | | } |
| | | return temp; |
| | | } |
| | | } |