* \brief Close serial port * \param p fd * \return RIG_OK or < 0 */
| 985 | * \return RIG_OK or < 0 |
| 986 | */ |
| 987 | int ser_close(hamlib_port_t *p) |
| 988 | { |
| 989 | int rc; |
| 990 | term_options_backup_t *term_backup, *term_backup_prev; |
| 991 | |
| 992 | //rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); |
| 993 | |
| 994 | /* |
| 995 | * For microHam devices, do not close the |
| 996 | * socket via close but call a service routine |
| 997 | * (which might decide to keep the socket open). |
| 998 | * However, unset p->fd and uh_ptt_fd/uh_radio_fd. |
| 999 | */ |
| 1000 | if (p->fd == uh_ptt_fd) |
| 1001 | { |
| 1002 | uh_close_ptt(); |
| 1003 | uh_ptt_fd = -1; |
| 1004 | p->fd = -1; |
| 1005 | return (0); |
| 1006 | } |
| 1007 | |
| 1008 | if (p->fd == uh_radio_fd) |
| 1009 | { |
| 1010 | uh_close_radio(); |
| 1011 | uh_radio_fd = -1; |
| 1012 | p->fd = -1; |
| 1013 | return (0); |
| 1014 | } |
| 1015 | |
| 1016 | // Find backup termios options to restore before closing |
| 1017 | term_backup = term_options_backup_head; |
| 1018 | term_backup_prev = term_options_backup_head; |
| 1019 | |
| 1020 | while (term_backup) |
| 1021 | { |
| 1022 | if (term_backup->fd == p->fd) |
| 1023 | { |
| 1024 | // Found matching. Remove from list |
| 1025 | if (term_backup == term_options_backup_head) |
| 1026 | { |
| 1027 | term_options_backup_head = term_backup->next; |
| 1028 | } |
| 1029 | else |
| 1030 | { |
| 1031 | term_backup_prev->next = term_backup->next; |
| 1032 | } |
| 1033 | |
| 1034 | break; |
| 1035 | } |
| 1036 | |
| 1037 | term_backup_prev = term_backup; |
| 1038 | term_backup = term_backup->next; |
| 1039 | } |
| 1040 | |
| 1041 | // Restore backup termios |
| 1042 | if (term_backup) |
| 1043 | { |
| 1044 | rig_debug(RIG_DEBUG_VERBOSE, "%s: restoring options\n", __func__); |
no test coverage detected