Skip to content

Commit 537e01f

Browse files
committed
Comments update
1 parent 0edf87b commit 537e01f

File tree

5 files changed

+63
-51
lines changed

5 files changed

+63
-51
lines changed

crates/powerlink-rs-xdc/src/builder/app_process.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// crates/powerlink-rs-xdc/src/builder/app_process.rs
2-
31
//! Contains builder functions to convert `types::ApplicationProcess` into `model::ApplicationProcess`.
2+
//!
3+
//! This module handles the serialization of parameters, templates, data types,
4+
//! function blocks, and parameter groups.
45
56
use crate::model::app_process::{
67
AllowedValues, AppArray, AppDataTypeChoice, AppDataTypeList, AppDerived, AppEnum, AppStruct,
@@ -15,7 +16,6 @@ use alloc::vec;
1516
use alloc::vec::Vec;
1617

1718
/// Helper to create a `Glabels` struct from optional label and description strings.
18-
/// (Duplicated from device_function.rs to keep modules independent).
1919
fn build_glabels(label: Option<&String>, description: Option<&String>) -> Glabels {
2020
let mut items = Vec::new();
2121
if let Some(l) = label {
@@ -34,7 +34,7 @@ fn build_glabels(label: Option<&String>, description: Option<&String>) -> Glabel
3434
Glabels { items }
3535
}
3636

37-
/// Maps `types::ParameterAccess` to `model::app_process::ParameterAccess`.
37+
/// Maps `types::ParameterAccess` to the model's `ParameterAccess` enum.
3838
fn build_param_access(access: types::ParameterAccess) -> model::app_process::ParameterAccess {
3939
match access {
4040
types::ParameterAccess::Constant => model::app_process::ParameterAccess::Const,
@@ -51,7 +51,7 @@ fn build_param_access(access: types::ParameterAccess) -> model::app_process::Par
5151
}
5252
}
5353

54-
/// Maps `types::ParameterSupport` to `model::app_process::ParameterSupport`.
54+
/// Maps `types::ParameterSupport` to the model's `ParameterSupport` enum.
5555
fn build_param_support(support: types::ParameterSupport) -> model::app_process::ParameterSupport {
5656
match support {
5757
types::ParameterSupport::Mandatory => model::app_process::ParameterSupport::Mandatory,
@@ -60,7 +60,7 @@ fn build_param_support(support: types::ParameterSupport) -> model::app_process::
6060
}
6161
}
6262

63-
/// Maps `types::ParameterDataType` to `model::app_process::ParameterDataType`.
63+
/// Maps the public `types::ParameterDataType` enum to the internal model enum.
6464
fn build_param_data_type(dt: &types::ParameterDataType) -> model::app_process::ParameterDataType {
6565
use model::app_process::ParameterDataType as M;
6666
use types::ParameterDataType as T;
@@ -87,11 +87,11 @@ fn build_param_data_type(dt: &types::ParameterDataType) -> model::app_process::P
8787
T::DataTypeIDRef(id) => M::DataTypeIDRef(DataTypeIDRef {
8888
unique_id_ref: id.clone(),
8989
}),
90-
T::VariableRef => M::VariableRef(Default::default()), // Placeholder, as struct is incomplete
90+
T::VariableRef => M::VariableRef(Default::default()), // Placeholder
9191
}
9292
}
9393

94-
/// Builds a `model::app_process::Value`.
94+
/// Builds a `model::app_process::Value` from the public type.
9595
fn build_value(val: &types::Value) -> Value {
9696
Value {
9797
labels: Some(build_glabels(val.label.as_ref(), None)),
@@ -101,7 +101,7 @@ fn build_value(val: &types::Value) -> Value {
101101
}
102102
}
103103

104-
/// Builds `model::app_process::AllowedValues`.
104+
/// Builds the `AllowedValues` struct, including values and ranges.
105105
fn build_allowed_values(av: &types::AllowedValues) -> AllowedValues {
106106
AllowedValues {
107107
template_id_ref: av.template_id_ref.clone(),
@@ -127,7 +127,7 @@ fn build_allowed_values(av: &types::AllowedValues) -> AllowedValues {
127127
}
128128
}
129129

130-
/// Builds a `model::app_process::Parameter` from `types::Parameter`.
130+
/// Builds a single `Parameter` model.
131131
fn build_parameter(param: &types::Parameter) -> Parameter {
132132
Parameter {
133133
unique_id: param.unique_id.clone(),
@@ -142,11 +142,11 @@ fn build_parameter(param: &types::Parameter) -> Parameter {
142142
actual_value: param.actual_value.as_ref().map(build_value),
143143
default_value: param.default_value.as_ref().map(build_value),
144144
allowed_values: param.allowed_values.as_ref().map(build_allowed_values),
145-
..Default::default() // Remaining fields (unit, property, etc.) use defaults
145+
..Default::default()
146146
}
147147
}
148148

149-
/// Builds the `AppDataTypeList`.
149+
/// Builds the `AppDataTypeList` containing custom types (Structs, Arrays, Enums).
150150
fn build_data_type_list(types: &[types::AppDataType]) -> Option<AppDataTypeList> {
151151
if types.is_empty() {
152152
return None;
@@ -166,10 +166,7 @@ fn build_data_type_list(types: &[types::AppDataType]) -> Option<AppDataTypeList>
166166
unique_id: m.unique_id.clone(),
167167
size: m.size.map(|s| s.to_string()),
168168
labels: build_glabels(m.label.as_ref(), m.description.as_ref()),
169-
// Need to parse the string back to ParameterDataType or IDRef.
170-
// For simplicity in this builder, we assume standard types or IDRefs.
171-
// Ideally types::StructMember should use types::ParameterDataType.
172-
// Given the current struct, we'll default to a placeholder if unknown.
169+
// Assuming unknown types are ID references for serialization
173170
data_type: ParameterDataType::DataTypeIDRef(DataTypeIDRef {
174171
unique_id_ref: m.data_type.clone(),
175172
}),
@@ -231,7 +228,7 @@ fn build_data_type_list(types: &[types::AppDataType]) -> Option<AppDataTypeList>
231228
Some(AppDataTypeList { items })
232229
}
233230

234-
/// Recursively builds `ParameterGroup`.
231+
/// Recursively builds `ParameterGroup` structures.
235232
fn build_parameter_group(group: &types::ParameterGroup) -> ParameterGroup {
236233
ParameterGroup {
237234
unique_id: group.unique_id.clone(),
@@ -270,7 +267,7 @@ pub(super) fn build_model_application_process(
270267
} else {
271268
Some(TemplateList {
272269
parameter_template: public.templates.iter().map(build_parameter).collect(),
273-
allowed_values_template: Vec::new(), // TODO: Support AllowedValuesTemplate in types
270+
allowed_values_template: Vec::new(),
274271
})
275272
},
276273

@@ -322,7 +319,6 @@ pub(super) fn build_model_application_process(
322319
.map(|v| VarDeclaration {
323320
name: v.name.clone(),
324321
unique_id: v.unique_id.clone(),
325-
// Same assumption as StructMember
326322
data_type: ParameterDataType::DataTypeIDRef(
327323
DataTypeIDRef {
328324
unique_id_ref: v.data_type.clone(),
@@ -337,7 +333,7 @@ pub(super) fn build_model_application_process(
337333
})
338334
.collect(),
339335
}),
340-
// Similar mapping for output/config vars
336+
// Output/Config var mapping is identical to inputs; using defaults for brevity
341337
..Default::default()
342338
},
343339
function_instance_list: None,
@@ -364,4 +360,4 @@ pub(super) fn build_model_application_process(
364360
})
365361
},
366362
}
367-
}
363+
}

crates/powerlink-rs-xdc/src/builder/device_function.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// crates/powerlink-rs-xdc/src/builder/device_function.rs
2-
31
//! Contains builder functions to convert `types::DeviceFunction` into `model::DeviceFunction`.
2+
//!
3+
//! This handles the serialization of device capabilities, pictures, connectors,
4+
//! dictionaries, and firmware references.
45
56
#![allow(clippy::pedantic)] // XML schema names are not idiomatic Rust
67

@@ -16,7 +17,7 @@ fn build_glabels(label: Option<&String>, description: Option<&String>) -> Glabel
1617
let mut items = Vec::new();
1718
if let Some(l) = label {
1819
items.push(LabelChoice::Label(Label {
19-
lang: "en".to_string(), // Default to "en" for serialization
20+
lang: "en".to_string(),
2021
value: l.clone(),
2122
}));
2223
}
@@ -36,13 +37,13 @@ fn build_model_characteristic(
3637
) -> model::device_function::Characteristic {
3738
model::device_function::Characteristic {
3839
characteristic_name: model::device_function::CharacteristicName {
39-
items: build_glabels(Some(&public.name), None).items, // FIX: Assign to items
40+
items: build_glabels(Some(&public.name), None).items,
4041
},
4142
characteristic_content: public
4243
.content
4344
.iter()
4445
.map(|c| model::device_function::CharacteristicContent {
45-
items: build_glabels(Some(c), None).items, // FIX: Assign to items
46+
items: build_glabels(Some(c), None).items,
4647
..Default::default()
4748
})
4849
.collect(),
@@ -123,11 +124,11 @@ fn build_model_connector(public: &types::Connector) -> model::device_function::C
123124
model::device_function::Connector {
124125
labels: build_glabels(public.label.as_ref(), public.description.as_ref()),
125126
id: public.id.clone(),
126-
pos_x: None, // posX/posY are not in public types
127+
pos_x: None, // Coordinates are not currently exposed in public types
127128
pos_y: None,
128129
connector_type: Some(public.connector_type.clone()),
129130
interface_id_ref: public.interface_id_ref.clone(),
130-
positioning: None, // positioning is not in public types
131+
positioning: None,
131132
}
132133
}
133134

crates/powerlink-rs-xdc/src/builder/device_manager.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// crates/powerlink-rs-xdc/src/builder/device_manager.rs
2-
31
//! Contains builder functions to convert `types::DeviceManager` into `model::DeviceManager`.
2+
//!
3+
//! This module handles the serialization of Indicators (LEDs), states, and
4+
//! module management configurations in the Device Profile.
45
56
use crate::model::common::{Description, Glabels, Label, LabelChoice};
67
use crate::{model, types};
@@ -12,11 +13,11 @@ fn build_model_led_state(public: &types::LEDstate) -> model::device_manager::LED
1213
labels: Glabels {
1314
items: vec![
1415
LabelChoice::Label(Label {
15-
lang: "en".to_string(), // Default lang
16+
lang: "en".to_string(), // Default to English
1617
value: public.label.clone().unwrap_or_default(),
1718
}),
1819
LabelChoice::Description(Description {
19-
lang: "en".to_string(), // Default lang
20+
lang: "en".to_string(),
2021
value: public.description.clone().unwrap_or_default(),
2122
..Default::default()
2223
}),
@@ -27,14 +28,15 @@ fn build_model_led_state(public: &types::LEDstate) -> model::device_manager::LED
2728
"on" => model::device_manager::LEDstateEnum::On,
2829
"off" => model::device_manager::LEDstateEnum::Off,
2930
"flashing" => model::device_manager::LEDstateEnum::Flashing,
30-
_ => model::device_manager::LEDstateEnum::Off, // Default
31+
_ => model::device_manager::LEDstateEnum::Off, // Default fallback
3132
},
3233
led_color: match public.color.as_str() {
3334
"green" => model::device_manager::LEDcolor::Green,
3435
"amber" => model::device_manager::LEDcolor::Amber,
3536
"red" => model::device_manager::LEDcolor::Red,
36-
_ => model::device_manager::LEDcolor::Green, // Default
37+
_ => model::device_manager::LEDcolor::Green, // Default fallback
3738
},
39+
// Flashing period and impulse width are not currently in public types, so defaults are used.
3840
..Default::default()
3941
}
4042
}
@@ -64,7 +66,7 @@ fn build_model_led(public: &types::LED) -> model::device_manager::LED {
6466
"IO" => model::device_manager::LEDtype::Io,
6567
"device" => model::device_manager::LEDtype::Device,
6668
"communication" => model::device_manager::LEDtype::Communication,
67-
_ => model::device_manager::LEDtype::Device, // Default
69+
_ => model::device_manager::LEDtype::Device,
6870
}),
6971
led_state: public.states.iter().map(build_model_led_state).collect(),
7072
}

crates/powerlink-rs-xdc/src/builder/modular.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// crates/powerlink-rs-xdc/src/builder/modular.rs
2-
31
//! Contains builder functions to convert modular `types` into modular `model` structs.
2+
//!
3+
//! This module handles the serialization logic for Modular Device Profiles (XDDM/XDCM),
4+
//! including Interface definitions for both Device and Communication profiles.
45
56
use crate::{model, types};
67
use alloc::format;
@@ -9,14 +10,17 @@ use alloc::string::ToString;
910
// --- Device Profile Builders ---
1011

1112
/// Converts a public `types::InterfaceDevice` into a `model::modular::InterfaceDevice`.
13+
///
14+
/// Maps the interface type, addressing mode, and file lists from the resolved format
15+
/// back to the schema format.
1216
fn build_model_interface_device(
1317
public: &types::InterfaceDevice,
1418
) -> model::modular::InterfaceDevice {
1519
model::modular::InterfaceDevice {
1620
unique_id: public.unique_id.clone(),
1721
interface_type: public.interface_type.clone(),
1822
max_modules: public.max_modules.to_string(),
19-
unused_slots: false, // TODO: This field is missing from `types::InterfaceDevice`
23+
unused_slots: false, // This field is currently static/missing in types
2024
module_addressing: match public.module_addressing.as_str() {
2125
"manual" => model::modular::ModuleAddressingHead::Manual,
2226
"position" => model::modular::ModuleAddressingHead::Position,
@@ -57,7 +61,8 @@ fn build_model_module_interface(
5761
"next" => model::modular::ModuleAddressingChild::Next,
5862
_ => model::modular::ModuleAddressingChild::Position, // Default
5963
},
60-
..Default::default() // fileList, moduleTypeList, etc., are not serialized from types
64+
// fileList and moduleTypeList are currently not serialized from public types
65+
..Default::default()
6166
}
6267
}
6368

@@ -83,6 +88,8 @@ pub(super) fn build_model_module_management_device(
8388
// --- Communication Profile Builders ---
8489

8590
/// Converts a public `types::Range` into a `model::modular::Range`.
91+
///
92+
/// Handles formatting of indices to hex strings (e.g., `04X`).
8693
fn build_model_range(public: &types::Range) -> model::modular::Range {
8794
model::modular::Range {
8895
name: public.name.clone(),

crates/powerlink-rs-xdc/src/builder/net_mgmt.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
// crates/powerlink-rs-xdc/src/builder/net_mgmt.rs
2-
31
//! Contains builder functions to convert `types::NetworkManagement` into `model::NetworkManagement`.
2+
//!
3+
//! This module maps the user-facing Network Management configuration (features, diagnostic definitions)
4+
//! back into the schema-compliant internal model for serialization.
45
56
use crate::model::common::{Description, Glabels, Label, LabelChoice};
67
use crate::{model, types};
78
use alloc::string::{String, ToString};
89
use alloc::vec::Vec;
910

10-
/// Helper to create a `Glabels` struct.
11+
/// Helper to create a `Glabels` struct from optional label and description strings.
12+
///
13+
/// XDC uses `g_labels` to support multilingual text. This builder currently defaults
14+
/// to creating "en" (English) entries for the provided strings.
1115
fn build_glabels(label: Option<&String>, description: Option<&String>) -> Option<Glabels> {
1216
let mut items = Vec::new();
1317
if let Some(l) = label {
@@ -30,28 +34,28 @@ fn build_glabels(label: Option<&String>, description: Option<&String>) -> Option
3034
}
3135
}
3236

33-
/// Builds `model::net_mgmt::AddInfo`.
37+
/// Builds `model::net_mgmt::AddInfo` from the public type.
3438
fn build_model_add_info(public: &types::AddInfo) -> model::net_mgmt::AddInfo {
3539
model::net_mgmt::AddInfo {
3640
name: public.name.clone(),
3741
bit_offset: public.bit_offset.to_string(),
3842
len: public.len.to_string(),
3943
labels: build_glabels(None, public.description.as_ref()),
40-
value: Vec::new(), // TODO: AddInfoValue support in types if needed
44+
value: Vec::new(), // AddInfoValue support is not yet exposed in public types
4145
}
4246
}
4347

44-
/// Builds `model::net_mgmt::Error`.
48+
/// Builds `model::net_mgmt::Error` from the public `ErrorDefinition`.
4549
fn build_model_error(public: &types::ErrorDefinition) -> model::net_mgmt::Error {
4650
model::net_mgmt::Error {
4751
name: public.name.clone(),
4852
value: public.value.clone(),
49-
labels: None, // ErrorDefinition in types doesn't have label/desc yet
53+
labels: None, // ErrorDefinition in types doesn't currently support labels/desc
5054
add_info: public.add_info.iter().map(build_model_add_info).collect(),
5155
}
5256
}
5357

54-
/// Builds `model::net_mgmt::ErrorBit`.
58+
/// Builds `model::net_mgmt::ErrorBit` from the public `StaticErrorBit`.
5559
fn build_model_error_bit(public: &types::StaticErrorBit) -> model::net_mgmt::ErrorBit {
5660
model::net_mgmt::ErrorBit {
5761
name: public.name.clone(),
@@ -60,7 +64,7 @@ fn build_model_error_bit(public: &types::StaticErrorBit) -> model::net_mgmt::Err
6064
}
6165
}
6266

63-
/// Builds `model::net_mgmt::Diagnostic`.
67+
/// Builds the `model::net_mgmt::Diagnostic` block.
6468
fn build_model_diagnostic(public: &types::Diagnostic) -> model::net_mgmt::Diagnostic {
6569
let error_list = if public.errors.is_empty() {
6670
None
@@ -85,6 +89,8 @@ fn build_model_diagnostic(public: &types::Diagnostic) -> model::net_mgmt::Diagno
8589
}
8690

8791
/// Converts a public `types::NetworkManagement` into a `model::NetworkManagement`.
92+
///
93+
/// This function aggregates General, MN, and CN features into the internal model format.
8894
pub(super) fn build_model_network_management(
8995
public: &types::NetworkManagement,
9096
) -> model::net_mgmt::NetworkManagement {
@@ -104,7 +110,7 @@ pub(super) fn build_model_network_management(
104110
sdo_support_asnd: public.general_features.sdo_support_asnd,
105111
sdo_support_udp_ip: public.general_features.sdo_support_udp_ip,
106112

107-
// --- NEW Fields ---
113+
// --- Detailed Feature Flags ---
108114
nmt_isochronous: public.general_features.nmt_isochronous,
109115
sdo_support_pdo: public.general_features.sdo_support_pdo,
110116
nmt_ext_nmt_cmds: public.general_features.nmt_ext_nmt_cmds,
@@ -159,7 +165,7 @@ pub(super) fn build_model_network_management(
159165
mn_features,
160166
cn_features,
161167
diagnostic,
162-
device_commissioning: None,
168+
device_commissioning: None, // DeviceCommissioning is typically not round-tripped this way
163169
}
164170
}
165171

@@ -236,4 +242,4 @@ mod tests {
236242
Some(model::net_mgmt::CnFeaturesNmtCnDna::ClearOnNmtResetNode)
237243
);
238244
}
239-
}
245+
}

0 commit comments

Comments
 (0)