F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
UdpReceiverComponentImpl.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title UdpReceiverImpl.hpp
3 // \author tcanham
4 // \brief hpp file for UdpReceiver component implementation class
5 //
6 // \copyright
7 // Copyright 2009-2015, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
13 #ifndef UdpReceiver_HPP
14 #define UdpReceiver_HPP
15 
16 #include "Svc/UdpReceiver/UdpReceiverComponentAc.hpp"
18 
19 namespace Svc {
20 
22  public UdpReceiverComponentBase
23  {
24 
25  public:
26 
27  // ----------------------------------------------------------------------
28  // Construction, initialization, and destruction
29  // ----------------------------------------------------------------------
30 
34  const char *const compName
35  );
36 
40 
42  void open(
43  const char* port
44  );
45 
47  void startThread(
48  NATIVE_UINT_TYPE priority,
49  NATIVE_UINT_TYPE stackSize,
50  NATIVE_UINT_TYPE affinity
51  );
52 
53 
54  PRIVATE:
55 
56  // ----------------------------------------------------------------------
57  // Handler implementations for user-defined typed input ports
58  // ----------------------------------------------------------------------
59 
62  void Sched_handler(
63  const NATIVE_INT_TYPE portNum,
64  U32 context
65  );
66 
67  static void workerTask(void* ptr);
68  void doRecv();
69  Os::Task m_socketTask;
70 
71  NATIVE_INT_TYPE m_fd;
72 
73  class UdpSerialBuffer :
75  {
76 
77  public:
78 
79 #ifdef BUILD_UT
80  UdpSerialBuffer& operator=(const UdpSerialBuffer& other);
81  UdpSerialBuffer(const Fw::SerializeBufferBase& other);
82  UdpSerialBuffer(const UdpSerialBuffer& other);
83  UdpSerialBuffer();
84 #endif
85 
86  NATIVE_UINT_TYPE getBuffCapacity() const {
87  return sizeof(m_buff);
88  }
89 
90  // Get the max number of bytes that can be serialized
91  NATIVE_UINT_TYPE getBuffSerLeft() const {
92 
93  const NATIVE_UINT_TYPE size = getBuffCapacity();
94  const NATIVE_UINT_TYPE loc = getBuffLength();
95 
96  if (loc >= (size-1) ) {
97  return 0;
98  }
99  else {
100  return (size - loc - 1);
101  }
102  }
103 
104  U8* getBuffAddr() {
105  return m_buff;
106  }
107 
108  const U8* getBuffAddr() const {
109  return m_buff;
110  }
111 
112  private:
113  // Should be the max of all the input ports serialized sizes...
114  U8 m_buff[UDP_RECEIVER_MSG_SIZE];
115 
116  } m_recvBuff;
117 
118  UdpSerialBuffer m_portBuff;
119 
120  U32 m_packetsReceived;
121  U32 m_bytesReceived;
122  U32 m_packetsDropped;
123  U32 m_decodeErrors;
124 
125  bool m_firstSeq;
126  U8 m_currSeq;
127 
128 
129  };
130 
131 } // end namespace Svc
132 
133 #endif
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:55
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:30
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:56
UdpReceiverComponentImpl(const char *const compName)
void open(const char *port)
Open the connection.
void startThread(NATIVE_UINT_TYPE priority, NATIVE_UINT_TYPE stackSize, NATIVE_UINT_TYPE affinity)
start worker thread
static const NATIVE_UINT_TYPE UDP_RECEIVER_MSG_SIZE