| Crates.io | powerlink-rs-xdc |
| lib.rs | powerlink-rs-xdc |
| version | 0.1.0 |
| created_at | 2025-11-13 16:41:32.830945+00 |
| updated_at | 2025-11-19 10:55:53.367023+00 |
| description | A no_std-compatible parser for POWERLINK XDC (XML Device Configuration) files. |
| homepage | |
| repository | https://github.com/fabiomolinar/powerlink-rs |
| max_upload_size | |
| id | 1931485 |
| size | 22,365,529 |
powerlink-rs-xdc)A no_std compatible, high-performance parser and serializer for ETHERNET POWERLINK XML Device Configuration (XDC) files, written in pure Rust.
This crate is part of the powerlink-rs project. It is designed to parse, validate, provide an ergonomic, strongly-typed Rust API for accessing data from .xdc files, and serialize that data back to XML. It is based on the EPSG DS 311 specification.
no_std Compatible: Can be used in embedded and bare-metal environments (alloc required).quick-xml parser to minimize allocations and efficiently handle large files.unwrap() or expect() in library code.save_xdc_to_string to serialize a complete XdcFile struct back into a standard XDC XML string.to_core_od converter to directly build the ObjectDictionary required by the powerlink-rs core crate.DeviceIdentityDeviceManager (including LEDs and modular support)ApplicationProcess (including parameterList, dataTypeList, etc.)ObjectList (the Object Dictionary)NetworkManagement (including GeneralFeatures, MNFeatures, CNFeatures, Diagnostic)use powerlink_rs_xdc::{load_xdc_from_str, to_core_od};
use std::fs;
fn main() {
// 1. Load the XDD/XDC file content
let xml_content = fs::read_to_string("tests/data/MyDevice.xdd")
.expect("Failed to read file");
// 2. Parse into a strongly-typed XdcFile struct
// (Use load_xdd_defaults_from_str for XDDs to prioritize defaultValue)
let xdc_file = load_xdc_from_str(&xml_content)
.expect("Failed to parse XDC");
println!("Device: {}", xdc_file.identity.product_name);
println!("Vendor ID: {:#010x}", xdc_file.identity.vendor_id);
// 3. Access the Object Dictionary
if let Some(obj) = xdc_file.object_dictionary.objects.iter().find(|o| o.index == 0x1000) {
println!("Device Type: {:?}", obj.data);
}
// 4. Convert to the core crate's ObjectDictionary format (if needed)
let core_od = to_core_od(&xdc_file)
.expect("Failed to convert to core OD");
}
Important Design Decision:
While the POWERLINK protocol transmits data in Little Endian byte order, this crate treats all data within XDC/XDD files as human-readable strings.
types.rs (e.g., Object::data, Parameter::actual_value) are stored as String (e.g., "0x1234", "500").ObjectValue enum) occurs in the converter.rs module. The powerlink-rs core crate then handles the subsequent serialization to Little Endian bytes for network transmission.This approach simplifies round-trip serialization (ensuring save_xdc_to_string produces XML that matches the input style) and decouples XML formatting from protocol-specific byte ordering.
The crate is designed around a three-stage pipeline: Parse -> Resolve -> Expose, with additional modules for serialization and conversion.
[file.xdc] -> parser.rs -> model/ -> resolver/ -> types.rs -> [Consumer]
[types.rs] -> converter.rs -> [powerlink-rs core]
[types.rs] -> builder/ -> [file.xdc]
src/parser.rs (Entry Point)
quick-xml's from_str deserializer. Its only job is to orchestrate the deserialization of the raw XML into the internal model structs.src/model/ (Internal serde Model)
#[serde(...)] attributes to guide quick-xml. Their goal is to capture the XML data as-is, including String representations of enums, hex values, etc.src/resolver/ (Business Logic)
model structs into the "smart" public types structs.uniqueIDRef lookups between ObjectList and ApplicationProcess), and passing value strings through.src/types.rs (Public API)
src/converter.rs (Core Integration)
types::ObjectDictionary into the powerlink_rs::od::ObjectDictionary used by the core powerlink-rs crate. This is where string-to-numeric parsing occurs.src/builder/ (Serialization)
save_xdc_to_string function for serializing a types::XdcFile struct back into XML.types structs back into the internal model structs for serialization by quick-xml.src/error.rs
XdcError enum.quick-xml) and data resolution errors (e.g., "Invalid AccessType string").src/lib.rs
src/types.rs and the main load_ and save_ functions.This table tracks the crate's implementation status against the main features of the EPSG DS 311 specification.
| Feature / Element | XSD Definition | Status | Notes |
|---|---|---|---|
| ProfileHeader | ProfileHeader_DataType |
π’ Implemented | All key fields modeled and resolved. |
| ProfileBody | ProfileBody_DataType |
π’ Implemented | |
| β‘οΈ DeviceIdentity | t_DeviceIdentity |
π’ Implemented | All fields from XSD are modeled and resolved. |
| β‘οΈ DeviceManager | t_DeviceManager |
π’ Implemented | indicatorList (LEDs) and modular moduleManagement are modeled and resolved. |
| β‘οΈ ApplicationProcess | t_ApplicationProcess |
π’ Implemented | All major sub-elements (parameterList, dataTypeList, parameterGroupList, functionTypeList, functionInstanceList) are modeled and resolved. |
| β‘οΈ ObjectList | ag_Powerlink_ObjectList |
π’ Implemented | Fully modeled and resolved, including uniqueIDRef resolution from ApplicationProcess. |
| β‘οΈ Object | ag_Powerlink_Object |
π’ Implemented | All key attributes modeled and resolved. |
| β‘οΈ SubObject | ag_Powerlink_Object |
π’ Implemented | All key attributes modeled and resolved. |
| β‘οΈ NetworkManagement | t_NetworkManagement |
π’ Implemented | All key sub-elements modeled and resolved. |
| β‘οΈ GeneralFeatures | t_GeneralFeatures |
π’ Implemented | Key features are modeled and resolved. |
| β‘οΈ MNFeatures | t_MNFeatures |
π’ Implemented | Key features are modeled and resolved. |
| β‘οΈ CNFeatures | t_CNFeatures |
π’ Implemented | Key features are modeled and resolved. |
| β‘οΈ Diagnostic | t_Diagnostic |
π’ Implemented | ErrorList and StaticErrorBitField are modeled and resolved. |
| Modular Support | *Modular_Head.xsd |
π’ Implemented | All modular profile bodies, moduleManagement, interfaceList, and rangeList elements are modeled and resolved. |
While the crate covers most of the EPSG DS 311 V1.2.1 specification and is sufficient for most standard device and communication profiles, certain optional or legacy elements are not yet implemented.
The parser is designed to be safe; it will ignore these unsupported elements rather than crashing.
serde models for ProfileHeader.serde models for Object and SubObject, including all attributes (name, accessType, PDOmapping, objFlags, etc.).serde models for DeviceIdentity.NetworkManagement, ApplicationProcess, and modular device extensions.serde models for NetworkManagement, GeneralFeatures, MNFeatures, CNFeatures, and Diagnostic.serde models for DeviceManager and all modular profile extensions (moduleManagement, interfaceList, rangeList).types for all new data.resolver.rs logic to map and validate all new data.accessType parsing, PDOmapping logic).Unsigned24, bit-packed structs).quick-xml serialization to write an XdcFile struct back to an XML string.validate() method to XdcFile that checks for common semantic configuration errors (e.g., invalid PDO mappings).builder.rs API for programmatically creating new XdcFile structs.save_xdc_to_string and to_core_od converter are implemented).