Bug fixes for issue #74

This commit is contained in:
Alex Spataru 2021-10-07 23:24:56 -05:00
parent 5b12dceb31
commit 18553022f6
4 changed files with 43 additions and 4 deletions

View File

@ -161,11 +161,20 @@ QIODevice *Network::openNetworkPort()
m_tcpSocket.connectToHost(hostAddr, portAddr);
}
// UDP connection, assign socket pointer & connect to host
// UDP connection, assign socket pointer & bind to host
else if (socketType() == QAbstractSocket::UdpSocket)
{
socket = &m_udpSocket;
m_udpSocket.connectToHost(hostAddr, portAddr);
QHostAddress address(hostAddr);
if (address.protocol() == QAbstractSocket::IPv4Protocol)
m_udpSocket.bind(QHostAddress::AnyIPv4, portAddr, QUdpSocket::ShareAddress);
else if (address.protocol() == QAbstractSocket::IPv6Protocol)
m_udpSocket.bind(QHostAddress::AnyIPv6, portAddr, QUdpSocket::ShareAddress);
else
m_udpSocket.bind(QHostAddress::Any, portAddr, QUdpSocket::ShareAddress);
m_udpSocket.joinMulticastGroup(address);
}
// Convert socket to IO device pointer

View File

@ -90,6 +90,8 @@ public:
QVector<QString> socketTypes() const;
QAbstractSocket::SocketType socketType() const;
QTcpSocket *tcpSocket() { return &m_tcpSocket; }
QUdpSocket *udpSocket() { return &m_udpSocket; }
static QString defaultHost() { return "127.0.0.1"; }
static quint16 defaultPort() { return 23; }

View File

@ -28,6 +28,8 @@
#include <IO/DataSources/Serial.h>
#include <IO/DataSources/Network.h>
#include <QNetworkDatagram>
using namespace IO;
/**
@ -576,8 +578,33 @@ void Manager::onDataReceived()
if (!device())
disconnectDevice();
// Initialize byte array
QByteArray data;
bool udpConnection = false;
// Check if we need to use UDP socket functions
if (dataSource() == DataSource::Network)
{
auto network = DataSources::Network::getInstance();
if (network->socketType() == QAbstractSocket::UdpSocket)
{
udpConnection = true;
auto udpSocket = network->udpSocket();
while (udpSocket->hasPendingDatagrams())
{
QByteArray datagram;
datagram.resize(int(udpSocket->pendingDatagramSize()));
udpSocket->readDatagram(datagram.data(), datagram.size());
data.append(datagram);
}
}
}
// We are using the TCP socket or the serial port
if (!udpConnection)
data = device()->readAll();
// Read data & append it to buffer
auto data = device()->readAll();
auto bytes = data.length();
// Feed watchdog (so that data is not cleared automatically)

View File

@ -792,7 +792,8 @@ void Dashboard::updatePlots()
m_linearPlotValues.append(QVector<double>());
m_linearPlotValues.last().reserve(points());
for (int j = 0; j < points(); ++j)
m_linearPlotValues[i].append(0.0001); // to avoid issues with log plots
m_linearPlotValues[i].append(
0.0001); // to avoid issues with log plots
}
}