aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Vymetálek <pavel@vym.cz>2020-04-06 16:55:13 +0200
committerPavel Vymetálek <pavel@vym.cz>2020-04-06 16:55:13 +0200
commit4fb0f336df691b6fb55c38c1128b63d94fc4e1d3 (patch)
tree6fe29dff4e211dc8df923f91d0210c00677d6815
parent3159ad30681e16943b42f43ba6fc57fcb2d8e713 (diff)
downloadsercp-pc-0.3.3.tar.gz
Fix aborting while received fileinfo is corruptedv0.3.3
-rw-r--r--sercp.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/sercp.c b/sercp.c
index bd22357..42a5e01 100644
--- a/sercp.c
+++ b/sercp.c
@@ -202,6 +202,7 @@ void TestArgs (int argc, char *argv[])
}
+//*****************************************************************************
void FlushSerialPort() {
if (serial_fd) {
@@ -213,6 +214,20 @@ if (serial_fd) {
}
}
+//*****************************************************************************
+
+void CloseSerialPort() {
+ if (serial_fd) {
+ #ifdef _WIN32
+ PurgeComm(serial_fd, PURGE_RXABORT| PURGE_TXABORT | PURGE_RXCLEAR | PURGE_TXCLEAR);
+ CloseHandle(serial_fd);
+ #else
+ tcflush(serial_fd, TCIOFLUSH);
+ close (serial_fd);
+ #endif
+ }
+}
+
//*****************************************************************************
//
@@ -440,6 +455,9 @@ void sercpRecv(void) {
}
} else {
printf("Fileinfo corrupted. End...\n");
+ FlushSerialPort();
+ CloseSerialPort();
+ exit(EXIT_FAILURE);
break;
}
break;
@@ -739,17 +757,6 @@ int OpenUart() {
#endif
}
-void CloseSerialPort() {
- if (serial_fd) {
-#ifdef _WIN32
- PurgeComm(serial_fd, PURGE_RXABORT| PURGE_TXABORT | PURGE_RXCLEAR | PURGE_TXCLEAR);
- CloseHandle(serial_fd);
-#else
- tcflush(serial_fd, TCIOFLUSH);
- close (serial_fd);
-#endif
- }
-}