|
@@ -1,5 +1,6 @@
|
|
|
package com.example.administrator.wingcool_gt9_apk;
|
|
|
|
|
|
+import android.Manifest;
|
|
|
import android.app.Activity;
|
|
|
import android.app.PendingIntent;
|
|
|
import android.content.Context;
|
|
@@ -23,6 +24,7 @@ import android.os.Message;
|
|
|
import android.os.SystemClock;
|
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
+import android.support.v4.content.ContextCompat;
|
|
|
import android.support.v7.app.AlertDialog;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
import android.os.Bundle;
|
|
@@ -95,6 +97,9 @@ public class FirmwareUpdate extends AppCompatActivity
|
|
|
private TextView mShow;
|
|
|
private TextView tvUpDataResult;
|
|
|
private int iProductId;
|
|
|
+ private byte byProductType = 0;
|
|
|
+ private static final byte GT9 = 0x01;
|
|
|
+ private static final byte GT7 = 0x02;
|
|
|
|
|
|
int FW_HEAD_LENGTH = 14;
|
|
|
int FW_SECTION_LENGTH = 0x2000; /** 8K */
|
|
@@ -107,8 +112,8 @@ public class FirmwareUpdate extends AppCompatActivity
|
|
|
int FW_GWAKE_LENGTH = (4 * FW_SECTION_LENGTH) ; /** 32k */
|
|
|
|
|
|
int FW_HEAD_OFFSET = 0;
|
|
|
- int FW_SS51_OFFSET = (FW_HEAD_OFFSET + FW_HEAD_LENGTH);
|
|
|
- int FW_DSP_OFFSET = (FW_SS51_OFFSET + FW_SS51_LENGTH);
|
|
|
+ int FW_SS51_OFFSET = (FW_HEAD_OFFSET + FW_HEAD_LENGTH); //14
|
|
|
+ int FW_DSP_OFFSET = (FW_SS51_OFFSET + FW_SS51_LENGTH); //
|
|
|
int FW_BOOT_OFFSET = (FW_DSP_OFFSET + FW_DSP_LENGTH);
|
|
|
int FW_BOOT_ISP_OFFSET = (FW_BOOT_OFFSET + FW_BOOT_LENGTH);
|
|
|
int FW_GLINK_OFFSET = (FW_BOOT_ISP_OFFSET + FW_BOOT_ISP_LENGTH);
|
|
@@ -152,8 +157,8 @@ public class FirmwareUpdate extends AppCompatActivity
|
|
|
switch (msg.what) {
|
|
|
case CONNECTED_SUCCESS://车机和手机连接成功
|
|
|
btnReadVersion.setEnabled(true);
|
|
|
- btn_update.setEnabled(true);
|
|
|
- btn_AutoUpdate.setEnabled(true);
|
|
|
+ //btn_update.setEnabled(true);
|
|
|
+ //btn_AutoUpdate.setEnabled(true);
|
|
|
//loopReceiverMessage();
|
|
|
break;
|
|
|
|
|
@@ -459,6 +464,12 @@ public class FirmwareUpdate extends AppCompatActivity
|
|
|
mUsbDeviceConnection = mUsbManager.openDevice(usbDevice);
|
|
|
if(null != mUsbEndpointIn){
|
|
|
iProductId = usbDevice.getProductId();
|
|
|
+ if ((iProductId == 0x0819) || (iProductId == 0x8191))
|
|
|
+ {
|
|
|
+ byProductType = GT7;
|
|
|
+ }else{
|
|
|
+ byProductType = GT9;
|
|
|
+ }
|
|
|
mHandler.sendEmptyMessage(CONNECTED_SUCCESS);
|
|
|
}
|
|
|
}
|
|
@@ -484,7 +495,7 @@ public class FirmwareUpdate extends AppCompatActivity
|
|
|
mSendData = mSendGetGt9VersionData;
|
|
|
isSendMessage = false;
|
|
|
|
|
|
- if ((iProductId == 0x0819) || (iProductId == 0x8191))
|
|
|
+ if (byProductType == GT7) //GT7
|
|
|
{
|
|
|
addressH = (byte)0x82;
|
|
|
addressL = (byte)0x40;
|
|
@@ -506,7 +517,7 @@ public class FirmwareUpdate extends AppCompatActivity
|
|
|
mShow.setText( "Null" );//输出显示
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
+ else //GT9
|
|
|
{
|
|
|
addressH = (byte)0x81;
|
|
|
addressL = (byte)0x40;
|
|
@@ -539,7 +550,7 @@ public class FirmwareUpdate extends AppCompatActivity
|
|
|
|
|
|
break;
|
|
|
|
|
|
- case R.id.btnAutoUpdate:
|
|
|
+ case R.id.btnAutoUpdate: //自动下载固件和配置
|
|
|
bottonMode = 3;
|
|
|
isReceiverMessage = false; //升级关闭循环接收信息
|
|
|
//mSendData = mSendGetGt9VersionData;
|
|
@@ -553,8 +564,9 @@ public class FirmwareUpdate extends AppCompatActivity
|
|
|
//mSendData = mSendGetGt9VersionData;
|
|
|
isSendMessage = false;
|
|
|
//mHandler.sendEmptyMessage(UPDATE_FW);
|
|
|
- updateProcHandle();
|
|
|
-
|
|
|
+ if (byProductType == GT9) {
|
|
|
+ updateProcHandle();
|
|
|
+ }
|
|
|
break;
|
|
|
|
|
|
default:
|
|
@@ -627,8 +639,53 @@ public class FirmwareUpdate extends AppCompatActivity
|
|
|
protected void onActivityResult ( int requestCode, int resultCode, Intent data){
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
if (requestCode == 1) {
|
|
|
- Uri uri = data.getData();
|
|
|
- edit_search.setText(uri.getPath().toString());
|
|
|
+
|
|
|
+ int permission_write = ContextCompat.checkSelfPermission(FirmwareUpdate.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
|
+ int permission_read = ContextCompat.checkSelfPermission(FirmwareUpdate.this, Manifest.permission.READ_EXTERNAL_STORAGE);
|
|
|
+
|
|
|
+ if ((permission_write != PackageManager.PERMISSION_GRANTED)
|
|
|
+ ||(permission_read != PackageManager.PERMISSION_GRANTED))
|
|
|
+ {
|
|
|
+
|
|
|
+ ActivityCompat.requestPermissions(FirmwareUpdate.this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
|
+ android.Manifest.permission.READ_EXTERNAL_STORAGE}, 3);
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ try {
|
|
|
+
|
|
|
+ File dir = Environment.getExternalStorageDirectory();
|
|
|
+ //Uri uri = data.getData();
|
|
|
+ File dataFile;
|
|
|
+ if (byProductType == GT9) { //GT9
|
|
|
+ edit_search.setText(dir.getPath() + "/GT9110H.bin");
|
|
|
+
|
|
|
+ dataFile = new File(dir.getPath(), "GT9110H.bin");
|
|
|
+ }else if (byProductType == GT7){ //GT7
|
|
|
+ edit_search.setText(dir.getPath() + "/GT738x.bin");
|
|
|
+
|
|
|
+ dataFile = new File(dir.getPath(), "GT738x.bin");
|
|
|
+ }else{ //other
|
|
|
+ edit_search.setText(dir.getPath() + "/GTxxxx.bin");
|
|
|
+
|
|
|
+ dataFile = new File(dir.getPath(), "GTxxxx.bin");
|
|
|
+ }
|
|
|
+
|
|
|
+ FileInputStream fis = new FileInputStream(dataFile);
|
|
|
+
|
|
|
+ InputStreamReader isr = new InputStreamReader(fis,"UTF-8");//文件编码Unicode,UTF-8,ASCII,GB2312,Big5
|
|
|
+ Reader in = new BufferedReader(isr);
|
|
|
+ int ch;
|
|
|
+ while ((ch = in.read()) > -1) {
|
|
|
+ buffer.append((char)ch);
|
|
|
+ }
|
|
|
+ in.close();
|
|
|
+
|
|
|
+ btn_update.setEnabled(true);
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ edit_search.setText(getResources().getString(R.string.invalidfile));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -999,17 +1056,12 @@ public class FirmwareUpdate extends AppCompatActivity
|
|
|
}
|
|
|
}
|
|
|
} catch (ArithmeticException e) {
|
|
|
- // mShow.setText("ArithmeticException!");
|
|
|
Update_log2 = Update_log2.concat("ArithmeticException");
|
|
|
Update_log2 = Update_log2.concat("\n");
|
|
|
- // mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
|
|
|
e.printStackTrace();
|
|
|
} catch (ArrayIndexOutOfBoundsException e) {
|
|
|
- // mShow.setText("ArrayIndexOutOfBoundsException!");
|
|
|
-
|
|
|
- Update_log2 = Update_log2.concat("ArrayIndexOutOfBoundsException");
|
|
|
+ Update_log2 = Update_log2.concat("Recall check success");
|
|
|
Update_log2 = Update_log2.concat("\n");
|
|
|
- // mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
@@ -1171,46 +1223,29 @@ public class FirmwareUpdate extends AppCompatActivity
|
|
|
config.close();
|
|
|
fis.close();
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
- /**
|
|
|
- for (int i = 0; i < 64; i++) {
|
|
|
-
|
|
|
- int k = mGt9FirmwareData[i+FW_DSP_ISP_OFFSET+FW_DSP_ISP_LENGTH-2] & 0xFF;
|
|
|
- if(i>1)
|
|
|
- {
|
|
|
- k= mConfigData[i-2]&0xFF;
|
|
|
- }
|
|
|
- String hv = Integer.toHexString(k);
|
|
|
- stringBuilder.append(hv);
|
|
|
- stringBuilder.append(",");
|
|
|
}
|
|
|
- mShow.setText(stringBuilder.toString());*/
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
} catch (FileNotFoundException e) {
|
|
|
e.printStackTrace();
|
|
|
- // mMessage.setText("文件没被发现");
|
|
|
- Update_log = "文件没被发现";
|
|
|
+ Update_log = getResources().getString(R.string.invalidfile);
|
|
|
mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
- // mMessage.setText("IOException");
|
|
|
Update_log = "IOException";
|
|
|
mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else{
|
|
|
- // mMessage.setText("SD卡不可读写!");
|
|
|
- Update_log = "SD卡不可读写!";
|
|
|
+ Update_log = getResources().getString(R.string.nopermission);
|
|
|
mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
- //return false;
|
|
|
- //int mOffset = mGt9FirmwareData.length - mDspIsplength;
|
|
|
|
|
|
if (mGt9FirmwareData[1] == 0x01 && mGt9FirmwareData[2] == 0x60) {
|
|
|
if (!iicWrite(maddressHigh, maddressLow, mGt9FirmwareData, FW_DSP_ISP_OFFSET, FW_DSP_ISP_LENGTH)) {
|