예제 #1
0
        private void PerformUpdate()
        {
            EdiabasInit();
            Android.App.ProgressDialog progress = new Android.App.ProgressDialog(this);
            progress.SetCancelable(false);
            progress.SetMessage(GetString(Resource.String.can_adapter_fw_update_active));
            progress.Show();

            _adapterThread = new Thread(() =>
            {
                bool updateOk  = false;
                bool connectOk = false;
                try
                {
                    connectOk = !InterfacePrepare();
                    BluetoothSocket bluetoothSocket = EdBluetoothInterface.BluetoothSocket;
                    if (bluetoothSocket == null)
                    {
                        connectOk = false;
                    }
                    else
                    {
                        connectOk = true;
                        updateOk  = PicBootloader.FwUpdate(bluetoothSocket);
                    }
                }
                catch (Exception)
                {
                    updateOk = false;
                }
                RunOnUiThread(() =>
                {
                    if (IsJobRunning())
                    {
                        _adapterThread.Join();
                    }
                    progress.Hide();
                    progress.Dispose();
                    string message;
                    if (updateOk)
                    {
                        message = GetString(Resource.String.can_adapter_fw_update_ok);
                    }
                    else
                    {
                        message = connectOk
                            ? GetString(Resource.String.can_adapter_fw_update_failed)
                            : GetString(Resource.String.can_adapter_fw_update_conn_failed);
                    }
                    _activityCommon.ShowAlert(message, updateOk ? Resource.String.alert_title_info : Resource.String.alert_title_error);
                    UpdateDisplay();
                    if (updateOk)
                    {
                        PerformRead();
                    }
                });
            });
            _adapterThread.Start();
            UpdateDisplay();
        }
예제 #2
0
        private void PerformUpdate()
        {
            EdiabasInit();
            CustomProgressDialog progress = new CustomProgressDialog(this);

            progress.SetMessage(GetString(Resource.String.can_adapter_fw_update_active));
            progress.ButtonAbort.Visibility = ViewStates.Gone;
            progress.Show();

            _adapterThread = new Thread(() =>
            {
                bool updateOk  = false;
                bool connectOk = false;
                try
                {
                    connectOk        = InterfacePrepare();
                    Stream inStream  = null;
                    Stream outStream = null;
                    if (connectOk)
                    {
                        switch (_activityCommon.SelectedInterface)
                        {
                        case ActivityCommon.InterfaceType.Bluetooth:
                            {
                                BluetoothSocket bluetoothSocket = EdBluetoothInterface.BluetoothSocket;
                                if (bluetoothSocket == null)
                                {
                                    connectOk = false;
                                    break;
                                }
                                inStream  = bluetoothSocket.InputStream;
                                outStream = bluetoothSocket.OutputStream;
                                break;
                            }

                        case ActivityCommon.InterfaceType.DeepObdWifi:
                            {
                                NetworkStream networkStream = EdCustomWiFiInterface.NetworkStream;
                                if (networkStream == null)
                                {
                                    connectOk = false;
                                    break;
                                }
                                inStream  = networkStream;
                                outStream = networkStream;
                                break;
                            }
                        }
                    }
                    if (inStream == null || outStream == null)
                    {
                        connectOk = false;
                    }

                    if (connectOk)
                    {
                        updateOk = PicBootloader.FwUpdate(inStream, outStream);
                    }
                }
                catch (Exception)
                {
                    updateOk = false;
                }
                RunOnUiThread(() =>
                {
                    if (_activityCommon == null)
                    {
                        return;
                    }
                    if (IsJobRunning())
                    {
                        _adapterThread.Join();
                    }
                    progress.Dismiss();
                    progress.Dispose();
                    string message;
                    if (updateOk)
                    {
                        message = GetString(Resource.String.can_adapter_fw_update_ok);
                    }
                    else
                    {
                        message = connectOk
                            ? GetString(Resource.String.can_adapter_fw_update_failed)
                            : GetString(Resource.String.can_adapter_fw_update_conn_failed);
                    }
                    _activityCommon.ShowAlert(message, updateOk ? Resource.String.alert_title_info : Resource.String.alert_title_error);
                    UpdateDisplay();
                    if (updateOk)
                    {
                        PerformRead();
                    }
                });
            });
            _adapterThread.Start();
            UpdateDisplay();
        }