fix: correct CCSDS packet length calculation

Signed-off-by: 0rlych1kk4 <orlychikka@gmail.com>
This commit is contained in:
0rlych1kk4
2026-08-31 14:28:24 +08:00
parent 12824b2906
commit 1649306802
2 changed files with 51 additions and 2 deletions
+2 -2
View File
@@ -54,7 +54,7 @@ impl CcsdsTcPacketOwned {
pub fn len_written(&self) -> usize {
ccsds_packet_len_for_user_data_len_with_checksum(
postcard::experimental::serialized_size(&self.tc_header).unwrap() as usize
+ postcard::experimental::serialized_size(&self.payload).unwrap() as usize,
+ self.payload.len(),
)
.unwrap()
}
@@ -116,7 +116,7 @@ impl CcsdsTmPacketOwned {
pub fn len_written(&self) -> usize {
ccsds_packet_len_for_user_data_len_with_checksum(
postcard::experimental::serialized_size(&self.tm_header).unwrap() as usize
+ postcard::experimental::serialized_size(&self.payload).unwrap() as usize,
+ self.payload.len(),
)
.unwrap()
}
+49
View File
@@ -0,0 +1,49 @@
use arbitrary_int::u11;
use spacepackets::{SpacePacketHeader, time::cds::CdsTime};
use types::{
Apid, ComponentId, MessageType, TcHeader, TmHeader,
ccsds::{CcsdsTcPacketOwned, CcsdsTmPacketOwned},
};
#[test]
fn tc_len_written_matches_actual_serialized_length() {
let packet = CcsdsTcPacketOwned::new_with_request(
SpacePacketHeader::new_from_apid(u11::new(Apid::Tmtc as u16)),
TcHeader::new(ComponentId::Controller, MessageType::Ping),
types::control::request::Request::Ping,
);
let actual = packet.to_vec();
println!("TC len_written(): {}", packet.len_written());
println!("TC actual len: {}", actual.len());
assert_eq!(packet.len_written(), actual.len());
}
#[test]
fn tm_len_written_matches_actual_serialized_length() {
let timestamp = CdsTime::new_with_u16_days(0, 0);
let tm_header = TmHeader::new(
ComponentId::Controller,
ComponentId::Ground,
MessageType::Verification,
None,
&timestamp,
);
let packet = CcsdsTmPacketOwned::new_with_serde_payload(
SpacePacketHeader::new_from_apid(u11::new(Apid::Tmtc as u16)),
&tm_header,
&types::control::response::Response::Ok,
)
.unwrap();
let actual = packet.to_vec();
println!("TM len_written(): {}", packet.len_written());
println!("TM actual len: {}", actual.len());
assert_eq!(packet.len_written(), actual.len());
}