Struct teleinfo_nom::TeleinfoMessage
source · 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
impl TeleinfoMessage
sourcepub fn get_message_type(&self) -> TeleinfoMessageType
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)
sourcepub fn get_meter_type(&self) -> TeleinfoMeterType
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)
sourcepub fn get_current_index(&self) -> String
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())
sourcepub fn get_billing_indices(&self) -> Vec<String>
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(),
])
sourcepub fn get_value(&self, key: String) -> Option<&TeleinfoValue>
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 }))
sourcepub fn get_values(&self, keys: Vec<String>) -> Vec<(String, Option<String>)>
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
impl Clone for TeleinfoMessage
source§fn clone(&self) -> TeleinfoMessage
fn clone(&self) -> TeleinfoMessage
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for TeleinfoMessage
impl Debug for TeleinfoMessage
source§impl PartialEq<TeleinfoMessage> for TeleinfoMessage
impl PartialEq<TeleinfoMessage> for TeleinfoMessage
source§fn eq(&self, other: &TeleinfoMessage) -> bool
fn eq(&self, other: &TeleinfoMessage) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl StructuralPartialEq for TeleinfoMessage
Auto Trait Implementations§
impl RefUnwindSafe for TeleinfoMessage
impl Send for TeleinfoMessage
impl Sync for TeleinfoMessage
impl Unpin for TeleinfoMessage
impl UnwindSafe for TeleinfoMessage
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more