Rework str based responses to json

This commit is contained in:
Lorow
2025-10-14 22:49:44 +02:00
parent e5ce325e3f
commit 5c66c9ca77
2 changed files with 14 additions and 8 deletions
@@ -95,8 +95,8 @@ CommandResult getLEDDutyCycleCommand(std::shared_ptr<DependencyRegistry> registr
const auto projectConfig = registry->resolve<ProjectConfig>(DependencyType::project_config); const auto projectConfig = registry->resolve<ProjectConfig>(DependencyType::project_config);
const auto deviceCfg = projectConfig->getDeviceConfig(); const auto deviceCfg = projectConfig->getDeviceConfig();
int duty = deviceCfg.led_external_pwm_duty_cycle; int duty = deviceCfg.led_external_pwm_duty_cycle;
auto result = std::format("{{ \"led_external_pwm_duty_cycle\": {} }}", duty); const auto json = nlohmann::json{{"led_external_pwm_duty_cycle", duty}};
return CommandResult::getSuccessResult(result); return CommandResult::getSuccessResult(json);
} }
CommandResult startStreamingCommand() CommandResult startStreamingCommand()
@@ -173,8 +173,11 @@ CommandResult getDeviceModeCommand(std::shared_ptr<DependencyRegistry> registry)
break; break;
} }
auto result = std::format("{{ \"mode\": \"{}\", \"value\": {} }}", modeStr, static_cast<int>(currentMode)); const auto json = nlohmann::json{
return CommandResult::getSuccessResult(result); {"mode", modeStr},
{"value", static_cast<int>(currentMode)},
};
return CommandResult::getSuccessResult(json);
} }
CommandResult getSerialNumberCommand(std::shared_ptr<DependencyRegistry> /*registry*/) CommandResult getSerialNumberCommand(std::shared_ptr<DependencyRegistry> /*registry*/)
@@ -193,8 +196,11 @@ CommandResult getSerialNumberCommand(std::shared_ptr<DependencyRegistry> /*regis
std::snprintf(mac_colon, sizeof(mac_colon), "%02X:%02X:%02X:%02X:%02X:%02X", std::snprintf(mac_colon, sizeof(mac_colon), "%02X:%02X:%02X:%02X:%02X:%02X",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
auto result = std::format("{{ \"serial\": \"{}\", \"mac\": \"{}\" }}", serial_no_sep, mac_colon); const auto json = nlohmann::json{
return CommandResult::getSuccessResult(result); {"serial", serial_no_sep},
{"mac", mac_colon},
};
return CommandResult::getSuccessResult(json);
} }
CommandResult getLEDCurrentCommand(std::shared_ptr<DependencyRegistry> registry) CommandResult getLEDCurrentCommand(std::shared_ptr<DependencyRegistry> registry)
@@ -17,6 +17,6 @@ CommandResult getMDNSNameCommand(std::shared_ptr<DependencyRegistry> registry)
const auto projectConfig = registry->resolve<ProjectConfig>(DependencyType::project_config); const auto projectConfig = registry->resolve<ProjectConfig>(DependencyType::project_config);
auto mdnsConfig = projectConfig->getMDNSConfig(); auto mdnsConfig = projectConfig->getMDNSConfig();
auto result = std::format("{{ \"hostname\": \"{}\" }}", mdnsConfig.hostname); const auto json = nlohmann::json{{"hostname", mdnsConfig.hostname}};
return CommandResult::getSuccessResult(result); return CommandResult::getSuccessResult(json);
} }