* @brief Processes a chunk of received bytes and extracts complete frames. */
| 76 | * @brief Processes a chunk of received bytes and extracts complete frames. |
| 77 | */ |
| 78 | void IO::FrameReader::processData(const CapturedDataPtr& data) |
| 79 | { |
| 80 | Q_ASSERT(m_operationMode >= SerialStudio::ProjectFile |
| 81 | && m_operationMode <= SerialStudio::QuickPlot); |
| 82 | Q_ASSERT(m_checksumLength >= 0); |
| 83 | |
| 84 | if (!data || data->data.isEmpty()) |
| 85 | return; |
| 86 | |
| 87 | if (m_operationMode == SerialStudio::ConsoleOnly) |
| 88 | return; |
| 89 | |
| 90 | bool framesEnqueued = false; |
| 91 | |
| 92 | if (m_operationMode == SerialStudio::ProjectFile |
| 93 | && m_frameDetectionMode == SerialStudio::NoDelimiters) { |
| 94 | framesEnqueued = m_queue.try_enqueue(data); |
| 95 | if (!framesEnqueued) [[unlikely]] |
| 96 | noteDroppedFrame(); |
| 97 | } |
| 98 | |
| 99 | else { |
| 100 | appendChunk(data); |
| 101 | const auto overflow = m_circularBuffer.overflowCount(); |
| 102 | if (overflow > 0) [[unlikely]] { |
| 103 | const auto now = CapturedData::SteadyClock::now(); |
| 104 | if (now - m_lastOverflowLog >= std::chrono::seconds(5)) { |
| 105 | m_lastOverflowLog = now; |
| 106 | qWarning() << "[FrameReader] Buffer overflow:" << overflow |
| 107 | << "bytes lost -- data rate exceeds processing capacity"; |
| 108 | } |
| 109 | discardPendingBytes(overflow); |
| 110 | m_circularBuffer.resetOverflowCount(); |
| 111 | } |
| 112 | |
| 113 | const auto initialSize = m_queue.size_approx(); |
| 114 | switch (m_operationMode) { |
| 115 | case SerialStudio::QuickPlot: |
| 116 | readEndDelimitedFrames(); |
| 117 | break; |
| 118 | case SerialStudio::ProjectFile: |
| 119 | switch (m_frameDetectionMode) { |
| 120 | case SerialStudio::EndDelimiterOnly: |
| 121 | readEndDelimitedFrames(); |
| 122 | break; |
| 123 | case SerialStudio::StartDelimiterOnly: |
| 124 | readStartDelimitedFrames(); |
| 125 | break; |
| 126 | case SerialStudio::StartAndEndDelimiter: |
| 127 | readStartEndDelimitedFrames(); |
| 128 | break; |
| 129 | default: |
| 130 | break; |
| 131 | } |
| 132 | break; |
| 133 | default: |
| 134 | break; |
| 135 | } |
no test coverage detected