lzw
2024-02-28 d4feb21868458d2db8275a7e8440922e5807ed0f
app/src/main/java/com/fwupgrade/saymanss/FwUpgradeService.java
@@ -61,6 +61,7 @@
    private static final int UPGRADE_FAIL = 3;
    private static final int UPGRADE_SUCCESS = 4;
    private CameraInfo mCamInfo = null;
    private static final String TAG = FwUpgradeService.class.getCanonicalName();
    private IFwAidlInterface.Stub mBinder = new IFwAidlInterface.Stub() {
@@ -83,6 +84,7 @@
        super.onCreate();
        Log.i(TAG,"onCreate");
        initTarget();
        initData();
        initDeviceSDK();
        UStorageTestModule.getInstance().initUStorageDeviceModuleWithVirtualDisk(AppPathInfo.getLogPath());
@@ -117,13 +119,17 @@
                case USB_DEVICE_DETACHED:
                    boolean isSuccessful1 = (boolean) msg.obj;
                    if (isSuccessful1) {
                        Toast.makeText(FwUpgradeService.this, "USB设备权限申请成功", Toast.LENGTH_SHORT).show();
                    } else {
                        Log.i(TAG,"发送失败结果广播给驾培");
                        sendToDriveTrainByBroadCast(0,1);
                        sendToNewDriveTrainByBroadCast(0,1);
                    int count = (int) msg.obj;
                    Log.i(TAG,"count="+count);
                    if (count<2) {
                        tty.clear();
                        initTarget();
                        int ret = UstorageDeviceInstance.getInstance().tryAgain(FwUpgradeService.this);
                        if (ret==1){
                            Log.i(TAG,"发送失败结果广播给驾培");
                            sendToDriveTrainByBroadCast(0,1);
                            sendToNewDriveTrainByBroadCast(0,1);
                        }
                    }
                    break;
@@ -150,7 +156,7 @@
                    int errCode = msg.arg1;
                    int succ_num = 0, fail_num = 0;
                    Log.d("fwup","Upgrade result:" + devName + ", errCode: " + errCode);
                    Log.d("fwup","Upgrade result:" + devName + ", errCode: " + errCode+".ttySize="+tty.size());
                    if (tty.containsKey(devName)) {
                        tty.put(devName, errCode == 0? UPGRADE_SUCCESS:UPGRADE_FAIL);
@@ -207,8 +213,10 @@
        for (UsbDevice usbDevice: targets) {
            if (usbDevice.getDeviceName().compareTo(min) < 0) {
                min = usbDevice.getDeviceName();
            }
        }
        Log.i(TAG,"min="+min);
        tty.put(min, UPGRADE_PRESET);
    }
@@ -244,16 +252,19 @@
     * UstorageDeviceSDK初始化.
     */
    private void initDeviceSDK() {
        int count = 0 ;
        int ret = UstorageDeviceInstance.getInstance().tryAttcheDeviceHandle(FwUpgradeService.this, FwUpgradeService.this);
        Log.i(TAG,"initDeviceSDk,ret="+ret);
        if (ret==1){
            ++count;
            Log.i(TAG,"再次的初始化");
            Message message = Message.obtain();
            message.obj = false;
            message.obj = count;
            message.what = USB_DEVICE_DETACHED;
            mHander.sendMessageDelayed(message,1000);
        }
    }
    @Override
@@ -298,7 +309,7 @@
        String serial = ctrlBlock.getSerial();
        Log.d(TAG,"sonixCamInit " + String.format("vendorId:%d productId:%d fileDescriptor:%d busNum:%d devNum:%d usbfsName:%s devName:%s serial:%s", vendorId, productId, fileDescriptor, busNum, devNum, usbfsName, devName, serial));
        Log.d(TAG,"sonixCamInit " + String.format("vendorId:%d productId:%d fileDescriptor:%d busNum:%d devNum:%d usbfsName:%s devName:%s serial:%s,tty.size=%d", vendorId, productId, fileDescriptor, busNum, devNum, usbfsName, devName, serial,tty.size()));
        if (tty.containsKey(devName) && tty.get(devName) == 0) {
@@ -306,16 +317,17 @@
            tty.put(devName, 1);
        }
        if (!isTarget) {
            Log.d(TAG,"Not sonixCam, close");
            ctrlBlock.close();
            sendToDriveTrainByBroadCast(0,1);
            sendToNewDriveTrainByBroadCast(0,1);
            return;
        }
        Log.d(TAG,"Is sonixCam, upgrade!");
        Message msg = Message.obtain();
        //msg.obj = errCode == 0;
        msg.obj = new CameraInfo(vendorId, productId, fileDescriptor, busNum, devNum, usbfsName, devName);