aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGergő J. Miklós2020-10-17 05:38:18 +0200
committerGergő J. Miklós2020-10-17 05:38:18 +0200
commit816738fff33ffe3d0654be755c25626b3f4d2772 (patch)
treeba23d21813f5ae797c9ae8afac92f81eb182db51
parent89402128bb7e993a375cf54476e3627826dc071c (diff)
downloadi2sensors-816738fff33ffe3d0654be755c25626b3f4d2772.tar.gz
i2sensors-816738fff33ffe3d0654be755c25626b3f4d2772.zip
i2sensors: error handling
-rw-r--r--src/main.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index 3ba3da3..b9eb4d0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -91,21 +91,23 @@ __uint8_t *xchg_data (__uint8_t *buf, __uint16_t wrlen, __uint16_t waitlen, _
if( funcs & I2C_FUNC_I2C ){
#endif
if(write(devicef, buf, 1) != 1){ //# write one byte to device
- fprintf (stderr, "I2C write error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__);
+ fprintf (stdout, "I2C write error: [NO: %d, MSG: %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
- fprintf (stderr, "I2C read error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__);
+ fprintf (stdout, "I2C read error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__);
+ exit(EXIT_FAILURE);
}
#ifdef WITH_I2C_SMBUS
} else if ( funcs && I2C_FUNC_SMBUS_WORD_DATA ){
if(i2c_smbus_write_byte(devicef, buf[0] ) < 0){ //# write one byte to device
- fprintf (stderr, "I2C write error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__);
+ fprintf (stdout, "I2C write error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__);
}
usleep(waitlen*1000); //# Wait 10ms for reading
if((data = i2c_smbus_read_word_data(devicef, buf[0])) < 0) { //# read the result
- fprintf (stderr, "I2C read error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__);
+ fprintf (stdout, "I2C read error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__);
+ exit(EXIT_FAILURE);
} else {
buf[0] = data & 0x0FF;
buf[1] = (data >> 8) & 0x0FF;
@@ -158,7 +160,7 @@ int main( int argc, char *argv[] ){
}
if (ioctl(devicef, I2C_FUNCS, &funcs) < 0) { //Get i2c device features
- fprintf (stderr, "\n\tAdapter function error [ERR: %d, MSG: %s] at %s, line %d. \n", errno, strerror(errno), __FILE__, __LINE__);
+ fprintf (stdout, "\n\tAdapter function error [ERR: %d, MSG: %s] at %s, line %d. \n", errno, strerror(errno), __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
@@ -170,7 +172,7 @@ int main( int argc, char *argv[] ){
if (ioctl(devicef, I2C_SLAVE_FORCE, addr) < 0){ //# Seeking/Opening the device on the Bus
//printf("\n\tCan't open i2c DEVICE, errno: %d\n\n",errno);
- fprintf (stderr, "\n\tCan't open i2c DEVICE! [ERR: %d, MSG: %s] at %s, line %d. \n", errno, strerror(errno), __FILE__, __LINE__);
+ fprintf (stdout, "\n\tCan't open i2c DEVICE! [ERR: %d, MSG: %s] at %s, line %d. \n", errno, strerror(errno), __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
} else {