MCPcopy Create free account
hub / github.com/Hamlib/Hamlib / serial_setup

Function serial_setup

src/serial.c:373–812  ·  view source on GitHub ↗

* \brief Set up Serial port according to requests in port * \param rp * \return RIG_OK or < 0 */

Source from the content-addressed store, hash-verified

371 * \return RIG_OK or < 0
372 */
373int HAMLIB_API serial_setup(hamlib_port_t *rp)
374{
375 int fd;
376 /* There's a lib replacement for termios under Mingw */
377#if defined(HAVE_TERMIOS_H)
378 speed_t speed; /* serial comm speed */
379 struct termios options, orig_options;
380#elif defined(HAVE_TERMIO_H)
381 struct termio options, orig_options;
382#elif defined(HAVE_SGTTY_H)
383 struct sgttyb sg, orig_sg;
384#else
385# error "No term control supported!"
386#endif
387 term_options_backup_t *term_backup = NULL;
388
389 if (!rp)
390 {
391 return (-RIG_EINVAL);
392 }
393
394 fd = rp->fd;
395
396 // Linux sets pins high so we force them low once
397 // This fails on Linux and MacOS with hardware flow control
398 // Seems setting low disables hardware flow setting later
399// ser_set_rts(rp, 0);
400// ser_set_dtr(rp, 0);
401
402 /*
403 * Get the current options for the port...
404 */
405#if defined(HAVE_TERMIOS_H)
406 rig_debug(RIG_DEBUG_TRACE, "%s: tcgetattr\n", __func__);
407 tcgetattr(fd, &options);
408 memcpy(&orig_options, &options, sizeof(orig_options));
409#elif defined(HAVE_TERMIO_H)
410 rig_debug(RIG_DEBUG_TRACE, "%s: IOCTL TCGETA\n", __func__);
411 IOCTL(fd, TCGETA, &options);
412 memcpy(&orig_options, &options, sizeof(orig_options));
413#else /* sgtty */
414 rig_debug(RIG_DEBUG_TRACE, "%s: IOCTL TIOCGETP\n", __func__);
415 IOCTL(fd, TIOCGETP, &sg);
416 memcpy(&orig_sg, &sg, sizeof(orig_sg));
417#endif
418
419#ifdef HAVE_CFMAKERAW
420 /* Set serial port to RAW mode by default. */
421 rig_debug(RIG_DEBUG_TRACE, "%s: cfmakeraw\n", __func__);
422 cfmakeraw(&options);
423#endif
424
425 /*
426 * Set the baud rates to requested values
427 */
428 switch (rp->parm.serial.rate)
429 {
430 case 150:

Callers 5

pcr_set_comm_speedFunction · 0.85
pcr_openFunction · 0.85
thd74_get_chan_all_cbFunction · 0.85
thd72_get_chan_all_cbFunction · 0.85
serial_openFunction · 0.85

Calls 7

rig_debugFunction · 0.85
tcgetattrFunction · 0.85
cfmakerawFunction · 0.85
cfsetispeedFunction · 0.85
cfsetospeedFunction · 0.85
tcflushFunction · 0.85
tcsetattrFunction · 0.85

Tested by

no test coverage detected