* \brief Flush all characters waiting in RX buffer. * \param p * \return RIG_OK */
| 818 | * \return RIG_OK |
| 819 | */ |
| 820 | int HAMLIB_API serial_flush(hamlib_port_t *p) |
| 821 | { |
| 822 | int len; |
| 823 | int timeout_save; |
| 824 | short timeout_retry_save; |
| 825 | unsigned char buf[4096]; |
| 826 | |
| 827 | #ifdef __WIN32__ |
| 828 | struct termios_list *index; |
| 829 | index = win32_serial_find_port(p->fd); |
| 830 | |
| 831 | if (!index) |
| 832 | { |
| 833 | rig_debug(RIG_DEBUG_ERR, "%s: No WIN32 index for port???\n", __func__); |
| 834 | return -1; |
| 835 | } |
| 836 | |
| 837 | PurgeComm(index->hComm, PURGE_RXCLEAR); |
| 838 | return RIG_OK; |
| 839 | |
| 840 | #endif |
| 841 | |
| 842 | if (p->fd == uh_ptt_fd || p->fd == uh_radio_fd || p->flushx) |
| 843 | { |
| 844 | /* |
| 845 | * Catch microHam case: |
| 846 | * if fd corresponds to a microHam device drain the line |
| 847 | * (which is a socket) by reading until it is empty. |
| 848 | */ |
| 849 | int n, nbytes = 0; |
| 850 | |
| 851 | rig_debug(RIG_DEBUG_TRACE, "%s: flushing\n", __func__); |
| 852 | |
| 853 | while ((n = read(p->fd, buf, sizeof(buf))) > 0) |
| 854 | { |
| 855 | nbytes += n; |
| 856 | //int i; |
| 857 | |
| 858 | //for (i = 0; i < n; ++i) { printf("0x%02x(%c) ", buf[i], isprint(buf[i]) ? buf[i] : '~'); } |
| 859 | |
| 860 | /* do nothing */ |
| 861 | } |
| 862 | |
| 863 | rig_debug(RIG_DEBUG_TRACE, "read flushed %d bytes\n", nbytes); |
| 864 | |
| 865 | |
| 866 | return (RIG_OK); |
| 867 | } |
| 868 | |
| 869 | timeout_save = p->timeout; |
| 870 | //rig_debug(RIG_DEBUG_ERR, "%s: p->timeout=%d\n", __func__, p->timeout); |
| 871 | timeout_retry_save = p->timeout_retry; |
| 872 | p->timeout = 0; |
| 873 | p->timeout_retry = 0; |
| 874 | |
| 875 | |
| 876 | do |
| 877 | { |
no test coverage detected