From c5a651a8b7474792a25ec09d42dcd67833b5b84f Mon Sep 17 00:00:00 2001 From: Alex Spataru Date: Fri, 24 Sep 2021 17:57:47 -0500 Subject: [PATCH] Remove unnecessary checks --- src/JSON/FrameInfo.h | 40 +--------------------------------------- src/JSON/Generator.cpp | 27 ++------------------------- src/JSON/Generator.h | 1 - src/UI/DataProvider.cpp | 5 +---- src/UI/GraphProvider.cpp | 3 +-- 5 files changed, 5 insertions(+), 71 deletions(-) diff --git a/src/JSON/FrameInfo.h b/src/JSON/FrameInfo.h index 0046e662..2ca0c2be 100644 --- a/src/JSON/FrameInfo.h +++ b/src/JSON/FrameInfo.h @@ -27,46 +27,13 @@ #include #include -/** - * 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 { quint64 frameNumber; QDateTime rxDateTime; QJsonDocument jsonDocument; } JFI_Object; - -//---------------------------------------------------------------------------------------- -// Convenience functions -//---------------------------------------------------------------------------------------- +Q_DECLARE_METATYPE(JFI_Object) extern bool JFI_Valid(const JFI_Object &info); extern void JFI_SortList(QList *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, const QJsonDocument &d); -/* - * Important magic to be able to use JFI structures in Qt signals/slots - */ -Q_DECLARE_METATYPE(JFI_Object) - #endif diff --git a/src/JSON/Generator.cpp b/src/JSON/Generator.cpp index 097a673c..f1385cb5 100644 --- a/src/JSON/Generator.cpp +++ b/src/JSON/Generator.cpp @@ -217,36 +217,13 @@ void Generator::writeSettings(const QString &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 */ void Generator::loadJSON(const QJsonDocument &json) { - auto jfi = JFI_CreateNew(m_frameCount, QDateTime::currentDateTime(), json); 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 if (error.error == QJsonParseError::NoError) - loadJFI(JFI_CreateNew(frame, time, document)); + emit jsonChanged(JFI_CreateNew(frame, time, document)); } diff --git a/src/JSON/Generator.h b/src/JSON/Generator.h index a7e1d256..3477ed45 100644 --- a/src/JSON/Generator.h +++ b/src/JSON/Generator.h @@ -88,7 +88,6 @@ private: public slots: void readSettings(); - void loadJFI(const JFI_Object &info); void writeSettings(const QString &path); void loadJSON(const QJsonDocument &json); diff --git a/src/UI/DataProvider.cpp b/src/UI/DataProvider.cpp index 9b30f6ff..355abdaf 100644 --- a/src/UI/DataProvider.cpp +++ b/src/UI/DataProvider.cpp @@ -140,8 +140,5 @@ void DataProvider::selectLatestJSON(const JFI_Object &frameInfo) auto currFrameCount = m_latestJsonFrame.frameNumber; if (currFrameCount < frameCount) - { - if (JFI_Valid(frameInfo)) - m_latestJsonFrame = frameInfo; - } + m_latestJsonFrame = frameInfo; } diff --git a/src/UI/GraphProvider.cpp b/src/UI/GraphProvider.cpp index 9b71174c..b7c5a557 100644 --- a/src/UI/GraphProvider.cpp +++ b/src/UI/GraphProvider.cpp @@ -386,6 +386,5 @@ void GraphProvider::updateGraph(QAbstractSeries *series, const int index) */ void GraphProvider::registerFrame(const JFI_Object &frameInfo) { - if (JFI_Valid(frameInfo)) - m_jsonList.append(frameInfo); + m_jsonList.append(frameInfo); }