private void UpdateActuatorInfo() { UpdateActuatorStatus(); string language = ActivityCommon.GetCurrentLanguage(); StringBuilder stringBuilderComments = new StringBuilder(); XmlToolEcuActivity.JobInfo selectedJob = GetSelectedJob(); List <EcuFunctionStructs.EcuJob> ecuJobList = selectedJob?.EcuFixedFuncStruct?.EcuJobList; if (ecuJobList != null) { string preOpText = selectedJob.EcuFixedFuncStruct.PrepOp?.GetTitle(language); if (!string.IsNullOrWhiteSpace(preOpText)) { int presetCount = ecuJobList.Count(x => x.GetPhaseType() == EcuFunctionStructs.EcuJob.PhaseType.Preset); if (presetCount > 0) { AppendSbText(stringBuilderComments, preOpText); } else { preOpText = string.Empty; } } string procOpText = selectedJob.EcuFixedFuncStruct.ProcOp?.GetTitle(language); if (!string.IsNullOrWhiteSpace(procOpText) && procOpText != preOpText) { int mainCount = ecuJobList.Count(x => x.GetPhaseType() == EcuFunctionStructs.EcuJob.PhaseType.Main); if (mainCount > 0) { AppendSbText(stringBuilderComments, procOpText); } else { procOpText = string.Empty; } } string postOpText = selectedJob.EcuFixedFuncStruct.PostOp?.GetTitle(language); if (!string.IsNullOrWhiteSpace(postOpText) && postOpText != preOpText && postOpText != procOpText) { int resetCount = ecuJobList.Count(x => x.GetPhaseType() == EcuFunctionStructs.EcuJob.PhaseType.Reset); if (resetCount > 0) { AppendSbText(stringBuilderComments, postOpText); } } } string actuatorFunctionComment = stringBuilderComments.ToString(); _layoutBmwActuatorComments.Visibility = !string.IsNullOrWhiteSpace(actuatorFunctionComment) ? ViewStates.Visible : ViewStates.Gone; _textBmwActuatorComments.Text = actuatorFunctionComment; }
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); }