From d9941fe4e30358f98c90a080dd0835fceb0213ee Mon Sep 17 00:00:00 2001
From: lizhanwei <Dana_Lee1016@126.com>
Date: 星期一, 10 二月 2020 19:34:25 +0800
Subject: [PATCH] 修改发送单片机文件内容 命令ID;修改读取单片机内容方法
---
app/src/main/java/safeluck/drive/evaluation/Constant.java | 2
app/src/main/java/safeluck/drive/evaluation/util/FileUtil.java | 32 +++++++++++++++
app/src/main/java/safeluck/drive/evaluation/fragment/BaseDatasFragment.java | 27 ++++++++++---
3 files changed, 53 insertions(+), 8 deletions(-)
diff --git a/app/src/main/java/safeluck/drive/evaluation/Constant.java b/app/src/main/java/safeluck/drive/evaluation/Constant.java
index 9edc49a..a311211 100644
--- a/app/src/main/java/safeluck/drive/evaluation/Constant.java
+++ b/app/src/main/java/safeluck/drive/evaluation/Constant.java
@@ -71,6 +71,6 @@
public static final int DEBUG_TXT = 0x0010;
public static final String BIND_RTCM_TOPIC = "BIND_RTCM_TOPIC";
public static final String BIND_DEBUG_TXT = "BIND_DEBUG_TXT";
- public static final int UPGRADE_MCU_CONTENT_FILE = 21;
+ public static final int UPGRADE_MCU_CONTENT_FILE = 0x8100;
public static String exam_enter_exitdata="exam_enter_exitdata";
}
diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/BaseDatasFragment.java b/app/src/main/java/safeluck/drive/evaluation/fragment/BaseDatasFragment.java
index 3e6fbfe..195dc0a 100644
--- a/app/src/main/java/safeluck/drive/evaluation/fragment/BaseDatasFragment.java
+++ b/app/src/main/java/safeluck/drive/evaluation/fragment/BaseDatasFragment.java
@@ -3,6 +3,8 @@
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -11,6 +13,11 @@
import com.anyun.exam.lib.AYSdk;
import com.anyun.exam.lib.MyLog;
+import com.anyun.exam.lib.util.ByteUtil;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import me.yokeyword.fragmentation.SupportFragment;
import safeluck.drive.evaluation.Constant;
@@ -65,14 +72,22 @@
((BaseSettingFragment)getParentFragment()).startBrotherFragment(SignalConfigFragment.newInstance());
break;
case R.id.btn_mcu_upgrade:
- StringBuffer stringBuffer = FileUtil.readMCUtFileFromSD(getContext(),"dfu.bin");
- if (stringBuffer != null){
- AYSdk.getInstance().sendCmd(Constant.UPGRADE_MCU_CONTENT_FILE, stringBuffer.toString());
- }else{
- MyLog.i(TAG,"mcu鍗囩骇鏂囦欢涓嶅瓨鍦�");
+
+
+ try {
+ byte[] datas =FileUtil.readLocalFile(getActivity(),"dfu.bin");
+ if (datas != null){
+
+ String strs = new String(datas, Charset.forName("ISO-8859-1"));
+ Log.i(TAG, "onClick: datas.legnth=="+strs.getBytes("ISO-8859-1").length);
+ AYSdk.getInstance().sendCmd(Constant.UPGRADE_MCU_CONTENT_FILE, strs);
+ }else{
+ MyLog.i(TAG,"mcu鍗囩骇鏂囦欢涓嶅瓨鍦�");
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
}
-
break;
default:
break;
diff --git a/app/src/main/java/safeluck/drive/evaluation/util/FileUtil.java b/app/src/main/java/safeluck/drive/evaluation/util/FileUtil.java
index 72036c1..7704465 100644
--- a/app/src/main/java/safeluck/drive/evaluation/util/FileUtil.java
+++ b/app/src/main/java/safeluck/drive/evaluation/util/FileUtil.java
@@ -8,8 +8,10 @@
import android.util.Log;
import com.anyun.exam.lib.MyLog;
+import com.anyun.exam.lib.util.ByteUtil;
import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -120,9 +122,10 @@
e.printStackTrace();
}
- InputStreamReader inputStreamReader = new InputStreamReader(inputStream,"ISO-8859-1");
+ InputStreamReader inputStreamReader = new InputStreamReader(inputStream,"GB2312");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
while((lineTxt = bufferedReader.readLine()) != null){
+// System.out.println( ByteUtil.byte2hex(lineTxt.getBytes("ISO-8859-1")));
stringBuffer.append(lineTxt);
@@ -182,4 +185,31 @@
}
}
+ public static byte[] readLocalFile(Context context,String fileName) throws IOException {
+ InputStream inputStream = null;
+ String dir = Environment.getExternalStorageDirectory().getAbsolutePath()+"/";
+ File file = new File(dir,fileName);
+ if (!file.exists()){
+ MyLog.d(TAG,dir+"鐩綍涓�"+fileName+"鏂囦欢涓嶅瓨鍦�");
+ return null;
+ }
+ try {
+ inputStream = new FileInputStream(file);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ byte[] data = toByteArray(inputStream);
+ inputStream.close();
+ return data;
+ }
+ private static byte[] toByteArray(InputStream in) throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024 * 4];
+ int n = 0;
+ while ((n = in.read(buffer)) != -1) {
+ out.write(buffer, 0, n);
+ }
+ return out.toByteArray();
+ }
+
}
--
Gitblit v1.8.0