DanielT / autosar-data

A rust crate to work with Autosar data (arxml) files
Apache License 2.0
32 stars 10 forks source link

Unable to set CharacterData for ElementName: Value #14

Closed b4skyx closed 12 months ago

b4skyx commented 12 months ago

Error when trying to set CharacterData for Autosar Tag VALUE. Error: IncorrectContentType

Desired Behavior: CharacterData should be set for VALUE as element VALUE is of type CharacterData

The autosar xsd template defines VALUE tag as following: image

To reproduce the Error the sample program can be used:

use autosar_data::*;
use std::error::Error;
fn test_value() -> Result<(), Box<dyn Error>> {
    let model = AutosarModel::new();
    model.create_file("test.arxml", AutosarVersion::Autosar_00044)?;
    let package_elements = model
        .root_element()
        .create_sub_element(ElementName::ArPackages)?
        .create_named_sub_element(ElementName::ArPackage, "TestPackage")?
        .create_sub_element(ElementName::Elements)?;
    let created_pdu = package_elements.create_named_sub_element(ElementName::ISignalIPdu, "TestPDU")?;
        let event_controlled_timing = created_pdu
            .create_sub_element(ElementName::IPduTimingSpecifications)?
            .create_sub_element(ElementName::IPduTiming)?
            .create_sub_element(ElementName::TransmissionModeDeclaration)?
            .create_sub_element(ElementName::TransmissionModeTrueTiming)?
            .create_sub_element(ElementName::EventControlledTiming)?;
        event_controlled_timing
            .create_sub_element(ElementName::NumberOfRepetitions)?
            .set_character_data(CharacterData::String("0".to_string()))?;
        let value = event_controlled_timing
            .create_sub_element(ElementName::RepetitionPeriod)?
            .create_sub_element(ElementName::Value)?;
        println!("{:?}", value.content_type());
        value.set_character_data(CharacterData::String("0".to_string()))?;
    model.write()?;
    Ok(())
}
fn main() {
    println!("Hello, world!");
    let _ = test_value().unwrap();
}

Sample Output:

Hello, world!
CharacterData
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: IncorrectContentType', src/main.rs:31:26
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Desired Output: test.arxml should be written with CharacterData of VALUE element set.

rust version: rustc 1.72.1 autosar-data = "0.11.0"

DanielT commented 12 months ago

Hi, It looks like the Autosar xsd you are looking at is not original. In the xsd files I have the definition looks different: VALUE has the type TIME-VALUE

         <xsd:element maxOccurs="1" minOccurs="0" name="VALUE" type="AR:TIME-VALUE">
            <xsd:annotation>
               <xsd:documentation>Average value of a date (in seconds)</xsd:documentation>
               <xsd:appinfo source="tags">mmt.qualifiedName="TimeRangeType.value";pureMM.maxOccurs="1";pureMM.minOccurs="1"</xsd:appinfo>
            </xsd:annotation>
         </xsd:element>

and a TIME-VALUE is ultimately an xsd:double.

You can download the latest official xsd file here: https://www.autosar.org/fileadmin/standards/R22-11/FO/AUTOSAR_MMOD_XMLSchema.zip

b4skyx commented 12 months ago

Oh yes you're right. The xsd file I referred to was generated by lemmix server. The original autosar template does defines it as double. Changing the CharacterData to Double solved the issue. Thanks for pointing me to the right direction 😄