F´ Flight Software - C/C++ Documentation  NASA-v1.5.0
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 
61 
62  // ----------------------------------------------------------------------
63  // Handler implementations for user-defined typed input ports
64  // ----------------------------------------------------------------------
65 
68  void Sched_handler(
69  const NATIVE_INT_TYPE portNum,
71  );
72 
74 
75  // ----------------------------------------------------------------------
76  // Handler implementations for user-defined serial input ports
77  // ----------------------------------------------------------------------
78 
81  void PortsIn_handler(
82  NATIVE_INT_TYPE portNum,
84  );
85 
90 
91  struct sockaddr_in m_servAddr;
92 
95  {
96 
97  public:
98 
99 #ifdef BUILD_UT
100  void operator=(const UdpSerialBuffer& other);
102  UdpSerialBuffer(const UdpSerialBuffer& other);
103  UdpSerialBuffer();
104 #endif
105 
107  return sizeof(m_buff);
108  }
109 
110  // Get the max number of bytes that can be serialized
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 
137 
138  };
139 
140 } // end namespace Svc
141 
142 #endif
Svc::UdpSenderComponentImpl::UdpSerialBuffer::getBuffCapacity
NATIVE_UINT_TYPE getBuffCapacity(void) const
returns capacity, not current size, of buffer
Definition: UdpSenderComponentImpl.hpp:106
PRIVATE
#define PRIVATE
overridable private for unit testing
Definition: BasicTypes.hpp:118
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::UdpSenderComponentImpl::m_seq
U8 m_seq
packet sequence number; used to detect drops on the server end
Definition: UdpSenderComponentImpl.hpp:89
Svc::UdpSenderComponentImpl::m_bytesSent
NATIVE_UINT_TYPE m_bytesSent
number of bytes sent to server
Definition: UdpSenderComponentImpl.hpp:88
Svc::UdpSenderComponentImpl::context
PRIVATE NATIVE_UINT_TYPE context
Definition: UdpSenderComponentImpl.hpp:71
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
Svc::UdpSenderComponentImpl::m_servAddr
struct sockaddr_in m_servAddr
server address for sends
Definition: UdpSenderComponentImpl.hpp:91
Svc::UdpSenderComponentImpl::UdpSerialBuffer::getBuffAddr
const U8 * getBuffAddr(void) const
gets buffer address for data reading, const version
Definition: UdpSenderComponentImpl.hpp:128
Svc::UdpSenderComponentImpl::UdpSerialBuffer::getBuffAddr
U8 * getBuffAddr(void)
gets buffer address for data filling
Definition: UdpSenderComponentImpl.hpp:124
NATIVE_UINT_TYPE
unsigned int NATIVE_UINT_TYPE
native unsigned integer type declaration
Definition: BasicTypes.hpp:30
Svc::UdpSenderComponentImpl::m_fd
NATIVE_INT_TYPE m_fd
file descriptor for UDP socket
Definition: UdpSenderComponentImpl.hpp:86
Fw::SerializeBufferBase::getBuffLength
NATIVE_UINT_TYPE getBuffLength() const
returns current buffer size
Definition: Serializable.cpp:592
Svc::UdpSenderComponentImpl::UdpSerialBuffer::getBuffSerLeft
NATIVE_UINT_TYPE getBuffSerLeft(void) const
Definition: UdpSenderComponentImpl.hpp:111
UdpSenderComponentImplCfg.hpp
Svc::UdpSenderComponentImpl
Definition: UdpSenderComponentImpl.hpp:26
Svc::UdpSenderComponentImpl::UdpSenderComponentImpl
UdpSenderComponentImpl(const char *const compName)
Definition: UdpSenderComponentImpl.cpp:32
Fw::SerializeBufferBase::operator=
const SerializeBufferBase & operator=(const SerializeBufferBase &src)
equal operator
Definition: Serializable.cpp:60
Svc::UdpSenderComponentImpl::Buffer
PRIVATE Fw::SerializeBufferBase & Buffer
Definition: UdpSenderComponentImpl.hpp:84
Svc::UdpSenderComponentImpl::m_sendBuff
Svc::UdpSenderComponentImpl::UdpSerialBuffer m_sendBuff
Svc
Definition: ActiveLoggerComponentAc.cpp:22
Svc::UdpSenderComponentImpl::m_packetsSent
NATIVE_UINT_TYPE m_packetsSent
number of packets sent to server
Definition: UdpSenderComponentImpl.hpp:87
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
Svc::UdpSenderComponentImpl::UdpSerialBuffer
Definition: UdpSenderComponentImpl.hpp:95