Skip to main content

cimstructs/
AnalogControl.rs

1/// An analog control used for supervisory control.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct AnalogControl {
4    #[serde(flatten)]
5    pub base: super::Control,
6    /// The MeasurementValue that is controlled.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub analog_value: Option<super::base::MridRef>,
9    /// Normal value range maximum for any of the Control.value. Used for scaling, e.g. in bar graphs.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub max_value: Option<f64>,
12    /// Normal value range minimum for any of the Control.value. Used for scaling, e.g. in bar graphs.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub min_value: Option<f64>,
15}
16impl crate::base::CimElement for AnalogControl {
17    fn mrid(&self) -> &str { &self.base.base.base.id }
18    fn type_name(&self) -> &'static str { "AnalogControl" }
19    fn as_any(&self) -> &dyn std::any::Any { self }
20    fn to_json_value(&self) -> serde_json::Value {
21        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
22    }
23    fn to_block(&self) -> crate::base::RdfBlock {
24        let mut block = self.base.to_block();
25        block.type_name = "AnalogControl".to_string();
26        if let Some(ref v) = self.analog_value {
27            block.fields.insert("AnalogControl.AnalogValue".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
28        }
29        if let Some(v) = self.max_value {
30            block.fields.insert("AnalogControl.maxValue".into(), crate::base::FieldValue::Text(v.to_string()));
31        }
32        if let Some(v) = self.min_value {
33            block.fields.insert("AnalogControl.minValue".into(), crate::base::FieldValue::Text(v.to_string()));
34        }
35        block
36    }
37}
38
39impl AnalogControl {
40    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
41        let mut obj = Self::default();
42        obj.base.base.base.id.clone_from(&b.mrid);
43        for (key, val) in &b.fields {
44            match key.as_str() {
45                "AnalogControl.AnalogValue" => {
46                    if let crate::base::FieldValue::Resource(sv) = val {
47                        obj.analog_value = Some(crate::base::MridRef { mrid: sv.clone() });
48                    }
49                }
50                "AnalogControl.maxValue" => {
51                    match val {
52                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.max_value = Some(v); } }
53                        crate::base::FieldValue::TextList(svs) => {
54                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.max_value = Some(v); } }
55                        }
56                        _ => {}
57                    }
58                }
59                "AnalogControl.minValue" => {
60                    match val {
61                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.min_value = Some(v); } }
62                        crate::base::FieldValue::TextList(svs) => {
63                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.min_value = Some(v); } }
64                        }
65                        _ => {}
66                    }
67                }
68                "Control.PowerSystemResource" => {
69                    if let crate::base::FieldValue::Resource(sv) = val {
70                        obj.base.power_system_resource = Some(crate::base::MridRef { mrid: sv.clone() });
71                    }
72                }
73                "Control.controlType" => {
74                    match val {
75                        crate::base::FieldValue::Text(sv) => { obj.base.control_type = sv.clone(); }
76                        crate::base::FieldValue::TextList(svs) => {
77                            if let Some(sv) = svs.last() { obj.base.control_type = sv.clone(); }
78                        }
79                        _ => {}
80                    }
81                }
82                "Control.operationInProgress" => {
83                    match val {
84                        crate::base::FieldValue::Text(sv) => { obj.base.operation_in_progress = Some(sv.trim() == "true"); }
85                        crate::base::FieldValue::TextList(svs) => {
86                            if let Some(sv) = svs.last() { obj.base.operation_in_progress = Some(sv.trim() == "true"); }
87                        }
88                        _ => {}
89                    }
90                }
91                "Control.timeStamp" => {
92                    match val {
93                        crate::base::FieldValue::Text(sv) => { obj.base.time_stamp = sv.clone(); }
94                        crate::base::FieldValue::TextList(svs) => {
95                            if let Some(sv) = svs.last() { obj.base.time_stamp = sv.clone(); }
96                        }
97                        _ => {}
98                    }
99                }
100                "Control.unitMultiplier" => {
101                    if let crate::base::FieldValue::Resource(sv) = val {
102                        obj.base.unit_multiplier = Some(crate::base::UriRef { uri: sv.clone() });
103                    }
104                }
105                "Control.unitSymbol" => {
106                    if let crate::base::FieldValue::Resource(sv) = val {
107                        obj.base.unit_symbol = Some(crate::base::UriRef { uri: sv.clone() });
108                    }
109                }
110                "IdentifiedObject.description" => {
111                    match val {
112                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.description = sv.clone(); }
113                        crate::base::FieldValue::TextList(svs) => {
114                            if let Some(sv) = svs.last() { obj.base.base.base.description = sv.clone(); }
115                        }
116                        _ => {}
117                    }
118                }
119                "IdentifiedObject.energyIdentCodeEic" => {
120                    match val {
121                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
122                        crate::base::FieldValue::TextList(svs) => {
123                            if let Some(sv) = svs.last() { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
124                        }
125                        _ => {}
126                    }
127                }
128                "IdentifiedObject.mRID" => {
129                    match val {
130                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.m_rid = sv.clone(); }
131                        crate::base::FieldValue::TextList(svs) => {
132                            if let Some(sv) = svs.last() { obj.base.base.base.m_rid = sv.clone(); }
133                        }
134                        _ => {}
135                    }
136                }
137                "IdentifiedObject.name" => {
138                    match val {
139                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.name = sv.clone(); }
140                        crate::base::FieldValue::TextList(svs) => {
141                            if let Some(sv) = svs.last() { obj.base.base.base.name = sv.clone(); }
142                        }
143                        _ => {}
144                    }
145                }
146                "IdentifiedObject.shortName" => {
147                    match val {
148                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.short_name = sv.clone(); }
149                        crate::base::FieldValue::TextList(svs) => {
150                            if let Some(sv) = svs.last() { obj.base.base.base.short_name = sv.clone(); }
151                        }
152                        _ => {}
153                    }
154                }
155                _ => {}
156            }
157        }
158        obj
159    }
160}