From c658bf9a9e38731e08a0526972c0c911c1980c65 Mon Sep 17 00:00:00 2001 From: Pavel Vymetálek Date: Wed, 27 Feb 2019 09:49:13 +0100 Subject: Doplněn odkaz GNU/GPL, řízení toku RTS/CTS na Windows, doplěn .rc soubor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sercp.c | 63 ++++++++++++++++++++++++++++----------------------------------- 1 file changed, 28 insertions(+), 35 deletions(-) (limited to 'sercp.c') diff --git a/sercp.c b/sercp.c index dfa2eaf..0055716 100644 --- a/sercp.c +++ b/sercp.c @@ -1,11 +1,22 @@ - +/* + * sercp - serial copy for transfering file to/from ZX Spectrum 128 AY's RS232 + * Copyright (c) 2018-2019 Pavel Vymetalek + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version (GPL-3.0-or-later). + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #ifdef __WIN32 -// #include -// #include -// #include -// #include - #include #include #include @@ -109,6 +120,7 @@ void usage(void) { printf ("sercp %s (c)2018-2019 Pavel Vymetalek \n", _version); printf ("serial copy for transfering file to/from ZX Spectrum 128 AY's RS232\n"); printf ("Uses 1109bytes of fileinfo - blocks sums, filename, etc.\n"); + printf ("More info at https://vym.cz/sercp/\n"); printf ("Usage:\nsercp [-v] [-h] -d /dev/serial [-b baud_rate] [-w time] [-r] \n"); printf ("\t-v, --version\tShow version info\n"); printf ("\t-h, --help\tShow this text\n"); @@ -118,7 +130,7 @@ void usage(void) { printf ("\t-d, --device\tSerial communication device\n"); #endif printf ("\t-b, --baud\tSet the communication speed. Default 38400Bd\n"); - printf ("\t-w, --wait\tWaiting in milliseconds between transmitted blocks. Default is -w 800 milliseconds\n"); + printf ("\t-w, --wait\tWaiting in milliseconds between transmitted blocks.\n\t\t\tDefault is -w 800 ms\n"); printf ("\t-r, --read\tRead file from serial port\n"); } @@ -148,7 +160,6 @@ void TestArgs (int argc, char *argv[]) #ifdef __WIN32 sprintf(MODEMDEVICE, "\\\\.\\%s", optarg); #else -// strncpy(MODEMDEVICE, optarg, strlen(optarg)); sprintf(MODEMDEVICE, "%s", optarg); #endif printf ("Serial port: %s\n", MODEMDEVICE); @@ -203,15 +214,9 @@ void uSleep(int waitTime) { #endif } -// cross-platform sleep function void sleep_ms(int milliseconds) { #ifdef WIN32 Sleep(milliseconds); -// #elif _POSIX_C_SOURCE >= 199309L -// struct timespec ts; -// ts.tv_sec = milliseconds / 1000; -// ts.tv_nsec = (milliseconds % 1000) * 1000000; -// nanosleep(&ts, NULL); #else usleep(milliseconds * 1000); #endif @@ -473,16 +478,6 @@ void sercpRecv(void) { break; } // } - /*else if (length > 16384) { -#ifdef __WIN32 - ReadFile(serial_fd, p_buff, 16384, &ulNumBytes, NULL); - len = (uint16_t)ulNumBytes; -#else - len = read (serial_fd, p_buff, 16384); -#endif - printf("Nejaky bordel. Koncim...\n"); - break; - }*/ } } if (tapout_fd) { @@ -515,16 +510,12 @@ void sercpSend(void) { no = stat(sercp_file, &st); if (no != 0) { -// err = errno; -// error(1, err, "can't stat input file"); printf ("can't stat input file\n"); exit (EXIT_FAILURE); } tap_fd = fopen(sercp_file, "rb"); if (tap_fd == NULL) { -// err = errno; -// error(1, err, "can't open input file"); printf ("can't open input file\n"); exit (EXIT_FAILURE); } @@ -567,7 +558,6 @@ void sercpSend(void) { #endif printf("Fileinfo sent with filename: %s\n", bname); // TODO Cekat pauzu mezi bloky -// uSleep (wait_ms * 1000); sleep_ms(wait_ms); rewind(tap_fd); // prenaseny soubor na zacatek @@ -582,7 +572,6 @@ void sercpSend(void) { #ifdef __WIN32 WriteFile(serial_fd, (void*)p_buff, sent_size, &ulNumBytes, NULL); odeslano = (size_t)ulNumBytes; -// sleep_ms(wait_ms); #else odeslano = write (serial_fd, (void*)p_buff, sent_size); tcdrain(serial_fd); @@ -595,12 +584,16 @@ void sercpSend(void) { } DoProgress(overall_sent, st.st_size, PROGRESS_PERCENT); } -// uSleep (wait_ms * 1000); sleep_ms(wait_ms); file_len -= len; } - printf("\nFile sent...\n"); + if (is_continue) { + printf("\nFile sent...\n"); + } else { + printf("\nend...\n"); + } + fclose(tap_fd); } @@ -623,9 +616,10 @@ int OpenUart() { sDCB.fBinary = TRUE; sDCB.StopBits = ONESTOPBIT; sDCB.fAbortOnError = TRUE; - sDCB.fOutxCtsFlow = FALSE; sDCB.fOutxDsrFlow = FALSE; -// sDCB.fDtrControl = DTR_CONTROL_ENABLE; + sDCB.fDtrControl = DTR_CONTROL_DISABLE; + sDCB.fRtsControl = RTS_CONTROL_ENABLE; + sDCB.fOutxCtsFlow = TRUE; if (SetCommState(serial_fd, &sDCB) == 0) { return (-1); } @@ -633,7 +627,6 @@ int OpenUart() { if (GetCommTimeouts(serial_fd, &sCommTimeouts) == 0) { return (-1); } - sCommTimeouts.ReadIntervalTimeout = MAXDWORD; //80 sCommTimeouts.ReadTotalTimeoutConstant = 00; sCommTimeouts.ReadTotalTimeoutMultiplier = 00; -- cgit