From: Adrian Remonda <adrianremonda@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: adrianremonda@gmail.com, broonie@kernel.org, corbet@lwn.net,
linux-spi@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/4] Cleaned hexadecimal dump
Date: Sat, 7 Mar 2015 12:56:32 -0500 [thread overview]
Message-ID: <1425750995-18176-2-git-send-email-adrianremonda@gmail.com> (raw)
In-Reply-To: <1425750995-18176-1-git-send-email-adrianremonda@gmail.com>
Signed-off-by: Adrian Remonda <adrianremonda@gmail.com>
---
Documentation/spi/spidev_test.c | 35 +++++++++++++++++++++++++++++------
1 file changed, 29 insertions(+), 6 deletions(-)
diff --git a/Documentation/spi/spidev_test.c b/Documentation/spi/spidev_test.c
index 3a2f9d59edab..533050ced9f1 100644
--- a/Documentation/spi/spidev_test.c
+++ b/Documentation/spi/spidev_test.c
@@ -15,6 +15,7 @@
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
@@ -35,6 +36,33 @@ static uint8_t bits = 8;
static uint32_t speed = 500000;
static uint16_t delay;
+static void hexDump(const void *src, size_t length, size_t bLine, char *prefix)
+{
+ int i = 0;
+ char *address = (char *)src;
+ char *line = (char *)address;
+ unsigned char c;
+
+ printf("%s | ", prefix);
+ while (length-- > 0) {
+ printf("%02X ", (unsigned char)*address++);
+ if (!(++i % bLine) || (length == 0 && i % bLine)) {
+ if (length == 0) {
+ while (i++ % bLine)
+ printf("__ ");
+ }
+ printf(" | "); /* right close */
+ while (line < address) {
+ c = *line++;
+ printf("%c", (c < 33 || c == 255) ? 0x2E : c);
+ }
+ printf("\n");
+ if (length > 0)
+ printf("%s | ", prefix);
+ }
+ }
+}
+
static void transfer(int fd)
{
int ret;
@@ -76,12 +104,7 @@ static void transfer(int fd)
if (ret < 1)
pabort("can't send spi message");
- for (ret = 0; ret < ARRAY_SIZE(tx); ret++) {
- if (!(ret % 6))
- puts("");
- printf("%.2X ", rx[ret]);
- }
- puts("");
+ hexDump(rx, ARRAY_SIZE(tx), 32, "RX");
}
static void print_usage(const char *prog)
--
1.7.10.4
next prev parent reply other threads:[~2015-03-07 17:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-07 17:56 [PATCH 0/4] spi: spidev_test: Added functionalities Adrian Remonda
2015-03-07 17:56 ` Adrian Remonda [this message]
2015-03-07 17:56 ` [PATCH 2/4] Added verbose output Adrian Remonda
2015-03-07 17:56 ` [PATCH 3/4] Added input buffer from the terminal Adrian Remonda
2015-03-07 17:56 ` [PATCH 4/4] Moved spidev_tools.c to tools/spi Adrian Remonda
2015-03-09 18:38 ` [PATCH 3/4] Added input buffer from the terminal Mark Brown
2015-03-08 2:22 ` [PATCH 1/4] Cleaned hexadecimal dump Joe Perches
2015-03-08 10:53 ` Andy Shevchenko
2015-03-08 16:20 ` Joe Perches
[not found] ` <1425750995-18176-2-git-send-email-adrianremonda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-03-09 13:51 ` Geert Uytterhoeven
2015-03-09 18:40 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1425750995-18176-2-git-send-email-adrianremonda@gmail.com \
--to=adrianremonda@gmail.com \
--cc=broonie@kernel.org \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).