Merge pull request 'Update STM32F3 example' (#148) from update-stm32f3-example-tmtc-handling into main
All checks were successful
Rust/sat-rs/pipeline/head This commit looks good

Reviewed-on: #148
This commit is contained in:
Robin Müller 2024-04-04 18:33:00 +02:00
commit 0fec994028
9 changed files with 315 additions and 220 deletions

View File

@ -22,9 +22,9 @@ dependencies = [
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.1.0" version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80"
[[package]] [[package]]
name = "bare-metal" name = "bare-metal"
@ -88,19 +88,13 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "chrono" name = "chrono"
version = "0.4.35" version = "0.4.37"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e"
dependencies = [ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "cobs"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15"
[[package]] [[package]]
name = "cobs" name = "cobs"
version = "0.2.3" version = "0.2.3"
@ -189,7 +183,7 @@ dependencies = [
"ident_case", "ident_case",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.53", "syn 2.0.58",
] ]
[[package]] [[package]]
@ -200,7 +194,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f"
dependencies = [ dependencies = [
"darling_core", "darling_core",
"quote", "quote",
"syn 2.0.53", "syn 2.0.58",
] ]
[[package]] [[package]]
@ -233,7 +227,7 @@ dependencies = [
"proc-macro-error", "proc-macro-error",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.53", "syn 2.0.58",
] ]
[[package]] [[package]]
@ -265,7 +259,7 @@ checksum = "984bc6eca246389726ac2826acc2488ca0fe5fcd6b8d9b48797021951d76a125"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.53", "syn 2.0.58",
] ]
[[package]] [[package]]
@ -331,7 +325,7 @@ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.53", "syn 2.0.58",
] ]
[[package]] [[package]]
@ -559,7 +553,7 @@ checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.53", "syn 2.0.58",
] ]
[[package]] [[package]]
@ -580,9 +574,9 @@ checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.13" version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02"
[[package]] [[package]]
name = "pin-utils" name = "pin-utils"
@ -634,9 +628,9 @@ dependencies = [
[[package]] [[package]]
name = "rtcc" name = "rtcc"
version = "0.3.1" version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4fbd0d5bed2b76e27a7ef872568b34072c1af94c277cd52c17a89d54673b3fe" checksum = "95973c3a0274adc4f3c5b70d2b5b85618d6de9559a6737d3293ecae9a2fc0839"
dependencies = [ dependencies = [
"chrono", "chrono",
] ]
@ -680,7 +674,7 @@ dependencies = [
"proc-macro-error", "proc-macro-error",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.53", "syn 2.0.58",
] ]
[[package]] [[package]]
@ -729,10 +723,8 @@ dependencies = [
[[package]] [[package]]
name = "satrs" name = "satrs"
version = "0.2.0-rc.0" version = "0.2.0-rc.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8cb19cba46a45047ff0879ebfbf9d6ae1c5b2e0e38b2e08760b10a441d4dae6"
dependencies = [ dependencies = [
"cobs 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "cobs",
"crc", "crc",
"delegate", "delegate",
"num-traits", "num-traits",
@ -747,7 +739,7 @@ dependencies = [
name = "satrs-example-stm32f3-disco" name = "satrs-example-stm32f3-disco"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"cobs 0.2.3 (git+https://github.com/robamu/cobs.rs.git?branch=all_features)", "cobs",
"cortex-m", "cortex-m",
"cortex-m-rt", "cortex-m-rt",
"cortex-m-semihosting", "cortex-m-semihosting",
@ -767,9 +759,7 @@ dependencies = [
[[package]] [[package]]
name = "satrs-shared" name = "satrs-shared"
version = "0.1.2" version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75a402ba556a7f5eef707035b45e64a3259b09674311e98697f3dd0508a1bf51"
dependencies = [ dependencies = [
"spacepackets", "spacepackets",
] ]
@ -809,12 +799,12 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]] [[package]]
name = "spacepackets" name = "spacepackets"
version = "0.10.0" version = "0.11.0-rc.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28246ae2451af240c3e3ff3c51363c7b6ad565ca6aa9bad23b8c725687c485e1" checksum = "c2cfd5f9a4c7f10714d21f9bc61f2d176cb7ae092cdd687e7ade2d4e6f7d7125"
dependencies = [ dependencies = [
"chrono",
"crc", "crc",
"defmt",
"delegate", "delegate",
"num-traits", "num-traits",
"num_enum", "num_enum",
@ -909,9 +899,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.53" version = "2.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032" checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -935,7 +925,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.53", "syn 2.0.58",
] ]
[[package]] [[package]]
@ -1001,5 +991,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.53", "syn 2.0.58",
] ]

View File

@ -46,8 +46,9 @@ branch = "complete-dma-update-hal"
# path = "../stm32f3-discovery" # path = "../stm32f3-discovery"
[dependencies.satrs] [dependencies.satrs]
version = "0.2.0-rc.0" path = "../satrs"
default-features = false default-features = false
features = ["defmt"]
[dev-dependencies] [dev-dependencies]
defmt-test = "0.3" defmt-test = "0.3"

View File

@ -103,3 +103,12 @@ After that, you can for example send a ping to the MCU using the following comma
```sh ```sh
./main.py -p /ping ./main.py -p /ping
``` ```
You can configure the blinky frequency using
```sh
./main.py -p /change_blink_freq
```
All these commands will package a PUS telecommand which will be sent to the MCU using the COBS
format as the packet framing format.

View File

@ -94,6 +94,7 @@ class SatRsConfigHook(HookBase):
def create_cmd_definition_tree() -> CmdTreeNode: def create_cmd_definition_tree() -> CmdTreeNode:
root_node = CmdTreeNode.root_node() root_node = CmdTreeNode.root_node()
root_node.add_child(CmdTreeNode("ping", "Send PUS ping TC")) root_node.add_child(CmdTreeNode("ping", "Send PUS ping TC"))
root_node.add_child(CmdTreeNode("change_blink_freq", "Change blink frequency"))
return root_node return root_node
@ -215,6 +216,25 @@ class TcHandler(TcHandlerBase):
if cmd_path == "/ping": if cmd_path == "/ping":
q.add_log_cmd("Sending PUS ping telecommand") q.add_log_cmd("Sending PUS ping telecommand")
q.add_pus_tc(PusTelecommand(service=17, subservice=1)) q.add_pus_tc(PusTelecommand(service=17, subservice=1))
if cmd_path == "/change_blink_freq":
self.create_change_blink_freq_command(q)
def create_change_blink_freq_command(self, q: DefaultPusQueueHelper):
q.add_log_cmd("Changing blink frequency")
while True:
blink_freq = int(
input(
"Please specify new blink frequency in ms. Valid Range [2..10000]: "
)
)
if blink_freq < 2 or blink_freq > 10000:
print(
"Invalid blink frequency. Please specify a value between 2 and 10000."
)
continue
break
app_data = struct.pack("!I", blink_freq)
q.add_pus_tc(PusTelecommand(service=8, subservice=1, app_data=app_data))
def main(): def main():

View File

@ -1,5 +1,13 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
use satrs::pus::verification::{
FailParams, TcStateAccepted, VerificationReportCreator, VerificationToken,
};
use satrs::spacepackets::ecss::tc::PusTcReader;
use satrs::spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader};
use satrs::spacepackets::ecss::EcssEnumU16;
use satrs::spacepackets::CcsdsPacket;
use satrs::spacepackets::{ByteConversionError, SpHeader};
// global logger + panicking-behavior + memory layout // global logger + panicking-behavior + memory layout
use satrs_example_stm32f3_disco as _; use satrs_example_stm32f3_disco as _;
@ -7,21 +15,17 @@ use rtic::app;
use heapless::{mpmc::Q8, Vec}; use heapless::{mpmc::Q8, Vec};
#[allow(unused_imports)] #[allow(unused_imports)]
use rtic_monotonics::systick::fugit::TimerInstantU32; use rtic_monotonics::systick::fugit::{MillisDurationU32, TimerInstantU32};
use rtic_monotonics::systick::ExtU32; use rtic_monotonics::systick::ExtU32;
use satrs::seq_count::SequenceCountProviderCore; use satrs::seq_count::SequenceCountProviderCore;
use satrs::{ use satrs::spacepackets::{ecss::PusPacket, ecss::WritablePusPacket};
pool::StoreError,
pus::{EcssChannel, EcssTmSenderCore, EcssTmtcError, PusTmWrapper},
spacepackets::{ecss::PusPacket, ecss::WritablePusPacket},
};
use stm32f3xx_hal::dma::dma1; use stm32f3xx_hal::dma::dma1;
use stm32f3xx_hal::gpio::{PushPull, AF7, PA2, PA3}; use stm32f3xx_hal::gpio::{PushPull, AF7, PA2, PA3};
use stm32f3xx_hal::pac::USART2; use stm32f3xx_hal::pac::USART2;
use stm32f3xx_hal::serial::{Rx, RxEvent, Serial, SerialDmaRx, SerialDmaTx, Tx, TxEvent}; use stm32f3xx_hal::serial::{Rx, RxEvent, Serial, SerialDmaRx, SerialDmaTx, Tx, TxEvent};
const UART_BAUD: u32 = 115200; const UART_BAUD: u32 = 115200;
const BLINK_FREQ_MS: u32 = 1000; const DEFAULT_BLINK_FREQ_MS: u32 = 1000;
const TX_HANDLER_FREQ_MS: u32 = 20; const TX_HANDLER_FREQ_MS: u32 = 20;
const MIN_DELAY_BETWEEN_TX_PACKETS_MS: u32 = 5; const MIN_DELAY_BETWEEN_TX_PACKETS_MS: u32 = 5;
const MAX_TC_LEN: usize = 128; const MAX_TC_LEN: usize = 128;
@ -54,7 +58,6 @@ type TcPacket = Vec<u8, MAX_TC_LEN>;
static TM_REQUESTS: Q8<TmPacket> = Q8::new(); static TM_REQUESTS: Q8<TmPacket> = Q8::new();
use core::cell::RefCell;
use core::sync::atomic::{AtomicU16, Ordering}; use core::sync::atomic::{AtomicU16, Ordering};
pub struct SeqCountProviderAtomicRef { pub struct SeqCountProviderAtomicRef {
@ -93,56 +96,45 @@ pub struct TxIdle {
dma_channel: dma1::C7, dma_channel: dma1::C7,
} }
pub struct TmSender { #[derive(Debug, defmt::Format)]
vec: Option<RefCell<Vec<u8, MAX_TM_LEN>>>, pub enum TmSendError {
ByteConversion(ByteConversionError),
Queue,
} }
impl TmSender { impl From<ByteConversionError> for TmSendError {
pub fn new(tm_packet: TmPacket) -> Self { fn from(value: ByteConversionError) -> Self {
Self { Self::ByteConversion(value)
vec: Some(RefCell::new(tm_packet)),
}
} }
} }
impl EcssChannel for TmSender { fn send_tm(tm_creator: PusTmCreator) -> Result<(), TmSendError> {
fn id(&self) -> satrs::ChannelId { if tm_creator.len_written() > MAX_TM_LEN {
0 return Err(ByteConversionError::ToSliceTooSmall {
expected: tm_creator.len_written(),
found: MAX_TM_LEN,
} }
} .into());
impl EcssTmSenderCore for TmSender {
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcError> {
let vec = self.vec.as_ref();
if vec.is_none() {
panic!("send_tm should only be called once");
} }
let vec_ref = vec.unwrap(); let mut tm_vec = TmPacket::new();
let mut vec = vec_ref.borrow_mut(); tm_vec
match tm { .resize(tm_creator.len_written(), 0)
PusTmWrapper::InStore(addr) => return Err(EcssTmtcError::CantSendAddr(addr)), .expect("vec resize failed");
PusTmWrapper::Direct(tm) => { tm_creator.write_to_bytes(tm_vec.as_mut_slice())?;
if tm.len_written() > MAX_TM_LEN {
return Err(EcssTmtcError::Store(StoreError::DataTooLarge(
tm.len_written(),
)));
}
vec.resize(tm.len_written(), 0).expect("vec resize failed");
tm.write_to_bytes(vec.as_mut_slice())?;
defmt::info!( defmt::info!(
"Sending TM[{},{}] with size {}", "Sending TM[{},{}] with size {}",
tm.service(), tm_creator.service(),
tm.subservice(), tm_creator.subservice(),
tm.len_written() tm_creator.len_written()
); );
drop(vec);
TM_REQUESTS TM_REQUESTS
.enqueue(vec_ref.take()) .enqueue(tm_vec)
.map_err(|_| EcssTmtcError::Store(StoreError::StoreFull(0)))?; .map_err(|_| TmSendError::Queue)?;
}
}
Ok(()) Ok(())
} }
fn handle_tm_send_error(error: TmSendError) {
defmt::warn!("sending tm failed with error {}", error);
} }
pub enum UartTxState { pub enum UartTxState {
@ -157,18 +149,106 @@ pub struct UartTxShared {
state: UartTxState, state: UartTxState,
} }
pub struct RequestWithToken {
token: VerificationToken<TcStateAccepted>,
request: Request,
}
#[derive(Debug, defmt::Format)]
pub enum Request {
Ping,
ChangeBlinkFrequency(u32),
}
#[derive(Debug, defmt::Format)]
pub enum RequestError {
InvalidApid = 1,
InvalidService = 2,
InvalidSubservice = 3,
NotEnoughAppData = 4,
}
pub fn convert_pus_tc_to_request(
tc: &PusTcReader,
verif_reporter: &mut VerificationReportCreator,
src_data_buf: &mut [u8],
timestamp: &[u8],
) -> Result<RequestWithToken, RequestError> {
defmt::info!(
"Found PUS TC [{},{}] with length {}",
tc.service(),
tc.subservice(),
tc.len_packed()
);
let token = verif_reporter.add_tc(tc);
if tc.apid() != PUS_APID {
defmt::warn!("Received tc with unknown APID {}", tc.apid());
let result = send_tm(
verif_reporter
.acceptance_failure(
src_data_buf,
token,
SEQ_COUNT_PROVIDER.get_and_increment(),
0,
FailParams::new(timestamp, &EcssEnumU16::new(0), &[]),
)
.unwrap(),
);
if let Err(e) = result {
handle_tm_send_error(e);
}
return Err(RequestError::InvalidApid);
}
let (tm_creator, accepted_token) = verif_reporter
.acceptance_success(
src_data_buf,
token,
SEQ_COUNT_PROVIDER.get_and_increment(),
0,
timestamp,
)
.unwrap();
if let Err(e) = send_tm(tm_creator) {
handle_tm_send_error(e);
}
if tc.service() == 17 && tc.subservice() == 1 {
if tc.subservice() == 1 {
return Ok(RequestWithToken {
request: Request::Ping,
token: accepted_token,
});
} else {
return Err(RequestError::InvalidSubservice);
}
} else if tc.service() == 8 {
if tc.subservice() == 1 {
if tc.user_data().len() < 4 {
return Err(RequestError::NotEnoughAppData);
}
let new_freq_ms = u32::from_be_bytes(tc.user_data()[0..4].try_into().unwrap());
return Ok(RequestWithToken {
request: Request::ChangeBlinkFrequency(new_freq_ms),
token: accepted_token,
});
} else {
return Err(RequestError::InvalidSubservice);
}
} else {
return Err(RequestError::InvalidService);
}
}
#[app(device = stm32f3xx_hal::pac, peripherals = true)] #[app(device = stm32f3xx_hal::pac, peripherals = true)]
mod app { mod app {
use super::*; use super::*;
use core::slice::Iter; use core::slice::Iter;
use rtic_monotonics::systick::Systick; use rtic_monotonics::systick::Systick;
use rtic_monotonics::Monotonic; use rtic_monotonics::Monotonic;
use satrs::pus::verification::FailParams; use satrs::pus::verification::{TcStateStarted, VerificationReportCreator};
use satrs::pus::verification::VerificationReporterCore; use satrs::spacepackets::{ecss::tc::PusTcReader, time::cds::P_FIELD_BASE};
use satrs::spacepackets::{
ecss::tc::PusTcReader, ecss::tm::PusTmCreator, ecss::tm::PusTmSecondaryHeader,
ecss::EcssEnumU16, time::cds::P_FIELD_BASE, CcsdsPacket, SpHeader,
};
#[allow(unused_imports)] #[allow(unused_imports)]
use stm32f3_discovery::leds::Direction; use stm32f3_discovery::leds::Direction;
use stm32f3_discovery::leds::Leds; use stm32f3_discovery::leds::Leds;
@ -181,15 +261,16 @@ mod app {
#[shared] #[shared]
struct Shared { struct Shared {
blink_freq: MillisDurationU32,
tx_shared: UartTxShared, tx_shared: UartTxShared,
rx_transfer: Option<RxDmaTransferType>, rx_transfer: Option<RxDmaTransferType>,
} }
#[local] #[local]
struct Local { struct Local {
verif_reporter: VerificationReportCreator,
leds: Leds, leds: Leds,
last_dir: Direction, last_dir: Direction,
verif_reporter: VerificationReporterCore,
curr_dir: Iter<'static, Direction>, curr_dir: Iter<'static, Direction>,
} }
@ -215,8 +296,6 @@ mod app {
defmt::info!("Starting sat-rs demo application for the STM32F3-Discovery"); defmt::info!("Starting sat-rs demo application for the STM32F3-Discovery");
let mut gpioe = cx.device.GPIOE.split(&mut rcc.ahb); let mut gpioe = cx.device.GPIOE.split(&mut rcc.ahb);
let verif_reporter = VerificationReporterCore::new(PUS_APID).unwrap();
let leds = Leds::new( let leds = Leds::new(
gpioe.pe8, gpioe.pe8,
gpioe.pe9, gpioe.pe9,
@ -265,8 +344,12 @@ mod app {
defmt::info!("Spawning tasks"); defmt::info!("Spawning tasks");
blink::spawn().unwrap(); blink::spawn().unwrap();
serial_tx_handler::spawn().unwrap(); serial_tx_handler::spawn().unwrap();
let verif_reporter = VerificationReportCreator::new(PUS_APID).unwrap();
( (
Shared { Shared {
blink_freq: MillisDurationU32::from_ticks(DEFAULT_BLINK_FREQ_MS),
tx_shared: UartTxShared { tx_shared: UartTxShared {
last_completed: None, last_completed: None,
state: UartTxState::Idle(Some(TxIdle { state: UartTxState::Idle(Some(TxIdle {
@ -277,17 +360,16 @@ mod app {
rx_transfer: Some(rx_transfer), rx_transfer: Some(rx_transfer),
}, },
Local { Local {
//timer: mono_timer, verif_reporter,
leds, leds,
last_dir: Direction::North, last_dir: Direction::North,
curr_dir: Direction::iter(), curr_dir: Direction::iter(),
verif_reporter,
}, },
) )
} }
#[task(local = [leds, curr_dir, last_dir])] #[task(local = [leds, curr_dir, last_dir], shared=[blink_freq])]
async fn blink(cx: blink::Context) { async fn blink(mut cx: blink::Context) {
let blink::LocalResources { let blink::LocalResources {
leds, leds,
curr_dir, curr_dir,
@ -311,7 +393,8 @@ mod app {
toggle_leds(curr_dir.next().unwrap()); toggle_leds(curr_dir.next().unwrap());
} }
} }
Systick::delay(BLINK_FREQ_MS.millis()).await; let current_blink_freq = cx.shared.blink_freq.lock(|current| *current);
Systick::delay(current_blink_freq).await;
} }
} }
@ -386,18 +469,18 @@ mod app {
#[task( #[task(
local = [ local = [
stamp_buf: [u8; 7] = [0; 7], verif_reporter,
decode_buf: [u8; MAX_TC_LEN] = [0; MAX_TC_LEN], decode_buf: [u8; MAX_TC_LEN] = [0; MAX_TC_LEN],
src_data_buf: [u8; MAX_TM_LEN] = [0; MAX_TM_LEN], src_data_buf: [u8; MAX_TM_LEN] = [0; MAX_TM_LEN],
verif_reporter timestamp: [u8; 7] = [0; 7],
], ],
shared = [blink_freq]
)] )]
async fn serial_rx_handler( async fn serial_rx_handler(
cx: serial_rx_handler::Context, mut cx: serial_rx_handler::Context,
received_packet: Vec<u8, MAX_TC_LEN>, received_packet: Vec<u8, MAX_TC_LEN>,
) { ) {
defmt::info!("running rx handler"); cx.local.timestamp[0] = P_FIELD_BASE;
cx.local.stamp_buf[0] = P_FIELD_BASE;
defmt::info!("Received packet with {} bytes", received_packet.len()); defmt::info!("Received packet with {} bytes", received_packet.len());
let decode_buf = cx.local.decode_buf; let decode_buf = cx.local.decode_buf;
let packet = received_packet.as_slice(); let packet = received_packet.as_slice();
@ -417,18 +500,49 @@ mod app {
Ok(len) => { Ok(len) => {
defmt::info!("Decoded packet length: {}", len); defmt::info!("Decoded packet length: {}", len);
let pus_tc = PusTcReader::new(decode_buf); let pus_tc = PusTcReader::new(decode_buf);
let verif_reporter = cx.local.verif_reporter;
match pus_tc { match pus_tc {
Ok((tc, tc_len)) => handle_tc( Ok((tc, _tc_len)) => {
tc, match convert_pus_tc_to_request(
tc_len, &tc,
verif_reporter, cx.local.verif_reporter,
cx.local.src_data_buf, cx.local.src_data_buf,
cx.local.stamp_buf, cx.local.timestamp,
), ) {
Err(_e) => { Ok(request_with_token) => {
// TODO: Print error after API rework. let started_token = handle_start_verification(
defmt::warn!("Error unpacking PUS TC"); request_with_token.token,
cx.local.verif_reporter,
cx.local.src_data_buf,
cx.local.timestamp,
);
match request_with_token.request {
Request::Ping => {
handle_ping_request(cx.local.timestamp);
}
Request::ChangeBlinkFrequency(new_freq_ms) => {
defmt::info!("Received blink frequency change request with new frequncy {}", new_freq_ms);
cx.shared.blink_freq.lock(|blink_freq| {
*blink_freq =
MillisDurationU32::from_ticks(new_freq_ms);
});
}
}
handle_completion_verification(
started_token,
cx.local.verif_reporter,
cx.local.src_data_buf,
cx.local.timestamp,
);
}
Err(e) => {
// TODO: Error handling: Send verification failure based on request error.
defmt::warn!("request error {}", e);
}
}
}
Err(e) => {
defmt::warn!("Error unpacking PUS TC: {}", e);
} }
} }
} }
@ -438,78 +552,12 @@ mod app {
} }
} }
fn handle_tc( fn handle_ping_request(timestamp: &[u8]) {
tc: PusTcReader,
tc_len: usize,
verif_reporter: &mut VerificationReporterCore,
src_data_buf: &mut [u8; MAX_TM_LEN],
stamp_buf: &[u8; 7],
) {
defmt::info!(
"Found PUS TC [{},{}] with length {}",
tc.service(),
tc.subservice(),
tc_len
);
let token = verif_reporter.add_tc(&tc);
if tc.apid() != PUS_APID {
defmt::warn!("Received tc with unknown APID {}", tc.apid());
let sendable = verif_reporter
.acceptance_failure(
src_data_buf,
token,
SEQ_COUNT_PROVIDER.get(),
0,
FailParams::new(stamp_buf, &EcssEnumU16::new(0), &[]),
)
.unwrap();
let sender = TmSender::new(TmPacket::new());
if let Err(_e) = verif_reporter.send_acceptance_failure(sendable, &sender) {
defmt::warn!("Sending acceptance failure failed");
};
return;
}
let sendable = verif_reporter
.acceptance_success(src_data_buf, token, SEQ_COUNT_PROVIDER.get(), 0, stamp_buf)
.unwrap();
let sender = TmSender::new(TmPacket::new());
let accepted_token = match verif_reporter.send_acceptance_success(sendable, &sender) {
Ok(token) => token,
Err(_e) => {
// TODO: Print error as soon as EcssTmtcError has Format attr.. or rework API.
defmt::warn!("Sending acceptance success failed");
return;
}
};
if tc.service() == 17 {
if tc.subservice() == 1 {
let sendable = verif_reporter
.start_success(
src_data_buf,
accepted_token,
SEQ_COUNT_PROVIDER.get(),
0,
stamp_buf,
)
.unwrap();
// let mem_block = poolmod::TM::alloc().unwrap().init([0u8; MAX_TM_LEN]);
let sender = TmSender::new(TmPacket::new());
let started_token = match verif_reporter.send_start_success(sendable, &sender) {
Ok(token) => token,
Err(_e) => {
// TODO: Print error as soon as EcssTmtcError has Format attr.. or rework API.
defmt::warn!("Sending acceptance success failed");
return;
}
};
defmt::info!("Received PUS ping telecommand, sending ping reply TM[17,2]"); defmt::info!("Received PUS ping telecommand, sending ping reply TM[17,2]");
let mut sp_header = let sp_header =
SpHeader::tc_unseg(PUS_APID, SEQ_COUNT_PROVIDER.get(), 0).unwrap(); SpHeader::new_for_unseg_tc(PUS_APID, SEQ_COUNT_PROVIDER.get_and_increment(), 0);
let sec_header = PusTmSecondaryHeader::new_simple(17, 2, stamp_buf); let sec_header = PusTmSecondaryHeader::new_simple(17, 2, timestamp);
let ping_reply = PusTmCreator::new(&mut sp_header, sec_header, &[], true); let ping_reply = PusTmCreator::new(sp_header, sec_header, &[], true);
let mut tm_packet = TmPacket::new(); let mut tm_packet = TmPacket::new();
tm_packet tm_packet
.resize(ping_reply.len_written(), 0) .resize(ping_reply.len_written(), 0)
@ -519,23 +567,49 @@ mod app {
defmt::warn!("TC queue full"); defmt::warn!("TC queue full");
return; return;
} }
SEQ_COUNT_PROVIDER.increment(); }
let sendable = verif_reporter
fn handle_start_verification(
accepted_token: VerificationToken<TcStateAccepted>,
verif_reporter: &mut VerificationReportCreator,
src_data_buf: &mut [u8],
timestamp: &[u8],
) -> VerificationToken<TcStateStarted> {
let (tm_creator, started_token) = verif_reporter
.start_success(
src_data_buf,
accepted_token,
SEQ_COUNT_PROVIDER.get(),
0,
&timestamp,
)
.unwrap();
let result = send_tm(tm_creator);
if let Err(e) = result {
handle_tm_send_error(e);
}
started_token
}
fn handle_completion_verification(
started_token: VerificationToken<TcStateStarted>,
verif_reporter: &mut VerificationReportCreator,
src_data_buf: &mut [u8],
timestamp: &[u8],
) {
let result = send_tm(
verif_reporter
.completion_success( .completion_success(
src_data_buf, src_data_buf,
started_token, started_token,
SEQ_COUNT_PROVIDER.get(), SEQ_COUNT_PROVIDER.get(),
0, 0,
stamp_buf, timestamp,
) )
.unwrap(); .unwrap(),
let sender = TmSender::new(TmPacket::new()); );
if let Err(_e) = verif_reporter.send_step_or_completion_success(sendable, &sender) { if let Err(e) = result {
defmt::warn!("Sending completion success failed"); handle_tm_send_error(e);
}
} else {
// TODO: Invalid subservice
}
} }
} }

View File

@ -18,9 +18,7 @@ default-features = false
optional = true optional = true
[dependencies.spacepackets] [dependencies.spacepackets]
git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git"
version = "0.11.0-rc.2" version = "0.11.0-rc.2"
branch = "main"
default-features = false default-features = false
[features] [features]

View File

@ -71,9 +71,8 @@ features = ["all"]
optional = true optional = true
[dependencies.spacepackets] [dependencies.spacepackets]
git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git" # git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git"
version = "0.11.0-rc.2" version = "0.11.0-rc.2"
branch = "main"
default-features = false default-features = false
[dependencies.cobs] [dependencies.cobs]
@ -117,6 +116,7 @@ alloc = [
serde = ["dep:serde", "spacepackets/serde", "satrs-shared/serde"] serde = ["dep:serde", "spacepackets/serde", "satrs-shared/serde"]
crossbeam = ["crossbeam-channel"] crossbeam = ["crossbeam-channel"]
heapless = ["dep:heapless"] heapless = ["dep:heapless"]
defmt = ["spacepackets/defmt"]
test_util = [] test_util = []
doc-images = [] doc-images = []

View File

@ -1,12 +1,10 @@
use crate::pus::{source_buffer_large_enough, EcssTmtcError}; use crate::pus::source_buffer_large_enough;
use spacepackets::ecss::tm::PusTmCreator; use spacepackets::ecss::tm::PusTmCreator;
use spacepackets::ecss::tm::PusTmSecondaryHeader; use spacepackets::ecss::tm::PusTmSecondaryHeader;
use spacepackets::ecss::{EcssEnumeration, PusError}; use spacepackets::ecss::EcssEnumeration;
use spacepackets::ByteConversionError; use spacepackets::ByteConversionError;
use spacepackets::{SpHeader, MAX_APID}; use spacepackets::{SpHeader, MAX_APID};
use crate::pus::EcssTmSenderCore;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
pub use alloc_mod::*; pub use alloc_mod::*;
@ -134,10 +132,12 @@ impl EventReportCreator {
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
mod alloc_mod { mod alloc_mod {
use super::*; use super::*;
use crate::pus::{EcssTmSenderCore, EcssTmtcError};
use crate::ComponentId; use crate::ComponentId;
use alloc::vec; use alloc::vec;
use alloc::vec::Vec; use alloc::vec::Vec;
use core::cell::RefCell; use core::cell::RefCell;
use spacepackets::ecss::PusError;
pub trait EventTmHookProvider { pub trait EventTmHookProvider {
fn modify_tm(&self, tm: &mut PusTmCreator); fn modify_tm(&self, tm: &mut PusTmCreator);
@ -268,8 +268,9 @@ mod tests {
use crate::events::{EventU32, Severity}; use crate::events::{EventU32, Severity};
use crate::pus::test_util::TEST_COMPONENT_ID_0; use crate::pus::test_util::TEST_COMPONENT_ID_0;
use crate::pus::tests::CommonTmInfo; use crate::pus::tests::CommonTmInfo;
use crate::pus::{ChannelWithId, PusTmVariant}; use crate::pus::{ChannelWithId, EcssTmSenderCore, EcssTmtcError, PusTmVariant};
use crate::ComponentId; use crate::ComponentId;
use spacepackets::ecss::PusError;
use spacepackets::ByteConversionError; use spacepackets::ByteConversionError;
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::VecDeque; use std::collections::VecDeque;

View File

@ -92,7 +92,7 @@ use delegate::delegate;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use spacepackets::ecss::tc::IsPusTelecommand; use spacepackets::ecss::tc::IsPusTelecommand;
use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader}; use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader};
use spacepackets::ecss::{EcssEnumeration, PusError}; use spacepackets::ecss::EcssEnumeration;
use spacepackets::{ByteConversionError, CcsdsPacket, PacketId, PacketSequenceCtrl}; use spacepackets::{ByteConversionError, CcsdsPacket, PacketId, PacketSequenceCtrl};
use spacepackets::{SpHeader, MAX_APID}; use spacepackets::{SpHeader, MAX_APID};
@ -883,6 +883,8 @@ impl VerificationReportCreator {
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
pub mod alloc_mod { pub mod alloc_mod {
use spacepackets::ecss::PusError;
use super::*; use super::*;
use crate::{pus::PusTmVariant, ComponentId}; use crate::{pus::PusTmVariant, ComponentId};
use core::cell::RefCell; use core::cell::RefCell;