opcua_kit/unit.rs
1/// A programmatic OPC UA engineering unit, identified by its authority and signed ID.
2///
3/// Localized display names and descriptions do not participate in comparisons.
4/// See [Part 8, EUInformation](https://reference.opcfoundation.org/specs/OPC-10000-8/5.6.4.3).
5#[derive(Clone, Debug, Eq, PartialEq)]
6#[cfg_attr(
7 feature = "commissioning",
8 derive(serde::Serialize, serde::Deserialize),
9 serde(rename_all = "camelCase", deny_unknown_fields)
10)]
11pub struct EngineeringUnit {
12 /// Case-sensitive namespace URI for the organization defining the unit.
13 pub namespace_uri: String,
14 /// Identifier assigned by that organization. A server can report -1 for an unknown unit.
15 pub unit_id: i32,
16}
17
18impl EngineeringUnit {
19 /// Whether the server supplied both parts of a usable programmatic identity.
20 pub fn is_identified(&self) -> bool {
21 self.unit_id != -1
22 && !self.namespace_uri.trim().is_empty()
23 && !self.namespace_uri.chars().any(char::is_control)
24 }
25
26 #[cfg(feature = "cems")]
27 /// Whether this is the UN/CEFACT watt-hour unit (common code WHR).
28 pub fn is_watt_hour(&self) -> bool {
29 self.namespace_uri == "http://www.opcfoundation.org/UA/units/un/cefact"
30 && self.unit_id == 0x574852
31 }
32}