Enumeration Code Generation with Embedded Coder (autosar.tlc)

Hello,
does anyone have a clue what causes the following error message and how I can overcome this problem? I have a Simulink model that uses the enumeration defined in "State_Car.m"
classdef State_Car < Simulink.IntEnumType
enumeration
PARKEN_BN_NIO(1)
PARKEN_BN_IO(2)
STANDFKT_KUNDE_NICHT_IM_FZG(3)
WOHNEN(5)
PRUEFEN_ANALYSE_DIAGNOSE(7)
FAHRBEREITSCHAFT_HERSTELLEN(8)
FAHREN(10)
FAHRBEREITSCHAFT_BEENDEN(12)
SIGNAl_UNBEFUELLT(15)
end
end
The error message I get during build process is:
### Build procedure for model: 'swc_heat_2017b' aborted due to an error.
The header file of the enumerated type State_Car, should be set to Rte_Type.h. To fix this error, update the getHeaderFile method of the enumeration type to return Rte_Type.h

1 件のコメント

Y
Y 2025 年 6 月 12 日
Hello for the enumeration problem, I have a little sharing to help everyone
1-If enumeration is only used within SWC, there is no need to define the Rte_type. h header file; If the SWC external port also needs to be enumerated, it is necessary to add the Rte_type. h header file
2-Enumeration generates different forms define or typedef , as shown in the following example:
2.1-Generate enumeration exists in the form of define
classdef BulbStatus < uint8
enumeration
On(0)
Off(1)
end
end
2.2-Generate enumeration exists in the form of typedef
classdef BulbStatus < Simulink.IntEnumType
enumeration
On(0)
Off(1)
end
end

サインインしてコメントする。

 採用された回答

Lucas Lebert
Lucas Lebert 2018 年 7 月 5 日
編集済み: Lucas Lebert 2020 年 8 月 20 日

1 投票

Hi Yu Zhao!
As per the AUTOSAR standard, all data types must have a definition generated in Rte_type.h. This is the reason for the error and it is not possible to use a different header when doing AUTOSAR code generation.
For data types used solely inside of a SWC (not in the definition of a port) you only need to specify the header file as Rte_type.h only if you want the data type to be exported as an IncludedDataTypeSet.
Here's a small example for the implementation of the getHeaderFile method:
classdef State_Car < Simulink.IntEnumType
enumeration
On(1)
Off(2)
end
methods (Static = true)
function retVal = getHeaderFile()
retVal = 'Rte_Type.h';
end
end
end
Have a great day!
~Lucas

7 件のコメント

Yu Zhao
Yu Zhao 2018 年 7 月 9 日
編集済み: Yu Zhao 2018 年 7 月 9 日
Hi Lucas,
your model indeed compiles with autosar.tlc and enumeration. However after inserting a matlab function I get the error message:
Data 'u' (#961) has compiled structure or enumeration type 'State_Car', which specifies custom header file 'Rte_Type.h'. This custom header file must be directly or indirectly included in model's Configuration Parameters 'Simulation Target/Header file' field.
No '#include "<headerfile>"' is detected in 'Simulation Target/Header file' field.'
Do you know the root of this problem?
Thanks Yu
Lucas Lebert
Lucas Lebert 2018 年 7 月 16 日
Hi!
You need to activate the checkbox "Generate typedefs for imported bus and enumeration types" in the configuration parameters.
Thanks!
~Lucas
Yu Zhao
Yu Zhao 2018 年 7 月 16 日
Hi Lucas,
that eliminated the error. However instead of enumeration typedefs #define is generated:
#ifndef State_Car_PARKEN_BN_NIO
#define State_Car_PARKEN_BN_NIO (1)
#endif
#ifndef State_Car_PARKEN_BN_IO
#define State_Car_PARKEN_BN_IO (2)
#endif
#ifndef State_Car_STANDFKT_KUNDE_NICHT_IM_FZG
#define State_Car_STANDFKT_KUNDE_NICHT_IM_FZG (3)
#endif
#ifndef State_Car_WOHNEN
#define State_Car_WOHNEN (5)
#endif
...
I'm looking for typedef enum to minimize file size. Is it possible to force code in "Rte_Type.h" such as
typedef enum {
...
} state_car;
?
Cam Leeper
Cam Leeper 2019 年 5 月 31 日
Did you figure out how to switch from #define to typedef enum?
Gabriele Minini
Gabriele Minini 2020 年 9 月 23 日
i have the same problem, i would like to switch from #define to enum, anyone know how to do this?
Hailin Ren
Hailin Ren 2020 年 12 月 9 日
I will take this feedback to my colleagues to be considered as an enhancement.
Arian
Arian 2022 年 9 月 11 日
I have added this method to my enumeration type but the Simulink could not compile the model for simulation ( after Ctrl + D).

サインインしてコメントする。

その他の回答 (2 件)

Manuel Stumpf
Manuel Stumpf 2018 年 7 月 16 日

0 投票

It looks like I have a similar problem: Is it possible to use a RTE data type inside a referenced subsystem (e.g. in state flow)? I want to use the same data types inside of referenced subsystems and the external interface of my SWC. Right now I keep getting error messages like above.
Regards, Manuel

2 件のコメント

Lucas Lebert
Lucas Lebert 2018 年 7 月 16 日
Hi, Manuel!
I would need to have a closer look at this. Could you please submit a help request to support@mathworks.de so I or one of my colleagues can have a look at this?
Thanks! ~Lucas
Manuel Stumpf
Manuel Stumpf 2018 年 7 月 16 日
Thanks Lucas,
your answer to Yu's question gave me the hint that I needed. Code generation for Autosar is successful now! Thanks again, Manuel

サインインしてコメントする。

Zhenwei Sun
Zhenwei Sun 2018 年 9 月 11 日

0 投票

hi, i'm with same issues. i don't need the data def in "Rte_Types.h" due to this class is only for my SWC used. anyone have fix this problem?

1 件のコメント

Tarun Jhamnani
Tarun Jhamnani 2020 年 8 月 31 日
classdef (Enumeration) EnColor < uint8
enumeration
Red (0)
Green (1)
Blue (2)
end
methods (Static = true)
function retValue = getDefaultValue()
retValue = EnColor.Red;
end
end
end
Define enum as above, you can change the base data type as you like. Secondly, What Lucas recommended setting.
Generated code will be something like below :
typedef uint8_T EnColor;
#define Red ((EnColor)0)
#define Green ((EnColor)1)
#define Blue ((EnColor)2)

サインインしてコメントする。

製品

リリース

R2017b

質問済み:

2018 年 7 月 3 日

コメント済み:

Y
Y
2025 年 6 月 12 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by