From cc0b5a25a21417d5adb36a9d565a061fbb7f1ae4 Mon Sep 17 00:00:00 2001 From: Pavel Vymetálek Date: Sun, 17 Jan 2021 14:49:15 +0100 Subject: Use gnu99 instead of gnu11, add O_NDELAY to serial port initialization --- CHANGELOG | 1 + Makefile | 8 ++++---- sercp.c | 17 ++++++++++++----- sercp.rc | 8 ++++---- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4fc540a..bcab710 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +2020-05-01 v0.3.5 use gnu99 instead of gnu11, add O_NDELAY to serial port initialization 2020-04-08 v0.3.4 removed hw flow control for mac and bsd 2020-04-06 v0.3.3 fixed progressbar for files smaller than 256 bytes 2020-04-05 v0.3.2 changes for __APPLE__ and BSD - still not work on aplle :( diff --git a/Makefile b/Makefile index a107f8c..8c60fcc 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ all: $(PROJECT) windows: $(PROJECT).w32 $(PROJECT).w64 sercp: $(PROJECT).c - $(CC) $(PROJECT).c -o $(PROJECT) -Wall -pedantic -MP -MD -std=gnu11 -Werror=format-security -O2 -Wformat + $(CC) $(PROJECT).c -o $(PROJECT) -Wall -pedantic -MP -MD -std=gnu99 -Werror=format-security -O2 -Wformat install: $(PROJECT) install -d $(DESTDIR)$(PREFIX)/bin/ @@ -18,17 +18,17 @@ install: $(PROJECT) sercp.w64: $(PROJECT).c rm -f $(PROJECT).res $(WINCC64_PREFIX)-windres -i $(PROJECT).rc --input-format=rc --codepage=65001 -o $(PROJECT).res -O coff - $(WINCC64_PREFIX)-gcc $(PROJECT).c $(PROJECT).res -o $(PROJECT).exe -Wall -pedantic -MP -MD -std=gnu11 -Werror=format-security -Wformat -O2 + $(WINCC64_PREFIX)-gcc $(PROJECT).c $(PROJECT).res -o $(PROJECT).exe -Wall -pedantic -MP -MD -std=gnu99 -Werror=format-security -Wformat -O2 $(WINCC64_PREFIX)-strip $(PROJECT).exe sercp.w32: $(PROJECT).c rm -f $(PROJECT).res $(WINCC_PREFIX)-windres -i $(PROJECT).rc --input-format=rc --codepage=65001 -o $(PROJECT).res -O coff - $(WINCC_PREFIX)-gcc $(PROJECT).res $(PROJECT).c -o $(PROJECT)32.exe -Wall -pedantic -MP -MD -std=gnu11 -Werror=format-security -Wformat -O2 + $(WINCC_PREFIX)-gcc $(PROJECT).res $(PROJECT).c -o $(PROJECT)32.exe -Wall -pedantic -MP -MD -std=gnu99 -Werror=format-security -Wformat -O2 $(WINCC_PREFIX)-strip $(PROJECT)32.exe debug: $(PROJECT).c - $(CC) $(PROJECT).c -o $(PROJECT) -Wall -pedantic -MP -MD -std=gnu11 -Werror=format-security -g -O0 -Wformat + $(CC) $(PROJECT).c -o $(PROJECT) -Wall -pedantic -MP -MD -std=gnu99 -Werror=format-security -g -O0 -Wformat clean: rm -f $(PROJECT) $(PROJECT).d $(PROJECT).o $(PROJECT).res $(PROJECT)*.d $(PROJECT)*.exe diff --git a/sercp.c b/sercp.c index 84d8992..f85871b 100644 --- a/sercp.c +++ b/sercp.c @@ -24,7 +24,6 @@ #include #include #include - #include #include #include #include @@ -65,7 +64,7 @@ #define FALSE 0 #define true 1 #define TRUE 1 -const char* _version = "v0.3.4"; +const char* _version = "v0.3.5"; // SERIAL FILE *tapout_fd = NULL; int is_outfile = 0; @@ -86,6 +85,10 @@ int scp = 0; int is_scp_read = 0; int is_continue = 1; +// prototypes + +void sleep_ms(int milliseconds); + char SERIALDEVICE[128] = { #ifdef _WIN32 "\\\\.\\COM1" @@ -169,7 +172,7 @@ void TestArgs (int argc, char *argv[]) #else sprintf(SERIALDEVICE, "%s", optarg); #endif - printf ("Serial port: %s\n", SERIALDEVICE); +// printf ("Serial port: %s\n", SERIALDEVICE); break; case 'b': baud_rate = atoi(optarg); @@ -204,6 +207,7 @@ void TestArgs (int argc, char *argv[]) void FlushSerialPort() { if (serial_fd) { + sleep_ms(20); #ifdef _WIN32 PurgeComm(serial_fd, PURGE_RXABORT| PURGE_TXABORT | PURGE_RXCLEAR | PURGE_TXCLEAR); #else @@ -652,6 +656,8 @@ void sercpSend(void) { } } printf("\nFile sent...\n"); + // FIXME na __APPLE__ tady pomaha pockat + // sleep_ms(5000); fclose(tap_fd); } @@ -699,13 +705,14 @@ int OpenUart() { #else struct termios oldtio, newtio; /* open the device to be non-blocking (read will return immediatly) */ - serial_fd = open(SERIALDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + serial_fd = open(SERIALDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK | O_NDELAY); if (serial_fd < 0) { perror(SERIALDEVICE); return(-1); } tcgetattr(serial_fd, &oldtio); /* save current port settings */ bzero(&newtio, sizeof (newtio)); + cfmakeraw(&newtio); switch (baud_rate){ case 115200: newtio.c_cflag = B115200; @@ -736,7 +743,6 @@ int OpenUart() { newtio.c_cflag = B38400; break; } - cfmakeraw(&newtio); cfsetspeed(&newtio, baud_rate); #if defined (__APPLE__) || defined (BSD) // newtio.c_cflag |= CS8 | CLOCAL | CREAD | CCTS_OFLOW | CRTS_IFLOW; @@ -751,6 +757,7 @@ int OpenUart() { newtio.c_cc[VMIN] = 0; newtio.c_cc[VTIME] = 0; tcsetattr(serial_fd, TCSANOW, &newtio); + sleep_ms(20); tcflush(serial_fd, TCIOFLUSH); return 0; #endif diff --git a/sercp.rc b/sercp.rc index 1f53adc..038e212 100644 --- a/sercp.rc +++ b/sercp.rc @@ -1,8 +1,8 @@ // RC file, codepage utf-8 !!!!! #include // include for version info constants 1 VERSIONINFO -FILEVERSION 0,3,4,0 -PRODUCTVERSION 0,3,4,0 +FILEVERSION 0,3,5,0 +PRODUCTVERSION 0,3,5,0 FILETYPE VFT_APP { BLOCK "StringFileInfo" @@ -10,14 +10,14 @@ FILETYPE VFT_APP BLOCK "040904E4" { VALUE "CompanyName", "vym.cz" - VALUE "FileVersion", "0.3.4" + VALUE "FileVersion", "0.3.5" VALUE "FileDescription", "sercp - serial copy for ZX Spectrum" VALUE "InternalName", "sercp" VALUE "LegalCopyright", "GNU GPL v3 or above" VALUE "LegalTrademarks", "Pavel Vymetálek" VALUE "OriginalFilename", "sercp" VALUE "ProductName", "sercp" - VALUE "ProductVersion", "0.3.4" + VALUE "ProductVersion", "0.3.5" VALUE "Build environment", "Linux: Mingw64, x86_64" } } -- cgit