xiaoxiang781216 commented on a change in pull request #572:
URL: 
https://github.com/apache/incubator-nuttx-apps/pull/572#discussion_r565789424



##########
File path: nshlib/nsh_printf.c
##########
@@ -84,7 +87,34 @@ int cmd_printf(FAR struct nsh_vtbl_s *vtbl, int argc, char 
**argv)
             {
               case 'x':
                 fmt++;
-                nsh_output(vtbl, "%c", strtol(fmt, NULL, 16));
+                value = strtol(fmt, NULL, 16);
+                len = strnlen(fmt, 10);
+
+                /* Is it a Big Endian MCU ? */
+
+                if (BYTE_ORDER == BIG_ENDIAN)
+                  {
+                    value = __swap_uint32(value);

Review comment:
       Don't manually swap the value.
   (0x12345678 & 0xff00) >> 8 always get 0x56.
   

##########
File path: nshlib/nsh_printf.c
##########
@@ -84,7 +87,34 @@ int cmd_printf(FAR struct nsh_vtbl_s *vtbl, int argc, char 
**argv)
             {
               case 'x':
                 fmt++;
-                nsh_output(vtbl, "%c", strtol(fmt, NULL, 16));
+                value = strtol(fmt, NULL, 16);
+                len = strnlen(fmt, 10);
+
+                /* Is it a Big Endian MCU ? */
+
+                if (BYTE_ORDER == BIG_ENDIAN)
+                  {
+                    value = __swap_uint32(value);
+                  }
+
+                if (len == 8)

Review comment:
       change to len >= 7(len >= 3, len >= 1)

##########
File path: nshlib/nsh_printf.c
##########
@@ -84,7 +87,34 @@ int cmd_printf(FAR struct nsh_vtbl_s *vtbl, int argc, char 
**argv)
             {
               case 'x':
                 fmt++;
-                nsh_output(vtbl, "%c", strtol(fmt, NULL, 16));
+                value = strtol(fmt, NULL, 16);

Review comment:
       change strtol to strtoul

##########
File path: nshlib/nsh_printf.c
##########
@@ -84,7 +87,34 @@ int cmd_printf(FAR struct nsh_vtbl_s *vtbl, int argc, char 
**argv)
             {
               case 'x':
                 fmt++;
-                nsh_output(vtbl, "%c", strtol(fmt, NULL, 16));
+                value = strtol(fmt, NULL, 16);
+                len = strnlen(fmt, 10);
+
+                /* Is it a Big Endian MCU ? */
+
+                if (BYTE_ORDER == BIG_ENDIAN)
+                  {
+                    value = __swap_uint32(value);
+                  }
+
+                if (len == 8)
+                  {
+                    nsh_output(vtbl, "%c%c%c%c", value & 0xff,
+                                                 (value & 0xff00) >> 8,
+                                                 (value & 0xff0000) >> 16,
+                                                 (value & 0xff000000) >> 24);
+                  }
+                else
+                  if (len == 4)
+                    {
+                      nsh_output(vtbl, "%c%c", value & 0xff,
+                                               (value & 0xff00) >> 8);
+                    }
+                  else
+                    if (len == 2)

Review comment:
       same question

##########
File path: nshlib/nsh_printf.c
##########
@@ -84,7 +87,34 @@ int cmd_printf(FAR struct nsh_vtbl_s *vtbl, int argc, char 
**argv)
             {
               case 'x':
                 fmt++;
-                nsh_output(vtbl, "%c", strtol(fmt, NULL, 16));
+                value = strtol(fmt, NULL, 16);
+                len = strnlen(fmt, 10);
+
+                /* Is it a Big Endian MCU ? */
+
+                if (BYTE_ORDER == BIG_ENDIAN)
+                  {
+                    value = __swap_uint32(value);
+                  }
+
+                if (len == 8)
+                  {
+                    nsh_output(vtbl, "%c%c%c%c", value & 0xff,
+                                                 (value & 0xff00) >> 8,
+                                                 (value & 0xff0000) >> 16,
+                                                 (value & 0xff000000) >> 24);
+                  }
+                else
+                  if (len == 4)

Review comment:
       Why split "else if" into two lines?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to