mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-15 05:22:53 +08:00
Bug fixes for issue #74
This commit is contained in:
parent
5b12dceb31
commit
18553022f6
@ -161,11 +161,20 @@ QIODevice *Network::openNetworkPort()
|
|||||||
m_tcpSocket.connectToHost(hostAddr, portAddr);
|
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)
|
else if (socketType() == QAbstractSocket::UdpSocket)
|
||||||
{
|
{
|
||||||
socket = &m_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
|
// Convert socket to IO device pointer
|
||||||
|
@ -90,6 +90,8 @@ public:
|
|||||||
QVector<QString> socketTypes() const;
|
QVector<QString> socketTypes() const;
|
||||||
QAbstractSocket::SocketType socketType() const;
|
QAbstractSocket::SocketType socketType() const;
|
||||||
|
|
||||||
|
QTcpSocket *tcpSocket() { return &m_tcpSocket; }
|
||||||
|
QUdpSocket *udpSocket() { return &m_udpSocket; }
|
||||||
static QString defaultHost() { return "127.0.0.1"; }
|
static QString defaultHost() { return "127.0.0.1"; }
|
||||||
static quint16 defaultPort() { return 23; }
|
static quint16 defaultPort() { return 23; }
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
#include <IO/DataSources/Serial.h>
|
#include <IO/DataSources/Serial.h>
|
||||||
#include <IO/DataSources/Network.h>
|
#include <IO/DataSources/Network.h>
|
||||||
|
|
||||||
|
#include <QNetworkDatagram>
|
||||||
|
|
||||||
using namespace IO;
|
using namespace IO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -576,8 +578,33 @@ void Manager::onDataReceived()
|
|||||||
if (!device())
|
if (!device())
|
||||||
disconnectDevice();
|
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
|
// Read data & append it to buffer
|
||||||
auto data = device()->readAll();
|
|
||||||
auto bytes = data.length();
|
auto bytes = data.length();
|
||||||
|
|
||||||
// Feed watchdog (so that data is not cleared automatically)
|
// Feed watchdog (so that data is not cleared automatically)
|
||||||
|
@ -792,7 +792,8 @@ void Dashboard::updatePlots()
|
|||||||
m_linearPlotValues.append(QVector<double>());
|
m_linearPlotValues.append(QVector<double>());
|
||||||
m_linearPlotValues.last().reserve(points());
|
m_linearPlotValues.last().reserve(points());
|
||||||
for (int j = 0; j < points(); ++j)
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user