drivers: hwinfo: shell: add support for displaying device EUI64 ID

This adds a 'deveui64' command to display the just added EUI64 device
id. Display "Not supported by hardware" on devices that do not have it.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
This commit is contained in:
Aurelien Jarno 2024-04-28 21:09:15 +02:00 committed by David Leach
parent 185edca797
commit ce29e275c9

View file

@ -38,6 +38,33 @@ static int cmd_get_device_id(const struct shell *sh, size_t argc, char **argv)
return 0; return 0;
} }
static int cmd_get_device_eui64(const struct shell *sh, size_t argc, char **argv)
{
uint8_t dev_eui64[8];
int ret;
int i;
ret = hwinfo_get_device_eui64(dev_eui64);
if (ret == -ENOSYS) {
shell_error(sh, "Not supported by hardware");
return -ENOSYS;
} else if (ret < 0) {
shell_error(sh, "Error: %d", ret);
return ret;
}
shell_fprintf(sh, SHELL_NORMAL, "EUI64: 0x");
for (i = 0 ; i < 8 ; i++) {
shell_fprintf(sh, SHELL_NORMAL, "%02x", dev_eui64[i]);
}
shell_fprintf(sh, SHELL_NORMAL, "\n");
return 0;
}
static inline const char *cause_to_string(uint32_t cause) static inline const char *cause_to_string(uint32_t cause)
{ {
switch (cause) { switch (cause) {
@ -188,6 +215,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(sub_reset_cause,
SHELL_STATIC_SUBCMD_SET_CREATE(sub_hwinfo, SHELL_STATIC_SUBCMD_SET_CREATE(sub_hwinfo,
SHELL_CMD_ARG(devid, NULL, "Show device id", cmd_get_device_id, 1, 0), SHELL_CMD_ARG(devid, NULL, "Show device id", cmd_get_device_id, 1, 0),
SHELL_CMD_ARG(deveui64, NULL, "Show device eui64", cmd_get_device_eui64, 1, 0),
SHELL_CMD_ARG(reset_cause, &sub_reset_cause, "Reset cause commands", SHELL_CMD_ARG(reset_cause, &sub_reset_cause, "Reset cause commands",
cmd_show_reset_cause, 1, 0), cmd_show_reset_cause, 1, 0),
SHELL_SUBCMD_SET_END /* Array terminated. */ SHELL_SUBCMD_SET_END /* Array terminated. */