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"; } 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; 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(); } }