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 = 1;
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  U8 idlePvns = PvnBitfield::SPP_MASK
94  );
97 
98  private:
99  // ----------------------------------------------------------------------
100  // Handler implementations for typed input ports
101  // ----------------------------------------------------------------------
102 
107  void comStatusIn_handler(FwIndexType portNum,
108  Fw::Success& condition
109  ) override;
110 
117  void dataIn_handler(FwIndexType portNum,
118  Fw::Buffer& data,
119  const ComCfg::FrameContext& context) override;
120 
124  void dataReturnIn_handler(FwIndexType portNum,
125  Fw::Buffer& data,
126  const ComCfg::FrameContext& context) override;
127 
128  // ----------------------------------------------------------------------
129  // Helpers
130  // ----------------------------------------------------------------------
131 
132  FwSizeType get_min_size();
133 
134  private:
138  void fill_with_idle_packet(AosVc& vc, const ComCfg::FrameContext& context);
139 
140  void serialize_idle_spp_packet(Fw::SerializeBufferBase& serializer, U16 length);
141 
143  void setup_header(const ComCfg::FrameContext& context);
144 
146  void setup_m_pdu_header(const ComCfg::FrameContext& context, bool noFresh = false);
147 
149  void pack_packet(Fw::Buffer& data, const ComCfg::FrameContext& context, FwSizeType offset = 0);
150 
152  void check_and_send_vc(AosFramer::AosVc& currentVc);
153 
155  void pack_pad_send(Fw::Buffer& data, const ComCfg::FrameContext& context, FwSizeType offset = 0);
156 
158  void compute_and_inject_fecf(AosVc& currentVc);
159 
161  static bool buffer_belongs(Fw::Buffer& buffer, U8 const* start, FwSizeType size);
162 
166  AosVc& get_vc_struct(const ComCfg::FrameContext& context);
167 
168  // ----------------------------------------------------------------------
169  // Members
170  // ----------------------------------------------------------------------
171  private:
172  // Config Parameters
173  bool m_fecf = true;
174 
175  AosVc m_vcs[1];
176 };
177 
178 } // namespace Ccsds
179 } // namespace Svc
180 
181 #endif
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
friend class AosFramerTester
Definition: AosFramer.hpp:24
The size of the serial representation.
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
The size of the serial representation.
PlatformIndexType FwIndexType
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
void configure(U32 fixedFixedSize, bool frameErrorControlField, U8 idlePvns=PvnBitfield::SPP_MASK)
Definition: AosFramer.cpp:26
Success/Failure.
Fw::Buffer buffer
Buffer object pointing at frameBufferBacker.
Definition: AosFramer.hpp:53