Get Metadata About Service Interface - MATLAB & Simulink (original) (raw)
Main Content
This example shows how you can use the code descriptor programming interface to retrieve metadata about the code interfaces generated for a model. You can use this metadata to declare and define your target platform service functions.
Use the Embedded Coder Dictionary to create code interface definitions for services that your generated code uses. For more information, see Create a Service Interface Configuration.
In this example, you build code for a model, create a coder.codedescriptor.CodeDescriptor object, and then use the various methods in the code descriptor programming interface.
Open example model ComponentDeploymentFcn
. This model uses the shared Embedded Coder Dictionary ComponentDeploymentCoderDictionary.sldd
.
model = 'ComponentDeploymentFcn'; open_system(model);
To use the code descriptor programming interface, build the model and create a coder.codedescriptor.CodeDescriptor
object for the model.
evalc('slbuild(model)'); codeDescObj = coder.getCodeDescriptor(model);
Get Service Function Declaration
1. Retrieve the function prototype for a specified service function by using the getServiceFunctionPrototype method. You can locate the name of a service function in the code generation report. To open the report, in the Embedded Coder app, on C Code tab, click the Open Report button. In the report, select the Code Interface Report tab and view the service functions listed under Service Interface section.
serviceFunctionName = 'set_CD_integrator_DataTransfer'; serviceFunctionPrototype = getServiceFunctionPrototype(codeDescObj, ... serviceFunctionName)
serviceFunctionPrototype = Prototype with properties: Name: 'set_CD_integrator_DataTransfer' Return: [1×1 coder.descriptor.types.Argument] HeaderFile: '' SourceFile: '' Arguments: [1×0 coder.descriptor.types.Argument Sequence]
The code generator returns a coder.descriptor.types.Prototype
object.
2. Retrieve the function declaration of the specified service function by using the getServiceFunctionDeclaration method.
serviceFunctionDeclaration = getServiceFunctionDeclaration(codeDescObj, ... serviceFunctionPrototype)
serviceFunctionDeclaration = 'real_T * set_CD_integrator_DataTransfer(void)'
The code generator returns the function declaration as produced in the generated code. You can use this function declaration to generate your own service header files to ease component code integration with target platform services.
Get Service Interface Information
Retrieve the service interface object, also referred as a code configuration object, by using the getServices method.
serviceObj = codeDescObj.getServices();
The code generator returns a coder.descriptor.ServiceInterface object. Use this object to retrieve metadata about the service interface configuration that you define in the shared Embedded Coder Dictionary.
You can retrieve information of these types of service interface by specifying the corresponding enumerated values as input:
- Sender and Receiver —
coder.descriptor.Services.SenderReceiver
- Data Transfer —
coder.descriptor.Services.DataTransfer
- Timer —
coder.descriptor.Services.Timer
- Measurement —
coder.descriptor.Services.Measurement
- ParameterTuning —
coder.descriptor.Services.ParameterTuning
For example, to retrieve information about the data transfer service interface by using the getServiceInterface method, use these commands:
serviceInterfaceType = coder.descriptor.Services.DataTransfer; serviceInterfaceTypeObj = getServiceInterface(serviceObj, serviceInterfaceType)
serviceInterfaceTypeObj = DataTransferServiceInterface with properties: DataTransferElements: [1×1 coder.descriptor.DataTransferElement Sequence]
The code generator returns a coder.descriptor.DataTransferServiceInterface object. Use this object to further retrieve metadata about coder.descriptor.DataTransferElement and coder.descriptor.DataTransferFunction objects.
Similarly, you can get information for the coder.descriptor.SenderReceiverServiceInterface and coder.descriptor.TimerServiceInterface objects.
To get information about the parameter argument tuning service interface, pass coder.descriptor.Services.ParameterTuning
to getServiceInterface
, and then pass the output object to getParameterArgumentInterfaces.
Get Service Function Information
Use the various methods of the coder.descriptor.ServiceInterface
class to retrieve information about service functions.
- To retrieve the name of the header file that contains the service interface prototypes, use the getServicesHeaderFileName
serviceHeaderFile = getServicesHeaderFileName(serviceObj)
serviceHeaderFile = 'services.h'
- To retrieve a list of entry-point functions that call a specified service function, use the getCallableFunctionsThatCallServiceFunction
serviceFunctionName = 'set_CD_integrator_DataTransfer'; entryPointFunctions = getCallableFunctionsThatCallServiceFunction(serviceObj, serviceFunctionName)
entryPointFunctions = 1×1 cell array {'CD_integrator'}
- To retrieve a list of service functions that call a specified entry-point function, use the getCalledServiceFunctions method. The code generator returns the
coder.descriptor.ServiceFunctions
object that contains a representation of the number of service functions of each type present in the generated code.
entryPointFunctionName = 'CD_integrator'; serviceFunctions = getCalledServiceFunctions(serviceObj, entryPointFunctionName)
serviceFunctions = ServiceFunctions with properties: ReceiverFunctions: [1×1 StdString Set] SenderFunctions: [1×0 StdString Set] DataTransferFunctions: [1×1 StdString Set] TimerFunctions: [1×1 StdString Set]
- To retrieve information about the data communication method, as specified in the Embedded Coder Dictionary, for a specified service function, use the getServiceDataCommMethod method. The code generator returns an enumerated value of type
DataCommunicationMethodEnum
.
serviceFunctionName = 'get_CD_accumulator_DataTransfer'; dataCommMethod = getServiceDataCommMethod(serviceObj, serviceFunctionName)
dataCommMethod = DataCommunicationMethodEnum enumeration
OutsideExecution