Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cats/ham-cats
  • sam/ham-cats
  • Quantum_P/ham-cats
  • Reed/ham-cats
4 results
Show changes
Commits on Source (4)
[package] [package]
name = "ham-cats" name = "ham-cats"
version = "0.2.1" version = "0.2.2"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"
description = "Reference implementations for CATS, the ham radio protocol" description = "Reference implementations for CATS, the ham radio protocol"
......
...@@ -107,7 +107,7 @@ impl<'a, const N: usize, T> From<&'a mut [T; N]> for Buffer<'a, N, T> { ...@@ -107,7 +107,7 @@ impl<'a, const N: usize, T> From<&'a mut [T; N]> for Buffer<'a, N, T> {
} }
} }
impl<'a, const N: usize, T> Deref for Buffer<'a, N, T> { impl<const N: usize, T> Deref for Buffer<'_, N, T> {
type Target = [T]; type Target = [T];
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
...@@ -115,7 +115,7 @@ impl<'a, const N: usize, T> Deref for Buffer<'a, N, T> { ...@@ -115,7 +115,7 @@ impl<'a, const N: usize, T> Deref for Buffer<'a, N, T> {
} }
} }
impl<'a, const N: usize, T> DerefMut for Buffer<'a, N, T> { impl<const N: usize, T> DerefMut for Buffer<'_, N, T> {
fn deref_mut(&mut self) -> &mut [T] { fn deref_mut(&mut self) -> &mut [T] {
&mut self.data[..self.i] &mut self.data[..self.i]
} }
......
#![no_std] #![cfg_attr(not(test), no_std)]
pub mod buffer; pub mod buffer;
pub mod error; pub mod error;
......
...@@ -169,7 +169,7 @@ impl<'a, const N: usize> Packet<'a, N> { ...@@ -169,7 +169,7 @@ impl<'a, const N: usize> Packet<'a, N> {
/// Encodes packet for transmission on the air. /// Encodes packet for transmission on the air.
/// Includes the data length L, but does not include the preamble or sync word. /// Includes the data length L, but does not include the preamble or sync word.
pub fn fully_encode(self, out: &mut Buffer<N>) -> Result<(), EncodeError> { pub fn fully_encode<const M: usize>(self, out: &mut Buffer<M>) -> Result<(), EncodeError> {
let mut data = self.semi_encode().map_err(|(err, _)| err)?; let mut data = self.semi_encode().map_err(|(err, _)| err)?;
whitener::whiten(&mut data); whitener::whiten(&mut data);
ldpc::encode(&mut data)?; ldpc::encode(&mut data)?;
...@@ -379,7 +379,7 @@ impl<'a, const N: usize> Packet<'a, N> { ...@@ -379,7 +379,7 @@ impl<'a, const N: usize> Packet<'a, N> {
} }
} }
impl<'a, const N: usize> Debug for Packet<'a, N> { impl<const N: usize> Debug for Packet<'_, N> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_list() f.debug_list()
.entries(ValidatedWhiskerIter::new(&self.buf)) .entries(ValidatedWhiskerIter::new(&self.buf))
......
use core::fmt::{Debug, Display};
use half::f16; use half::f16;
#[derive(Debug, PartialEq, Clone)] #[derive(PartialEq, Clone)]
pub struct Gps { pub struct Gps {
latitude: i32, latitude: i32,
longitude: i32, longitude: i32,
...@@ -100,6 +101,27 @@ impl Gps { ...@@ -100,6 +101,27 @@ impl Gps {
} }
} }
impl Debug for Gps {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("Gps")
.field("latitude", &DebugUnits(self.latitude(), "°"))
.field("longitude", &DebugUnits(self.longitude(), "°"))
.field("altitude", &DebugUnits(self.altitude, " m"))
.field("max_error", &DebugUnits(self.max_error, " m"))
.field("heading", &DebugUnits(self.heading(), "°"))
.field("speed", &DebugUnits(self.speed, " m/s"))
.finish()
}
}
struct DebugUnits<'a, T>(T, &'a str);
impl<T: Display> Debug for DebugUnits<'_, T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}{}", self.0, self.1)
}
}
// no-std and it's not worth bringing in a library for this // no-std and it's not worth bringing in a library for this
fn round(v: f64) -> u32 { fn round(v: f64) -> u32 {
let floor = v as u32; let floor = v as u32;
...@@ -135,4 +157,11 @@ mod tests { ...@@ -135,4 +157,11 @@ mod tests {
let gps = Gps::new(0.0, 0.0, f16::from_f32(0.0), 0, 540.0, f16::from_f32(0.0)); let gps = Gps::new(0.0, 0.0, f16::from_f32(0.0), 0, 540.0, f16::from_f32(0.0));
assert_eq!(gps.heading, 128); assert_eq!(gps.heading, 128);
} }
#[test]
fn debug_printing() {
let gps = Gps::new(0.0, 0.0, f16::from_f32(0.0), 0, 359.0, f16::from_f32(0.0));
let x = format!("{gps:?}");
assert_eq!(x,"Gps { latitude: 0°, longitude: 0°, altitude: 0 m, max_error: 0 m, heading: 358.59375°, speed: 0 m/s }")
}
} }
...@@ -155,7 +155,7 @@ impl<'a> WhiskerIter<'a> { ...@@ -155,7 +155,7 @@ impl<'a> WhiskerIter<'a> {
} }
} }
impl<'a> Iterator for WhiskerIter<'a> { impl Iterator for WhiskerIter<'_> {
type Item = Result<Whisker, DecodeError>; type Item = Result<Whisker, DecodeError>;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
...@@ -179,7 +179,7 @@ impl<'a> ValidatedWhiskerIter<'a> { ...@@ -179,7 +179,7 @@ impl<'a> ValidatedWhiskerIter<'a> {
} }
} }
impl<'a> Iterator for ValidatedWhiskerIter<'a> { impl Iterator for ValidatedWhiskerIter<'_> {
type Item = Whisker; type Item = Whisker;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
......
...@@ -232,7 +232,7 @@ impl<'a> PastHop<'a> { ...@@ -232,7 +232,7 @@ impl<'a> PastHop<'a> {
} }
} }
#[derive(Debug)] #[derive(Debug, Clone)]
struct UntrustedRouteIter<'a> { struct UntrustedRouteIter<'a> {
route: &'a Route, route: &'a Route,
i: usize, i: usize,
...@@ -312,6 +312,7 @@ impl<'a> Iterator for UntrustedRouteIter<'a> { ...@@ -312,6 +312,7 @@ impl<'a> Iterator for UntrustedRouteIter<'a> {
} }
} }
#[derive(Clone)]
pub struct RouteIter<'a> { pub struct RouteIter<'a> {
iter: UntrustedRouteIter<'a>, iter: UntrustedRouteIter<'a>,
} }
......