F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
UdpSenderComponentImpl.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title UdpSenderImpl.hpp
3 // \author tcanham
4 // \brief hpp file for UdpSender 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 UdpSender_HPP
14 #define UdpSender_HPP
15 
16 #include <Svc/UdpSender/UdpSenderComponentAc.hpp>
18 #include <sys/socket.h>
19 #include <arpa/inet.h>
20 
21 
22 namespace Svc {
23 
25  public UdpSenderComponentBase
26  {
27 
28  public:
29 
30  // ----------------------------------------------------------------------
31  // Construction, initialization, and destruction
32  // ----------------------------------------------------------------------
33 
37  const char *const compName
38  );
39 
42  void init(
43  const NATIVE_INT_TYPE queueDepth,
44  const NATIVE_INT_TYPE msgSize,
45  const NATIVE_INT_TYPE instance = 0
46  );
47 
48 
52 
55  void open(
56  const char* addr,
57  const char* port
58  );
59 
60  PRIVATE:
61 
62  // ----------------------------------------------------------------------
63  // Handler implementations for user-defined typed input ports
64  // ----------------------------------------------------------------------
65 
68  void Sched_handler(
69  const NATIVE_INT_TYPE portNum,
70  U32 context
71  );
72 
73  PRIVATE:
74 
75  // ----------------------------------------------------------------------
76  // Handler implementations for user-defined serial input ports
77  // ----------------------------------------------------------------------
78 
81  void PortsIn_handler(
82  NATIVE_INT_TYPE portNum,
84  );
85 
86  NATIVE_INT_TYPE m_fd;
87  NATIVE_UINT_TYPE m_packetsSent;
88  NATIVE_UINT_TYPE m_bytesSent;
89  U8 m_seq;
90 
91  struct sockaddr_in m_servAddr;
92 
93  class UdpSerialBuffer :
95  {
96 
97  public:
98 
99 #ifdef BUILD_UT
100  UdpSerialBuffer& operator=(const UdpSerialBuffer& other);
101  UdpSerialBuffer(const Fw::SerializeBufferBase& other);
102  UdpSerialBuffer(const UdpSerialBuffer& other);
103  UdpSerialBuffer();
104 #endif
105 
106  NATIVE_UINT_TYPE getBuffCapacity() const {
107  return sizeof(m_buff);
108  }
109 
110  // Get the max number of bytes that can be serialized
111  NATIVE_UINT_TYPE getBuffSerLeft() const {
112 
113  const NATIVE_UINT_TYPE size = getBuffCapacity();
114  const NATIVE_UINT_TYPE loc = getBuffLength();
115 
116  if (loc >= (size-1) ) {
117  return 0;
118  }
119  else {
120  return (size - loc - 1);
121  }
122  }
123 
124  U8* getBuffAddr() {
125  return m_buff;
126  }
127 
128  const U8* getBuffAddr() const {
129  return m_buff;
130  }
131 
132  private:
133  // Should be the max of all the input ports serialized sizes...
134  U8 m_buff[UDP_SENDER_MSG_SIZE];
135 
136  } m_sendBuff;
137 
138  };
139 
140 } // end namespace Svc
141 
142 #endif
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:26
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:52
UdpSenderComponentImpl(const char *const compName)
void open(const char *addr, const char *port)
void init(const NATIVE_INT_TYPE queueDepth, const NATIVE_INT_TYPE msgSize, const NATIVE_INT_TYPE instance=0)
static const NATIVE_UINT_TYPE UDP_SENDER_MSG_SIZE