* \brief Close the communication channel to the rotator. * \param rot The #ROT handle of the rotator to be closed. * * Closes the communication channel to a rotator for which #ROT handle has * been passed by argument that was previously opened with rot_open(). * * \return RIG_OK if the operation has been successful, otherwise a **negative * value** if an error occurred (in which case, cause
| 604 | * \sa rot_cleanup(), rot_open() |
| 605 | */ |
| 606 | int HAMLIB_API rot_close(ROT *rot) |
| 607 | { |
| 608 | const struct rot_caps *caps; |
| 609 | struct rot_state *rs; |
| 610 | hamlib_port_t *rotp = ROTPORT(rot); |
| 611 | |
| 612 | rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); |
| 613 | |
| 614 | if (!rot || !rot->caps) |
| 615 | { |
| 616 | return -RIG_EINVAL; |
| 617 | } |
| 618 | |
| 619 | caps = rot->caps; |
| 620 | rs = ROTSTATE(rot); |
| 621 | |
| 622 | if (!rs->comm_state) |
| 623 | { |
| 624 | return -RIG_EINVAL; |
| 625 | } |
| 626 | |
| 627 | /* |
| 628 | * Let the backend say 73s to the rot. |
| 629 | * and ignore the return code. |
| 630 | */ |
| 631 | if (caps->rot_close) |
| 632 | { |
| 633 | caps->rot_close(rot); |
| 634 | } |
| 635 | |
| 636 | |
| 637 | if (rotp->fd != -1) |
| 638 | { |
| 639 | switch (rotp->type.rig) |
| 640 | { |
| 641 | case RIG_PORT_SERIAL: |
| 642 | ser_close(rotp); |
| 643 | break; |
| 644 | |
| 645 | case RIG_PORT_PARALLEL: |
| 646 | par_close(rotp); |
| 647 | break; |
| 648 | |
| 649 | #if defined(HAVE_LIB_USB_H) || defined(HAMB_LIBUSB_1_0_LIBUSB_H) |
| 650 | |
| 651 | case RIG_PORT_USB: |
| 652 | usb_port_close(rotp); |
| 653 | break; |
| 654 | #endif |
| 655 | |
| 656 | case RIG_PORT_NETWORK: |
| 657 | case RIG_PORT_UDP_NETWORK: |
| 658 | network_close(rotp); |
| 659 | break; |
| 660 | |
| 661 | default: |
| 662 | close(rotp->fd); |
| 663 | } |
no test coverage detected