16 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <arpa/inet.h>
26 #define DEBUG_PRINT(...)
36 const char *
const compName
37 ) : UdpReceiverComponentBase(compName),
52 if (this->m_fd != -1) {
62 this->m_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
63 if (-1 == this->m_fd) {
65 this->log_WARNING_HI_UR_SocketError(arg);
70 memset(&saddr, 0,
sizeof(saddr));
72 saddr.sin_family = AF_INET;
73 saddr.sin_port = htons(atoi(port));
74 saddr.sin_addr.s_addr = htonl(INADDR_ANY);
77 NATIVE_INT_TYPE status = bind(this->m_fd , (
struct sockaddr*)&saddr,
sizeof(saddr));
80 this->log_WARNING_HI_UR_BindError(arg);
84 this->log_ACTIVITY_HI_UR_PortOpened(atoi(port));
94 Os::Task::TaskStatus stat = this->m_socketTask.
start(
99 UdpReceiverComponentImpl::workerTask,
102 FW_ASSERT(Os::Task::TASK_OK == stat,stat);
110 void UdpReceiverComponentImpl ::
116 this->tlmWrite_UR_BytesReceived(this->m_bytesReceived);
117 this->tlmWrite_UR_PacketsReceived(this->m_packetsReceived);
118 this->tlmWrite_UR_PacketsDropped(this->m_packetsDropped);
121 void UdpReceiverComponentImpl::workerTask(
void* ptr) {
128 void UdpReceiverComponentImpl::doRecv() {
133 this->m_recvBuff.getBuffAddr(),
134 this->m_recvBuff.getBuffCapacity(),
139 if (errno != EINTR) {
141 this->log_WARNING_HI_UR_RecvError(arg);
151 stat = this->m_recvBuff.deserialize(seqNum);
154 this->log_WARNING_HI_UR_DecodeError(DECODE_SEQ,stat);
155 this->m_decodeErrors++;
160 if (this->m_firstSeq) {
162 this->m_currSeq = seqNum;
163 this->m_firstSeq =
false;
166 if (seqNum != ++this->m_currSeq) {
168 U8 diff = seqNum - this->m_currSeq;
169 this->m_packetsDropped += diff;
171 this->log_WARNING_HI_UR_DroppedPacket(diff);
173 this->m_currSeq = seqNum;
179 stat = this->m_recvBuff.deserialize(portNum);
182 this->log_WARNING_HI_UR_DecodeError(DECODE_PORT,stat);
183 this->m_decodeErrors++;
188 stat = this->m_recvBuff.deserialize(this->m_portBuff);
190 this->log_WARNING_HI_UR_DecodeError(DECODE_BUFFER,stat);
191 this->m_decodeErrors++;
196 DEBUG_PRINT(
"Calling port %d with %d bytes.\n",portNum,this->m_portBuff.getBuffLength());
197 if (this->isConnected_PortsOut_OutputPort(portNum)) {
204 this->log_WARNING_HI_UR_DecodeError(PORT_SEND,stat);
205 this->m_decodeErrors++;
208 this->m_packetsReceived++;
209 this->m_bytesReceived += psize;
215 UdpReceiverComponentImpl::UdpSerialBuffer& UdpReceiverComponentImpl::UdpSerialBuffer::operator=(
const UdpReceiverComponentImpl::UdpSerialBuffer& other) {
217 this->serialize(other.getBuffAddr(),other.getBuffLength(),
true);
221 UdpReceiverComponentImpl::UdpSerialBuffer::UdpSerialBuffer(
228 UdpReceiverComponentImpl::UdpSerialBuffer::UdpSerialBuffer(
229 const UdpReceiverComponentImpl::UdpSerialBuffer& other) :
Fw::SerializeBufferBase() {
230 FW_ASSERT(
sizeof(this->m_buff)>= other.getBuffLength(),
sizeof(this->m_buff),other.getBuffLength());
231 memcpy(this->m_buff,other.m_buff,other.getBuffLength());
232 this->setBuffLen(other.getBuffLength());
235 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.
virtual U8 * getBuffAddr()=0
gets buffer address for data filling
Serializable::SizeType getBuffLength() const
returns current buffer size
Status start(const Arguments &arguments) override
start the task
~UdpReceiverComponentImpl()
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
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.