Browse Source

Send probe datas on a new port

pull/1/head
miladS 1 year ago
parent
commit
e0849692f4
  1. 2
      logic/include/model/DataSender.h
  2. 5
      logic/include/network/UdpDataSender.h
  3. 36
      logic/src/network/UdpDataSender.cpp

2
logic/include/model/DataSender.h

@ -10,12 +10,14 @@ class DataSender : public QObject
public:
virtual void send(const QByteArray& data) = 0;
virtual void sendProbeSlots(const QByteArray& data) = 0;
virtual ~DataSender()
{
}
signals:
void dataReady(const QByteArray& data);
void probeSlotsDataReady(const QByteArray& data);
};
#endif //DATASENDER_H

5
logic/include/network/UdpDataSender.h

@ -10,18 +10,21 @@ class UdpDataSender : public DataSender
Q_OBJECT
private:
QUdpSocket* _socket;
QUdpSocket* _socketDashboard;
QUdpSocket* _socketProbeSlots;
public:
UdpDataSender();
~UdpDataSender() override;
void send(const QByteArray& data) override;
void sendProbeSlots(const QByteArray& data) override;
//uncrustify off
public slots:
//uncrustify on
void read();
void readProbeSlots();
};
#endif //UDPDATASENDER_H

36
logic/src/network/UdpDataSender.cpp

@ -4,31 +4,51 @@
void UdpDataSender::send(const QByteArray& data)
{
_socket->writeDatagram(data, QHostAddress::LocalHost, 5446);
_socketDashboard->writeDatagram(data, QHostAddress::LocalHost, 5446);
}
/*************************************************************************************************/
void UdpDataSender::sendProbeSlots(const QByteArray& data)
{
_socketProbeSlots->writeDatagram(data, QHostAddress::LocalHost, 5450);
}
/*************************************************************************************************/
void UdpDataSender::read()
{
char data[DATAGRAM_SIZE];
int cnt = _socket->readDatagram(data, DATAGRAM_SIZE);
int cnt = _socketDashboard->readDatagram(data, DATAGRAM_SIZE);
QByteArray a(data, cnt);
emit dataReady(a);
}
/*************************************************************************************************/
UdpDataSender::UdpDataSender()
void UdpDataSender::readProbeSlots()
{
_socket = new QUdpSocket();
char data[DATAGRAM_SIZE];
int cnt = _socketProbeSlots->readDatagram(data, DATAGRAM_SIZE);
QByteArray a(data, cnt);
emit probeSlotsDataReady(a);
}
_socket->bind(QHostAddress::Any, 5445);
/*************************************************************************************************/
UdpDataSender::UdpDataSender()
{
_socketDashboard = new QUdpSocket();
_socketDashboard->bind(QHostAddress::Any, 5445);
connect(_socketDashboard, SIGNAL(readyRead()), this, SLOT(read()));
connect(_socket, SIGNAL(readyRead()), this, SLOT(read()));
_socketProbeSlots = new QUdpSocket();
_socketProbeSlots->bind(QHostAddress::Any, 5449);
connect(_socketProbeSlots, SIGNAL(readyRead()), this, SLOT(readProbeSlots()));
}
/*************************************************************************************************/
UdpDataSender::~UdpDataSender()
{
_socket->close();
delete _socket;
_socketDashboard->close();
delete _socketDashboard;
_socketProbeSlots->close();
delete _socketProbeSlots;
}

Loading…
Cancel
Save