F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
AosFramer.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title AosFramer.hpp
3 // \author Will MacCormack (Aos Modifications)
4 // \brief hpp file for AosFramer component implementation class
5 // \details modified from thomas-bc's TmFramer
6 // ======================================================================
7 
8 #ifndef Svc_Ccsds_AosFramer_HPP
9 #define Svc_Ccsds_AosFramer_HPP
10 
18 
19 namespace Svc {
20 
21 namespace Ccsds {
22 
23 class AosFramer final : public AosFramerComponentBase {
24  friend class AosFramerTester;
25 
26  static constexpr U8 SPP_IDLE_DATA_PATTERN = 0x44;
27  static constexpr U8 MIN_SPP_LENGTH = 7;
28 
29  // Offset to start of payload
30  static constexpr U16 START_OF_PAYLOAD = AOSHeader::SERIALIZED_SIZE + M_PDUHeader::SERIALIZED_SIZE;
31 
32  enum class BufferOwnershipState {
33  NOT_OWNED,
34  OWNED,
35  };
36 
37  struct PDU {
38  Fw::Buffer packet;
39  ComCfg::FrameContext context;
40  FwSizeType offset = 0;
41  };
42 
43  struct AosVc {
44  U8 vc_struct_index = 0xFF;
45  U8 virtualChannelId = 0;
46  // Current implementation uses a single virtual channel, so we can use a single virtual frame count
47  U32 virtualFrameCount = 0;
48 
49  // Because the AOS protocol use fixed width frames, and only one frame is in transit between ComQueue and
50  // ComInterface at a time, we can use a member fixed-size buffer to hold the frame data
51  struct FrameBuffer {
54  BufferOwnershipState state = BufferOwnershipState::OWNED;
55  } frame;
56 
57  // multi frame per PDU support
58  PDU outstanding;
59 
60  // Bitfield of supported PVNs for inserted Idle Packets
61  // Default to only supporting SPP Idle packets
62  U8 idle_packet_types = PvnBitfield::SPP_MASK;
63 
64  // SPP Idle packet backstop
65  // Technically we'd only use 6 of the 7 bytes at worst
66  // cuz the first one had to go into the prev frame
67  struct SppIdle {
68  U8 backer[MIN_SPP_LENGTH];
69  U8 offset = 0;
70  } spp_idle;
71 
72  // Multi PDU per frame and
73  U16 current_payload_offset = 0;
74  bool past_first_fresh_packet = false;
75  };
76 
77  public:
78  // ----------------------------------------------------------------------
79  // Component construction and destruction
80  // ----------------------------------------------------------------------
81 
83  AosFramer(const char* const compName
84  );
85 
87  ~AosFramer();
88 
91  void configure(U32 fixedFixedSize,
92  bool frameErrorControlField,
93  U16 spacecraftId = ComCfg::SpacecraftId,
94  U8 vcId = 1,
95  U8 idlePvns = PvnBitfield::SPP_MASK
96  );
99 
100  private:
101  // ----------------------------------------------------------------------
102  // Handler implementations for typed input ports
103  // ----------------------------------------------------------------------
104 
109  void comStatusIn_handler(FwIndexType portNum,
110  Fw::Success& condition
111  ) override;
112 
119  void dataIn_handler(FwIndexType portNum,
120  Fw::Buffer& data,
121  const ComCfg::FrameContext& context) override;
122 
126  void dataReturnIn_handler(FwIndexType portNum,
127  Fw::Buffer& data,
128  const ComCfg::FrameContext& context) override;
129 
130  // ----------------------------------------------------------------------
131  // Helpers
132  // ----------------------------------------------------------------------
133 
134  FwSizeType get_min_size();
135 
136  private:
140  void fill_with_idle_packet(AosVc& vc, const ComCfg::FrameContext& context);
141 
142  void serialize_idle_spp_packet(Fw::SerialBufferBase& serializer, U16 length);
143 
145  void setup_header(const ComCfg::FrameContext& context);
146 
148  void setup_m_pdu_header(const ComCfg::FrameContext& context, bool noFresh = false);
149 
151  void pack_packet(Fw::Buffer& data, const ComCfg::FrameContext& context, FwSizeType offset = 0);
152 
154  void check_and_send_vc(AosFramer::AosVc& currentVc);
155 
157  void pack_pad_send(Fw::Buffer& data, const ComCfg::FrameContext& context, FwSizeType offset = 0);
158 
160  void compute_and_inject_fecf(AosVc& currentVc);
161 
163  static bool buffer_belongs(Fw::Buffer& buffer, U8 const* start, FwSizeType size);
164 
168  AosVc& get_vc_struct(const ComCfg::FrameContext& context);
169 
170  // ----------------------------------------------------------------------
171  // Members
172  // ----------------------------------------------------------------------
173  private:
174  // Config Parameters
175  bool m_fecf = true;
176  U16 m_spacecraftId = 0;
177 
178  AosVc m_vcs[1];
179 };
180 
181 } // namespace Ccsds
182 } // namespace Svc
183 
184 #endif
void configure(U32 fixedFixedSize, bool frameErrorControlField, U16 spacecraftId=ComCfg::SpacecraftId, U8 vcId=1, U8 idlePvns=PvnBitfield::SPP_MASK)
Definition: AosFramer.cpp:26
PlatformSizeType FwSizeType
U8 backer[ComCfg::AosMaxFrameFixedSize]
Buffer to hold the frame data.
Definition: AosFramer.hpp:52
~AosFramer()
Destroy AosFramer object.
Definition: AosFramer.cpp:24
Auto-generated base for AosFramer component.
AosFramer(const char *const compName)
Construct AosFramer object.
Definition: AosFramer.cpp:19
BufferOwnershipState state
whether m_frameBuffer is owned by AosFramer
Definition: AosFramer.hpp:54
The size of the serial representation.
The size of the serial representation.
friend class AosFramerTester
Definition: AosFramer.hpp:24
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
PlatformIndexType FwIndexType
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
Success/Failure.
Fw::Buffer buffer
Buffer object pointing at frameBufferBacker.
Definition: AosFramer.hpp:53