mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-19 19:44:35 +08:00
Add support in printf command to send 8-32 bits value
This commit is contained in:

committed by
Xiang Xiao

parent
8a19fe36e1
commit
382638c8c6
@@ -63,6 +63,8 @@ int cmd_printf(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
{
|
{
|
||||||
FAR char *fmt;
|
FAR char *fmt;
|
||||||
char ch;
|
char ch;
|
||||||
|
uint32_t value;
|
||||||
|
int len;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* parse each argument, detecting the right action to take
|
/* parse each argument, detecting the right action to take
|
||||||
@@ -84,7 +86,25 @@ int cmd_printf(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
{
|
{
|
||||||
case 'x':
|
case 'x':
|
||||||
fmt++;
|
fmt++;
|
||||||
nsh_output(vtbl, "%c", strtol(fmt, NULL, 16));
|
value = strtoul(fmt, NULL, 16);
|
||||||
|
len = strnlen(fmt, 10);
|
||||||
|
|
||||||
|
if (len >= 7)
|
||||||
|
{
|
||||||
|
nsh_output(vtbl, "%c%c%c%c", value & 0xff,
|
||||||
|
(value & 0xff00) >> 8,
|
||||||
|
(value & 0xff0000) >> 16,
|
||||||
|
(value & 0xff000000) >> 24);
|
||||||
|
}
|
||||||
|
else if (len >= 3)
|
||||||
|
{
|
||||||
|
nsh_output(vtbl, "%c%c", value & 0xff,
|
||||||
|
(value & 0xff00) >> 8);
|
||||||
|
}
|
||||||
|
else if (len >= 1)
|
||||||
|
{
|
||||||
|
nsh_output(vtbl, "%c", value & 0xff);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
|
Reference in New Issue
Block a user