The COMASSO initiative provides a community-sourced AUTOSAR 4.x basic software stack and tooling to work with that. One of the tools is the BSWDT, which uses the Eclipse projects Xpand and Xtend for model checking and code generation. It provides not only the BSW in readable form, but also the code generators and validators are there for you to inspect, learn from and modify. This blog article shows how to find your way around those files.
First of all, we need to create a simple Eclipse project (File->New Project…) and then make it a BSW configuration project by invoking the context menu on the project and setting the project configuration:
After that, we import the BSW and BSW code generators into the project:
- .chk: These contain model validations and checks
- .xpt: The actual code generators
- .ext: Model-to-Model transformations and utility functions
- .oaw: Workflow files (not discussed here)
- .bamf: Build action manifests.
All files except the .bamf come from the Eclipse Project xpand/mwe. The .bamf files are an implementation of the AUTOSAR build action manifest. In short, the bamf files invoke the oaw-files which in turn invoke .chk, x.pt and .ext. The details will not be discussed here.
However, we will have a look at the .chk files. A .chk files consists of a number of context statements. A context statement of a specific type will be invoked for all occurances of that type in your model. This is a very simple check for the ComMChannel. No need to loop through the model yourself, everything is done by the framework:
Code generation is done with Xpand. Xpand is a template based language that allows you to easily specifiy the generators. The big advantage is the flexible type system, that derives the available types from the param-defs in your workspace. So if you have vendor-specific param defs, all the types will be immediately available in the language as first-class types.
Note that everything highlighted blue in the example above will be printed 1:1 in the output and the statements between ‘<<‘ and ‘>>’ will be evaluated on the model. Note in line 124 that complex queries are possible. Of course, Xpand provides a comfortable set of additional statements for outputing code.
The files under “generateid” are used for automatically setting information prior to generation – e.g. by generating ids. An example from LIN could be:
The system comes with a profiling component that supports analysis of the time spent in checks and generation. Profiling will be introduced in another blog post.