16 #include <sys/types.h>
23 #define DEBUG_PRINT(x,...)
33 const char *
const compName
34 ) : UdpSenderComponentBase(compName),
50 UdpSenderComponentBase::init(queueDepth, msgSize, instance);
56 if (this->m_fd != -1) {
69 this->m_fd = socket(AF_INET, SOCK_DGRAM, 0);
70 if (-1 == this->m_fd) {
72 this->log_WARNING_HI_US_SocketError(arg);
77 memset((
char*)&m_servAddr, 0,
sizeof(m_servAddr));
78 m_servAddr.sin_family = AF_INET;
79 m_servAddr.sin_port = htons(atoi(port));
80 inet_aton(addr , &m_servAddr.sin_addr);
83 this->log_ACTIVITY_HI_US_PortOpened(arg,atoi(port));
93 void UdpSenderComponentImpl ::
99 this->tlmWrite_US_BytesSent(this->m_bytesSent);
100 this->tlmWrite_US_PacketsSent(this->m_packetsSent);
107 void UdpSenderComponentImpl ::
114 if (-1 == this->m_fd) {
120 m_sendBuff.resetSer();
123 stat = m_sendBuff.serialize(this->m_seq++);
126 stat = m_sendBuff.serialize(
static_cast<U8>(portNum));
129 stat = m_sendBuff.serialize(Buffer);
132 DEBUG_PRINT(
"Sending %d bytes\n",m_sendBuff.getBuffLength());
133 ssize_t sendStat = sendto(this->m_fd,
134 m_sendBuff.getBuffAddr(),
135 m_sendBuff.getBuffLength(),
137 (
struct sockaddr *) &m_servAddr,
139 if (-1 == sendStat) {
141 this->log_WARNING_HI_US_SendError(arg);
143 FW_ASSERT((
int)m_sendBuff.getBuffLength() == sendStat,(
int)m_sendBuff.getBuffLength(),sendStat,portNum);
144 this->m_packetsSent++;
145 this->m_bytesSent += sendStat;
150 void UdpSenderComponentImpl::UdpSerialBuffer::operator=(
const Svc::UdpSenderComponentImpl::UdpSerialBuffer& other) {
152 this->serialize(other.getBuffAddr(),other.getBuffLength(),
true);
155 UdpSenderComponentImpl::UdpSerialBuffer::UdpSerialBuffer(
162 UdpSenderComponentImpl::UdpSerialBuffer::UdpSerialBuffer(
163 const UdpSenderComponentImpl::UdpSerialBuffer& other) :
Fw::SerializeBufferBase() {
164 FW_ASSERT(
sizeof(this->m_buff)>= other.getBuffLength(),
sizeof(this->m_buff),other.getBuffLength());
165 memcpy(this->m_buff,other.m_buff,other.getBuffLength());
166 this->setBuffLen(other.getBuffLength());
169 UdpSenderComponentImpl::UdpSerialBuffer::UdpSerialBuffer():
Fw::SerializeBufferBase() {