Skip to main content

GetProfilePackResponse

Struct GetProfilePackResponse 

Source
pub struct GetProfilePackResponse<'a> {
    pub server_id: ServerId<'a>,
    pub act_time: Time,
    pub reg_period: u32,
    pub tree_path: NameList<'a>,
    pub columns: ProfileColumns<'a>,
    pub periods: ProfilePeriods<'a>,
    pub rawdata: Option<&'a [u8]>,
    pub profile_signature: Option<&'a [u8]>,
}
Expand description

SML_GetProfilePack.Res: a profile as one header and many rows.

Fields§

§server_id: ServerId<'a>

The device that answered.

§act_time: Time

The device’s time when it answered.

§reg_period: u32

The registration period in seconds (0: event driven).

§tree_path: NameList<'a>

The profile.

§columns: ProfileColumns<'a>

What each column holds (header_List).

§periods: ProfilePeriods<'a>

The rows (period_List).

§rawdata: Option<&'a [u8]>

Raw data, when asked for.

§profile_signature: Option<&'a [u8]>

A signature over the profile, when the device signs. Not verified by this crate.

Implementations§

Source§

impl<'a> GetProfilePackResponse<'a>

Source

pub fn quantity( &self, period: &ProfilePeriod<'_>, obis: Obis, ) -> Option<Quantity>

The value of column obis in period, scaled by the column’s header, when it is numeric. None when no column has that name or a header or value cannot be read. (A decoded response has one value per column; a built one is not checked, and a short row gives None for the missing columns.)

Examples found in repository?
examples/decode.rs (line 197)
123fn print(bytes: &[u8], options: ParseOptions) -> (usize, (usize, usize)) {
124    let mut decoder = Decoder::new(vec![0u8; 64 * 1024]).with_crc_check(options.crc);
125    let (mut frames, mut errors) = (0, 0);
126    let mut dzg_frames = (0, 0); // (possible, confirmed by the status word)
127    decoder.push_slice(bytes, |frame| {
128        let frame = match frame {
129            Ok(f) => f,
130            Err(e) => {
131                errors += 1;
132                return eprintln!("frame error: {e}");
133            }
134        };
135        frames += 1;
136        println!("── frame {frames} · {} bytes", frame.len());
137        let mut messages = Messages::new(frame, options);
138        while let Some(message) = messages.next() {
139            match message {
140                Err(e) => {
141                    errors += 1;
142                    eprintln!("   message error at byte {}: {e}", messages.offset());
143                }
144                Ok(m) => match m.body {
145                    Body::GetListResponse(list) => {
146                        let time = list.act_sensor_time.map(|t| format!("  at {t}")).unwrap_or_default();
147                        println!("   GetListResponse  server {}{time}", list.server_id);
148                        match dzg_suspect(frame, options.with_dzg_power(false)) {
149                            Dzg::Unchanged => {}
150                            Dzg::Possible => dzg_frames.0 += 1,
151                            Dzg::Confirmed => dzg_frames.1 += 1,
152                        }
153                        for entry in list.entries {
154                            match entry {
155                                Ok(e) => println!("   {}", line(&e)),
156                                Err(err) => {
157                                    errors += 1;
158                                    eprintln!("   entry error: {err}");
159                                }
160                            }
161                        }
162                    }
163                    Body::OpenResponse(o) => println!("   OpenResponse     server {}", o.server_id),
164                    Body::CloseResponse(_) => println!("   CloseResponse"),
165                    Body::Attention(a) => {
166                        println!("   Attention        {:02x?} {}", a.number, a.description().unwrap_or(""));
167                    }
168                    Body::GetProcParameterResponse(r) => {
169                        println!("   GetProcParameterResponse  server {}", r.server_id);
170                        tree(&r.tree, 2);
171                    }
172                    Body::SetProcParameterRequest(r) => {
173                        println!("   SetProcParameterRequest");
174                        tree(&r.tree, 2);
175                    }
176                    Body::GetProfileListResponse(r) => {
177                        println!(
178                            "   GetProfileListResponse  server {}  period {} s",
179                            r.server_id, r.reg_period
180                        );
181                        for e in r.entries.iter().flatten() {
182                            let q = e.quantity().map_or_else(|| format!("{:?}", e.value), |q| q.to_string());
183                            println!("     {:<24} {q}", e.obis.to_string());
184                        }
185                    }
186                    Body::GetProfilePackResponse(p) => {
187                        println!(
188                            "   GetProfilePackResponse  server {}  period {} s",
189                            p.server_id, p.reg_period
190                        );
191                        for row in p.periods.iter().flatten() {
192                            let cells: Vec<String> = p
193                                .columns
194                                .iter()
195                                .flatten()
196                                .map(|c| {
197                                    p.quantity(&row, c.obis)
198                                        .map_or_else(|| "–".into(), |q| format!("{} {q}", c.obis))
199                                })
200                                .collect();
201                            println!("     {}  {}", row.val_time, cells.join("  "));
202                        }
203                    }
204                    Body::Other { tag, raw } => {
205                        println!("   body 0x{tag:08x} ({} bytes, not typed)", raw.len())
206                    }
207                    other => println!("   {other:?}"),
208                },
209            }
210        }
211    });
212    if frames == 0 && errors == 0 {
213        if looks_like_iec_62056_21(bytes) {
214            eprintln!(
215                "no SML frame: this is IEC 62056-21 text (D0), an older protocol, not SML. \
216                 Read it with an IEC 62056-21 parser."
217            );
218        } else {
219            eprintln!("no complete frame found: is the capture long enough (a few seconds) and 9600 8N1?");
220        }
221        errors += 1;
222    }
223    (errors, dzg_frames)
224}

Trait Implementations§

Source§

impl<'a> Clone for GetProfilePackResponse<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for GetProfilePackResponse<'a>

Source§

impl<'a> Debug for GetProfilePackResponse<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for GetProfilePackResponse<'a>

Source§

impl<'a> PartialEq for GetProfilePackResponse<'a>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for GetProfilePackResponse<'a>

Auto Trait Implementations§

§

impl<'a> Forget for GetProfilePackResponse<'a>

§

impl<'a> Freeze for GetProfilePackResponse<'a>
where &'a [u8]: Freeze, &'a [&'a [u8]]: Freeze, &'a [ProfileColumn]: Freeze, &'a [ProfilePeriod<'a>]: Freeze,

§

impl<'a> Move for GetProfilePackResponse<'a>

§

impl<'a> RefUnwindSafe for GetProfilePackResponse<'a>

§

impl<'a> Send for GetProfilePackResponse<'a>
where &'a [u8]: Send, &'a [&'a [u8]]: Send, &'a [ProfileColumn]: Send, &'a [ProfilePeriod<'a>]: Send,

§

impl<'a> Sync for GetProfilePackResponse<'a>

§

impl<'a> Unpin for GetProfilePackResponse<'a>
where &'a [u8]: Unpin, &'a [&'a [u8]]: Unpin, &'a [ProfileColumn]: Unpin, &'a [ProfilePeriod<'a>]: Unpin,

§

impl<'a> UnsafeUnpin for GetProfilePackResponse<'a>
where &'a [u8]: UnsafeUnpin, &'a [&'a [u8]]: UnsafeUnpin, &'a [ProfileColumn]: UnsafeUnpin, &'a [ProfilePeriod<'a>]: UnsafeUnpin,

§

impl<'a> UnwindSafe for GetProfilePackResponse<'a>
where &'a [u8]: UnwindSafe, &'a [&'a [u8]]: UnwindSafe, &'a [ProfileColumn]: UnwindSafe, &'a [ProfilePeriod<'a>]: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.