Skip to content
Snippets Groups Projects
Commit b9af4119 authored by Stephen D's avatar Stephen D
Browse files

update ham-cats

parent 94b3700b
No related branches found
No related tags found
No related merge requests found
...@@ -306,7 +306,7 @@ dependencies = [ ...@@ -306,7 +306,7 @@ dependencies = [
[[package]] [[package]]
name = "ham-cats" name = "ham-cats"
version = "0.1.0" version = "0.1.0"
source = "git+https://gitlab.scd31.com/cats/ham-cats/#97ff918c4e3aaa6e15dadbaa1ab9c12b1fdb5655" source = "git+https://gitlab.scd31.com/cats/ham-cats/#81e90ddc21a4aa0e56acd05a18edb658593cf434"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"bitvec", "bitvec",
...@@ -370,9 +370,9 @@ checksum = "23c19ea22fc166b77441be6ea377e5aa20121490cdec0af18a14356d390f45b5" ...@@ -370,9 +370,9 @@ checksum = "23c19ea22fc166b77441be6ea377e5aa20121490cdec0af18a14356d390f45b5"
[[package]] [[package]]
name = "libm" name = "libm"
version = "0.2.7" version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
...@@ -493,9 +493,9 @@ dependencies = [ ...@@ -493,9 +493,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.69" version = "1.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
......
use ham_cats::{ use ham_cats::{buffer::Buffer, packet::Packet};
buffer::Buffer,
packet::Packet,
whisker::{Route, RouteNode},
};
use rf4463::{config::RADIO_CONFIG_CATS, error::TransferError, Rf4463}; use rf4463::{config::RADIO_CONFIG_CATS, error::TransferError, Rf4463};
use rtic::Mutex; use rtic::Mutex;
use stm32f4xx_hal::{ use stm32f4xx_hal::{
...@@ -119,8 +115,8 @@ impl<'a> RadioManager<'a> { ...@@ -119,8 +115,8 @@ impl<'a> RadioManager<'a> {
callsign: &str, callsign: &str,
ssid: u8, ssid: u8,
) { ) {
if should_digipeat(callsign, ssid, &packet) { if packet.should_digipeat(callsign, ssid).is_ok() {
if append_to_packet_route(callsign, ssid, &mut packet).is_none() { if packet.append_to_route(callsign, ssid).is_err() {
return; return;
} }
...@@ -132,103 +128,3 @@ impl<'a> RadioManager<'a> { ...@@ -132,103 +128,3 @@ impl<'a> RadioManager<'a> {
} }
} }
} }
pub fn should_digipeat(callsign: &str, ssid: u8, packet: &Packet<MAX_PACKET_LEN>) -> bool {
let route = match packet.route() {
Some(x) => x,
None => {
return false;
}
};
if let Some(ident) = packet.identification() {
if &ident.callsign == callsign && ident.ssid == ssid {
// this node is the source of the packet
return false;
}
}
let max_hops: usize = route.max_hops.into();
let cur_hops = route
.iter()
.filter(|r| match r {
RouteNode::Internet => false,
RouteNode::Identity(_, _, is_future) => !is_future,
})
.count();
if max_hops <= cur_hops {
// already hit our max hops
return false;
}
let already_digipeated = route.iter().any(|r| match r {
RouteNode::Internet => false,
RouteNode::Identity(rc, rs, is_future) => rc == callsign && rs == ssid && !is_future,
});
if already_digipeated {
// this node has already digipeated this packet
return false;
}
let next_node = route.iter().find_map(|r| match r {
RouteNode::Identity(c, s, is_future) if is_future => Some((c, s)),
_ => None,
});
match next_node {
Some((rc, rs)) => rc == callsign && rs == ssid,
None => true,
}
}
#[must_use]
pub fn append_to_packet_route(
callsign: &str,
ssid: u8,
packet: &mut Packet<MAX_PACKET_LEN>,
) -> Option<()> {
let mut route = packet.route().unwrap_or(Route::new(0));
append_to_route(callsign, ssid, &mut route)?;
packet.clear_route();
packet.add_route(route).ok()?;
Some(())
}
#[must_use]
fn append_to_route(callsign: &str, ssid: u8, r: &mut Route) -> Option<()> {
let replace_future = r.iter().any(|rn| match rn {
RouteNode::Identity(rc, rs, is_future) => rc == callsign && rs == ssid && is_future,
_ => false,
});
if replace_future {
let mut new_route = Route::new(r.max_hops);
let mut already_replaced = false;
for rn in r.iter() {
match rn {
RouteNode::Identity(rc, rs, is_future)
if rc == callsign && rs == ssid && is_future && !already_replaced =>
{
already_replaced = true;
new_route.push_callsign(callsign, ssid, false)?;
}
RouteNode::Identity(rc, rs, is_future) => {
new_route.push_callsign(rc, rs, is_future)?;
}
RouteNode::Internet => {
new_route.push_internet()?;
}
}
}
*r = new_route;
} else {
r.push_callsign(callsign, ssid, false)?;
}
Some(())
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment