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
56use crate :: model:: app_process:: {
67 AllowedValues , AppArray , AppDataTypeChoice , AppDataTypeList , AppDerived , AppEnum , AppStruct ,
@@ -15,7 +16,6 @@ use alloc::vec;
1516use 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).
1919fn 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 .
3838fn 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 .
5555fn 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 .
6464fn 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 .
9595fn 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 .
105105fn 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 .
131131fn 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) .
150150fn 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 .
235232fn 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+ }
0 commit comments