F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
19namespace 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
39 void init(
40 const NATIVE_INT_TYPE instance = 0
41 );
42
46
48 void open(
49 const char* port
50 );
51
53 void startThread(
54 NATIVE_UINT_TYPE priority,
55 NATIVE_UINT_TYPE stackSize,
56 NATIVE_UINT_TYPE affinity
57 );
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 static void workerTask(void* ptr);
74 void doRecv();
75 Os::Task m_socketTask;
76
77 NATIVE_INT_TYPE m_fd;
78
79 class UdpSerialBuffer :
81 {
82
83 public:
84
85#ifdef BUILD_UT
86 UdpSerialBuffer& operator=(const UdpSerialBuffer& other);
87 UdpSerialBuffer(const Fw::SerializeBufferBase& other);
88 UdpSerialBuffer(const UdpSerialBuffer& other);
89 UdpSerialBuffer();
90#endif
91
92 NATIVE_UINT_TYPE getBuffCapacity() const {
93 return sizeof(m_buff);
94 }
95
96 // Get the max number of bytes that can be serialized
97 NATIVE_UINT_TYPE getBuffSerLeft() const {
98
99 const NATIVE_UINT_TYPE size = getBuffCapacity();
100 const NATIVE_UINT_TYPE loc = getBuffLength();
101
102 if (loc >= (size-1) ) {
103 return 0;
104 }
105 else {
106 return (size - loc - 1);
107 }
108 }
109
110 U8* getBuffAddr() {
111 return m_buff;
112 }
113
114 const U8* getBuffAddr() const {
115 return m_buff;
116 }
117
118 private:
119 // Should be the max of all the input ports serialized sizes...
121
122 } m_recvBuff;
123
124 UdpSerialBuffer m_portBuff;
125
126 U32 m_packetsReceived;
127 U32 m_bytesReceived;
128 U32 m_packetsDropped;
129 U32 m_decodeErrors;
130
131 bool m_firstSeq;
132 U8 m_currSeq;
133
134
135 };
136
137} // end namespace Svc
138
139#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
SerializeBufferBase & operator=(const SerializeBufferBase &src)
equal operator
NATIVE_UINT_TYPE getBuffLength() const
returns current buffer size
forward declaration
Definition Task.hpp:15
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
void init(const NATIVE_INT_TYPE instance=0)
static const NATIVE_UINT_TYPE UDP_RECEIVER_MSG_SIZE