15 #include "Fw/Types/BasicTypes.hpp" 
   16 #include <sys/types.h> 
   21 #include <sys/socket.h> 
   22 #include <arpa/inet.h> 
   26 #define DEBUG_PRINT(x,...) 
   36         const char *
const compName
 
   37     ) : UdpReceiverComponentBase(compName),
 
   54     UdpReceiverComponentBase::init(instance);
 
   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) {
 
  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;
 
  223   UdpReceiverComponentImpl::UdpSerialBuffer& UdpReceiverComponentImpl::UdpSerialBuffer::operator=(
const UdpReceiverComponentImpl::UdpSerialBuffer& other) {
 
  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() {