diff options
author | Pavel Vymetálek <pavel@vym.cz> | 2020-04-05 14:22:31 +0200 |
---|---|---|
committer | Pavel Vymetálek <pavel@vym.cz> | 2020-04-05 14:22:31 +0200 |
commit | 3c8188b0070131a5b0eddb9a57dd54722d965b4c (patch) | |
tree | d927c469d5feab20af4aee1cb97007228566cf26 /sercp.c | |
parent | 3aae9607fcf3127a044d1e30fa2a8904f81f6b7b (diff) | |
download | sercp-pc-3c8188b0070131a5b0eddb9a57dd54722d965b4c.tar.gz |
Fix remaining length of data while read fileinfo
Diffstat (limited to 'sercp.c')
-rw-r--r-- | sercp.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -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; |