Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix display of PacketUp #480

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,23 @@ impl From<PacketRouterPacketDownV1> for PacketDown {

impl fmt::Display for PacketUp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut frequency = self.0.frequency.to_string();
if frequency.len() > 6 {
// insert period before the last 6 digits
frequency.insert(frequency.len() - 6, '.');
// remove trailing 0's
frequency = frequency.trim_end_matches('0').to_string();
// append MHz to the string
frequency.push_str(" MHz");
} else {
// return in Hz
frequency.push_str(" Hz");
}

f.write_fmt(format_args!(
"@{} us, {:.2} MHz, {:?}, snr: {}, rssi: {}, len: {}",
"@{} us, {}, {:?}, snr: {}, rssi: {}, len: {}",
self.0.timestamp,
self.0.frequency,
frequency,
self.0.datarate(),
self.0.snr,
self.0.rssi,
Expand Down
Loading