From ccd5baad28186f67c3466e5caf20c88ea3254bd8 Mon Sep 17 00:00:00 2001 From: Gergő J. Miklós Date: Sat, 10 Oct 2020 23:46:35 +0200 Subject: error handling --- src/main.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 5919421..4d4f4ca 100644 --- a/src/main.c +++ b/src/main.c @@ -19,9 +19,9 @@ #include "hih61xx.h" #include "hmc5883.h" -#define VERSION 1.27 +#define VERSION 1.28 #ifndef _BUILD_TIME_ - #define _BUILD_TIME_ __DATE__" "__TIME__ + #define _BUILD_TIME_ __DATE__" "__TIME__ #endif // extern void lm75_print_help(void); @@ -65,29 +65,21 @@ void print_help(void) { } void bus_err(int ern){ - //printf("I2C communication(rd) error. errno: %d\n",errno); - fprintf (stderr, "Internal error %d at %s, line %d. (function: %s/%s)\n", ern, __FILE__, __LINE__, __func__, __FUNCTION__); -} -void bus_errr(int ern){ - //printf("I2C communication(rd) error. errno: %d\n",errno); - fprintf (stderr, "Internal error %d at %s, line %d. (function: %s/%s)\n", errno, __FILE__, __LINE__, __func__, __FUNCTION__); + printf("I2C communication(rd) error. errno: %d\n",errno); + //fprintf (stderr, "Internal error %d at %s, line %d. (function: %s/%s)\n", ern, __FILE__, __LINE__, __func__, __FUNCTION__); } uchar *xchg_data (uchar *buf, uint16 wrlen, uint16 waitlen, uint16 rdlen){ //# [buf] = 32 byte if(write(devicef, buf, 1) != 1){ //# write one byte to device - perror("I2C communication(wrr) error."); - fprintf (stderr, "I2C error (WR) %d at %s, line %d. (function: %s/%s)\n", errno, __FILE__, __LINE__, __func__, __FUNCTION__); - bus_err(errno); - bus_errr(0); + //perror("I2C communication(wrr) error."); + fprintf (stderr, "I2C communication(WR) error: [%d, %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__); } usleep(waitlen*1000); //# Wait 10ms for reading if(read(devicef, buf, rdlen) != rdlen) { //# read the result - perror("I2C communication(rd) error."); - fprintf (stderr, "I2C error (WR) %d at %s, line %d. (function: %s/%s)\n", errno, __FILE__, __LINE__, __func__, __FUNCTION__); - bus_err(errno); - bus_errr(0); + //perror("I2C communication(rd) error."); + fprintf (stderr, "I2C communication(RD) error: [%d, %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__); } return buf; } -- cgit v1.2.3