* @brief Set serial port by device name */
| 161 | * @brief Set serial port by device name |
| 162 | */ |
| 163 | API::CommandResponse API::Handlers::UARTHandler::setDevice(const QString& id, |
| 164 | const QJsonObject& params) |
| 165 | { |
| 166 | if (!params.contains(QStringLiteral("device"))) { |
| 167 | return CommandResponse::makeError( |
| 168 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: device")); |
| 169 | } |
| 170 | |
| 171 | const QString device = params.value(QStringLiteral("device")).toString(); |
| 172 | if (device.isEmpty()) { |
| 173 | return CommandResponse::makeError( |
| 174 | id, ErrorCode::InvalidParam, QStringLiteral("Device name cannot be empty")); |
| 175 | } |
| 176 | |
| 177 | auto* uart = IO::ConnectionManager::instance().uart(); |
| 178 | QMetaObject::invokeMethod( |
| 179 | uart, [uart, device]() { uart->registerDevice(device); }, Qt::AutoConnection); |
| 180 | |
| 181 | QJsonObject result; |
| 182 | result[QStringLiteral("device")] = device; |
| 183 | return CommandResponse::makeSuccess(id, result); |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * @brief Set serial port by index |
no test coverage detected