16 #include <sys/types.h>
23 #define DEBUG_PRINT(...)
33 const char *
const compName
34 ) : UdpSenderComponentBase(compName),
46 if (this->m_fd != -1) {
59 this->m_fd = socket(AF_INET, SOCK_DGRAM, 0);
60 if (-1 == this->m_fd) {
62 this->log_WARNING_HI_US_SocketError(arg);
67 memset(&m_servAddr, 0,
sizeof(m_servAddr));
68 m_servAddr.sin_family = AF_INET;
69 m_servAddr.sin_port = htons(atoi(port));
70 inet_aton(addr , &m_servAddr.sin_addr);
73 this->log_ACTIVITY_HI_US_PortOpened(arg,atoi(port));
83 void UdpSenderComponentImpl ::
89 this->tlmWrite_US_BytesSent(this->m_bytesSent);
90 this->tlmWrite_US_PacketsSent(this->m_packetsSent);
97 void UdpSenderComponentImpl ::
104 if (-1 == this->m_fd) {
110 m_sendBuff.resetSer();
113 stat = m_sendBuff.serialize(this->m_seq++);
116 stat = m_sendBuff.serialize(
static_cast<U8>(portNum));
119 stat = m_sendBuff.serialize(Buffer);
122 DEBUG_PRINT(
"Sending %d bytes\n",m_sendBuff.getBuffLength());
123 ssize_t sendStat = sendto(this->m_fd,
124 m_sendBuff.getBuffAddr(),
125 m_sendBuff.getBuffLength(),
127 reinterpret_cast<struct sockaddr *
>(&m_servAddr),
129 if (-1 == sendStat) {
131 this->log_WARNING_HI_US_SendError(arg);
133 FW_ASSERT((
int)m_sendBuff.getBuffLength() == sendStat,(
int)m_sendBuff.getBuffLength(),sendStat,portNum);
134 this->m_packetsSent++;
135 this->m_bytesSent += sendStat;
140 UdpSerialBuffer& UdpSenderComponentImpl::UdpSerialBuffer::operator=(
const Svc::UdpSenderComponentImpl::UdpSerialBuffer& other) {
142 this->serialize(other.getBuffAddr(),other.getBuffLength(),
true);
146 UdpSenderComponentImpl::UdpSerialBuffer::UdpSerialBuffer(
153 UdpSenderComponentImpl::UdpSerialBuffer::UdpSerialBuffer(
154 const UdpSenderComponentImpl::UdpSerialBuffer& other) :
Fw::SerializeBufferBase() {
155 FW_ASSERT(
sizeof(this->m_buff)>= other.getBuffLength(),
sizeof(this->m_buff),other.getBuffLength());
156 memcpy(this->m_buff,other.m_buff,other.getBuffLength());
157 this->setBuffLen(other.getBuffLength());
160 UdpSenderComponentImpl::UdpSerialBuffer::UdpSerialBuffer():
Fw::SerializeBufferBase() {
PlatformIntType NATIVE_INT_TYPE
uint8_t U8
8-bit unsigned integer
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
UdpSenderComponentImpl(const char *const compName)
void open(const char *addr, const char *port)
~UdpSenderComponentImpl()
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.