Hi guys!
I have quite easy, I guess ^^, problem with modification of my code. In general it reads incomming messeges (UDP) and print them in cmd. Instead of reading them all the time, I would like to modify it to wait for new value and then display. Thanks in advance for any help!
Code:
#include "myudp.h"
{
connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
}
void MyUDP::readyRead()
{
double a[3];
double prev_a[3];
buffer.resize(socket->pendingDatagramSize());
quint16 senderPort;
socket->readDatagram(buffer.data(), buffer.size(),
&sender, &senderPort);
if(a[0] != prev_a[0] || a[1] != prev_a[1] || a[2] != prev_a[2])
{
memcpy(&a, buffer, 3*sizeof(double));
qDebug() << "\nMessage from: " << sender.toString();
qDebug() << "Message port: " << senderPort;
qDebug() << "X:" << a[0];
qDebug() << "Y:" << a[1];
qDebug() << "V:" << a[2];
}
prev_a[0] = a[0];
prev_a[1] = a[1];
prev_a[2] = a[2];
}
#include "myudp.h"
MyUDP::MyUDP(QObject *parent) :
QObject(parent)
{
socket = new QUdpSocket(this);
socket->bind(QHostAddress::LocalHost, 25000);
connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
}
void MyUDP::readyRead()
{
double a[3];
double prev_a[3];
QByteArray buffer;
buffer.resize(socket->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;
socket->readDatagram(buffer.data(), buffer.size(),
&sender, &senderPort);
if(a[0] != prev_a[0] || a[1] != prev_a[1] || a[2] != prev_a[2])
{
memcpy(&a, buffer, 3*sizeof(double));
qDebug() << "\nMessage from: " << sender.toString();
qDebug() << "Message port: " << senderPort;
qDebug() << "X:" << a[0];
qDebug() << "Y:" << a[1];
qDebug() << "V:" << a[2];
}
prev_a[0] = a[0];
prev_a[1] = a[1];
prev_a[2] = a[2];
}
To copy to clipboard, switch view to plain text mode
Bookmarks