mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-15 05:22:53 +08:00
Remove unnecessary checks
This commit is contained in:
parent
700a69d9fe
commit
c5a651a8b7
@ -27,46 +27,13 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines a JSON frame information structure. We need to use this in order to be able
|
|
||||||
* to correctly process all received frames in a thread-worker manner.
|
|
||||||
*
|
|
||||||
* Every time we receive a frame from the serial/network device, we generate the JSON
|
|
||||||
* in another thread in order to avoid putting excessive pressure in the GUI thread.
|
|
||||||
*
|
|
||||||
* This results in a perceived increase of application performance. However, since each
|
|
||||||
* JSON frame is generated in a different worker thread, the main thread may not receive
|
|
||||||
* JSON data in the correct order.
|
|
||||||
*
|
|
||||||
* To mitigate this, we create this structure, which contains the following information:
|
|
||||||
* - Frame number (assigned by the JSON::Generator class when raw frame data is
|
|
||||||
* received, and before the JSON object is genereated/parsed).
|
|
||||||
* - RX date/time (assigned in the same manner as the frame number).
|
|
||||||
* - JSON document/object (which contains all the frame information + what we should
|
|
||||||
* do with it).
|
|
||||||
*
|
|
||||||
* We need to register the frame number because (in some cases), the RX date/time will be
|
|
||||||
* the same between two or more frames (e.g. if you have a very high baud rate, there is
|
|
||||||
* a chance that frames will be registered with the same rx date/time down to the
|
|
||||||
* millisecond, this was the root cause of bug #35).
|
|
||||||
*
|
|
||||||
* To mitigate this, we simply increment the frame number each time that we receive a raw
|
|
||||||
* frame. Frame numbers are registered as a uint64_t for this very reason (it would take
|
|
||||||
* about 585 years to overflow this variable, if you had a computer that was able to
|
|
||||||
* process a frame every nanosecond).
|
|
||||||
*
|
|
||||||
* Frame number is reset when the device connection state is changed.
|
|
||||||
*/
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
quint64 frameNumber;
|
quint64 frameNumber;
|
||||||
QDateTime rxDateTime;
|
QDateTime rxDateTime;
|
||||||
QJsonDocument jsonDocument;
|
QJsonDocument jsonDocument;
|
||||||
} JFI_Object;
|
} JFI_Object;
|
||||||
|
Q_DECLARE_METATYPE(JFI_Object)
|
||||||
//----------------------------------------------------------------------------------------
|
|
||||||
// Convenience functions
|
|
||||||
//----------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
extern bool JFI_Valid(const JFI_Object &info);
|
extern bool JFI_Valid(const JFI_Object &info);
|
||||||
extern void JFI_SortList(QList<JFI_Object> *list);
|
extern void JFI_SortList(QList<JFI_Object> *list);
|
||||||
@ -75,9 +42,4 @@ extern JFI_Object JFI_Empty(const quint64 n = 0);
|
|||||||
extern JFI_Object JFI_CreateNew(const quint64 n, const QDateTime &t,
|
extern JFI_Object JFI_CreateNew(const quint64 n, const QDateTime &t,
|
||||||
const QJsonDocument &d);
|
const QJsonDocument &d);
|
||||||
|
|
||||||
/*
|
|
||||||
* Important magic to be able to use JFI structures in Qt signals/slots
|
|
||||||
*/
|
|
||||||
Q_DECLARE_METATYPE(JFI_Object)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -217,36 +217,13 @@ void Generator::writeSettings(const QString &path)
|
|||||||
m_settings.setValue("json_map_location", path);
|
m_settings.setValue("json_map_location", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Notifies the rest of the application that a new JSON frame has been received. The JFI
|
|
||||||
* also contains RX date/time and frame number.
|
|
||||||
*
|
|
||||||
* Read the "FrameInfo.h" file for more information.
|
|
||||||
*/
|
|
||||||
void Generator::loadJFI(const JFI_Object &info)
|
|
||||||
{
|
|
||||||
bool csvOpen = CSV::Player::getInstance()->isOpen();
|
|
||||||
bool devOpen = IO::Manager::getInstance()->connected();
|
|
||||||
bool mqttSub = MQTT::Client::getInstance()->isSubscribed();
|
|
||||||
|
|
||||||
if (csvOpen || devOpen || mqttSub)
|
|
||||||
{
|
|
||||||
if (JFI_Valid(info))
|
|
||||||
emit jsonChanged(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new JFI event with the given @a JSON document and increment the frame count
|
* Create a new JFI event with the given @a JSON document and increment the frame count
|
||||||
*/
|
*/
|
||||||
void Generator::loadJSON(const QJsonDocument &json)
|
void Generator::loadJSON(const QJsonDocument &json)
|
||||||
{
|
{
|
||||||
auto jfi = JFI_CreateNew(m_frameCount, QDateTime::currentDateTime(), json);
|
|
||||||
m_frameCount++;
|
m_frameCount++;
|
||||||
loadJFI(jfi);
|
emit jsonChanged(JFI_CreateNew(m_frameCount, QDateTime::currentDateTime(), json));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -362,5 +339,5 @@ void Generator::processFrame(const QByteArray &data, const quint64 frame,
|
|||||||
|
|
||||||
// No parse error, update UI & reset error counter
|
// No parse error, update UI & reset error counter
|
||||||
if (error.error == QJsonParseError::NoError)
|
if (error.error == QJsonParseError::NoError)
|
||||||
loadJFI(JFI_CreateNew(frame, time, document));
|
emit jsonChanged(JFI_CreateNew(frame, time, document));
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,6 @@ private:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void readSettings();
|
void readSettings();
|
||||||
void loadJFI(const JFI_Object &info);
|
|
||||||
void writeSettings(const QString &path);
|
void writeSettings(const QString &path);
|
||||||
void loadJSON(const QJsonDocument &json);
|
void loadJSON(const QJsonDocument &json);
|
||||||
|
|
||||||
|
@ -140,8 +140,5 @@ void DataProvider::selectLatestJSON(const JFI_Object &frameInfo)
|
|||||||
auto currFrameCount = m_latestJsonFrame.frameNumber;
|
auto currFrameCount = m_latestJsonFrame.frameNumber;
|
||||||
|
|
||||||
if (currFrameCount < frameCount)
|
if (currFrameCount < frameCount)
|
||||||
{
|
m_latestJsonFrame = frameInfo;
|
||||||
if (JFI_Valid(frameInfo))
|
|
||||||
m_latestJsonFrame = frameInfo;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -386,6 +386,5 @@ void GraphProvider::updateGraph(QAbstractSeries *series, const int index)
|
|||||||
*/
|
*/
|
||||||
void GraphProvider::registerFrame(const JFI_Object &frameInfo)
|
void GraphProvider::registerFrame(const JFI_Object &frameInfo)
|
||||||
{
|
{
|
||||||
if (JFI_Valid(frameInfo))
|
m_jsonList.append(frameInfo);
|
||||||
m_jsonList.append(frameInfo);
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user