MATLAB: How to change the generated reference to E_NOT_OK in an ARXML file

AUTOSAR Blocksetclientserverinterfacee_not_okgetautosarpropertiesnot_okpossibleerror

I have generated an ARXML file but the generated reference is always set to "NOT_OK", and I cannot change it to other AUTOSAR Standard Return Types such as "E_NOT_OK" or to user specific error references such as "E_CUSTOM_MESSAGE".
How can I change the content of the generated ARXML file so that it matches the AUTOSAR standard type definition?

Best Answer

An existing generated reference (such as "NOT_OK") can be changed to a different Type by using getAUTOSARProperties() and it's object functions. The following code replaces the "NOT_OK" to "E_NOT_OK":
>> arProps = autosar.api.getAUTOSARProperties(bdroot)
>> interfaces = arProps.find([],"Operation","PathType","FullyQualified")
>> oper = arProps.get(interfaces{1},"PossibleError","PathType","FullyQualified")
>> arProps.set(oper{1},"Name","E_NOT_OK")
However, this requires the model to have been used for code generation once, otherwise there is no configured error to change. An alternative method that adds the configuration from scratch, is by adding the available errors on the 'ClientServerInterface' first, then configure the corresponding error that an operation should reference. The following code adds type definitionsĀ "E_NOT_OK" and "E_CUSTOM_MESSAGE":
>> arProps = autosar.api.getAUTOSARProperties(bdroot)
>> interfaces = arProps.find([],"ClientServerInterface")
>> add(arProps,interfaces{1},'PossibleError','E_NOT_OK')
>> set(arProps,[interfaces{1} '/E_NOT_OK'],'errorCode',1)
>> add(arProps,interfaces{1},'PossibleError','E_CUSTOM_MESSAGE')
>> set(arProps,[interfaces{1} '/E_CUSTOM_MESSAGE'],'errorCode',2)
>> possibleErrors = arProps.get(interfaces{1},"PossibleError")
>> operations = arProps.find([],"Operation","PathType","FullyQualified")
>> set(arProps,operations{1}, "PossibleError", possibleErrors)
Background on Standard Return Type:
This type is provided by AUTOSAR standard which can be used as standard API return type shared between the RTE and BSW modules. This can be used by API functions of the RTE which could indicate states and errors. "E_NOT_OK" <->0x01 is used for general error.