fctom1215
2020-02-14 806ed6836b84fbea87d19a0cb4414e120dd9c049
Merge branch 'master' of https://gitee.com/endian11/DriveJudge
9个文件已修改
171 ■■■■ 已修改文件
app/src/main/java/safeluck/drive/evaluation/bean/DriveExamProtocol.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/bean/GainStuMessage.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/bean/KeepaliveMessage.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/bean/RegisterMessage.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/bean/StartExamMessage.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/fragment/TakePhotoFragment.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/util/Utils.java 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
im_lib/src/main/java/com/anyun/im_lib/util/ByteUtil.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/bean/DriveExamProtocol.java
@@ -2,7 +2,10 @@
import android.util.Log;
import com.anyun.exam.lib.MyLog;
import com.anyun.im_lib.util.ByteUtil;
import safeluck.drive.evaluation.util.Utils;
/**
 * MyApplication2
@@ -76,7 +79,7 @@
     * @return
     */
    public byte[] toBytes(){
        byte[] desBytes = new byte[1+16+2+1+1];
        byte[] desBytes = new byte[1+16+msgBodyLength()+1+1];
        int pos = 0;
@@ -95,7 +98,8 @@
        System.arraycopy(msgIdBytes,0,desBytes,pos,msgIdBytes.length);
        pos+=msgIdBytes.length;
        //消息体属性
        //消息体属性 默认为消息体长度
        msg_property = msgBodyLength();
        byte[] msg_pro_bytes = ByteUtil.shortGetBytes(msg_property);
        System.arraycopy(msg_pro_bytes,0,desBytes,pos,msg_pro_bytes.length);
        pos+=msg_pro_bytes.length;
@@ -117,16 +121,19 @@
        pos+=messageBodyBytes.length;
        //校验码
        // TODO: 2019/12/18 校验码需要计算   还有转义需要处理
        checkCode =   Utils.calCheckCode(ByteUtil.subArray(desBytes,1,pos-1));
        desBytes[pos] = checkCode;
        pos++;
        //末尾结束标识位
        desBytes[pos] = MESSAGE_TAIL;
        Log.i(TAG, "包长度="+(pos+1));
        Log.i(TAG, "包内容: "+ByteUtil.byte2HexStr(desBytes));
        return desBytes;
        MyLog.i(TAG, "原始包长度="+(pos+1));
        MyLog.i(TAG, "原始包内容: "+ByteUtil.byte2HexStr(desBytes));
        byte[] tranferbytes = Utils.transferMeaning(desBytes);
        MyLog.i(TAG,"转义后的包内容:"+ByteUtil.byte2HexStr(tranferbytes));
        return tranferbytes;
    }
    protected abstract short msgBodyLength();
}
app/src/main/java/safeluck/drive/evaluation/bean/GainStuMessage.java
@@ -8,19 +8,21 @@
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class GainStuMessage extends DriveExamProtocol {
    // TODO: 2019/12/19
    /**
     * 构造函数
     *
     * @param msg_id 消息ID
     */
    private static final int BODY_LENGTH = 0;
    public GainStuMessage(short msg_id) {
        super(msg_id);
    }
    @Override
    protected short msgBodyLength() {
        return BODY_LENGTH;
    }
    @Override
    protected byte[] createMessageBody() {
        return new byte[0];
        return new byte[BODY_LENGTH];
    }
}
app/src/main/java/safeluck/drive/evaluation/bean/KeepaliveMessage.java
@@ -9,6 +9,8 @@
 */
public class KeepaliveMessage extends DriveExamProtocol {
    private static final int BODY_LENGTH = 0;
// TODO: 2019/12/19  
    public KeepaliveMessage(short msg_id) {
@@ -16,7 +18,12 @@
    }
    @Override
    protected short msgBodyLength() {
        return BODY_LENGTH;
    }
    @Override
    protected byte[] createMessageBody() {
        return new byte[0];
        return new byte[BODY_LENGTH];
    }
}
app/src/main/java/safeluck/drive/evaluation/bean/RegisterMessage.java
@@ -8,6 +8,8 @@
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class RegisterMessage extends DriveExamProtocol {
    private static final int BODY_LENGTH = 2;
    /**
     * 构造函数
     *
@@ -18,10 +20,16 @@
    }
    @Override
    protected short msgBodyLength() {
        return BODY_LENGTH;
    }
    @Override
    protected byte[] createMessageBody() {
        byte[] messageBody = new byte[2];
        byte[] messageBody = new byte[BODY_LENGTH];
        messageBody[0] = 0x65;
        messageBody[1] = 0x66;
        messageBody[1] = 0x67;
        return messageBody;
    }
}
app/src/main/java/safeluck/drive/evaluation/bean/StartExamMessage.java
@@ -8,6 +8,10 @@
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class StartExamMessage extends DriveExamProtocol {
    private static final int BODY_LENGTH = 0;
// TODO: 2019/12/19  
    /**
     * 构造函数
@@ -19,7 +23,12 @@
    }
    @Override
    protected short msgBodyLength() {
        return BODY_LENGTH;
    }
    @Override
    protected byte[] createMessageBody() {
        return new byte[0];
        return new byte[BODY_LENGTH];
    }
}
app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java
@@ -209,9 +209,9 @@
        if (canvas2 == null || bmp == null) {
            return;
        }
        _mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
//        _mActivity.runOnUiThread(new Runnable() {
//            @Override
//            public void run() {
                double base_x = 100, base_y = 100;
                double max_x = 0, min_x = 0, max_y = 0, min_y = 0;
@@ -331,10 +331,13 @@
                // 提交画布
                Canvas canvas = holder.lockCanvas();
                if (canvas != null){
                canvas.drawBitmap(bmp, 0, 0, paint);
                holder.unlockCanvasAndPost(canvas);
            }
        });
//            }
//        });
    }
    public void CCL(final int c, final int who) {
app/src/main/java/safeluck/drive/evaluation/fragment/TakePhotoFragment.java
@@ -35,6 +35,7 @@
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseIntArray;
import android.view.LayoutInflater;
@@ -619,7 +620,13 @@
            if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
                throw new RuntimeException("Time out waiting to lock camera opening.");
            }
            if(!TextUtils.isEmpty(mCameraId)){
            manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler);
            }else{
                MyLog.i(TAG,"CameraID--null");
            }
        } catch (CameraAccessException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
app/src/main/java/safeluck/drive/evaluation/util/Utils.java
@@ -1,7 +1,11 @@
package safeluck.drive.evaluation.util;
import android.content.res.Resources;
import android.util.Log;
import android.util.TypedValue;
import com.anyun.exam.lib.MyLog;
import com.anyun.exam.lib.util.ByteUtil;
/**
 * MyApplication2
@@ -10,6 +14,7 @@
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class Utils {
    private static final String TAG = "Utils";
    public static float px2dp(float value){
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,value, Resources.getSystem().getDisplayMetrics());
    }
@@ -22,4 +27,73 @@
    public static float dp2Px(int dpValue){
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX,dpValue,Resources.getSystem().getDisplayMetrics());
    }
    /**
     * 平台协议生成的校验码
     * @param bytes
     * @return
     */
    public static byte calCheckCode(byte[] bytes){
        byte checkCode =0;
        // 参与运算的两个值,如果两个相应bit位相同,则结果为0,否则为1。
        for (int i = 0; i < bytes.length; i++) {
            checkCode ^= bytes[i];
        }
        return checkCode;
    }
    /**
     * 转义
     * 采用Ox7e表示,若校验码、消息头以及消息体中出现0x7e,则要进行转义处理,转义规则定义如下:
     * 0x7e<——>0x7d后紧跟一个0x02;
     * 0x7d<——>0x7d后紧跟一个0x01。
     * @param datas
     * @return
     */
    public static byte[] transferMeaning(byte[] datas){
        byte [] temp = new byte[datas.length*2];
        int y = 0;
        temp[y++] = 0x7e;
        for (int i = 1; i < datas.length-1; i++) {
            if (datas[i] == 0x7E) {
                temp[y++] = 0x7D;
                temp[y++] = 0x02;
            } else if (datas[i] == 0x7D) {
                temp[y++] = 0x7D;
                temp[y++] = 0x01;
            } else {
                temp[y++] = datas[i];
            }
        }
        temp[y++] = 0x7e;
        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;
    }
}
im_lib/src/main/java/com/anyun/im_lib/util/ByteUtil.java
@@ -1,6 +1,7 @@
package com.anyun.im_lib.util;
import android.text.TextUtils;
import android.util.Log;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
@@ -15,7 +16,7 @@
 */
public class ByteUtil {
private static final String TAG = "ByteUtil";
    /**
     * @功能: BCD码转为10进制串(阿拉伯数据)
     * @参数: BCD码
@@ -69,6 +70,7 @@
            byte b = (byte) a;
            bbt[p] = b;
        }
        Log.i(TAG, "str2Bcd: "+byte2HexStr(bbt));
        return bbt;
    }
@@ -206,4 +208,10 @@
        System.out.println(byte2HexStr(shortGetBytes((short) b)));
    }
    public static byte[] subArray(byte[] srcBytes, int begin, int length) {
        byte[] bytes = new byte[length];
        System.arraycopy(srcBytes,begin,bytes,0,length);
        Log.i(TAG, "subArray: "+byte2HexStr(bytes));
        return bytes;
    }
}