16 #include <sys/types.h> 21 #include <sys/socket.h> 22 #include <arpa/inet.h> 33 const char *
const compName
34 ) : UdpReceiverComponentBase(compName),
49 if (this->m_fd != -1) {
59 this->m_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
60 if (-1 == this->m_fd) {
62 this->log_WARNING_HI_UR_SocketError(arg);
67 memset(&saddr, 0,
sizeof(saddr));
69 saddr.sin_family = AF_INET;
70 saddr.sin_port = htons(atoi(port));
71 saddr.sin_addr.s_addr = htonl(INADDR_ANY);
74 NATIVE_INT_TYPE status = bind(this->m_fd , (
struct sockaddr*)&saddr,
sizeof(saddr));
77 this->log_WARNING_HI_UR_BindError(arg);
81 this->log_ACTIVITY_HI_UR_PortOpened(atoi(port));
91 Os::Task::TaskStatus stat = this->m_socketTask.
start(
96 UdpReceiverComponentImpl::workerTask,
99 FW_ASSERT(Os::Task::TASK_OK == stat,stat);
107 void UdpReceiverComponentImpl ::
113 this->tlmWrite_UR_BytesReceived(this->m_bytesReceived);
114 this->tlmWrite_UR_PacketsReceived(this->m_packetsReceived);
115 this->tlmWrite_UR_PacketsDropped(this->m_packetsDropped);
118 void UdpReceiverComponentImpl::workerTask(
void* ptr) {
125 void UdpReceiverComponentImpl::doRecv() {
130 this->m_recvBuff.getBuffAddr(),
131 this->m_recvBuff.getBuffCapacity(),
136 if (errno != EINTR) {
138 this->log_WARNING_HI_UR_RecvError(arg);
148 stat = this->m_recvBuff.deserialize(seqNum);
151 this->log_WARNING_HI_UR_DecodeError(DECODE_SEQ,stat);
152 this->m_decodeErrors++;
157 if (this->m_firstSeq) {
159 this->m_currSeq = seqNum;
160 this->m_firstSeq =
false;
163 if (seqNum != ++this->m_currSeq) {
165 U8 diff = seqNum - this->m_currSeq;
166 this->m_packetsDropped += diff;
168 this->log_WARNING_HI_UR_DroppedPacket(diff);
170 this->m_currSeq = seqNum;
176 stat = this->m_recvBuff.deserialize(portNum);
179 this->log_WARNING_HI_UR_DecodeError(DECODE_PORT,stat);
180 this->m_decodeErrors++;
185 stat = this->m_recvBuff.deserialize(this->m_portBuff);
187 this->log_WARNING_HI_UR_DecodeError(DECODE_BUFFER,stat);
188 this->m_decodeErrors++;
193 if (this->isConnected_PortsOut_OutputPort(portNum)) {
200 this->log_WARNING_HI_UR_DecodeError(PORT_SEND,stat);
201 this->m_decodeErrors++;
204 this->m_packetsReceived++;
205 this->m_bytesReceived += psize;
211 UdpReceiverComponentImpl::UdpSerialBuffer& UdpReceiverComponentImpl::UdpSerialBuffer::operator=(
const UdpReceiverComponentImpl::UdpSerialBuffer& other) {
213 this->serialize(other.getBuffAddr(),other.getBuffLength(),
true);
217 UdpReceiverComponentImpl::UdpSerialBuffer::UdpSerialBuffer(
224 UdpReceiverComponentImpl::UdpSerialBuffer::UdpSerialBuffer(
225 const UdpReceiverComponentImpl::UdpSerialBuffer& other) :
Fw::SerializeBufferBase() {
226 FW_ASSERT(
sizeof(this->m_buff)>= other.getBuffLength(),
sizeof(this->m_buff),other.getBuffLength());
227 memcpy(this->m_buff,other.m_buff,other.getBuffLength());
228 this->setBuffLen(other.getBuffLength());
231 UdpReceiverComponentImpl::UdpSerialBuffer::UdpSerialBuffer():
Fw::SerializeBufferBase() {
PlatformUIntType NATIVE_UINT_TYPE
Serialization/Deserialization operation was successful.
PlatformIntType NATIVE_INT_TYPE
Status start(const Arguments &arguments) override
start the task
UdpReceiverComponentImpl(const char *const compName)
SerializeStatus
forward declaration for string
Serializable::SizeType getBuffLength() const
returns current buffer size
~UdpReceiverComponentImpl()
void open(const char *port)
Open the connection.
C++-compatible configuration header for fprime configuration.
uint8_t U8
8-bit unsigned integer
void startThread(NATIVE_UINT_TYPE priority, NATIVE_UINT_TYPE stackSize, NATIVE_UINT_TYPE affinity)
start worker thread
virtual U8 * getBuffAddr()=0
gets buffer address for data filling