Add 'get_who_am_i' command and related configurations for device identification

This commit is contained in:
PhosphorosVR
2025-09-05 17:47:04 +02:00
parent e4881ef5a0
commit 93b2f7f23f
12 changed files with 85 additions and 7 deletions

View File

@@ -26,7 +26,8 @@ std::unordered_map<std::string, CommandType> commandTypeMap = {
{"set_led_duty_cycle", CommandType::SET_LED_DUTY_CYCLE},
{"get_led_duty_cycle", CommandType::GET_LED_DUTY_CYCLE},
{"get_serial", CommandType::GET_SERIAL},
{"get_led_current", CommandType::GET_LED_CURRENT},
{"get_led_current", CommandType::GET_LED_CURRENT},
{"get_who_am_i", CommandType::GET_WHO_AM_I},
};
std::function<CommandResult()> CommandManager::createCommand(const CommandType type, std::string_view json) const
@@ -107,6 +108,9 @@ std::function<CommandResult()> CommandManager::createCommand(const CommandType t
case CommandType::GET_LED_CURRENT:
return [this]
{ return getLEDCurrentCommand(this->registry); };
case CommandType::GET_WHO_AM_I:
return [this]
{ return getInfoCommand(this->registry); };
default:
return nullptr;
}

View File

@@ -48,6 +48,7 @@ enum class CommandType
GET_LED_DUTY_CYCLE,
GET_SERIAL,
GET_LED_CURRENT,
GET_WHO_AM_I,
};
class CommandManager

View File

@@ -248,3 +248,14 @@ CommandResult getLEDCurrentCommand(std::shared_ptr<DependencyRegistry> registry)
return CommandResult::getErrorResult("Monitoring disabled");
#endif
}
CommandResult getInfoCommand(std::shared_ptr<DependencyRegistry> /*registry*/)
{
const char* who = CONFIG_GENERAL_WHO_AM_I;
const char* ver = CONFIG_GENERAL_Version;
// Ensure non-null strings
if (!who) who = "";
if (!ver) ver = "";
auto result = std::format("{{ \"who_am_i\": \"{}\", \"version\": \"{}\" }}", who, ver);
return CommandResult::getSuccessResult(result);
}

View File

@@ -25,4 +25,7 @@ CommandResult getDeviceModeCommand(std::shared_ptr<DependencyRegistry> registry)
CommandResult getSerialNumberCommand(std::shared_ptr<DependencyRegistry> registry);
// Monitoring
CommandResult getLEDCurrentCommand(std::shared_ptr<DependencyRegistry> registry);
CommandResult getLEDCurrentCommand(std::shared_ptr<DependencyRegistry> registry);
// General info
CommandResult getInfoCommand(std::shared_ptr<DependencyRegistry> registry);