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:
parent
72b19dfbba
commit
dc54f28ff3
system/zmodem
@ -84,6 +84,9 @@ int rz_main(int argc, FAR char **argv)
|
||||
FAR const char *devname = CONFIG_SYSTEM_ZMODEM_DEVNAME;
|
||||
FAR const char *pathname = CONFIG_SYSTEM_ZMODEM_MOUNTPOINT;
|
||||
int exitcode = EXIT_FAILURE;
|
||||
#ifdef CONFIG_SERIAL_TERMIOS
|
||||
struct termios saveterm;
|
||||
#endif
|
||||
int option;
|
||||
int ret;
|
||||
int fd;
|
||||
@ -136,10 +139,20 @@ int rz_main(int argc, FAR char **argv)
|
||||
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
|
||||
/* Enable hardware Rx/Tx flow control */
|
||||
|
||||
zm_flowc(fd);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Get the Zmodem handle */
|
||||
@ -166,12 +179,18 @@ errout_with_zmodem:
|
||||
(void)zmr_release(handle);
|
||||
|
||||
errout_with_device:
|
||||
#ifdef CONFIG_SERIAL_TERMIOS
|
||||
#ifdef CONFIG_SYSTEM_ZMODEM_FLOWC
|
||||
/* Flush the serial output to assure do not hang trying to drain it */
|
||||
|
||||
tcflush(fd, TCIOFLUSH);
|
||||
#endif
|
||||
|
||||
/* Restore the saved terminal setting */
|
||||
|
||||
tcsetattr(fd, TCSANOW, &saveterm);
|
||||
#endif
|
||||
|
||||
(void)close(fd);
|
||||
|
||||
errout:
|
||||
|
@ -106,6 +106,9 @@ int sz_main(int argc, FAR char **argv)
|
||||
bool skip = false;
|
||||
long tmp;
|
||||
int exitcode = EXIT_FAILURE;
|
||||
#ifdef CONFIG_SERIAL_TERMIOS
|
||||
struct termios saveterm;
|
||||
#endif
|
||||
int option;
|
||||
int ret;
|
||||
int fd;
|
||||
@ -188,10 +191,20 @@ int sz_main(int argc, FAR char **argv)
|
||||
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
|
||||
/* Enable hardware Rx/Tx flow control */
|
||||
|
||||
zm_flowc(fd);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Get the Zmodem handle */
|
||||
@ -265,12 +278,18 @@ errout_with_zmodem:
|
||||
(void)zms_release(handle);
|
||||
|
||||
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 */
|
||||
|
||||
tcflush(fd, TCIOFLUSH);
|
||||
#endif
|
||||
|
||||
/* Restore the saved terminal setting */
|
||||
|
||||
tcsetattr(fd, TCSANOW, &saveterm);
|
||||
#endif
|
||||
|
||||
(void)close(fd);
|
||||
|
||||
errout:
|
||||
|
@ -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);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: zm_rawmode
|
||||
*
|
||||
* Description:
|
||||
* Set the terminal to the raw mode
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SERIAL_TERMIOS
|
||||
void zm_rawmode(int fd);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: zm_flowc
|
||||
*
|
||||
* Description:
|
||||
* 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
|
||||
|
@ -473,15 +473,31 @@ uint32_t zm_filecrc(FAR struct zm_state_s *pzm, FAR const char *filename)
|
||||
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
|
||||
*
|
||||
* Description:
|
||||
* 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user