From 806ed6836b84fbea87d19a0cb4414e120dd9c049 Mon Sep 17 00:00:00 2001
From: fctom1215 <fctom1215@outlook.com>
Date: 星期五, 14 二月 2020 14:30:44 +0800
Subject: [PATCH] Merge branch 'master' of https://gitee.com/endian11/DriveJudge
---
app/src/main/java/safeluck/drive/evaluation/util/Utils.java | 74 +++++++++++++++++++++++++++++++++++++
1 files changed, 74 insertions(+), 0 deletions(-)
diff --git a/app/src/main/java/safeluck/drive/evaluation/util/Utils.java b/app/src/main/java/safeluck/drive/evaluation/util/Utils.java
index cad654f..a0548a7 100644
--- a/app/src/main/java/safeluck/drive/evaluation/util/Utils.java
+++ b/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;
+ }
}
--
Gitblit v1.8.0