* \brief close the communication to the rig * \param rig The #RIG handle of the radio to be closed * * Closes communication to a radio which \a RIG handle has been passed * by argument that was previously open with rig_open(). * * \return RIG_OK if the operation has been successful, otherwise * a negative value if an error occurred (in which case, cause is * set appropriately). * * \sa
| 1748 | * \sa rig_cleanup(), rig_open() |
| 1749 | */ |
| 1750 | int HAMLIB_API rig_close(RIG *rig) |
| 1751 | { |
| 1752 | const struct rig_caps *caps; |
| 1753 | hamlib_port_t *rp, *pttp, *dcdp; |
| 1754 | struct rig_state *rs; |
| 1755 | |
| 1756 | if (!rig || !rig->caps) |
| 1757 | { |
| 1758 | rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); |
| 1759 | return -RIG_EINVAL; |
| 1760 | } |
| 1761 | |
| 1762 | ENTERFUNC; |
| 1763 | |
| 1764 | |
| 1765 | caps = rig->caps; |
| 1766 | rs = STATE(rig); |
| 1767 | rp = RIGPORT(rig); |
| 1768 | pttp = PTTPORT(rig); |
| 1769 | dcdp = DCDPORT(rig); |
| 1770 | |
| 1771 | if (!rs->comm_state) |
| 1772 | { |
| 1773 | RETURNFUNC(-RIG_EINVAL); |
| 1774 | } |
| 1775 | |
| 1776 | remove_opened_rig(rig); |
| 1777 | |
| 1778 | rs->comm_status = RIG_COMM_STATUS_DISCONNECTED; |
| 1779 | |
| 1780 | if (!skip_init) |
| 1781 | { |
| 1782 | morse_data_handler_stop(rig); |
| 1783 | async_data_handler_stop(rig); |
| 1784 | rig_poll_routine_stop(rig); |
| 1785 | network_multicast_receiver_stop(rig); |
| 1786 | network_multicast_publisher_stop(rig); |
| 1787 | } |
| 1788 | |
| 1789 | // Let the backend say 73 to the rig. |
| 1790 | // and ignore the return code. |
| 1791 | if (caps->rig_close) |
| 1792 | { |
| 1793 | caps->rig_close(rig); |
| 1794 | } |
| 1795 | |
| 1796 | |
| 1797 | /* |
| 1798 | * FIXME: what happens if PTT and rig ports are the same? |
| 1799 | * (eg. ptt_type = RIG_PTT_SERIAL) |
| 1800 | */ |
| 1801 | switch (pttp->type.ptt) |
| 1802 | { |
| 1803 | case RIG_PTT_NONE: |
| 1804 | case RIG_PTT_RIG: |
| 1805 | case RIG_PTT_RIG_MICDATA: |
| 1806 | break; |
| 1807 |