Click or drag to resize

How to use your own DiagCom implementations

Via the OTX-Runtime API it is possible to use a customer specific DiagCom implementation. Doing this, the user can implement the diagcom extension, with an own diagnostic runtime system, with an own behavior.

The following table lists all related OTX elements with its counterpart in the API:

OTX

API

GetComChannel

GetComChannelOccurred Event

CreateDiagServiceByName

CreateDiagServiceByNameOccurred Event

CreateDiagServiceBySemantic

CreateDiagServiceBySemanticOccurred Event

GetDiagServiceListBySemantic

GetDiagServiceListBySemanticOccurred Event

GetRepetitionTime

GetRepetitionTimeOccurred Event

GetRequest

GetRequestOccurred Event

GetPdu

GetPduOccurred Event

GetFirstResult

GetFirstResultOccurred Event

GetAllResultsOccurred

GetAllResultsOccurred Event

GetFirstResponse

GetFirstResponseOccurred Event

GetAllResponses

GetAllResponsesOccurred Event

GetParameterBySemanticOccurred

GetParameterBySemanticOccurred Event

GetFirstResponse

GetFirstResponseOccurred Event

GetParameterByPathOccurred

GetParameterByPathOccurred Event

GetParameterAsListOccurred

GetParameterAsListOccurred Event

GetParameterValueAsBoolean

GetParameterValueAsString

GetParameterValueAsInteger

GetParameterValueAsFloat

GetParameterValueAsByteField

GetParameterValueAsQuantity

GetParameterValueOccurred Event

GetComplexComParameter

GetComplexComParameterOccurred Event

GetComParameterValueAsBoolean

GetComParameterValueAsString

GetComParameterValueAsInteger

GetComParameterValueAsFloat

GetComParameterValueAsByteField

GetComParameterValueAsQuantity

GetComParameterValueOccurred Event

GetDefaultComplexComParameter

GetDefaultComplexComParameterOccurred Event

GetDefaultComParameterValueAsBoolean

GetDefaultComParameterValueAsString

GetDefaultComParameterValueAsInteger

GetDefaultComParameterValueAsFloat

GetDefaultComParameterValueAsByteField

GetDefaultComParameterValueAsQuantity

GetDefaultComParameterValueOccurred Event

IdentifyAndSelectVariant

IdentifyAndSelectVariantOccurred Event

CloseComChannel

CloseComChannelOccurred Event

SetComParameter

SetComParameterOccurred Event

SetComplexComParameter

SetComplexComParameterOccurred Event

ExecuteDiagService

ExecuteDiagServiceOccurred Event

ExecuteHexDiagService

ExecuteHexDiagServiceOccurred Event

StartRepeatedExecution

StartRepeatedExecutionOccurred Event

StopRepeatedExecution

StopRepeatedExecutionOccurred Event

SetRepetitionTime

SetRepetitionTimeOccurred Event

SetParameterValue

SetParameterValueOccurred Event

SetParameterValueBySemantic

SetParameterValueBySemanticOccurred Event

GetAllResultsAndClear

GetAllResultsAndClearOccurred Event

SetPdu

SetPduOccurred Event

Example
Simple example to use an own implementation for GetComChannel, CreateDiagServiceByName and ExecuteDiagService activities.
C#
using System;
using System.Collections.Generic;
using OpenTestSystem.Mvci.Dsa;
using OpenTestSystem.Otx.Runtime.Api;
using OpenTestSystem.Otx.Runtime.Api.Otx.Parameter;
using OpenTestSystem.Otx.Runtime.Api.Types;
using OpenTestSystem.Otx.Runtime.Api.Types.Exception;

namespace ClassLibrary1
{
    public class Class1
    {

        RuntimeManager runtimeManager = new RuntimeManager();

        public Init()
        {
            // Register events
            runtimeManager.GetComChannelOccurred += new OpenTestSystem.Otx.Runtime.Api.Event.GetComChannelHandler(RuntimeManager_GetComChannelOccurred);
            runtimeManager.CreateDiagServiceByNameOccurred += new OpenTestSystem.Otx.Runtime.Api.Event.CreateDiagServiceByNameHandler(runtimeManager_CreateDiagServiceByNameOccurred);
            runtimeManager.ExecuteDiagServiceOccurred += new OpenTestSystem.Otx.Runtime.Api.Event.ExecuteDiagServiceHandler(runtimeManager_ExecuteDiagServiceOccurred);
        }

        #region CallBacks

        void RuntimeManager_GetComChannelOccurred(string identifier, string ecuVariantName, bool performVariantSelection, out IComChannel comChannel, out OpenTestSystem.Otx.Runtime.Api.Types.Exception.Exception exception)
        {
            exception = null;
            try
            {
                // Opens the specified MCDLogicalLink
                OpenTestSystem.Mvci.Dsa.MCDLogicalLink mcdLogicalLink = InternalGetComChannel(identifier, ref ecuVariantName, performVariantSelection);

                // Create OTX-ComChannel
                comChannel = new ComChannel(identifier, ecuVariantName);
            }
            catch (OpenTestSystem.Otx.Runtime.Api.Types.Exception.Exception e)
            {
                // Exception mapping
                if (...)
                {
                    exception = new UnknownTargetException("Target unknown", e);
                }
                else if (...)
                {
                    exception = new LossOfComException("Communication lost");
                }
                else
                {
                    exception = e;
                }
            }
        }

        void runtimeManager_CreateDiagServiceByNameOccurred(IComChannel comChannel, string name, out IDiagService diagService, out OpenTestSystem.Otx.Runtime.Api.Types.Exception.Exception exception)
        {
            exception = null;
            try
            {
                if (!comChannelMap.ContainsKey(comChannel.Handle))
                {
                    throw new UnknownTargetException("Unknown ComChannel");
                }

                // Creates the specified McdDiagService
                OpenTestSystem.Mvci.Dsa.MCDDiagService mcdDiagService = InternalCreateDiagServiceByName(comChannelMap[comChannel.Handle], name);

                // Create OTX-DiagService
                diagService = new DiagService(comChannel, name);
            }
            catch (OpenTestSystem.Otx.Runtime.Api.Types.Exception.Exception e)
            {
                // Exception mapping
                if (...)
                {
                    exception = new UnknownTargetException("Target unknown", e);
                }
                else
                {
                    exception = e;
                }
            }
        }

        void runtimeManager_ExecuteDiagServiceOccurred(bool executeAsync, bool suppressPositiveResponse, IDiagService diagService, IParam[] requestParameters, ref IParam[] responseParameters, out IResult result, out ResultStates resultState, out OpenTestSystem.Otx.Runtime.Api.Types.Exception.Exception exception)
        {
            exception = null;
            try
            {
                if (!diagServiceMap.ContainsKey(diagService.Handle))
                {
                    throw new UnknownTargetException("Unknown DiagService");
                }

                // Executes the DiagService and maps the ResponseParameters
                OpenTestSystem.Mvci.Dsa.MCDResult mcdResult = InternalExecuteDiagService(executeAsync, suppressPositiveResponse, diagServiceMap[diagService.Handle], requestParameters, ref responseParameters);

                // Create OTX-Result
                result = new Result(diagService, GetOtxResultState(mcdResult.GetResultState()));
                resultState = result.ResultState;
            }
            catch (OpenTestSystem.Otx.Runtime.Api.Types.Exception.Exception e)
            {
                // Exception mapping
                if (...)
                {
                    exception = new UnknownTargetException("Target unknown", e);
                }
                else if (...)
                {
                    // ...
                }
                else
                {
                    exception = e;
                }
            }
        }

        #endregion

        #region Helpers

        private ResultStates GetOtxResultState(OpenTestSystem.Otf.Model.MVCIServer.Interfaces.IMCDResultState mcdResultState)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region MVCIServerAccess

        private MCDLogicalLink InternalGetComChannel(string identifier, ref string ecuVariantName, bool performVariantSelection)
        {
            throw new NotImplementedException();
        }

        private MCDDiagService InternalCreateDiagServiceByName(MCDLogicalLink mcdLogicalLink, string name)
        {
            throw new NotImplementedException();
        }

        private MCDResult InternalExecuteDiagService(bool executeAsync, bool suppressPositiveResponse, MCDDiagService mCDDiagService, Parameter[] requestParameters, ref Parameter[] responseParameters)
        {
            // RequestParameter mapping
            MCDRequestParameters mcdRequestParameters = GetMcdRequestParameters();
            foreach (Parameter parameter in requestParameters)
            {
                MCDRequestParameter mcdRequestParameter = mcdRequestParameters.GetItemByName(parameter.Name) as MCDRequestParameter;
                mcdRequestParameter.SetValueAsString(runtimeManager.ConvertValueToString(parameter.Value));
            }

            // ...
            // ExecuteDiagService
            // ...

            // ResponseParameter mapping
            MCDResponseParameters mcdResponseParameters = GetMCDResponseParameters();
            foreach (Parameter parameter in responseParameters)
            {
                MCDResponseParameter mcdResponseParameter = mcdResponseParameters.GetItemByName(parameter.Name) as MCDResponseParameter;
                parameter.Value = runtimeManager.ConvertStringToValue(mcdResponseParameter.GetValue().GetValueAsString(),mcdResponseParameter.GetValue().GetType().ToString());
            }

            return ...;
        }

        private MCDResponseParameters GetMCDResponseParameters()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}