Compare commits
1 Commits
main
...
ccsds-sche
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7b8a8c1d1
|
@@ -6,7 +6,6 @@ members = [
|
||||
"satrs-example",
|
||||
"satrs-minisim",
|
||||
"satrs-shared",
|
||||
"embedded-examples/embedded-client",
|
||||
]
|
||||
|
||||
exclude = [
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
[package]
|
||||
name = "embedded-client"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
serialport = "4"
|
||||
toml = "0.9"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
satrs-stm32f3-disco-rtic = { path = "../stm32f3-disco-rtic" }
|
||||
spacepackets = { git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git", version = "0.17" }
|
||||
tmtc-utils = { git = "https://egit.irs.uni-stuttgart.de/rust/tmtc-utils.git", version = "0.1" }
|
||||
postcard = { version = "1", features = ["alloc"] }
|
||||
cobs = "0.5"
|
||||
fern = "0.7"
|
||||
humantime = "2"
|
||||
log = "0.4"
|
||||
@@ -1,2 +0,0 @@
|
||||
[interface]
|
||||
serial_port = "/dev/ttyUSB0"
|
||||
@@ -1,107 +0,0 @@
|
||||
use std::{
|
||||
fs::File,
|
||||
io::Read,
|
||||
path::Path,
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
|
||||
use clap::Parser;
|
||||
use cobs::CobsDecoderOwned;
|
||||
use satrs_stm32f3_disco_rtic::Request;
|
||||
use spacepackets::{CcsdsPacketCreatorOwned, CcsdsPacketReader, SpHeader};
|
||||
use tmtc_utils::transport::{PacketTransport, serial::PacketTransportSerialCobs};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
struct Cli {
|
||||
#[arg(short, long)]
|
||||
ping: bool,
|
||||
|
||||
/// Set frequency in milliseconds.
|
||||
#[arg(short, long)]
|
||||
set_led_frequency: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
struct Config {
|
||||
interface: Interface,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
struct Interface {
|
||||
serial_port: String,
|
||||
}
|
||||
|
||||
fn setup_logger() -> Result<(), fern::InitError> {
|
||||
fern::Dispatch::new()
|
||||
.format(|out, message, record| {
|
||||
out.finish(format_args!(
|
||||
"[{} {} {}] {}",
|
||||
humantime::format_rfc3339_seconds(SystemTime::now()),
|
||||
record.level(),
|
||||
record.target(),
|
||||
message
|
||||
))
|
||||
})
|
||||
.level(log::LevelFilter::Debug)
|
||||
.chain(std::io::stdout())
|
||||
.chain(fern::log_file("output.log")?)
|
||||
.apply()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
setup_logger().expect("failed to initialize logger");
|
||||
println!("sat-rs embedded examples TMTC client");
|
||||
|
||||
let cli = Cli::parse();
|
||||
let mut config_file =
|
||||
File::open(Path::new("config.toml")).expect("opening config.toml file failed");
|
||||
let mut toml_str = String::new();
|
||||
config_file
|
||||
.read_to_string(&mut toml_str)
|
||||
.expect("reading config.toml file failed");
|
||||
let config: Config = toml::from_str(&toml_str).expect("parsing config.toml file failed");
|
||||
println!("Connecting to serial port {}", config.interface.serial_port);
|
||||
|
||||
let serial = serialport::new(config.interface.serial_port, 115200)
|
||||
.open()
|
||||
.expect("opening serial port failed");
|
||||
let mut transport = PacketTransportSerialCobs::new(serial, CobsDecoderOwned::new(1024));
|
||||
|
||||
if cli.ping {
|
||||
let request = Request::Ping;
|
||||
let tc = create_stm32f3_tc(&request);
|
||||
log::info!(
|
||||
"Sending ping request with TC ID: {:#010x}",
|
||||
tc.ccsds_packet_id_and_psc().raw()
|
||||
);
|
||||
transport.send(&tc.to_vec()).unwrap();
|
||||
}
|
||||
|
||||
if let Some(freq_ms) = cli.set_led_frequency {
|
||||
let request = Request::ChangeBlinkFrequency(Duration::from_millis(freq_ms as u64));
|
||||
let tc = create_stm32f3_tc(&request);
|
||||
log::info!(
|
||||
"Sending change blink frequency request {:?} with TC ID: {:#010x}",
|
||||
request,
|
||||
tc.ccsds_packet_id_and_psc().raw()
|
||||
);
|
||||
transport.send(&tc.to_vec()).unwrap();
|
||||
}
|
||||
|
||||
log::info!("Waiting for response...");
|
||||
loop {
|
||||
transport
|
||||
.receive(|packet: &[u8]| {
|
||||
let reader = CcsdsPacketReader::new_with_checksum(packet);
|
||||
log::info!("Received packet: {:?}", reader);
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn create_stm32f3_tc(request: &Request) -> CcsdsPacketCreatorOwned {
|
||||
let req_raw = postcard::to_allocvec(&request).unwrap();
|
||||
let sp_header = SpHeader::new_from_apid(satrs_stm32f3_disco_rtic::APID);
|
||||
CcsdsPacketCreatorOwned::new_tc_with_checksum(sp_header, &req_raw).unwrap()
|
||||
}
|
||||
@@ -34,4 +34,4 @@ rustflags = [
|
||||
target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)
|
||||
|
||||
[env]
|
||||
DEFMT_LOG = "info"
|
||||
DEFMT_LOG = "info"
|
||||
@@ -1,4 +1,4 @@
|
||||
/target
|
||||
/itm.txt
|
||||
/.cargo/config.toml
|
||||
/.cargo/config*
|
||||
/.vscode
|
||||
|
||||
1202
embedded-examples/stm32f3-disco-rtic/Cargo.lock
generated
1202
embedded-examples/stm32f3-disco-rtic/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -9,33 +9,49 @@ default-run = "satrs-stm32f3-disco-rtic"
|
||||
[dependencies]
|
||||
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
|
||||
cortex-m-rt = "0.7"
|
||||
defmt = "1"
|
||||
defmt-rtt = { version = "1" }
|
||||
panic-probe = { version = "1", features = ["print-defmt"] }
|
||||
embedded-hal = "1"
|
||||
defmt = "0.3"
|
||||
defmt-brtt = { version = "0.1", default-features = false, features = ["rtt"] }
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
embedded-hal = "0.2.7"
|
||||
cortex-m-semihosting = "0.5.0"
|
||||
embassy-stm32 = { version = "0.4", features = ["defmt", "stm32f303vc", "unstable-pac"] }
|
||||
enumset = "1"
|
||||
heapless = "0.9"
|
||||
spacepackets = { version = "0.17", git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git", default-features = false, features = ["defmt", "serde"] }
|
||||
static_cell = "2"
|
||||
cobs = { version = "0.5", default-features = false, features = ["defmt"] }
|
||||
postcard = { version = "1" }
|
||||
arbitrary-int = "2"
|
||||
thiserror = { version = "2", default-features = false }
|
||||
serde = { version = "1", default-features = false, features = ["derive"] }
|
||||
heapless = "0.8"
|
||||
|
||||
rtic = { version = "2", features = ["thumbv7-backend"] }
|
||||
rtic-sync = { version = "1" }
|
||||
rtic-monotonics = { version = "2", features = ["cortex-m-systick"] }
|
||||
[dependencies.rtic]
|
||||
version = "2"
|
||||
features = ["thumbv7-backend"]
|
||||
|
||||
#[dependencies.satrs]
|
||||
# path = "../../satrs"
|
||||
#default-features = false
|
||||
# features = ["defmt"]
|
||||
[dependencies.rtic-monotonics]
|
||||
version = "2"
|
||||
features = ["cortex-m-systick"]
|
||||
|
||||
[dependencies.cobs]
|
||||
version = "0.3"
|
||||
default-features = false
|
||||
|
||||
[dependencies.stm32f3xx-hal]
|
||||
git = "https://github.com/robamu/stm32f3xx-hal"
|
||||
version = "0.11.0-alpha.0"
|
||||
features = ["stm32f303xc", "rt", "enumset"]
|
||||
branch = "complete-dma-update"
|
||||
# Can be used in workspace to develop and update HAL
|
||||
# path = "../stm32f3xx-hal"
|
||||
|
||||
[dependencies.stm32f3-discovery]
|
||||
git = "https://github.com/robamu/stm32f3-discovery"
|
||||
version = "0.8.0-alpha.0"
|
||||
branch = "complete-dma-update-hal"
|
||||
# Can be used in workspace to develop and update BSP
|
||||
# path = "../stm32f3-discovery"
|
||||
|
||||
[dependencies.satrs]
|
||||
# path = "satrs"
|
||||
version = "0.2"
|
||||
default-features = false
|
||||
features = ["defmt"]
|
||||
|
||||
[dev-dependencies]
|
||||
defmt-test = "0.4"
|
||||
defmt-test = "0.3"
|
||||
|
||||
# cargo test
|
||||
[profile.test]
|
||||
|
||||
38601
embedded-examples/stm32f3-disco-rtic/STM32F303.svd
Normal file
38601
embedded-examples/stm32f3-disco-rtic/STM32F303.svd
Normal file
File diff suppressed because it is too large
Load Diff
10
embedded-examples/stm32f3-disco-rtic/legacy/jlink.gdb
Normal file
10
embedded-examples/stm32f3-disco-rtic/legacy/jlink.gdb
Normal file
@@ -0,0 +1,10 @@
|
||||
target extended-remote localhost:2331
|
||||
|
||||
monitor reset
|
||||
|
||||
# *try* to stop at the user entry point (it might be gone due to inlining)
|
||||
break main
|
||||
|
||||
load
|
||||
|
||||
continue
|
||||
12
embedded-examples/stm32f3-disco-rtic/legacy/openocd.cfg
Normal file
12
embedded-examples/stm32f3-disco-rtic/legacy/openocd.cfg
Normal file
@@ -0,0 +1,12 @@
|
||||
# Sample OpenOCD configuration for the STM32F3DISCOVERY development board
|
||||
|
||||
# Depending on the hardware revision you got you'll have to pick ONE of these
|
||||
# interfaces. At any time only one interface should be commented out.
|
||||
|
||||
# Revision C (newer revision)
|
||||
source [find interface/stlink.cfg]
|
||||
|
||||
# Revision A and B (older revisions)
|
||||
# source [find interface/stlink-v2.cfg]
|
||||
|
||||
source [find target/stm32f3x.cfg]
|
||||
42
embedded-examples/stm32f3-disco-rtic/legacy/openocd.gdb
Normal file
42
embedded-examples/stm32f3-disco-rtic/legacy/openocd.gdb
Normal file
@@ -0,0 +1,42 @@
|
||||
target extended-remote :3333
|
||||
|
||||
# print demangled symbols
|
||||
set print asm-demangle on
|
||||
|
||||
# set backtrace limit to not have infinite backtrace loops
|
||||
set backtrace limit 32
|
||||
|
||||
# detect unhandled exceptions, hard faults and panics
|
||||
break DefaultHandler
|
||||
break HardFault
|
||||
break rust_begin_unwind
|
||||
# # run the next few lines so the panic message is printed immediately
|
||||
# # the number needs to be adjusted for your panic handler
|
||||
# commands $bpnum
|
||||
# next 4
|
||||
# end
|
||||
|
||||
# *try* to stop at the user entry point (it might be gone due to inlining)
|
||||
break main
|
||||
|
||||
# monitor arm semihosting enable
|
||||
|
||||
# # send captured ITM to the file itm.fifo
|
||||
# # (the microcontroller SWO pin must be connected to the programmer SWO pin)
|
||||
# # 8000000 must match the core clock frequency
|
||||
# # 2000000 is the frequency of the SWO pin. This was added for newer
|
||||
# openocd versions like v0.12.0.
|
||||
# monitor tpiu config internal itm.txt uart off 8000000 2000000
|
||||
|
||||
# # OR: make the microcontroller SWO pin output compatible with UART (8N1)
|
||||
# # 8000000 must match the core clock frequency
|
||||
# # 2000000 is the frequency of the SWO pin
|
||||
# monitor tpiu config external uart off 8000000 2000000
|
||||
|
||||
# # enable ITM port 0
|
||||
# monitor itm port 0 on
|
||||
|
||||
load
|
||||
|
||||
# start the process but immediately halt the processor
|
||||
stepi
|
||||
8
embedded-examples/stm32f3-disco-rtic/pyclient/.gitignore
vendored
Normal file
8
embedded-examples/stm32f3-disco-rtic/pyclient/.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/venv
|
||||
/.tmtc-history.txt
|
||||
/log
|
||||
/.idea/*
|
||||
!/.idea/runConfigurations
|
||||
|
||||
/seqcnt.txt
|
||||
/tmtc_conf.json
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"com_if": "serial_cobs",
|
||||
"serial_baudrate": 115200
|
||||
}
|
||||
305
embedded-examples/stm32f3-disco-rtic/pyclient/main.py
Executable file
305
embedded-examples/stm32f3-disco-rtic/pyclient/main.py
Executable file
@@ -0,0 +1,305 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Example client for the sat-rs example application"""
|
||||
import struct
|
||||
import logging
|
||||
import sys
|
||||
import time
|
||||
from typing import Any, Optional, cast
|
||||
from prompt_toolkit.history import FileHistory, History
|
||||
from spacepackets.ecss.tm import CdsShortTimestamp
|
||||
|
||||
import tmtccmd
|
||||
from spacepackets.ecss import PusTelemetry, PusTelecommand, PusTm, PusVerificator
|
||||
from spacepackets.ecss.pus_17_test import Service17Tm
|
||||
from spacepackets.ecss.pus_1_verification import UnpackParams, Service1Tm
|
||||
|
||||
from tmtccmd import TcHandlerBase, ProcedureParamsWrapper
|
||||
from tmtccmd.core.base import BackendRequest
|
||||
from tmtccmd.core.ccsds_backend import QueueWrapper
|
||||
from tmtccmd.logging import add_colorlog_console_logger
|
||||
from tmtccmd.pus import VerificationWrapper
|
||||
from tmtccmd.tmtc import CcsdsTmHandler, SpecificApidHandlerBase
|
||||
from tmtccmd.com import ComInterface
|
||||
from tmtccmd.config import (
|
||||
CmdTreeNode,
|
||||
default_json_path,
|
||||
SetupParams,
|
||||
HookBase,
|
||||
params_to_procedure_conversion,
|
||||
)
|
||||
from tmtccmd.config.com import SerialCfgWrapper
|
||||
from tmtccmd.config import PreArgsParsingWrapper, SetupWrapper
|
||||
from tmtccmd.logging.pus import (
|
||||
RegularTmtcLogWrapper,
|
||||
RawTmtcTimedLogWrapper,
|
||||
TimedLogWhen,
|
||||
)
|
||||
from tmtccmd.tmtc import (
|
||||
TcQueueEntryType,
|
||||
ProcedureWrapper,
|
||||
TcProcedureType,
|
||||
FeedWrapper,
|
||||
SendCbParams,
|
||||
DefaultPusQueueHelper,
|
||||
)
|
||||
from tmtccmd.pus.s5_fsfw_event import Service5Tm
|
||||
from spacepackets.seqcount import FileSeqCountProvider, PusFileSeqCountProvider
|
||||
from tmtccmd.util.obj_id import ObjectIdDictT
|
||||
|
||||
_LOGGER = logging.getLogger()
|
||||
|
||||
EXAMPLE_PUS_APID = 0x02
|
||||
|
||||
|
||||
class SatRsConfigHook(HookBase):
|
||||
def __init__(self, json_cfg_path: str):
|
||||
super().__init__(json_cfg_path)
|
||||
|
||||
def get_communication_interface(self, com_if_key: str) -> Optional[ComInterface]:
|
||||
from tmtccmd.config.com import (
|
||||
create_com_interface_default,
|
||||
create_com_interface_cfg_default,
|
||||
)
|
||||
|
||||
assert self.cfg_path is not None
|
||||
cfg = create_com_interface_cfg_default(
|
||||
com_if_key=com_if_key,
|
||||
json_cfg_path=self.cfg_path,
|
||||
space_packet_ids=None,
|
||||
)
|
||||
if cfg is None:
|
||||
raise ValueError(
|
||||
f"No valid configuration could be retrieved for the COM IF with key {com_if_key}"
|
||||
)
|
||||
if cfg.com_if_key == "serial_cobs":
|
||||
cfg = cast(SerialCfgWrapper, cfg)
|
||||
cfg.serial_cfg.serial_timeout = 0.5
|
||||
return create_com_interface_default(cfg)
|
||||
|
||||
def get_command_definitions(self) -> CmdTreeNode:
|
||||
"""This function should return the root node of the command definition tree."""
|
||||
return create_cmd_definition_tree()
|
||||
|
||||
def get_cmd_history(self) -> Optional[History]:
|
||||
"""Optionlly return a history class for the past command paths which will be used
|
||||
when prompting a command path from the user in CLI mode."""
|
||||
return FileHistory(".tmtc-history.txt")
|
||||
|
||||
def get_object_ids(self) -> ObjectIdDictT:
|
||||
from tmtccmd.config.objects import get_core_object_ids
|
||||
|
||||
return get_core_object_ids()
|
||||
|
||||
|
||||
def create_cmd_definition_tree() -> CmdTreeNode:
|
||||
root_node = CmdTreeNode.root_node()
|
||||
root_node.add_child(CmdTreeNode("ping", "Send PUS ping TC"))
|
||||
root_node.add_child(CmdTreeNode("change_blink_freq", "Change blink frequency"))
|
||||
return root_node
|
||||
|
||||
|
||||
class PusHandler(SpecificApidHandlerBase):
|
||||
def __init__(
|
||||
self,
|
||||
file_logger: logging.Logger,
|
||||
verif_wrapper: VerificationWrapper,
|
||||
raw_logger: RawTmtcTimedLogWrapper,
|
||||
):
|
||||
super().__init__(EXAMPLE_PUS_APID, None)
|
||||
self.file_logger = file_logger
|
||||
self.raw_logger = raw_logger
|
||||
self.verif_wrapper = verif_wrapper
|
||||
|
||||
def handle_tm(self, packet: bytes, _user_args: Any):
|
||||
try:
|
||||
pus_tm = PusTm.unpack(
|
||||
packet, timestamp_len=CdsShortTimestamp.TIMESTAMP_SIZE
|
||||
)
|
||||
except ValueError as e:
|
||||
_LOGGER.warning("Could not generate PUS TM object from raw data")
|
||||
_LOGGER.warning(f"Raw Packet: [{packet.hex(sep=',')}], REPR: {packet!r}")
|
||||
raise e
|
||||
service = pus_tm.service
|
||||
tm_packet = None
|
||||
if service == 1:
|
||||
tm_packet = Service1Tm.unpack(
|
||||
data=packet, params=UnpackParams(CdsShortTimestamp.TIMESTAMP_SIZE, 1, 2)
|
||||
)
|
||||
res = self.verif_wrapper.add_tm(tm_packet)
|
||||
if res is None:
|
||||
_LOGGER.info(
|
||||
f"Received Verification TM[{tm_packet.service}, {tm_packet.subservice}] "
|
||||
f"with Request ID {tm_packet.tc_req_id.as_u32():#08x}"
|
||||
)
|
||||
_LOGGER.warning(
|
||||
f"No matching telecommand found for {tm_packet.tc_req_id}"
|
||||
)
|
||||
else:
|
||||
self.verif_wrapper.log_to_console(tm_packet, res)
|
||||
self.verif_wrapper.log_to_file(tm_packet, res)
|
||||
if service == 3:
|
||||
_LOGGER.info("No handling for HK packets implemented")
|
||||
_LOGGER.info(f"Raw packet: 0x[{packet.hex(sep=',')}]")
|
||||
pus_tm = PusTelemetry.unpack(packet, CdsShortTimestamp.TIMESTAMP_SIZE)
|
||||
if pus_tm.subservice == 25:
|
||||
if len(pus_tm.source_data) < 8:
|
||||
raise ValueError("No addressable ID in HK packet")
|
||||
json_str = pus_tm.source_data[8:]
|
||||
_LOGGER.info("received JSON string: " + json_str.decode("utf-8"))
|
||||
if service == 5:
|
||||
tm_packet = Service5Tm.unpack(packet, CdsShortTimestamp.TIMESTAMP_SIZE)
|
||||
if service == 17:
|
||||
tm_packet = Service17Tm.unpack(packet, CdsShortTimestamp.TIMESTAMP_SIZE)
|
||||
if tm_packet.subservice == 2:
|
||||
_LOGGER.info("Received Ping Reply TM[17,2]")
|
||||
else:
|
||||
_LOGGER.info(
|
||||
f"Received Test Packet with unknown subservice {tm_packet.subservice}"
|
||||
)
|
||||
if tm_packet is None:
|
||||
_LOGGER.info(
|
||||
f"The service {service} is not implemented in Telemetry Factory"
|
||||
)
|
||||
tm_packet = PusTelemetry.unpack(packet, CdsShortTimestamp.TIMESTAMP_SIZE)
|
||||
self.raw_logger.log_tm(pus_tm)
|
||||
|
||||
|
||||
def make_addressable_id(target_id: int, unique_id: int) -> bytes:
|
||||
byte_string = bytearray(struct.pack("!I", target_id))
|
||||
byte_string.extend(struct.pack("!I", unique_id))
|
||||
return byte_string
|
||||
|
||||
|
||||
class TcHandler(TcHandlerBase):
|
||||
def __init__(
|
||||
self,
|
||||
seq_count_provider: FileSeqCountProvider,
|
||||
verif_wrapper: VerificationWrapper,
|
||||
):
|
||||
super(TcHandler, self).__init__()
|
||||
self.seq_count_provider = seq_count_provider
|
||||
self.verif_wrapper = verif_wrapper
|
||||
self.queue_helper = DefaultPusQueueHelper(
|
||||
queue_wrapper=QueueWrapper.empty(),
|
||||
tc_sched_timestamp_len=7,
|
||||
seq_cnt_provider=seq_count_provider,
|
||||
pus_verificator=verif_wrapper.pus_verificator,
|
||||
default_pus_apid=EXAMPLE_PUS_APID,
|
||||
)
|
||||
|
||||
def send_cb(self, send_params: SendCbParams):
|
||||
entry_helper = send_params.entry
|
||||
if entry_helper.is_tc:
|
||||
if entry_helper.entry_type == TcQueueEntryType.PUS_TC:
|
||||
pus_tc_wrapper = entry_helper.to_pus_tc_entry()
|
||||
pus_tc_wrapper.pus_tc.seq_count = (
|
||||
self.seq_count_provider.get_and_increment()
|
||||
)
|
||||
self.verif_wrapper.add_tc(pus_tc_wrapper.pus_tc)
|
||||
raw_tc = pus_tc_wrapper.pus_tc.pack()
|
||||
_LOGGER.info(f"Sending {pus_tc_wrapper.pus_tc}")
|
||||
send_params.com_if.send(raw_tc)
|
||||
elif entry_helper.entry_type == TcQueueEntryType.LOG:
|
||||
log_entry = entry_helper.to_log_entry()
|
||||
_LOGGER.info(log_entry.log_str)
|
||||
|
||||
def queue_finished_cb(self, info: ProcedureWrapper):
|
||||
if info.proc_type == TcProcedureType.TREE_COMMANDING:
|
||||
def_proc = info.to_tree_commanding_procedure()
|
||||
_LOGGER.info(f"Queue handling finished for command {def_proc.cmd_path}")
|
||||
|
||||
def feed_cb(self, info: ProcedureWrapper, wrapper: FeedWrapper):
|
||||
q = self.queue_helper
|
||||
q.queue_wrapper = wrapper.queue_wrapper
|
||||
if info.proc_type == TcProcedureType.TREE_COMMANDING:
|
||||
def_proc = info.to_tree_commanding_procedure()
|
||||
cmd_path = def_proc.cmd_path
|
||||
if cmd_path == "/ping":
|
||||
q.add_log_cmd("Sending PUS ping telecommand")
|
||||
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():
|
||||
add_colorlog_console_logger(_LOGGER)
|
||||
tmtccmd.init_printout(False)
|
||||
hook_obj = SatRsConfigHook(json_cfg_path=default_json_path())
|
||||
parser_wrapper = PreArgsParsingWrapper()
|
||||
parser_wrapper.create_default_parent_parser()
|
||||
parser_wrapper.create_default_parser()
|
||||
parser_wrapper.add_def_proc_args()
|
||||
params = SetupParams()
|
||||
post_args_wrapper = parser_wrapper.parse(hook_obj, params)
|
||||
proc_wrapper = ProcedureParamsWrapper()
|
||||
if post_args_wrapper.use_gui:
|
||||
post_args_wrapper.set_params_without_prompts(proc_wrapper)
|
||||
else:
|
||||
post_args_wrapper.set_params_with_prompts(proc_wrapper)
|
||||
params.apid = EXAMPLE_PUS_APID
|
||||
setup_args = SetupWrapper(
|
||||
hook_obj=hook_obj, setup_params=params, proc_param_wrapper=proc_wrapper
|
||||
)
|
||||
# Create console logger helper and file loggers
|
||||
tmtc_logger = RegularTmtcLogWrapper()
|
||||
file_logger = tmtc_logger.logger
|
||||
raw_logger = RawTmtcTimedLogWrapper(when=TimedLogWhen.PER_HOUR, interval=1)
|
||||
verificator = PusVerificator()
|
||||
verification_wrapper = VerificationWrapper(verificator, _LOGGER, file_logger)
|
||||
# Create primary TM handler and add it to the CCSDS Packet Handler
|
||||
tm_handler = PusHandler(file_logger, verification_wrapper, raw_logger)
|
||||
ccsds_handler = CcsdsTmHandler(generic_handler=None)
|
||||
ccsds_handler.add_apid_handler(tm_handler)
|
||||
|
||||
# Create TC handler
|
||||
seq_count_provider = PusFileSeqCountProvider()
|
||||
tc_handler = TcHandler(seq_count_provider, verification_wrapper)
|
||||
tmtccmd.setup(setup_args=setup_args)
|
||||
init_proc = params_to_procedure_conversion(setup_args.proc_param_wrapper)
|
||||
tmtc_backend = tmtccmd.create_default_tmtc_backend(
|
||||
setup_wrapper=setup_args,
|
||||
tm_handler=ccsds_handler,
|
||||
tc_handler=tc_handler,
|
||||
init_procedure=init_proc,
|
||||
)
|
||||
tmtccmd.start(tmtc_backend=tmtc_backend, hook_obj=hook_obj)
|
||||
try:
|
||||
while True:
|
||||
state = tmtc_backend.periodic_op(None)
|
||||
if state.request == BackendRequest.TERMINATION_NO_ERROR:
|
||||
sys.exit(0)
|
||||
elif state.request == BackendRequest.DELAY_IDLE:
|
||||
_LOGGER.info("TMTC Client in IDLE mode")
|
||||
time.sleep(3.0)
|
||||
elif state.request == BackendRequest.DELAY_LISTENER:
|
||||
time.sleep(0.8)
|
||||
elif state.request == BackendRequest.DELAY_CUSTOM:
|
||||
if state.next_delay.total_seconds() <= 0.4:
|
||||
time.sleep(state.next_delay.total_seconds())
|
||||
else:
|
||||
time.sleep(0.4)
|
||||
elif state.request == BackendRequest.CALL_NEXT:
|
||||
pass
|
||||
except KeyboardInterrupt:
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,2 @@
|
||||
tmtccmd == 8.0.1
|
||||
# -e git+https://github.com/robamu-org/tmtccmd.git@main#egg=tmtccmd
|
||||
@@ -1,61 +1,76 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
use satrs_stm32f3_disco_rtic as _;
|
||||
|
||||
use panic_probe as _;
|
||||
use rtic::app;
|
||||
use stm32f3_discovery::leds::Leds;
|
||||
use stm32f3_discovery::stm32f3xx_hal::delay::Delay;
|
||||
use stm32f3_discovery::stm32f3xx_hal::{pac, prelude::*};
|
||||
use stm32f3_discovery::switch_hal::{OutputSwitch, ToggleableOutputSwitch};
|
||||
|
||||
#[app(device = embassy_stm32)]
|
||||
mod app {
|
||||
use rtic_monotonics::fugit::ExtU32;
|
||||
use rtic_monotonics::Monotonic as _;
|
||||
use satrs_stm32f3_disco_rtic::{Direction, LedPinSet, Leds};
|
||||
#[cortex_m_rt::entry]
|
||||
fn main() -> ! {
|
||||
defmt::println!("STM32F3 Discovery Blinky");
|
||||
let dp = pac::Peripherals::take().unwrap();
|
||||
let mut rcc = dp.RCC.constrain();
|
||||
let cp = cortex_m::Peripherals::take().unwrap();
|
||||
let mut flash = dp.FLASH.constrain();
|
||||
let clocks = rcc.cfgr.freeze(&mut flash.acr);
|
||||
let mut delay = Delay::new(cp.SYST, clocks);
|
||||
|
||||
rtic_monotonics::systick_monotonic!(Mono, 1000);
|
||||
let mut gpioe = dp.GPIOE.split(&mut rcc.ahb);
|
||||
let mut leds = Leds::new(
|
||||
gpioe.pe8,
|
||||
gpioe.pe9,
|
||||
gpioe.pe10,
|
||||
gpioe.pe11,
|
||||
gpioe.pe12,
|
||||
gpioe.pe13,
|
||||
gpioe.pe14,
|
||||
gpioe.pe15,
|
||||
&mut gpioe.moder,
|
||||
&mut gpioe.otyper,
|
||||
);
|
||||
let delay_ms = 200u16;
|
||||
loop {
|
||||
leds.ld3_n.toggle().ok();
|
||||
delay.delay_ms(delay_ms);
|
||||
leds.ld3_n.toggle().ok();
|
||||
delay.delay_ms(delay_ms);
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
//explicit on/off
|
||||
leds.ld4_nw.on().ok();
|
||||
delay.delay_ms(delay_ms);
|
||||
leds.ld4_nw.off().ok();
|
||||
delay.delay_ms(delay_ms);
|
||||
|
||||
#[local]
|
||||
struct Local {
|
||||
leds: Leds,
|
||||
current_dir: Direction,
|
||||
}
|
||||
leds.ld5_ne.on().ok();
|
||||
delay.delay_ms(delay_ms);
|
||||
leds.ld5_ne.off().ok();
|
||||
delay.delay_ms(delay_ms);
|
||||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local) {
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
leds.ld6_w.on().ok();
|
||||
delay.delay_ms(delay_ms);
|
||||
leds.ld6_w.off().ok();
|
||||
delay.delay_ms(delay_ms);
|
||||
|
||||
defmt::info!("Starting sat-rs demo application for the STM32F3-Discovery using RTICv2");
|
||||
leds.ld7_e.on().ok();
|
||||
delay.delay_ms(delay_ms);
|
||||
leds.ld7_e.off().ok();
|
||||
delay.delay_ms(delay_ms);
|
||||
|
||||
let led_pin_set = LedPinSet {
|
||||
pin_n: p.PE8,
|
||||
pin_ne: p.PE9,
|
||||
pin_e: p.PE10,
|
||||
pin_se: p.PE11,
|
||||
pin_s: p.PE12,
|
||||
pin_sw: p.PE13,
|
||||
pin_w: p.PE14,
|
||||
pin_nw: p.PE15,
|
||||
};
|
||||
let leds = Leds::new(led_pin_set);
|
||||
leds.ld8_sw.on().ok();
|
||||
delay.delay_ms(delay_ms);
|
||||
leds.ld8_sw.off().ok();
|
||||
delay.delay_ms(delay_ms);
|
||||
|
||||
// Initialize the systick interrupt & obtain the token to prove that we did
|
||||
Mono::start(cx.core.SYST, 8_000_000);
|
||||
blinky::spawn().expect("failed to spawn blinky task");
|
||||
(
|
||||
Shared {},
|
||||
Local {
|
||||
leds,
|
||||
current_dir: Direction::North,
|
||||
},
|
||||
)
|
||||
}
|
||||
leds.ld9_se.on().ok();
|
||||
delay.delay_ms(delay_ms);
|
||||
leds.ld9_se.off().ok();
|
||||
delay.delay_ms(delay_ms);
|
||||
|
||||
#[task(local = [leds, current_dir])]
|
||||
async fn blinky(cx: blinky::Context) {
|
||||
loop {
|
||||
cx.local.leds.blink_next(cx.local.current_dir);
|
||||
Mono::delay(200.millis()).await;
|
||||
}
|
||||
leds.ld10_s.on().ok();
|
||||
delay.delay_ms(delay_ms);
|
||||
leds.ld10_s.off().ok();
|
||||
delay.delay_ms(delay_ms);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,190 +1,51 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use arbitrary_int::u11;
|
||||
use core::time::Duration;
|
||||
use embassy_stm32::gpio::Output;
|
||||
use spacepackets::{
|
||||
ccsds_packet_len_for_user_data_len_with_checksum, CcsdsPacketCreationError,
|
||||
CcsdsPacketCreatorWithReservedData, CcsdsPacketIdAndPsc, SpacePacketHeader,
|
||||
};
|
||||
use cortex_m_semihosting::debug;
|
||||
|
||||
pub const APID: u11 = u11::new(0x02);
|
||||
use defmt_brtt as _; // global logger
|
||||
|
||||
#[derive(defmt::Format, serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone, Copy)]
|
||||
pub enum Direction {
|
||||
North,
|
||||
NorthEast,
|
||||
East,
|
||||
SouthEast,
|
||||
South,
|
||||
SouthWest,
|
||||
West,
|
||||
NorthWest,
|
||||
use stm32f3xx_hal as _; // memory layout
|
||||
|
||||
use panic_probe as _;
|
||||
|
||||
// same panicking *behavior* as `panic-probe` but doesn't print a panic message
|
||||
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
|
||||
#[defmt::panic_handler]
|
||||
fn panic() -> ! {
|
||||
cortex_m::asm::udf()
|
||||
}
|
||||
|
||||
impl Direction {
|
||||
pub fn switch_to_next(&mut self) -> (Self, Self) {
|
||||
let curr = *self;
|
||||
*self = match self {
|
||||
Direction::North => Direction::NorthEast,
|
||||
Direction::NorthEast => Direction::East,
|
||||
Direction::East => Direction::SouthEast,
|
||||
Direction::SouthEast => Direction::South,
|
||||
Direction::South => Direction::SouthWest,
|
||||
Direction::SouthWest => Direction::West,
|
||||
Direction::West => Direction::NorthWest,
|
||||
Direction::NorthWest => Direction::North,
|
||||
};
|
||||
(curr, *self)
|
||||
/// Terminates the application and makes a semihosting-capable debug tool exit
|
||||
/// with status code 0.
|
||||
pub fn exit() -> ! {
|
||||
loop {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, defmt::Format, serde::Serialize, serde::Deserialize)]
|
||||
pub enum Request {
|
||||
Ping,
|
||||
ChangeBlinkFrequency(Duration),
|
||||
}
|
||||
|
||||
#[derive(Debug, defmt::Format, serde::Serialize, serde::Deserialize)]
|
||||
pub struct TmHeader {
|
||||
pub tc_packet_id: Option<CcsdsPacketIdAndPsc>,
|
||||
pub uptime_millis: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, defmt::Format, serde::Serialize, serde::Deserialize)]
|
||||
pub enum Response {
|
||||
CommandDone,
|
||||
}
|
||||
|
||||
pub fn tm_size(tm_header: &TmHeader, response: &Response) -> usize {
|
||||
ccsds_packet_len_for_user_data_len_with_checksum(
|
||||
postcard::experimental::serialized_size(tm_header).unwrap()
|
||||
+ postcard::experimental::serialized_size(response).unwrap(),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn create_tm_packet(
|
||||
buf: &mut [u8],
|
||||
sp_header: SpacePacketHeader,
|
||||
tm_header: TmHeader,
|
||||
response: Response,
|
||||
) -> Result<usize, CcsdsPacketCreationError> {
|
||||
let packet_data_size = postcard::experimental::serialized_size(&tm_header).unwrap()
|
||||
+ postcard::experimental::serialized_size(&response).unwrap();
|
||||
let mut creator =
|
||||
CcsdsPacketCreatorWithReservedData::new_tm_with_checksum(sp_header, packet_data_size, buf)?;
|
||||
|
||||
let current_index = postcard::to_slice(&tm_header, creator.packet_data_mut())
|
||||
.unwrap()
|
||||
.len();
|
||||
postcard::to_slice(&response, &mut creator.packet_data_mut()[current_index..]).unwrap();
|
||||
Ok(creator.finish())
|
||||
}
|
||||
|
||||
pub struct Leds {
|
||||
pub north: Output<'static>,
|
||||
pub north_east: Output<'static>,
|
||||
pub east: Output<'static>,
|
||||
pub south_east: Output<'static>,
|
||||
pub south: Output<'static>,
|
||||
pub south_west: Output<'static>,
|
||||
pub west: Output<'static>,
|
||||
pub north_west: Output<'static>,
|
||||
}
|
||||
|
||||
impl Leds {
|
||||
pub fn blink_next(&mut self, current_dir: &mut Direction) {
|
||||
let (prev, curr) = current_dir.switch_to_next();
|
||||
self.set_dir_low(prev);
|
||||
self.set_dir_high(curr);
|
||||
}
|
||||
|
||||
pub fn set_dir(&mut self, dir: Direction, level: embassy_stm32::gpio::Level) {
|
||||
match dir {
|
||||
Direction::North => self.north.set_level(level),
|
||||
Direction::NorthEast => self.north_east.set_level(level),
|
||||
Direction::East => self.east.set_level(level),
|
||||
Direction::SouthEast => self.south_east.set_level(level),
|
||||
Direction::South => self.south.set_level(level),
|
||||
Direction::SouthWest => self.south_west.set_level(level),
|
||||
Direction::West => self.west.set_level(level),
|
||||
Direction::NorthWest => self.north_west.set_level(level),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_dir_low(&mut self, dir: Direction) {
|
||||
self.set_dir(dir, embassy_stm32::gpio::Level::Low);
|
||||
}
|
||||
|
||||
pub fn set_dir_high(&mut self, dir: Direction) {
|
||||
self.set_dir(dir, embassy_stm32::gpio::Level::High);
|
||||
/// Hardfault handler.
|
||||
///
|
||||
/// Terminates the application and makes a semihosting-capable debug tool exit
|
||||
/// with an error. This seems better than the default, which is to spin in a
|
||||
/// loop.
|
||||
#[cortex_m_rt::exception]
|
||||
unsafe fn HardFault(_frame: &cortex_m_rt::ExceptionFrame) -> ! {
|
||||
loop {
|
||||
debug::exit(debug::EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LedPinSet {
|
||||
pub pin_n: embassy_stm32::Peri<'static, embassy_stm32::peripherals::PE8>,
|
||||
pub pin_ne: embassy_stm32::Peri<'static, embassy_stm32::peripherals::PE9>,
|
||||
pub pin_e: embassy_stm32::Peri<'static, embassy_stm32::peripherals::PE10>,
|
||||
pub pin_se: embassy_stm32::Peri<'static, embassy_stm32::peripherals::PE11>,
|
||||
pub pin_s: embassy_stm32::Peri<'static, embassy_stm32::peripherals::PE12>,
|
||||
pub pin_sw: embassy_stm32::Peri<'static, embassy_stm32::peripherals::PE13>,
|
||||
pub pin_w: embassy_stm32::Peri<'static, embassy_stm32::peripherals::PE14>,
|
||||
pub pin_nw: embassy_stm32::Peri<'static, embassy_stm32::peripherals::PE15>,
|
||||
}
|
||||
// defmt-test 0.3.0 has the limitation that this `#[tests]` attribute can only be used
|
||||
// once within a crate. the module can be in any file but there can only be at most
|
||||
// one `#[tests]` module in this library crate
|
||||
#[cfg(test)]
|
||||
#[defmt_test::tests]
|
||||
mod unit_tests {
|
||||
use defmt::assert;
|
||||
|
||||
impl Leds {
|
||||
pub fn new(pin_set: LedPinSet) -> Self {
|
||||
let led_n = Output::new(
|
||||
pin_set.pin_n,
|
||||
embassy_stm32::gpio::Level::Low,
|
||||
embassy_stm32::gpio::Speed::Medium,
|
||||
);
|
||||
let led_ne = Output::new(
|
||||
pin_set.pin_ne,
|
||||
embassy_stm32::gpio::Level::Low,
|
||||
embassy_stm32::gpio::Speed::Medium,
|
||||
);
|
||||
let led_e = Output::new(
|
||||
pin_set.pin_e,
|
||||
embassy_stm32::gpio::Level::Low,
|
||||
embassy_stm32::gpio::Speed::Medium,
|
||||
);
|
||||
let led_se = Output::new(
|
||||
pin_set.pin_se,
|
||||
embassy_stm32::gpio::Level::Low,
|
||||
embassy_stm32::gpio::Speed::Medium,
|
||||
);
|
||||
let led_s = Output::new(
|
||||
pin_set.pin_s,
|
||||
embassy_stm32::gpio::Level::Low,
|
||||
embassy_stm32::gpio::Speed::Medium,
|
||||
);
|
||||
let led_sw = Output::new(
|
||||
pin_set.pin_sw,
|
||||
embassy_stm32::gpio::Level::Low,
|
||||
embassy_stm32::gpio::Speed::Medium,
|
||||
);
|
||||
let led_w = Output::new(
|
||||
pin_set.pin_w,
|
||||
embassy_stm32::gpio::Level::Low,
|
||||
embassy_stm32::gpio::Speed::Medium,
|
||||
);
|
||||
let led_nw = Output::new(
|
||||
pin_set.pin_nw,
|
||||
embassy_stm32::gpio::Level::Low,
|
||||
embassy_stm32::gpio::Speed::Medium,
|
||||
);
|
||||
Self {
|
||||
north: led_n,
|
||||
north_east: led_ne,
|
||||
east: led_e,
|
||||
south_east: led_se,
|
||||
south: led_s,
|
||||
south_west: led_sw,
|
||||
west: led_w,
|
||||
north_west: led_nw,
|
||||
}
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert!(true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,349 +1,682 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
use arbitrary_int::{u11, u14};
|
||||
use cortex_m_semihosting::debug::{self, EXIT_FAILURE, EXIT_SUCCESS};
|
||||
use satrs_stm32f3_disco_rtic::{create_tm_packet, tm_size, CcsdsPacketId, Request, Response};
|
||||
use spacepackets::{CcsdsPacketCreationError, SpHeader};
|
||||
|
||||
use defmt_rtt as _; // global logger
|
||||
|
||||
use panic_probe as _;
|
||||
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
|
||||
use satrs_stm32f3_disco_rtic as _;
|
||||
|
||||
use rtic::app;
|
||||
|
||||
use heapless::{mpmc::Q8, Vec};
|
||||
#[allow(unused_imports)]
|
||||
use rtic_monotonics::fugit::{MillisDurationU32, TimerInstantU32};
|
||||
use rtic_monotonics::systick::prelude::*;
|
||||
|
||||
use crate::app::Mono;
|
||||
use satrs::seq_count::SequenceCountProviderCore;
|
||||
use satrs::spacepackets::{ecss::PusPacket, ecss::WritablePusPacket};
|
||||
use stm32f3xx_hal::dma::dma1;
|
||||
use stm32f3xx_hal::gpio::{PushPull, AF7, PA2, PA3};
|
||||
use stm32f3xx_hal::pac::USART2;
|
||||
use stm32f3xx_hal::serial::{Rx, RxEvent, Serial, SerialDmaRx, SerialDmaTx, Tx, TxEvent};
|
||||
|
||||
const UART_BAUD: u32 = 115200;
|
||||
const DEFAULT_BLINK_FREQ_MS: u32 = 1000;
|
||||
const TX_HANDLER_FREQ_MS: u32 = 20;
|
||||
const MIN_DELAY_BETWEEN_TX_PACKETS_MS: u32 = 5;
|
||||
const MAX_TC_LEN: usize = 128;
|
||||
const MAX_TM_LEN: usize = 128;
|
||||
pub const PUS_APID: u16 = 0x02;
|
||||
|
||||
pub const PUS_APID: u11 = u11::new(0x02);
|
||||
type TxType = Tx<USART2, PA2<AF7<PushPull>>>;
|
||||
type RxType = Rx<USART2, PA3<AF7<PushPull>>>;
|
||||
type InstantFugit = TimerInstantU32<1000>;
|
||||
type TxDmaTransferType = SerialDmaTx<&'static [u8], dma1::C7, TxType>;
|
||||
type RxDmaTransferType = SerialDmaRx<&'static mut [u8], dma1::C6, RxType>;
|
||||
|
||||
// This is the predictable maximum overhead of the COBS encoding scheme.
|
||||
// It is simply the maximum packet lenght dividied by 254 rounded up.
|
||||
const COBS_TM_OVERHEAD: usize = cobs::max_encoding_overhead(MAX_TM_LEN);
|
||||
const COBS_TC_OVERHEAD: usize = (MAX_TC_LEN + 254 - 1) / 254;
|
||||
const COBS_TM_OVERHEAD: usize = (MAX_TM_LEN + 254 - 1) / 254;
|
||||
|
||||
const TC_BUF_LEN: usize = MAX_TC_LEN + COBS_TC_OVERHEAD;
|
||||
const TM_BUF_LEN: usize = MAX_TC_LEN + COBS_TM_OVERHEAD;
|
||||
|
||||
const TC_DMA_BUF_LEN: usize = 512;
|
||||
// This is a static buffer which should ONLY (!) be used as the TX DMA
|
||||
// transfer buffer.
|
||||
static mut DMA_TX_BUF: [u8; TM_BUF_LEN] = [0; TM_BUF_LEN];
|
||||
// This is a static buffer which should ONLY (!) be used as the RX DMA
|
||||
// transfer buffer.
|
||||
static mut DMA_RX_BUF: [u8; TC_BUF_LEN] = [0; TC_BUF_LEN];
|
||||
|
||||
type TmPacket = heapless::Vec<u8, MAX_TM_LEN>;
|
||||
type TmPacket = Vec<u8, MAX_TM_LEN>;
|
||||
type TcPacket = Vec<u8, MAX_TC_LEN>;
|
||||
|
||||
static TM_QUEUE: heapless::mpmc::Queue<TmPacket, 16> = heapless::mpmc::Queue::new();
|
||||
static TM_REQUESTS: Q8<TmPacket> = Q8::new();
|
||||
|
||||
#[derive(Debug, defmt::Format, thiserror::Error)]
|
||||
pub enum TmSendError {
|
||||
#[error("packet creation error: {0}")]
|
||||
PacketCreation(#[from] CcsdsPacketCreationError),
|
||||
#[error("queue error")]
|
||||
Queue,
|
||||
use core::sync::atomic::{AtomicU16, Ordering};
|
||||
|
||||
pub struct SeqCountProviderAtomicRef {
|
||||
atomic: AtomicU16,
|
||||
ordering: Ordering,
|
||||
}
|
||||
|
||||
impl SeqCountProviderAtomicRef {
|
||||
pub const fn new(ordering: Ordering) -> Self {
|
||||
Self {
|
||||
atomic: AtomicU16::new(0),
|
||||
ordering,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SequenceCountProviderCore<u16> for SeqCountProviderAtomicRef {
|
||||
fn get(&self) -> u16 {
|
||||
self.atomic.load(self.ordering)
|
||||
}
|
||||
|
||||
fn increment(&self) {
|
||||
self.atomic.fetch_add(1, self.ordering);
|
||||
}
|
||||
|
||||
fn get_and_increment(&self) -> u16 {
|
||||
self.atomic.fetch_add(1, self.ordering)
|
||||
}
|
||||
}
|
||||
|
||||
static SEQ_COUNT_PROVIDER: SeqCountProviderAtomicRef =
|
||||
SeqCountProviderAtomicRef::new(Ordering::Relaxed);
|
||||
|
||||
pub struct TxIdle {
|
||||
tx: TxType,
|
||||
dma_channel: dma1::C7,
|
||||
}
|
||||
|
||||
#[derive(Debug, defmt::Format)]
|
||||
pub struct RequestWithTcId {
|
||||
pub request: Request,
|
||||
pub tc_id: CcsdsPacketId,
|
||||
pub enum TmSendError {
|
||||
ByteConversion(ByteConversionError),
|
||||
Queue,
|
||||
}
|
||||
|
||||
#[app(device = embassy_stm32)]
|
||||
mod app {
|
||||
use core::time::Duration;
|
||||
impl From<ByteConversionError> for TmSendError {
|
||||
fn from(value: ByteConversionError) -> Self {
|
||||
Self::ByteConversion(value)
|
||||
}
|
||||
}
|
||||
|
||||
fn send_tm(tm_creator: PusTmCreator) -> Result<(), TmSendError> {
|
||||
if tm_creator.len_written() > MAX_TM_LEN {
|
||||
return Err(ByteConversionError::ToSliceTooSmall {
|
||||
expected: tm_creator.len_written(),
|
||||
found: MAX_TM_LEN,
|
||||
}
|
||||
.into());
|
||||
}
|
||||
let mut tm_vec = TmPacket::new();
|
||||
tm_vec
|
||||
.resize(tm_creator.len_written(), 0)
|
||||
.expect("vec resize failed");
|
||||
tm_creator.write_to_bytes(tm_vec.as_mut_slice())?;
|
||||
defmt::info!(
|
||||
"Sending TM[{},{}] with size {}",
|
||||
tm_creator.service(),
|
||||
tm_creator.subservice(),
|
||||
tm_creator.len_written()
|
||||
);
|
||||
TM_REQUESTS
|
||||
.enqueue(tm_vec)
|
||||
.map_err(|_| TmSendError::Queue)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_tm_send_error(error: TmSendError) {
|
||||
defmt::warn!("sending tm failed with error {}", error);
|
||||
}
|
||||
|
||||
pub enum UartTxState {
|
||||
// Wrapped in an option because we need an owned type later.
|
||||
Idle(Option<TxIdle>),
|
||||
// Same as above
|
||||
Transmitting(Option<TxDmaTransferType>),
|
||||
}
|
||||
|
||||
pub struct UartTxShared {
|
||||
last_completed: Option<InstantFugit>,
|
||||
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)]
|
||||
mod app {
|
||||
use super::*;
|
||||
use arbitrary_int::u14;
|
||||
use rtic::Mutex;
|
||||
use rtic_sync::{
|
||||
channel::{Receiver, Sender},
|
||||
make_channel,
|
||||
};
|
||||
use satrs_stm32f3_disco_rtic::{CcsdsPacketId, LedPinSet, Request, Response};
|
||||
use spacepackets::CcsdsPacketReader;
|
||||
use core::slice::Iter;
|
||||
use satrs::pus::verification::{TcStateStarted, VerificationReportCreator};
|
||||
use satrs::spacepackets::{ecss::tc::PusTcReader, time::cds::P_FIELD_BASE};
|
||||
#[allow(unused_imports)]
|
||||
use stm32f3_discovery::leds::Direction;
|
||||
use stm32f3_discovery::leds::Leds;
|
||||
use stm32f3xx_hal::prelude::*;
|
||||
|
||||
use stm32f3_discovery::switch_hal::OutputSwitch;
|
||||
use stm32f3xx_hal::Switch;
|
||||
#[allow(dead_code)]
|
||||
type SerialType = Serial<USART2, (PA2<AF7<PushPull>>, PA3<AF7<PushPull>>)>;
|
||||
|
||||
systick_monotonic!(Mono, 1000);
|
||||
|
||||
embassy_stm32::bind_interrupts!(struct Irqs {
|
||||
USART2 => embassy_stm32::usart::InterruptHandler<embassy_stm32::peripherals::USART2>;
|
||||
});
|
||||
|
||||
#[shared]
|
||||
struct Shared {
|
||||
blink_freq: Duration,
|
||||
blink_freq: MillisDurationU32,
|
||||
tx_shared: UartTxShared,
|
||||
rx_transfer: Option<RxDmaTransferType>,
|
||||
}
|
||||
|
||||
#[local]
|
||||
struct Local {
|
||||
leds: satrs_stm32f3_disco_rtic::Leds,
|
||||
current_dir: satrs_stm32f3_disco_rtic::Direction,
|
||||
seq_count: u14,
|
||||
tx: embassy_stm32::usart::UartTx<'static, embassy_stm32::mode::Async>,
|
||||
rx: embassy_stm32::usart::RingBufferedUartRx<'static>,
|
||||
verif_reporter: VerificationReportCreator,
|
||||
leds: Leds,
|
||||
last_dir: Direction,
|
||||
curr_dir: Iter<'static, Direction>,
|
||||
}
|
||||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local) {
|
||||
static DMA_BUF: static_cell::ConstStaticCell<[u8; TC_DMA_BUF_LEN]> =
|
||||
static_cell::ConstStaticCell::new([0; TC_DMA_BUF_LEN]);
|
||||
let mut rcc = cx.device.RCC.constrain();
|
||||
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
|
||||
let (req_sender, req_receiver) = make_channel!(RequestWithTcId, 16);
|
||||
// Initialize the systick interrupt & obtain the token to prove that we did
|
||||
Mono::start(cx.core.SYST, 8_000_000);
|
||||
|
||||
defmt::info!("sat-rs demo application for the STM32F3-Discovery with RTICv2");
|
||||
let led_pin_set = LedPinSet {
|
||||
pin_n: p.PE8,
|
||||
pin_ne: p.PE9,
|
||||
pin_e: p.PE10,
|
||||
pin_se: p.PE11,
|
||||
pin_s: p.PE12,
|
||||
pin_sw: p.PE13,
|
||||
pin_w: p.PE14,
|
||||
pin_nw: p.PE15,
|
||||
};
|
||||
let leds = satrs_stm32f3_disco_rtic::Leds::new(led_pin_set);
|
||||
let mut flash = cx.device.FLASH.constrain();
|
||||
let clocks = rcc
|
||||
.cfgr
|
||||
.use_hse(8.MHz())
|
||||
.sysclk(8.MHz())
|
||||
.pclk1(8.MHz())
|
||||
.freeze(&mut flash.acr);
|
||||
|
||||
let mut config = embassy_stm32::usart::Config::default();
|
||||
config.baudrate = UART_BAUD;
|
||||
let uart = embassy_stm32::usart::Uart::new(
|
||||
p.USART2, p.PA3, p.PA2, Irqs, p.DMA1_CH7, p.DMA1_CH6, config,
|
||||
)
|
||||
.unwrap();
|
||||
// Set up monotonic timer.
|
||||
//let mono_timer = MonoTimer::new(cx.core.DWT, clocks, &mut cx.core.DCB);
|
||||
|
||||
let (tx, rx) = uart.split();
|
||||
defmt::info!("Starting sat-rs demo application for the STM32F3-Discovery");
|
||||
let mut gpioe = cx.device.GPIOE.split(&mut rcc.ahb);
|
||||
|
||||
let leds = Leds::new(
|
||||
gpioe.pe8,
|
||||
gpioe.pe9,
|
||||
gpioe.pe10,
|
||||
gpioe.pe11,
|
||||
gpioe.pe12,
|
||||
gpioe.pe13,
|
||||
gpioe.pe14,
|
||||
gpioe.pe15,
|
||||
&mut gpioe.moder,
|
||||
&mut gpioe.otyper,
|
||||
);
|
||||
let mut gpioa = cx.device.GPIOA.split(&mut rcc.ahb);
|
||||
// USART2 pins
|
||||
let mut pins = (
|
||||
// TX pin: PA2
|
||||
gpioa
|
||||
.pa2
|
||||
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl),
|
||||
// RX pin: PA3
|
||||
gpioa
|
||||
.pa3
|
||||
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl),
|
||||
);
|
||||
pins.1.internal_pull_up(&mut gpioa.pupdr, true);
|
||||
let mut usart2 = Serial::new(
|
||||
cx.device.USART2,
|
||||
pins,
|
||||
UART_BAUD.Bd(),
|
||||
clocks,
|
||||
&mut rcc.apb1,
|
||||
);
|
||||
usart2.configure_rx_interrupt(RxEvent::Idle, Switch::On);
|
||||
// This interrupt is enabled to re-schedule new transfers in the interrupt handler immediately.
|
||||
usart2.configure_tx_interrupt(TxEvent::TransmissionComplete, Switch::On);
|
||||
|
||||
let dma1 = cx.device.DMA1.split(&mut rcc.ahb);
|
||||
let (mut tx_serial, mut rx_serial) = usart2.split();
|
||||
|
||||
// This interrupt is immediately triggered, clear it. It will only be reset
|
||||
// by the hardware when data is received on RX (RXNE event)
|
||||
rx_serial.clear_event(RxEvent::Idle);
|
||||
// For some reason, this is also immediately triggered..
|
||||
tx_serial.clear_event(TxEvent::TransmissionComplete);
|
||||
let rx_transfer = rx_serial.read_exact(unsafe { DMA_RX_BUF.as_mut_slice() }, dma1.ch6);
|
||||
defmt::info!("Spawning tasks");
|
||||
blinky::spawn().unwrap();
|
||||
blink::spawn().unwrap();
|
||||
serial_tx_handler::spawn().unwrap();
|
||||
serial_rx_handler::spawn(req_sender).unwrap();
|
||||
req_handler::spawn(req_receiver).unwrap();
|
||||
|
||||
let verif_reporter = VerificationReportCreator::new(PUS_APID).unwrap();
|
||||
|
||||
(
|
||||
Shared {
|
||||
blink_freq: Duration::from_millis(DEFAULT_BLINK_FREQ_MS as u64),
|
||||
blink_freq: MillisDurationU32::from_ticks(DEFAULT_BLINK_FREQ_MS),
|
||||
tx_shared: UartTxShared {
|
||||
last_completed: None,
|
||||
state: UartTxState::Idle(Some(TxIdle {
|
||||
tx: tx_serial,
|
||||
dma_channel: dma1.ch7,
|
||||
})),
|
||||
},
|
||||
rx_transfer: Some(rx_transfer),
|
||||
},
|
||||
Local {
|
||||
verif_reporter,
|
||||
leds,
|
||||
tx,
|
||||
seq_count: u14::new(0),
|
||||
rx: rx.into_ring_buffered(DMA_BUF.take()),
|
||||
current_dir: satrs_stm32f3_disco_rtic::Direction::North,
|
||||
last_dir: Direction::North,
|
||||
curr_dir: Direction::iter(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[task(local = [leds, current_dir], shared=[blink_freq])]
|
||||
async fn blinky(mut cx: blinky::Context) {
|
||||
#[task(local = [leds, curr_dir, last_dir], shared=[blink_freq])]
|
||||
async fn blink(mut cx: blink::Context) {
|
||||
let blink::LocalResources {
|
||||
leds,
|
||||
curr_dir,
|
||||
last_dir,
|
||||
..
|
||||
} = cx.local;
|
||||
let mut toggle_leds = |dir: &Direction| {
|
||||
let last_led = leds.for_direction(*last_dir);
|
||||
last_led.off().ok();
|
||||
let led = leds.for_direction(*dir);
|
||||
led.on().ok();
|
||||
*last_dir = *dir;
|
||||
};
|
||||
loop {
|
||||
cx.local.leds.blink_next(cx.local.current_dir);
|
||||
match curr_dir.next() {
|
||||
Some(dir) => {
|
||||
toggle_leds(dir);
|
||||
}
|
||||
None => {
|
||||
*curr_dir = Direction::iter();
|
||||
toggle_leds(curr_dir.next().unwrap());
|
||||
}
|
||||
}
|
||||
let current_blink_freq = cx.shared.blink_freq.lock(|current| *current);
|
||||
Mono::delay(MillisDurationU32::from_ticks(
|
||||
current_blink_freq.as_millis() as u32,
|
||||
))
|
||||
.await;
|
||||
Mono::delay(current_blink_freq).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[task(
|
||||
local = [
|
||||
tx,
|
||||
encoded_buf: [u8; TM_BUF_LEN] = [0; TM_BUF_LEN]
|
||||
],
|
||||
shared = [],
|
||||
shared = [tx_shared],
|
||||
)]
|
||||
async fn serial_tx_handler(cx: serial_tx_handler::Context) {
|
||||
async fn serial_tx_handler(mut cx: serial_tx_handler::Context) {
|
||||
loop {
|
||||
while let Some(vec) = TM_QUEUE.dequeue() {
|
||||
let encoded_len =
|
||||
cobs::encode_including_sentinels(&vec[0..vec.len()], cx.local.encoded_buf);
|
||||
defmt::debug!("sending {} bytes over UART", encoded_len);
|
||||
cx.local
|
||||
.tx
|
||||
.write(&cx.local.encoded_buf[0..encoded_len])
|
||||
.await
|
||||
.unwrap();
|
||||
let is_idle = cx.shared.tx_shared.lock(|tx_shared| {
|
||||
if let UartTxState::Idle(_) = tx_shared.state {
|
||||
return true;
|
||||
}
|
||||
false
|
||||
});
|
||||
if is_idle {
|
||||
let last_completed = cx.shared.tx_shared.lock(|shared| shared.last_completed);
|
||||
if let Some(last_completed) = last_completed {
|
||||
let elapsed_ms = (Mono::now() - last_completed).to_millis();
|
||||
if elapsed_ms < MIN_DELAY_BETWEEN_TX_PACKETS_MS {
|
||||
Mono::delay((MIN_DELAY_BETWEEN_TX_PACKETS_MS - elapsed_ms).millis()).await;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Check for completion after 1 ms
|
||||
Mono::delay(1.millis()).await;
|
||||
continue;
|
||||
}
|
||||
if let Some(vec) = TM_REQUESTS.dequeue() {
|
||||
cx.shared
|
||||
.tx_shared
|
||||
.lock(|tx_shared| match &mut tx_shared.state {
|
||||
UartTxState::Idle(tx) => {
|
||||
let encoded_len;
|
||||
//debug!(target: "serial_tx_handler", "bytes: {:x?}", &buf[0..len]);
|
||||
// Safety: We only copy the data into the TX DMA buffer in this task.
|
||||
// If the DMA is active, another branch will be taken.
|
||||
unsafe {
|
||||
// 0 sentinel value as start marker
|
||||
DMA_TX_BUF[0] = 0;
|
||||
encoded_len =
|
||||
cobs::encode(&vec[0..vec.len()], &mut DMA_TX_BUF[1..]);
|
||||
// Should never panic, we accounted for the overhead.
|
||||
// Write into transfer buffer directly, no need for intermediate
|
||||
// encoding buffer.
|
||||
// 0 end marker
|
||||
DMA_TX_BUF[encoded_len + 1] = 0;
|
||||
}
|
||||
//debug!(target: "serial_tx_handler", "Sending {} bytes", encoded_len + 2);
|
||||
//debug!("sent: {:x?}", &mut_tx_dma_buf[0..encoded_len + 2]);
|
||||
let tx_idle = tx.take().unwrap();
|
||||
// Transfer completion and re-scheduling of new TX transfers will be done
|
||||
// by the IRQ handler.
|
||||
// SAFETY: The DMA is the exclusive writer to the DMA buffer now.
|
||||
let transfer = tx_idle.tx.write_all(
|
||||
unsafe { &DMA_TX_BUF[0..encoded_len + 2] },
|
||||
tx_idle.dma_channel,
|
||||
);
|
||||
tx_shared.state = UartTxState::Transmitting(Some(transfer));
|
||||
// The memory block is automatically returned to the pool when it is dropped.
|
||||
}
|
||||
UartTxState::Transmitting(_) => (),
|
||||
});
|
||||
// Check for completion after 1 ms
|
||||
Mono::delay(1.millis()).await;
|
||||
continue;
|
||||
}
|
||||
// Nothing to do, and we are idle.
|
||||
Mono::delay(TX_HANDLER_FREQ_MS.millis()).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[task(
|
||||
local = [
|
||||
rx,
|
||||
read_buf: [u8; 128] = [0; 128],
|
||||
verif_reporter,
|
||||
decode_buf: [u8; MAX_TC_LEN] = [0; MAX_TC_LEN],
|
||||
src_data_buf: [u8; MAX_TM_LEN] = [0; MAX_TM_LEN],
|
||||
timestamp: [u8; 7] = [0; 7],
|
||||
],
|
||||
shared = [blink_freq]
|
||||
)]
|
||||
async fn serial_rx_handler(
|
||||
cx: serial_rx_handler::Context,
|
||||
mut sender: Sender<'static, RequestWithTcId, 16>,
|
||||
mut cx: serial_rx_handler::Context,
|
||||
received_packet: Vec<u8, MAX_TC_LEN>,
|
||||
) {
|
||||
let mut decoder = cobs::CobsDecoder::new(cx.local.decode_buf);
|
||||
loop {
|
||||
match cx.local.rx.read(cx.local.read_buf).await {
|
||||
Ok(bytes) => {
|
||||
defmt::debug!("received {} bytes over UART", bytes);
|
||||
for byte in cx.local.read_buf[0..bytes].iter() {
|
||||
match decoder.feed(*byte) {
|
||||
Ok(None) => (),
|
||||
Ok(Some(packet_size)) => {
|
||||
match CcsdsPacketReader::new_with_checksum(
|
||||
&decoder.dest()[0..packet_size],
|
||||
) {
|
||||
Ok(packet) => {
|
||||
let packet_id = packet.packet_id();
|
||||
let psc = packet.psc();
|
||||
let tc_packet_id = CcsdsPacketId { packet_id, psc };
|
||||
if let Ok(request) =
|
||||
postcard::from_bytes::<Request>(packet.packet_data())
|
||||
{
|
||||
sender
|
||||
.send(RequestWithTcId {
|
||||
request,
|
||||
tc_id: tc_packet_id,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
cx.local.timestamp[0] = P_FIELD_BASE;
|
||||
defmt::info!("Received packet with {} bytes", received_packet.len());
|
||||
let decode_buf = cx.local.decode_buf;
|
||||
let packet = received_packet.as_slice();
|
||||
let mut start_idx = None;
|
||||
for (idx, byte) in packet.iter().enumerate() {
|
||||
if *byte != 0 {
|
||||
start_idx = Some(idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if start_idx.is_none() {
|
||||
defmt::warn!("decoding error, can only process cobs encoded frames, data is all 0");
|
||||
return;
|
||||
}
|
||||
let start_idx = start_idx.unwrap();
|
||||
match cobs::decode(&received_packet.as_slice()[start_idx..], decode_buf) {
|
||||
Ok(len) => {
|
||||
defmt::info!("Decoded packet length: {}", len);
|
||||
let pus_tc = PusTcReader::new(decode_buf);
|
||||
match pus_tc {
|
||||
Ok((tc, _tc_len)) => {
|
||||
match convert_pus_tc_to_request(
|
||||
&tc,
|
||||
cx.local.verif_reporter,
|
||||
cx.local.src_data_buf,
|
||||
cx.local.timestamp,
|
||||
) {
|
||||
Ok(request_with_token) => {
|
||||
let started_token = handle_start_verification(
|
||||
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);
|
||||
}
|
||||
Err(e) => {
|
||||
defmt::error!("error unpacking ccsds packet: {}", e);
|
||||
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) => {
|
||||
defmt::error!("cobs decoding error: {}", e);
|
||||
// TODO: Error handling: Send verification failure based on request error.
|
||||
defmt::warn!("request error {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
defmt::error!("uart read error: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[task(shared = [blink_freq], local = [seq_count])]
|
||||
async fn req_handler(
|
||||
mut cx: req_handler::Context,
|
||||
mut receiver: Receiver<'static, RequestWithTcId, 16>,
|
||||
) {
|
||||
loop {
|
||||
match receiver.recv().await {
|
||||
Ok(request_with_tc_id) => {
|
||||
let tm_send_result = match request_with_tc_id.request {
|
||||
Request::Ping => handle_ping_request(&mut cx, request_with_tc_id.tc_id),
|
||||
Request::ChangeBlinkFrequency(duration) => {
|
||||
handle_change_blink_frequency_request(
|
||||
&mut cx,
|
||||
request_with_tc_id.tc_id,
|
||||
duration,
|
||||
)
|
||||
}
|
||||
};
|
||||
if let Err(e) = tm_send_result {
|
||||
defmt::error!("error sending TM response: {}", e);
|
||||
Err(e) => {
|
||||
defmt::warn!("Error unpacking PUS TC: {}", e);
|
||||
}
|
||||
}
|
||||
Err(_e) => defmt::error!("request receive error"),
|
||||
}
|
||||
Err(_) => {
|
||||
defmt::warn!("decoding error, can only process cobs encoded frames")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_ping_request(
|
||||
cx: &mut req_handler::Context,
|
||||
tc_packet_id: CcsdsPacketId,
|
||||
) -> Result<(), TmSendError> {
|
||||
defmt::info!("Received PUS ping telecommand, sending ping reply");
|
||||
send_tm(tc_packet_id, Response::CommandDone, *cx.local.seq_count)?;
|
||||
*cx.local.seq_count = cx.local.seq_count.wrapping_add(u14::new(1));
|
||||
Ok(())
|
||||
fn handle_ping_request(timestamp: &[u8]) {
|
||||
defmt::info!("Received PUS ping telecommand, sending ping reply TM[17,2]");
|
||||
let sp_header =
|
||||
SpHeader::new_for_unseg_tc(PUS_APID, SEQ_COUNT_PROVIDER.get_and_increment(), 0);
|
||||
let sec_header = PusTmSecondaryHeader::new_simple(17, 2, timestamp);
|
||||
let ping_reply = PusTmCreator::new(sp_header, sec_header, &[], true);
|
||||
let mut tm_packet = TmPacket::new();
|
||||
tm_packet
|
||||
.resize(ping_reply.len_written(), 0)
|
||||
.expect("vec resize failed");
|
||||
ping_reply.write_to_bytes(&mut tm_packet).unwrap();
|
||||
if TM_REQUESTS.enqueue(tm_packet).is_err() {
|
||||
defmt::warn!("TC queue full");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_change_blink_frequency_request(
|
||||
cx: &mut req_handler::Context,
|
||||
tc_packet_id: CcsdsPacketId,
|
||||
duration: Duration,
|
||||
) -> Result<(), TmSendError> {
|
||||
defmt::info!(
|
||||
"Received ChangeBlinkFrequency request, new frequency: {} ms",
|
||||
duration.as_millis()
|
||||
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,
|
||||
×tamp,
|
||||
)
|
||||
.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(
|
||||
src_data_buf,
|
||||
started_token,
|
||||
SEQ_COUNT_PROVIDER.get(),
|
||||
0,
|
||||
timestamp,
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
if let Err(e) = result {
|
||||
handle_tm_send_error(e);
|
||||
}
|
||||
}
|
||||
|
||||
#[task(binds = DMA1_CH6, shared = [rx_transfer])]
|
||||
fn rx_dma_isr(mut cx: rx_dma_isr::Context) {
|
||||
let mut tc_packet = TcPacket::new();
|
||||
cx.shared.rx_transfer.lock(|rx_transfer| {
|
||||
let rx_ref = rx_transfer.as_ref().unwrap();
|
||||
if rx_ref.is_complete() {
|
||||
let uart_rx_owned = rx_transfer.take().unwrap();
|
||||
let (buf, c, rx) = uart_rx_owned.stop();
|
||||
// The received data is transferred to another task now to avoid any processing overhead
|
||||
// during the interrupt. There are multiple ways to do this, we use a stack allocaed vector here
|
||||
// to do this.
|
||||
tc_packet.resize(buf.len(), 0).expect("vec resize failed");
|
||||
tc_packet.copy_from_slice(buf);
|
||||
|
||||
// Start the next transfer as soon as possible.
|
||||
*rx_transfer = Some(rx.read_exact(buf, c));
|
||||
|
||||
// Send the vector to a regular task.
|
||||
serial_rx_handler::spawn(tc_packet).expect("spawning rx handler task failed");
|
||||
// If this happens, there is a high chance that the maximum packet length was
|
||||
// exceeded. Circular mode is not used here, so data might be missed.
|
||||
defmt::warn!(
|
||||
"rx transfer with maximum length {}, might miss data",
|
||||
TC_BUF_LEN
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[task(binds = USART2_EXTI26, shared = [rx_transfer, tx_shared])]
|
||||
fn serial_isr(mut cx: serial_isr::Context) {
|
||||
cx.shared
|
||||
.blink_freq
|
||||
.lock(|blink_freq| *blink_freq = duration);
|
||||
send_tm(tc_packet_id, Response::CommandDone, *cx.local.seq_count)?;
|
||||
*cx.local.seq_count = cx.local.seq_count.wrapping_add(u14::new(1));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn send_tm(
|
||||
tc_packet_id: CcsdsPacketId,
|
||||
response: Response,
|
||||
current_seq_count: u14,
|
||||
) -> Result<(), TmSendError> {
|
||||
let sp_header = SpHeader::new_for_unseg_tc(PUS_APID, current_seq_count, 0);
|
||||
let tm_header = satrs_stm32f3_disco_rtic::TmHeader {
|
||||
tc_packet_id: Some(tc_packet_id),
|
||||
uptime_millis: Mono::now().duration_since_epoch().to_millis(),
|
||||
};
|
||||
let mut tm_packet = TmPacket::new();
|
||||
let tm_size = tm_size(&tm_header, &response);
|
||||
tm_packet.resize(tm_size, 0).expect("vec resize failed");
|
||||
create_tm_packet(&mut tm_packet, sp_header, tm_header, response)?;
|
||||
if TM_QUEUE.enqueue(tm_packet).is_err() {
|
||||
defmt::warn!("TC queue full");
|
||||
return Err(TmSendError::Queue);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// same panicking *behavior* as `panic-probe` but doesn't print a panic message
|
||||
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
|
||||
#[defmt::panic_handler]
|
||||
fn panic() -> ! {
|
||||
cortex_m::asm::udf()
|
||||
}
|
||||
|
||||
/// Terminates the application and makes a semihosting-capable debug tool exit
|
||||
/// with status code 0.
|
||||
pub fn exit() -> ! {
|
||||
loop {
|
||||
debug::exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/// Hardfault handler.
|
||||
///
|
||||
/// Terminates the application and makes a semihosting-capable debug tool exit
|
||||
/// with an error. This seems better than the default, which is to spin in a
|
||||
/// loop.
|
||||
#[cortex_m_rt::exception]
|
||||
unsafe fn HardFault(_frame: &cortex_m_rt::ExceptionFrame) -> ! {
|
||||
loop {
|
||||
debug::exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// defmt-test 0.3.0 has the limitation that this `#[tests]` attribute can only be used
|
||||
// once within a crate. the module can be in any file but there can only be at most
|
||||
// one `#[tests]` module in this library crate
|
||||
#[cfg(test)]
|
||||
#[defmt_test::tests]
|
||||
mod unit_tests {
|
||||
use defmt::assert;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert!(true)
|
||||
.tx_shared
|
||||
.lock(|tx_shared| match &mut tx_shared.state {
|
||||
UartTxState::Idle(_) => (),
|
||||
UartTxState::Transmitting(transfer) => {
|
||||
let transfer_ref = transfer.as_ref().unwrap();
|
||||
if transfer_ref.is_complete() {
|
||||
let transfer = transfer.take().unwrap();
|
||||
let (_, dma_channel, mut tx) = transfer.stop();
|
||||
tx.clear_event(TxEvent::TransmissionComplete);
|
||||
tx_shared.state = UartTxState::Idle(Some(TxIdle { tx, dma_channel }));
|
||||
// We cache the last completed time to ensure that there is a minimum delay between consecutive
|
||||
// transferred packets.
|
||||
tx_shared.last_completed = Some(Mono::now());
|
||||
}
|
||||
}
|
||||
});
|
||||
let mut tc_packet = TcPacket::new();
|
||||
cx.shared.rx_transfer.lock(|rx_transfer| {
|
||||
let rx_transfer_ref = rx_transfer.as_ref().unwrap();
|
||||
// Received a partial packet.
|
||||
if rx_transfer_ref.is_event_triggered(RxEvent::Idle) {
|
||||
let rx_transfer_owned = rx_transfer.take().unwrap();
|
||||
let (buf, ch, mut rx, rx_len) = rx_transfer_owned.stop_and_return_received_bytes();
|
||||
// The received data is transferred to another task now to avoid any processing overhead
|
||||
// during the interrupt. There are multiple ways to do this, we use a stack
|
||||
// allocated vector to do this.
|
||||
tc_packet
|
||||
.resize(rx_len as usize, 0)
|
||||
.expect("vec resize failed");
|
||||
tc_packet[0..rx_len as usize].copy_from_slice(&buf[0..rx_len as usize]);
|
||||
rx.clear_event(RxEvent::Idle);
|
||||
serial_rx_handler::spawn(tc_packet).expect("spawning rx handler failed");
|
||||
*rx_transfer = Some(rx.read_exact(buf, ch));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
629
embedded-examples/stm32h7-nucleo-rtic/Cargo.lock
generated
629
embedded-examples/stm32h7-nucleo-rtic/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -16,17 +16,16 @@ harness = false
|
||||
[dependencies]
|
||||
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
|
||||
cortex-m-rt = "0.7"
|
||||
defmt = "1"
|
||||
defmt = "0.3"
|
||||
defmt-brtt = { version = "0.1", default-features = false, features = ["rtt"] }
|
||||
panic-probe = { version = "1", features = ["print-defmt"] }
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
cortex-m-semihosting = "0.5.0"
|
||||
# TODO: Replace with embassy-hal.
|
||||
stm32h7xx-hal = { version="0.16", features= ["stm32h743v", "ethernet"] }
|
||||
embedded-alloc = "0.6"
|
||||
rtic-sync = { version = "1", features = ["defmt-03"] }
|
||||
|
||||
[dependencies.smoltcp]
|
||||
version = "0.12"
|
||||
version = "0.11"
|
||||
default-features = false
|
||||
features = ["medium-ethernet", "proto-ipv4", "socket-raw", "socket-dhcpv4", "socket-udp", "defmt"]
|
||||
|
||||
@@ -40,12 +39,12 @@ features = ["cortex-m-systick"]
|
||||
|
||||
[dependencies.satrs]
|
||||
path = "../../satrs"
|
||||
# version = "0.2"
|
||||
version = "0.2"
|
||||
default-features = false
|
||||
features = ["defmt", "heapless"]
|
||||
|
||||
[dev-dependencies]
|
||||
defmt-test = "0.4"
|
||||
defmt-test = "0.3"
|
||||
|
||||
# cargo build/run
|
||||
[profile.dev]
|
||||
|
||||
5
justfile
5
justfile
@@ -1,12 +1,9 @@
|
||||
all: check build embedded test fmt clippy docs
|
||||
all: check embedded test fmt clippy docs
|
||||
|
||||
check:
|
||||
cargo check
|
||||
cargo check -p satrs-example --no-default-features
|
||||
|
||||
build:
|
||||
cargo build
|
||||
|
||||
test:
|
||||
cargo nextest run --all-features
|
||||
cargo test --doc --all-features
|
||||
|
||||
@@ -484,7 +484,6 @@ mod tests {
|
||||
sync::{mpsc, Arc},
|
||||
};
|
||||
|
||||
use arbitrary_int::u21;
|
||||
use satrs::{
|
||||
mode::{ModeReply, ModeRequest},
|
||||
mode_tree::ModeParent,
|
||||
@@ -575,7 +574,7 @@ mod tests {
|
||||
let (request_tx, request_rx) = mpsc::sync_channel(5);
|
||||
let (reply_tx_to_pus, reply_rx_to_pus) = mpsc::sync_channel(5);
|
||||
let (reply_tx_to_parent, reply_rx_to_parent) = mpsc::sync_channel(5);
|
||||
let id = UniqueApidTargetId::new(Apid::Acs.raw_value(), u21::new(1));
|
||||
let id = UniqueApidTargetId::new(Apid::Acs.raw_value(), 1);
|
||||
let mode_node = ModeRequestHandlerMpscBounded::new(id.into(), request_rx);
|
||||
let (composite_request_tx, composite_request_rx) = mpsc::channel();
|
||||
let (hk_reply_tx, hk_reply_rx) = mpsc::sync_channel(10);
|
||||
|
||||
@@ -2,7 +2,7 @@ use arbitrary_int::u11;
|
||||
use satrs::pus::verification::RequestId;
|
||||
use satrs::spacepackets::ecss::tc::PusTcCreator;
|
||||
use satrs::spacepackets::ecss::tm::PusTmReader;
|
||||
use satrs::spacepackets::ecss::{CreatorConfig, MessageTypeId};
|
||||
use satrs::spacepackets::ecss::CreatorConfig;
|
||||
use satrs::spacepackets::SpHeader;
|
||||
use satrs_example::config::{OBSW_SERVER_ADDR, SERVER_PORT};
|
||||
use std::net::{IpAddr, SocketAddr, UdpSocket};
|
||||
@@ -13,7 +13,8 @@ fn main() {
|
||||
let addr = SocketAddr::new(IpAddr::V4(OBSW_SERVER_ADDR), SERVER_PORT);
|
||||
let pus_tc = PusTcCreator::new_simple(
|
||||
SpHeader::new_from_apid(u11::new(0x02)),
|
||||
MessageTypeId::new(17, 1),
|
||||
17,
|
||||
1,
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
@@ -34,9 +35,9 @@ fn main() {
|
||||
match res {
|
||||
Ok(_len) => {
|
||||
let pus_tm = PusTmReader::new(&buf, 7).expect("Parsing PUS TM failed");
|
||||
if pus_tm.service_type_id() == 17 && pus_tm.message_subtype_id() == 2 {
|
||||
if pus_tm.service() == 17 && pus_tm.subservice() == 2 {
|
||||
println!("Received PUS Ping Reply TM[17,2]")
|
||||
} else if pus_tm.service_type_id() == 1 {
|
||||
} else if pus_tm.service() == 1 {
|
||||
if pus_tm.source_data().is_empty() {
|
||||
println!("Invalid verification TM, no source data");
|
||||
}
|
||||
@@ -45,29 +46,28 @@ fn main() {
|
||||
println!("Invalid verification TM source data, less than 4 bytes")
|
||||
}
|
||||
let req_id = RequestId::from_bytes(src_data).unwrap();
|
||||
let subtype_id = pus_tm.message_subtype_id();
|
||||
if subtype_id == 1 {
|
||||
if pus_tm.subservice() == 1 {
|
||||
println!("Received TM[1,1] acceptance success for request ID {req_id}")
|
||||
} else if subtype_id == 2 {
|
||||
} else if pus_tm.subservice() == 2 {
|
||||
println!("Received TM[1,2] acceptance failure for request ID {req_id}")
|
||||
} else if subtype_id == 3 {
|
||||
} else if pus_tm.subservice() == 3 {
|
||||
println!("Received TM[1,3] start success for request ID {req_id}")
|
||||
} else if subtype_id == 4 {
|
||||
} else if pus_tm.subservice() == 4 {
|
||||
println!("Received TM[1,2] start failure for request ID {req_id}")
|
||||
} else if subtype_id == 5 {
|
||||
} else if pus_tm.subservice() == 5 {
|
||||
println!("Received TM[1,5] step success for request ID {req_id}")
|
||||
} else if subtype_id == 6 {
|
||||
} else if pus_tm.subservice() == 6 {
|
||||
println!("Received TM[1,6] step failure for request ID {req_id}")
|
||||
} else if subtype_id == 7 {
|
||||
} else if pus_tm.subservice() == 7 {
|
||||
println!("Received TM[1,7] completion success for request ID {req_id}")
|
||||
} else if subtype_id == 8 {
|
||||
} else if pus_tm.subservice() == 8 {
|
||||
println!("Received TM[1,8] completion failure for request ID {req_id}");
|
||||
}
|
||||
} else {
|
||||
println!(
|
||||
"Received TM[{}, {}] with {} bytes",
|
||||
pus_tm.service_type_id(),
|
||||
pus_tm.message_subtype_id(),
|
||||
pus_tm.service(),
|
||||
pus_tm.subservice(),
|
||||
size
|
||||
);
|
||||
}
|
||||
|
||||
@@ -506,7 +506,6 @@ impl<ComInterface: SerialInterface> ModeChild for PcduHandler<ComInterface> {
|
||||
mod tests {
|
||||
use std::sync::mpsc;
|
||||
|
||||
use arbitrary_int::u21;
|
||||
use satrs::{
|
||||
mode::ModeRequest, power::SwitchStateBinary, request::GenericMessage, tmtc::PacketAsVec,
|
||||
};
|
||||
@@ -573,7 +572,7 @@ mod tests {
|
||||
let (switch_request_tx, switch_reqest_rx) = mpsc::channel();
|
||||
let shared_switch_map = Arc::new(Mutex::new(SwitchSet::default()));
|
||||
let mut handler = PcduHandler::new(
|
||||
UniqueApidTargetId::new(Apid::Eps.raw_value(), u21::new(0)),
|
||||
UniqueApidTargetId::new(Apid::Eps.raw_value(), 0),
|
||||
"TEST_PCDU",
|
||||
mode_node,
|
||||
composite_request_rx,
|
||||
|
||||
@@ -218,7 +218,6 @@ impl<TmSender: EcssTmSender> EventHandler<TmSender> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use arbitrary_int::u21;
|
||||
use satrs::{
|
||||
events_legacy::EventU32,
|
||||
pus::verification::VerificationReporterConfig,
|
||||
@@ -228,7 +227,7 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
|
||||
const TEST_CREATOR_ID: UniqueApidTargetId = UniqueApidTargetId::new(u11::new(1), u21::new(2));
|
||||
const TEST_CREATOR_ID: UniqueApidTargetId = UniqueApidTargetId::new(u11::new(1), 2);
|
||||
const TEST_EVENT: EventU32 = EventU32::new(satrs::events_legacy::Severity::Info, 1, 1);
|
||||
|
||||
pub struct EventManagementTestbench {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use arbitrary_int::traits::Integer as _;
|
||||
use derive_new::new;
|
||||
use satrs::hk::UniqueId;
|
||||
use satrs::request::UniqueApidTargetId;
|
||||
use satrs::spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader};
|
||||
use satrs::spacepackets::ecss::{hk, CreatorConfig, MessageTypeId};
|
||||
use satrs::spacepackets::ecss::{hk, CreatorConfig};
|
||||
use satrs::spacepackets::{ByteConversionError, SpHeader};
|
||||
|
||||
#[derive(Debug, new, Copy, Clone)]
|
||||
@@ -30,7 +29,7 @@ impl HkUniqueId {
|
||||
expected: 8,
|
||||
});
|
||||
}
|
||||
buf[0..4].copy_from_slice(&self.target_id.unique_id.as_u32().to_be_bytes());
|
||||
buf[0..4].copy_from_slice(&self.target_id.unique_id.to_be_bytes());
|
||||
buf[4..8].copy_from_slice(&self.set_id.to_be_bytes());
|
||||
|
||||
Ok(8)
|
||||
@@ -54,13 +53,9 @@ impl PusHkHelper {
|
||||
hk_data_writer: &mut HkWriter,
|
||||
buf: &'b mut [u8],
|
||||
) -> Result<PusTmCreator<'a, 'b>, ByteConversionError> {
|
||||
let sec_header = PusTmSecondaryHeader::new(
|
||||
MessageTypeId::new(3, hk::Subservice::TmHkPacket as u8),
|
||||
0,
|
||||
0,
|
||||
timestamp,
|
||||
);
|
||||
buf[0..4].copy_from_slice(&self.component_id.unique_id.as_u32().to_be_bytes());
|
||||
let sec_header =
|
||||
PusTmSecondaryHeader::new(3, hk::Subservice::TmHkPacket as u8, 0, 0, timestamp);
|
||||
buf[0..4].copy_from_slice(&self.component_id.unique_id.to_be_bytes());
|
||||
buf[4..8].copy_from_slice(&set_id.to_be_bytes());
|
||||
let (_, second_half) = buf.split_at_mut(8);
|
||||
let hk_data_len = hk_data_writer(second_half)?;
|
||||
|
||||
@@ -14,8 +14,7 @@ pub enum Apid {
|
||||
|
||||
pub mod acs {
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[bitbybit::bitenum(u21, exhaustive = false)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum Id {
|
||||
Subsystem = 1,
|
||||
Assembly = 2,
|
||||
@@ -24,32 +23,30 @@ pub mod acs {
|
||||
}
|
||||
|
||||
pub const SUBSYSTEM: super::UniqueApidTargetId =
|
||||
super::UniqueApidTargetId::new(super::Apid::Acs.raw_value(), Id::Subsystem.raw_value());
|
||||
super::UniqueApidTargetId::new(super::Apid::Acs.raw_value(), Id::Subsystem as u32);
|
||||
pub const ASSEMBLY: super::UniqueApidTargetId =
|
||||
super::UniqueApidTargetId::new(super::Apid::Acs.raw_value(), Id::Assembly.raw_value());
|
||||
super::UniqueApidTargetId::new(super::Apid::Acs.raw_value(), Id::Assembly as u32);
|
||||
pub const MGM0: super::UniqueApidTargetId =
|
||||
super::UniqueApidTargetId::new(super::Apid::Acs.raw_value(), Id::Mgm0.raw_value());
|
||||
super::UniqueApidTargetId::new(super::Apid::Acs.raw_value(), Id::Mgm0 as u32);
|
||||
pub const MGM1: super::UniqueApidTargetId =
|
||||
super::UniqueApidTargetId::new(super::Apid::Acs.raw_value(), Id::Mgm1.raw_value());
|
||||
super::UniqueApidTargetId::new(super::Apid::Acs.raw_value(), Id::Mgm1 as u32);
|
||||
}
|
||||
|
||||
pub mod eps {
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[bitbybit::bitenum(u21, exhaustive = false)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum Id {
|
||||
Pcdu = 0,
|
||||
Subsystem = 1,
|
||||
}
|
||||
|
||||
pub const PCDU: super::UniqueApidTargetId =
|
||||
super::UniqueApidTargetId::new(super::Apid::Eps.raw_value(), Id::Pcdu.raw_value());
|
||||
super::UniqueApidTargetId::new(super::Apid::Eps.raw_value(), Id::Pcdu as u32);
|
||||
pub const SUBSYSTEM: super::UniqueApidTargetId =
|
||||
super::UniqueApidTargetId::new(super::Apid::Eps.raw_value(), Id::Subsystem.raw_value());
|
||||
super::UniqueApidTargetId::new(super::Apid::Eps.raw_value(), Id::Subsystem as u32);
|
||||
}
|
||||
|
||||
pub mod generic_pus {
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[bitbybit::bitenum(u21, exhaustive = false)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum Id {
|
||||
PusEventManagement = 0,
|
||||
PusRouting = 1,
|
||||
@@ -61,49 +58,39 @@ pub mod generic_pus {
|
||||
|
||||
pub const PUS_EVENT_MANAGEMENT: super::UniqueApidTargetId = super::UniqueApidTargetId::new(
|
||||
super::Apid::GenericPus.raw_value(),
|
||||
Id::PusEventManagement.raw_value(),
|
||||
);
|
||||
pub const PUS_ROUTING: super::UniqueApidTargetId = super::UniqueApidTargetId::new(
|
||||
super::Apid::GenericPus.raw_value(),
|
||||
Id::PusRouting.raw_value(),
|
||||
);
|
||||
pub const PUS_TEST: super::UniqueApidTargetId = super::UniqueApidTargetId::new(
|
||||
super::Apid::GenericPus.raw_value(),
|
||||
Id::PusTest.raw_value(),
|
||||
);
|
||||
pub const PUS_ACTION: super::UniqueApidTargetId = super::UniqueApidTargetId::new(
|
||||
super::Apid::GenericPus.raw_value(),
|
||||
Id::PusAction.raw_value(),
|
||||
);
|
||||
pub const PUS_MODE: super::UniqueApidTargetId = super::UniqueApidTargetId::new(
|
||||
super::Apid::GenericPus.raw_value(),
|
||||
Id::PusMode.raw_value(),
|
||||
Id::PusEventManagement as u32,
|
||||
);
|
||||
pub const PUS_ROUTING: super::UniqueApidTargetId =
|
||||
super::UniqueApidTargetId::new(super::Apid::GenericPus.raw_value(), Id::PusRouting as u32);
|
||||
pub const PUS_TEST: super::UniqueApidTargetId =
|
||||
super::UniqueApidTargetId::new(super::Apid::GenericPus.raw_value(), Id::PusTest as u32);
|
||||
pub const PUS_ACTION: super::UniqueApidTargetId =
|
||||
super::UniqueApidTargetId::new(super::Apid::GenericPus.raw_value(), Id::PusAction as u32);
|
||||
pub const PUS_MODE: super::UniqueApidTargetId =
|
||||
super::UniqueApidTargetId::new(super::Apid::GenericPus.raw_value(), Id::PusMode as u32);
|
||||
pub const PUS_HK: super::UniqueApidTargetId =
|
||||
super::UniqueApidTargetId::new(super::Apid::GenericPus.raw_value(), Id::PusHk.raw_value());
|
||||
super::UniqueApidTargetId::new(super::Apid::GenericPus.raw_value(), Id::PusHk as u32);
|
||||
}
|
||||
|
||||
pub mod sched {
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[bitbybit::bitenum(u21, exhaustive = false)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum Id {
|
||||
PusSched = 0,
|
||||
}
|
||||
|
||||
pub const PUS_SCHED: super::UniqueApidTargetId =
|
||||
super::UniqueApidTargetId::new(super::Apid::Sched.raw_value(), Id::PusSched.raw_value());
|
||||
super::UniqueApidTargetId::new(super::Apid::Sched.raw_value(), Id::PusSched as u32);
|
||||
}
|
||||
|
||||
pub mod tmtc {
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[bitbybit::bitenum(u21, exhaustive = false)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum Id {
|
||||
UdpServer = 0,
|
||||
TcpServer = 1,
|
||||
}
|
||||
|
||||
pub const UDP_SERVER: super::UniqueApidTargetId =
|
||||
super::UniqueApidTargetId::new(super::Apid::Tmtc.raw_value(), Id::UdpServer.raw_value());
|
||||
super::UniqueApidTargetId::new(super::Apid::Tmtc.raw_value(), Id::UdpServer as u32);
|
||||
pub const TCP_SERVER: super::UniqueApidTargetId =
|
||||
super::UniqueApidTargetId::new(super::Apid::Tmtc.raw_value(), Id::TcpServer.raw_value());
|
||||
super::UniqueApidTargetId::new(super::Apid::Tmtc.raw_value(), Id::TcpServer as u32);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::{
|
||||
};
|
||||
|
||||
use log::{info, warn};
|
||||
use satrs::hal::std::tcp_spacepackets_server::CcsdsPacketParser;
|
||||
use satrs::tmtc::StoreAndSendError;
|
||||
use satrs::{
|
||||
encoding::ccsds::{SpValidity, SpacePacketValidator},
|
||||
hal::std::tcp_server::{HandledConnectionHandler, ServerConfig, TcpSpacepacketsServer},
|
||||
@@ -103,14 +103,16 @@ impl PacketSource for SyncTcpTmSource {
|
||||
}
|
||||
}
|
||||
|
||||
pub type TcpServer<ReceivesTc> = TcpSpacepacketsServer<
|
||||
pub type TcpServer<ReceivesTc, SendError> = TcpSpacepacketsServer<
|
||||
SyncTcpTmSource,
|
||||
ReceivesTc,
|
||||
SimplePacketValidator,
|
||||
ConnectionFinishedHandler,
|
||||
(),
|
||||
SendError,
|
||||
>;
|
||||
|
||||
pub struct TcpTask(pub TcpServer<TmTcSender>);
|
||||
pub struct TcpTask(pub TcpServer<TmTcSender, StoreAndSendError>);
|
||||
|
||||
impl TcpTask {
|
||||
pub fn new(
|
||||
@@ -122,7 +124,8 @@ impl TcpTask {
|
||||
Ok(Self(TcpSpacepacketsServer::new(
|
||||
cfg,
|
||||
tm_source,
|
||||
CcsdsPacketParser::new(cfg.id, 2048, tc_sender, SimplePacketValidator { valid_ids }),
|
||||
tc_sender,
|
||||
SimplePacketValidator { valid_ids },
|
||||
ConnectionFinishedHandler::default(),
|
||||
None,
|
||||
)?))
|
||||
|
||||
@@ -5,8 +5,7 @@ use std::sync::mpsc;
|
||||
use log::{info, warn};
|
||||
use satrs::hal::std::udp_server::{ReceiveResult, UdpTcServer};
|
||||
use satrs::pus::HandlingStatus;
|
||||
use satrs::queue::GenericSendError;
|
||||
use satrs::tmtc::PacketAsVec;
|
||||
use satrs::tmtc::{PacketAsVec, StoreAndSendError};
|
||||
|
||||
use satrs::pool::{PoolProviderWithGuards, SharedStaticMemoryPool};
|
||||
use satrs::tmtc::PacketInPool;
|
||||
@@ -69,7 +68,7 @@ impl UdpTmHandler for DynamicUdpTmHandler {
|
||||
}
|
||||
|
||||
pub struct UdpTmtcServer<TmHandler: UdpTmHandler> {
|
||||
pub udp_tc_server: UdpTcServer<TmTcSender, GenericSendError>,
|
||||
pub udp_tc_server: UdpTcServer<TmTcSender, StoreAndSendError>,
|
||||
pub tm_handler: TmHandler,
|
||||
}
|
||||
|
||||
@@ -116,7 +115,7 @@ mod tests {
|
||||
|
||||
use arbitrary_int::traits::Integer as _;
|
||||
use arbitrary_int::u14;
|
||||
use satrs::spacepackets::ecss::{CreatorConfig, MessageTypeId};
|
||||
use satrs::spacepackets::ecss::CreatorConfig;
|
||||
use satrs::{
|
||||
spacepackets::{
|
||||
ecss::{tc::PusTcCreator, WritablePusPacket},
|
||||
@@ -182,14 +181,9 @@ mod tests {
|
||||
tm_handler,
|
||||
};
|
||||
let sph = SpHeader::new_for_unseg_tc(ids::Apid::GenericPus.raw_value(), u14::ZERO, 0);
|
||||
let ping_tc = PusTcCreator::new_simple(
|
||||
sph,
|
||||
MessageTypeId::new(17, 1),
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
)
|
||||
.to_vec()
|
||||
.unwrap();
|
||||
let ping_tc = PusTcCreator::new_simple(sph, 17, 1, &[], CreatorConfig::default())
|
||||
.to_vec()
|
||||
.unwrap();
|
||||
let client = UdpSocket::bind("127.0.0.1:0").expect("Connecting to UDP server failed");
|
||||
let client_addr = client.local_addr().unwrap();
|
||||
println!("{}", server_addr);
|
||||
|
||||
@@ -161,7 +161,7 @@ impl PusTcToRequestConverter<ActivePusActionRequestStd, ActionRequest> for Actio
|
||||
verif_reporter: &impl VerificationReportingProvider,
|
||||
time_stamp: &[u8],
|
||||
) -> Result<(ActivePusActionRequestStd, ActionRequest), Self::Error> {
|
||||
let subservice = tc.message_subtype_id();
|
||||
let subservice = tc.subservice();
|
||||
let user_data = tc.user_data();
|
||||
if user_data.len() < 8 {
|
||||
verif_reporter
|
||||
@@ -270,14 +270,13 @@ impl TargetedPusService for ActionServiceWrapper {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use arbitrary_int::traits::Integer as _;
|
||||
use satrs::pus::test_util::{
|
||||
TEST_APID, TEST_COMPONENT_ID_0, TEST_COMPONENT_ID_1, TEST_UNIQUE_ID_0, TEST_UNIQUE_ID_1,
|
||||
};
|
||||
use satrs::pus::verification::test_util::TestVerificationReporter;
|
||||
use satrs::pus::{verification, EcssTcVecCacher};
|
||||
use satrs::request::MessageMetadata;
|
||||
use satrs::spacepackets::ecss::{CreatorConfig, MessageTypeId};
|
||||
use satrs::spacepackets::ecss::CreatorConfig;
|
||||
use satrs::tmtc::PacketAsVec;
|
||||
use satrs::ComponentId;
|
||||
use satrs::{
|
||||
@@ -450,10 +449,10 @@ mod tests {
|
||||
);
|
||||
// Create a basic action request and verify forwarding.
|
||||
let sp_header = SpHeader::new_from_apid(TEST_APID);
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(8, 128));
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(8, 128);
|
||||
let action_id = 5_u32;
|
||||
let mut app_data: [u8; 8] = [0; 8];
|
||||
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_1.as_u32().to_be_bytes());
|
||||
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_1.to_be_bytes());
|
||||
app_data[4..8].copy_from_slice(&action_id.to_be_bytes());
|
||||
let pus8_packet =
|
||||
PusTcCreator::new(sp_header, sec_header, &app_data, CreatorConfig::default());
|
||||
@@ -492,7 +491,7 @@ mod tests {
|
||||
TEST_COMPONENT_ID_1.id(),
|
||||
);
|
||||
// Create a basic action request and verify forwarding.
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(8, 128));
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(8, 128);
|
||||
let action_id = 5_u32;
|
||||
let mut app_data: [u8; 8] = [0; 8];
|
||||
// Invalid ID, routing should fail.
|
||||
@@ -518,11 +517,11 @@ mod tests {
|
||||
TEST_COMPONENT_ID_0.raw(),
|
||||
ActionRequestConverter::default(),
|
||||
);
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(8, 128));
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(8, 128);
|
||||
let action_id = 5_u32;
|
||||
let mut app_data: [u8; 8] = [0; 8];
|
||||
// Invalid ID, routing should fail.
|
||||
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.as_u32().to_be_bytes());
|
||||
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.to_be_bytes());
|
||||
app_data[4..8].copy_from_slice(&action_id.to_be_bytes());
|
||||
let pus8_packet = PusTcCreator::new(
|
||||
SpHeader::new_from_apid(TEST_APID),
|
||||
@@ -554,11 +553,11 @@ mod tests {
|
||||
fn converter_action_req_with_data() {
|
||||
let mut testbench =
|
||||
PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ActionRequestConverter::default());
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(8, 128));
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(8, 128);
|
||||
let action_id = 5_u32;
|
||||
let mut app_data: [u8; 16] = [0; 16];
|
||||
// Invalid ID, routing should fail.
|
||||
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.as_u32().to_be_bytes());
|
||||
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.to_be_bytes());
|
||||
app_data[4..8].copy_from_slice(&action_id.to_be_bytes());
|
||||
for i in 0..8 {
|
||||
app_data[i + 8] = i as u8;
|
||||
@@ -697,7 +696,7 @@ mod tests {
|
||||
ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), ActionReplyHandler::default());
|
||||
let action_reply = ActionReplyPus::new(5_u32, ActionReplyVariant::Completed);
|
||||
let unrequested_reply =
|
||||
GenericMessage::new(MessageMetadata::new(10_u32, 15_u32), action_reply);
|
||||
GenericMessage::new(MessageMetadata::new(10_u32, 15_u64), action_reply);
|
||||
// Right now this function does not do a lot. We simply check that it does not panic or do
|
||||
// weird stuff.
|
||||
let result = testbench.handle_unrequested_reply(&unrequested_reply);
|
||||
|
||||
@@ -164,7 +164,7 @@ impl PusTcToRequestConverter<ActivePusRequestStd, HkRequest> for HkRequestConver
|
||||
found: 4,
|
||||
});
|
||||
}
|
||||
let subservice = tc.message_subtype_id();
|
||||
let subservice = tc.subservice();
|
||||
let target_id_and_apid = UniqueApidTargetId::from_pus_tc(tc).expect("invalid tc format");
|
||||
let unique_id = u32::from_be_bytes(tc.user_data()[4..8].try_into().unwrap());
|
||||
|
||||
@@ -303,12 +303,12 @@ impl TargetedPusService for HkServiceWrapper {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use arbitrary_int::traits::Integer as _;
|
||||
use arbitrary_int::{u14, u21};
|
||||
use arbitrary_int::u14;
|
||||
use satrs::pus::test_util::{
|
||||
TEST_COMPONENT_ID_0, TEST_COMPONENT_ID_1, TEST_UNIQUE_ID_0, TEST_UNIQUE_ID_1,
|
||||
};
|
||||
use satrs::request::MessageMetadata;
|
||||
use satrs::spacepackets::ecss::{CreatorConfig, MessageTypeId};
|
||||
use satrs::spacepackets::ecss::CreatorConfig;
|
||||
use satrs::{
|
||||
hk::HkRequestVariant,
|
||||
pus::test_util::TEST_APID,
|
||||
@@ -335,12 +335,13 @@ mod tests {
|
||||
let target_id = TEST_UNIQUE_ID_0;
|
||||
let unique_id = 5_u32;
|
||||
let mut app_data: [u8; 8] = [0; 8];
|
||||
app_data[0..4].copy_from_slice(&target_id.as_u32().to_be_bytes());
|
||||
app_data[0..4].copy_from_slice(&target_id.to_be_bytes());
|
||||
app_data[4..8].copy_from_slice(&unique_id.to_be_bytes());
|
||||
|
||||
let hk_req = PusTcCreator::new_simple(
|
||||
sp_header,
|
||||
MessageTypeId::new(3, Subservice::TcGenerateOneShotHk as u8),
|
||||
3,
|
||||
Subservice::TcGenerateOneShotHk as u8,
|
||||
&app_data,
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
@@ -364,7 +365,7 @@ mod tests {
|
||||
let target_id = TEST_UNIQUE_ID_0;
|
||||
let unique_id = 5_u32;
|
||||
let mut app_data: [u8; 8] = [0; 8];
|
||||
app_data[0..4].copy_from_slice(&target_id.as_u32().to_be_bytes());
|
||||
app_data[0..4].copy_from_slice(&target_id.to_be_bytes());
|
||||
app_data[4..8].copy_from_slice(&unique_id.to_be_bytes());
|
||||
let mut generic_check = |tc: &PusTcCreator| {
|
||||
let accepted_token = hk_bench.add_tc(tc);
|
||||
@@ -379,14 +380,16 @@ mod tests {
|
||||
};
|
||||
let tc0 = PusTcCreator::new_simple(
|
||||
sp_header,
|
||||
MessageTypeId::new(3, Subservice::TcEnableHkGeneration as u8),
|
||||
3,
|
||||
Subservice::TcEnableHkGeneration as u8,
|
||||
&app_data,
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
generic_check(&tc0);
|
||||
let tc1 = PusTcCreator::new_simple(
|
||||
sp_header,
|
||||
MessageTypeId::new(3, Subservice::TcEnableDiagGeneration as u8),
|
||||
3,
|
||||
Subservice::TcEnableDiagGeneration as u8,
|
||||
&app_data,
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
@@ -401,7 +404,7 @@ mod tests {
|
||||
let target_id = TEST_UNIQUE_ID_0;
|
||||
let unique_id = 5_u32;
|
||||
let mut app_data: [u8; 8] = [0; 8];
|
||||
app_data[0..4].copy_from_slice(&target_id.as_u32().to_be_bytes());
|
||||
app_data[0..4].copy_from_slice(&target_id.to_be_bytes());
|
||||
app_data[4..8].copy_from_slice(&unique_id.to_be_bytes());
|
||||
let mut generic_check = |tc: &PusTcCreator| {
|
||||
let accepted_token = hk_bench.add_tc(tc);
|
||||
@@ -416,14 +419,16 @@ mod tests {
|
||||
};
|
||||
let tc0 = PusTcCreator::new_simple(
|
||||
sp_header,
|
||||
MessageTypeId::new(3, Subservice::TcDisableHkGeneration as u8),
|
||||
3,
|
||||
Subservice::TcDisableHkGeneration as u8,
|
||||
&app_data,
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
generic_check(&tc0);
|
||||
let tc1 = PusTcCreator::new_simple(
|
||||
sp_header,
|
||||
MessageTypeId::new(3, Subservice::TcDisableDiagGeneration as u8),
|
||||
3,
|
||||
Subservice::TcDisableDiagGeneration as u8,
|
||||
&app_data,
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
@@ -439,7 +444,7 @@ mod tests {
|
||||
let unique_id = 5_u32;
|
||||
let mut app_data: [u8; 12] = [0; 12];
|
||||
let collection_interval_factor = 5_u32;
|
||||
app_data[0..4].copy_from_slice(&target_id.as_u32().to_be_bytes());
|
||||
app_data[0..4].copy_from_slice(&target_id.to_be_bytes());
|
||||
app_data[4..8].copy_from_slice(&unique_id.to_be_bytes());
|
||||
app_data[8..12].copy_from_slice(&collection_interval_factor.to_be_bytes());
|
||||
|
||||
@@ -457,14 +462,16 @@ mod tests {
|
||||
};
|
||||
let tc0 = PusTcCreator::new_simple(
|
||||
sp_header,
|
||||
MessageTypeId::new(3, Subservice::TcModifyHkCollectionInterval as u8),
|
||||
3,
|
||||
Subservice::TcModifyHkCollectionInterval as u8,
|
||||
&app_data,
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
generic_check(&tc0);
|
||||
let tc1 = PusTcCreator::new_simple(
|
||||
sp_header,
|
||||
MessageTypeId::new(3, Subservice::TcModifyDiagCollectionInterval as u8),
|
||||
3,
|
||||
Subservice::TcModifyDiagCollectionInterval as u8,
|
||||
&app_data,
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
@@ -475,8 +482,8 @@ mod tests {
|
||||
fn hk_reply_handler() {
|
||||
let mut reply_testbench =
|
||||
ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), HkReplyHandler::default());
|
||||
let sender_id = 2_u32;
|
||||
let apid_target_id = u21::new(3);
|
||||
let sender_id = 2_u64;
|
||||
let apid_target_id = 3_u32;
|
||||
let unique_id = 5_u32;
|
||||
let (req_id, active_req) = reply_testbench.add_tc(TEST_APID, apid_target_id, &[]);
|
||||
let reply = GenericMessage::new(
|
||||
@@ -497,7 +504,7 @@ mod tests {
|
||||
ReplyHandlerTestbench::new(TEST_COMPONENT_ID_1.id(), HkReplyHandler::default());
|
||||
let action_reply = HkReply::new(5_u32, HkReplyVariant::Ack);
|
||||
let unrequested_reply =
|
||||
GenericMessage::new(MessageMetadata::new(10_u32, 15_u32), action_reply);
|
||||
GenericMessage::new(MessageMetadata::new(10_u32, 15_u64), action_reply);
|
||||
// Right now this function does not do a lot. We simply check that it does not panic or do
|
||||
// weird stuff.
|
||||
let result = testbench.handle_unrequested_reply(&unrequested_reply);
|
||||
|
||||
@@ -113,7 +113,7 @@ impl PusTcDistributor {
|
||||
.verif_reporter
|
||||
.acceptance_success(&self.tm_sender, init_token, self.stamp_helper.stamp())
|
||||
.expect("Acceptance success failure");
|
||||
let service = PusServiceId::try_from(pus_tc.service_type_id());
|
||||
let service = PusServiceId::try_from(pus_tc.service());
|
||||
let tc_in_memory: TcInMemory = if let Some(store_addr) = addr_opt {
|
||||
PacketInPool::new(sender_id, store_addr).into()
|
||||
} else {
|
||||
@@ -531,11 +531,11 @@ pub fn generic_pus_request_timeout_handler(
|
||||
pub(crate) mod tests {
|
||||
use std::time::Duration;
|
||||
|
||||
use arbitrary_int::{u11, u21};
|
||||
use arbitrary_int::u11;
|
||||
use satrs::pus::test_util::TEST_COMPONENT_ID_0;
|
||||
use satrs::pus::{MpscTmAsVecSender, PusTmVariant};
|
||||
use satrs::request::RequestId;
|
||||
use satrs::spacepackets::ecss::{CreatorConfig, MessageTypeId};
|
||||
use satrs::spacepackets::ecss::CreatorConfig;
|
||||
use satrs::{
|
||||
pus::{
|
||||
verification::test_util::TestVerificationReporter, ActivePusRequestStd,
|
||||
@@ -593,11 +593,11 @@ pub(crate) mod tests {
|
||||
pub fn add_tc(
|
||||
&mut self,
|
||||
apid: u11,
|
||||
apid_target: u21,
|
||||
apid_target: u32,
|
||||
time_stamp: &[u8],
|
||||
) -> (verification::RequestId, ActivePusRequestStd) {
|
||||
let sp_header = SpHeader::new_from_apid(apid);
|
||||
let sec_header_dummy = PusTcSecondaryHeader::new_simple(MessageTypeId::new(0, 0));
|
||||
let sec_header_dummy = PusTcSecondaryHeader::new_simple(0, 0);
|
||||
let init = self.verif_reporter.start_verification(&PusTcCreator::new(
|
||||
sp_header,
|
||||
sec_header_dummy,
|
||||
@@ -722,7 +722,7 @@ pub(crate) mod tests {
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
time_stamp: &[u8],
|
||||
expected_apid: u11,
|
||||
expected_apid_target: u21,
|
||||
expected_apid_target: u32,
|
||||
) -> Result<(ActiveRequestInfo, Request), Converter::Error> {
|
||||
if self.current_packet.is_none() {
|
||||
return Err(GenericConversionError::InvalidAppData(
|
||||
|
||||
@@ -2,7 +2,7 @@ use arbitrary_int::traits::Integer as _;
|
||||
use arbitrary_int::u14;
|
||||
use derive_new::new;
|
||||
use satrs::mode_tree::{ModeNode, ModeParent};
|
||||
use satrs::spacepackets::ecss::{CreatorConfig, MessageTypeId};
|
||||
use satrs::spacepackets::ecss::CreatorConfig;
|
||||
use satrs_example::ids;
|
||||
use std::sync::mpsc;
|
||||
use std::time::Duration;
|
||||
@@ -81,12 +81,8 @@ impl PusReplyHandler<ActivePusRequestStd, ModeReply> for ModeReplyHandler {
|
||||
.expect("writing mode reply failed");
|
||||
let req_id = verification::RequestId::from(reply.request_id());
|
||||
let sp_header = SpHeader::new_for_unseg_tm(req_id.packet_id().apid(), u14::ZERO, 0);
|
||||
let sec_header = PusTmSecondaryHeader::new(
|
||||
MessageTypeId::new(200, Subservice::TmModeReply as u8),
|
||||
0,
|
||||
0,
|
||||
time_stamp,
|
||||
);
|
||||
let sec_header =
|
||||
PusTmSecondaryHeader::new(200, Subservice::TmModeReply as u8, 0, 0, time_stamp);
|
||||
let pus_tm = PusTmCreator::new(
|
||||
sp_header,
|
||||
sec_header,
|
||||
@@ -158,7 +154,7 @@ impl PusTcToRequestConverter<ActivePusRequestStd, ModeRequest> for ModeRequestCo
|
||||
verif_reporter: &impl VerificationReportingProvider,
|
||||
time_stamp: &[u8],
|
||||
) -> Result<(ActivePusRequestStd, ModeRequest), Self::Error> {
|
||||
let subservice = tc.message_subtype_id();
|
||||
let subservice = tc.subservice();
|
||||
let user_data = tc.user_data();
|
||||
let not_enough_app_data = |expected: usize| {
|
||||
verif_reporter
|
||||
@@ -306,7 +302,7 @@ mod tests {
|
||||
use arbitrary_int::u14;
|
||||
use satrs::pus::test_util::{TEST_APID, TEST_COMPONENT_ID_0, TEST_UNIQUE_ID_0};
|
||||
use satrs::request::MessageMetadata;
|
||||
use satrs::spacepackets::ecss::{CreatorConfig, MessageTypeId};
|
||||
use satrs::spacepackets::ecss::CreatorConfig;
|
||||
use satrs::{
|
||||
mode::{ModeAndSubmode, ModeReply, ModeRequest},
|
||||
pus::mode::Subservice,
|
||||
@@ -330,10 +326,9 @@ mod tests {
|
||||
let mut testbench =
|
||||
PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ModeRequestConverter::default());
|
||||
let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, u14::ZERO, 0);
|
||||
let sec_header =
|
||||
PusTcSecondaryHeader::new_simple(MessageTypeId::new(200, Subservice::TcReadMode as u8));
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(200, Subservice::TcReadMode as u8);
|
||||
let mut app_data: [u8; 4] = [0; 4];
|
||||
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.as_u32().to_be_bytes());
|
||||
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.to_be_bytes());
|
||||
let tc = PusTcCreator::new(sp_header, sec_header, &app_data, CreatorConfig::default());
|
||||
let token = testbench.add_tc(&tc);
|
||||
let (_active_req, req) = testbench
|
||||
@@ -347,11 +342,10 @@ mod tests {
|
||||
let mut testbench =
|
||||
PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ModeRequestConverter::default());
|
||||
let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, u14::ZERO, 0);
|
||||
let sec_header =
|
||||
PusTcSecondaryHeader::new_simple(MessageTypeId::new(200, Subservice::TcSetMode as u8));
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(200, Subservice::TcSetMode as u8);
|
||||
let mut app_data: [u8; 4 + ModeAndSubmode::RAW_LEN] = [0; 4 + ModeAndSubmode::RAW_LEN];
|
||||
let mode_and_submode = ModeAndSubmode::new(2, 1);
|
||||
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.as_u32().to_be_bytes());
|
||||
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.to_be_bytes());
|
||||
mode_and_submode
|
||||
.write_to_be_bytes(&mut app_data[4..])
|
||||
.unwrap();
|
||||
@@ -374,12 +368,9 @@ mod tests {
|
||||
let mut testbench =
|
||||
PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ModeRequestConverter::default());
|
||||
let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, u14::ZERO, 0);
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(
|
||||
200,
|
||||
Subservice::TcAnnounceMode as u8,
|
||||
));
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(200, Subservice::TcAnnounceMode as u8);
|
||||
let mut app_data: [u8; 4] = [0; 4];
|
||||
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.as_u32().to_be_bytes());
|
||||
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.to_be_bytes());
|
||||
let tc = PusTcCreator::new(sp_header, sec_header, &app_data, CreatorConfig::default());
|
||||
let token = testbench.add_tc(&tc);
|
||||
let (_active_req, req) = testbench
|
||||
@@ -393,12 +384,10 @@ mod tests {
|
||||
let mut testbench =
|
||||
PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ModeRequestConverter::default());
|
||||
let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, u14::ZERO, 0);
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(
|
||||
200,
|
||||
Subservice::TcAnnounceModeRecursive as u8,
|
||||
));
|
||||
let sec_header =
|
||||
PusTcSecondaryHeader::new_simple(200, Subservice::TcAnnounceModeRecursive as u8);
|
||||
let mut app_data: [u8; 4] = [0; 4];
|
||||
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.as_u32().to_be_bytes());
|
||||
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.to_be_bytes());
|
||||
let tc = PusTcCreator::new(sp_header, sec_header, &app_data, CreatorConfig::default());
|
||||
let token = testbench.add_tc(&tc);
|
||||
let (_active_req, req) = testbench
|
||||
@@ -415,7 +404,7 @@ mod tests {
|
||||
);
|
||||
let mode_reply = ModeReply::ModeReply(ModeAndSubmode::new(5, 1));
|
||||
let unrequested_reply =
|
||||
GenericMessage::new(MessageMetadata::new(10_u32, 15_u32), mode_reply);
|
||||
GenericMessage::new(MessageMetadata::new(10_u32, 15_u64), mode_reply);
|
||||
// Right now this function does not do a lot. We simply check that it does not panic or do
|
||||
// weird stuff.
|
||||
let result = testbench.handle_unrequested_reply(&unrequested_reply);
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::pus::create_verification_reporter;
|
||||
use crate::tmtc::sender::TmTcSender;
|
||||
use log::info;
|
||||
use satrs::pool::{PoolProvider, StaticMemoryPool};
|
||||
use satrs::pus::scheduler::{PusScheduler, TcInfo};
|
||||
use satrs::pus::scheduler::{PusSchedulerAlloc, TcInfo};
|
||||
use satrs::pus::scheduler_srv::PusSchedServiceHandler;
|
||||
use satrs::pus::verification::VerificationReporter;
|
||||
use satrs::pus::{
|
||||
@@ -86,7 +86,7 @@ pub struct SchedulingServiceWrapper {
|
||||
TmTcSender,
|
||||
EcssTcCacher,
|
||||
VerificationReporter,
|
||||
PusScheduler,
|
||||
PusSchedulerAlloc,
|
||||
>,
|
||||
pub sched_tc_pool: StaticMemoryPool,
|
||||
pub releaser_buf: [u8; 4096],
|
||||
@@ -179,7 +179,7 @@ pub fn create_scheduler_service(
|
||||
pus_sched_rx: mpsc::Receiver<EcssTcAndToken>,
|
||||
sched_tc_pool: StaticMemoryPool,
|
||||
) -> SchedulingServiceWrapper {
|
||||
let scheduler = PusScheduler::new_with_current_init_time(Duration::from_secs(5))
|
||||
let scheduler = PusSchedulerAlloc::new_with_current_init_time(Duration::from_secs(5))
|
||||
.expect("Creating PUS Scheduler failed");
|
||||
let pus_11_handler = PusSchedServiceHandler::new(
|
||||
PusServiceHelper::new(
|
||||
|
||||
@@ -122,7 +122,7 @@ impl DirectPusService for TestCustomServiceWrapper {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let fail_data = [tc.message_subtype_id()];
|
||||
let fail_data = [tc.subservice()];
|
||||
self.handler
|
||||
.service_helper
|
||||
.verif_reporter()
|
||||
|
||||
@@ -55,7 +55,7 @@ impl GenericRequestRouter {
|
||||
) {
|
||||
warn!(
|
||||
"Routing request for service {} failed: {error:?}",
|
||||
tc.service_type_id()
|
||||
tc.service()
|
||||
);
|
||||
let accepted_token: VerificationToken<TcStateAccepted> = active_request
|
||||
.token()
|
||||
@@ -66,8 +66,7 @@ impl GenericRequestRouter {
|
||||
let apid_target_id = UniqueApidTargetId::from(id);
|
||||
warn!("Target APID for request: {}", apid_target_id.apid);
|
||||
warn!("Target Unique ID for request: {}", apid_target_id.unique_id);
|
||||
let mut fail_data: [u8; core::mem::size_of::<ComponentId>()] =
|
||||
[0; core::mem::size_of::<ComponentId>()];
|
||||
let mut fail_data: [u8; 8] = [0; 8];
|
||||
fail_data.copy_from_slice(&id.to_be_bytes());
|
||||
verif_reporter
|
||||
.completion_failure(
|
||||
|
||||
@@ -4,7 +4,7 @@ use satrs::{
|
||||
pus::EcssTmSender,
|
||||
queue::GenericSendError,
|
||||
spacepackets::ecss::WritablePusPacket,
|
||||
tmtc::{PacketAsVec, PacketHandler, PacketSenderWithSharedPool},
|
||||
tmtc::{PacketAsVec, PacketSenderRaw, PacketSenderWithSharedPool, StoreAndSendError},
|
||||
ComponentId,
|
||||
};
|
||||
|
||||
@@ -48,33 +48,26 @@ impl EcssTmSender for TmTcSender {
|
||||
}
|
||||
}
|
||||
|
||||
impl PacketHandler for TmTcSender {
|
||||
type Error = GenericSendError;
|
||||
impl PacketSenderRaw for TmTcSender {
|
||||
type Error = StoreAndSendError;
|
||||
|
||||
fn handle_packet(&self, sender_id: ComponentId, packet: &[u8]) -> Result<(), Self::Error> {
|
||||
fn send_packet(&self, sender_id: ComponentId, packet: &[u8]) -> Result<(), Self::Error> {
|
||||
match self {
|
||||
TmTcSender::Static(packet_sender_with_shared_pool) => {
|
||||
if let Err(e) = packet_sender_with_shared_pool.handle_packet(sender_id, packet) {
|
||||
log::error!("Error sending packet via Static TM/TC sender: {:?}", e);
|
||||
}
|
||||
}
|
||||
TmTcSender::Heap(sync_sender) => {
|
||||
if let Err(e) = sync_sender.handle_packet(sender_id, packet) {
|
||||
log::error!("Error sending packet via Heap TM/TC sender: {:?}", e);
|
||||
}
|
||||
}
|
||||
TmTcSender::Mock(sender) => {
|
||||
sender.handle_packet(sender_id, packet).unwrap();
|
||||
packet_sender_with_shared_pool.send_packet(sender_id, packet)
|
||||
}
|
||||
TmTcSender::Heap(sync_sender) => sync_sender
|
||||
.send_packet(sender_id, packet)
|
||||
.map_err(StoreAndSendError::Send),
|
||||
TmTcSender::Mock(sender) => sender.send_packet(sender_id, packet),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl PacketHandler for MockSender {
|
||||
type Error = GenericSendError;
|
||||
impl PacketSenderRaw for MockSender {
|
||||
type Error = StoreAndSendError;
|
||||
|
||||
fn handle_packet(&self, sender_id: ComponentId, tc_raw: &[u8]) -> Result<(), Self::Error> {
|
||||
fn send_packet(&self, sender_id: ComponentId, tc_raw: &[u8]) -> Result<(), Self::Error> {
|
||||
let mut mut_queue = self.0.borrow_mut();
|
||||
mut_queue.push_back(PacketAsVec::new(sender_id, tc_raw.to_vec()));
|
||||
Ok(())
|
||||
|
||||
@@ -59,7 +59,7 @@ impl TmFunnelCommon {
|
||||
);
|
||||
let entry = self
|
||||
.msg_counter_map
|
||||
.entry(zero_copy_writer.service_type_id())
|
||||
.entry(zero_copy_writer.service())
|
||||
.or_insert(0);
|
||||
zero_copy_writer.set_msg_count(*entry);
|
||||
if *entry == u16::MAX {
|
||||
@@ -76,8 +76,8 @@ impl TmFunnelCommon {
|
||||
fn packet_printout(tm: &PusTmZeroCopyWriter) {
|
||||
info!(
|
||||
"Sending PUS TM[{},{}] with APID {}",
|
||||
tm.service_type_id(),
|
||||
tm.message_subtype_id(),
|
||||
tm.service(),
|
||||
tm.subservice(),
|
||||
tm.apid()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,9 +11,17 @@ license = "Apache-2.0"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
spacepackets = { version = "0.17", git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git", default-features = false }
|
||||
serde = { version = "1", default-features = false, optional = true }
|
||||
defmt = {version = "1", optional = true }
|
||||
spacepackets = { version = ">=0.14, <=0.16", default-features = false }
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1"
|
||||
default-features = false
|
||||
optional = true
|
||||
|
||||
[dependencies.defmt]
|
||||
version = "1"
|
||||
optional = true
|
||||
|
||||
|
||||
[features]
|
||||
serde = ["dep:serde", "spacepackets/serde"]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! This crates contains modules shared among other sat-rs framework crates.
|
||||
#![no_std]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
pub mod res_code;
|
||||
|
||||
@@ -14,7 +14,6 @@ pub struct ResultU16 {
|
||||
}
|
||||
|
||||
impl ResultU16 {
|
||||
#[inline]
|
||||
pub const fn new(group_id: u8, unique_id: u8) -> Self {
|
||||
Self {
|
||||
group_id,
|
||||
@@ -22,22 +21,18 @@ impl ResultU16 {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub const fn raw(&self) -> u16 {
|
||||
pub fn raw(&self) -> u16 {
|
||||
((self.group_id as u16) << 8) | self.unique_id as u16
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub const fn group_id(&self) -> u8 {
|
||||
pub fn group_id(&self) -> u8 {
|
||||
self.group_id
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub const fn unique_id(&self) -> u8 {
|
||||
pub fn unique_id(&self) -> u8 {
|
||||
self.unique_id
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_be_bytes(bytes: [u8; 2]) -> Self {
|
||||
Self::from(u16::from_be_bytes(bytes))
|
||||
}
|
||||
@@ -56,7 +51,6 @@ impl From<ResultU16> for EcssEnumU16 {
|
||||
}
|
||||
|
||||
impl UnsignedEnum for ResultU16 {
|
||||
#[inline]
|
||||
fn size(&self) -> usize {
|
||||
core::mem::size_of::<u16>()
|
||||
}
|
||||
@@ -73,14 +67,12 @@ impl UnsignedEnum for ResultU16 {
|
||||
Ok(self.size())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn value_raw(&self) -> u64 {
|
||||
fn value(&self) -> u64 {
|
||||
self.raw() as u64
|
||||
}
|
||||
}
|
||||
|
||||
impl EcssEnumeration for ResultU16 {
|
||||
#[inline]
|
||||
fn pfc(&self) -> u8 {
|
||||
16
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
- Bump `sat-rs` edition to 2024.
|
||||
- Bumped `spacepackets` to v0.16
|
||||
- `ComponentId` is u32 now
|
||||
- Simplified TCP servers
|
||||
|
||||
## Changed
|
||||
|
||||
|
||||
@@ -14,16 +14,16 @@ categories = ["aerospace", "aerospace::space-protocols", "no-std", "hardware-sup
|
||||
|
||||
[dependencies]
|
||||
satrs-shared = { version = "0.2", path = "../satrs-shared" }
|
||||
spacepackets = { version = "0.17", git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git", default-features = false }
|
||||
spacepackets = { version = "0.16", default-features = false }
|
||||
|
||||
delegate = "0.13"
|
||||
delegate = ">0.7, <=0.13"
|
||||
paste = "1"
|
||||
derive-new = "0.7"
|
||||
num_enum = { version = "0.7", default-features = false }
|
||||
cobs = { version = "0.5", default-features = false }
|
||||
derive-new = ">=0.6, <=0.7"
|
||||
num_enum = { version = ">0.5, <=0.7", default-features = false }
|
||||
cobs = { version = "0.4", default-features = false }
|
||||
thiserror = { version = "2", default-features = false }
|
||||
|
||||
hashbrown = { version = "0.16", optional = true }
|
||||
hashbrown = { version = ">=0.14, <=0.15", optional = true }
|
||||
static_cell = { version = "2" }
|
||||
heapless = { version = "0.9", optional = true }
|
||||
dyn-clone = { version = "1", optional = true }
|
||||
@@ -64,7 +64,6 @@ std = [
|
||||
]
|
||||
alloc = [
|
||||
"serde/alloc",
|
||||
"cobs/alloc",
|
||||
"spacepackets/alloc",
|
||||
"hashbrown",
|
||||
"dyn-clone",
|
||||
@@ -72,6 +71,7 @@ alloc = [
|
||||
]
|
||||
serde = ["dep:serde", "spacepackets/serde", "satrs-shared/serde"]
|
||||
crossbeam = ["crossbeam-channel"]
|
||||
# heapless = ["dep:heapless", "static_cell"]
|
||||
defmt = ["dep:defmt", "spacepackets/defmt"]
|
||||
test_util = []
|
||||
|
||||
|
||||
1
satrs/src/ccsds/mod.rs
Normal file
1
satrs/src/ccsds/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod scheduler;
|
||||
129
satrs/src/ccsds/scheduler.rs
Normal file
129
satrs/src/ccsds/scheduler.rs
Normal file
@@ -0,0 +1,129 @@
|
||||
use core::{hash::Hash, time::Duration};
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub use alloc_mod::*;
|
||||
use spacepackets::{
|
||||
ByteConversionError, PacketId, PacketSequenceControl,
|
||||
time::{TimestampError, UnixTime},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum ScheduleError {
|
||||
/// The release time is within the time-margin added on top of the current time.
|
||||
/// The first parameter is the current time, the second one the time margin, and the third one
|
||||
/// the release time.
|
||||
#[error("release time in margin")]
|
||||
ReleaseTimeInTimeMargin {
|
||||
current_time: UnixTime,
|
||||
time_margin: Duration,
|
||||
release_time: UnixTime,
|
||||
},
|
||||
/// Nested time-tagged commands are not allowed.
|
||||
#[error("nested scheduled tc")]
|
||||
NestedScheduledTc,
|
||||
#[error("tc data empty")]
|
||||
TcDataEmpty,
|
||||
#[error("timestamp error: {0}")]
|
||||
TimestampError(#[from] TimestampError),
|
||||
#[error("wrong subservice number {0}")]
|
||||
WrongSubservice(u8),
|
||||
#[error("wrong service number {0}")]
|
||||
WrongService(u8),
|
||||
#[error("byte conversion error: {0}")]
|
||||
ByteConversionError(#[from] ByteConversionError),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct CcsdsPacketId {
|
||||
pub packet_id: PacketId,
|
||||
pub psc: PacketSequenceControl,
|
||||
pub crc16: u16,
|
||||
}
|
||||
|
||||
impl Hash for CcsdsPacketId {
|
||||
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
|
||||
self.packet_id.hash(state);
|
||||
self.psc.raw().hash(state);
|
||||
self.crc16.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
pub mod alloc_mod {
|
||||
use core::time::Duration;
|
||||
#[cfg(feature = "std")]
|
||||
use std::time::SystemTimeError;
|
||||
|
||||
use spacepackets::time::UnixTime;
|
||||
|
||||
use crate::ccsds::scheduler::CcsdsPacketId;
|
||||
|
||||
pub struct CcsdsScheduler {
|
||||
tc_map: alloc::collections::BTreeMap<
|
||||
UnixTime,
|
||||
alloc::vec::Vec<(CcsdsPacketId, alloc::vec::Vec<u8>)>,
|
||||
>,
|
||||
packet_limit: usize,
|
||||
pub(crate) current_time: UnixTime,
|
||||
time_margin: Duration,
|
||||
enabled: bool,
|
||||
}
|
||||
|
||||
impl CcsdsScheduler {
|
||||
pub fn new(current_time: UnixTime, packet_limit: usize, time_margin: Duration) -> Self {
|
||||
Self {
|
||||
tc_map: alloc::collections::BTreeMap::new(),
|
||||
packet_limit,
|
||||
current_time,
|
||||
time_margin,
|
||||
enabled: true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Like [Self::new], but sets the `init_current_time` parameter to the current system time.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn new_with_current_init_time(
|
||||
packet_limit: usize,
|
||||
time_margin: Duration,
|
||||
) -> Result<Self, SystemTimeError> {
|
||||
Ok(Self::new(UnixTime::now()?, packet_limit, time_margin))
|
||||
}
|
||||
|
||||
pub fn num_of_entries(&self) -> usize {
|
||||
self.tc_map
|
||||
.values()
|
||||
.map(|v| v.iter().map(|(_, v)| v.len()).sum::<usize>())
|
||||
.sum()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn enable(&mut self) {
|
||||
self.enabled = true;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn disable(&mut self) {
|
||||
self.enabled = false;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn update_time(&mut self, current_time: UnixTime) {
|
||||
self.current_time = current_time;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn current_time(&self) -> &UnixTime {
|
||||
&self.current_time
|
||||
}
|
||||
|
||||
// TODO: Implementation
|
||||
pub fn insert_telecommand(
|
||||
&mut self,
|
||||
packet_id: CcsdsPacketId,
|
||||
packet: alloc::vec::Vec<u8>,
|
||||
release_time: UnixTime,
|
||||
) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -296,18 +296,18 @@ mod tests {
|
||||
fn test_mode_announce() {
|
||||
let mut assy_helper = DevManagerCommandingHelper::new(TransparentDevManagerHook::default());
|
||||
let mode_req_sender = ModeReqSenderMock::default();
|
||||
assy_helper.add_mode_child(ExampleId::Id1 as ComponentId, UNKNOWN_MODE);
|
||||
assy_helper.add_mode_child(ExampleId::Id2 as ComponentId, UNKNOWN_MODE);
|
||||
assy_helper.add_mode_child(ExampleId::Id1 as u64, UNKNOWN_MODE);
|
||||
assy_helper.add_mode_child(ExampleId::Id2 as u64, UNKNOWN_MODE);
|
||||
assy_helper
|
||||
.send_announce_mode_cmd_to_children(1, &mode_req_sender, false)
|
||||
.unwrap();
|
||||
assert_eq!(mode_req_sender.requests.borrow().len(), 2);
|
||||
let mut req = mode_req_sender.requests.borrow_mut().pop_front().unwrap();
|
||||
assert_eq!(req.target_id, ExampleId::Id1 as ComponentId);
|
||||
assert_eq!(req.target_id, ExampleId::Id1 as u64);
|
||||
assert_eq!(req.request_id, 1);
|
||||
assert_eq!(req.request, ModeRequest::AnnounceMode);
|
||||
req = mode_req_sender.requests.borrow_mut().pop_front().unwrap();
|
||||
assert_eq!(req.target_id, ExampleId::Id2 as ComponentId);
|
||||
assert_eq!(req.target_id, ExampleId::Id2 as u64);
|
||||
assert_eq!(req.request_id, 1);
|
||||
assert_eq!(req.request, ModeRequest::AnnounceMode);
|
||||
}
|
||||
@@ -316,18 +316,18 @@ mod tests {
|
||||
fn test_mode_announce_recursive() {
|
||||
let mut assy_helper = DevManagerCommandingHelper::new(TransparentDevManagerHook::default());
|
||||
let mode_req_sender = ModeReqSenderMock::default();
|
||||
assy_helper.add_mode_child(ExampleId::Id1 as ComponentId, UNKNOWN_MODE);
|
||||
assy_helper.add_mode_child(ExampleId::Id2 as ComponentId, UNKNOWN_MODE);
|
||||
assy_helper.add_mode_child(ExampleId::Id1 as u64, UNKNOWN_MODE);
|
||||
assy_helper.add_mode_child(ExampleId::Id2 as u64, UNKNOWN_MODE);
|
||||
assy_helper
|
||||
.send_announce_mode_cmd_to_children(1, &mode_req_sender, true)
|
||||
.unwrap();
|
||||
assert_eq!(mode_req_sender.requests.borrow().len(), 2);
|
||||
let mut req = mode_req_sender.requests.borrow_mut().pop_front().unwrap();
|
||||
assert_eq!(req.target_id, ExampleId::Id1 as ComponentId);
|
||||
assert_eq!(req.target_id, ExampleId::Id1 as u64);
|
||||
assert_eq!(req.request_id, 1);
|
||||
assert_eq!(req.request, ModeRequest::AnnounceModeRecursive);
|
||||
req = mode_req_sender.requests.borrow_mut().pop_front().unwrap();
|
||||
assert_eq!(req.target_id, ExampleId::Id2 as ComponentId);
|
||||
assert_eq!(req.target_id, ExampleId::Id2 as u64);
|
||||
assert_eq!(req.request_id, 1);
|
||||
assert_eq!(req.request, ModeRequest::AnnounceModeRecursive);
|
||||
}
|
||||
@@ -337,12 +337,12 @@ mod tests {
|
||||
let mut dev_mgmt_helper =
|
||||
DevManagerCommandingHelper::new(TransparentDevManagerHook::default());
|
||||
let mode_req_sender = ModeReqSenderMock::default();
|
||||
dev_mgmt_helper.add_mode_child(ExampleId::Id1 as ComponentId, UNKNOWN_MODE);
|
||||
dev_mgmt_helper.add_mode_child(ExampleId::Id1 as u64, UNKNOWN_MODE);
|
||||
let expected_mode = ModeAndSubmode::new(ExampleMode::Mode1 as u32, 0);
|
||||
dev_mgmt_helper
|
||||
.send_mode_cmd_to_one_child(
|
||||
1,
|
||||
ExampleId::Id1 as ComponentId,
|
||||
ExampleId::Id1 as u64,
|
||||
expected_mode,
|
||||
false,
|
||||
&mode_req_sender,
|
||||
@@ -350,7 +350,7 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(mode_req_sender.requests.borrow().len(), 1);
|
||||
let req = mode_req_sender.requests.borrow_mut().pop_front().unwrap();
|
||||
assert_eq!(req.target_id, ExampleId::Id1 as ComponentId);
|
||||
assert_eq!(req.target_id, ExampleId::Id1 as u64);
|
||||
assert_eq!(req.request_id, 1);
|
||||
assert_eq!(
|
||||
req.request,
|
||||
@@ -368,7 +368,7 @@ mod tests {
|
||||
assert_eq!(ctx.active_request_id, 1);
|
||||
}
|
||||
let reply = GenericMessage::new(
|
||||
MessageMetadata::new(1, ExampleId::Id1 as ComponentId),
|
||||
MessageMetadata::new(1, ExampleId::Id1 as u64),
|
||||
ModeReply::ModeReply(expected_mode),
|
||||
);
|
||||
if let DevManagerHelperResult::ModeCommandingDone(ActiveModeCommandContext {
|
||||
@@ -387,15 +387,15 @@ mod tests {
|
||||
let mut dev_mgmt_helper =
|
||||
DevManagerCommandingHelper::new(TransparentDevManagerHook::default());
|
||||
let mode_req_sender = ModeReqSenderMock::default();
|
||||
dev_mgmt_helper.add_mode_child(ExampleId::Id1 as ComponentId, UNKNOWN_MODE);
|
||||
dev_mgmt_helper.add_mode_child(ExampleId::Id2 as ComponentId, UNKNOWN_MODE);
|
||||
dev_mgmt_helper.add_mode_child(ExampleId::Id1 as u64, UNKNOWN_MODE);
|
||||
dev_mgmt_helper.add_mode_child(ExampleId::Id2 as u64, UNKNOWN_MODE);
|
||||
let expected_mode = ModeAndSubmode::new(ExampleMode::Mode2 as u32, 0);
|
||||
dev_mgmt_helper
|
||||
.send_mode_cmd_to_all_children(1, expected_mode, false, &mode_req_sender)
|
||||
.unwrap();
|
||||
assert_eq!(mode_req_sender.requests.borrow().len(), 2);
|
||||
let req = mode_req_sender.requests.borrow_mut().pop_front().unwrap();
|
||||
assert_eq!(req.target_id, ExampleId::Id1 as ComponentId);
|
||||
assert_eq!(req.target_id, ExampleId::Id1 as u64);
|
||||
assert_eq!(req.request_id, 1);
|
||||
assert_eq!(
|
||||
req.request,
|
||||
@@ -405,7 +405,7 @@ mod tests {
|
||||
}
|
||||
);
|
||||
let req = mode_req_sender.requests.borrow_mut().pop_front().unwrap();
|
||||
assert_eq!(req.target_id, ExampleId::Id2 as ComponentId);
|
||||
assert_eq!(req.target_id, ExampleId::Id2 as u64);
|
||||
assert_eq!(req.request_id, 1);
|
||||
assert_eq!(
|
||||
req.request,
|
||||
@@ -424,7 +424,7 @@ mod tests {
|
||||
}
|
||||
|
||||
let reply = GenericMessage::new(
|
||||
MessageMetadata::new(1, ExampleId::Id1 as ComponentId),
|
||||
MessageMetadata::new(1, ExampleId::Id1 as u64),
|
||||
ModeReply::ModeReply(expected_mode),
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -432,7 +432,7 @@ mod tests {
|
||||
DevManagerHelperResult::Busy
|
||||
);
|
||||
let reply = GenericMessage::new(
|
||||
MessageMetadata::new(1, ExampleId::Id2 as ComponentId),
|
||||
MessageMetadata::new(1, ExampleId::Id2 as u64),
|
||||
ModeReply::ModeReply(expected_mode),
|
||||
);
|
||||
if let DevManagerHelperResult::ModeCommandingDone(ActiveModeCommandContext {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use spacepackets::SpHeader;
|
||||
|
||||
use crate::{ComponentId, tmtc::PacketHandler};
|
||||
use crate::{ComponentId, tmtc::PacketSenderRaw};
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum SpValidity {
|
||||
@@ -24,17 +24,13 @@ pub trait SpacePacketValidator {
|
||||
#[derive(Default, Debug, PartialEq, Eq)]
|
||||
pub struct ParseResult {
|
||||
pub packets_found: u32,
|
||||
pub parsed_bytes: usize,
|
||||
// If an incomplete space packet was found, its start index is indicated by this value.
|
||||
//pub incomplete_packet_start: Option<usize>,
|
||||
/// If an incomplete space packet was found, its start index is indicated by this value.
|
||||
pub incomplete_tail_start: Option<usize>,
|
||||
}
|
||||
|
||||
/// This function parses a given buffer for tightly packed CCSDS space packets.
|
||||
///
|
||||
/// Please note that it is recommended to use a proper data link layer instead to have proper
|
||||
/// packet framing and to allow more reliable recovery from packet loss.
|
||||
/// It uses the [spacepackets::SpHeader] of the CCSDS packets and a user provided
|
||||
/// [SpacePacketValidator] to check whether a received space packet is relevant for processing.
|
||||
/// This function parses a given buffer for tightly packed CCSDS space packets. It uses the
|
||||
/// [spacepackets::SpHeader] of the CCSDS packets and a user provided [SpacePacketValidator]
|
||||
/// to check whether a received space packet is relevant for processing.
|
||||
///
|
||||
/// This function is also able to deal with broken tail packets at the end as long a the parser
|
||||
/// can read the full 7 bytes which constitue a space packet header plus one byte minimal size.
|
||||
@@ -45,18 +41,17 @@ pub struct ParseResult {
|
||||
/// [SpacePacketValidator]:
|
||||
///
|
||||
/// 1. [SpValidity::Valid]: The parser will forward all packets to the given `packet_sender` and
|
||||
/// return the number of packets found.If the [PacketHandler::handle_packet] calls fails, the
|
||||
/// return the number of packets found.If the [PacketSenderRaw::send_packet] calls fails, the
|
||||
/// error will be returned.
|
||||
/// 2. [SpValidity::Invalid]: The parser assumes that the synchronization is lost and tries to
|
||||
/// find the start of a new space packet header by scanning all the following bytes.
|
||||
/// 3. [SpValidity::Skip]: The parser skips the packet using the packet length determined from the
|
||||
/// space packet header.
|
||||
///
|
||||
pub fn parse_buffer_for_ccsds_space_packets<SendError>(
|
||||
buf: &[u8],
|
||||
packet_validator: &(impl SpacePacketValidator + ?Sized),
|
||||
sender_id: ComponentId,
|
||||
packet_sender: &(impl PacketHandler<Error = SendError> + ?Sized),
|
||||
packet_sender: &(impl PacketSenderRaw<Error = SendError> + ?Sized),
|
||||
) -> Result<ParseResult, SendError> {
|
||||
let mut parse_result = ParseResult::default();
|
||||
let mut current_idx = 0;
|
||||
@@ -71,12 +66,11 @@ pub fn parse_buffer_for_ccsds_space_packets<SendError>(
|
||||
let packet_size = sp_header.packet_len();
|
||||
if (current_idx + packet_size) <= buf_len {
|
||||
packet_sender
|
||||
.handle_packet(sender_id, &buf[current_idx..current_idx + packet_size])?;
|
||||
.send_packet(sender_id, &buf[current_idx..current_idx + packet_size])?;
|
||||
parse_result.packets_found += 1;
|
||||
} else {
|
||||
// Move packet to start of buffer if applicable.
|
||||
//parse_result.incomplete_packet_start = Some(current_idx);
|
||||
break;
|
||||
parse_result.incomplete_tail_start = Some(current_idx);
|
||||
}
|
||||
current_idx += packet_size;
|
||||
continue;
|
||||
@@ -90,7 +84,6 @@ pub fn parse_buffer_for_ccsds_space_packets<SendError>(
|
||||
}
|
||||
}
|
||||
}
|
||||
parse_result.parsed_bytes = current_idx;
|
||||
Ok(parse_result)
|
||||
}
|
||||
|
||||
@@ -99,7 +92,7 @@ mod tests {
|
||||
use arbitrary_int::{u11, u14};
|
||||
use spacepackets::{
|
||||
CcsdsPacket, PacketId, PacketSequenceControl, PacketType, SequenceFlags, SpHeader,
|
||||
ecss::{CreatorConfig, MessageTypeId, tc::PusTcCreator},
|
||||
ecss::{CreatorConfig, tc::PusTcCreator},
|
||||
};
|
||||
|
||||
use crate::{ComponentId, encoding::tests::TcCacher};
|
||||
@@ -139,12 +132,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_basic() {
|
||||
let sph = SpHeader::new_from_apid(TEST_APID_0);
|
||||
let ping_tc = PusTcCreator::new_simple(
|
||||
sph,
|
||||
MessageTypeId::new(17, 1),
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
let ping_tc = PusTcCreator::new_simple(sph, 17, 1, &[], CreatorConfig::default());
|
||||
let mut buffer: [u8; 32] = [0; 32];
|
||||
let packet_len = ping_tc
|
||||
.write_to_bytes(&mut buffer)
|
||||
@@ -169,14 +157,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_multi_packet() {
|
||||
let sph = SpHeader::new_from_apid(TEST_APID_0);
|
||||
let ping_tc = PusTcCreator::new_simple(
|
||||
sph,
|
||||
MessageTypeId::new(17, 1),
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
let action_tc =
|
||||
PusTcCreator::new_simple(sph, MessageTypeId::new(8, 0), &[], CreatorConfig::default());
|
||||
let ping_tc = PusTcCreator::new_simple(sph, 17, 1, &[], CreatorConfig::default());
|
||||
let action_tc = PusTcCreator::new_simple(sph, 8, 0, &[], CreatorConfig::default());
|
||||
let mut buffer: [u8; 32] = [0; 32];
|
||||
let packet_len_ping = ping_tc
|
||||
.write_to_bytes(&mut buffer)
|
||||
@@ -210,15 +192,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_multi_apid() {
|
||||
let sph = SpHeader::new_from_apid(TEST_APID_0);
|
||||
let ping_tc = PusTcCreator::new_simple(
|
||||
sph,
|
||||
MessageTypeId::new(17, 1),
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
let ping_tc = PusTcCreator::new_simple(sph, 17, 1, &[], CreatorConfig::default());
|
||||
let sph = SpHeader::new_from_apid(TEST_APID_1);
|
||||
let action_tc =
|
||||
PusTcCreator::new_simple(sph, MessageTypeId::new(8, 0), &[], CreatorConfig::default());
|
||||
let action_tc = PusTcCreator::new_simple(sph, 8, 0, &[], CreatorConfig::default());
|
||||
let mut buffer: [u8; 32] = [0; 32];
|
||||
let packet_len_ping = ping_tc
|
||||
.write_to_bytes(&mut buffer)
|
||||
@@ -248,13 +224,15 @@ mod tests {
|
||||
fn test_split_packet_multi() {
|
||||
let ping_tc = PusTcCreator::new_simple(
|
||||
SpHeader::new_from_apid(TEST_APID_0),
|
||||
MessageTypeId::new(17, 1),
|
||||
17,
|
||||
1,
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
let action_tc = PusTcCreator::new_simple(
|
||||
SpHeader::new_from_apid(TEST_APID_1),
|
||||
MessageTypeId::new(8, 0),
|
||||
8,
|
||||
0,
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
@@ -276,7 +254,8 @@ mod tests {
|
||||
assert!(parse_result.is_ok());
|
||||
let parse_result = parse_result.unwrap();
|
||||
assert_eq!(parse_result.packets_found, 1);
|
||||
let incomplete_tail_idx = parse_result.parsed_bytes;
|
||||
assert!(parse_result.incomplete_tail_start.is_some());
|
||||
let incomplete_tail_idx = parse_result.incomplete_tail_start.unwrap();
|
||||
assert_eq!(incomplete_tail_idx, packet_len_ping);
|
||||
|
||||
let queue = tc_cacher.tc_queue.borrow();
|
||||
@@ -289,7 +268,8 @@ mod tests {
|
||||
fn test_one_split_packet() {
|
||||
let ping_tc = PusTcCreator::new_simple(
|
||||
SpHeader::new_from_apid(TEST_APID_0),
|
||||
MessageTypeId::new(17, 1),
|
||||
17,
|
||||
1,
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{ComponentId, tmtc::PacketHandler};
|
||||
use cobs::{decode_in_place, encode_including_sentinels, max_encoding_length};
|
||||
use crate::{ComponentId, tmtc::PacketSenderRaw};
|
||||
use cobs::{decode_in_place, encode, max_encoding_length};
|
||||
|
||||
/// This function encodes the given packet with COBS and also wraps the encoded packet with
|
||||
/// the sentinel value 0. It can be used repeatedly on the same encoded buffer by expecting
|
||||
@@ -37,16 +37,15 @@ pub fn encode_packet_with_cobs(
|
||||
if *current_idx + max_encoding_len + 2 > encoded_buf.len() {
|
||||
return false;
|
||||
}
|
||||
*current_idx += encode_including_sentinels(packet, &mut encoded_buf[*current_idx..]);
|
||||
encoded_buf[*current_idx] = 0;
|
||||
*current_idx += 1;
|
||||
*current_idx += encode(packet, &mut encoded_buf[*current_idx..]);
|
||||
encoded_buf[*current_idx] = 0;
|
||||
*current_idx += 1;
|
||||
true
|
||||
}
|
||||
|
||||
/// This function parses a given buffer for COBS encoded packets.
|
||||
///
|
||||
/// Please note that, it is recommended to use [cobs::CobsDecoderOwned] or [cobs::CobsDecoder]
|
||||
/// instead.
|
||||
///
|
||||
/// The packet structure is
|
||||
/// This function parses a given buffer for COBS encoded packets. The packet structure is
|
||||
/// expected to be like this, assuming a sentinel value of 0 as the packet delimiter:
|
||||
///
|
||||
/// 0 | ... Encoded Packet Data ... | 0 | 0 | ... Encoded Packet Data ... | 0
|
||||
@@ -59,7 +58,7 @@ pub fn encode_packet_with_cobs(
|
||||
pub fn parse_buffer_for_cobs_encoded_packets<SendError>(
|
||||
buf: &mut [u8],
|
||||
sender_id: ComponentId,
|
||||
packet_sender: &(impl PacketHandler<Error = SendError> + ?Sized),
|
||||
packet_sender: &(impl PacketSenderRaw<Error = SendError> + ?Sized),
|
||||
next_write_idx: &mut usize,
|
||||
) -> Result<u32, SendError> {
|
||||
let mut start_index_packet = 0;
|
||||
@@ -80,7 +79,7 @@ pub fn parse_buffer_for_cobs_encoded_packets<SendError>(
|
||||
let decode_result = decode_in_place(&mut buf[start_index_packet..i]);
|
||||
if let Ok(packet_len) = decode_result {
|
||||
packets_found += 1;
|
||||
packet_sender.handle_packet(
|
||||
packet_sender.send_packet(
|
||||
sender_id,
|
||||
&buf[start_index_packet..start_index_packet + packet_len],
|
||||
)?;
|
||||
|
||||
@@ -12,7 +12,7 @@ pub(crate) mod tests {
|
||||
|
||||
use crate::{
|
||||
ComponentId,
|
||||
tmtc::{PacketAsVec, PacketHandler},
|
||||
tmtc::{PacketAsVec, PacketSenderRaw},
|
||||
};
|
||||
|
||||
use super::cobs::encode_packet_with_cobs;
|
||||
@@ -25,10 +25,10 @@ pub(crate) mod tests {
|
||||
pub(crate) tc_queue: RefCell<VecDeque<PacketAsVec>>,
|
||||
}
|
||||
|
||||
impl PacketHandler for TcCacher {
|
||||
impl PacketSenderRaw for TcCacher {
|
||||
type Error = ();
|
||||
|
||||
fn handle_packet(&self, sender_id: ComponentId, tc_raw: &[u8]) -> Result<(), Self::Error> {
|
||||
fn send_packet(&self, sender_id: ComponentId, tc_raw: &[u8]) -> Result<(), Self::Error> {
|
||||
let mut mut_queue = self.tc_queue.borrow_mut();
|
||||
mut_queue.push_back(PacketAsVec::new(sender_id, tc_raw.to_vec()));
|
||||
Ok(())
|
||||
|
||||
@@ -386,7 +386,7 @@ impl UnsignedEnum for EventU32 {
|
||||
self.base.write_to_bytes(self.raw(), buf, self.size())
|
||||
}
|
||||
|
||||
fn value_raw(&self) -> u64 {
|
||||
fn value(&self) -> u64 {
|
||||
self.raw().into()
|
||||
}
|
||||
}
|
||||
@@ -445,7 +445,7 @@ impl<SEVERITY: HasSeverity> UnsignedEnum for EventU32TypedSev<SEVERITY> {
|
||||
delegate!(to self.event {
|
||||
fn size(&self) -> usize;
|
||||
fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<usize, ByteConversionError>;
|
||||
fn value_raw(&self) -> u64;
|
||||
fn value(&self) -> u64;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -558,7 +558,7 @@ impl UnsignedEnum for EventU16 {
|
||||
self.base.write_to_bytes(self.raw(), buf, self.size())
|
||||
}
|
||||
|
||||
fn value_raw(&self) -> u64 {
|
||||
fn value(&self) -> u64 {
|
||||
self.raw().into()
|
||||
}
|
||||
}
|
||||
@@ -611,7 +611,7 @@ impl<SEVERITY: HasSeverity> UnsignedEnum for EventU16TypedSev<SEVERITY> {
|
||||
delegate!(to self.event {
|
||||
fn size(&self) -> usize;
|
||||
fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<usize, ByteConversionError>;
|
||||
fn value_raw(&self) -> u64;
|
||||
fn value(&self) -> u64;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
pub mod tcp_server;
|
||||
pub mod udp_server;
|
||||
|
||||
pub mod tcp_cobs_server;
|
||||
pub mod tcp_spacepackets_server;
|
||||
mod tcp_cobs_server;
|
||||
mod tcp_spacepackets_server;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use alloc::sync::Arc;
|
||||
use alloc::vec;
|
||||
use cobs::CobsDecoderOwned;
|
||||
use cobs::DecodeError;
|
||||
use cobs::encode;
|
||||
use core::sync::atomic::AtomicBool;
|
||||
use core::time::Duration;
|
||||
@@ -11,58 +9,40 @@ use std::io::Write;
|
||||
use std::net::SocketAddr;
|
||||
use std::vec::Vec;
|
||||
|
||||
use crate::queue::GenericSendError;
|
||||
use crate::tmtc::PacketHandler;
|
||||
use crate::encoding::parse_buffer_for_cobs_encoded_packets;
|
||||
use crate::tmtc::PacketSenderRaw;
|
||||
use crate::tmtc::PacketSource;
|
||||
|
||||
use crate::ComponentId;
|
||||
use crate::hal::std::tcp_server::{
|
||||
ConnectionResult, ServerConfig, TcpTcParser, TcpTmSender, TcpTmtcGenericServer,
|
||||
ConnectionResult, ServerConfig, TcpTcParser, TcpTmSender, TcpTmtcError, TcpTmtcGenericServer,
|
||||
};
|
||||
|
||||
use super::tcp_server::HandledConnectionHandler;
|
||||
use super::tcp_server::HandledConnectionInfo;
|
||||
|
||||
/// Concrete [TcpTcParser] implementation for the [TcpTmtcInCobsServer].
|
||||
pub struct CobsTcParser<PacketHandlerInstance: PacketHandler> {
|
||||
sender_id: ComponentId,
|
||||
owned_decoder: CobsDecoderOwned,
|
||||
packet_handler: PacketHandlerInstance,
|
||||
last_decode_error: Option<DecodeError>,
|
||||
}
|
||||
#[derive(Default)]
|
||||
pub struct CobsTcParser {}
|
||||
|
||||
impl<PacketHandlerInstance: PacketHandler> CobsTcParser<PacketHandlerInstance> {
|
||||
pub fn new(
|
||||
impl<TmError, TcError: 'static> TcpTcParser<TmError, TcError> for CobsTcParser {
|
||||
fn handle_tc_parsing(
|
||||
&mut self,
|
||||
tc_buffer: &mut [u8],
|
||||
sender_id: ComponentId,
|
||||
decoder_buf_size: usize,
|
||||
packet_handler: PacketHandlerInstance,
|
||||
) -> Self {
|
||||
Self {
|
||||
tc_sender: &(impl PacketSenderRaw<Error = TcError> + ?Sized),
|
||||
conn_result: &mut HandledConnectionInfo,
|
||||
current_write_idx: usize,
|
||||
next_write_idx: &mut usize,
|
||||
) -> Result<(), TcpTmtcError<TmError, TcError>> {
|
||||
conn_result.num_received_tcs += parse_buffer_for_cobs_encoded_packets(
|
||||
&mut tc_buffer[..current_write_idx],
|
||||
sender_id,
|
||||
owned_decoder: CobsDecoderOwned::new(decoder_buf_size),
|
||||
packet_handler,
|
||||
last_decode_error: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<PacketHandlerInstance: PacketHandler> TcpTcParser for CobsTcParser<PacketHandlerInstance> {
|
||||
fn reset(&mut self) {
|
||||
self.owned_decoder.reset();
|
||||
}
|
||||
|
||||
fn push(&mut self, data: &[u8], conn_result: &mut HandledConnectionInfo) {
|
||||
for byte in data {
|
||||
match self.owned_decoder.feed(*byte) {
|
||||
Ok(Some(packet_len)) => {
|
||||
self.packet_handler
|
||||
.handle_packet(self.sender_id, &self.owned_decoder.dest()[..packet_len])
|
||||
.ok();
|
||||
conn_result.num_received_tcs += 1;
|
||||
}
|
||||
Ok(None) => (),
|
||||
Err(e) => self.last_decode_error = Some(e),
|
||||
}
|
||||
}
|
||||
tc_sender,
|
||||
next_write_idx,
|
||||
)
|
||||
.map_err(|e| TcpTmtcError::TcError(e))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,18 +61,22 @@ impl CobsTmSender {
|
||||
}
|
||||
}
|
||||
|
||||
impl TcpTmSender for CobsTmSender {
|
||||
impl<TmError, TcError> TcpTmSender<TmError, TcError> for CobsTmSender {
|
||||
fn handle_tm_sending(
|
||||
&mut self,
|
||||
tm_buffer: &mut [u8],
|
||||
tm_source: &mut (impl PacketSource<Error = ()> + ?Sized),
|
||||
tm_source: &mut (impl PacketSource<Error = TmError> + ?Sized),
|
||||
conn_result: &mut HandledConnectionInfo,
|
||||
stream: &mut TcpStream,
|
||||
) -> Result<bool, std::io::Error> {
|
||||
) -> Result<bool, TcpTmtcError<TmError, TcError>> {
|
||||
let mut tm_was_sent = false;
|
||||
// Write TM until TM source is exhausted or there is an unexpected error. For now, there
|
||||
// is no limit for the amount of TM written this way.
|
||||
while let Ok(read_tm_len) = tm_source.retrieve_packet(tm_buffer) {
|
||||
loop {
|
||||
// Write TM until TM source is exhausted. For now, there is no limit for the amount
|
||||
// of TM written this way.
|
||||
let read_tm_len = tm_source
|
||||
.retrieve_packet(tm_buffer)
|
||||
.map_err(|e| TcpTmtcError::TmError(e))?;
|
||||
|
||||
if read_tm_len == 0 {
|
||||
return Ok(tm_was_sent);
|
||||
}
|
||||
@@ -111,7 +95,6 @@ impl TcpTmSender for CobsTmSender {
|
||||
current_idx += 1;
|
||||
stream.write_all(&self.tm_encoding_buffer[..current_idx])?;
|
||||
}
|
||||
Ok(tm_was_sent)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,8 +108,8 @@ impl TcpTmSender for CobsTmSender {
|
||||
///
|
||||
/// Using a framing protocol like COBS imposes minimal restrictions on the type of TMTC data
|
||||
/// exchanged while also allowing packets with flexible size and a reliable way to reconstruct full
|
||||
/// packets even from a data stream which is split up. The server wil use the streaming
|
||||
/// [CobsDecoderOwned] decoder to parse for packets and pass them to a
|
||||
/// packets even from a data stream which is split up. The server wil use the
|
||||
/// [parse_buffer_for_cobs_encoded_packets] function to parse for packets and pass them to a
|
||||
/// generic TC receiver. The user can use [crate::encoding::encode_packet_with_cobs] to encode
|
||||
/// telecommands sent to the server.
|
||||
///
|
||||
@@ -135,19 +118,30 @@ impl TcpTmSender for CobsTmSender {
|
||||
/// The [TCP integration tests](https://egit.irs.uni-stuttgart.de/rust/sat-rs/src/branch/main/satrs/tests/tcp_servers.rs)
|
||||
/// test also serves as the example application for this module.
|
||||
pub struct TcpTmtcInCobsServer<
|
||||
TmSource: PacketSource<Error = ()>,
|
||||
TcHandler: PacketHandler<Error = GenericSendError>,
|
||||
TmSource: PacketSource<Error = TmError>,
|
||||
TcSender: PacketSenderRaw<Error = SendError>,
|
||||
HandledConnection: HandledConnectionHandler,
|
||||
TmError,
|
||||
SendError: 'static,
|
||||
> {
|
||||
pub generic_server:
|
||||
TcpTmtcGenericServer<TmSource, CobsTmSender, CobsTcParser<TcHandler>, HandledConnection>,
|
||||
pub generic_server: TcpTmtcGenericServer<
|
||||
TmSource,
|
||||
TcSender,
|
||||
CobsTmSender,
|
||||
CobsTcParser,
|
||||
HandledConnection,
|
||||
TmError,
|
||||
SendError,
|
||||
>,
|
||||
}
|
||||
|
||||
impl<
|
||||
TmSource: PacketSource<Error = ()>,
|
||||
TcHandler: PacketHandler<Error = GenericSendError>,
|
||||
TmSource: PacketSource<Error = TmError>,
|
||||
TcReceiver: PacketSenderRaw<Error = TcError>,
|
||||
HandledConnection: HandledConnectionHandler,
|
||||
> TcpTmtcInCobsServer<TmSource, TcHandler, HandledConnection>
|
||||
TmError: 'static,
|
||||
TcError: 'static,
|
||||
> TcpTmtcInCobsServer<TmSource, TcReceiver, HandledConnection, TmError, TcError>
|
||||
{
|
||||
/// Create a new TCP TMTC server which exchanges TMTC packets encoded with
|
||||
/// [COBS protocol](https://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing).
|
||||
@@ -162,16 +156,17 @@ impl<
|
||||
pub fn new(
|
||||
cfg: ServerConfig,
|
||||
tm_source: TmSource,
|
||||
cobs_tc_parser: CobsTcParser<TcHandler>,
|
||||
tc_receiver: TcReceiver,
|
||||
handled_connection: HandledConnection,
|
||||
stop_signal: Option<Arc<AtomicBool>>,
|
||||
) -> Result<Self, std::io::Error> {
|
||||
Ok(Self {
|
||||
generic_server: TcpTmtcGenericServer::new(
|
||||
cfg,
|
||||
cobs_tc_parser,
|
||||
CobsTcParser::default(),
|
||||
CobsTmSender::new(cfg.tm_buffer_size),
|
||||
tm_source,
|
||||
tc_receiver,
|
||||
handled_connection,
|
||||
stop_signal,
|
||||
)?,
|
||||
@@ -190,7 +185,7 @@ impl<
|
||||
pub fn handle_all_connections(
|
||||
&mut self,
|
||||
poll_duration: Option<Duration>,
|
||||
) -> Result<ConnectionResult, std::io::Error>;
|
||||
) -> Result<ConnectionResult, TcpTmtcError<TmError, TcError>>;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,6 +212,7 @@ mod tests {
|
||||
ConnectionResult, ServerConfig,
|
||||
tests::{ConnectionFinishedHandler, SyncTmSource},
|
||||
},
|
||||
queue::GenericSendError,
|
||||
tmtc::PacketAsVec,
|
||||
};
|
||||
use alloc::sync::Arc;
|
||||
@@ -247,12 +243,17 @@ mod tests {
|
||||
tc_sender: mpsc::Sender<PacketAsVec>,
|
||||
tm_source: SyncTmSource,
|
||||
stop_signal: Option<Arc<AtomicBool>>,
|
||||
) -> TcpTmtcInCobsServer<SyncTmSource, mpsc::Sender<PacketAsVec>, ConnectionFinishedHandler>
|
||||
{
|
||||
) -> TcpTmtcInCobsServer<
|
||||
SyncTmSource,
|
||||
mpsc::Sender<PacketAsVec>,
|
||||
ConnectionFinishedHandler,
|
||||
(),
|
||||
GenericSendError,
|
||||
> {
|
||||
TcpTmtcInCobsServer::new(
|
||||
ServerConfig::new(TCP_SERVER_ID, *addr, Duration::from_millis(2), 1024, 1024),
|
||||
tm_source,
|
||||
super::CobsTcParser::new(TCP_SERVER_ID, 1024, tc_sender),
|
||||
tc_sender,
|
||||
ConnectionFinishedHandler::default(),
|
||||
stop_signal,
|
||||
)
|
||||
|
||||
@@ -12,7 +12,7 @@ use std::net::SocketAddr;
|
||||
use std::thread;
|
||||
|
||||
use crate::ComponentId;
|
||||
use crate::tmtc::PacketSource;
|
||||
use crate::tmtc::{PacketSenderRaw, PacketSource};
|
||||
use thiserror::Error;
|
||||
|
||||
// Re-export the TMTC in COBS server.
|
||||
@@ -73,9 +73,11 @@ impl ServerConfig {
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum TcpTmError<TmError> {
|
||||
pub enum TcpTmtcError<TmError, TcError> {
|
||||
#[error("TM retrieval error: {0}")]
|
||||
TmError(TmError),
|
||||
#[error("TC retrieval error: {0}")]
|
||||
TcError(TcError),
|
||||
#[error("io error: {0}")]
|
||||
Io(#[from] std::io::Error),
|
||||
}
|
||||
@@ -114,29 +116,32 @@ pub trait HandledConnectionHandler {
|
||||
}
|
||||
|
||||
/// Generic parser abstraction for an object which can parse for telecommands given a raw
|
||||
/// bytestream received from a TCP socket and extract packets from them. This allows different
|
||||
/// encoding schemes for telecommands.
|
||||
pub trait TcpTcParser {
|
||||
/// Reset the state of the parser.
|
||||
fn reset(&mut self);
|
||||
|
||||
/// Pushes received data into the parser.
|
||||
fn push(&mut self, tc_data: &[u8], conn_result: &mut HandledConnectionInfo);
|
||||
/// bytestream received from a TCP socket and send them using a generic [PacketSenderRaw]
|
||||
/// implementation. This allows different encoding schemes for telecommands.
|
||||
pub trait TcpTcParser<TmError, SendError> {
|
||||
fn handle_tc_parsing(
|
||||
&mut self,
|
||||
tc_buffer: &mut [u8],
|
||||
sender_id: ComponentId,
|
||||
tc_sender: &(impl PacketSenderRaw<Error = SendError> + ?Sized),
|
||||
conn_result: &mut HandledConnectionInfo,
|
||||
current_write_idx: usize,
|
||||
next_write_idx: &mut usize,
|
||||
) -> Result<(), TcpTmtcError<TmError, SendError>>;
|
||||
}
|
||||
|
||||
/// Generic sender abstraction for an object which can pull telemetry from a given TM source
|
||||
/// using a [PacketSource] and then send them back to a client using a given [TcpStream].
|
||||
/// The concrete implementation can also perform any encoding steps which are necessary before
|
||||
/// sending back the data to a client.
|
||||
pub trait TcpTmSender {
|
||||
/// Returns whether any packets were sent back to the client.
|
||||
pub trait TcpTmSender<TmError, TcError> {
|
||||
fn handle_tm_sending(
|
||||
&mut self,
|
||||
tm_buffer: &mut [u8],
|
||||
tm_source: &mut (impl PacketSource<Error = ()> + ?Sized),
|
||||
tm_source: &mut (impl PacketSource<Error = TmError> + ?Sized),
|
||||
conn_result: &mut HandledConnectionInfo,
|
||||
stream: &mut TcpStream,
|
||||
) -> Result<bool, std::io::Error>;
|
||||
) -> Result<bool, TcpTmtcError<TmError, TcError>>;
|
||||
}
|
||||
|
||||
/// TCP TMTC server implementation for exchange of generic TMTC packets in a generic way which
|
||||
@@ -146,8 +151,7 @@ pub trait TcpTmSender {
|
||||
/// through the following 4 core abstractions:
|
||||
///
|
||||
/// 1. [TcpTcParser] to parse for telecommands from the raw bytestream received from a client.
|
||||
/// 2. Parsed telecommands will be handled by the [TcpTcParser] object as well. For example, this
|
||||
/// parser can contain a message queue handle to send the packets somewhere.
|
||||
/// 2. Parsed telecommands will be sent using the [PacketSenderRaw] object.
|
||||
/// 3. [TcpTmSender] to send telemetry pulled from a TM source back to the client.
|
||||
/// 4. [PacketSource] as a generic TM source used by the [TcpTmSender].
|
||||
///
|
||||
@@ -159,10 +163,13 @@ pub trait TcpTmSender {
|
||||
/// 1. [TcpTmtcInCobsServer] to exchange TMTC wrapped inside the COBS framing protocol.
|
||||
/// 2. [TcpSpacepacketsServer] to exchange space packets via TCP.
|
||||
pub struct TcpTmtcGenericServer<
|
||||
TmSource: PacketSource<Error = ()>,
|
||||
TmSender: TcpTmSender,
|
||||
TcParser: TcpTcParser,
|
||||
TmSource: PacketSource<Error = TmError>,
|
||||
TcSender: PacketSenderRaw<Error = TcSendError>,
|
||||
TmSender: TcpTmSender<TmError, TcSendError>,
|
||||
TcParser: TcpTcParser<TmError, TcSendError>,
|
||||
HandledConnection: HandledConnectionHandler,
|
||||
TmError,
|
||||
TcSendError,
|
||||
> {
|
||||
pub id: ComponentId,
|
||||
pub finished_handler: HandledConnection,
|
||||
@@ -170,6 +177,7 @@ pub struct TcpTmtcGenericServer<
|
||||
pub(crate) inner_loop_delay: Duration,
|
||||
pub(crate) tm_source: TmSource,
|
||||
pub(crate) tm_buffer: Vec<u8>,
|
||||
pub(crate) tc_sender: TcSender,
|
||||
pub(crate) tc_buffer: Vec<u8>,
|
||||
poll: Poll,
|
||||
events: Events,
|
||||
@@ -179,11 +187,23 @@ pub struct TcpTmtcGenericServer<
|
||||
}
|
||||
|
||||
impl<
|
||||
TmSource: PacketSource<Error = ()>,
|
||||
TmSender: TcpTmSender,
|
||||
TcParser: TcpTcParser,
|
||||
TmSource: PacketSource<Error = TmError>,
|
||||
TcSender: PacketSenderRaw<Error = TcSendError>,
|
||||
TmSender: TcpTmSender<TmError, TcSendError>,
|
||||
TcParser: TcpTcParser<TmError, TcSendError>,
|
||||
HandledConnection: HandledConnectionHandler,
|
||||
> TcpTmtcGenericServer<TmSource, TmSender, TcParser, HandledConnection>
|
||||
TmError: 'static,
|
||||
TcSendError: 'static,
|
||||
>
|
||||
TcpTmtcGenericServer<
|
||||
TmSource,
|
||||
TcSender,
|
||||
TmSender,
|
||||
TcParser,
|
||||
HandledConnection,
|
||||
TmError,
|
||||
TcSendError,
|
||||
>
|
||||
{
|
||||
/// Create a new generic TMTC server instance.
|
||||
///
|
||||
@@ -203,6 +223,7 @@ impl<
|
||||
tc_parser: TcParser,
|
||||
tm_sender: TmSender,
|
||||
tm_source: TmSource,
|
||||
tc_receiver: TcSender,
|
||||
finished_handler: HandledConnection,
|
||||
stop_signal: Option<Arc<AtomicBool>>,
|
||||
) -> Result<Self, std::io::Error> {
|
||||
@@ -242,6 +263,7 @@ impl<
|
||||
inner_loop_delay: cfg.inner_loop_delay,
|
||||
tm_source,
|
||||
tm_buffer: vec![0; cfg.tm_buffer_size],
|
||||
tc_sender: tc_receiver,
|
||||
tc_buffer: vec![0; cfg.tc_buffer_size],
|
||||
stop_signal,
|
||||
finished_handler,
|
||||
@@ -275,7 +297,7 @@ impl<
|
||||
pub fn handle_all_connections(
|
||||
&mut self,
|
||||
poll_timeout: Option<Duration>,
|
||||
) -> Result<ConnectionResult, std::io::Error> {
|
||||
) -> Result<ConnectionResult, TcpTmtcError<TmError, TcSendError>> {
|
||||
let mut handled_connections = 0;
|
||||
// Poll Mio for events.
|
||||
self.poll.poll(&mut self.events, poll_timeout)?;
|
||||
@@ -305,7 +327,7 @@ impl<
|
||||
Err(ref err) if err.kind() == io::ErrorKind::WouldBlock => break,
|
||||
Err(err) => {
|
||||
self.reregister_poll_interest()?;
|
||||
return Err(err);
|
||||
return Err(TcpTmtcError::Io(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -328,24 +350,58 @@ impl<
|
||||
&mut self,
|
||||
mut stream: TcpStream,
|
||||
addr: SocketAddr,
|
||||
) -> Result<(), std::io::Error> {
|
||||
self.tc_handler.reset();
|
||||
) -> Result<(), TcpTmtcError<TmError, TcSendError>> {
|
||||
let mut current_write_idx;
|
||||
let mut next_write_idx = 0;
|
||||
let mut connection_result = HandledConnectionInfo::new(addr);
|
||||
current_write_idx = next_write_idx;
|
||||
loop {
|
||||
let read_result = stream.read(&mut self.tc_buffer);
|
||||
let read_result = stream.read(&mut self.tc_buffer[current_write_idx..]);
|
||||
match read_result {
|
||||
Ok(0) => {
|
||||
// Connection closed by client.
|
||||
// Connection closed by client. If any TC was read, parse for complete packets.
|
||||
// After that, break the outer loop.
|
||||
if current_write_idx > 0 {
|
||||
self.tc_handler.handle_tc_parsing(
|
||||
&mut self.tc_buffer,
|
||||
self.id,
|
||||
&self.tc_sender,
|
||||
&mut connection_result,
|
||||
current_write_idx,
|
||||
&mut next_write_idx,
|
||||
)?;
|
||||
}
|
||||
break;
|
||||
}
|
||||
Ok(read_len) => {
|
||||
self.tc_handler
|
||||
.push(&self.tc_buffer[0..read_len], &mut connection_result);
|
||||
current_write_idx += read_len;
|
||||
// TC buffer is full, we must parse for complete packets now.
|
||||
if current_write_idx == self.tc_buffer.capacity() {
|
||||
self.tc_handler.handle_tc_parsing(
|
||||
&mut self.tc_buffer,
|
||||
self.id,
|
||||
&self.tc_sender,
|
||||
&mut connection_result,
|
||||
current_write_idx,
|
||||
&mut next_write_idx,
|
||||
)?;
|
||||
current_write_idx = next_write_idx;
|
||||
}
|
||||
}
|
||||
Err(e) => match e.kind() {
|
||||
// As per [TcpStream::set_read_timeout] documentation, this should work for
|
||||
// both UNIX and Windows.
|
||||
std::io::ErrorKind::WouldBlock | std::io::ErrorKind::TimedOut => {
|
||||
self.tc_handler.handle_tc_parsing(
|
||||
&mut self.tc_buffer,
|
||||
self.id,
|
||||
&self.tc_sender,
|
||||
&mut connection_result,
|
||||
current_write_idx,
|
||||
&mut next_write_idx,
|
||||
)?;
|
||||
current_write_idx = next_write_idx;
|
||||
|
||||
if !self.tm_handler.handle_tm_sending(
|
||||
&mut self.tm_buffer,
|
||||
&mut self.tm_source,
|
||||
@@ -370,7 +426,7 @@ impl<
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(e);
|
||||
return Err(TcpTmtcError::Io(e));
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -446,11 +502,8 @@ pub(crate) mod tests {
|
||||
.connection_info
|
||||
.pop_back()
|
||||
.expect("no connection info available");
|
||||
assert_eq!(
|
||||
last_conn_result.num_received_tcs, num_tcs,
|
||||
"received tcs mismatch"
|
||||
);
|
||||
assert_eq!(last_conn_result.num_sent_tms, num_tms, "sent tms missmatch");
|
||||
assert_eq!(last_conn_result.num_received_tcs, num_tcs);
|
||||
assert_eq!(last_conn_result.num_sent_tms, num_tms);
|
||||
}
|
||||
|
||||
pub fn check_no_connections_left(&self) {
|
||||
|
||||
@@ -7,104 +7,39 @@ use std::{io::Write, net::SocketAddr};
|
||||
use crate::{
|
||||
ComponentId,
|
||||
encoding::{ccsds::SpacePacketValidator, parse_buffer_for_ccsds_space_packets},
|
||||
queue::GenericSendError,
|
||||
tmtc::{PacketHandler, PacketSource},
|
||||
tmtc::{PacketSenderRaw, PacketSource},
|
||||
};
|
||||
|
||||
use super::tcp_server::{
|
||||
ConnectionResult, HandledConnectionHandler, HandledConnectionInfo, ServerConfig, TcpTcParser,
|
||||
TcpTmSender, TcpTmtcGenericServer,
|
||||
TcpTmSender, TcpTmtcError, TcpTmtcGenericServer,
|
||||
};
|
||||
|
||||
pub struct CcsdsPacketParser<
|
||||
PacketValidator: SpacePacketValidator,
|
||||
PacketHandlerInstance: PacketHandler,
|
||||
> {
|
||||
sender_id: ComponentId,
|
||||
parsing_buffer: alloc::vec::Vec<u8>,
|
||||
validator: PacketValidator,
|
||||
packet_handler: PacketHandlerInstance,
|
||||
current_write_index: usize,
|
||||
}
|
||||
|
||||
impl<PacketValidator: SpacePacketValidator, PacketHandlerInstance: PacketHandler>
|
||||
CcsdsPacketParser<PacketValidator, PacketHandlerInstance>
|
||||
{
|
||||
pub fn new(
|
||||
impl<T: SpacePacketValidator, TmError, TcError: 'static> TcpTcParser<TmError, TcError> for T {
|
||||
fn handle_tc_parsing(
|
||||
&mut self,
|
||||
tc_buffer: &mut [u8],
|
||||
sender_id: ComponentId,
|
||||
parsing_buf_size: usize,
|
||||
packet_handler: PacketHandlerInstance,
|
||||
validator: PacketValidator,
|
||||
) -> Self {
|
||||
Self {
|
||||
tc_sender: &(impl PacketSenderRaw<Error = TcError> + ?Sized),
|
||||
conn_result: &mut HandledConnectionInfo,
|
||||
current_write_idx: usize,
|
||||
next_write_idx: &mut usize,
|
||||
) -> Result<(), TcpTmtcError<TmError, TcError>> {
|
||||
// Reader vec full, need to parse for packets.
|
||||
let parse_result = parse_buffer_for_ccsds_space_packets(
|
||||
&tc_buffer[..current_write_idx],
|
||||
self,
|
||||
sender_id,
|
||||
parsing_buffer: alloc::vec![0; parsing_buf_size],
|
||||
validator,
|
||||
packet_handler,
|
||||
current_write_index: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn write_to_buffer(&mut self, data: &[u8]) -> usize {
|
||||
let available = self.parsing_buffer.len() - self.current_write_index;
|
||||
let to_write = core::cmp::min(data.len(), available);
|
||||
|
||||
self.parsing_buffer[self.current_write_index..self.current_write_index + to_write]
|
||||
.copy_from_slice(&data[..to_write]);
|
||||
self.current_write_index += to_write;
|
||||
|
||||
to_write
|
||||
}
|
||||
|
||||
fn parse_and_handle_packets(&mut self) -> u32 {
|
||||
match parse_buffer_for_ccsds_space_packets(
|
||||
&self.parsing_buffer[..self.current_write_index],
|
||||
&self.validator,
|
||||
self.sender_id,
|
||||
&self.packet_handler,
|
||||
) {
|
||||
Ok(parse_result) => {
|
||||
self.parsing_buffer
|
||||
.copy_within(parse_result.parsed_bytes..self.current_write_index, 0);
|
||||
self.current_write_index -= parse_result.parsed_bytes;
|
||||
parse_result.packets_found
|
||||
}
|
||||
Err(_) => 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn drop_first_half_of_buffer(&mut self) {
|
||||
let mid = self.parsing_buffer.len() / 2;
|
||||
self.parsing_buffer.copy_within(mid.., 0);
|
||||
self.current_write_index -= mid;
|
||||
}
|
||||
}
|
||||
impl<PacketValidator: SpacePacketValidator, PacketHandlerInstance: PacketHandler> TcpTcParser
|
||||
for CcsdsPacketParser<PacketValidator, PacketHandlerInstance>
|
||||
{
|
||||
fn reset(&mut self) {
|
||||
self.current_write_index = 0;
|
||||
}
|
||||
|
||||
fn push(&mut self, mut tc_buffer: &[u8], conn_result: &mut HandledConnectionInfo) {
|
||||
while !tc_buffer.is_empty() {
|
||||
// Write as much as possible to buffer
|
||||
let written = self.write_to_buffer(tc_buffer);
|
||||
tc_buffer = &tc_buffer[written..];
|
||||
|
||||
// Parse for complete packets
|
||||
let packets_found = self.parse_and_handle_packets();
|
||||
conn_result.num_received_tcs += packets_found;
|
||||
|
||||
if tc_buffer.is_empty() {
|
||||
break;
|
||||
}
|
||||
|
||||
// Handle buffer overflow
|
||||
if self.current_write_index == self.parsing_buffer.len() {
|
||||
self.drop_first_half_of_buffer();
|
||||
}
|
||||
tc_sender,
|
||||
)
|
||||
.map_err(|e| TcpTmtcError::TcError(e))?;
|
||||
if let Some(broken_tail_start) = parse_result.incomplete_tail_start {
|
||||
// Copy broken tail to front of buffer.
|
||||
tc_buffer.copy_within(broken_tail_start..current_write_idx, 0);
|
||||
*next_write_idx = current_write_idx - broken_tail_start;
|
||||
}
|
||||
conn_result.num_received_tcs += parse_result.packets_found;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,18 +47,21 @@ impl<PacketValidator: SpacePacketValidator, PacketHandlerInstance: PacketHandler
|
||||
#[derive(Default)]
|
||||
pub struct SpacepacketsTmSender {}
|
||||
|
||||
impl TcpTmSender for SpacepacketsTmSender {
|
||||
impl<TmError, TcError> TcpTmSender<TmError, TcError> for SpacepacketsTmSender {
|
||||
fn handle_tm_sending(
|
||||
&mut self,
|
||||
tm_buffer: &mut [u8],
|
||||
tm_source: &mut (impl PacketSource<Error = ()> + ?Sized),
|
||||
tm_source: &mut (impl PacketSource<Error = TmError> + ?Sized),
|
||||
conn_result: &mut HandledConnectionInfo,
|
||||
stream: &mut TcpStream,
|
||||
) -> Result<bool, std::io::Error> {
|
||||
) -> Result<bool, TcpTmtcError<TmError, TcError>> {
|
||||
let mut tm_was_sent = false;
|
||||
while let Ok(read_tm_len) = tm_source.retrieve_packet(tm_buffer) {
|
||||
loop {
|
||||
// Write TM until TM source is exhausted. For now, there is no limit for the amount
|
||||
// of TM written this way.
|
||||
let read_tm_len = tm_source
|
||||
.retrieve_packet(tm_buffer)
|
||||
.map_err(|e| TcpTmtcError::TmError(e))?;
|
||||
|
||||
if read_tm_len == 0 {
|
||||
return Ok(tm_was_sent);
|
||||
@@ -133,7 +71,6 @@ impl TcpTmSender for SpacepacketsTmSender {
|
||||
|
||||
stream.write_all(&tm_buffer[..read_tm_len])?;
|
||||
}
|
||||
Ok(tm_was_sent)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,25 +88,32 @@ impl TcpTmSender for SpacepacketsTmSender {
|
||||
/// The [TCP server integration tests](https://egit.irs.uni-stuttgart.de/rust/sat-rs/src/branch/main/satrs/tests/tcp_servers.rs)
|
||||
/// also serves as the example application for this module.
|
||||
pub struct TcpSpacepacketsServer<
|
||||
TmSource: PacketSource<Error = ()>,
|
||||
TcSender: PacketHandler<Error = GenericSendError>,
|
||||
TmSource: PacketSource<Error = TmError>,
|
||||
TcSender: PacketSenderRaw<Error = SendError>,
|
||||
Validator: SpacePacketValidator,
|
||||
HandledConnection: HandledConnectionHandler,
|
||||
TmError,
|
||||
SendError: 'static,
|
||||
> {
|
||||
pub generic_server: TcpTmtcGenericServer<
|
||||
TmSource,
|
||||
TcSender,
|
||||
SpacepacketsTmSender,
|
||||
CcsdsPacketParser<Validator, TcSender>,
|
||||
Validator,
|
||||
HandledConnection,
|
||||
TmError,
|
||||
SendError,
|
||||
>,
|
||||
}
|
||||
|
||||
impl<
|
||||
TmSource: PacketSource<Error = ()>,
|
||||
TcSender: PacketHandler<Error = GenericSendError>,
|
||||
TmSource: PacketSource<Error = TmError>,
|
||||
TcSender: PacketSenderRaw<Error = TcError>,
|
||||
Validator: SpacePacketValidator,
|
||||
HandledConnection: HandledConnectionHandler,
|
||||
> TcpSpacepacketsServer<TmSource, TcSender, Validator, HandledConnection>
|
||||
TmError: 'static,
|
||||
TcError: 'static,
|
||||
> TcpSpacepacketsServer<TmSource, TcSender, Validator, HandledConnection, TmError, TcError>
|
||||
{
|
||||
///
|
||||
/// ## Parameter
|
||||
@@ -178,7 +122,7 @@ impl<
|
||||
/// * `tm_source` - Generic TM source used by the server to pull telemetry packets which are
|
||||
/// then sent back to the client.
|
||||
/// * `tc_sender` - Any received telecommands which were decoded successfully will be
|
||||
/// forwarded using this [PacketHandler].
|
||||
/// forwarded using this [PacketSenderRaw].
|
||||
/// * `validator` - Used to determine the space packets relevant for further processing and
|
||||
/// to detect broken space packets.
|
||||
/// * `handled_connection_hook` - Called to notify the user about a succesfully handled
|
||||
@@ -188,16 +132,18 @@ impl<
|
||||
pub fn new(
|
||||
cfg: ServerConfig,
|
||||
tm_source: TmSource,
|
||||
tc_parser: CcsdsPacketParser<Validator, TcSender>,
|
||||
tc_sender: TcSender,
|
||||
validator: Validator,
|
||||
handled_connection_hook: HandledConnection,
|
||||
stop_signal: Option<Arc<AtomicBool>>,
|
||||
) -> Result<Self, std::io::Error> {
|
||||
Ok(Self {
|
||||
generic_server: TcpTmtcGenericServer::new(
|
||||
cfg,
|
||||
tc_parser,
|
||||
validator,
|
||||
SpacepacketsTmSender::default(),
|
||||
tm_source,
|
||||
tc_sender,
|
||||
handled_connection_hook,
|
||||
stop_signal,
|
||||
)?,
|
||||
@@ -216,7 +162,7 @@ impl<
|
||||
pub fn handle_all_connections(
|
||||
&mut self,
|
||||
poll_timeout: Option<Duration>
|
||||
) -> Result<ConnectionResult, std::io::Error>;
|
||||
) -> Result<ConnectionResult, TcpTmtcError<TmError, TcError>>;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -241,7 +187,7 @@ mod tests {
|
||||
use hashbrown::HashSet;
|
||||
use spacepackets::{
|
||||
CcsdsPacket, PacketId, SpHeader,
|
||||
ecss::{CreatorConfig, MessageTypeId, WritablePusPacket, tc::PusTcCreator},
|
||||
ecss::{CreatorConfig, WritablePusPacket, tc::PusTcCreator},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -251,6 +197,7 @@ mod tests {
|
||||
ConnectionResult, ServerConfig,
|
||||
tests::{ConnectionFinishedHandler, SyncTmSource},
|
||||
},
|
||||
queue::GenericSendError,
|
||||
tmtc::PacketAsVec,
|
||||
};
|
||||
|
||||
@@ -277,19 +224,23 @@ mod tests {
|
||||
|
||||
fn generic_tmtc_server(
|
||||
addr: &SocketAddr,
|
||||
tc_parser: super::CcsdsPacketParser<SimpleValidator, mpsc::Sender<PacketAsVec>>,
|
||||
tc_sender: mpsc::Sender<PacketAsVec>,
|
||||
tm_source: SyncTmSource,
|
||||
validator: SimpleValidator,
|
||||
stop_signal: Option<Arc<AtomicBool>>,
|
||||
) -> TcpSpacepacketsServer<
|
||||
SyncTmSource,
|
||||
mpsc::Sender<PacketAsVec>,
|
||||
SimpleValidator,
|
||||
ConnectionFinishedHandler,
|
||||
(),
|
||||
GenericSendError,
|
||||
> {
|
||||
TcpSpacepacketsServer::new(
|
||||
ServerConfig::new(TCP_SERVER_ID, *addr, Duration::from_millis(2), 1024, 1024),
|
||||
tm_source,
|
||||
tc_parser,
|
||||
tc_sender,
|
||||
validator,
|
||||
ConnectionFinishedHandler::default(),
|
||||
stop_signal,
|
||||
)
|
||||
@@ -305,8 +256,9 @@ mod tests {
|
||||
validator.0.insert(TEST_PACKET_ID_0);
|
||||
let mut tcp_server = generic_tmtc_server(
|
||||
&auto_port_addr,
|
||||
super::CcsdsPacketParser::new(TCP_SERVER_ID, 1024, tc_sender.clone(), validator),
|
||||
tc_sender.clone(),
|
||||
tm_source,
|
||||
validator,
|
||||
None,
|
||||
);
|
||||
let dest_addr = tcp_server
|
||||
@@ -334,7 +286,8 @@ mod tests {
|
||||
});
|
||||
let ping_tc = PusTcCreator::new_simple(
|
||||
SpHeader::new_from_apid(TEST_APID_0),
|
||||
MessageTypeId::new(17, 1),
|
||||
17,
|
||||
1,
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
@@ -369,7 +322,8 @@ mod tests {
|
||||
let mut total_tm_len = 0;
|
||||
let verif_tm = PusTcCreator::new_simple(
|
||||
SpHeader::new_from_apid(TEST_APID_0),
|
||||
MessageTypeId::new(1, 1),
|
||||
1,
|
||||
1,
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
@@ -378,7 +332,8 @@ mod tests {
|
||||
tm_source.add_tm(&tm_0);
|
||||
let verif_tm = PusTcCreator::new_simple(
|
||||
SpHeader::new_from_apid(TEST_APID_1),
|
||||
MessageTypeId::new(1, 3),
|
||||
1,
|
||||
3,
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
@@ -392,8 +347,9 @@ mod tests {
|
||||
validator.0.insert(TEST_PACKET_ID_1);
|
||||
let mut tcp_server = generic_tmtc_server(
|
||||
&auto_port_addr,
|
||||
super::CcsdsPacketParser::new(TCP_SERVER_ID, 1024, tc_sender.clone(), validator),
|
||||
tc_sender.clone(),
|
||||
tm_source,
|
||||
validator,
|
||||
None,
|
||||
);
|
||||
let dest_addr = tcp_server
|
||||
@@ -428,7 +384,8 @@ mod tests {
|
||||
// Send telecommands
|
||||
let ping_tc = PusTcCreator::new_simple(
|
||||
SpHeader::new_from_apid(TEST_APID_0),
|
||||
MessageTypeId::new(17, 1),
|
||||
17,
|
||||
1,
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
@@ -438,7 +395,8 @@ mod tests {
|
||||
.expect("writing to TCP server failed");
|
||||
let action_tc = PusTcCreator::new_simple(
|
||||
SpHeader::new_from_apid(TEST_APID_1),
|
||||
MessageTypeId::new(8, 0),
|
||||
8,
|
||||
0,
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Generic UDP TC server.
|
||||
use crate::ComponentId;
|
||||
use crate::tmtc::PacketHandler;
|
||||
use crate::tmtc::PacketSenderRaw;
|
||||
use core::fmt::Debug;
|
||||
use std::io::{self, ErrorKind};
|
||||
use std::net::{SocketAddr, ToSocketAddrs, UdpSocket};
|
||||
@@ -12,7 +12,7 @@ use std::vec::Vec;
|
||||
///
|
||||
/// It caches all received telecomands into a vector. The maximum expected telecommand size should
|
||||
/// be declared upfront. This avoids dynamic allocation during run-time. The user can specify a TC
|
||||
/// sender in form of a special trait object which implements [PacketHandler]. For example, this
|
||||
/// sender in form of a special trait object which implements [PacketSenderRaw]. For example, this
|
||||
/// can be used to send the telecommands to a centralized TC source component for further
|
||||
/// processing and routing.
|
||||
///
|
||||
@@ -24,9 +24,9 @@ use std::vec::Vec;
|
||||
/// use spacepackets::ecss::WritablePusPacket;
|
||||
/// use satrs::hal::std::udp_server::UdpTcServer;
|
||||
/// use satrs::ComponentId;
|
||||
/// use satrs::tmtc::PacketHandler;
|
||||
/// use satrs::tmtc::PacketSenderRaw;
|
||||
/// use spacepackets::SpHeader;
|
||||
/// use spacepackets::ecss::tc::{MessageTypeId, PusTcCreator, CreatorConfig};
|
||||
/// use spacepackets::ecss::tc::{PusTcCreator, CreatorConfig};
|
||||
/// use arbitrary_int::u11;
|
||||
///
|
||||
/// const UDP_SERVER_ID: ComponentId = 0x05;
|
||||
@@ -36,7 +36,7 @@ use std::vec::Vec;
|
||||
/// let mut udp_tc_server = UdpTcServer::new(UDP_SERVER_ID, dest_addr, 2048, packet_sender)
|
||||
/// .expect("Creating UDP TMTC server failed");
|
||||
/// let sph = SpHeader::new_from_apid(u11::new(0x02));
|
||||
/// let pus_tc = PusTcCreator::new_simple(sph, MessageTypeId::new(17, 1), &[], CreatorConfig::default());
|
||||
/// let pus_tc = PusTcCreator::new_simple(sph, 17, 1, &[], CreatorConfig::default());
|
||||
/// // Can not fail.
|
||||
/// let ping_tc_raw = pus_tc.to_vec().unwrap();
|
||||
///
|
||||
@@ -60,7 +60,7 @@ use std::vec::Vec;
|
||||
/// [example code](https://egit.irs.uni-stuttgart.de/rust/sat-rs/src/branch/main/satrs-example/src/tmtc.rs#L67)
|
||||
/// on how to use this TC server. It uses the server to receive PUS telecommands on a specific port
|
||||
/// and then forwards them to a generic CCSDS packet receiver.
|
||||
pub struct UdpTcServer<TcSender: PacketHandler<Error = SendError>, SendError> {
|
||||
pub struct UdpTcServer<TcSender: PacketSenderRaw<Error = SendError>, SendError> {
|
||||
pub id: ComponentId,
|
||||
pub socket: UdpSocket,
|
||||
recv_buf: Vec<u8>,
|
||||
@@ -78,7 +78,7 @@ pub enum ReceiveResult<SendError: Debug + 'static> {
|
||||
Send(SendError),
|
||||
}
|
||||
|
||||
impl<TcSender: PacketHandler<Error = SendError>, SendError: Debug + 'static>
|
||||
impl<TcSender: PacketSenderRaw<Error = SendError>, SendError: Debug + 'static>
|
||||
UdpTcServer<TcSender, SendError>
|
||||
{
|
||||
pub fn new<A: ToSocketAddrs>(
|
||||
@@ -112,7 +112,7 @@ impl<TcSender: PacketHandler<Error = SendError>, SendError: Debug + 'static>
|
||||
let (num_bytes, from) = res;
|
||||
self.sender_addr = Some(from);
|
||||
self.tc_sender
|
||||
.handle_packet(self.id, &self.recv_buf[0..num_bytes])
|
||||
.send_packet(self.id, &self.recv_buf[0..num_bytes])
|
||||
.map_err(ReceiveResult::Send)?;
|
||||
Ok(res)
|
||||
}
|
||||
@@ -127,12 +127,12 @@ mod tests {
|
||||
use crate::ComponentId;
|
||||
use crate::hal::std::udp_server::{ReceiveResult, UdpTcServer};
|
||||
use crate::queue::GenericSendError;
|
||||
use crate::tmtc::PacketHandler;
|
||||
use crate::tmtc::PacketSenderRaw;
|
||||
use arbitrary_int::u11;
|
||||
use core::cell::RefCell;
|
||||
use spacepackets::SpHeader;
|
||||
use spacepackets::ecss::CreatorConfig;
|
||||
use spacepackets::ecss::tc::PusTcCreator;
|
||||
use spacepackets::ecss::{CreatorConfig, MessageTypeId};
|
||||
use std::collections::VecDeque;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};
|
||||
use std::vec::Vec;
|
||||
@@ -146,10 +146,10 @@ mod tests {
|
||||
pub sent_cmds: RefCell<VecDeque<Vec<u8>>>,
|
||||
}
|
||||
|
||||
impl PacketHandler for PingReceiver {
|
||||
impl PacketSenderRaw for PingReceiver {
|
||||
type Error = GenericSendError;
|
||||
|
||||
fn handle_packet(&self, sender_id: ComponentId, tc_raw: &[u8]) -> Result<(), Self::Error> {
|
||||
fn send_packet(&self, sender_id: ComponentId, tc_raw: &[u8]) -> Result<(), Self::Error> {
|
||||
assert_eq!(sender_id, UDP_SERVER_ID);
|
||||
let mut sent_data = Vec::new();
|
||||
sent_data.extend_from_slice(tc_raw);
|
||||
@@ -169,12 +169,7 @@ mod tests {
|
||||
.expect("Creating UDP TMTC server failed");
|
||||
is_send(&udp_tc_server);
|
||||
let sph = SpHeader::new_from_apid(u11::new(0x02));
|
||||
let pus_tc = PusTcCreator::new_simple(
|
||||
sph,
|
||||
MessageTypeId::new(17, 1),
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
let pus_tc = PusTcCreator::new_simple(sph, 17, 1, &[], CreatorConfig::default());
|
||||
let len = pus_tc
|
||||
.write_to_bytes(&mut buf)
|
||||
.expect("Error writing PUS TC packet");
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
//! - The [pus] module which provides special support for projects using
|
||||
//! the [ECSS PUS C standard](https://ecss.nl/standard/ecss-e-st-70-41c-space-engineering-telemetry-and-telecommand-packet-utilization-15-april-2016/).
|
||||
#![no_std]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
#[cfg(any(feature = "alloc", test))]
|
||||
extern crate alloc;
|
||||
#[cfg(feature = "alloc")]
|
||||
@@ -51,13 +51,14 @@ pub mod scheduling;
|
||||
pub mod subsystem;
|
||||
pub mod time;
|
||||
pub mod tmtc;
|
||||
pub mod ccsds;
|
||||
|
||||
pub use spacepackets;
|
||||
|
||||
use spacepackets::PacketId;
|
||||
|
||||
/// Generic component ID type.
|
||||
pub type ComponentId = u32;
|
||||
pub type ComponentId = u64;
|
||||
|
||||
pub trait ValidatorU16Id {
|
||||
fn validate(&self, id: u16) -> bool;
|
||||
|
||||
@@ -4,7 +4,6 @@ use spacepackets::ByteConversionError;
|
||||
use spacepackets::SpHeader;
|
||||
use spacepackets::ecss::CreatorConfig;
|
||||
use spacepackets::ecss::EcssEnumeration;
|
||||
use spacepackets::ecss::MessageTypeId;
|
||||
use spacepackets::ecss::tm::PusTmCreator;
|
||||
use spacepackets::ecss::tm::PusTmSecondaryHeader;
|
||||
|
||||
@@ -111,12 +110,8 @@ impl EventReportCreator {
|
||||
src_data_len += aux_data.len();
|
||||
}
|
||||
source_buffer_large_enough(src_data_buf.len(), src_data_len)?;
|
||||
let sec_header = PusTmSecondaryHeader::new(
|
||||
MessageTypeId::new(5, subservice.into()),
|
||||
0,
|
||||
self.dest_id,
|
||||
time_stamp,
|
||||
);
|
||||
let sec_header =
|
||||
PusTmSecondaryHeader::new(5, subservice.into(), 0, self.dest_id, time_stamp);
|
||||
let mut current_idx = 0;
|
||||
event_id.write_to_be_bytes(&mut src_data_buf[0..event_id.size()])?;
|
||||
current_idx += event_id.size();
|
||||
|
||||
@@ -311,7 +311,7 @@ pub mod alloc_mod {
|
||||
mod tests {
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec;
|
||||
use arbitrary_int::{u11, u21};
|
||||
use arbitrary_int::u11;
|
||||
use spacepackets::ecss::PusPacket;
|
||||
use spacepackets::ecss::event::Subservice;
|
||||
use spacepackets::ecss::tm::PusTmReader;
|
||||
@@ -325,7 +325,7 @@ mod tests {
|
||||
const LOW_SEV_EVENT: EventU32 = EventU32::new(Severity::Low, 1, 5);
|
||||
const EMPTY_STAMP: [u8; 7] = [0; 7];
|
||||
const TEST_APID: u11 = u11::new(0x02);
|
||||
const TEST_ID: UniqueApidTargetId = UniqueApidTargetId::new(TEST_APID, u21::new(0x05));
|
||||
const TEST_ID: UniqueApidTargetId = UniqueApidTargetId::new(TEST_APID, 0x05);
|
||||
|
||||
fn create_basic_man_1() -> DefaultPusEventU32TmCreator {
|
||||
let reporter = EventReporter::new(TEST_ID.raw(), TEST_APID, 0, 128);
|
||||
@@ -409,8 +409,8 @@ mod tests {
|
||||
assert!(res.params_were_propagated);
|
||||
let event_tm = event_rx.try_recv().expect("no event received");
|
||||
let tm = PusTmReader::new(&event_tm.packet, 7).expect("reading TM failed");
|
||||
assert_eq!(tm.service_type_id(), 5);
|
||||
assert_eq!(tm.message_subtype_id(), Subservice::TmInfoReport as u8);
|
||||
assert_eq!(tm.service(), 5);
|
||||
assert_eq!(tm.subservice(), Subservice::TmInfoReport as u8);
|
||||
assert_eq!(tm.user_data().len(), 4 + param_data.len());
|
||||
let u32_event = u32::from_be_bytes(tm.user_data()[0..4].try_into().unwrap());
|
||||
assert_eq!(u32_event, INFO_EVENT.raw());
|
||||
@@ -437,8 +437,8 @@ mod tests {
|
||||
assert!(res.params_were_propagated);
|
||||
let event_tm = event_rx.try_recv().expect("no event received");
|
||||
let tm = PusTmReader::new(&event_tm.packet, 7).expect("reading TM failed");
|
||||
assert_eq!(tm.service_type_id(), 5);
|
||||
assert_eq!(tm.message_subtype_id(), Subservice::TmInfoReport as u8);
|
||||
assert_eq!(tm.service(), 5);
|
||||
assert_eq!(tm.subservice(), Subservice::TmInfoReport as u8);
|
||||
assert_eq!(tm.user_data().len(), 4 + param_data.len());
|
||||
let u32_event = u32::from_be_bytes(tm.user_data()[0..4].try_into().unwrap());
|
||||
assert_eq!(u32_event, INFO_EVENT.raw());
|
||||
|
||||
@@ -60,11 +60,11 @@ impl<
|
||||
.tc_in_mem_converter_mut()
|
||||
.cache(&ecss_tc_and_token.tc_in_memory)?;
|
||||
let tc = self.service_helper.tc_in_mem_converter().convert()?;
|
||||
let subservice = tc.message_subtype_id();
|
||||
let subservice = tc.subservice();
|
||||
let srv = Subservice::try_from(subservice);
|
||||
if srv.is_err() {
|
||||
return Ok(DirectPusPacketHandlerResult::CustomSubservice(
|
||||
tc.message_subtype_id(),
|
||||
tc.subservice(),
|
||||
ecss_tc_and_token.token,
|
||||
));
|
||||
}
|
||||
@@ -121,7 +121,7 @@ impl<
|
||||
| Subservice::TmMediumSeverityReport
|
||||
| Subservice::TmHighSeverityReport => {
|
||||
return Err(PusPacketHandlingError::RequestConversion(
|
||||
GenericConversionError::WrongService(tc.message_subtype_id()),
|
||||
GenericConversionError::WrongService(tc.subservice()),
|
||||
));
|
||||
}
|
||||
Subservice::TcEnableEventGeneration => {
|
||||
@@ -147,8 +147,8 @@ mod tests {
|
||||
use arbitrary_int::traits::Integer as _;
|
||||
use arbitrary_int::u14;
|
||||
use delegate::delegate;
|
||||
use spacepackets::ecss::CreatorConfig;
|
||||
use spacepackets::ecss::event::Subservice;
|
||||
use spacepackets::ecss::{CreatorConfig, MessageTypeId};
|
||||
use spacepackets::time::{TimeWriter, cds};
|
||||
use spacepackets::util::UnsignedEnum;
|
||||
use spacepackets::{
|
||||
@@ -246,7 +246,7 @@ mod tests {
|
||||
event_req_receiver: mpsc::Receiver<EventRequestWithToken>,
|
||||
) {
|
||||
let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, u14::ZERO, 0);
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(5, subservice as u8));
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(5, subservice as u8);
|
||||
let mut app_data = [0; 4];
|
||||
TEST_EVENT_0
|
||||
.write_to_be_bytes(&mut app_data)
|
||||
@@ -311,7 +311,7 @@ mod tests {
|
||||
let (event_request_tx, _) = mpsc::channel();
|
||||
let mut test_harness = Pus5HandlerWithStoreTester::new(event_request_tx);
|
||||
let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, u14::ZERO, 0);
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(5, 200));
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(5, 200);
|
||||
let ping_tc =
|
||||
PusTcCreator::new_no_app_data(sp_header, sec_header, CreatorConfig::default());
|
||||
let token = test_harness.start_verification(&ping_tc);
|
||||
@@ -331,10 +331,8 @@ mod tests {
|
||||
let (event_request_tx, _) = mpsc::channel();
|
||||
let mut test_harness = Pus5HandlerWithStoreTester::new(event_request_tx);
|
||||
let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, u14::ZERO, 0);
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(
|
||||
5,
|
||||
Subservice::TcEnableEventGeneration as u8,
|
||||
));
|
||||
let sec_header =
|
||||
PusTcSecondaryHeader::new_simple(5, Subservice::TcEnableEventGeneration as u8);
|
||||
let ping_tc =
|
||||
PusTcCreator::new(sp_header, sec_header, &[0, 1, 2], CreatorConfig::default());
|
||||
let token = test_harness.start_verification(&ping_tc);
|
||||
|
||||
@@ -1258,7 +1258,7 @@ pub(crate) fn source_buffer_large_enough(
|
||||
|
||||
#[cfg(any(feature = "test_util", test))]
|
||||
pub mod test_util {
|
||||
use arbitrary_int::{u11, u21};
|
||||
use arbitrary_int::u11;
|
||||
use spacepackets::ecss::{tc::PusTcCreator, tm::PusTmReader};
|
||||
|
||||
use crate::request::UniqueApidTargetId;
|
||||
@@ -1269,8 +1269,8 @@ pub mod test_util {
|
||||
};
|
||||
|
||||
pub const TEST_APID: u11 = u11::new(0x101);
|
||||
pub const TEST_UNIQUE_ID_0: u21 = u21::new(0x05);
|
||||
pub const TEST_UNIQUE_ID_1: u21 = u21::new(0x06);
|
||||
pub const TEST_UNIQUE_ID_0: u32 = 0x05;
|
||||
pub const TEST_UNIQUE_ID_1: u32 = 0x06;
|
||||
|
||||
pub const TEST_COMPONENT_ID_0: UniqueApidTargetId =
|
||||
UniqueApidTargetId::new(TEST_APID, TEST_UNIQUE_ID_0);
|
||||
@@ -1364,10 +1364,10 @@ pub mod tests {
|
||||
let mut timestamp = [0; 7];
|
||||
timestamp.clone_from_slice(&tm.timestamp()[0..7]);
|
||||
Self {
|
||||
subservice: PusPacket::message_subtype_id(tm),
|
||||
subservice: PusPacket::subservice(tm),
|
||||
apid: tm.apid(),
|
||||
seq_count: tm.seq_count(),
|
||||
msg_counter: tm.msg_type_counter(),
|
||||
msg_counter: tm.msg_counter(),
|
||||
dest_id: tm.dest_id(),
|
||||
timestamp: timestamp.to_vec(),
|
||||
}
|
||||
@@ -1478,8 +1478,8 @@ pub mod tests {
|
||||
let tm_pool = self.tm_pool.0.read().unwrap();
|
||||
let tm_raw = tm_pool.read_as_vec(&tm_in_pool.store_addr).unwrap();
|
||||
let tm = PusTmReader::new(&tm_raw, 7).unwrap();
|
||||
assert_eq!(PusPacket::service_type_id(&tm), 1);
|
||||
assert_eq!(PusPacket::message_subtype_id(&tm), subservice);
|
||||
assert_eq!(PusPacket::service(&tm), 1);
|
||||
assert_eq!(PusPacket::subservice(&tm), subservice);
|
||||
assert_eq!(tm.apid(), TEST_APID);
|
||||
let req_id =
|
||||
RequestId::from_bytes(tm.user_data()).expect("generating request ID failed");
|
||||
@@ -1597,8 +1597,8 @@ pub mod tests {
|
||||
assert!(next_msg.is_ok());
|
||||
let next_msg = next_msg.unwrap();
|
||||
let tm = PusTmReader::new(next_msg.packet.as_slice(), 7).unwrap();
|
||||
assert_eq!(PusPacket::service_type_id(&tm), 1);
|
||||
assert_eq!(PusPacket::message_subtype_id(&tm), subservice);
|
||||
assert_eq!(PusPacket::service(&tm), 1);
|
||||
assert_eq!(PusPacket::subservice(&tm), subservice);
|
||||
assert_eq!(tm.apid(), TEST_APID);
|
||||
let req_id =
|
||||
RequestId::from_bytes(tm.user_data()).expect("generating request ID failed");
|
||||
@@ -1615,9 +1615,9 @@ pub mod tests {
|
||||
|
||||
impl<const SERVICE: u8> TestConverter<SERVICE> {
|
||||
pub fn check_service(&self, tc: &PusTcReader) -> Result<(), PusPacketHandlingError> {
|
||||
if tc.service_type_id() != SERVICE {
|
||||
if tc.service() != SERVICE {
|
||||
return Err(PusPacketHandlingError::RequestConversion(
|
||||
GenericConversionError::WrongService(tc.service_type_id()),
|
||||
GenericConversionError::WrongService(tc.service()),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -37,7 +37,6 @@ mod tests {
|
||||
use std::sync::mpsc;
|
||||
|
||||
use crate::{
|
||||
ComponentId,
|
||||
mode::{
|
||||
ModeAndSubmode, ModeReply, ModeReplySender, ModeRequest, ModeRequestSender,
|
||||
ModeRequestorAndHandlerMpsc, ModeRequestorOneChildMpsc,
|
||||
@@ -45,9 +44,9 @@ mod tests {
|
||||
request::{GenericMessage, MessageMetadata},
|
||||
};
|
||||
|
||||
const TEST_COMPONENT_ID_0: ComponentId = 5;
|
||||
const TEST_COMPONENT_ID_1: ComponentId = 6;
|
||||
const TEST_COMPONENT_ID_2: ComponentId = 7;
|
||||
const TEST_COMPONENT_ID_0: u64 = 5;
|
||||
const TEST_COMPONENT_ID_1: u64 = 6;
|
||||
const TEST_COMPONENT_ID_2: u64 = 7;
|
||||
|
||||
#[test]
|
||||
fn test_simple_mode_requestor() {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! The core data structure of this module is the [PusScheduler]. This structure can be used
|
||||
//! to perform the scheduling of telecommands like specified in the ECSS standard.
|
||||
use arbitrary_int::{u11, u14};
|
||||
use core::fmt::{Debug, Display, Formatter};
|
||||
use core::fmt::Debug;
|
||||
use core::time::Duration;
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -12,8 +12,6 @@ use spacepackets::ecss::tc::{GenericPusTcSecondaryHeader, IsPusTelecommand, PusT
|
||||
use spacepackets::ecss::{PusError, PusPacket, WritablePusPacket};
|
||||
use spacepackets::time::{CcsdsTimeProvider, TimeReader, TimeWriter, TimestampError, UnixTime};
|
||||
use spacepackets::{ByteConversionError, CcsdsPacket};
|
||||
#[cfg(feature = "std")]
|
||||
use std::error::Error;
|
||||
|
||||
use crate::pool::{PoolError, PoolProvider};
|
||||
#[cfg(feature = "alloc")]
|
||||
@@ -144,107 +142,39 @@ impl<TimeProvider: CcsdsTimeProvider + Clone> TimeWindow<TimeProvider> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub enum ScheduleError {
|
||||
PusError(PusError),
|
||||
#[error("pus error: {0}")]
|
||||
PusError(#[from] PusError),
|
||||
/// The release time is within the time-margin added on top of the current time.
|
||||
/// The first parameter is the current time, the second one the time margin, and the third one
|
||||
/// the release time.
|
||||
#[error("release time in margin")]
|
||||
ReleaseTimeInTimeMargin {
|
||||
current_time: UnixTime,
|
||||
time_margin: Duration,
|
||||
release_time: UnixTime,
|
||||
},
|
||||
/// Nested time-tagged commands are not allowed.
|
||||
#[error("nested scheduled tc")]
|
||||
NestedScheduledTc,
|
||||
StoreError(PoolError),
|
||||
#[error("store error")]
|
||||
Pool(#[from] PoolError),
|
||||
#[error("tc data empty")]
|
||||
TcDataEmpty,
|
||||
TimestampError(TimestampError),
|
||||
#[error("timestamp error: {0}")]
|
||||
TimestampError(#[from] TimestampError),
|
||||
#[error("wrong subservice number {0}")]
|
||||
WrongSubservice(u8),
|
||||
#[error("wrong service number {0}")]
|
||||
WrongService(u8),
|
||||
ByteConversionError(ByteConversionError),
|
||||
}
|
||||
|
||||
impl Display for ScheduleError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
|
||||
match self {
|
||||
ScheduleError::PusError(e) => {
|
||||
write!(f, "Pus Error: {e}")
|
||||
}
|
||||
ScheduleError::ReleaseTimeInTimeMargin {
|
||||
current_time,
|
||||
time_margin,
|
||||
release_time,
|
||||
} => {
|
||||
write!(
|
||||
f,
|
||||
"time margin too short, current time: {current_time:?}, time margin: {time_margin:?}, release time: {release_time:?}"
|
||||
)
|
||||
}
|
||||
ScheduleError::NestedScheduledTc => {
|
||||
write!(f, "nested scheduling is not allowed")
|
||||
}
|
||||
ScheduleError::StoreError(e) => {
|
||||
write!(f, "pus scheduling: {e}")
|
||||
}
|
||||
ScheduleError::TcDataEmpty => {
|
||||
write!(f, "empty TC data field")
|
||||
}
|
||||
ScheduleError::TimestampError(e) => {
|
||||
write!(f, "pus scheduling: {e}")
|
||||
}
|
||||
ScheduleError::WrongService(srv) => {
|
||||
write!(f, "pus scheduling: wrong service number {srv}")
|
||||
}
|
||||
ScheduleError::WrongSubservice(subsrv) => {
|
||||
write!(f, "pus scheduling: wrong subservice number {subsrv}")
|
||||
}
|
||||
ScheduleError::ByteConversionError(e) => {
|
||||
write!(f, "pus scheduling: {e}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PusError> for ScheduleError {
|
||||
fn from(e: PusError) -> Self {
|
||||
Self::PusError(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PoolError> for ScheduleError {
|
||||
fn from(e: PoolError) -> Self {
|
||||
Self::StoreError(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TimestampError> for ScheduleError {
|
||||
fn from(e: TimestampError) -> Self {
|
||||
Self::TimestampError(e)
|
||||
}
|
||||
}
|
||||
impl From<ByteConversionError> for ScheduleError {
|
||||
fn from(e: ByteConversionError) -> Self {
|
||||
Self::ByteConversionError(e)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Error for ScheduleError {
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||
match self {
|
||||
ScheduleError::PusError(e) => Some(e),
|
||||
ScheduleError::StoreError(e) => Some(e),
|
||||
ScheduleError::TimestampError(e) => Some(e),
|
||||
ScheduleError::ByteConversionError(e) => Some(e),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
#[error("byte conversion error: {0}")]
|
||||
ByteConversionError(#[from] ByteConversionError),
|
||||
}
|
||||
|
||||
/// Generic trait for scheduler objects which are able to schedule ECSS PUS C packets.
|
||||
pub trait PusSchedulerProvider {
|
||||
pub trait PusScheduler {
|
||||
type TimeProvider: CcsdsTimeProvider + TimeReader;
|
||||
|
||||
fn reset(&mut self, store: &mut (impl PoolProvider + ?Sized)) -> Result<(), PoolError>;
|
||||
@@ -272,16 +202,14 @@ pub trait PusSchedulerProvider {
|
||||
pus_tc: &(impl IsPusTelecommand + PusPacket + GenericPusTcSecondaryHeader),
|
||||
pool: &mut (impl PoolProvider + ?Sized),
|
||||
) -> Result<TcInfo, ScheduleError> {
|
||||
if PusPacket::service_type_id(pus_tc) != 11 {
|
||||
return Err(ScheduleError::WrongService(PusPacket::service_type_id(
|
||||
if PusPacket::service(pus_tc) != 11 {
|
||||
return Err(ScheduleError::WrongService(PusPacket::service(pus_tc)));
|
||||
}
|
||||
if PusPacket::subservice(pus_tc) != 4 {
|
||||
return Err(ScheduleError::WrongSubservice(PusPacket::subservice(
|
||||
pus_tc,
|
||||
)));
|
||||
}
|
||||
if PusPacket::message_subtype_id(pus_tc) != 4 {
|
||||
return Err(ScheduleError::WrongSubservice(
|
||||
PusPacket::message_subtype_id(pus_tc),
|
||||
));
|
||||
}
|
||||
if pus_tc.user_data().is_empty() {
|
||||
return Err(ScheduleError::TcDataEmpty);
|
||||
}
|
||||
@@ -301,9 +229,7 @@ pub trait PusSchedulerProvider {
|
||||
pool: &mut (impl PoolProvider + ?Sized),
|
||||
) -> Result<TcInfo, ScheduleError> {
|
||||
let check_tc = PusTcReader::new(tc)?;
|
||||
if PusPacket::service_type_id(&check_tc) == 11
|
||||
&& PusPacket::message_subtype_id(&check_tc) == 4
|
||||
{
|
||||
if PusPacket::service(&check_tc) == 11 && PusPacket::subservice(&check_tc) == 4 {
|
||||
return Err(ScheduleError::NestedScheduledTc);
|
||||
}
|
||||
let req_id = RequestId::from_tc(&check_tc);
|
||||
@@ -405,7 +331,7 @@ pub mod alloc_mod {
|
||||
///
|
||||
/// Currently, sub-schedules and groups are not supported.
|
||||
#[derive(Debug)]
|
||||
pub struct PusScheduler {
|
||||
pub struct PusSchedulerAlloc {
|
||||
// TODO: Use MonotonicTime from tai-time crate instead of UnixTime and cache leap seconds.
|
||||
// TODO: Introduce optional limit of commands stored in the TC map. If a limit is set,
|
||||
// there will be a check for each insertion whether the map is full, making the memory
|
||||
@@ -415,7 +341,8 @@ pub mod alloc_mod {
|
||||
time_margin: Duration,
|
||||
enabled: bool,
|
||||
}
|
||||
impl PusScheduler {
|
||||
|
||||
impl PusSchedulerAlloc {
|
||||
/// Create a new PUS scheduler.
|
||||
///
|
||||
/// # Arguments
|
||||
@@ -427,7 +354,7 @@ pub mod alloc_mod {
|
||||
/// * `tc_buf_size` - Buffer for temporary storage of telecommand packets. This buffer
|
||||
/// should be large enough to accomodate the largest expected TC packets.
|
||||
pub fn new(init_current_time: UnixTime, time_margin: Duration) -> Self {
|
||||
PusScheduler {
|
||||
PusSchedulerAlloc {
|
||||
tc_map: Default::default(),
|
||||
current_time: init_current_time,
|
||||
time_margin,
|
||||
@@ -449,10 +376,12 @@ pub mod alloc_mod {
|
||||
num_entries
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn update_time(&mut self, current_time: UnixTime) {
|
||||
self.current_time = current_time;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn current_time(&self) -> &UnixTime {
|
||||
&self.current_time
|
||||
}
|
||||
@@ -491,9 +420,7 @@ pub mod alloc_mod {
|
||||
pool: &mut (impl PoolProvider + ?Sized),
|
||||
) -> Result<TcInfo, ScheduleError> {
|
||||
let check_tc = PusTcReader::new(tc)?;
|
||||
if PusPacket::service_type_id(&check_tc) == 11
|
||||
&& PusPacket::message_subtype_id(&check_tc) == 4
|
||||
{
|
||||
if PusPacket::service(&check_tc) == 11 && PusPacket::subservice(&check_tc) == 4 {
|
||||
return Err(ScheduleError::NestedScheduledTc);
|
||||
}
|
||||
let req_id = RequestId::from_tc(&check_tc);
|
||||
@@ -798,7 +725,7 @@ pub mod alloc_mod {
|
||||
}
|
||||
}
|
||||
|
||||
impl PusSchedulerProvider for PusScheduler {
|
||||
impl PusScheduler for PusSchedulerAlloc {
|
||||
type TimeProvider = cds::CdsTime;
|
||||
|
||||
/// This will disable the scheduler and clear the schedule as specified in 6.11.4.4.
|
||||
@@ -871,7 +798,7 @@ mod tests {
|
||||
use arbitrary_int::traits::Integer;
|
||||
use arbitrary_int::{u11, u14};
|
||||
use spacepackets::ecss::tc::{PusTcCreator, PusTcReader, PusTcSecondaryHeader};
|
||||
use spacepackets::ecss::{CreatorConfig, MessageTypeId, WritablePusPacket};
|
||||
use spacepackets::ecss::{CreatorConfig, WritablePusPacket};
|
||||
use spacepackets::time::{TimeWriter, UnixTime, cds};
|
||||
use spacepackets::{PacketId, PacketSequenceControl, PacketType, SequenceFlags, SpHeader};
|
||||
use std::time::Duration;
|
||||
@@ -895,32 +822,17 @@ mod tests {
|
||||
|
||||
fn scheduled_tc(timestamp: UnixTime, buf: &mut [u8]) -> PusTcCreator<'_> {
|
||||
let (sph, len_app_data) = pus_tc_base(timestamp, buf);
|
||||
PusTcCreator::new_simple(
|
||||
sph,
|
||||
MessageTypeId::new(11, 4),
|
||||
&buf[..len_app_data],
|
||||
CreatorConfig::default(),
|
||||
)
|
||||
PusTcCreator::new_simple(sph, 11, 4, &buf[..len_app_data], CreatorConfig::default())
|
||||
}
|
||||
|
||||
fn wrong_tc_service(timestamp: UnixTime, buf: &mut [u8]) -> PusTcCreator<'_> {
|
||||
let (sph, len_app_data) = pus_tc_base(timestamp, buf);
|
||||
PusTcCreator::new_simple(
|
||||
sph,
|
||||
MessageTypeId::new(12, 4),
|
||||
&buf[..len_app_data],
|
||||
CreatorConfig::default(),
|
||||
)
|
||||
PusTcCreator::new_simple(sph, 12, 4, &buf[..len_app_data], CreatorConfig::default())
|
||||
}
|
||||
|
||||
fn wrong_tc_subservice(timestamp: UnixTime, buf: &mut [u8]) -> PusTcCreator<'_> {
|
||||
let (sph, len_app_data) = pus_tc_base(timestamp, buf);
|
||||
PusTcCreator::new_simple(
|
||||
sph,
|
||||
MessageTypeId::new(11, 5),
|
||||
&buf[..len_app_data],
|
||||
CreatorConfig::default(),
|
||||
)
|
||||
PusTcCreator::new_simple(sph, 11, 5, &buf[..len_app_data], CreatorConfig::default())
|
||||
}
|
||||
|
||||
fn double_wrapped_time_tagged_tc(timestamp: UnixTime, buf: &mut [u8]) -> PusTcCreator<'_> {
|
||||
@@ -931,18 +843,15 @@ mod tests {
|
||||
let sph = SpHeader::new_for_unseg_tc(u11::new(0x02), u14::new(0x34), 0);
|
||||
// app data should not matter, double wrapped time-tagged commands should be rejected right
|
||||
// away
|
||||
let inner_time_tagged_tc = PusTcCreator::new_simple(
|
||||
sph,
|
||||
MessageTypeId::new(11, 4),
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
let inner_time_tagged_tc =
|
||||
PusTcCreator::new_simple(sph, 11, 4, &[], CreatorConfig::default());
|
||||
let packet_len = inner_time_tagged_tc
|
||||
.write_to_bytes(&mut buf[len_time_stamp..])
|
||||
.expect("writing inner time tagged tc failed");
|
||||
PusTcCreator::new_simple(
|
||||
sph,
|
||||
MessageTypeId::new(11, 4),
|
||||
11,
|
||||
4,
|
||||
&buf[..len_time_stamp + packet_len],
|
||||
CreatorConfig::default(),
|
||||
)
|
||||
@@ -950,22 +859,12 @@ mod tests {
|
||||
|
||||
fn invalid_time_tagged_cmd() -> PusTcCreator<'static> {
|
||||
let sph = SpHeader::new_for_unseg_tc(u11::new(0x02), u14::new(0x34), 1);
|
||||
PusTcCreator::new_simple(
|
||||
sph,
|
||||
MessageTypeId::new(11, 4),
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
)
|
||||
PusTcCreator::new_simple(sph, 11, 4, &[], CreatorConfig::default())
|
||||
}
|
||||
|
||||
fn base_ping_tc_simple_ctor(seq_count: u14, app_data: &'static [u8]) -> PusTcCreator<'static> {
|
||||
let sph = SpHeader::new_for_unseg_tc(u11::new(0x02), seq_count, 0);
|
||||
PusTcCreator::new_simple(
|
||||
sph,
|
||||
MessageTypeId::new(17, 1),
|
||||
app_data,
|
||||
CreatorConfig::default(),
|
||||
)
|
||||
PusTcCreator::new_simple(sph, 17, 1, app_data, CreatorConfig::default())
|
||||
}
|
||||
|
||||
fn ping_tc_to_store(
|
||||
@@ -982,7 +881,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_enable_api() {
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
assert!(scheduler.is_enabled());
|
||||
scheduler.disable();
|
||||
assert!(!scheduler.is_enabled());
|
||||
@@ -996,7 +896,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
|
||||
let mut buf: [u8; 32] = [0; 32];
|
||||
let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, u14::new(0), &[]);
|
||||
@@ -1038,7 +939,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn insert_multi_with_same_time() {
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
|
||||
scheduler
|
||||
.insert_unwrapped_and_stored_tc(
|
||||
@@ -1097,7 +999,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_time_update() {
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let time = UnixTime::new(1, 2_000_000);
|
||||
scheduler.update_time(time);
|
||||
assert_eq!(scheduler.current_time(), &time);
|
||||
@@ -1130,7 +1033,7 @@ mod tests {
|
||||
let apid_to_set = u11::new(0x22);
|
||||
let seq_count = u14::new(105);
|
||||
let sp_header = SpHeader::new_for_unseg_tc(apid_to_set, u14::new(105), 0);
|
||||
let mut sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(17, 1));
|
||||
let mut sec_header = PusTcSecondaryHeader::new_simple(17, 1);
|
||||
sec_header.source_id = src_id_to_set;
|
||||
let ping_tc =
|
||||
PusTcCreator::new_no_app_data(sp_header, sec_header, CreatorConfig::default());
|
||||
@@ -1151,7 +1054,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
|
||||
let mut buf: [u8; 32] = [0; 32];
|
||||
let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, u14::ZERO, &[]);
|
||||
@@ -1219,7 +1123,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
|
||||
let mut buf: [u8; 32] = [0; 32];
|
||||
let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, u14::ZERO, &[]);
|
||||
@@ -1279,7 +1184,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
|
||||
scheduler.disable();
|
||||
|
||||
@@ -1344,7 +1250,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn insert_unwrapped_tc() {
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
|
||||
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new_from_subpool_cfg_tuples(
|
||||
vec![(10, 32), (5, 64)],
|
||||
@@ -1394,7 +1301,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn insert_wrapped_tc() {
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
|
||||
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new_from_subpool_cfg_tuples(
|
||||
vec![(10, 32), (5, 64)],
|
||||
@@ -1446,7 +1354,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn insert_wrong_service() {
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
|
||||
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new_from_subpool_cfg_tuples(
|
||||
vec![(10, 32), (5, 64)],
|
||||
@@ -1471,7 +1380,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn insert_wrong_subservice() {
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
|
||||
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new_from_subpool_cfg_tuples(
|
||||
vec![(10, 32), (5, 64)],
|
||||
@@ -1496,7 +1406,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn insert_wrapped_tc_faulty_app_data() {
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new_from_subpool_cfg_tuples(
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
@@ -1513,7 +1424,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn insert_doubly_wrapped_time_tagged_cmd() {
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new_from_subpool_cfg_tuples(
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
@@ -1531,7 +1443,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_ctor_from_current() {
|
||||
let scheduler = PusScheduler::new_with_current_init_time(Duration::from_secs(5))
|
||||
let scheduler = PusSchedulerAlloc::new_with_current_init_time(Duration::from_secs(5))
|
||||
.expect("creation from current time failed");
|
||||
let current_time = scheduler.current_time;
|
||||
assert!(current_time.as_secs() > 0);
|
||||
@@ -1539,7 +1451,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_update_from_current() {
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
assert_eq!(scheduler.current_time.as_secs(), 0);
|
||||
scheduler
|
||||
.update_time_from_now()
|
||||
@@ -1549,7 +1462,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn release_time_within_time_margin() {
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
|
||||
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new_from_subpool_cfg_tuples(
|
||||
vec![(10, 32), (5, 64)],
|
||||
@@ -1582,7 +1496,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut buf: [u8; 32] = [0; 32];
|
||||
let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, u14::ZERO, &[]);
|
||||
scheduler
|
||||
@@ -1619,7 +1534,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut buf: [u8; 32] = [0; 32];
|
||||
let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, u14::ZERO, &[]);
|
||||
scheduler
|
||||
@@ -1645,7 +1561,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut buf: [u8; 32] = [0; 32];
|
||||
let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, u14::ZERO, &[]);
|
||||
scheduler
|
||||
@@ -1666,7 +1583,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut buf: [u8; 32] = [0; 32];
|
||||
let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, u14::ZERO, &[]);
|
||||
scheduler
|
||||
@@ -1687,7 +1605,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut buf: [u8; 32] = [0; 32];
|
||||
let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, u14::ZERO, &[]);
|
||||
scheduler
|
||||
@@ -1729,7 +1648,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn insert_full_store_test() {
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
|
||||
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new_from_subpool_cfg_tuples(
|
||||
vec![(1, 64)],
|
||||
@@ -1745,7 +1665,7 @@ mod tests {
|
||||
assert!(insert_res.is_err());
|
||||
let err = insert_res.unwrap_err();
|
||||
match err {
|
||||
ScheduleError::StoreError(e) => match e {
|
||||
ScheduleError::Pool(e) => match e {
|
||||
PoolError::StoreFull(_) => {}
|
||||
_ => panic!("unexpected store error {e}"),
|
||||
},
|
||||
@@ -1755,7 +1675,7 @@ mod tests {
|
||||
|
||||
fn insert_command_with_release_time(
|
||||
pool: &mut StaticMemoryPool,
|
||||
scheduler: &mut PusScheduler,
|
||||
scheduler: &mut PusSchedulerAlloc,
|
||||
seq_count: u14,
|
||||
release_secs: u64,
|
||||
) -> TcInfo {
|
||||
@@ -1774,7 +1694,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let tc_info_0 = insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 50);
|
||||
let tc_info_1 = insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 100);
|
||||
assert_eq!(scheduler.num_scheduled_telecommands(), 2);
|
||||
@@ -1806,7 +1727,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let _ = insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 50);
|
||||
let tc_info_1 = insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 100);
|
||||
let tc_info_2 = insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 150);
|
||||
@@ -1841,7 +1763,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let tc_info_0 = insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 50);
|
||||
let tc_info_1 = insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 100);
|
||||
let _ = insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 150);
|
||||
@@ -1876,7 +1799,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let _ = insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 50);
|
||||
let tc_info_1 = insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 100);
|
||||
let tc_info_2 = insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 150);
|
||||
@@ -1917,7 +1841,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 50);
|
||||
insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 100);
|
||||
assert_eq!(scheduler.num_scheduled_telecommands(), 2);
|
||||
@@ -1946,7 +1871,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 50);
|
||||
let cmd_0_to_delete =
|
||||
insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 100);
|
||||
@@ -1973,7 +1899,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let cmd_0_to_delete =
|
||||
insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 50);
|
||||
let cmd_1_to_delete =
|
||||
@@ -2001,7 +1928,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let cmd_out_of_range_0 =
|
||||
insert_command_with_release_time(&mut pool, &mut scheduler, u14::ZERO, 50);
|
||||
let cmd_0_to_delete =
|
||||
@@ -2039,7 +1967,8 @@ mod tests {
|
||||
vec![(10, 32), (5, 64)],
|
||||
false,
|
||||
));
|
||||
let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
let mut scheduler =
|
||||
PusSchedulerAlloc::new(UnixTime::new_only_secs(0), Duration::from_secs(5));
|
||||
|
||||
let mut buf: [u8; 32] = [0; 32];
|
||||
let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, u14::ZERO, &[]);
|
||||
@@ -2081,7 +2010,7 @@ mod tests {
|
||||
PacketSequenceControl::new(SequenceFlags::Unsegmented, u14::new(5)),
|
||||
0,
|
||||
);
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(17, 1));
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(17, 1);
|
||||
let ping_tc = PusTcCreator::new_no_app_data(sph, sec_header, CreatorConfig::default());
|
||||
let mut buf: [u8; 64] = [0; 64];
|
||||
let result = generate_insert_telecommand_app_data(&mut buf, &time_writer, &ping_tc);
|
||||
@@ -2103,7 +2032,7 @@ mod tests {
|
||||
PacketSequenceControl::new(SequenceFlags::Unsegmented, u14::new(5)),
|
||||
0,
|
||||
);
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(17, 1));
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(17, 1);
|
||||
let ping_tc = PusTcCreator::new_no_app_data(sph, sec_header, CreatorConfig::default());
|
||||
let mut buf: [u8; 16] = [0; 16];
|
||||
let result = generate_insert_telecommand_app_data(&mut buf, &time_writer, &ping_tc);
|
||||
@@ -2132,7 +2061,7 @@ mod tests {
|
||||
PacketSequenceControl::new(SequenceFlags::Unsegmented, u14::new(5)),
|
||||
0,
|
||||
);
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(17, 1));
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(17, 1);
|
||||
let ping_tc = PusTcCreator::new_no_app_data(sph, sec_header, CreatorConfig::default());
|
||||
let mut buf: [u8; 64] = [0; 64];
|
||||
generate_insert_telecommand_app_data(&mut buf, &time_writer, &ping_tc).unwrap();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::scheduler::PusSchedulerProvider;
|
||||
use super::scheduler::PusScheduler;
|
||||
use super::verification::{VerificationReporter, VerificationReportingProvider};
|
||||
use super::{
|
||||
CacheAndReadRawEcssTc, DirectPusPacketHandlerResult, EcssTcInSharedPoolCacher, EcssTcReceiver,
|
||||
@@ -26,11 +26,11 @@ pub struct PusSchedServiceHandler<
|
||||
TmSender: EcssTmSender,
|
||||
TcInMemConverter: CacheAndReadRawEcssTc,
|
||||
VerificationReporter: VerificationReportingProvider,
|
||||
PusScheduler: PusSchedulerProvider,
|
||||
PusSchedulerInstance: PusScheduler,
|
||||
> {
|
||||
pub service_helper:
|
||||
PusServiceHelper<TcReceiver, TmSender, TcInMemConverter, VerificationReporter>,
|
||||
scheduler: PusScheduler,
|
||||
scheduler: PusSchedulerInstance,
|
||||
}
|
||||
|
||||
impl<
|
||||
@@ -38,7 +38,7 @@ impl<
|
||||
TmSender: EcssTmSender,
|
||||
TcInMemConverter: CacheAndReadRawEcssTc,
|
||||
VerificationReporter: VerificationReportingProvider,
|
||||
Scheduler: PusSchedulerProvider,
|
||||
Scheduler: PusScheduler,
|
||||
> PusSchedServiceHandler<TcReceiver, TmSender, TcInMemConverter, VerificationReporter, Scheduler>
|
||||
{
|
||||
pub fn new(
|
||||
@@ -79,7 +79,7 @@ impl<
|
||||
.tc_in_mem_converter_mut()
|
||||
.cache(&ecss_tc_and_token.tc_in_memory)?;
|
||||
let tc = self.service_helper.tc_in_mem_converter().convert()?;
|
||||
let subservice = PusPacket::message_subtype_id(&tc);
|
||||
let subservice = PusPacket::subservice(&tc);
|
||||
let standard_subservice = scheduling::Subservice::try_from(subservice);
|
||||
if standard_subservice.is_err() {
|
||||
return Ok(DirectPusPacketHandlerResult::CustomSubservice(
|
||||
@@ -254,7 +254,7 @@ mod tests {
|
||||
use crate::pus::{DirectPusPacketHandlerResult, MpscTcReceiver, PusPacketHandlingError};
|
||||
use crate::pus::{
|
||||
EcssTcInSharedPoolCacher,
|
||||
scheduler::{self, PusSchedulerProvider, TcInfo},
|
||||
scheduler::{self, PusScheduler, TcInfo},
|
||||
tests::PusServiceHandlerWithSharedStoreCommon,
|
||||
verification::{RequestId, TcStateAccepted, VerificationToken},
|
||||
};
|
||||
@@ -266,7 +266,7 @@ mod tests {
|
||||
use spacepackets::SpHeader;
|
||||
use spacepackets::ecss::scheduling::Subservice;
|
||||
use spacepackets::ecss::tc::PusTcSecondaryHeader;
|
||||
use spacepackets::ecss::{CreatorConfig, MessageTypeId, WritablePusPacket};
|
||||
use spacepackets::ecss::{CreatorConfig, WritablePusPacket};
|
||||
use spacepackets::time::TimeWriter;
|
||||
use spacepackets::{
|
||||
ecss::{tc::PusTcCreator, tm::PusTmReader},
|
||||
@@ -349,7 +349,7 @@ mod tests {
|
||||
inserted_tcs: VecDeque<TcInfo>,
|
||||
}
|
||||
|
||||
impl PusSchedulerProvider for TestScheduler {
|
||||
impl PusScheduler for TestScheduler {
|
||||
type TimeProvider = cds::CdsTime;
|
||||
|
||||
fn reset(
|
||||
@@ -389,7 +389,7 @@ mod tests {
|
||||
subservice: Subservice,
|
||||
) {
|
||||
let reply_header = SpHeader::new_for_unseg_tm(TEST_APID, u14::ZERO, 0);
|
||||
let tc_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(11, subservice as u8));
|
||||
let tc_header = PusTcSecondaryHeader::new_simple(11, subservice as u8);
|
||||
let enable_scheduling =
|
||||
PusTcCreator::new(reply_header, tc_header, &[0; 7], CreatorConfig::default());
|
||||
let token = test_harness.start_verification(&enable_scheduling);
|
||||
@@ -437,7 +437,7 @@ mod tests {
|
||||
fn test_insert_activity_tc() {
|
||||
let mut test_harness = Pus11HandlerWithStoreTester::new();
|
||||
let mut reply_header = SpHeader::new_for_unseg_tc(TEST_APID, u14::ZERO, 0);
|
||||
let mut sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(17, 1));
|
||||
let mut sec_header = PusTcSecondaryHeader::new_simple(17, 1);
|
||||
let ping_tc = PusTcCreator::new(reply_header, sec_header, &[], CreatorConfig::default());
|
||||
let req_id_ping_tc = scheduler::RequestId::from_tc(&ping_tc);
|
||||
let stamper = cds::CdsTime::now_with_u16_days().expect("time provider failed");
|
||||
@@ -447,10 +447,7 @@ mod tests {
|
||||
sched_app_data[written_len..written_len + ping_raw.len()].copy_from_slice(&ping_raw);
|
||||
written_len += ping_raw.len();
|
||||
reply_header = SpHeader::new_for_unseg_tc(TEST_APID, u14::ZERO, 0);
|
||||
sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(
|
||||
11,
|
||||
Subservice::TcInsertActivity as u8,
|
||||
));
|
||||
sec_header = PusTcSecondaryHeader::new_simple(11, Subservice::TcInsertActivity as u8);
|
||||
let enable_scheduling = PusTcCreator::new(
|
||||
reply_header,
|
||||
sec_header,
|
||||
|
||||
@@ -6,7 +6,7 @@ use arbitrary_int::traits::Integer as _;
|
||||
use arbitrary_int::u14;
|
||||
use spacepackets::SpHeader;
|
||||
use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader};
|
||||
use spacepackets::ecss::{CreatorConfig, MessageTypeId, PusPacket};
|
||||
use spacepackets::ecss::{CreatorConfig, PusPacket};
|
||||
use std::sync::mpsc;
|
||||
|
||||
use super::verification::{VerificationReporter, VerificationReportingProvider};
|
||||
@@ -59,10 +59,10 @@ impl<
|
||||
.tc_in_mem_converter_mut()
|
||||
.cache(&ecss_tc_and_token.tc_in_memory)?;
|
||||
let tc = self.service_helper.tc_in_mem_converter().convert()?;
|
||||
if tc.service_type_id() != 17 {
|
||||
return Err(GenericConversionError::WrongService(tc.service_type_id()).into());
|
||||
if tc.service() != 17 {
|
||||
return Err(GenericConversionError::WrongService(tc.service()).into());
|
||||
}
|
||||
if tc.message_subtype_id() == 1 {
|
||||
if tc.subservice() == 1 {
|
||||
let opt_started_token = match self.service_helper.verif_reporter().start_success(
|
||||
&self.service_helper.common.tm_sender,
|
||||
ecss_tc_and_token.token,
|
||||
@@ -82,7 +82,7 @@ impl<
|
||||
u14::ZERO,
|
||||
0,
|
||||
);
|
||||
let tc_header = PusTmSecondaryHeader::new_simple(MessageTypeId::new(17, 2), time_stamp);
|
||||
let tc_header = PusTmSecondaryHeader::new_simple(17, 2, time_stamp);
|
||||
let ping_reply =
|
||||
PusTmCreator::new(reply_header, tc_header, &[], CreatorConfig::default());
|
||||
if let Err(e) = self
|
||||
@@ -104,7 +104,7 @@ impl<
|
||||
}
|
||||
} else {
|
||||
return Ok(DirectPusPacketHandlerResult::CustomSubservice(
|
||||
tc.message_subtype_id(),
|
||||
tc.subservice(),
|
||||
ecss_tc_and_token.token,
|
||||
));
|
||||
}
|
||||
@@ -160,7 +160,7 @@ mod tests {
|
||||
use spacepackets::SpHeader;
|
||||
use spacepackets::ecss::tc::{PusTcCreator, PusTcSecondaryHeader};
|
||||
use spacepackets::ecss::tm::PusTmReader;
|
||||
use spacepackets::ecss::{CreatorConfig, MessageTypeId, PusPacket};
|
||||
use spacepackets::ecss::{CreatorConfig, PusPacket};
|
||||
use spacepackets::time::{TimeWriter, cds};
|
||||
|
||||
use super::PusService17TestHandler;
|
||||
@@ -292,7 +292,7 @@ mod tests {
|
||||
fn ping_test(test_harness: &mut (impl PusTestHarness + SimplePusPacketHandler)) {
|
||||
// Create a ping TC, verify acceptance.
|
||||
let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, u14::ZERO, 0);
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(17, 1));
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(17, 1);
|
||||
let ping_tc =
|
||||
PusTcCreator::new_no_app_data(sp_header, sec_header, CreatorConfig::default());
|
||||
let token = test_harness.start_verification(&ping_tc);
|
||||
@@ -311,8 +311,8 @@ mod tests {
|
||||
|
||||
// Ping reply
|
||||
let tm = test_harness.read_next_tm();
|
||||
assert_eq!(tm.service_type_id(), 17);
|
||||
assert_eq!(tm.message_subtype_id(), 2);
|
||||
assert_eq!(tm.service(), 17);
|
||||
assert_eq!(tm.subservice(), 2);
|
||||
assert!(tm.user_data().is_empty());
|
||||
|
||||
// TM completion
|
||||
@@ -348,7 +348,7 @@ mod tests {
|
||||
fn test_sending_unsupported_service() {
|
||||
let mut test_harness = Pus17HandlerWithStoreTester::new(0);
|
||||
let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, u14::ZERO, 0);
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(3, 1));
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(3, 1);
|
||||
let ping_tc =
|
||||
PusTcCreator::new_no_app_data(sp_header, sec_header, CreatorConfig::default());
|
||||
let token = test_harness.start_verification(&ping_tc);
|
||||
@@ -370,7 +370,7 @@ mod tests {
|
||||
fn test_sending_custom_subservice() {
|
||||
let mut test_harness = Pus17HandlerWithStoreTester::new(0);
|
||||
let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, u14::ZERO, 0);
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(17, 200));
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(17, 200);
|
||||
let ping_tc =
|
||||
PusTcCreator::new_no_app_data(sp_header, sec_header, CreatorConfig::default());
|
||||
let token = test_harness.start_verification(&ping_tc);
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
//! use satrs::request::UniqueApidTargetId;
|
||||
//! use spacepackets::ecss::PusPacket;
|
||||
//! use spacepackets::SpHeader;
|
||||
//! use spacepackets::ecss::tc::{MessageTypeId, PusTcCreator, PusTcSecondaryHeader, CreatorConfig};
|
||||
//! use spacepackets::ecss::tc::{PusTcCreator, PusTcSecondaryHeader, CreatorConfig};
|
||||
//! use spacepackets::ecss::tm::PusTmReader;
|
||||
//! use arbitrary_int::{u11, u21};
|
||||
//! use arbitrary_int::u11;
|
||||
//!
|
||||
//! const EMPTY_STAMP: [u8; 7] = [0; 7];
|
||||
//! const TEST_APID: u11 = u11::new(0x02);
|
||||
//! const TEST_COMPONENT_ID: UniqueApidTargetId = UniqueApidTargetId::new(TEST_APID, u21::new(0x05));
|
||||
//! const TEST_COMPONENT_ID: UniqueApidTargetId = UniqueApidTargetId::new(TEST_APID, 0x05);
|
||||
//!
|
||||
//! let pool_cfg = StaticPoolConfig::new_from_subpool_cfg_tuples(
|
||||
//! vec![(10, 32), (10, 64), (10, 128), (10, 1024)], false
|
||||
@@ -41,7 +41,7 @@
|
||||
//! let cfg = VerificationReporterConfig::new(TEST_APID, 1, 2, 8);
|
||||
//! let mut reporter = VerificationReporter::new(TEST_COMPONENT_ID.id(), &cfg);
|
||||
//!
|
||||
//! let tc_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(17, 1));
|
||||
//! let tc_header = PusTcSecondaryHeader::new_simple(17, 1);
|
||||
//! let pus_tc_0 = PusTcCreator::new_no_app_data(
|
||||
//! SpHeader::new_from_apid(TEST_APID),
|
||||
//! tc_header,
|
||||
@@ -67,11 +67,11 @@
|
||||
//! }
|
||||
//! let pus_tm = PusTmReader::new(&tm_buf[0..tm_len], 7).expect("Error reading verification TM");
|
||||
//! if packet_idx == 0 {
|
||||
//! assert_eq!(pus_tm.message_subtype_id(), 1);
|
||||
//! assert_eq!(pus_tm.subservice(), 1);
|
||||
//! } else if packet_idx == 1 {
|
||||
//! assert_eq!(pus_tm.message_subtype_id(), 3);
|
||||
//! assert_eq!(pus_tm.subservice(), 3);
|
||||
//! } else if packet_idx == 2 {
|
||||
//! assert_eq!(pus_tm.message_subtype_id(), 7);
|
||||
//! assert_eq!(pus_tm.subservice(), 7);
|
||||
//! }
|
||||
//! packet_idx += 1;
|
||||
//! }
|
||||
@@ -94,7 +94,7 @@ use serde::{Deserialize, Serialize};
|
||||
use spacepackets::SpHeader;
|
||||
use spacepackets::ecss::tc::IsPusTelecommand;
|
||||
use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader};
|
||||
use spacepackets::ecss::{CreatorConfig, EcssEnumeration, MessageTypeId};
|
||||
use spacepackets::ecss::{CreatorConfig, EcssEnumeration};
|
||||
use spacepackets::{ByteConversionError, CcsdsPacket, PacketId, PacketSequenceControl};
|
||||
|
||||
pub use spacepackets::ecss::verification::*;
|
||||
@@ -507,7 +507,9 @@ impl VerificationReportCreator {
|
||||
self.dest_id = dest_id;
|
||||
}
|
||||
|
||||
pub fn read_request_id(&self, pus_tc: &(impl CcsdsPacket + IsPusTelecommand)) -> RequestId {
|
||||
/// Initialize verification handling by passing a TC reference. This returns a token required
|
||||
/// to call the acceptance functions
|
||||
pub fn read_request_id_from_tc(pus_tc: &(impl CcsdsPacket + IsPusTelecommand)) -> RequestId {
|
||||
RequestId::new(pus_tc)
|
||||
}
|
||||
|
||||
@@ -820,12 +822,8 @@ impl VerificationReportCreator {
|
||||
time_stamp: &'time [u8],
|
||||
source_data_len: usize,
|
||||
) -> PusTmCreator<'time, 'src_data> {
|
||||
let tm_sec_header = PusTmSecondaryHeader::new(
|
||||
MessageTypeId::new(1, subservice),
|
||||
msg_counter,
|
||||
self.dest_id,
|
||||
time_stamp,
|
||||
);
|
||||
let tm_sec_header =
|
||||
PusTmSecondaryHeader::new(1, subservice, msg_counter, self.dest_id, time_stamp);
|
||||
PusTmCreator::new(
|
||||
sp_header,
|
||||
tm_sec_header,
|
||||
@@ -899,7 +897,7 @@ pub mod alloc_mod {
|
||||
> {
|
||||
owner_id: ComponentId,
|
||||
source_data_buf: RefCell<alloc::vec::Vec<u8>>,
|
||||
pub report_creator: VerificationReportCreator,
|
||||
pub reporter_creator: VerificationReportCreator,
|
||||
pub tm_hook: VerificationHookInstance,
|
||||
}
|
||||
|
||||
@@ -915,7 +913,7 @@ pub mod alloc_mod {
|
||||
+ cfg.fail_code_field_width
|
||||
+ cfg.max_fail_data_len
|
||||
]),
|
||||
report_creator: reporter,
|
||||
reporter_creator: reporter,
|
||||
tm_hook: DummyVerificationHook::default(),
|
||||
}
|
||||
}
|
||||
@@ -939,7 +937,7 @@ pub mod alloc_mod {
|
||||
+ cfg.fail_code_field_width
|
||||
+ cfg.max_fail_data_len
|
||||
]),
|
||||
report_creator: reporter,
|
||||
reporter_creator: reporter,
|
||||
tm_hook,
|
||||
}
|
||||
}
|
||||
@@ -948,7 +946,9 @@ pub mod alloc_mod {
|
||||
&self,
|
||||
pus_tc: &(impl CcsdsPacket + IsPusTelecommand),
|
||||
) -> VerificationToken<TcStateNone> {
|
||||
VerificationToken::<TcStateNone>::new(self.report_creator.read_request_id(pus_tc))
|
||||
VerificationToken::<TcStateNone>::new(
|
||||
VerificationReportCreator::read_request_id_from_tc(pus_tc),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn start_verification_with_req_id(
|
||||
@@ -959,7 +959,7 @@ pub mod alloc_mod {
|
||||
}
|
||||
|
||||
delegate!(
|
||||
to self.report_creator {
|
||||
to self.reporter_creator {
|
||||
pub fn set_apid(&mut self, apid: u11);
|
||||
pub fn apid(&self) -> u11;
|
||||
pub fn dest_id(&self) -> u16;
|
||||
@@ -976,7 +976,7 @@ pub mod alloc_mod {
|
||||
for VerificationReporter<VerificationHookInstance>
|
||||
{
|
||||
delegate!(
|
||||
to self.report_creator {
|
||||
to self.reporter_creator {
|
||||
fn set_apid(&mut self, apid: Apid);
|
||||
fn apid(&self) -> Apid;
|
||||
}
|
||||
@@ -1002,7 +1002,7 @@ pub mod alloc_mod {
|
||||
) -> Result<VerificationToken<TcStateAccepted>, EcssTmtcError> {
|
||||
let mut source_data_buf = self.source_data_buf.borrow_mut();
|
||||
let mut tm_creator = self
|
||||
.report_creator
|
||||
.reporter_creator
|
||||
.acceptance_success(
|
||||
source_data_buf.as_mut_slice(),
|
||||
&token.request_id(),
|
||||
@@ -1025,7 +1025,7 @@ pub mod alloc_mod {
|
||||
) -> Result<(), EcssTmtcError> {
|
||||
let mut buf = self.source_data_buf.borrow_mut();
|
||||
let mut tm_creator = self
|
||||
.report_creator
|
||||
.reporter_creator
|
||||
.acceptance_failure(
|
||||
buf.as_mut_slice(),
|
||||
&token.request_id(),
|
||||
@@ -1050,7 +1050,7 @@ pub mod alloc_mod {
|
||||
) -> Result<VerificationToken<TcStateStarted>, EcssTmtcError> {
|
||||
let mut buf = self.source_data_buf.borrow_mut();
|
||||
let mut tm_creator = self
|
||||
.report_creator
|
||||
.reporter_creator
|
||||
.start_success(
|
||||
buf.as_mut_slice(),
|
||||
&token.request_id(),
|
||||
@@ -1076,7 +1076,7 @@ pub mod alloc_mod {
|
||||
) -> Result<(), EcssTmtcError> {
|
||||
let mut buf = self.source_data_buf.borrow_mut();
|
||||
let mut tm_creator = self
|
||||
.report_creator
|
||||
.reporter_creator
|
||||
.start_failure(
|
||||
buf.as_mut_slice(),
|
||||
&token.request_id(),
|
||||
@@ -1102,7 +1102,7 @@ pub mod alloc_mod {
|
||||
) -> Result<(), EcssTmtcError> {
|
||||
let mut buf = self.source_data_buf.borrow_mut();
|
||||
let mut tm_creator = self
|
||||
.report_creator
|
||||
.reporter_creator
|
||||
.step_success(
|
||||
buf.as_mut_slice(),
|
||||
&token.request_id(),
|
||||
@@ -1129,7 +1129,7 @@ pub mod alloc_mod {
|
||||
) -> Result<(), EcssTmtcError> {
|
||||
let mut buf = self.source_data_buf.borrow_mut();
|
||||
let mut tm_creator = self
|
||||
.report_creator
|
||||
.reporter_creator
|
||||
.step_failure(buf.as_mut_slice(), token, u14::ZERO, 0, params)
|
||||
.map_err(PusError::ByteConversion)?;
|
||||
self.tm_hook.modify_tm(&mut tm_creator);
|
||||
@@ -1150,7 +1150,7 @@ pub mod alloc_mod {
|
||||
) -> Result<(), EcssTmtcError> {
|
||||
let mut buf = self.source_data_buf.borrow_mut();
|
||||
let mut tm_creator = self
|
||||
.report_creator
|
||||
.reporter_creator
|
||||
.completion_success(
|
||||
buf.as_mut_slice(),
|
||||
&token.request_id(),
|
||||
@@ -1176,7 +1176,7 @@ pub mod alloc_mod {
|
||||
) -> Result<(), EcssTmtcError> {
|
||||
let mut buf = self.source_data_buf.borrow_mut();
|
||||
let mut tm_creator = self
|
||||
.report_creator
|
||||
.reporter_creator
|
||||
.completion_failure(
|
||||
buf.as_mut_slice(),
|
||||
&token.request_id(),
|
||||
@@ -1427,7 +1427,7 @@ pub mod test_util {
|
||||
token.request_id(),
|
||||
VerificationReportInfo::AcceptanceFailure(FailureData {
|
||||
sender: self.owner_id(),
|
||||
error_enum: params.failure_code.value_raw(),
|
||||
error_enum: params.failure_code.value(),
|
||||
fail_data: params.failure_data.to_vec(),
|
||||
time_stamp: params.time_stamp.to_vec(),
|
||||
}),
|
||||
@@ -1464,7 +1464,7 @@ pub mod test_util {
|
||||
token.request_id(),
|
||||
VerificationReportInfo::StartedFailure(FailureData {
|
||||
sender: self.owner_id(),
|
||||
error_enum: params.failure_code.value_raw(),
|
||||
error_enum: params.failure_code.value(),
|
||||
fail_data: params.failure_data.to_vec(),
|
||||
time_stamp: params.time_stamp.to_vec(),
|
||||
}),
|
||||
@@ -1486,7 +1486,7 @@ pub mod test_util {
|
||||
sender: self.owner_id(),
|
||||
time_stamp: time_stamp.to_vec(),
|
||||
},
|
||||
step: step.value_raw() as u16,
|
||||
step: step.value() as u16,
|
||||
},
|
||||
));
|
||||
Ok(())
|
||||
@@ -1502,7 +1502,7 @@ pub mod test_util {
|
||||
token.request_id(),
|
||||
VerificationReportInfo::StepFailure(FailureData {
|
||||
sender: self.owner_id(),
|
||||
error_enum: params.common.failure_code.value_raw(),
|
||||
error_enum: params.common.failure_code.value(),
|
||||
fail_data: params.common.failure_data.to_vec(),
|
||||
time_stamp: params.common.time_stamp.to_vec(),
|
||||
}),
|
||||
@@ -1536,7 +1536,7 @@ pub mod test_util {
|
||||
token.request_id(),
|
||||
VerificationReportInfo::CompletionFailure(FailureData {
|
||||
sender: self.owner_id(),
|
||||
error_enum: params.failure_code.value_raw(),
|
||||
error_enum: params.failure_code.value(),
|
||||
fail_data: params.failure_data.to_vec(),
|
||||
time_stamp: params.time_stamp.to_vec(),
|
||||
}),
|
||||
@@ -1731,8 +1731,8 @@ pub mod tests {
|
||||
use arbitrary_int::{u11, u14};
|
||||
use spacepackets::ecss::tc::{PusTcCreator, PusTcReader, PusTcSecondaryHeader};
|
||||
use spacepackets::ecss::{
|
||||
CreatorConfig, EcssEnumU8, EcssEnumU16, EcssEnumU32, EcssEnumeration, MessageTypeId,
|
||||
PusError, PusPacket, WritablePusPacket,
|
||||
CreatorConfig, EcssEnumU8, EcssEnumU16, EcssEnumU32, EcssEnumeration, PusError, PusPacket,
|
||||
WritablePusPacket,
|
||||
};
|
||||
use spacepackets::util::UnsignedEnum;
|
||||
use spacepackets::{ByteConversionError, SpHeader};
|
||||
@@ -1783,7 +1783,7 @@ pub mod tests {
|
||||
panic!("TestSender: Can not deal with addresses");
|
||||
}
|
||||
PusTmVariant::Direct(tm) => {
|
||||
assert_eq!(PusPacket::service_type_id(&tm), 1);
|
||||
assert_eq!(PusPacket::service(&tm), 1);
|
||||
assert!(!tm.source_data().is_empty());
|
||||
let mut time_stamp = [0; 7];
|
||||
time_stamp.clone_from_slice(&tm.timestamp()[0..7]);
|
||||
@@ -2102,7 +2102,7 @@ pub mod tests {
|
||||
|
||||
fn create_generic_ping() -> PusTcCreator<'static> {
|
||||
let sph = SpHeader::new_for_unseg_tc(TEST_APID, u14::new(0x34), 0);
|
||||
let tc_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(17, 1));
|
||||
let tc_header = PusTcSecondaryHeader::new_simple(17, 1);
|
||||
PusTcCreator::new(sph, tc_header, &[], CreatorConfig::default())
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use arbitrary_int::{prelude::*, u11, u21};
|
||||
use arbitrary_int::u11;
|
||||
use core::{fmt, marker::PhantomData};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -29,11 +29,11 @@ pub type Apid = u11;
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct UniqueApidTargetId {
|
||||
pub apid: Apid,
|
||||
pub unique_id: u21,
|
||||
pub unique_id: u32,
|
||||
}
|
||||
|
||||
impl UniqueApidTargetId {
|
||||
pub const fn new(apid: Apid, target: u21) -> Self {
|
||||
pub const fn new(apid: Apid, target: u32) -> Self {
|
||||
Self {
|
||||
apid,
|
||||
unique_id: target,
|
||||
@@ -41,7 +41,7 @@ impl UniqueApidTargetId {
|
||||
}
|
||||
|
||||
pub fn raw(&self) -> ComponentId {
|
||||
((self.apid.value() as u32) << 21) | (self.unique_id.value())
|
||||
((self.apid.value() as u64) << 32) | (self.unique_id as u64)
|
||||
}
|
||||
|
||||
pub fn id(&self) -> ComponentId {
|
||||
@@ -61,21 +61,21 @@ impl UniqueApidTargetId {
|
||||
}
|
||||
Ok(Self::new(
|
||||
tc.apid(),
|
||||
u21::new(u32::from_be_bytes(tc.user_data()[0..4].try_into().unwrap())),
|
||||
u32::from_be_bytes(tc.user_data()[0..4].try_into().unwrap()),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ComponentId> for UniqueApidTargetId {
|
||||
fn from(raw: ComponentId) -> Self {
|
||||
impl From<u64> for UniqueApidTargetId {
|
||||
fn from(raw: u64) -> Self {
|
||||
Self {
|
||||
apid: u11::new((raw >> 21) as u16),
|
||||
unique_id: u21::new(raw & u21::MAX.value()),
|
||||
apid: u11::new((raw >> 32) as u16),
|
||||
unique_id: raw as u32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<UniqueApidTargetId> for ComponentId {
|
||||
impl From<UniqueApidTargetId> for u64 {
|
||||
fn from(target_and_apid_id: UniqueApidTargetId) -> Self {
|
||||
target_and_apid_id.raw()
|
||||
}
|
||||
@@ -497,38 +497,37 @@ mod tests {
|
||||
use std::sync::mpsc;
|
||||
|
||||
use alloc::string::ToString;
|
||||
use arbitrary_int::{u11, u14, u21};
|
||||
use arbitrary_int::{u11, u14};
|
||||
use spacepackets::{
|
||||
ByteConversionError, SpHeader,
|
||||
ecss::{
|
||||
CreatorConfig, MessageTypeId,
|
||||
CreatorConfig,
|
||||
tc::{PusTcCreator, PusTcSecondaryHeader},
|
||||
},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ComponentId,
|
||||
queue::{GenericReceiveError, GenericSendError},
|
||||
request::{Apid, MessageMetadata, MessageSenderMap, MessageSenderStoreProvider},
|
||||
};
|
||||
|
||||
use super::{GenericMessage, MessageReceiverWithId, UniqueApidTargetId};
|
||||
|
||||
const TEST_CHANNEL_ID_0: ComponentId = 1;
|
||||
const TEST_CHANNEL_ID_1: ComponentId = 2;
|
||||
const TEST_CHANNEL_ID_2: ComponentId = 3;
|
||||
const TEST_CHANNEL_ID_0: u64 = 1;
|
||||
const TEST_CHANNEL_ID_1: u64 = 2;
|
||||
const TEST_CHANNEL_ID_2: u64 = 3;
|
||||
|
||||
#[test]
|
||||
fn test_basic_target_id_with_apid() {
|
||||
let id = UniqueApidTargetId::new(Apid::new(0x111), u21::new(0x01));
|
||||
let id = UniqueApidTargetId::new(Apid::new(0x111), 0x01);
|
||||
assert_eq!(id.apid.value(), 0x111);
|
||||
assert_eq!(id.unique_id.value(), 0x01);
|
||||
assert_eq!(id.unique_id, 0x01);
|
||||
assert_eq!(id.id(), id.raw());
|
||||
assert_eq!(ComponentId::from(id), id.raw());
|
||||
assert_eq!(u64::from(id), id.raw());
|
||||
let id_raw = id.raw();
|
||||
let id_from_raw = UniqueApidTargetId::from(id_raw);
|
||||
assert_eq!(id_from_raw, id);
|
||||
assert_eq!(id.id(), (0x111 << 21) | 0x01);
|
||||
assert_eq!(id.id(), (0x111 << 32) | 0x01);
|
||||
let string = id.to_string();
|
||||
assert_eq!(
|
||||
string,
|
||||
@@ -540,21 +539,17 @@ mod tests {
|
||||
fn test_basic_target_id_with_apid_from_pus_tc() {
|
||||
let sp_header = SpHeader::new_for_unseg_tc(u11::new(0x111), u14::new(5), 0);
|
||||
let app_data = 1_u32.to_be_bytes();
|
||||
let pus_tc = PusTcCreator::new_simple(
|
||||
sp_header,
|
||||
MessageTypeId::new(17, 1),
|
||||
&app_data,
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
let pus_tc =
|
||||
PusTcCreator::new_simple(sp_header, 17, 1, &app_data, CreatorConfig::default());
|
||||
let id = UniqueApidTargetId::from_pus_tc(&pus_tc).unwrap();
|
||||
assert_eq!(id.apid.value(), 0x111);
|
||||
assert_eq!(id.unique_id.value(), 1);
|
||||
assert_eq!(id.unique_id, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_basic_target_id_with_apid_from_pus_tc_invalid_app_data() {
|
||||
let sp_header = SpHeader::new_for_unseg_tc(u11::new(0x111), u14::new(5), 0);
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(17, 1));
|
||||
let sec_header = PusTcSecondaryHeader::new_simple(17, 1);
|
||||
let pus_tc = PusTcCreator::new_no_app_data(sp_header, sec_header, CreatorConfig::default());
|
||||
let error = UniqueApidTargetId::from_pus_tc(&pus_tc);
|
||||
assert!(error.is_err());
|
||||
|
||||
@@ -782,7 +782,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(self.sender.requests.borrow().len(), 2);
|
||||
let req_0 = self.sender.requests.get_mut().pop_front().unwrap();
|
||||
assert_eq!(req_0.target_id, ExampleTargetId::Target0 as ComponentId);
|
||||
assert_eq!(req_0.target_id, ExampleTargetId::Target0 as u64);
|
||||
assert_eq!(req_0.request_id, expected_req_id);
|
||||
assert_eq!(
|
||||
req_0.request,
|
||||
@@ -792,7 +792,7 @@ mod tests {
|
||||
}
|
||||
);
|
||||
let req_1 = self.sender.requests.borrow_mut().pop_front().unwrap();
|
||||
assert_eq!(req_1.target_id, ExampleTargetId::Target1 as ComponentId);
|
||||
assert_eq!(req_1.target_id, ExampleTargetId::Target1 as u64);
|
||||
assert_eq!(
|
||||
req_1.request,
|
||||
ModeRequest::SetMode {
|
||||
@@ -808,7 +808,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(self.sender.requests.borrow().len(), 1);
|
||||
let req_0 = self.sender.requests.get_mut().pop_front().unwrap();
|
||||
assert_eq!(req_0.target_id, ExampleTargetId::Target2 as ComponentId);
|
||||
assert_eq!(req_0.target_id, ExampleTargetId::Target2 as u64);
|
||||
assert_eq!(req_0.request_id, expected_req_id);
|
||||
assert_eq!(
|
||||
req_0.request,
|
||||
@@ -827,7 +827,7 @@ mod tests {
|
||||
assert_eq!(self.execution_helper.current_sequence_index().unwrap(), 0);
|
||||
assert_eq!(self.sender.requests.borrow().len(), 2);
|
||||
let req_0 = self.sender.requests.get_mut().pop_front().unwrap();
|
||||
assert_eq!(req_0.target_id, ExampleTargetId::Target0 as ComponentId);
|
||||
assert_eq!(req_0.target_id, ExampleTargetId::Target0 as u64);
|
||||
assert_eq!(req_0.request_id, expected_req_id);
|
||||
assert_eq!(
|
||||
req_0.request,
|
||||
@@ -837,7 +837,7 @@ mod tests {
|
||||
}
|
||||
);
|
||||
let req_1 = self.sender.requests.borrow_mut().pop_front().unwrap();
|
||||
assert_eq!(req_1.target_id, ExampleTargetId::Target1 as ComponentId);
|
||||
assert_eq!(req_1.target_id, ExampleTargetId::Target1 as u64);
|
||||
assert_eq!(
|
||||
req_1.request,
|
||||
ModeRequest::SetMode {
|
||||
@@ -850,9 +850,9 @@ mod tests {
|
||||
|
||||
fn create_default_mode_store() -> ModeStoreVec {
|
||||
let mut mode_store = ModeStoreVec::default();
|
||||
mode_store.add_component(ExampleTargetId::Target0 as ComponentId, UNKNOWN_MODE);
|
||||
mode_store.add_component(ExampleTargetId::Target1 as ComponentId, UNKNOWN_MODE);
|
||||
mode_store.add_component(ExampleTargetId::Target2 as ComponentId, UNKNOWN_MODE);
|
||||
mode_store.add_component(ExampleTargetId::Target0 as u64, UNKNOWN_MODE);
|
||||
mode_store.add_component(ExampleTargetId::Target1 as u64, UNKNOWN_MODE);
|
||||
mode_store.add_component(ExampleTargetId::Target2 as u64, UNKNOWN_MODE);
|
||||
mode_store
|
||||
}
|
||||
|
||||
@@ -863,13 +863,13 @@ mod tests {
|
||||
let mut table_seq_0 = SequenceTableMapTable::new("MODE_0_SEQ_0");
|
||||
table_seq_0.add_entry(SequenceTableEntry::new(
|
||||
"TARGET_0",
|
||||
ExampleTargetId::Target0 as ComponentId,
|
||||
ExampleTargetId::Target0 as u64,
|
||||
SUBSYSTEM_MD0_TGT0_MODE,
|
||||
false,
|
||||
));
|
||||
table_seq_0.add_entry(SequenceTableEntry::new(
|
||||
"TARGET_1",
|
||||
ExampleTargetId::Target1 as ComponentId,
|
||||
ExampleTargetId::Target1 as u64,
|
||||
SUBSYSTEM_MD0_TGT1_MODE,
|
||||
false,
|
||||
));
|
||||
@@ -881,13 +881,13 @@ mod tests {
|
||||
let mut table_seq_0 = SequenceTableMapTable::new("MODE_1_SEQ_0");
|
||||
table_seq_0.add_entry(SequenceTableEntry::new(
|
||||
"MD1_SEQ0_TGT0",
|
||||
ExampleTargetId::Target0 as ComponentId,
|
||||
ExampleTargetId::Target0 as u64,
|
||||
SUBSYSTEM_MD1_ST0_TGT0_MODE,
|
||||
false,
|
||||
));
|
||||
table_seq_0.add_entry(SequenceTableEntry::new(
|
||||
"MD1_SEQ0_TGT1",
|
||||
ExampleTargetId::Target1 as ComponentId,
|
||||
ExampleTargetId::Target1 as u64,
|
||||
SUBSYSTEM_MD1_ST0_TGT1_MODE,
|
||||
false,
|
||||
));
|
||||
@@ -895,7 +895,7 @@ mod tests {
|
||||
let mut table_seq_1 = SequenceTableMapTable::new("MODE_1_SEQ_1");
|
||||
table_seq_1.add_entry(SequenceTableEntry::new(
|
||||
"MD1_SEQ1_TGT2",
|
||||
ExampleTargetId::Target2 as ComponentId,
|
||||
ExampleTargetId::Target2 as u64,
|
||||
SUBSYSTEM_MD1_ST1_TGT2_MODE,
|
||||
false,
|
||||
));
|
||||
@@ -1263,11 +1263,11 @@ mod tests {
|
||||
assert_eq!(req.request, ModeRequest::AnnounceModeRecursive);
|
||||
};
|
||||
let req0 = tb.sender.requests.borrow_mut().pop_front().unwrap();
|
||||
check_req(req0, ExampleTargetId::Target0 as ComponentId);
|
||||
check_req(req0, ExampleTargetId::Target0 as u64);
|
||||
let req1 = tb.sender.requests.borrow_mut().pop_front().unwrap();
|
||||
check_req(req1, ExampleTargetId::Target1 as ComponentId);
|
||||
check_req(req1, ExampleTargetId::Target1 as u64);
|
||||
let req2 = tb.sender.requests.borrow_mut().pop_front().unwrap();
|
||||
check_req(req2, ExampleTargetId::Target2 as ComponentId);
|
||||
check_req(req2, ExampleTargetId::Target2 as u64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1283,11 +1283,11 @@ mod tests {
|
||||
assert_eq!(req.request, ModeRequest::AnnounceMode);
|
||||
};
|
||||
let req0 = tb.sender.requests.borrow_mut().pop_front().unwrap();
|
||||
check_req(req0, ExampleTargetId::Target0 as ComponentId);
|
||||
check_req(req0, ExampleTargetId::Target0 as u64);
|
||||
let req1 = tb.sender.requests.borrow_mut().pop_front().unwrap();
|
||||
check_req(req1, ExampleTargetId::Target1 as ComponentId);
|
||||
check_req(req1, ExampleTargetId::Target1 as u64);
|
||||
let req2 = tb.sender.requests.borrow_mut().pop_front().unwrap();
|
||||
check_req(req2, ExampleTargetId::Target2 as ComponentId);
|
||||
check_req(req2, ExampleTargetId::Target2 as u64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -50,20 +50,20 @@ impl PacketInPool {
|
||||
|
||||
/// Generic trait for object which can send any packets in form of a raw bytestream, with
|
||||
/// no assumptions about the received protocol.
|
||||
pub trait PacketHandler: Send {
|
||||
pub trait PacketSenderRaw: Send {
|
||||
type Error;
|
||||
fn handle_packet(&self, sender_id: ComponentId, packet: &[u8]) -> Result<(), Self::Error>;
|
||||
fn send_packet(&self, sender_id: ComponentId, packet: &[u8]) -> Result<(), Self::Error>;
|
||||
}
|
||||
|
||||
/// Extension trait of [PacketHandler] which allows downcasting by implementing [Downcast].
|
||||
/// Extension trait of [PacketSenderRaw] which allows downcasting by implementing [Downcast].
|
||||
#[cfg(feature = "alloc")]
|
||||
pub trait PacketSenderRawExt: PacketHandler + Downcast {
|
||||
pub trait PacketSenderRawExt: PacketSenderRaw + Downcast {
|
||||
// Remove this once trait upcasting coercion has been implemented.
|
||||
// Tracking issue: https://github.com/rust-lang/rust/issues/65991
|
||||
fn upcast(&self) -> &dyn PacketHandler<Error = Self::Error>;
|
||||
fn upcast(&self) -> &dyn PacketSenderRaw<Error = Self::Error>;
|
||||
// Remove this once trait upcasting coercion has been implemented.
|
||||
// Tracking issue: https://github.com/rust-lang/rust/issues/65991
|
||||
fn upcast_mut(&mut self) -> &mut dyn PacketHandler<Error = Self::Error>;
|
||||
fn upcast_mut(&mut self) -> &mut dyn PacketSenderRaw<Error = Self::Error>;
|
||||
}
|
||||
|
||||
/// Blanket implementation to automatically implement [PacketSenderRawExt] when the [alloc]
|
||||
@@ -71,16 +71,16 @@ pub trait PacketSenderRawExt: PacketHandler + Downcast {
|
||||
#[cfg(feature = "alloc")]
|
||||
impl<T> PacketSenderRawExt for T
|
||||
where
|
||||
T: PacketHandler + Send + 'static,
|
||||
T: PacketSenderRaw + Send + 'static,
|
||||
{
|
||||
// Remove this once trait upcasting coercion has been implemented.
|
||||
// Tracking issue: https://github.com/rust-lang/rust/issues/65991
|
||||
fn upcast(&self) -> &dyn PacketHandler<Error = Self::Error> {
|
||||
fn upcast(&self) -> &dyn PacketSenderRaw<Error = Self::Error> {
|
||||
self
|
||||
}
|
||||
// Remove this once trait upcasting coercion has been implemented.
|
||||
// Tracking issue: https://github.com/rust-lang/rust/issues/65991
|
||||
fn upcast_mut(&mut self) -> &mut dyn PacketHandler<Error = Self::Error> {
|
||||
fn upcast_mut(&mut self) -> &mut dyn PacketSenderRaw<Error = Self::Error> {
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -288,19 +288,19 @@ pub mod std_mod {
|
||||
}
|
||||
}
|
||||
|
||||
impl PacketHandler for mpsc::Sender<PacketAsVec> {
|
||||
impl PacketSenderRaw for mpsc::Sender<PacketAsVec> {
|
||||
type Error = GenericSendError;
|
||||
|
||||
fn handle_packet(&self, sender_id: ComponentId, packet: &[u8]) -> Result<(), Self::Error> {
|
||||
fn send_packet(&self, sender_id: ComponentId, packet: &[u8]) -> Result<(), Self::Error> {
|
||||
self.send(PacketAsVec::new(sender_id, packet.to_vec()))
|
||||
.map_err(|_| GenericSendError::RxDisconnected)
|
||||
}
|
||||
}
|
||||
|
||||
impl PacketHandler for mpsc::SyncSender<PacketAsVec> {
|
||||
impl PacketSenderRaw for mpsc::SyncSender<PacketAsVec> {
|
||||
type Error = GenericSendError;
|
||||
|
||||
fn handle_packet(&self, sender_id: ComponentId, tc_raw: &[u8]) -> Result<(), Self::Error> {
|
||||
fn send_packet(&self, sender_id: ComponentId, tc_raw: &[u8]) -> Result<(), Self::Error> {
|
||||
self.try_send(PacketAsVec::new(sender_id, tc_raw.to_vec()))
|
||||
.map_err(|e| match e {
|
||||
mpsc::TrySendError::Full(_) => GenericSendError::QueueFull(None),
|
||||
@@ -402,12 +402,12 @@ pub mod std_mod {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Sender: PacketInPoolSender, PacketStore: CcsdsPacketPool + Send> PacketHandler
|
||||
impl<Sender: PacketInPoolSender, PacketStore: CcsdsPacketPool + Send> PacketSenderRaw
|
||||
for PacketSenderWithSharedPool<Sender, PacketStore>
|
||||
{
|
||||
type Error = StoreAndSendError;
|
||||
|
||||
fn handle_packet(&self, sender_id: ComponentId, packet: &[u8]) -> Result<(), Self::Error> {
|
||||
fn send_packet(&self, sender_id: ComponentId, packet: &[u8]) -> Result<(), Self::Error> {
|
||||
let mut shared_pool = self.shared_pool.borrow_mut();
|
||||
let store_addr = shared_pool.add_raw_tc(packet)?;
|
||||
drop(shared_pool);
|
||||
@@ -450,7 +450,7 @@ pub mod std_mod {
|
||||
_sp_header: &SpHeader,
|
||||
tc_raw: &[u8],
|
||||
) -> Result<(), Self::Error> {
|
||||
self.handle_packet(sender_id, tc_raw)
|
||||
self.send_packet(sender_id, tc_raw)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,10 +494,10 @@ pub(crate) mod tests {
|
||||
|
||||
pub(crate) fn send_with_sender<SendError>(
|
||||
sender_id: ComponentId,
|
||||
packet_sender: &(impl PacketHandler<Error = SendError> + ?Sized),
|
||||
packet_sender: &(impl PacketSenderRaw<Error = SendError> + ?Sized),
|
||||
packet: &[u8],
|
||||
) -> Result<(), SendError> {
|
||||
packet_sender.handle_packet(sender_id, packet)
|
||||
packet_sender.send_packet(sender_id, packet)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use arbitrary_int::{u11, u14};
|
||||
use spacepackets::SpHeader;
|
||||
use spacepackets::ecss::CreatorConfig;
|
||||
use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader};
|
||||
use spacepackets::ecss::{CreatorConfig, MessageTypeId};
|
||||
use spacepackets::time::cds::CdsTime;
|
||||
|
||||
pub struct PusTmWithCdsShortHelper {
|
||||
@@ -50,10 +50,7 @@ impl PusTmWithCdsShortHelper {
|
||||
seq_count: u14,
|
||||
) -> PusTmCreator<'_, 'data> {
|
||||
let reply_header = SpHeader::new_for_unseg_tm(self.apid, seq_count, 0);
|
||||
let tc_header = PusTmSecondaryHeader::new_simple(
|
||||
MessageTypeId::new(service, subservice),
|
||||
&self.cds_short_buf,
|
||||
);
|
||||
let tc_header = PusTmSecondaryHeader::new_simple(service, subservice, &self.cds_short_buf);
|
||||
PusTmCreator::new(
|
||||
reply_header,
|
||||
tc_header,
|
||||
@@ -76,8 +73,8 @@ mod tests {
|
||||
let stamper = CdsTime::new_with_u16_days(0, 0);
|
||||
let tm =
|
||||
pus_tm_helper.create_pus_tm_with_stamper(17, 1, &[1, 2, 3, 4], &stamper, u14::new(25));
|
||||
assert_eq!(tm.service_type_id(), 17);
|
||||
assert_eq!(tm.message_subtype_id(), 1);
|
||||
assert_eq!(tm.service(), 17);
|
||||
assert_eq!(tm.subservice(), 1);
|
||||
assert_eq!(tm.user_data(), &[1, 2, 3, 4]);
|
||||
assert_eq!(tm.seq_count().value(), 25);
|
||||
assert_eq!(tm.timestamp(), [64, 0, 0, 0, 0, 0, 0])
|
||||
@@ -87,8 +84,8 @@ mod tests {
|
||||
fn test_helper_from_now() {
|
||||
let mut pus_tm_helper = PusTmWithCdsShortHelper::new(u11::new(0x123));
|
||||
let tm = pus_tm_helper.create_pus_tm_timestamp_now(17, 1, &[1, 2, 3, 4], u14::new(25));
|
||||
assert_eq!(tm.service_type_id(), 17);
|
||||
assert_eq!(tm.message_subtype_id(), 1);
|
||||
assert_eq!(tm.service(), 17);
|
||||
assert_eq!(tm.subservice(), 1);
|
||||
assert_eq!(tm.user_data(), &[1, 2, 3, 4]);
|
||||
assert_eq!(tm.seq_count().value(), 25);
|
||||
assert_eq!(tm.timestamp().len(), 7);
|
||||
|
||||
@@ -45,7 +45,7 @@ pub enum AcsMode {
|
||||
}
|
||||
|
||||
#[derive(Debug, TryFromPrimitive)]
|
||||
#[repr(u32)]
|
||||
#[repr(u64)]
|
||||
pub enum TestComponentId {
|
||||
MagnetometerDevice0 = 1,
|
||||
MagnetometerDevice1 = 2,
|
||||
@@ -299,7 +299,7 @@ struct AcsSubsystem {
|
||||
|
||||
impl AcsSubsystem {
|
||||
pub fn id() -> ComponentId {
|
||||
TestComponentId::AcsSubsystem as ComponentId
|
||||
TestComponentId::AcsSubsystem as u64
|
||||
}
|
||||
|
||||
pub fn new(mode_node: ModeRequestorAndHandlerMpscBounded) -> Self {
|
||||
@@ -518,7 +518,7 @@ struct MgmAssembly {
|
||||
|
||||
impl MgmAssembly {
|
||||
pub fn id() -> ComponentId {
|
||||
TestComponentId::MagnetometerAssembly as ComponentId
|
||||
TestComponentId::MagnetometerAssembly as u64
|
||||
}
|
||||
pub fn new(mode_node: ModeRequestorAndHandlerMpscBounded) -> Self {
|
||||
Self {
|
||||
@@ -923,7 +923,7 @@ impl ModeRequestHandler for CommonDevice {
|
||||
mode_and_submode: ModeAndSubmode,
|
||||
forced: bool,
|
||||
) -> Result<(), ModeError> {
|
||||
if self.id() == TestComponentId::MagnetorquerDevice as ComponentId {
|
||||
if self.id() == TestComponentId::MagnetorquerDevice as u64 {
|
||||
println!("test");
|
||||
}
|
||||
self.mode_and_submode = mode_and_submode;
|
||||
@@ -996,7 +996,7 @@ pub struct AcsController {
|
||||
|
||||
impl AcsController {
|
||||
pub fn id() -> ComponentId {
|
||||
TestComponentId::AcsController as ComponentId
|
||||
TestComponentId::AcsController as u64
|
||||
}
|
||||
pub fn new(mode_node: ModeRequestHandlerMpscBounded) -> Self {
|
||||
Self {
|
||||
@@ -1020,7 +1020,7 @@ impl AcsController {
|
||||
|
||||
impl ModeNode for AcsController {
|
||||
fn id(&self) -> ComponentId {
|
||||
TestComponentId::AcsController as ComponentId
|
||||
TestComponentId::AcsController as u64
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1185,22 +1185,22 @@ impl TreeTestbench {
|
||||
|
||||
let mut mgm_dev_0 = CommonDevice::new(
|
||||
"MGM_0",
|
||||
TestComponentId::MagnetometerDevice0 as ComponentId,
|
||||
TestComponentId::MagnetometerDevice0 as u64,
|
||||
mgm_dev_node_0,
|
||||
);
|
||||
let mut mgm_dev_1 = CommonDevice::new(
|
||||
"MGM_1",
|
||||
TestComponentId::MagnetometerDevice1 as ComponentId,
|
||||
TestComponentId::MagnetometerDevice1 as u64,
|
||||
mgm_dev_node_1,
|
||||
);
|
||||
let mut mgt_dev = CommonDevice::new(
|
||||
"MGT",
|
||||
TestComponentId::MagnetorquerDevice as ComponentId,
|
||||
TestComponentId::MagnetorquerDevice as u64,
|
||||
mgt_dev_node,
|
||||
);
|
||||
let mut mgt_manager = DeviceManager::new(
|
||||
"MGT_MANAGER",
|
||||
TestComponentId::MgtDevManager as ComponentId,
|
||||
TestComponentId::MgtDevManager as u64,
|
||||
mgt_dev_mgmt_node,
|
||||
);
|
||||
let mut mgm_assy = MgmAssembly::new(mgm_assy_node);
|
||||
@@ -1212,38 +1212,38 @@ impl TreeTestbench {
|
||||
let mut target_table_safe = TargetTablesMapValue::new("SAFE_TARGET_TBL", None);
|
||||
target_table_safe.add_entry(TargetTableEntry::new(
|
||||
"CTRL_SAFE",
|
||||
TestComponentId::AcsController as ComponentId,
|
||||
TestComponentId::AcsController as u64,
|
||||
ModeAndSubmode::new(AcsMode::SAFE as u32, 0),
|
||||
// All submodes allowed.
|
||||
Some(0xffff),
|
||||
));
|
||||
target_table_safe.add_entry(TargetTableEntry::new_with_precise_submode(
|
||||
"MGM_A_NML",
|
||||
TestComponentId::MagnetometerAssembly as ComponentId,
|
||||
TestComponentId::MagnetometerAssembly as u64,
|
||||
ModeAndSubmode::new(DefaultMode::NORMAL as u32, 0),
|
||||
));
|
||||
target_table_safe.add_entry(TargetTableEntry::new_with_precise_submode(
|
||||
"MGT_MAN_NML",
|
||||
TestComponentId::MgtDevManager as ComponentId,
|
||||
TestComponentId::MgtDevManager as u64,
|
||||
ModeAndSubmode::new(DefaultMode::NORMAL as u32, 0),
|
||||
));
|
||||
let mut sequence_tbl_safe_0 = SequenceTableMapTable::new("SAFE_SEQ_0_TBL");
|
||||
sequence_tbl_safe_0.add_entry(SequenceTableEntry::new(
|
||||
"SAFE_SEQ_0_MGM_A",
|
||||
TestComponentId::MagnetometerAssembly as ComponentId,
|
||||
TestComponentId::MagnetometerAssembly as u64,
|
||||
ModeAndSubmode::new(DefaultMode::NORMAL as Mode, 0),
|
||||
false,
|
||||
));
|
||||
sequence_tbl_safe_0.add_entry(SequenceTableEntry::new(
|
||||
"SAFE_SEQ_0_MGT_MAN",
|
||||
TestComponentId::MgtDevManager as ComponentId,
|
||||
TestComponentId::MgtDevManager as u64,
|
||||
ModeAndSubmode::new(DefaultMode::NORMAL as Mode, 0),
|
||||
false,
|
||||
));
|
||||
let mut sequence_tbl_safe_1 = SequenceTableMapTable::new("SAFE_SEQ_1_TBL");
|
||||
sequence_tbl_safe_1.add_entry(SequenceTableEntry::new(
|
||||
"SAFE_SEQ_1_ACS_CTRL",
|
||||
TestComponentId::AcsController as ComponentId,
|
||||
TestComponentId::AcsController as u64,
|
||||
ModeAndSubmode::new(AcsMode::SAFE as Mode, 0),
|
||||
false,
|
||||
));
|
||||
@@ -1408,7 +1408,7 @@ fn announce_recursively() {
|
||||
fn generic_mode_reply_checker(
|
||||
reply_meta: MessageMetadata,
|
||||
mode_and_submode: ModeAndSubmode,
|
||||
expected_modes: &mut HashMap<ComponentId, ModeAndSubmode>,
|
||||
expected_modes: &mut HashMap<u64, ModeAndSubmode>,
|
||||
) {
|
||||
let id = TestComponentId::try_from(reply_meta.sender_id()).expect("invalid sender id");
|
||||
if !expected_modes.contains_key(&reply_meta.sender_id()) {
|
||||
@@ -1528,15 +1528,15 @@ fn command_safe_mode() {
|
||||
);
|
||||
let mut expected_modes = HashMap::new();
|
||||
expected_modes.insert(
|
||||
TestComponentId::AcsController as ComponentId,
|
||||
TestComponentId::AcsController as u64,
|
||||
ModeAndSubmode::new(AcsMode::SAFE as u32, 0),
|
||||
);
|
||||
expected_modes.insert(
|
||||
TestComponentId::MagnetometerAssembly as ComponentId,
|
||||
TestComponentId::MagnetometerAssembly as u64,
|
||||
ModeAndSubmode::new(DefaultMode::NORMAL as u32, 0),
|
||||
);
|
||||
expected_modes.insert(
|
||||
TestComponentId::MgtDevManager as ComponentId,
|
||||
TestComponentId::MgtDevManager as u64,
|
||||
ModeAndSubmode::new(DefaultMode::NORMAL as u32, 0),
|
||||
);
|
||||
while let Some(reply) = tb.subsystem.mode_reply_mock.mode_reply_messages.pop_front() {
|
||||
@@ -1558,11 +1558,11 @@ fn command_safe_mode() {
|
||||
);
|
||||
let mut expected_modes = HashMap::new();
|
||||
expected_modes.insert(
|
||||
TestComponentId::MagnetometerDevice0 as ComponentId,
|
||||
TestComponentId::MagnetometerDevice0 as u64,
|
||||
ModeAndSubmode::new(DefaultMode::NORMAL as u32, 0),
|
||||
);
|
||||
expected_modes.insert(
|
||||
TestComponentId::MagnetometerDevice1 as ComponentId,
|
||||
TestComponentId::MagnetometerDevice1 as u64,
|
||||
ModeAndSubmode::new(DefaultMode::NORMAL as u32, 0),
|
||||
);
|
||||
while let Some(reply) = tb.mgm_assy.mode_reply_mock.mode_reply_messages.pop_front() {
|
||||
@@ -1578,7 +1578,7 @@ fn command_safe_mode() {
|
||||
);
|
||||
let mut expected_modes = HashMap::new();
|
||||
expected_modes.insert(
|
||||
TestComponentId::MagnetorquerDevice as ComponentId,
|
||||
TestComponentId::MagnetorquerDevice as u64,
|
||||
ModeAndSubmode::new(DefaultMode::NORMAL as u32, 0),
|
||||
);
|
||||
let reply = tb
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use arbitrary_int::{u11, u21};
|
||||
use arbitrary_int::u11;
|
||||
use satrs::event_man_legacy::{
|
||||
EventManagerWithMpsc, EventMessage, EventMessageU32, EventRoutingError, EventSendProvider,
|
||||
EventU32SenderMpsc,
|
||||
@@ -18,7 +18,7 @@ const INFO_EVENT: EventU32TypedSev<SeverityInfo> = EventU32TypedSev::<SeverityIn
|
||||
const LOW_SEV_EVENT: EventU32 = EventU32::new(Severity::Low, 1, 5);
|
||||
const EMPTY_STAMP: [u8; 7] = [0; 7];
|
||||
const TEST_APID: u11 = u11::new(0x02);
|
||||
const TEST_ID: UniqueApidTargetId = UniqueApidTargetId::new(TEST_APID, u21::new(0x05));
|
||||
const TEST_ID: UniqueApidTargetId = UniqueApidTargetId::new(TEST_APID, 0x05);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum CustomTmSenderError {
|
||||
@@ -107,8 +107,8 @@ fn test_threaded_usage() {
|
||||
Ok(event_tm) => {
|
||||
let tm = PusTmReader::new(event_tm.packet.as_slice(), 7)
|
||||
.expect("Deserializing TM failed");
|
||||
assert_eq!(tm.service_type_id(), 5);
|
||||
assert_eq!(tm.message_subtype_id(), 1);
|
||||
assert_eq!(tm.service(), 5);
|
||||
assert_eq!(tm.subservice(), 1);
|
||||
let src_data = tm.source_data();
|
||||
assert!(!src_data.is_empty());
|
||||
assert_eq!(src_data.len(), 4);
|
||||
@@ -137,8 +137,8 @@ fn test_threaded_usage() {
|
||||
Ok(event_tm) => {
|
||||
let tm = PusTmReader::new(event_tm.packet.as_slice(), 7)
|
||||
.expect("Deserializing TM failed");
|
||||
assert_eq!(tm.service_type_id(), 5);
|
||||
assert_eq!(tm.message_subtype_id(), 2);
|
||||
assert_eq!(tm.service(), 5);
|
||||
assert_eq!(tm.subservice(), 2);
|
||||
let src_data = tm.source_data();
|
||||
assert!(!src_data.is_empty());
|
||||
assert_eq!(src_data.len(), 12);
|
||||
|
||||
@@ -13,9 +13,7 @@ pub mod crossbeam_test {
|
||||
use spacepackets::SpHeader;
|
||||
use spacepackets::ecss::tc::{PusTcCreator, PusTcReader, PusTcSecondaryHeader};
|
||||
use spacepackets::ecss::tm::PusTmReader;
|
||||
use spacepackets::ecss::{
|
||||
CreatorConfig, EcssEnumU8, EcssEnumU16, MessageTypeId, WritablePusPacket,
|
||||
};
|
||||
use spacepackets::ecss::{CreatorConfig, EcssEnumU8, EcssEnumU16, WritablePusPacket};
|
||||
use std::sync::RwLock;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
@@ -62,7 +60,7 @@ pub mod crossbeam_test {
|
||||
{
|
||||
let mut tc_guard = shared_tc_pool.write().unwrap();
|
||||
let sph = SpHeader::new_for_unseg_tc(TEST_APID, u14::ZERO, 0);
|
||||
let tc_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(17, 1));
|
||||
let tc_header = PusTcSecondaryHeader::new_simple(17, 1);
|
||||
let pus_tc_0 = PusTcCreator::new_no_app_data(sph, tc_header, CreatorConfig::default());
|
||||
req_id_0 = RequestId::new(&pus_tc_0);
|
||||
let addr = tc_guard
|
||||
@@ -72,7 +70,7 @@ pub mod crossbeam_test {
|
||||
.unwrap();
|
||||
tx_tc_0.send(addr).unwrap();
|
||||
let sph = SpHeader::new_for_unseg_tc(TEST_APID, u14::new(1), 0);
|
||||
let tc_header = PusTcSecondaryHeader::new_simple(MessageTypeId::new(5, 1));
|
||||
let tc_header = PusTcSecondaryHeader::new_simple(5, 1);
|
||||
let pus_tc_1 = PusTcCreator::new_no_app_data(sph, tc_header, CreatorConfig::default());
|
||||
req_id_1 = RequestId::new(&pus_tc_1);
|
||||
let addr = tc_guard
|
||||
@@ -166,11 +164,11 @@ pub mod crossbeam_test {
|
||||
RequestId::from_bytes(&pus_tm.source_data()[0..RequestId::SIZE_AS_BYTES])
|
||||
.expect("reading request ID from PUS TM source data failed");
|
||||
if !verif_map.contains_key(&req_id) {
|
||||
let content = vec![pus_tm.service_type_id()];
|
||||
let content = vec![pus_tm.subservice()];
|
||||
verif_map.insert(req_id, content);
|
||||
} else {
|
||||
let content = verif_map.get_mut(&req_id).unwrap();
|
||||
content.push(pus_tm.message_subtype_id())
|
||||
content.push(pus_tm.subservice())
|
||||
}
|
||||
packet_counter += 1;
|
||||
}
|
||||
|
||||
@@ -29,18 +29,15 @@ use satrs::{
|
||||
ccsds::{SpValidity, SpacePacketValidator},
|
||||
cobs::encode_packet_with_cobs,
|
||||
},
|
||||
hal::std::{
|
||||
tcp_server::{
|
||||
CobsTcParser, ConnectionResult, HandledConnectionHandler, HandledConnectionInfo,
|
||||
ServerConfig, TcpSpacepacketsServer, TcpTmtcInCobsServer,
|
||||
},
|
||||
tcp_spacepackets_server::CcsdsPacketParser,
|
||||
hal::std::tcp_server::{
|
||||
ConnectionResult, HandledConnectionHandler, HandledConnectionInfo, ServerConfig,
|
||||
TcpSpacepacketsServer, TcpTmtcInCobsServer,
|
||||
},
|
||||
tmtc::PacketSource,
|
||||
};
|
||||
use spacepackets::{
|
||||
CcsdsPacket, PacketId, SpHeader,
|
||||
ecss::{CreatorConfig, MessageTypeId, WritablePusPacket, tc::PusTcCreator},
|
||||
ecss::{CreatorConfig, WritablePusPacket, tc::PusTcCreator},
|
||||
};
|
||||
use std::{collections::VecDeque, sync::Arc, vec::Vec};
|
||||
|
||||
@@ -124,7 +121,7 @@ fn test_cobs_server() {
|
||||
1024,
|
||||
),
|
||||
tm_source,
|
||||
CobsTcParser::new(TCP_SERVER_ID, 1024, tc_sender.clone()),
|
||||
tc_sender.clone(),
|
||||
ConnectionFinishedHandler::default(),
|
||||
None,
|
||||
)
|
||||
@@ -222,8 +219,7 @@ fn test_ccsds_server() {
|
||||
let (tc_sender, tc_receiver) = mpsc::channel();
|
||||
let mut tm_source = SyncTmSource::default();
|
||||
let sph = SpHeader::new_for_unseg_tc(TEST_APID_0, u14::new(0), 0);
|
||||
let verif_tm =
|
||||
PusTcCreator::new_simple(sph, MessageTypeId::new(1, 1), &[], CreatorConfig::default());
|
||||
let verif_tm = PusTcCreator::new_simple(sph, 1, 1, &[], CreatorConfig::default());
|
||||
let tm_0 = verif_tm.to_vec().expect("tm generation failed");
|
||||
tm_source.add_tm(&tm_0);
|
||||
let mut packet_id_lookup = SimpleVerificator::default();
|
||||
@@ -237,7 +233,8 @@ fn test_ccsds_server() {
|
||||
1024,
|
||||
),
|
||||
tm_source,
|
||||
CcsdsPacketParser::new(TCP_SERVER_ID, 1024, tc_sender, packet_id_lookup),
|
||||
tc_sender,
|
||||
packet_id_lookup,
|
||||
ConnectionFinishedHandler::default(),
|
||||
None,
|
||||
)
|
||||
@@ -272,12 +269,7 @@ fn test_ccsds_server() {
|
||||
|
||||
// Send ping telecommand.
|
||||
let sph = SpHeader::new_for_unseg_tc(TEST_APID_0, u14::new(0), 0);
|
||||
let ping_tc = PusTcCreator::new_simple(
|
||||
sph,
|
||||
MessageTypeId::new(17, 1),
|
||||
&[],
|
||||
CreatorConfig::default(),
|
||||
);
|
||||
let ping_tc = PusTcCreator::new_simple(sph, 17, 1, &[], CreatorConfig::default());
|
||||
let tc_0 = ping_tc.to_vec().expect("packet creation failed");
|
||||
stream
|
||||
.write_all(&tc_0)
|
||||
|
||||
Reference in New Issue
Block a user