* @brief Computes the FrameConfig for device 0 from current state. */
| 227 | * @brief Computes the FrameConfig for device 0 from current state. |
| 228 | */ |
| 229 | IO::FrameConfig AppState::deriveFrameConfig() const |
| 230 | { |
| 231 | IO::FrameConfig cfg; |
| 232 | cfg.operationMode = m_operationMode; |
| 233 | |
| 234 | if (m_operationMode == SerialStudio::QuickPlot) { |
| 235 | cfg.startSequences = {}; |
| 236 | cfg.finishSequences = {QByteArray("\n"), QByteArray("\r\n"), QByteArray("\r")}; |
| 237 | cfg.checksumAlgorithm = QString(); |
| 238 | cfg.frameDetection = SerialStudio::EndDelimiterOnly; |
| 239 | return cfg; |
| 240 | } |
| 241 | |
| 242 | if (m_operationMode == SerialStudio::ConsoleOnly) { |
| 243 | cfg.startSequences = {}; |
| 244 | cfg.finishSequences = {}; |
| 245 | cfg.checksumAlgorithm = QString(); |
| 246 | cfg.frameDetection = SerialStudio::NoDelimiters; |
| 247 | return cfg; |
| 248 | } |
| 249 | |
| 250 | const auto& sources = DataModel::ProjectModel::instance().sources(); |
| 251 | if (sources.empty()) { |
| 252 | cfg.startSequences = {QByteArray("/*")}; |
| 253 | cfg.finishSequences = {QByteArray("*/")}; |
| 254 | cfg.checksumAlgorithm = QString(); |
| 255 | cfg.frameDetection = DataModel::ProjectModel::instance().frameDetection(); |
| 256 | return cfg; |
| 257 | } |
| 258 | |
| 259 | cfg.frameDetection = static_cast<SerialStudio::FrameDetection>(sources[0].frameDetection); |
| 260 | |
| 261 | QByteArray startSeq; |
| 262 | QByteArray finishSeq; |
| 263 | DataModel::read_io_settings( |
| 264 | startSeq, finishSeq, cfg.checksumAlgorithm, DataModel::serialize(sources[0])); |
| 265 | |
| 266 | cfg.startSequences = startSeq.isEmpty() ? QList<QByteArray>{} : QList<QByteArray>{startSeq}; |
| 267 | cfg.finishSequences = finishSeq.isEmpty() ? QList<QByteArray>{} : QList<QByteArray>{finishSeq}; |
| 268 | |
| 269 | if ((cfg.frameDetection == SerialStudio::StartDelimiterOnly |
| 270 | || cfg.frameDetection == SerialStudio::StartAndEndDelimiter) |
| 271 | && cfg.startSequences.isEmpty()) [[unlikely]] |
| 272 | cfg.frameDetection = |
| 273 | cfg.finishSequences.isEmpty() ? SerialStudio::NoDelimiters : SerialStudio::EndDelimiterOnly; |
| 274 | |
| 275 | if (cfg.frameDetection == SerialStudio::EndDelimiterOnly && cfg.finishSequences.isEmpty()) |
| 276 | [[unlikely]] |
| 277 | cfg.frameDetection = SerialStudio::NoDelimiters; |
| 278 | |
| 279 | return cfg; |
| 280 | } |
nothing calls this directly
no test coverage detected