From f8ae02cf6bad5c5c207aa2b2e9d5b2a5a1e8d3de Mon Sep 17 00:00:00 2001 From: Gergő J. Miklós Date: Sat, 10 Oct 2020 22:35:14 +0200 Subject: test --- src/main.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 383884d..2ff69a8 100644 --- a/src/main.c +++ b/src/main.c @@ -61,21 +61,29 @@ void print_help(void) { } void bus_err(int ern){ - printf("I2C communication(rd) error. errno: %d\n",errno); + //printf("I2C communication(rd) error. errno: %d\n",errno); + fprintf (stderr, "Internal error %d at %s, line %d. (function: %s/%s)", 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)", errno, __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."); - printf("errno: %d\n",errno); + fprintf (stderr, "I2C error (WR) %d at %s, line %d. (function: %s/%s)", errno, __FILE__, __LINE__, __func__, __FUNCTION__); + bus_err(errno); + bus_errr(0); } usleep(waitlen*1000); //# Wait 10ms for reading if(read(devicef, buf, rdlen) != rdlen) { //# read the result perror("I2C communication(rd) error."); - printf("errno: %d\n",errno); + fprintf (stderr, "I2C error (WR) %d at %s, line %d. (function: %s/%s)", errno, __FILE__, __LINE__, __func__, __FUNCTION__); + bus_err(errno); + bus_errr(0); } return buf; } -- cgit v1.2.3