apps/system/zmodem: Switch to the raw mode before transfer and restore to the original setting after finishing the transfer.

This commit is contained in:
Xiang Xiao 2019-01-27 07:09:31 -06:00 committed by Gregory Nutt
parent 72b19dfbba
commit dc54f28ff3
4 changed files with 70 additions and 7 deletions

View File

@ -84,6 +84,9 @@ int rz_main(int argc, FAR char **argv)
FAR const char *devname = CONFIG_SYSTEM_ZMODEM_DEVNAME; FAR const char *devname = CONFIG_SYSTEM_ZMODEM_DEVNAME;
FAR const char *pathname = CONFIG_SYSTEM_ZMODEM_MOUNTPOINT; FAR const char *pathname = CONFIG_SYSTEM_ZMODEM_MOUNTPOINT;
int exitcode = EXIT_FAILURE; int exitcode = EXIT_FAILURE;
#ifdef CONFIG_SERIAL_TERMIOS
struct termios saveterm;
#endif
int option; int option;
int ret; int ret;
int fd; int fd;
@ -136,10 +139,20 @@ int rz_main(int argc, FAR char **argv)
goto errout; goto errout;
} }
#ifdef CONFIG_SERIAL_TERMIOS
/* Save the current terminal setting */
tcgetattr(fd, &saveterm);
/* Enable the raw mode */
zm_rawmode(fd);
#ifdef CONFIG_SYSTEM_ZMODEM_FLOWC #ifdef CONFIG_SYSTEM_ZMODEM_FLOWC
/* Enable hardware Rx/Tx flow control */ /* Enable hardware Rx/Tx flow control */
zm_flowc(fd); zm_flowc(fd);
#endif
#endif #endif
/* Get the Zmodem handle */ /* Get the Zmodem handle */
@ -166,12 +179,18 @@ errout_with_zmodem:
(void)zmr_release(handle); (void)zmr_release(handle);
errout_with_device: errout_with_device:
#ifdef CONFIG_SERIAL_TERMIOS
#ifdef CONFIG_SYSTEM_ZMODEM_FLOWC #ifdef CONFIG_SYSTEM_ZMODEM_FLOWC
/* Flush the serial output to assure do not hang trying to drain it */ /* Flush the serial output to assure do not hang trying to drain it */
tcflush(fd, TCIOFLUSH); tcflush(fd, TCIOFLUSH);
#endif #endif
/* Restore the saved terminal setting */
tcsetattr(fd, TCSANOW, &saveterm);
#endif
(void)close(fd); (void)close(fd);
errout: errout:

View File

@ -106,6 +106,9 @@ int sz_main(int argc, FAR char **argv)
bool skip = false; bool skip = false;
long tmp; long tmp;
int exitcode = EXIT_FAILURE; int exitcode = EXIT_FAILURE;
#ifdef CONFIG_SERIAL_TERMIOS
struct termios saveterm;
#endif
int option; int option;
int ret; int ret;
int fd; int fd;
@ -188,10 +191,20 @@ int sz_main(int argc, FAR char **argv)
goto errout; goto errout;
} }
#ifdef CONFIG_SERIAL_TERMIOS
/* Save the current terminal setting */
tcgetattr(fd, &saveterm);
/* Enable the raw mode */
zm_rawmode(fd);
#ifdef CONFIG_SYSTEM_ZMODEM_FLOWC #ifdef CONFIG_SYSTEM_ZMODEM_FLOWC
/* Enable hardware Rx/Tx flow control */ /* Enable hardware Rx/Tx flow control */
zm_flowc(fd); zm_flowc(fd);
#endif
#endif #endif
/* Get the Zmodem handle */ /* Get the Zmodem handle */
@ -265,12 +278,18 @@ errout_with_zmodem:
(void)zms_release(handle); (void)zms_release(handle);
errout_with_device: errout_with_device:
#ifdef CONFIG_SYSTEM_ZMODEM_FLOWC #ifdef CONFIG_SERIAL_TERMIOS
# ifdef CONFIG_SYSTEM_ZMODEM_FLOWC
/* Flush the serial output to assure do not hang trying to drain it */ /* Flush the serial output to assure do not hang trying to drain it */
tcflush(fd, TCIOFLUSH); tcflush(fd, TCIOFLUSH);
#endif #endif
/* Restore the saved terminal setting */
tcsetattr(fd, TCSANOW, &saveterm);
#endif
(void)close(fd); (void)close(fd);
errout: errout:

View File

@ -578,15 +578,24 @@ int zm_writefile(int fd, FAR const uint8_t *buffer, size_t buflen, bool zcnl);
uint32_t zm_filecrc(FAR struct zm_state_s *pzm, FAR const char *filename); uint32_t zm_filecrc(FAR struct zm_state_s *pzm, FAR const char *filename);
/****************************************************************************
* Name: zm_rawmode
*
* Description:
* Set the terminal to the raw mode
*
****************************************************************************/
#ifdef CONFIG_SERIAL_TERMIOS
void zm_rawmode(int fd);
#endif
/**************************************************************************** /****************************************************************************
* Name: zm_flowc * Name: zm_flowc
* *
* Description: * Description:
* Enable hardware Rx/Tx flow control. * Enable hardware Rx/Tx flow control.
* *
* REVISIT: Consider returning the original termios settings so that they
* could be restored with rx/sz exits.
*
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_SYSTEM_ZMODEM_FLOWC #ifdef CONFIG_SYSTEM_ZMODEM_FLOWC

View File

@ -473,15 +473,31 @@ uint32_t zm_filecrc(FAR struct zm_state_s *pzm, FAR const char *filename)
return ~crc; return ~crc;
} }
/****************************************************************************
* Name: zm_rawmode
*
* Description:
* Set the terminal to the raw mode
*
****************************************************************************/
#ifdef CONFIG_SERIAL_TERMIOS
void zm_rawmode(int fd)
{
struct termios term;
tcgetattr(fd, &term);
cfmakeraw(&term);
tcsetattr(fd, TCSANOW, &term);
}
#endif
/**************************************************************************** /****************************************************************************
* Name: zm_flowc * Name: zm_flowc
* *
* Description: * Description:
* Enable hardware Rx/Tx flow control. * Enable hardware Rx/Tx flow control.
* *
* REVISIT: Consider returning the original termios settings so that they
* could be restored with rx/sz exits.
*
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_SYSTEM_ZMODEM_FLOWC #ifdef CONFIG_SYSTEM_ZMODEM_FLOWC