Commit 6caef012 authored by Lorenz Meier's avatar Lorenz Meier

Merge pull request #437 from Susurrus/simpleCheckRates

Add display of the upstream data rate to the Debug Console
parents 17883dbb 03e904d5
......@@ -73,7 +73,7 @@ public:
/* Connection characteristics */
/**
* @Brief Get the nominal data rate of the interface.
* @Brief Get the maximum connection speed for this interface.
*
* The nominal data rate is the theoretical maximum data rate of the
* interface. For 100Base-T Ethernet this would be 100 Mbit/s (100'000'000
......@@ -81,7 +81,27 @@ public:
*
* @return The nominal data rate of the interface in bit per second, 0 if unknown
**/
virtual qint64 getNominalDataRate() const = 0;
virtual qint64 getConnectionSpeed() const = 0;
/**
* @Brief Get the current incoming data rate.
*
* This should be over a short timespan, something like 100ms. A precise value isn't necessary,
* and this can be filtered, but should be a reasonable estimate of current data rate.
*
* @return The data rate of the interface in bits per second, 0 if unknown
**/
virtual qint64 getCurrentInDataRate() const = 0;
/**
* @Brief Get the current outgoing data rate.
*
* This should be over a short timespan, something like 100ms. A precise value isn't necessary,
* and this can be filtered, but should be a reasonable estimate of current data rate.
*
* @return The data rate of the interface in bits per second, 0 if unknown
**/
virtual qint64 getCurrentOutDataRate() const = 0;
/**
* @brief Connect this interface logically
......
......@@ -1000,8 +1000,18 @@ QString MAVLinkSimulationLink::getName() const
return name;
}
qint64 MAVLinkSimulationLink::getNominalDataRate() const
qint64 MAVLinkSimulationLink::getConnectionSpeed() const
{
/* 100 Mbit is reasonable fast and sufficient for all embedded applications */
return 100000000;
}
\ No newline at end of file
}
qint64 MAVLinkSimulationLink::getCurrentInDataRate() const
{
return 0;
}
qint64 MAVLinkSimulationLink::getCurrentOutDataRate() const
{
return 0;
}
......@@ -58,8 +58,10 @@ public:
bool connect();
bool disconnect();
/* Extensive statistics for scientific purposes */
qint64 getNominalDataRate() const;
// Extensive statistics for scientific purposes
qint64 getConnectionSpeed() const;
qint64 getCurrentInDataRate() const;
qint64 getCurrentOutDataRate() const;
QString getName() const;
int getId() const;
......
......@@ -496,16 +496,18 @@ bool OpalLink::disconnect()
return true;
}
// Data rate functions
qint64 OpalLink::getConnectionSpeed() const
{
return 0; //unknown
}
qint64 OpalLink::getCurrentInDataRate() const
{
return 0;
}
/*
*
Statisctics
*
*/
qint64 OpalLink::getNominalDataRate() const
qint64 OpalLink::getCurrentOutDataRate() const
{
return 0; //unknown
}
\ No newline at end of file
return 0;
}
......@@ -75,10 +75,9 @@ public:
QString getName() const;
bool isConnected() const;
/* Connection characteristics */
qint64 getNominalDataRate() const;
qint64 getConnectionSpeed() const;
qint64 getCurrentInDataRate() const;
qint64 getCurrentOutDataRate() const;
bool connect();
......
This diff is collapsed.
......@@ -68,6 +68,10 @@ public:
static const int poll_interval = SERIAL_POLL_INTERVAL; ///< Polling interval, defined in configuration.h
static const int buffer_size = 20; ///< Specify how many data points to capture for data rate calculations.
static const qint64 stats_timespan = 500; ///< Set the maximum age of samples to use for data calculations (ms).
/** @brief Get a list of the currently available ports */
QList<QString> getCurrentPorts();
......@@ -95,8 +99,9 @@ public:
int getDataBitsType() const;
int getStopBitsType() const;
/* Extensive statistics for scientific purposes */
qint64 getNominalDataRate() const;
qint64 getConnectionSpeed() const;
qint64 getCurrentInDataRate() const;
qint64 getCurrentOutDataRate() const;
void loadSettings();
void writeSettings();
......@@ -147,19 +152,45 @@ protected:
int m_stopBits;
int m_parity;
QString m_portName;
// QString m_name;
int m_timeout;
int m_id;
QMutex m_dataMutex;
QMutex m_writeMutex;
// Implement a simple circular buffer for storing when and how much data was received.
// Used for calculating the incoming data rate. Use with *StatsBuffer() functions.
int inDataIndex;
quint64 inDataWriteAmounts[buffer_size]; // In bytes
qint64 inDataWriteTimes[buffer_size]; // in ms
// Implement a simple circular buffer for storing when and how much data was transmit.
// Used for calculating the outgoing data rate. Use with *StatsBuffer() functions.
int outDataIndex;
quint64 outDataWriteAmounts[buffer_size]; // In bytes
qint64 outDataWriteTimes[buffer_size]; // in ms
quint64 m_connectionStartTime; // Connection start time (ms since epoch)
mutable QMutex m_statisticsMutex; // Mutex for accessing the statistics member variables (inData*,outData*,bitsSent,bitsReceived)
QMutex m_dataMutex; // Mutex for reading data from m_port
QMutex m_writeMutex; // Mutex for accessing the m_transmitBuffer.
QList<QString> m_ports;
private:
/**
* @brief WriteDataStatsBuffer Stores transmission times/amounts for statistics
*
* This function logs the send times and amounts of datas to the given circular buffers.
* This data is used for calculating the transmission rate.
*
* @param bytesBuffer The buffer to write the bytes value into.
* @param timeBuffer The buffer to write the time value into
* @param writeIndex The write index used for this buffer.
* @param bytes The amount of bytes transmit.
* @param time The time (in ms) this transmission occurred.
*/
void WriteDataStatsBuffer(quint64 *bytesBuffer, qint64 *timeBuffer, int *writeIndex, quint64 bytes, qint64 time);
volatile bool m_stopp;
volatile bool m_reqReset;
QMutex m_stoppMutex;
QByteArray m_transmitBuffer;
QMutex m_stoppMutex; // Mutex for accessing m_stopp
QByteArray m_transmitBuffer; // An internal buffer for receiving data from member functions and actually transmitting them via the serial port.
bool hardwareConnect();
......
......@@ -262,7 +262,17 @@ void TCPLink::setName(QString name)
}
qint64 TCPLink::getNominalDataRate() const
qint64 TCPLink::getConnectionSpeed() const
{
return 54000000; // 54 Mbit
}
\ No newline at end of file
}
qint64 TCPLink::getCurrentInDataRate() const
{
return 0;
}
qint64 TCPLink::getCurrentOutDataRate() const
{
return 0;
}
......@@ -68,9 +68,11 @@ public:
int getParityType() const;
int getDataBitsType() const;
int getStopBitsType() const;
/* Extensive statistics for scientific purposes */
qint64 getNominalDataRate() const;
// Extensive statistics for scientific purposes
qint64 getConnectionSpeed() const;
qint64 getCurrentInDataRate() const;
qint64 getCurrentOutDataRate() const;
void run();
......
......@@ -376,7 +376,17 @@ void UDPLink::setName(QString name)
}
qint64 UDPLink::getNominalDataRate() const
qint64 UDPLink::getConnectionSpeed() const
{
return 54000000; // 54 Mbit
}
\ No newline at end of file
}
qint64 UDPLink::getCurrentInDataRate() const
{
return 0;
}
qint64 UDPLink::getCurrentOutDataRate() const
{
return 0;
}
......@@ -71,8 +71,10 @@ public:
return hosts;
}
/* Extensive statistics for scientific purposes */
qint64 getNominalDataRate() const;
// Extensive statistics for scientific purposes
qint64 getConnectionSpeed() const;
qint64 getCurrentInDataRate() const;
qint64 getCurrentOutDataRate() const;
void run();
......
......@@ -119,10 +119,21 @@ bool XbeeLink::isConnected() const
return this->m_connected;
}
qint64 XbeeLink::getNominalDataRate() const
qint64 XbeeLink::getConnectionSpeed() const
{
return this->m_baudRate;
}
qint64 XbeeLink::getCurrentInDataRate() const
{
return 0;
}
qint64 XbeeLink::getCurrentOutDataRate() const
{
return 0;
}
bool XbeeLink::hardwareConnect()
{
emit tryConnectBegin(true);
......@@ -245,4 +256,4 @@ void CALLTYPE XbeeLink::portCallback(xbee_con *xbeeCon, xbee_pkt *XbeePkt)
buf.push_back(XbeePkt->data[i]);
}
emit bytesReceived(this, buf);
}*/
\ No newline at end of file
}*/
......@@ -34,11 +34,15 @@ public: // virtual functions from LinkInterface
int getId() const;
QString getName() const;
bool isConnected() const;
qint64 getNominalDataRate() const;
bool connect();
bool disconnect();
qint64 bytesAvailable();
// Extensive statistics for scientific purposes
qint64 getConnectionSpeed() const;
qint64 getCurrentOutDataRate() const;
qint64 getCurrentInDataRate() const;
public slots: // virtual functions from LinkInterface
void writeBytes(const char *bytes, qint64 length);
......
This diff is collapsed.
......@@ -137,11 +137,10 @@ protected:
quint64 lastLineBuffer; ///< Last line buffer emission time
QTimer lineBufferTimer; ///< Line buffer timer
QTimer snapShotTimer; ///< Timer for measuring traffic snapshots
int snapShotInterval; ///< Snapshot interval for traffic measurements
int snapShotBytes; ///< Number of bytes received in current snapshot
float dataRate; ///< Current data rate
float lowpassDataRate; ///< Lowpass filtered data rate
float dataRateThreshold; ///< Threshold where to enable auto-hold
static const int snapShotInterval = 500; ///< Set the time between UI updates for the data rate (ms)
float lowpassInDataRate; ///< Lowpass filtered data rate (kilobytes/s)
static const float inDataRateThreshold = 0.4; ///< Threshold where to enable auto-hold (kilobytes/s)
float lowpassOutDataRate; ///< Low-pass filtered outgoing data rate (kilobytes/s)
QStringList commandHistory;
QString currCommand;
int commandIndex;
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>566</width>
<height>190</height>
<width>570</width>
<height>211</height>
</rect>
</property>
<property name="windowTitle">
......@@ -24,7 +24,7 @@
<number>6</number>
</property>
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="10,0,0,0,0,0">
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="10,0,0,0,0,0,0,0,0">
<item>
<widget class="QComboBox" name="linkComboBox">
<property name="maximumSize">
......@@ -39,9 +39,75 @@
</widget>
</item>
<item>
<widget class="QLabel" name="speedLabel">
<widget class="QLabel" name="downArrow">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>12</width>
<height>16</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>12</width>
<height>16</height>
</size>
</property>
<property name="baseSize">
<size>
<width>12</width>
<height>16</height>
</size>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../../qgroundcontrol.qrc">:/files/images/actions/go-down.svg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="downSpeedLabel">
<property name="text">
<string>00.0 kB/s</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="upArrow">
<property name="maximumSize">
<size>
<width>12</width>
<height>16</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../../qgroundcontrol.qrc">:/files/images/actions/go-up.svg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="upSpeedLabel">
<property name="text">
<string>0.0 kB/s</string>
<string>00.0 kB/s</string>
</property>
</widget>
</item>
......
......@@ -204,7 +204,7 @@ void APMToolBar::updateLinkDisplay(LinkInterface* newLink)
QObject *object = rootObject();
if (newLink && object){
qint64 baudrate = newLink->getNominalDataRate();
qint64 baudrate = newLink->getConnectionSpeed();
object->setProperty("baudrateLabel", QString::number(baudrate));
QString linkName = newLink->getName();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment