pub struct Search { /* private fields */ }Expand description
A secondary-address search (wildcard scan): finds every meter on the bus.
Probes a selection with the first digit fixed and the rest wildcarded. No reply: no
meter there. E5: exactly one meter, read with REQ_UD2 to learn its address. A
garbled reply: several meters collided, so the next digit is fixed too, 0 to 9, and
so on. Depth-first, at most 8 digits deep; ends after at most 10 × 8 × (meters + 1)
selections, plus one read per meter.
Implementations§
Source§impl Search
impl Search
Sourcepub const fn new() -> Self
pub const fn new() -> Self
A search of the whole bus.
Examples found in repository?
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_selections(self, max: u32) -> Self
pub const fn max_selections(self, max: u32) -> Self
Give up after max selections (default 20 000: a bus of 250 meters needs at most
10 × 8 × 251). A stuck line or a babbling device makes every probe look like a
collision, and the full tree has 10⁸ prefixes.
Sourcepub const fn is_complete(&self) -> bool
pub const fn is_complete(&self) -> bool
Whether the search covered the whole bus (false while running, or after it gave
up at Search::max_selections).
Sourcepub fn probe(&self) -> SecondaryAddress
pub fn probe(&self) -> SecondaryAddress
The selection pattern being probed.
Sourcepub const fn selections(&self) -> u32
pub const fn selections(&self) -> u32
How many selections have been sent.
Examples found in repository?
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 next_request(&mut self) -> Option<Request>
pub fn next_request(&mut self) -> Option<Request>
The next frame to send, or None when the search is over.
Examples found in repository?
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. received is whatever arrived in that time (empty if
nothing): bytes that are not a valid frame mean several meters answered at once.
Examples found in repository?
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(&mut self, bytes: &[u8]) -> Event<'static>
pub fn reply(&mut self, bytes: &[u8]) -> Event<'static>
Hand over what arrived. Incomplete but plausible bytes: Event::NeedMore;
anything invalid: a collision.
Examples found in repository?
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}