* \brief Close the communication channel to the amplifier. * * \param amp The #AMP handle of the amplifier to be closed. * * Closes the communication channel to an amplifier for which the #AMP * handle has been passed by argument that was previously opened with * amp_open(). * * \return RIG_OK if the operation has been successful, otherwise a **negative * value** if an error occurred (in
| 469 | * \sa amp_cleanup(), amp_open() |
| 470 | */ |
| 471 | int HAMLIB_API amp_close(AMP *amp) |
| 472 | { |
| 473 | const struct amp_caps *caps; |
| 474 | struct amp_state *rs; |
| 475 | hamlib_port_t *ap = AMPPORT(amp); |
| 476 | |
| 477 | amp_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); |
| 478 | |
| 479 | if (amp == NULL) |
| 480 | { |
| 481 | amp_debug(RIG_DEBUG_ERR, "%s: NULL ptr? amp=%p\n", __func__, amp); |
| 482 | return -RIG_EINVAL; |
| 483 | } |
| 484 | |
| 485 | if (amp->caps == NULL) |
| 486 | { |
| 487 | amp_debug(RIG_DEBUG_ERR, "%s: NULL ptr? amp->caps=%p\n", __func__, amp->caps); |
| 488 | return -RIG_EINVAL; |
| 489 | } |
| 490 | |
| 491 | caps = amp->caps; |
| 492 | rs = AMPSTATE(amp); |
| 493 | |
| 494 | if (!rs->comm_state) |
| 495 | { |
| 496 | amp_debug(RIG_DEBUG_ERR, "%s: comm_state=0? rs=%p, rs->comm_state=%d\n", |
| 497 | __func__, rs, rs->comm_state); |
| 498 | return -RIG_EINVAL; |
| 499 | } |
| 500 | |
| 501 | /* |
| 502 | * Let the backend say 73s to the amp. |
| 503 | * and ignore the return code. |
| 504 | */ |
| 505 | if (caps->amp_close) |
| 506 | { |
| 507 | caps->amp_close(amp); |
| 508 | } |
| 509 | |
| 510 | |
| 511 | if (ap->fd != -1) |
| 512 | { |
| 513 | switch (ap->type.rig) |
| 514 | { |
| 515 | case RIG_PORT_SERIAL: |
| 516 | ser_close(ap); |
| 517 | break; |
| 518 | |
| 519 | case RIG_PORT_PARALLEL: |
| 520 | par_close(ap); |
| 521 | break; |
| 522 | |
| 523 | case RIG_PORT_USB: |
| 524 | usb_port_close(ap); |
| 525 | break; |
| 526 | |
| 527 | case RIG_PORT_NETWORK: |
| 528 | case RIG_PORT_UDP_NETWORK: |
no test coverage detected