lizhanwei
2020-02-13 1d5420e54b4d542e3af7dcc4f1878092e15813ad
接收消息转义还原
2个文件已修改
31 ■■■■■ 已修改文件
app/src/main/java/safeluck/drive/evaluation/bean/RegisterMessage.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/util/Utils.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/bean/RegisterMessage.java
@@ -9,7 +9,7 @@
 */
public class RegisterMessage extends DriveExamProtocol {
    private static final int BODY_LENGTH = 4;
    private static final int BODY_LENGTH = 2;
    /**
     * 构造函数
     *
@@ -28,8 +28,8 @@
    @Override
    protected byte[] createMessageBody() {
        byte[] messageBody = new byte[BODY_LENGTH];
        messageBody[0] = 0x7E;
        messageBody[1] = 0x66;
        messageBody[0] = 0x65;
        messageBody[1] = 0x67;
        return messageBody;
    }
}
app/src/main/java/safeluck/drive/evaluation/util/Utils.java
@@ -71,4 +71,29 @@
        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;
    }
}