serial_unix: Return instead of exit in case of error.

This commit is contained in:
Uwe Bonnes 2020-05-02 16:35:25 +02:00
parent ef558eebb8
commit 921c23eb74
1 changed files with 21 additions and 21 deletions

View File

@ -40,7 +40,7 @@ static int set_interface_attribs(void)
struct termios tty; struct termios tty;
memset (&tty, 0, sizeof tty); memset (&tty, 0, sizeof tty);
if (tcgetattr (fd, &tty) != 0) { if (tcgetattr (fd, &tty) != 0) {
fprintf(stderr,"error %d from tcgetattr", errno); printf("error %d from tcgetattr", errno);
return -1; return -1;
} }
@ -62,7 +62,7 @@ static int set_interface_attribs(void)
tty.c_cflag &= ~CRTSCTS; tty.c_cflag &= ~CRTSCTS;
if (tcsetattr (fd, TCSANOW, &tty) != 0) { if (tcsetattr (fd, TCSANOW, &tty) != 0) {
fprintf(stderr,"error %d from tcsetattr", errno); printf("error %d from tcsetattr", errno);
return -1; return -1;
} }
return 0; return 0;
@ -77,7 +77,7 @@ int serial_open(BMP_CL_OPTIONS_t *cl_opts, char *serial)
struct dirent *dp; struct dirent *dp;
DIR *dir = opendir(DEVICE_BY_ID); DIR *dir = opendir(DEVICE_BY_ID);
if (!dir) { if (!dir) {
fprintf(stderr, "No serial device found\n"); printf("No serial device found\n");
return -1; return -1;
} }
int num_devices = 0; int num_devices = 0;
@ -95,24 +95,24 @@ int serial_open(BMP_CL_OPTIONS_t *cl_opts, char *serial)
} }
closedir(dir); closedir(dir);
if ((num_devices == 0) && (num_total == 0)){ if ((num_devices == 0) && (num_total == 0)){
fprintf(stderr, "No BMP probe found\n"); printf("No BMP probe found\n");
return -1; return -1;
} else if (num_devices != 1) { } else if (num_devices != 1) {
fprintf(stderr, "Available Probes:\n"); printf("Available Probes:\n");
dir = opendir(DEVICE_BY_ID); dir = opendir(DEVICE_BY_ID);
if (dir) { if (dir) {
while ((dp = readdir(dir)) != NULL) { while ((dp = readdir(dir)) != NULL) {
if ((strstr(dp->d_name, BMP_IDSTRING)) && if ((strstr(dp->d_name, BMP_IDSTRING)) &&
(strstr(dp->d_name, "-if00"))) (strstr(dp->d_name, "-if00")))
fprintf(stderr, "%s\n", dp->d_name); printf("%s\n", dp->d_name);
} }
closedir(dir); closedir(dir);
if (serial) if (serial)
fprintf(stderr, "Do no match given serial \"%s\"\n", serial); printf("Do no match given serial \"%s\"\n", serial);
else else
fprintf(stderr, "Select Probe with -s <(Partial) Serial Number\n"); printf("Select Probe with -s <(Partial) Serial Number\n");
} else { } else {
fprintf(stderr, "Could not opendir %s: %s\n", name, strerror(errno)); printf("Could not opendir %s: %s\n", name, strerror(errno));
} }
return -1; return -1;
} }
@ -121,7 +121,7 @@ int serial_open(BMP_CL_OPTIONS_t *cl_opts, char *serial)
} }
fd = open(name, O_RDWR | O_SYNC | O_NOCTTY); fd = open(name, O_RDWR | O_SYNC | O_NOCTTY);
if (fd < 0) { if (fd < 0) {
fprintf(stderr,"Couldn't open serial port %s\n", name); printf("Couldn't open serial port %s\n", name);
return -1; return -1;
} }
/* BMP only offers an USB-Serial connection with no real serial /* BMP only offers an USB-Serial connection with no real serial
@ -143,8 +143,8 @@ int platform_buffer_write(const uint8_t *data, int size)
printf("%s\n",data); printf("%s\n",data);
s = write(fd, data, size); s = write(fd, data, size);
if (s < 0) { if (s < 0) {
fprintf(stderr, "Failed to write\n"); printf("Failed to write\n");
exit(-2); return(-2);
} }
return size; return size;
@ -170,12 +170,12 @@ int platform_buffer_read(uint8_t *data, int maxsize)
ret = select(fd + 1, &rset, NULL, NULL, &tv); ret = select(fd + 1, &rset, NULL, NULL, &tv);
if (ret < 0) { if (ret < 0) {
fprintf(stderr,"Failed on select\n"); printf("Failed on select\n");
exit(-4); return(-3);
} }
if(ret == 0) { if(ret == 0) {
fprintf(stderr,"Timeout on read RESP\n"); printf("Timeout on read RESP\n");
exit(-3); return(-4);
} }
s = read(fd, c, 1); s = read(fd, c, 1);
@ -187,12 +187,12 @@ int platform_buffer_read(uint8_t *data, int maxsize)
FD_SET(fd, &rset); FD_SET(fd, &rset);
ret = select(fd + 1, &rset, NULL, NULL, &tv); ret = select(fd + 1, &rset, NULL, NULL, &tv);
if (ret < 0) { if (ret < 0) {
fprintf(stderr,"Failed on select\n"); printf("Failed on select\n");
exit(-4); exit(-4);
} }
if(ret == 0) { if(ret == 0) {
fprintf(stderr,"Timeout on read\n"); printf("Timeout on read\n");
exit(-3); return(-5);
} }
s = read(fd, c, 1); s = read(fd, c, 1);
if (*c==REMOTE_EOM) { if (*c==REMOTE_EOM) {
@ -205,7 +205,7 @@ int platform_buffer_read(uint8_t *data, int maxsize)
} }
}while ((s >= 0) && ((c - data) < maxsize)); }while ((s >= 0) && ((c - data) < maxsize));
fprintf(stderr,"Failed to read\n"); printf("Failed to read\n");
exit(-3); return(-6);
return 0; return 0;
} }