diff --git a/src/packet.rs b/src/packet.rs index 13f370c3..eef25a41 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -50,10 +50,23 @@ impl From 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,