Main Content

Configure AUTOSAR Adaptive Service Discovery Modes

AUTOSAR adaptive service communication provides the option to configure applications to use one-time or dynamic discovery to subscribe to services. The default discovery mode, OneTime, allows an AUTOSAR application to find and subscribe to services at initialization. This mode of discovery may require that services are started before the application. You can change the service discovery mode to DynamicDiscovery to enable an AUTOSAR application to find and subscribe to services as they become available.

You can configure, in your model or programmatically, the service discovery mode of each required service port as OneTime or DynamicDiscovery:

  • From your model, you can use the AUTOSAR Dictionary to open the Service discovery attributes of required ports and select their service discovery modes.

    This example shows how to set a required port to DynamicDiscovery.

  • Programmatically, you can use the set function from the getAUTOSARProperties API to configure the service discovery mode.

    This example shows how to set a required port to DynamicDiscovery.

    hModel = 'autosar_LaneGuidance';
    apiObj = autosar.api.getAUTOSARProperties(hModel);
    set(apiObj,"/LaneGuidance_pkg/LaneGuidance_swc/LaneGuidance/RequiredPort/", ...
    "ServiceDiscoveryMode", "DynamicDiscovery")

The service discovery mode value impacts the generated C++ code (in the model source code file) in the following two locations:

  • The call site of the StartFindService API and registration of the callback (for both the InstanceIdentifier and InstanceSpecifier variants).

    // Model initialize function
    void autosar_LaneGuidanceModelClass::initialize()
      ProvidedPort = std::make_shared< company::chassis::provided::skeleton::
        ProvidedInterfaceSkeleton >(ara::com::InstanceIdentifier("2"), ara::com::
           this, std::placeholders::_1, std::placeholders::_2)), ara::com::
  • The definition of the callback function.

    void autosar_LaneGuidanceModelClass::RequiredPortSvcHandler(ara::com::
      ServiceHandleContainer< company::chassis::required::proxy::
      RequiredInterfaceProxy::HandleType > svcHandles, const ara::com::
      FindServiceHandle fsHandle)
      if ((!RequiredPort) && (svcHandles.size() > 0U)) {
        RequiredPort = std::make_shared< company::chassis::required::proxy::
          RequiredInterfaceProxy >(*svcHandles.begin());

Related Examples

More About