Expand description
Crate autosar-data
This crate provides functionality to read, modify and write Autosar arxml files, both separately and in projects consisting of multiple files.
Features:
- read and write arxml files
- fully validate all data when it is loaded
- non-strict mode so that invalid but structurally sound data can be loaded
- various element operations to modify and create sub-elements, data and attributes
- support for Autosar paths and cross references
- all operations are thread safe, e.g. it is possible to load mutliple files on separate threads
§Examples
use autosar_data::*;
/* load a multi-file data model */
let model = AutosarModel::new();
let (file_1, warnings_1) = model.load_file("some_file.arxml", false)?;
let (file_2, warnings_2) = model.load_file("other_file.arxml", false)?;
/* load a buffer */
let (file_3, _) = model.load_buffer(buffer, "filename.arxml", true)?;
/* write all files of the model */
model.write()?;
/* alternatively: */
for file in model.files() {
let file_data = file.serialize();
// do something with file_data
}
/* iterate over all elements in all files */
for (depth, element) in model.elements_dfs() {
if element.is_identifiable() {
/* the element is identifiable using an Autosar path */
println!("{depth}: {}, {}", element.element_name(), element.path()?);
} else {
println!("{depth}: {}", element.element_name());
}
}
/* get an element by its Autosar path */
let pdu_element = model.get_element_by_path("/Package/Mid/PduName").unwrap();
/* work with the content of elements */
if let Some(length) = pdu_element
.get_sub_element(ElementName::Length)
.and_then(|elem| elem.character_data())
.and_then(|cdata| cdata.string_value())
{
println!("Pdu Length: {length}");
}
/* modify the attributes of an element */
pdu_element.set_attribute_string(AttributeName::Uuid, "12ab34cd-1234-1234-1234-12ab34cd56ef");
pdu_element.remove_attribute(AttributeName::Uuid);
§Example Programs
Two complete example programs can be found in the examples directory of the source repostitory. They are:
- businfo, which extracts information about bus settings, frames, pdus and signals from an autosar ECU extract
generate_files
, which for each Autosar version generates an arxml file containing a least one instance of every specified element
Structs§
- Arxml
File - An Autosar arxml file
- Attribute
- A single attribute of an arxml element
- Autosar
Model AutosarModel
is the top level data type in the autosar-data crate.- Element
- An arxml element
- Valid
SubElement Info - information about a sub element
- Weak
Arxml File - Weak reference to an arxml file
- Weak
Element - Weak reference to an Element
Enums§
- Arxml
Lexer Error ArxmlLexerError
contains all errors that can occur while reading data- Arxml
Parser Error ArxmlParserError
contains all the errors that can occur while parsing a file- Attribute
Name - Enum of all attribute names in Autosar
- Autosar
Data Error - The error type
AutosarDataError
wraps all errors that can be generated anywhere in the crate - Autosar
Version - Enum of all Autosar versions
- Character
Data - The enum
CharacterData
provides typed access to the content of elements and attributes - Compatibility
Error - Possible kinds of compatibility errors that can be found by
ArxmlFile::check_version_compatibility()
- Content
Type - The content type of an Element
- Element
Content - One content item inside an arxml element
- Element
Name - Enum of all element names in Autosar
- Enum
Item - Enum of all possible enum values in Autosar
Functions§
- check_
buffer - Check a buffer to see if the content looks like arxml data
- check_
file - Check a file to see if it looks like an arxml file