From f2a7724892c4f667b88278dac447bf948cd9eafc Mon Sep 17 00:00:00 2001 From: "Frank Singleton, VK3FCS" Date: Sun, 30 Jul 2000 03:57:19 +0000 Subject: [PATCH] added generic hex dump routine, static void dump_hex(unsigned char *ptr, int size, int width); git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@58 7ae35d74-ebe9-4afe-98af-79ac388436b8 --- common/serial.c | 61 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/common/serial.c b/common/serial.c index b918be4b8..e8e8591ae 100644 --- a/common/serial.c +++ b/common/serial.c @@ -5,7 +5,7 @@ * Provides useful routines for read/write serial data for communicating * via serial interface . * - * $Id: serial.c,v 1.3 2000-07-30 02:00:49 javabear Exp $ + * $Id: serial.c,v 1.4 2000-07-30 03:57:19 javabear Exp $ * */ @@ -19,6 +19,7 @@ #include #include "serial.h" +static void dump_hex(unsigned char *ptr, int size, int width); /* * Open serial port @@ -152,22 +153,18 @@ void pause2() { * */ -int write_block(int fd, unsigned char *data) { +int write_block(int fd, unsigned char *txbuffer) { int i; - printf("write_block data = "); - for (i=0; i<5; i++) { - if(write(fd, &data[i] , 1) < 0) { + if(write(fd, &txbuffer[i] , 1) < 0) { fputs("write() of byte failed!\n", stderr); return -1; } - printf(" 0x%.2x ", data[i]); - pause2(); /* 50 msec */ } - printf("\n"); + dump_hex(txbuffer,5,16); return 0; } @@ -190,7 +187,7 @@ int read_sleep(int fd, unsigned char *rxbuffer, int num ) { int n = 0; int i; - printf("read_sleep called with num = %i \n",num); + printf("serial:read_sleep called with num = %i \n",num); while(1) { ioctl(fd, FIONREAD, &bytes); /* get bytes in buffer */ @@ -200,18 +197,46 @@ int read_sleep(int fd, unsigned char *rxbuffer, int num ) { sleep(1); /* wait 1 second and try again */ } - printf("\n"); /* this should not block now */ n = read(fd,rxbuffer,num); /* grab num bytes from rig */ - printf("read_sleep data = "); - for(i=0; i