Преглед изворни кода

加了对GT2931的识别,能读到配置,下发配置还存在问题

robbin пре 2 година
родитељ
комит
bdfab7f994
2 измењених фајлова са 178 додато и 175 уклоњено
  1. 1 1
      app/build.gradle
  2. 177 174
      app/src/main/java/com/example/administrator/wingcool_gt9_apk/Config.java

+ 1 - 1
app/build.gradle

@@ -14,7 +14,7 @@ android {
         variant ->
             variant.outputs.all{
                 //´Ë´¦Ö¸¶¨Éú³ÉµÄapkÎļþÃû
-                outputFileName = "WingCoolAPK_V3.0.0_20220311.apk"
+                outputFileName = "WingCoolAPK_V3.0.0_20220916_debug.apk"
             }
     }
     lintOptions {

+ 177 - 174
app/src/main/java/com/example/administrator/wingcool_gt9_apk/Config.java

@@ -87,6 +87,8 @@ public class Config extends AppCompatActivity
     private byte byProductType = 0;
     private static final byte GT9 = 0x01;
     private static final byte GT7 = 0x02;
+    private static final byte GT29336 = 0x03;
+    private static final byte GT2931 = 0x04;
     private Button mReadCfg;
     private Button mSendCfg;
     private byte[] mBytes = new byte[2048];
@@ -1985,12 +1987,21 @@ public class Config extends AppCompatActivity
                             mUsbDeviceConnection.claimInterface(mUsbInterface, true);
                             if(null != mUsbEndpointIn){
                                 iProductId = usbDevice.getProductId();
+                                /*
                                 if ((iProductId == 0x0819) || (iProductId == 0x8191) || (iProductId == 0x0528) )
                                 {
                                     byProductType = GT7;
                                 }
                                 else{
-                                    byProductType = GT9;
+                                    byProductType = GT29336;
+                                }
+                                */
+                                if (iProductId == 0x0829)
+                                {
+                                    byProductType = GT29336;
+                                }
+                                else{
+                                    byProductType = GT2931;
                                 }
                                 mHandler.sendEmptyMessage(CONNECTED_SUCCESS);
                             }
@@ -3209,6 +3220,7 @@ public class Config extends AppCompatActivity
         String value;
         byte addressH;
         byte addressL;
+        byte addrfirstbyte, addrsecondbyte, addrthirdbyte;
         int checksum;
         int checksum2;
         int ichecksumhead;
@@ -3550,9 +3562,21 @@ public class Config extends AppCompatActivity
                 mBufferData[iconfiglen + 64 - 2] = (byte)((lchecksum & 0x00ff0000) >> 16);
                 mBufferData[iconfiglen + 64 - 1] = (byte)((lchecksum & 0xff000000) >> 24);
 
-                iicWrite32Bits((byte)0x01, (byte)0x3B, (byte)0x74, mBufferData,0,iconfiglen + 64);
+                if (byProductType == GT29336) {
+                    addrfirstbyte = (byte)0x01;
+                    addrsecondbyte = (byte)0x3B;
+                    addrthirdbyte = (byte)0x74;
+                }
+                else
+                {
+                    addrfirstbyte = (byte)0x01;
+                    addrsecondbyte = (byte)0x21;
+                    addrthirdbyte = (byte)0x8C;
+                }
+
+                iicWrite32Bits(addrfirstbyte, addrsecondbyte, addrthirdbyte, mBufferData,0,iconfiglen + 64);
 
-                if (!recallCheck((byte)0x01, (byte)0x3B, (byte)0x74, mBufferData, 0, iconfiglen + 64)) {
+                if (!recallCheck(addrfirstbyte, addrsecondbyte, addrthirdbyte, mBufferData, 0, iconfiglen + 64)) {
                     stMessageLog = "Recall check config error!!";
                     stMessageLogShow = stMessageLogShow.concat(stMessageLog);
                 } else {
@@ -3581,6 +3605,12 @@ public class Config extends AppCompatActivity
                         stMessageLogShow = stMessageLogShow.concat(stMessageLog);
                         break;
                     }
+                    else if (mBytes[0] == (byte)0x01)
+                    {
+                        stMessageLog = "receive finish!!";
+                        stMessageLogShow = stMessageLogShow.concat(stMessageLog);
+                        break;
+                    }
 
                 }while(mBytes[0] != (byte)0x80);
 
@@ -3599,6 +3629,12 @@ public class Config extends AppCompatActivity
                 do {
                     SystemClock.sleep(30);
                     iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes, 1);
+                    if (mBytes[0] == (byte)0x01)
+                    {
+                        stMessageLog = "receive finish!!";
+                        stMessageLogShow = stMessageLogShow.concat(stMessageLog);
+                        break;
+                    }
                 }while(mBytes[0] != (byte)0x80);
 
                 //mShow.setText("Send cfg finish!!");
@@ -3606,33 +3642,33 @@ public class Config extends AppCompatActivity
                 stMessageLogShow = stMessageLogShow.concat(stMessageLog);
                 mShow.setText(stMessageLogShow);
 
-                    //将checksum填入配置中
-                    //if (checksum % 256 == 0)  //校验和正确
-                    {
-                        //mBufferData[184] = (byte) (256 - checksum % 256);
-                        // mShow.setText("Cfg Checksum  re-calculation!");
-                    }
+                //将checksum填入配置中
+                //if (checksum % 256 == 0)  //校验和正确
+                {
+                    //mBufferData[184] = (byte) (256 - checksum % 256);
+                    // mShow.setText("Cfg Checksum  re-calculation!");
+                }
 
-                    //更新配置标志位
-                    //mBufferData[185] = 0x01;
-
-                    //mSendData = mBufferData;
-                    //mHandler.sendEmptyMessage(DEBUG_MESSAGE_SUCCESS);
-
-                    //扩展命令  0x03,0x01,0x0f,-128,0x47,0x00,0x39,
-                    //addressH = (byte) 0x80;
-                    //addressL = (byte) 0x47;
-                    //iicWrite(addressH, addressL, mBufferData, 0, 186);
-                    //if (!recallCheck(addressH, addressL, mBufferData, 0, 185)) {
-                    //    mShow.setText("Recall check error,Send cfg failed");
-                        // return false;
-                    //} else {
-                    //    mShow.setText("Recall check success,Send cfg success");
-                    //}
+                //更新配置标志位
+                //mBufferData[185] = 0x01;
+
+                //mSendData = mBufferData;
+                //mHandler.sendEmptyMessage(DEBUG_MESSAGE_SUCCESS);
+
+                //扩展命令  0x03,0x01,0x0f,-128,0x47,0x00,0x39,
+                //addressH = (byte) 0x80;
+                //addressL = (byte) 0x47;
+                //iicWrite(addressH, addressL, mBufferData, 0, 186);
+                //if (!recallCheck(addressH, addressL, mBufferData, 0, 185)) {
+                //    mShow.setText("Recall check error,Send cfg failed");
+                    // return false;
+                //} else {
+                //    mShow.setText("Recall check success,Send cfg success");
+                //}
 
-                    //if (iChooseVPager == 8) {
-                    //    mCfg80FF.setText(Integer.toHexString(mBufferData[184] & 0xff));
-                    //}
+                //if (iChooseVPager == 8) {
+                //    mCfg80FF.setText(Integer.toHexString(mBufferData[184] & 0xff));
+                //}
 
                 break;
             case R.id.readcfg:  //read cfg
@@ -3642,170 +3678,137 @@ public class Config extends AppCompatActivity
                 checksum = 0;
                 checksum2 = 0;
 
-                if (byProductType == GT9)
-                {
-                    /*
-                    //read [0x10174] = 0x80 or 0x01,表示上条命令已执行完毕,或当前固件处于空闲状态
-                    do {
-                        SystemClock.sleep(1);
-                        iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes, 1);
-                    }while((mBytes[0] != 0x80) && (mBytes[0] != 0x01));
-                    */
-
-                    //send 0x00 0x00 0x04 0x07 0x0B 0x00 to [0x10174],通知GT29XX,要读cfg
-                    mBytes[0] = 0x00;
-                    mBytes[1] = 0x00;
-                    mBytes[2] = 0x04;
-                    mBytes[3] = 0x07;
-                    mBytes[4] = 0x0B;
-                    mBytes[5] = 0x00;
-                    iicWrite32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes,0,6);
-
-
-                    //read [0x10175] = 0x80,config is ready
-                    //do {
-                    //    SystemClock.sleep(30);
-                    //    iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x75, mBytes, 1);
-                    //}while(mBytes[0] != (byte)0x80);
-
-                    //read [0x10174] = 0x80,config is ready
-                    do {
-                        SystemClock.sleep(30);
-                        iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes, 1);
-                    }while(mBytes[0] != (byte)0x80);
-
-                    //SystemClock.sleep(2);
-
-                    //read buffer [0x13B74]
-                    iicRead32Bits((byte)0x01, (byte)0x3B, (byte)0x74, mBytes, 63);  //read config head
-
-                    int iConfigSize = 64 + (int)(mBytes[60] & 0xFF) * 256 + (mBytes[59] & 0xFF);   //the head lend is 64
-
-                    iicRead32Bits((byte)0x01, (byte)0x3B, (byte)0x74, mBytes, iConfigSize);  //read config
-
-                    for (int i = 0; i < iConfigSize; i++) {
-
-                        int k = mBytes[i] & 0xFF;
-                        checksum =checksum+ k;
-                        String hv = Integer.toHexString(k);
-                        if (hv.length() < 2){
-                            hv = "0" + hv;
-                        }
-                        mConfigShow[i] = hv;
-                        stringBuilder.append("0x" + hv);
-                        stringBuilder.append(",");
-                    }
 
-                    ReadCfgRam(mConfigShow);
+                /*
+                //read [0x10174] = 0x80 or 0x01,表示上条命令已执行完毕,或当前固件处于空闲状态
+                do {
+                    SystemClock.sleep(1);
+                    iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes, 1);
+                }while((mBytes[0] != 0x80) && (mBytes[0] != 0x01));
+                */
 
-                    edtConfigDataShow.setText(stringBuilder.toString());
+                //send 0x00 0x00 0x04 0x07 0x0B 0x00 to [0x10174],通知GT29XX,要读cfg
+                mBytes[0] = 0x00;
+                mBytes[1] = 0x00;
+                mBytes[2] = 0x04;
+                mBytes[3] = 0x07;
+                mBytes[4] = 0x0B;
+                mBytes[5] = 0x00;
+                iicWrite32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes,0,6);
 
-                    SystemClock.sleep(5);
 
-                    //send 0x00 0x00 0x04 0x08 0x0C 0x00 to [0x10174],通知GT29XX,通信结束
-                    mBytes[0] = 0x00;
-                    mBytes[1] = 0x00;
-                    mBytes[2] = 0x04;
-                    mBytes[3] = 0x08;
-                    mBytes[4] = 0x0C;
-                    mBytes[5] = 0x00;
-                    iicWrite32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes, 0, 6);
+                //read [0x10175] = 0x80,config is ready
+                //do {
+                //    SystemClock.sleep(30);
+                //    iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x75, mBytes, 1);
+                //}while(mBytes[0] != (byte)0x80);
 
-                    //read [0x10175] = 0x80,config is ready
-                    //do {
-                    //    SystemClock.sleep(30);
-                    //    iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x75, mBytes, 1);
-                    //}while(mBytes[0] != (byte)0x80);
+                //read [0x10174] = 0x80,config is ready
+                do {
+                    SystemClock.sleep(30);
+                    iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes, 1);
+                }while(mBytes[0] != (byte)0x80);
 
-                    //read [0x10175] = 0x80,read config is over
-                    do {
-                        SystemClock.sleep(30);
-                        iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes, 1);
-                    }while(mBytes[0] != (byte)0x80);
+                //SystemClock.sleep(2);
 
-                    //SystemClock.sleep(2);
+                if (byProductType == GT29336) {
+                    addrfirstbyte = (byte)0x01;
+                    addrsecondbyte = (byte)0x3B;
+                    addrthirdbyte = (byte)0x74;
+                }else {
+                    addrfirstbyte = (byte)0x01;
+                    addrsecondbyte = (byte)0x21;
+                    addrthirdbyte = (byte)0x8C;
+                }
 
-                    iicRead32Bits((byte)0x01, (byte)0x00, (byte)0x2B, mBytes, 4);  //read Sensor ID
-                    tvVenderID.setText("VenderID:"+Integer.toString(mBytes[0] & 0xFF));
+                //read buffer [0x13B74]/[0X1218C]
+                iicRead32Bits(addrfirstbyte, addrsecondbyte, addrthirdbyte, mBytes, 63);  //read config head
 
-                    /*
-                    addressH = (byte)0x80;
-                    addressL = (byte)0x47;
-                    iicRead(addressH,addressL,mBytes,186);
+                int iConfigSize = 64 + (int)(mBytes[60] & 0xFF) * 256 + (mBytes[59] & 0xFF);   //the head lend is 64
 
-                    for (int i = 0; i < 186; i++) {
+                iicRead32Bits(addrfirstbyte, addrsecondbyte, addrthirdbyte, mBytes, iConfigSize);  //read config
 
-                        int k = mBytes[i] & 0xFF;
-                        checksum =checksum+ k;
-                        String hv = Integer.toHexString(k);
-                        if (hv.length() < 2){
-                            hv = "0" + hv;
-                        }
-                        mConfigShow[i] = hv;
-                        stringBuilder.append(hv);
-                        stringBuilder.append(",");
-                    }
-                    if(checksum % 256 == 0)  //校验和正确
-                    {
-                        mShow.setText("Cfg Checksum is correct!");
-                    }
-                    else {
-                        mShow.setText("Cfg Checksum is error!");
+                for (int i = 0; i < iConfigSize; i++) {
+
+                    int k = mBytes[i] & 0xFF;
+                    checksum =checksum+ k;
+                    String hv = Integer.toHexString(k);
+                    if (hv.length() < 2){
+                        hv = "0" + hv;
                     }
+                    mConfigShow[i] = hv;
+                    stringBuilder.append("0x" + hv);
+                    stringBuilder.append(",");
+                }
 
-                    ReadCfgSample(mBytes);
-                    ReadCfgModuleSwitch(mBytes);
-                    ReadCfgNormalSetting(mBytes);
-                    ReadCfgChannelSetting(mBytes);
-                    ReadCfgPenSetting(mBytes);
-                    ReadCfgPlamRestrain(mBytes);
-                    ReadCfgKeySetting(mBytes);
-                    ReadCfgHoppingSetting(mBytes);
-
-                     */
-                }else{  //GT7
-                    addressH = (byte)0x80;
-                    addressL = (byte)0x50;
-                    iicRead(addressH,addressL,mBytes,444);
-
-                    for (int i = 0; i < 444; i++) {
-
-                        int k = mBytes[i] & 0xFF;
-                        if (i < 213)
-                        {
-                            checksum = checksum + k;
-                        }
-                        else {
-                            checksum2 = checksum2 + k;
-                        }
+                ReadCfgRam(mConfigShow);
 
-                        String hv = Integer.toHexString(k);
-                        if (hv.length() < 2){
-                            hv = "0" + hv;
-                        }
-                        mConfigShow[i] = hv;
-                        stringBuilder.append(hv);
-                        stringBuilder.append(",");
-                    }
-                    if((checksum % 256 == 0) && (checksum2 % 256 == 0))  //校验和正确
-                    {
-                        mShow.setText("Cfg Checksum is correct!");
-                    }
-                    else {
-                        mShow.setText("Cfg Checksum is error!");
+                edtConfigDataShow.setText(stringBuilder.toString());
+
+                SystemClock.sleep(5);
+
+                //send 0x00 0x00 0x04 0x08 0x0C 0x00 to [0x10174],通知GT29XX,通信结束
+                mBytes[0] = 0x00;
+                mBytes[1] = 0x00;
+                mBytes[2] = 0x04;
+                mBytes[3] = 0x08;
+                mBytes[4] = 0x0C;
+                mBytes[5] = 0x00;
+                iicWrite32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes, 0, 6);
+
+                //read [0x10175] = 0x80,config is ready
+                //do {
+                //    SystemClock.sleep(30);
+                //    iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x75, mBytes, 1);
+                //}while(mBytes[0] != (byte)0x80);
+
+                //read [0x10175] = 0x80,read config is over
+                do {
+                    SystemClock.sleep(30);
+                    iicRead32Bits((byte)0x01, (byte)0x01, (byte)0x74, mBytes, 1);
+                }while(mBytes[0] != (byte)0x80);
+
+                //SystemClock.sleep(2);
+
+                iicRead32Bits((byte)0x01, (byte)0x00, (byte)0x2B, mBytes, 4);  //read Sensor ID
+                tvVenderID.setText("VenderID:"+Integer.toString(mBytes[0] & 0xFF));
+
+                /*
+                addressH = (byte)0x80;
+                addressL = (byte)0x47;
+                iicRead(addressH,addressL,mBytes,186);
+
+                for (int i = 0; i < 186; i++) {
+
+                    int k = mBytes[i] & 0xFF;
+                    checksum =checksum+ k;
+                    String hv = Integer.toHexString(k);
+                    if (hv.length() < 2){
+                        hv = "0" + hv;
                     }
+                    mConfigShow[i] = hv;
+                    stringBuilder.append(hv);
+                    stringBuilder.append(",");
+                }
+                if(checksum % 256 == 0)  //校验和正确
+                {
+                    mShow.setText("Cfg Checksum is correct!");
+                }
+                else {
+                    mShow.setText("Cfg Checksum is error!");
                 }
 
-                //ReadCfgRam(mConfigShow);
+                ReadCfgSample(mBytes);
+                ReadCfgModuleSwitch(mBytes);
+                ReadCfgNormalSetting(mBytes);
+                ReadCfgChannelSetting(mBytes);
+                ReadCfgPenSetting(mBytes);
+                ReadCfgPlamRestrain(mBytes);
+                ReadCfgKeySetting(mBytes);
+                ReadCfgHoppingSetting(mBytes);
+
+                 */
 
-                //addressH = (byte)0x81;
-                //if (byProductType == GT7)
-                //{
-                //    addressH = (byte)0x82;
-                //}
-                //addressL = (byte)0x40;
-                //iicRead(addressH,addressL,mBytes,32);
-                //tvVenderID.setText("VenderID:"+Integer.toString(mBytes[10] & 0xFF));
 
                 break;
             case R.id.savecfg: