* \brief Open the communication channel to the amplifier. * * \param amp The #AMP handle of the amplifier to be opened. * * Opens the communication channel to an amplifier for which the #AMP handle * has been passed. * * \return RIG_OK if the operation has been successful, otherwise a **negative * value** if an error occurred (in which case, cause is set appropriately). * * \retval RIG_O
| 310 | * \sa amp_init(), amp_close() |
| 311 | */ |
| 312 | int HAMLIB_API amp_open(AMP *amp) |
| 313 | { |
| 314 | const struct amp_caps *caps; |
| 315 | struct amp_state *rs; |
| 316 | hamlib_port_t *ap = AMPPORT(amp); |
| 317 | int status; |
| 318 | int net1, net2, net3, net4, port; |
| 319 | |
| 320 | amp_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); |
| 321 | |
| 322 | if (!amp || !amp->caps) |
| 323 | { |
| 324 | return -RIG_EINVAL; |
| 325 | } |
| 326 | |
| 327 | caps = amp->caps; |
| 328 | rs = AMPSTATE(amp); |
| 329 | |
| 330 | if (rs->comm_state) |
| 331 | { |
| 332 | return -RIG_EINVAL; |
| 333 | } |
| 334 | |
| 335 | ap->fd = -1; |
| 336 | |
| 337 | // determine if we have a network address |
| 338 | if (sscanf(ap->pathname, "%d.%d.%d.%d:%d", &net1, &net2, &net3, &net4, |
| 339 | &port) == 5) |
| 340 | { |
| 341 | rig_debug(RIG_DEBUG_TRACE, "%s: using network address %s\n", __func__, |
| 342 | ap->pathname); |
| 343 | ap->type.rig = RIG_PORT_NETWORK; |
| 344 | } |
| 345 | |
| 346 | switch (ap->type.rig) |
| 347 | { |
| 348 | case RIG_PORT_SERIAL: |
| 349 | status = serial_open(ap); |
| 350 | |
| 351 | if (status != 0) |
| 352 | { |
| 353 | return status; |
| 354 | } |
| 355 | |
| 356 | break; |
| 357 | |
| 358 | case RIG_PORT_PARALLEL: |
| 359 | status = par_open(ap); |
| 360 | |
| 361 | if (status < 0) |
| 362 | { |
| 363 | return status; |
| 364 | } |
| 365 | |
| 366 | break; |
| 367 | |
| 368 | case RIG_PORT_DEVICE: |
| 369 | status = open(ap->pathname, O_RDWR, 0); |
no test coverage detected