示例#1
0
 private void HandleCustomBroadcast(Context context, Intent intent)
 {
     try
     {
         EdiabasThread ediabasThread = ActivityCommon.EdiabasThread;
         // ReSharper disable once UseNullPropagation
         if (ediabasThread == null)
         {
             return;
         }
         JobReader.PageInfo pageInfo = ediabasThread.JobPageInfo;
         if (pageInfo.ClassObject == null)
         {
             return;
         }
         Type       pageType          = pageInfo.ClassObject.GetType();
         MethodInfo broadcastReceived = pageType.GetMethod("BroadcastReceived", new[] { typeof(JobReader.PageInfo), typeof(Context), typeof(Intent) });
         if (broadcastReceived == null)
         {
             return;
         }
         object[] args = { pageInfo, context, intent };
         broadcastReceived.Invoke(pageInfo.ClassObject, args);
     }
     catch (Exception)
     {
         // ignored
     }
 }
        public override void OnCreate()
        {
            base.OnCreate();
#if DEBUG
            Android.Util.Log.Info(Tag, "OnCreate: the service is initializing.");
#endif
            _stopHandler    = new Handler();
            _activityCommon = new ActivityCommon(this, null, BroadcastReceived);
            _activityCommon.SetLock(ActivityCommon.LockType.Cpu);
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                if (_activityCommon.NotificationManager != null)
                {
                    Android.App.NotificationChannel notificationChannel = new Android.App.NotificationChannel(
                        ServiceNotificationChannelId,
                        Resources.GetString(Resource.String.app_name), Android.App.NotificationImportance.Low);
                    _activityCommon.NotificationManager.CreateNotificationChannel(notificationChannel);
                }
            }
            lock (ActivityCommon.GlobalLockObject)
            {
                EdiabasThread ediabasThread = ActivityCommon.EdiabasThread;
                if (ediabasThread != null)
                {
                    ediabasThread.ActiveContext = this;
                }
            }
        }
示例#3
0
        public override void OnDestroy()
        {
            // We need to shut things down.
            //Log.Info(Tag, "OnDestroy: The started service is shutting down.");

            // Remove the notification from the status bar.
            NotificationManagerCompat notificationManager = NotificationManagerCompat.From(this);

            notificationManager.Cancel(ServiceRunningNotificationId);
            _activityCommon.SetLock(ActivityCommon.LockType.None);
            DisconnectEdiabasEvents();
            lock (ActivityCommon.GlobalLockObject)
            {
                EdiabasThread ediabasThread = ActivityCommon.EdiabasThread;
                if (ediabasThread != null)
                {
                    ediabasThread.ActiveContext = null;
                }
            }

            _activityCommon.Dispose();
            _activityCommon = null;
            _isStarted      = false;

            if (_stopHandler != null)
            {
                _stopHandler.Dispose();
                _stopHandler = null;
            }
            base.OnDestroy();
        }
示例#4
0
        private void HandleActionBroadcast(Intent intent)
        {
            string request = intent.GetStringExtra("action");

            if (string.IsNullOrEmpty(request))
            {
                return;
            }
            string[] requestList = request.Split(':');
            if (requestList.Length < 1)
            {
                return;
            }
            if (string.Compare(requestList[0], "new_page", StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (requestList.Length < 2)
                {
                    return;
                }
                JobReader.PageInfo pageInfoSel = null;
                foreach (JobReader.PageInfo pageInfo in ActivityCommon.JobReader.PageList)
                {
                    if (string.Compare(pageInfo.Name, requestList[1], StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        pageInfoSel = pageInfo;
                        break;
                    }
                }
                if (pageInfoSel == null)
                {
                    return;
                }
                if (!ActivityCommon.CommActive)
                {
                    return;
                }
                EdiabasThread ediabasThread = ActivityCommon.EdiabasThread;
                if (ediabasThread == null)
                {
                    return;
                }
                if (ediabasThread.JobPageInfo != pageInfoSel)
                {
                    ActivityCommon.EdiabasThread.CommActive = true;
                    ediabasThread.JobPageInfo = pageInfoSel;
                }
            }
        }
示例#5
0
        public override void OnCreate()
        {
            base.OnCreate();
#if DEBUG
            Android.Util.Log.Info(Tag, "OnCreate: the service is initializing.");
#endif
            _stopHandler    = new Handler();
            _activityCommon = new ActivityCommon(this, null, BroadcastReceived);
            _activityCommon.SetLock(ActivityCommon.LockType.Cpu);
            lock (ActivityCommon.GlobalLockObject)
            {
                EdiabasThread ediabasThread = ActivityCommon.EdiabasThread;
                if (ediabasThread != null)
                {
                    ediabasThread.ActiveContext = this;
                }
            }
        }
示例#6
0
        private void ExecuteActuatorFunction(bool continuous)
        {
            if (IsJobRunning())
            {
                return;
            }

            XmlToolEcuActivity.JobInfo selectedJob = GetSelectedJob();
            if (selectedJob == null)
            {
                return;
            }
            object lockObject = new object();
            string language   = ActivityCommon.GetCurrentLanguage();

            bool  activation         = selectedJob.EcuFixedFuncStruct.Activation.ConvertToInt() > 0;
            Int64 activationDuration = selectedJob.EcuFixedFuncStruct.ActivationDurationMs.ConvertToInt();

            EdiabasOpen();

            _instanceData.Continuous   = continuous;
            _instanceData.StopActuator = false;
            _instanceData.AutoClose    = false;

            UpdateActuatorStatus();

            bool executeFailed = false;

            _jobThread = new Thread(() =>
            {
                try
                {
                    ActivityCommon.ResolveSgbdFile(_ediabas, _ecuInfo.Sgbd);

                    EcuFunctionStructs.EcuJob.PhaseType phase = EcuFunctionStructs.EcuJob.PhaseType.Preset;
                    RunOnUiThread(() =>
                    {
                        if (_activityCommon == null)
                        {
                            return;
                        }

                        string preOpText = selectedJob.EcuFixedFuncStruct.PrepOp?.GetTitle(language);
                        if (!string.IsNullOrWhiteSpace(preOpText))
                        {
                            _textBmwActuatorStatus.Text = preOpText;
                        }

                        UpdateActuatorStatus(true);
                    });

                    // from: RheingoldSessionController.dll BMW.Rheingold.RheingoldSessionController.EcuFunctions.EcuFunctionComponentTrigger.DoTriggerComponent
                    bool hasResetJobs      = selectedJob.EcuFixedFuncStruct.EcuJobList.Any(ecuJob => ecuJob.GetPhaseType() == EcuFunctionStructs.EcuJob.PhaseType.Reset);
                    StringBuilder sbStatus = new StringBuilder();
                    bool statusUpdated     = false;
                    long startTime         = Stopwatch.GetTimestamp();
                    for (; ;)
                    {
                        bool stopActuator = _instanceData.StopActuator;

                        EcuFunctionStructs.EcuJob.PhaseType currentPhase = phase;
                        if (stopActuator && currentPhase == EcuFunctionStructs.EcuJob.PhaseType.Main)
                        {
                            break;
                        }

                        bool updateStatus = currentPhase == EcuFunctionStructs.EcuJob.PhaseType.Main;
                        if (updateStatus && !statusUpdated)
                        {
                            lock (lockObject)
                            {
                                sbStatus.Clear();
                                string procOpText = selectedJob.EcuFixedFuncStruct.ProcOp?.GetTitle(language);
                                if (!string.IsNullOrWhiteSpace(procOpText))
                                {
                                    AppendSbText(sbStatus, procOpText);
                                }
                            }

                            RunOnUiThread(() =>
                            {
                                if (_activityCommon == null)
                                {
                                    return;
                                }

                                lock (lockObject)
                                {
                                    _textBmwActuatorStatus.Text = sbStatus.ToString();
                                }
                                UpdateActuatorStatus(true);
                            });
                        }

                        List <EdiabasThread.EcuFunctionResult> resultList = EdiabasThread.ExecuteEcuJobs(_ediabas, selectedJob.EcuFixedFuncStruct, null, false, currentPhase);
                        if (resultList == null)
                        {
                            executeFailed = true;
                            break;
                        }

                        if (phase == EcuFunctionStructs.EcuJob.PhaseType.Preset)
                        {
                            phase = EcuFunctionStructs.EcuJob.PhaseType.Main;
                        }

                        if (updateStatus && !statusUpdated)
                        {
                            statusUpdated = true;
                            lock (lockObject)
                            {
                                foreach (EdiabasThread.EcuFunctionResult ecuFunctionResult in resultList)
                                {
                                    AppendSbText(sbStatus, ecuFunctionResult.ResultString);
                                }
                            }

                            RunOnUiThread(() =>
                            {
                                if (_activityCommon == null)
                                {
                                    return;
                                }

                                lock (lockObject)
                                {
                                    _textBmwActuatorStatus.Text = sbStatus.ToString();
                                }
                                UpdateActuatorStatus(true);
                            });
                        }

                        if (currentPhase == EcuFunctionStructs.EcuJob.PhaseType.Main)
                        {
                            if (!_instanceData.Continuous)
                            {
                                if (!hasResetJobs)
                                {
                                    break;
                                }

                                for (;;)
                                {
                                    if (_instanceData.StopActuator)
                                    {
                                        break;
                                    }

                                    if (activation)
                                    {
                                        if (Stopwatch.GetTimestamp() - startTime > activationDuration * ActivityCommon.TickResolMs)
                                        {
                                            break;
                                        }
                                    }

                                    Thread.Sleep(100);
                                }
                                break;
                            }
                        }
                    }

                    if (!executeFailed)
                    {
                        EcuFunctionStructs.EcuJob.PhaseType currentPhase = EcuFunctionStructs.EcuJob.PhaseType.Reset;
                        RunOnUiThread(() =>
                        {
                            if (_activityCommon == null)
                            {
                                return;
                            }

                            string postOpText = selectedJob.EcuFixedFuncStruct.PostOp?.GetTitle(language);
                            if (!string.IsNullOrWhiteSpace(postOpText))
                            {
                                _textBmwActuatorStatus.Text = postOpText;
                            }

                            UpdateActuatorStatus(true);
                        });

                        List <EdiabasThread.EcuFunctionResult> resultList = EdiabasThread.ExecuteEcuJobs(_ediabas, selectedJob.EcuFixedFuncStruct, null, false, currentPhase);
                        if (resultList == null)
                        {
                            executeFailed = true;
                        }
                    }
                }
                catch (Exception)
                {
                    executeFailed = true;
                }

                RunOnUiThread(() =>
                {
                    if (_activityCommon == null)
                    {
                        return;
                    }

                    if (executeFailed)
                    {
                        _activityCommon.ShowAlert(GetString(Resource.String.bmw_actuator_operation_failed), Resource.String.alert_title_error);
                    }
                    else
                    {
                        if (_instanceData.AutoClose)
                        {
                            Finish();
                            return;
                        }
                    }

                    if (IsJobRunning())
                    {
                        _jobThread.Join();
                    }

                    _instanceData.StopActuator = false;

                    UpdateActuatorStatus(true);
                });
            });
            _jobThread.Start();

            UpdateActuatorStatus(true);
        }