Program for transferring files over a serial port using the Y-Modem (or X-Modem) transmission protocol. More...
|
Classes | |
| class | InFile |
| class | OutFile |
Defines | |
| #define | DEFAULT_BAUD 115200 |
| #define | DEFAULT_TIMEOUT 30 |
| #define | DEFAULT_LOG_TIMEOUT 10 |
| #define | MAX_LOG_END_STRING_LENGTH 128 |
| #define | STRINGIFY2(a) #a |
| #define | STRINGIFY(a) STRINGIFY2(a) |
Enumerations | |
| enum | Error { ErrorNoMemory = -500, ErrorLogFileError = -501 } |
Functions | |
| void | Help () |
| void | UsageError (const char *format,...) |
| void | Error (int error, const char *format,...) |
| bool | GetIntArg (const char *argStr, unsigned &arg) |
| Parse an integer command-line argument. | |
| bool | GetTimeoutArg (const char *argStr, unsigned &arg) |
| Parse an command-line timeout argument. | |
| void | ParseArgs (int argc, char **argv) |
| void | CaptureLog (SerialPort *port) |
| void | Send (SerialPort *port) |
| void | Receive (SerialPort *port) |
| int | main (int argc, char **argv) |
Variables | |
| const char * | ProgramName |
| unsigned | PortNum = DEFAULT_PORT |
| unsigned | PortBaud = DEFAULT_BAUD |
| unsigned | Timeout = DEFAULT_TIMEOUT*1000 |
| bool | XModemFlag = false |
| bool | CrcFlag = false |
| bool | GModeFlag = false |
| bool | SendFlag = false |
| bool | ReceiveFlag = false |
| const char * | FileName = 0 |
| const char * | DstFileName = 0 |
| const char * | LogFileName = 0 |
| unsigned | LogTimeout = DEFAULT_LOG_TIMEOUT*1000 |
| const char * | LogEndString = 0 |
| size_t | LogEndStringLength = 0 |
| bool | LogEcho = false |
| FILE * | LogFile = 0 |
Program for transferring files over a serial port using the Y-Modem (or X-Modem) transmission protocol.
This acts as a test program for the Y-Modem implementation and is a useful utility in its own right. It also supports receiving a 'log' after transmitting files; this can be used when sending a file to a development board and receiving instrumentation output which comes back on same port.
Usage: ymodem [OPTION]... FILE [DST-FILE]
-s[y|x|k] Send file.
If 'y' is specifieied Y-Modem protocol is used. (Default)
If 'x' is specifieied X-Modem protocol is used.
If 'k' is specifieied X-Modem 1K protocol is used.
-r[y|g|x|c] Receive file.
If 'y' is specifieied Y-Modem protocol is used. (Default)
If 'g' is specifieied Y-Modem G protocol is used.
If 'x' is specifieied X-Modem protocol is used.
If 'c' is specifieied X-Modem CRC protocol is used.
-pPORT Use communications port PORT.
-bBAUD Set baud rate for port to BAUD.
-tTIMEOUT Set timeout for transfer start (in seconds).
-lfLOG Capture log after transfer and write it to file LOG.
-ltLOGTIMEOUT Timeout for log capture (in seconds).
-lxSTRING End log capture when STRING is received.
-le Echo the captured log to STDOUT.FILE is optional when receiving a file by Y-Modem: options -ry or -rg DST-FILE is the name sent to receiver when using Y-Modem. Default is FILE.
Program exit values:
-le option to echo the captured log to STDOUT. | #define DEFAULT_BAUD 115200 |
Default value for PortBaud
Definition at line 94 of file ymodem_main.cpp.
| #define DEFAULT_TIMEOUT 30 |
Default value (in seconds) for Timeout
Definition at line 95 of file ymodem_main.cpp.
| #define DEFAULT_LOG_TIMEOUT 10 |
Default value (in seconds) for LogTimeout
Definition at line 96 of file ymodem_main.cpp.
| #define MAX_LOG_END_STRING_LENGTH 128 |
Maximum length for LogEndString
Definition at line 97 of file ymodem_main.cpp.
| #define STRINGIFY2 | ( | a | ) | #a |
Helper for STRINGIFY
Definition at line 128 of file ymodem_main.cpp.
| #define STRINGIFY | ( | a | ) | STRINGIFY2(a) |
Convert a into a quoted string
Definition at line 129 of file ymodem_main.cpp.
| enum Error |
Error values specifiec to this program.
| ErrorNoMemory |
Insufficient memory |
| ErrorLogFileError |
Error occured creating or writing to 'capture log' |
Definition at line 122 of file ymodem_main.cpp.
| void Help | ( | ) |
Display help message, then exit.
Definition at line 134 of file ymodem_main.cpp.
| void UsageError | ( | const char * | format, | |
| ... | ||||
| ) |
Print message when a bad command line is detected. Then do exit(1); .
| format | Format string a la printf. | |
| ... | Arguments for format sting, a la printf. |
Definition at line 170 of file ymodem_main.cpp.
| void Error | ( | int | error, | |
| const char * | format, | |||
| ... | ||||
| ) |
Print message when a error is detected. Then do exit(error); .
| error | The error number. | |
| format | Format string a la printf. | |
| ... | Arguments for format sting, a la printf. |
Definition at line 189 of file ymodem_main.cpp.
| bool GetIntArg | ( | const char * | argStr, | |
| unsigned & | arg | |||
| ) |
Parse an integer command-line argument.
This converts a decimal string into an unsigned integer.
| argStr | The string to convert. | |
| [out] | arg | The value of the converted number. |
Definition at line 212 of file ymodem_main.cpp.
| bool GetTimeoutArg | ( | const char * | argStr, | |
| unsigned & | arg | |||
| ) |
Parse an command-line timeout argument.
This converts a decimal string representing a number of seconds into an unsigned integer representing milliseconds.
| argStr | The string to convert. | |
| [out] | arg | The value of the converted timeout. |
Definition at line 234 of file ymodem_main.cpp.
| void ParseArgs | ( | int | argc, | |
| char ** | argv | |||
| ) |
Parse all of the command-line arguments.
| argc | The number of arguments. | |
| argv | Array of argument strings. |
Definition at line 253 of file ymodem_main.cpp.
| void CaptureLog | ( | SerialPort * | port | ) |
Capture data from the serial port and write it to the 'capture log' file. Log capture ends either when no data has been received for LogTimeout milliseconds, or when characters matching LogEndString are found.
| port | The serial port to receive data from. |
Definition at line 579 of file ymodem_main.cpp.
| void Send | ( | SerialPort * | port | ) |
Send the file.
| port | The serial port to use. |
Definition at line 660 of file ymodem_main.cpp.
| void Receive | ( | SerialPort * | port | ) |
Receive a file.
| port | The serial port to use. |
Definition at line 692 of file ymodem_main.cpp.
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Main function.
| argc | The number of arguments. | |
| argv | Array of argument strings. |
Definition at line 732 of file ymodem_main.cpp.
| const char* ProgramName |
Name of this program
Definition at line 100 of file ymodem_main.cpp.
| unsigned PortNum = DEFAULT_PORT |
Serial port number to use
Definition at line 101 of file ymodem_main.cpp.
| unsigned PortBaud = DEFAULT_BAUD |
Baud rate for serial port
Definition at line 102 of file ymodem_main.cpp.
| unsigned Timeout = DEFAULT_TIMEOUT*1000 |
Timeout (in milliseconds) before aborting transfer
Definition at line 103 of file ymodem_main.cpp.
| bool XModemFlag = false |
True for X-Modem, false for Y-Modem
Definition at line 104 of file ymodem_main.cpp.
| bool CrcFlag = false |
True for X-Modem CRC mode
Definition at line 105 of file ymodem_main.cpp.
| bool GModeFlag = false |
True for Y-Modem G mode
Definition at line 107 of file ymodem_main.cpp.
| bool SendFlag = false |
True if sending file
Definition at line 108 of file ymodem_main.cpp.
| bool ReceiveFlag = false |
True if receiving file
Definition at line 109 of file ymodem_main.cpp.
| const char* FileName = 0 |
Name of file to be transferred
Definition at line 110 of file ymodem_main.cpp.
| const char* DstFileName = 0 |
File name to send to receiver in Y-Modem transer
Definition at line 111 of file ymodem_main.cpp.
| const char* LogFileName = 0 |
Name of file for 'capture log'
Definition at line 112 of file ymodem_main.cpp.
| unsigned LogTimeout = DEFAULT_LOG_TIMEOUT*1000 |
Timeout (in milliseconds) before aborting 'capture log'
Definition at line 113 of file ymodem_main.cpp.
| const char* LogEndString = 0 |
String to terminate 'capture log'
Definition at line 114 of file ymodem_main.cpp.
Length of LogEndString
Definition at line 115 of file ymodem_main.cpp.
| bool LogEcho = false |
True if log should be echoed to STDOUT
Definition at line 116 of file ymodem_main.cpp.
| FILE* LogFile = 0 |
Handle of the 'capture log' file
Definition at line 570 of file ymodem_main.cpp.
1.6.1