1 /*
2  * Copyright (c) 2019 Alexander Wachter
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <sys/printk.h>
8 #include <shell/shell.h>
9 #include <drivers/hwinfo.h>
10 #include <zephyr/types.h>
11 #include <logging/log.h>
12 
cmd_get_device_id(const struct shell * shell,size_t argc,char ** argv)13 static int cmd_get_device_id(const struct shell *shell, size_t argc, char **argv)
14 {
15 	uint8_t dev_id[16];
16 	ssize_t length;
17 	int i;
18 
19 	length = hwinfo_get_device_id(dev_id, sizeof(dev_id));
20 
21 	if (length == -ENOTSUP) {
22 		shell_error(shell, "Not supported by hardware");
23 		return -ENOTSUP;
24 	} else if (length < 0) {
25 		shell_error(shell, "Error: %d", length);
26 		return length;
27 	}
28 
29 	shell_fprintf(shell, SHELL_NORMAL, "Length: %d\n", length);
30 	shell_fprintf(shell, SHELL_NORMAL, "ID: 0x");
31 
32 	for (i = 0 ; i < length ; i++) {
33 		shell_fprintf(shell, SHELL_NORMAL, "%02x", dev_id[i]);
34 	}
35 
36 	shell_fprintf(shell, SHELL_NORMAL, "\n");
37 
38 	return 0;
39 }
40 
41 SHELL_STATIC_SUBCMD_SET_CREATE(sub_hwinfo,
42 	SHELL_CMD_ARG(devid, NULL, "Show device id", cmd_get_device_id, 1, 0),
43 	SHELL_SUBCMD_SET_END /* Array terminated. */
44 );
45 
46 SHELL_CMD_ARG_REGISTER(hwinfo, &sub_hwinfo, "HWINFO commands", NULL, 2, 0);
47