firmware: add fmt::Display to RoutingTable

This commit is contained in:
Sebastien Bourdeauducq 2018-09-11 11:27:56 +08:00
parent 2fff96802b
commit 3d29a7ed14
1 changed files with 21 additions and 0 deletions

View File

@ -1,4 +1,5 @@
use board_misoc::{csr, config}; use board_misoc::{csr, config};
use core::fmt;
pub const DEST_COUNT: usize = 256; pub const DEST_COUNT: usize = 256;
pub const MAX_HOPS: usize = 32; pub const MAX_HOPS: usize = 32;
@ -26,6 +27,26 @@ impl RoutingTable {
} }
} }
impl fmt::Display for RoutingTable {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "RoutingTable {{")?;
for i in 0..DEST_COUNT {
if self.0[i][0] != INVALID_HOP {
write!(f, "{}:", i)?;
for j in 0..MAX_HOPS {
if self.0[i][j] == INVALID_HOP {
break;
}
write!(f, " {}", self.0[i][j])?;
}
write!(f, ";")?;
}
}
write!(f, " }}")?;
Ok(())
}
}
pub fn config_routing_table(default_n_links: usize) -> RoutingTable { pub fn config_routing_table(default_n_links: usize) -> RoutingTable {
let mut ret = RoutingTable::default_master(default_n_links); let mut ret = RoutingTable::default_master(default_n_links);
let ok = config::read("routing_table", |result| { let ok = config::read("routing_table", |result| {