mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-31 17:42:55 +08:00
Work on issue #90
This commit is contained in:
parent
3cd9a799f0
commit
415d934ab0
@ -90,6 +90,7 @@ Item {
|
||||
property alias udpLocalPort: network.udpLocalPort
|
||||
property alias udpRemotePort: network.udpRemotePort
|
||||
property alias udpMulticastEnabled: network.udpMulticastEnabled
|
||||
property alias udpProcessDatagramsDirectly: network.udpProcessDatagramsDirectly
|
||||
|
||||
//
|
||||
// MQTT settings
|
||||
|
@ -37,6 +37,7 @@ Control {
|
||||
property alias udpRemotePort: _udpRemotePort.text
|
||||
property alias socketType: _typeCombo.currentIndex
|
||||
property alias udpMulticastEnabled: _udpMulticast.checked
|
||||
property alias udpProcessDatagramsDirectly: _udpProcessDatagrams.checked
|
||||
|
||||
//
|
||||
// Signals
|
||||
@ -241,6 +242,30 @@ Control {
|
||||
root.uiChanged()
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// UDP multicast checkbox
|
||||
//
|
||||
Label {
|
||||
text: qsTr("Each datagram is a frame") + ":"
|
||||
opacity: _udpProcessDatagrams.enabled ? 1 : 0.5
|
||||
visible: Cpp_IO_Network.socketTypeIndex === 1
|
||||
} CheckBox {
|
||||
id: _udpProcessDatagrams
|
||||
opacity: enabled ? 1 : 0.5
|
||||
Layout.alignment: Qt.AlignLeft
|
||||
Layout.leftMargin: -app.spacing
|
||||
checked: Cpp_IO_Network.udpIgnoreFrameSequences
|
||||
visible: Cpp_IO_Network.socketTypeIndex === 1
|
||||
enabled: Cpp_IO_Network.socketTypeIndex === 1 && !Cpp_IO_Manager.connected
|
||||
|
||||
onCheckedChanged: {
|
||||
if (Cpp_IO_Network.udpIgnoreFrameSequences !== checked)
|
||||
Cpp_IO_Network.udpIgnoreFrameSequences = checked
|
||||
|
||||
root.uiChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -31,6 +31,7 @@ IO::DataSources::Network::Network()
|
||||
: m_hostExists(false)
|
||||
, m_udpMulticast(false)
|
||||
, m_lookupActive(false)
|
||||
, m_udpIgnoreFrameSequences(false)
|
||||
{
|
||||
setRemoteAddress("");
|
||||
setTcpPort(defaultTcpPort());
|
||||
@ -155,6 +156,15 @@ StringList IO::DataSources::Network::socketTypes() const
|
||||
return StringList { "TCP", "UDP" };
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns @c true if the @c IO::Manager should not check for start/end
|
||||
* frame sequences when an UDP datagram is received.
|
||||
*/
|
||||
bool IO::DataSources::Network::udpIgnoreFrameSequences() const
|
||||
{
|
||||
return m_udpIgnoreFrameSequences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the socket type. Valid return values are:
|
||||
*
|
||||
@ -288,6 +298,19 @@ void IO::DataSources::Network::setRemoteAddress(const QString &address)
|
||||
Q_EMIT addressChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* If @a ignore is set to @c true, then the @c IO::Manager should not check
|
||||
* for start/end frame sequences when an UDP datagram is received.
|
||||
*
|
||||
* Otherwise, the @c IO::Manager shall check for start/end sequences to identify
|
||||
* incoming frames.
|
||||
*/
|
||||
void IO::DataSources::Network::setUdpIgnoreFrameSequences(const bool ignore)
|
||||
{
|
||||
m_udpIgnoreFrameSequences = ignore;
|
||||
Q_EMIT udpIgnoreFrameSequencesChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a DNS lookup for the given @a host name
|
||||
*/
|
||||
|
@ -90,6 +90,10 @@ class Network : public QObject
|
||||
READ udpMulticast
|
||||
WRITE setUdpMulticast
|
||||
NOTIFY udpMulticastChanged)
|
||||
Q_PROPERTY(bool udpIgnoreFrameSequences
|
||||
READ udpIgnoreFrameSequences
|
||||
WRITE setUdpIgnoreFrameSequences
|
||||
NOTIFY udpIgnoreFrameSequencesChanged)
|
||||
// clang-format on
|
||||
|
||||
Q_SIGNALS:
|
||||
@ -98,6 +102,7 @@ Q_SIGNALS:
|
||||
void socketTypeChanged();
|
||||
void udpMulticastChanged();
|
||||
void lookupActiveChanged();
|
||||
void udpIgnoreFrameSequencesChanged();
|
||||
|
||||
private:
|
||||
explicit Network();
|
||||
@ -122,6 +127,7 @@ public:
|
||||
int socketTypeIndex() const;
|
||||
bool configurationOk() const;
|
||||
StringList socketTypes() const;
|
||||
bool udpIgnoreFrameSequences() const;
|
||||
QAbstractSocket::SocketType socketType() const;
|
||||
|
||||
QTcpSocket *tcpSocket() { return &m_tcpSocket; }
|
||||
@ -145,6 +151,7 @@ public Q_SLOTS:
|
||||
void setSocketTypeIndex(const int index);
|
||||
void setUdpRemotePort(const quint16 port);
|
||||
void setRemoteAddress(const QString &address);
|
||||
void setUdpIgnoreFrameSequences(const bool ignore);
|
||||
void setSocketType(const QAbstractSocket::SocketType type);
|
||||
|
||||
private Q_SLOTS:
|
||||
@ -159,6 +166,7 @@ private:
|
||||
bool m_lookupActive;
|
||||
quint16 m_udpLocalPort;
|
||||
quint16 m_udpRemotePort;
|
||||
bool m_udpIgnoreFrameSequences;
|
||||
QAbstractSocket::SocketType m_socketType;
|
||||
|
||||
QTcpSocket m_tcpSocket;
|
||||
|
@ -514,10 +514,18 @@ void IO::Manager::onDataReceived()
|
||||
auto udpSocket = DataSources::Network::instance().udpSocket();
|
||||
while (udpSocket->hasPendingDatagrams())
|
||||
{
|
||||
// Read datagram data
|
||||
QByteArray datagram;
|
||||
datagram.resize(int(udpSocket->pendingDatagramSize()));
|
||||
udpSocket->readDatagram(datagram.data(), datagram.size());
|
||||
data.append(datagram);
|
||||
|
||||
// Add datagram to data buffer
|
||||
if (!DataSources::Network::instance().udpIgnoreFrameSequences())
|
||||
data.append(datagram);
|
||||
|
||||
// Ingore start/end sequences & process frame directly
|
||||
else
|
||||
processPayload(datagram);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user