* @brief Configure frame parser settings for a specific source. */
| 4033 | * @brief Configure frame parser settings for a specific source. |
| 4034 | */ |
| 4035 | API::CommandResponse API::Handlers::ProjectHandler::frameParserConfigure(const QString& id, |
| 4036 | const QJsonObject& params) |
| 4037 | { |
| 4038 | auto& model = DataModel::ProjectModel::instance(); |
| 4039 | auto& manager = IO::ConnectionManager::instance(); |
| 4040 | bool updated = false; |
| 4041 | |
| 4042 | const int sourceId = params.contains(Keys::SourceId) ? params.value(Keys::SourceId).toInt() : 0; |
| 4043 | const int srcCount = static_cast<int>(model.sources().size()); |
| 4044 | |
| 4045 | if (sourceId < 0 || (!model.sources().empty() && sourceId >= srcCount)) |
| 4046 | return CommandResponse::makeError( |
| 4047 | id, ErrorCode::InvalidParam, QStringLiteral("Invalid sourceId")); |
| 4048 | |
| 4049 | if (params.contains(QStringLiteral("operationMode"))) { |
| 4050 | const int modeIdx = params.value(QStringLiteral("operationMode")).toInt(); |
| 4051 | if (modeIdx >= 0 && modeIdx <= 2) { |
| 4052 | AppState::instance().setOperationMode(static_cast<SerialStudio::OperationMode>(modeIdx)); |
| 4053 | updated = true; |
| 4054 | } |
| 4055 | } |
| 4056 | |
| 4057 | if (sourceId == 0) { |
| 4058 | if (params.contains(QStringLiteral("startSequence"))) { |
| 4059 | const QString start = params.value(QStringLiteral("startSequence")).toString(); |
| 4060 | manager.setStartSequence(start.toUtf8()); |
| 4061 | model.setFrameStartSequence(start); |
| 4062 | updated = true; |
| 4063 | } |
| 4064 | |
| 4065 | if (params.contains(QStringLiteral("endSequence"))) { |
| 4066 | const QString end = params.value(QStringLiteral("endSequence")).toString(); |
| 4067 | manager.setFinishSequence(end.toUtf8()); |
| 4068 | model.setFrameEndSequence(end); |
| 4069 | updated = true; |
| 4070 | } |
| 4071 | |
| 4072 | if (params.contains(Keys::ChecksumAlgorithm)) { |
| 4073 | const QString checksumName = params.value(Keys::ChecksumAlgorithm).toString(); |
| 4074 | manager.setChecksumAlgorithm(checksumName); |
| 4075 | model.setChecksumAlgorithm(checksumName); |
| 4076 | updated = true; |
| 4077 | } |
| 4078 | |
| 4079 | if (params.contains(Keys::FrameDetection)) { |
| 4080 | const int detectionIdx = params.value(Keys::FrameDetection).toInt(); |
| 4081 | if (detectionIdx >= 0 && detectionIdx <= 3) { |
| 4082 | model.setFrameDetection(static_cast<SerialStudio::FrameDetection>(detectionIdx)); |
| 4083 | updated = true; |
| 4084 | } |
| 4085 | } |
| 4086 | } else { |
| 4087 | DataModel::Source src = model.sources()[sourceId]; |
| 4088 | |
| 4089 | if (params.contains(QStringLiteral("startSequence"))) { |
| 4090 | src.frameStart = params.value(QStringLiteral("startSequence")).toString(); |
| 4091 | updated = true; |
| 4092 | } |
nothing calls this directly
no test coverage detected