From 3c8188b0070131a5b0eddb9a57dd54722d965b4c Mon Sep 17 00:00:00 2001 From: Pavel Vymetálek Date: Sun, 5 Apr 2020 14:22:31 +0200 Subject: Fix remaining length of data while read fileinfo --- TODO | 2 ++ sercp.c | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index d376bf1..0927f36 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,5 @@ +2020-04-04 + - add test serial line - show CTS, RTS lines state 2019-09-03 - fix progressbar for files smaller than 16kB diff --git a/sercp.c b/sercp.c index 234a3fb..07054f4 100644 --- a/sercp.c +++ b/sercp.c @@ -65,7 +65,6 @@ #define FALSE 0 #define true 1 #define TRUE 1 - const char* _version = "v0.3.2"; // SERIAL FILE *tapout_fd = NULL; @@ -369,7 +368,7 @@ uint32_t GetOverallLen(FILEINFO *p_fi) { void sercpRecv(void) { int recv_phase = 0; // 0 - fileinfo, 1 - 16kiB block, 2 - last block uint8_t block_index = 0; - uint16_t len; + size_t len = 0; uint16_t length = 0; uint16_t expected_len = 0; uint32_t overall_length = 0; // overall length of file @@ -404,7 +403,7 @@ void sercpRecv(void) { len = (uint16_t) ulNumBytes; #else sleep_ms(10); - len = read (serial_fd, p_buff, sizeof(fileinfo)); + len = read (serial_fd, p_buff, sizeof(fileinfo)-length); #endif p_buff += len; length += len; @@ -441,6 +440,7 @@ void sercpRecv(void) { len = read (serial_fd, p_buff, sizeof(fileinfo)); #endif printf("Received unknown data. End...\n"); + tcflush(serial_fd, TCIOFLUSH); exit (EXIT_FAILURE); break; } @@ -539,7 +539,7 @@ void sercpSend(void) { } // FIXME do this more sophisticated and crossplatform, for example by __SIZE_WIDTH__ -#if defined (__linux__) || defined(_WIN32) +#if defined (__linux__) || defined(_WIN32) || defined (BSD) printf ("File %s, length: %ld\n", sercp_file, st.st_size); #else printf ("File %s, length: %lld\n", sercp_file, st.st_size); @@ -707,11 +707,12 @@ int OpenUart() { } cfmakeraw(&newtio); cfsetspeed(&newtio, baud_rate); -#if defined __APPLE__ || defined BSD +#if defined (__APPLE__) || defined (BSD) newtio.c_cflag = CS8 | CLOCAL | CREAD | CCTS_OFLOW | CRTS_IFLOW; // CSTOPB - two stop bits NOT #else - newtio.c_cflag = CS8 | CLOCAL | CREAD | CRTSCTS; // CSTOPB - two stop bits NOT + newtio.c_cflag = CS8 | CLOCAL | CREAD | CRTSCTS; #endif + printf ("Serial device: %s, communication speed is: %d Bd\n", MODEMDEVICE, baud_rate); newtio.c_cc[VMIN] = 1; newtio.c_cc[VTIME] = 0; -- cgit