F´ Flight Software - C/C++ Documentation  NASA-v2.0.1
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  NATIVE_UINT_TYPE 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  void 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(void) const {
107  return sizeof(m_buff);
108  }
109 
110  // Get the max number of bytes that can be serialized
111  NATIVE_UINT_TYPE getBuffSerLeft(void) 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(void) {
125  return m_buff;
126  }
127 
128  const U8* getBuffAddr(void) 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
Fw::SerializeBufferBase
Definition: Serializable.hpp:43
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
Svc::UdpSenderComponentImpl::~UdpSenderComponentImpl
~UdpSenderComponentImpl(void)
Definition: UdpSenderComponentImpl.cpp:54
Svc::UDP_SENDER_MSG_SIZE
static const NATIVE_UINT_TYPE UDP_SENDER_MSG_SIZE
Definition: UdpSenderComponentImplCfg.hpp:12
Svc::UdpSenderComponentImpl::init
void init(const NATIVE_INT_TYPE queueDepth, const NATIVE_INT_TYPE msgSize, const NATIVE_INT_TYPE instance=0)
Definition: UdpSenderComponentImpl.cpp:44
NATIVE_UINT_TYPE
unsigned int NATIVE_UINT_TYPE
native unsigned integer type declaration
Definition: BasicTypes.hpp:30
UdpSenderComponentImplCfg.hpp
Svc::UdpSenderComponentImpl
Definition: UdpSenderComponentImpl.hpp:24
Svc::UdpSenderComponentImpl::UdpSenderComponentImpl
UdpSenderComponentImpl(const char *const compName)
Definition: UdpSenderComponentImpl.cpp:32
Svc
Definition: ActiveRateGroupImplCfg.hpp:18
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
Svc::UdpSenderComponentImpl::open
void open(const char *addr, const char *port)
Definition: UdpSenderComponentImpl.cpp:61