Skip to content

Commit

Permalink
fix display of PacketUp
Browse files Browse the repository at this point in the history
  • Loading branch information
lthiery committed Apr 17, 2024
1 parent 1d69023 commit 81d1ca1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ tokio = { version = "1", default-features = false, features = [
] }
tokio-stream = { version = "0", default-features = false }
futures = "*"
rust_decimal = { workspace = true }
triggered = "0.1"
tracing = "0"
tracing-subscriber = { version = "0", default-features = false, features = [
Expand Down
15 changes: 13 additions & 2 deletions src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,21 @@ impl From<PacketRouterPacketDownV1> for PacketDown {

impl fmt::Display for PacketUp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use rust_decimal::Decimal;
// format the frequency to appropriate units
let (mut frequency, f_units) = if self.frequency >= 1_000_000 {
(Decimal::new(self.frequency.into(), 6), "MHz")
} else if self.frequency >= 1_000 {
(Decimal::new(self.frequency.into(), 3), "kHz")
} else {
(Decimal::new(self.frequency.into(), 0), "Hz")
};
frequency.normalize_assign();
f.write_fmt(format_args!(
"@{} us, {:.2} MHz, {:?}, snr: {}, rssi: {}, len: {}",
"@{} us, {} {}, {:?}, snr: {}, rssi: {}, len: {}",
self.0.timestamp,
self.0.frequency,
frequency,
f_units,
self.0.datarate(),
self.0.snr,
self.0.rssi,
Expand Down

0 comments on commit 81d1ca1

Please sign in to comment.