21#include <sys/socket.h>
26#define DEBUG_PRINT(x,...)
34 UdpReceiverComponentImpl ::
35 UdpReceiverComponentImpl(
36 const char *
const compName
37 ) : UdpReceiverComponentBase(compName),
49 void UdpReceiverComponentImpl ::
54 UdpReceiverComponentBase::init(instance);
57 UdpReceiverComponentImpl ::
58 ~UdpReceiverComponentImpl()
60 if (this->m_fd != -1) {
70 this->m_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
71 if (-1 == this->m_fd) {
73 this->log_WARNING_HI_UR_SocketError(arg);
78 memset(&saddr, 0,
sizeof(saddr));
80 saddr.sin_family = AF_INET;
81 saddr.sin_port = htons(atoi(port));
82 saddr.sin_addr.s_addr = htonl(INADDR_ANY);
85 NATIVE_INT_TYPE status = bind(this->m_fd , (
struct sockaddr*)&saddr,
sizeof(saddr));
88 this->log_WARNING_HI_UR_BindError(arg);
92 this->log_ACTIVITY_HI_UR_PortOpened(atoi(port));
107 UdpReceiverComponentImpl::workerTask,
118 void UdpReceiverComponentImpl ::
124 this->tlmWrite_UR_BytesReceived(this->m_bytesReceived);
125 this->tlmWrite_UR_PacketsReceived(this->m_packetsReceived);
126 this->tlmWrite_UR_PacketsDropped(this->m_packetsDropped);
129 void UdpReceiverComponentImpl::workerTask(
void* ptr) {
130 UdpReceiverComponentImpl *compPtr =
static_cast<UdpReceiverComponentImpl*
>(ptr);
136 void UdpReceiverComponentImpl::doRecv() {
141 this->m_recvBuff.getBuffAddr(),
142 this->m_recvBuff.getBuffCapacity(),
147 if (errno != EINTR) {
149 this->log_WARNING_HI_UR_RecvError(arg);
159 stat = this->m_recvBuff.deserialize(seqNum);
162 this->log_WARNING_HI_UR_DecodeError(DECODE_SEQ,stat);
163 this->m_decodeErrors++;
168 if (this->m_firstSeq) {
170 this->m_currSeq = seqNum;
171 this->m_firstSeq =
false;
174 if (seqNum != ++this->m_currSeq) {
176 U8 diff = seqNum - this->m_currSeq;
177 this->m_packetsDropped += diff;
179 this->log_WARNING_HI_UR_DroppedPacket(diff);
181 this->m_currSeq = seqNum;
187 stat = this->m_recvBuff.deserialize(portNum);
190 this->log_WARNING_HI_UR_DecodeError(DECODE_PORT,stat);
191 this->m_decodeErrors++;
196 stat = this->m_recvBuff.deserialize(this->m_portBuff);
198 this->log_WARNING_HI_UR_DecodeError(DECODE_BUFFER,stat);
199 this->m_decodeErrors++;
204 DEBUG_PRINT(
"Calling port %d with %d bytes.\n",portNum,this->m_portBuff.getBuffLength());
205 if (this->isConnected_PortsOut_OutputPort(portNum)) {
212 this->log_WARNING_HI_UR_DecodeError(PORT_SEND,stat);
213 this->m_decodeErrors++;
216 this->m_packetsReceived++;
217 this->m_bytesReceived += psize;
225 this->serialize(other.getBuffAddr(),other.getBuffLength(),
true);
229 UdpReceiverComponentImpl::UdpSerialBuffer::UdpSerialBuffer(
236 UdpReceiverComponentImpl::UdpSerialBuffer::UdpSerialBuffer(
237 const UdpReceiverComponentImpl::UdpSerialBuffer& other) :
Fw::SerializeBufferBase() {
238 FW_ASSERT(
sizeof(this->m_buff)>= other.getBuffLength(),
sizeof(this->m_buff),other.getBuffLength());
239 memcpy(this->m_buff,other.m_buff,other.getBuffLength());
240 this->setBuffLen(other.getBuffLength());
243 UdpReceiverComponentImpl::UdpSerialBuffer::UdpSerialBuffer():
Fw::SerializeBufferBase() {
PlatformIntType NATIVE_INT_TYPE
uint8_t U8
8-bit unsigned integer
PlatformUIntType NATIVE_UINT_TYPE
C++-compatible configuration header for fprime configuration.
#define DEBUG_PRINT(x,...)
SerializeBufferBase & operator=(const SerializeBufferBase &src)
equal operator
virtual U8 * getBuffAddr()=0
gets buffer address for data filling
NATIVE_UINT_TYPE getBuffLength() const
returns current buffer size
@ TASK_OK
message sent/received okay
TaskStatus start(const Fw::StringBase &name, taskRoutine routine, void *arg, NATIVE_UINT_TYPE priority=TASK_DEFAULT, NATIVE_UINT_TYPE stackSize=TASK_DEFAULT, NATIVE_UINT_TYPE cpuAffinity=TASK_DEFAULT, NATIVE_UINT_TYPE identifier=TASK_DEFAULT)
start the task
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
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.