Skip to content

CCSDS AOS Deframer#4779

Open
Willmac16 wants to merge 114 commits intonasa:develfrom
Willmac16:aos-deframer
Open

CCSDS AOS Deframer#4779
Willmac16 wants to merge 114 commits intonasa:develfrom
Willmac16:aos-deframer

Conversation

@Willmac16
Copy link
Copy Markdown
Contributor

@Willmac16 Willmac16 commented Feb 27, 2026

Related Issue(s)
Has Unit Tests (y/n) y
Documentation Included (y/n) n
Generative AI was used in this contribution (y/n) y

Change Description

Add a CCSDS AOS SDL version 5 defamer that supports:

  • Space Packet Protocol
  • Encapsulation Packet Protocol
  • FECF on or off
  • 1 virtual channel--all the internal code should be ready for multiple just needs agreement on config & output port setup (i.e. vc per port array index)

Rationale

You need an AOS Deframer to rx AOS Frames from payloads/other craft.
AOS lets you do fixed frame width w/ variable packet size (including packets that span multiple frames)

Testing/Review Recommendations

Take a look at the processing I'm doing on SPP & EPP packets and what I'm emitting in the context for them. I could imagine a later rev of this component sharing w/ SPP defamer more logic/doing its job for it.

Other facet on the SPP & EPP processing is how light my validation is. I'm only checking that they contain the right PVN & grabbing size + idle. If we moved the full SPP parsing into this/called into a lib then you could maybe avoid throwing away packets by ID-ing a problem earlier (although dropping a frame upon packet issues is probably the only safe thing to do).

A double check on my read of the EPP spec would be beneficial since I caught a few bugs that lingered all the way into testing.

Future Work

I am likely done w/ AOS for near term; however, future work could be:

  • Porting downlink stack to AOS
  • Using AOS Framer to bootstrap USLP
  • Making a proper EPP Framer & Deframer
  • Consolidating logic into a lib btw AOS, SPP, & EPP deframers
  • Writing an AOS Frame Detector if using AOS over a byte stream like tcp vs a datagram protocol like UDP

AI Usage (see policy)

  • Claude Code for Web did the first pass
  • The Claude Code GitHub extension addressed feedback on 3-4 commits
  • Over the past couple days, while I worked in VSCode I would use ChatGPT Codex & Claude Code CLI for minor code movement/event creation and test tweaks. I've reviewed (and quite often heavily refactored) all of the flight code to match my stylistic and structural preferences

Overall, I'm not convinced the first 2 steps really provided that much of a speedup since much of the EPP structure was completely wrong, and the approach to spanning packets had significant code duplication. Maybe a minor psychological speedup simply because I had code to review to bootstrap rather than a blank slate.

The minor test writing & event creation usage felt like a speedup, but better editor skills/snippets might be able to handily beat that.

binaryfile
BINDIR
bitfield
Bitfield

Check warning

Code scanning / check-spelling

Ignored Expect Variant

[Bitfield](#security-tab) is ignored by check spelling because another more general variant is also in expect. \(ignored-expect-variant\)
endmacro
endraw
enduml
EPP

Check warning

Code scanning / check-spelling

Ignored Expect Variant

[EPP](#security-tab) is ignored by check spelling because another more general variant is also in expect. \(ignored-expect-variant\)
@Willmac16 Willmac16 changed the title Aos deframer CCSDS AOS Deframer Feb 27, 2026
@Willmac16
Copy link
Copy Markdown
Contributor Author

This PR should look less scary once #4630 merges

Copy link
Copy Markdown

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@Willmac16 Willmac16 marked this pull request as ready for review March 2, 2026 20:09
Copy link
Copy Markdown
Collaborator

@thomas-bc thomas-bc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! A few notes and questions. I'm also overall seeing very few asserts in the processing parts of the code, it'd be good if we add some.

const FwSizeType headerCap = AosDeframerVc::SpanningPacketState::HEADER_BUF_SIZE;
const FwSizeType toHeader = FW_MIN(size, headerCap - vc.spanningPacket.bytesReceived);
if (toHeader > 0) {
::memcpy(vc.spanningPacket.headerBuf + vc.spanningPacket.bytesReceived, data, toHeader);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is a bit complex to follow here, could we add a few comments? I'm also not entirely certain that there isn't a very niche edge-case in case FwSizeType isn't large, could there be a scenario where:

  1. you've accumulated a very large spanning packet
  2. headerCap - vc.spanningPacket.bytesReceived ends up wrapping around to a value lower than received size
  3. I think you'd hit an invalid memcpy() below?

Probably at least should assert both toHeader <= 8 and vc.spanningPacket.bytesReceived < 8 here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added those asserts & more more comments

}
}

AosDeframer::~AosDeframer() {}

Check notice

Code scanning / CodeQL

More than one statement per line Note

This line contains 2 statements; only one is allowed.

AosDeframer::~AosDeframer() {}

void AosDeframer::configure(U32 fixedFrameSize, bool frameErrorControlField, U16 spacecraftId, U8 vcId, U8 pvnMask) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

void AosDeframer::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
}
}

void AosDeframer::abandonSpanningPacket(AosDeframerVc& vc) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
return nullptr;
}

AosDeframer::AosDeframerVc* AosDeframer::parseAndValidateHeader(Fw::Buffer& data, ComCfg::FrameContext& context) {

Check notice

Code scanning / CodeQL

Function too long Note

parseAndValidateHeader has too many lines (72, while 60 are allowed).
}
}

FwSizeType AosDeframer::sizePacket(AosDeframerVc& vc, U8* packetStart, FwSizeType remainingBytes) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
}
}

FwSizeType AosDeframer::sizeSppPacket(U8* payloadStart, FwSizeType payloadSize) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
return totalPacketSize;
}

FwSizeType AosDeframer::sizeEppPacket(const U8* const payloadStart, FwSizeType payloadSize) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
AosDeframerVc* getVcStruct(const U8 vcId);

//! Per-virtual-channel state, mirroring the AosFramer::AosVc pattern for future multi-VC support
struct AosDeframerVc {

Check notice

Code scanning / CodeQL

More than one statement per line Note

This line contains 2 statements; only one is allowed.

// Spanning packet state (for packets that span multiple frames)
// Per CCSDS 732.0-B-5 Section 4.1.4.2.2.3
struct SpanningPacketState {

Check notice

Code scanning / CodeQL

More than one statement per line Note

This line contains 2 statements; only one is allowed.
@LeStarch LeStarch added Deferred To Future Release This PR is marked as deferred until after the upcoming release. and removed Deferred To Future Release This PR is marked as deferred until after the upcoming release. labels Mar 30, 2026
@Willmac16
Copy link
Copy Markdown
Contributor Author

I believe that should address all of your comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants