pub struct TeleinfoMessage { /* private fields */ }
Expand description

Representation of a full message from teleinfo

  • values is hashmap resolving index to TeleinfoValue
  • mode the mode of the messae as TeleinfoMode
  • valid whether the message is valid checksum wise

Implementations§

source§

impl TeleinfoMessage

source

pub fn get_message_type(&self) -> TeleinfoMessageType

Return message type as TeleinfoMessageType

Example
use std::fs::File;
let mut stream = File::open("assets/stream_standard_raw.txt").unwrap();
let (remain, result) = teleinfo_nom::get_message(&mut stream, "".to_string()).unwrap();
assert_eq!(result.get_message_type(),teleinfo_nom::TeleinfoMessageType::Normal)
source

pub fn get_meter_type(&self) -> TeleinfoMeterType

Return meter type as TeleinfoMeterType

Example
use std::fs::File;
let mut stream = File::open("assets/stream_standard_raw.txt").unwrap();
let (remain, result) = teleinfo_nom::get_message(&mut stream, "".to_string()).unwrap();
assert_eq!(result.get_meter_type(),teleinfo_nom::TeleinfoMeterType::TriPhase)
source

pub fn get_current_index(&self) -> String

Return the index currently increasing

Example
use std::fs::File;
let mut stream = File::open("assets/stream_standard_raw.txt").unwrap();
let (remain, result) = teleinfo_nom::get_message(&mut stream, "".to_string()).unwrap();
assert_eq!(result.get_current_index(),"EASF03".to_string());
let mut stream = File::open("assets/stream_legacy_raw.txt").unwrap();
let (remain, result) = teleinfo_nom::get_message(&mut stream, "".to_string()).unwrap();
assert_eq!(result.get_current_index(),"BBRHPJB".to_string())
source

pub fn get_billing_indices(&self) -> Vec<String>

Return all relevant billing indices for the message

Example
use std::fs::File;
let mut stream = File::open("assets/stream_standard_raw.txt").unwrap();
let (remain, result) = teleinfo_nom::get_message(&mut stream, "".to_string()).unwrap();
assert_eq!(result.get_billing_indices(),vec![
       "EASF01".to_string(),
       "EASF02".to_string(),
       "EASF03".to_string(),
       "EASF04".to_string(),
       "EASF05".to_string(),
       "EASF06".to_string(),
       "EASF07".to_string(),
       "EASF08".to_string(),
       "EASF09".to_string(),
       "EASF10".to_string(),
   ]);
let mut stream = File::open("assets/stream_legacy_raw.txt").unwrap();
let (remain, result) = teleinfo_nom::get_message(&mut stream, "".to_string()).unwrap();
assert_eq!(result.get_billing_indices(),vec![
"BBRHCJB".to_string(),
"BBRHPJB".to_string(),
"BBRHCJR".to_string(),
"BBRHPJR".to_string(),
"BBRHCJW".to_string(),
"BBRHPJW".to_string(),
])
source

pub fn get_value(&self, key: String) -> Option<&TeleinfoValue>

Return a &TeleinfoValue as Option for key

Example
use std::fs::File;
let mut stream = File::open("assets/stream_standard_raw.txt").unwrap();
let (remain, result) = teleinfo_nom::get_message(&mut stream, "".to_string()).unwrap();
assert_eq!(result.get_value("EASF03".to_string()).unwrap().value,"000487131");
let mut stream = File::open("assets/stream_legacy_raw.txt").unwrap();
let (remain, result) = teleinfo_nom::get_message(&mut stream, "".to_string()).unwrap();
assert_eq!(result.get_value("BBRHPJB".to_string()),Some(&teleinfo_nom::TeleinfoValue{value: "001012295".to_string(),
horodate: None }))
source

pub fn get_values(&self, keys: Vec<String>) -> Vec<(String, Option<String>)>

Return a vector of tuples with (index,Option(value)) from a vector of indices to fetch

Example
use std::fs::File;
let mut stream = File::open("assets/stream_standard_raw.txt").unwrap();
let (remain, result) = teleinfo_nom::get_message(&mut stream, "".to_string()).unwrap();
assert_eq!(result.get_values(result.get_billing_indices()),
           vec![
           ("EASF01".to_string(),Some("004855593".to_string())),
           ("EASF02".to_string(),Some("014090959".to_string())),
           ("EASF03".to_string(),Some("000487131".to_string())),
           ("EASF04".to_string(),Some("001481464".to_string())),
           ("EASF05".to_string(),Some("000227596".to_string())),
           ("EASF06".to_string(),Some("000706363".to_string())),
           ("EASF07".to_string(),Some("000000000".to_string())),
           ("EASF08".to_string(),Some("000000000".to_string())),
           ("EASF09".to_string(),Some("000000000".to_string())),
           ("EASF10".to_string(),Some("000000000".to_string())),
           ]);
let mut stream = File::open("assets/stream_legacy_raw.txt").unwrap();
let (remain, result) = teleinfo_nom::get_message(&mut stream, "".to_string()).unwrap();
assert_eq!(result.get_values(result.get_billing_indices()),
           vec![
           ("BBRHCJB".to_string(),Some("001478389".to_string())),
           ("BBRHPJB".to_string(),Some("001012295".to_string())),
           ("BBRHCJR".to_string(),Some("000025098".to_string())),
           ("BBRHPJR".to_string(),Some("000006010".to_string())),
           ("BBRHCJW".to_string(),Some("000134553".to_string())),
           ("BBRHPJW".to_string(),Some("000213701".to_string())),
           ]);

Trait Implementations§

source§

impl Clone for TeleinfoMessage

source§

fn clone(&self) -> TeleinfoMessage

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for TeleinfoMessage

source§

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

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

impl PartialEq<TeleinfoMessage> for TeleinfoMessage

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for TeleinfoMessage

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.