MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / buildReplayProjectJson

Method buildReplayProjectJson

app/src/Sessions/Export.cpp:403–456  ·  view source on GitHub ↗

* @brief Produces the project JSON stored with the session. */

Source from the content-addressed store, hash-verified

401 * @brief Produces the project JSON stored with the session.
402 */
403QJsonObject Sessions::ExportWorker::buildReplayProjectJson(const DataModel::Frame& frame) const
404{
405 {
406 QMutexLocker locker(m_projectSnapshotMutex);
407 if (!m_projectSnapshot->isEmpty()) {
408 const auto doc = QJsonDocument::fromJson(*m_projectSnapshot);
409 if (doc.isObject())
410 return doc.object();
411 }
412 }
413
414 if (AppState::instance().operationMode() == SerialStudio::ConsoleOnly) {
415 QJsonObject json;
416 json.insert(QStringLiteral("title"), frame.title);
417 json.insert(QStringLiteral("operationMode"), QStringLiteral("ConsoleOnly"));
418 return json;
419 }
420
421 QJsonObject json;
422 json.insert(Keys::Title, frame.title);
423
424 json.insert(Keys::FrameDetection, static_cast<int>(SerialStudio::EndDelimiterOnly));
425 json.insert(Keys::FrameEnd, QStringLiteral("\\n"));
426 json.insert(Keys::FrameStart, QStringLiteral(""));
427 json.insert(Keys::Decoder, static_cast<int>(SerialStudio::PlainText));
428
429 QJsonArray groupsArray;
430 for (const auto& group : frame.groups)
431 groupsArray.append(DataModel::serialize(group));
432
433 json.insert(Keys::Groups, groupsArray);
434 json.insert(Keys::Actions, QJsonArray());
435
436 QJsonObject source;
437 source.insert(Keys::Title, QStringLiteral("Device A"));
438 source.insert(Keys::SourceId, 0);
439 source.insert(Keys::BusType, static_cast<int>(SerialStudio::BusType::UART));
440 source.insert(Keys::FrameDetection, static_cast<int>(SerialStudio::EndDelimiterOnly));
441 source.insert(Keys::FrameStart, QString());
442 source.insert(Keys::FrameEnd, QStringLiteral("\\n"));
443 source.insert(Keys::Decoder, static_cast<int>(SerialStudio::PlainText));
444 source.insert(Keys::FrameParserLanguage, static_cast<int>(SerialStudio::Native));
445
446 const QString templateId = DataModel::defaultNativeTemplateId();
447 source.insert(Keys::FrameParserTemplate, templateId);
448 if (const auto* tmpl = DataModel::nativeTemplateById(templateId))
449 source.insert(Keys::FrameParserParams, DataModel::nativeTemplateDefaults(*tmpl));
450
451 QJsonArray sourcesArray;
452 sourcesArray.append(source);
453 json.insert(Keys::Sources, sourcesArray);
454
455 return json;
456}
457
458/**
459 * @brief Prepares the pre-compiled queries used on the frame hotpath.

Callers

nothing calls this directly

Calls 5

fromJsonFunction · 0.85
serializeFunction · 0.85
isEmptyMethod · 0.80
operationModeMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected