Fix xymodem error print outs

This commit is contained in:
Martin Lund 2024-04-10 20:04:28 +02:00
parent d8fb1ab0ca
commit 78f96bd32c
2 changed files with 26 additions and 12 deletions

View file

@ -80,6 +80,19 @@ extern char ansi_format[];
} \ } \
} }
#define tio_error_print(format, args...) \
{ \
if (!option.mute) \
{ \
if (print_tainted) \
putchar('\n'); \
if (option.color < 0) \
fprintf (stdout, "\r[%s] Error: " format "\r\n", timestamp_current_time(), ## args); \
else \
ansi_printf("[%s] Error: " format, timestamp_current_time(), ## args); \
} \
}
#define tio_printf(format, args...) \ #define tio_printf(format, args...) \
{ \ { \
if (!option.mute) \ if (!option.mute) \

View file

@ -20,6 +20,7 @@
#include <sys/poll.h> #include <sys/poll.h>
#include <termios.h> #include <termios.h>
#include "xymodem.h" #include "xymodem.h"
#include "print.h"
#define SOH 0x01 #define SOH 0x01
#define STX 0x02 #define STX 0x02
@ -105,7 +106,7 @@ static int xmodem_1k(int sio, const void *data, size_t len, int seq)
continue; continue;
} }
else if (rc < 0) { else if (rc < 0) {
perror("Read sync from serial failed"); tio_error_print("Read sync from serial failed");
return ERR; return ERR;
} }
} }
@ -138,7 +139,7 @@ static int xmodem_1k(int sio, const void *data, size_t len, int seq)
usleep(1000); usleep(1000);
continue; continue;
} }
perror("Write packet to serial failed"); tio_error_print("Write packet to serial failed");
return ERR; return ERR;
} }
from += rc; from += rc;
@ -157,7 +158,7 @@ static int xmodem_1k(int sio, const void *data, size_t len, int seq)
return ERR; return ERR;
rc = serial_poll(sio, &resp, 1, 50); rc = serial_poll(sio, &resp, 1, 50);
if (rc < 0) { if (rc < 0) {
perror("Read ack/nak from serial failed"); tio_error_print("Read ack/nak from serial failed");
return ERR; return ERR;
} else if(rc > 0) { } else if(rc > 0) {
break; break;
@ -187,14 +188,14 @@ static int xmodem_1k(int sio, const void *data, size_t len, int seq)
if (key_hit) if (key_hit)
return ERR; return ERR;
if (write(sio, EOT, 1) < 0) { if (write(sio, EOT, 1) < 0) {
perror("Write EOT to serial failed"); tio_error_print("Write EOT to serial failed");
return ERR; return ERR;
} }
write(STDOUT_FILENO, "|", 1); write(STDOUT_FILENO, "|", 1);
/* 1s timeout */ /* 1s timeout */
rc = serial_poll(sio, &resp, 1, 1000); rc = serial_poll(sio, &resp, 1, 1000);
if (rc < 0) { if (rc < 0) {
perror("Read from serial failed"); tio_error_print("Read from serial failed");
return ERR; return ERR;
} else if(rc == 0) { } else if(rc == 0) {
continue; continue;
@ -227,7 +228,7 @@ static int xmodem(int sio, const void *data, size_t len)
continue; continue;
} }
else if (rc < 0) { else if (rc < 0) {
perror("Read sync from serial failed"); tio_error_print("Read sync from serial failed");
return ERR; return ERR;
} }
} }
@ -260,7 +261,7 @@ static int xmodem(int sio, const void *data, size_t len)
usleep(1000); usleep(1000);
continue; continue;
} }
perror("Write packet to serial failed"); tio_error_print("Write packet to serial failed");
return ERR; return ERR;
} }
from += rc; from += rc;
@ -276,7 +277,7 @@ static int xmodem(int sio, const void *data, size_t len)
return ERR; return ERR;
rc = serial_poll(sio, &resp, 1, 50); rc = serial_poll(sio, &resp, 1, 50);
if (rc < 0) { if (rc < 0) {
perror("Read ack/nak from serial failed"); tio_error_print("Read ack/nak from serial failed");
return ERR; return ERR;
} else if(rc > 0) { } else if(rc > 0) {
break; break;
@ -306,14 +307,14 @@ static int xmodem(int sio, const void *data, size_t len)
if (key_hit) if (key_hit)
return ERR; return ERR;
if (write(sio, EOT, 1) < 0) { if (write(sio, EOT, 1) < 0) {
perror("Write EOT to serial failed"); tio_error_print("Write EOT to serial failed");
return ERR; return ERR;
} }
write(STDOUT_FILENO, "|", 1); write(STDOUT_FILENO, "|", 1);
/* 1s timeout */ /* 1s timeout */
rc = serial_poll(sio, &resp, 1, 1000); rc = serial_poll(sio, &resp, 1, 1000);
if (rc < 0) { if (rc < 0) {
perror("Read from serial failed"); tio_error_print("Read from serial failed");
return ERR; return ERR;
} else if(rc == 0) { } else if(rc == 0) {
continue; continue;
@ -336,7 +337,7 @@ int xymodem_send(int sio, const char *filename, modem_mode_t mode)
/* Open file, map into memory */ /* Open file, map into memory */
fd = open(filename, O_RDONLY); fd = open(filename, O_RDONLY);
if (fd < 0) { if (fd < 0) {
perror("Could not open file"); tio_error_print("Could not open file");
return ERR; return ERR;
} }
fstat(fd, &stat); fstat(fd, &stat);
@ -344,7 +345,7 @@ int xymodem_send(int sio, const char *filename, modem_mode_t mode)
buf = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0); buf = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
if (!buf) { if (!buf) {
close(fd); close(fd);
perror("Could not mmap file"); tio_error_print("Could not mmap file");
return ERR; return ERR;
} }