Merge branch 'master' of https://gitee.com/endian11/DriveJudge
| | |
| | | |
| | | import android.util.Log; |
| | | |
| | | import com.anyun.exam.lib.MyLog; |
| | | import com.anyun.im_lib.util.ByteUtil; |
| | | |
| | | import safeluck.drive.evaluation.util.Utils; |
| | | |
| | | /** |
| | | * MyApplication2 |
| | |
| | | * @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; |
| | | |
| | | |
| | |
| | | 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; |
| | |
| | | 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(); |
| | | |
| | | } |
| | |
| | | * 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]; |
| | | } |
| | | } |
| | |
| | | */ |
| | | public class KeepaliveMessage extends DriveExamProtocol { |
| | | |
| | | |
| | | private static final int BODY_LENGTH = 0; |
| | | // TODO: 2019/12/19 |
| | | |
| | | public KeepaliveMessage(short msg_id) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | protected short msgBodyLength() { |
| | | return BODY_LENGTH; |
| | | } |
| | | |
| | | @Override |
| | | protected byte[] createMessageBody() { |
| | | return new byte[0]; |
| | | return new byte[BODY_LENGTH]; |
| | | } |
| | | } |
| | |
| | | * All Rights Saved! Chongqing AnYun Tech co. LTD |
| | | */ |
| | | public class RegisterMessage extends DriveExamProtocol { |
| | | |
| | | private static final int BODY_LENGTH = 2; |
| | | /** |
| | | * 构造函数 |
| | | * |
| | |
| | | } |
| | | |
| | | @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; |
| | | } |
| | | } |
| | |
| | | * All Rights Saved! Chongqing AnYun Tech co. LTD |
| | | */ |
| | | public class StartExamMessage extends DriveExamProtocol { |
| | | |
| | | |
| | | |
| | | private static final int BODY_LENGTH = 0; |
| | | // TODO: 2019/12/19 |
| | | /** |
| | | * 构造函数 |
| | |
| | | } |
| | | |
| | | @Override |
| | | protected short msgBodyLength() { |
| | | return BODY_LENGTH; |
| | | } |
| | | |
| | | @Override |
| | | protected byte[] createMessageBody() { |
| | | return new byte[0]; |
| | | return new byte[BODY_LENGTH]; |
| | | } |
| | | } |
| | |
| | | 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; |
| | | |
| | |
| | | |
| | | // 提交画布 |
| | | 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) { |
| | |
| | | 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; |
| | |
| | | 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) { |
| | |
| | | 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 |
| | |
| | | * 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()); |
| | | } |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | package com.anyun.im_lib.util; |
| | | |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | | |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.CharBuffer; |
| | |
| | | */ |
| | | public class ByteUtil { |
| | | |
| | | |
| | | private static final String TAG = "ByteUtil"; |
| | | /** |
| | | * @功能: BCD码转为10进制串(阿拉伯数据) |
| | | * @参数: BCD码 |
| | |
| | | byte b = (byte) a; |
| | | bbt[p] = b; |
| | | } |
| | | Log.i(TAG, "str2Bcd: "+byte2HexStr(bbt)); |
| | | return bbt; |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |
| | | } |