pub struct Readout { /* private fields */ }Expand description
Read every telegram of one meter: SND_NKE (primary) or selection (secondary), then
REQ_UD2 with the frame count bit toggled until no more records follow, then
deselection (secondary). A request without a valid reply is repeated with the same
FCB, RETRIES times.
Implementations§
Source§impl Readout
impl Readout
Sourcepub const fn new(target: Target) -> Self
pub const fn new(target: Target) -> Self
A readout with the default retries and a limit of 16 telegrams.
Examples found in repository?
examples/master.rs (line 22)
18fn main() {
19 let mut bus = Scripted::default();
20
21 // 1. Read meter 1 completely: SND_NKE, then REQ_UD2 until no more records follow.
22 let mut readout = Readout::new(Target::Primary(1));
23 while let Some(request) = readout.next_request() {
24 let reply = bus.transfer(request.bytes(), request.timeout_ms(Baud::B2400));
25 let event = if reply.is_empty() { readout.timeout(&reply) } else { readout.reply(&reply) };
26 if let Event::Telegram(app) = event {
27 println!("telegram from {}", app.meter().map_or("?".into(), |m| m.to_string()));
28 for record in app.records().into_iter().flatten().flatten() {
29 println!(" {record}");
30 }
31 }
32 }
33 println!("{} telegrams\n", readout.telegrams());
34
35 // 2. Find every meter on the bus by secondary address.
36 let mut search = Search::new();
37 while let Some(request) = search.next_request() {
38 let reply = bus.transfer(request.bytes(), request.timeout_ms(Baud::B2400));
39 let event = if reply.is_empty() { search.timeout(&reply) } else { search.reply(&reply) };
40 if let Event::Found(meter) = event {
41 println!("found {meter}");
42 }
43 }
44 println!("{} selections", search.selections());
45}Sourcepub const fn max_telegrams(self, max: u8) -> Self
pub const fn max_telegrams(self, max: u8) -> Self
Stop after max telegrams even if the meter says more follow.
Sourcepub fn next_request(&mut self) -> Option<Request>
pub fn next_request(&mut self) -> Option<Request>
The next frame to send, or None when the readout is over.
Examples found in repository?
examples/master.rs (line 23)
18fn main() {
19 let mut bus = Scripted::default();
20
21 // 1. Read meter 1 completely: SND_NKE, then REQ_UD2 until no more records follow.
22 let mut readout = Readout::new(Target::Primary(1));
23 while let Some(request) = readout.next_request() {
24 let reply = bus.transfer(request.bytes(), request.timeout_ms(Baud::B2400));
25 let event = if reply.is_empty() { readout.timeout(&reply) } else { readout.reply(&reply) };
26 if let Event::Telegram(app) = event {
27 println!("telegram from {}", app.meter().map_or("?".into(), |m| m.to_string()));
28 for record in app.records().into_iter().flatten().flatten() {
29 println!(" {record}");
30 }
31 }
32 }
33 println!("{} telegrams\n", readout.telegrams());
34
35 // 2. Find every meter on the bus by secondary address.
36 let mut search = Search::new();
37 while let Some(request) = search.next_request() {
38 let reply = bus.transfer(request.bytes(), request.timeout_ms(Baud::B2400));
39 let event = if reply.is_empty() { search.timeout(&reply) } else { search.reply(&reply) };
40 if let Event::Found(meter) = event {
41 println!("found {meter}");
42 }
43 }
44 println!("{} selections", search.selections());
45}Sourcepub const fn is_complete(&self) -> bool
pub const fn is_complete(&self) -> bool
Whether every telegram was read.
Sourcepub const fn telegrams(&self) -> u8
pub const fn telegrams(&self) -> u8
How many telegrams were read.
Examples found in repository?
examples/master.rs (line 33)
18fn main() {
19 let mut bus = Scripted::default();
20
21 // 1. Read meter 1 completely: SND_NKE, then REQ_UD2 until no more records follow.
22 let mut readout = Readout::new(Target::Primary(1));
23 while let Some(request) = readout.next_request() {
24 let reply = bus.transfer(request.bytes(), request.timeout_ms(Baud::B2400));
25 let event = if reply.is_empty() { readout.timeout(&reply) } else { readout.reply(&reply) };
26 if let Event::Telegram(app) = event {
27 println!("telegram from {}", app.meter().map_or("?".into(), |m| m.to_string()));
28 for record in app.records().into_iter().flatten().flatten() {
29 println!(" {record}");
30 }
31 }
32 }
33 println!("{} telegrams\n", readout.telegrams());
34
35 // 2. Find every meter on the bus by secondary address.
36 let mut search = Search::new();
37 while let Some(request) = search.next_request() {
38 let reply = bus.transfer(request.bytes(), request.timeout_ms(Baud::B2400));
39 let event = if reply.is_empty() { search.timeout(&reply) } else { search.reply(&reply) };
40 if let Event::Found(meter) = event {
41 println!("found {meter}");
42 }
43 }
44 println!("{} selections", search.selections());
45}Sourcepub fn timeout(&mut self, received: &[u8]) -> Event<'static>
pub fn timeout(&mut self, received: &[u8]) -> Event<'static>
The timeout passed without a valid reply (received is ignored: a readout
repeats the request either way).
Examples found in repository?
examples/master.rs (line 25)
18fn main() {
19 let mut bus = Scripted::default();
20
21 // 1. Read meter 1 completely: SND_NKE, then REQ_UD2 until no more records follow.
22 let mut readout = Readout::new(Target::Primary(1));
23 while let Some(request) = readout.next_request() {
24 let reply = bus.transfer(request.bytes(), request.timeout_ms(Baud::B2400));
25 let event = if reply.is_empty() { readout.timeout(&reply) } else { readout.reply(&reply) };
26 if let Event::Telegram(app) = event {
27 println!("telegram from {}", app.meter().map_or("?".into(), |m| m.to_string()));
28 for record in app.records().into_iter().flatten().flatten() {
29 println!(" {record}");
30 }
31 }
32 }
33 println!("{} telegrams\n", readout.telegrams());
34
35 // 2. Find every meter on the bus by secondary address.
36 let mut search = Search::new();
37 while let Some(request) = search.next_request() {
38 let reply = bus.transfer(request.bytes(), request.timeout_ms(Baud::B2400));
39 let event = if reply.is_empty() { search.timeout(&reply) } else { search.reply(&reply) };
40 if let Event::Found(meter) = event {
41 println!("found {meter}");
42 }
43 }
44 println!("{} selections", search.selections());
45}Sourcepub fn reply<'a>(&mut self, bytes: &'a [u8]) -> Event<'a>
pub fn reply<'a>(&mut self, bytes: &'a [u8]) -> Event<'a>
Hand over what arrived: the bytes from the start of the reply.
Examples found in repository?
examples/master.rs (line 25)
18fn main() {
19 let mut bus = Scripted::default();
20
21 // 1. Read meter 1 completely: SND_NKE, then REQ_UD2 until no more records follow.
22 let mut readout = Readout::new(Target::Primary(1));
23 while let Some(request) = readout.next_request() {
24 let reply = bus.transfer(request.bytes(), request.timeout_ms(Baud::B2400));
25 let event = if reply.is_empty() { readout.timeout(&reply) } else { readout.reply(&reply) };
26 if let Event::Telegram(app) = event {
27 println!("telegram from {}", app.meter().map_or("?".into(), |m| m.to_string()));
28 for record in app.records().into_iter().flatten().flatten() {
29 println!(" {record}");
30 }
31 }
32 }
33 println!("{} telegrams\n", readout.telegrams());
34
35 // 2. Find every meter on the bus by secondary address.
36 let mut search = Search::new();
37 while let Some(request) = search.next_request() {
38 let reply = bus.transfer(request.bytes(), request.timeout_ms(Baud::B2400));
39 let event = if reply.is_empty() { search.timeout(&reply) } else { search.reply(&reply) };
40 if let Event::Found(meter) = event {
41 println!("found {meter}");
42 }
43 }
44 println!("{} selections", search.selections());
45}Trait Implementations§
Auto Trait Implementations§
impl Forget for Readout
impl Freeze for Readout
impl Move for Readout
impl RefUnwindSafe for Readout
impl Send for Readout
impl Sync for Readout
impl Unpin for Readout
impl UnsafeUnpin for Readout
impl UnwindSafe for Readout
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