* @brief Select CAN plugin by index */
| 108 | * @brief Select CAN plugin by index |
| 109 | */ |
| 110 | API::CommandResponse API::Handlers::CANBusHandler::setPluginIndex(const QString& id, |
| 111 | const QJsonObject& params) |
| 112 | { |
| 113 | if (!params.contains(QStringLiteral("pluginIndex"))) { |
| 114 | return CommandResponse::makeError( |
| 115 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: pluginIndex")); |
| 116 | } |
| 117 | |
| 118 | const int pluginIndex = params.value(QStringLiteral("pluginIndex")).toInt(); |
| 119 | auto* canbus = IO::ConnectionManager::instance().canBus(); |
| 120 | const auto& pluginList = canbus->pluginList(); |
| 121 | |
| 122 | if (pluginIndex < 0 || pluginIndex >= pluginList.count()) { |
| 123 | return CommandResponse::makeError(id, |
| 124 | ErrorCode::InvalidParam, |
| 125 | QStringLiteral("Invalid pluginIndex: %1. Valid range: 0-%2") |
| 126 | .arg(pluginIndex) |
| 127 | .arg(pluginList.count() - 1)); |
| 128 | } |
| 129 | |
| 130 | canbus->setPluginIndex(static_cast<quint8>(pluginIndex)); |
| 131 | |
| 132 | QJsonObject result; |
| 133 | result[QStringLiteral("pluginIndex")] = pluginIndex; |
| 134 | result[QStringLiteral("pluginName")] = pluginList.at(pluginIndex); |
| 135 | return CommandResponse::makeSuccess(id, result); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * @brief Select CAN interface by index |
nothing calls this directly
no test coverage detected