From 8d707be2a405b2243b9f84ddd8e6c34e8fe702a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Fillod=2C=20F8CFE?= Date: Sun, 23 Feb 2003 22:38:54 +0000 Subject: [PATCH] added support for set DTR/RTS state, useful to power external device from the serial port git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@1378 7ae35d74-ebe9-4afe-98af-79ac388436b8 --- src/conf.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++--- src/rig.c | 21 +++++++++++++++++--- src/token.h | 6 ++++-- 3 files changed, 75 insertions(+), 8 deletions(-) diff --git a/src/conf.c b/src/conf.c index ca9b5728f..7839aef14 100644 --- a/src/conf.c +++ b/src/conf.c @@ -3,13 +3,13 @@ * \ingroup rig * \brief Rig configuration interface * \author Stephane Fillod - * \date 2000-2002 + * \date 2000-2003 */ /* * Hamlib Interface - configuration interface - * Copyright (c) 2000,2002 by Stephane Fillod + * Copyright (c) 2000-2003 by Stephane Fillod * - * $Id: conf.c,v 1.8 2002-11-04 22:21:42 fillods Exp $ + * $Id: conf.c,v 1.9 2003-02-23 22:38:54 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -92,6 +92,14 @@ static const struct confparams frontend_cfg_params[] = { "VFO compensation in ppm", "0", RIG_CONF_NUMERIC, { .n = { 0.0, 1000.0, .001 } } }, + { TOK_RTS_STATE, "rts_state", "RTS state", + "Serial port set state of RTS signal for external powering", + "Unset", RIG_CONF_COMBO, { .c = {{ "Unset", "ON", "OFF", NULL }} } + }, + { TOK_DTR_STATE, "dtr_state", "DTR state", + "Serial port set state of DTR signal for external powering", + "Unset", RIG_CONF_COMBO, { .c = {{ "Unset", "ON", "OFF", NULL }} } + }, { RIG_CONF_END, NULL, } }; @@ -156,6 +164,28 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) return -RIG_EINVAL; break; + case TOK_RTS_STATE: + if (!strcmp(val, "Unset")) + rs->rigport.parm.serial.rts_state = RIG_SIGNAL_UNSET; + else if (!strcmp(val, "ON")) + rs->rigport.parm.serial.rts_state = RIG_SIGNAL_ON; + else if (!strcmp(val, "OFF")) + rs->rigport.parm.serial.rts_state = RIG_SIGNAL_OFF; + else + return -RIG_EINVAL; + break; + + case TOK_DTR_STATE: + if (!strcmp(val, "Unset")) + rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_UNSET; + else if (!strcmp(val, "ON")) + rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_ON; + else if (!strcmp(val, "OFF")) + rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_OFF; + else + return -RIG_EINVAL; + break; + case TOK_ITU_REGION: rs->itu_region = atoi(val); switch(rs->itu_region) { @@ -247,6 +277,26 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val) strcpy(val, s); break; + case TOK_RTS_STATE: + switch (rs->rigport.parm.serial.rts_state) { + case RIG_SIGNAL_UNSET: s = "Unset"; break; + case RIG_SIGNAL_ON: s = "ON"; break; + case RIG_SIGNAL_OFF: s = "OFF"; break; + default: return -RIG_EINVAL; + } + strcpy(val, s); + break; + + case TOK_DTR_STATE: + switch (rs->rigport.parm.serial.dtr_state) { + case RIG_SIGNAL_UNSET: s = "Unset"; break; + case RIG_SIGNAL_ON: s = "ON"; break; + case RIG_SIGNAL_OFF: s = "OFF"; break; + default: return -RIG_EINVAL; + } + strcpy(val, s); + break; + case TOK_VFO_COMP: sprintf(val, "%f", rs->vfo_comp); break; diff --git a/src/rig.c b/src/rig.c index dbf8d082e..d8581d496 100644 --- a/src/rig.c +++ b/src/rig.c @@ -1,8 +1,8 @@ /* * Hamlib Interface - main file - * Copyright (c) 2000-2002 by Stephane Fillod and Frank Singleton + * Copyright (c) 2000-2003 by Stephane Fillod and Frank Singleton * - * $Id: rig.c,v 1.66 2003-01-29 22:31:18 fillods Exp $ + * $Id: rig.c,v 1.67 2003-02-23 22:38:54 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -26,7 +26,7 @@ * \brief Ham Radio Control Libraries interface * \author Stephane Fillod * \author Frank Singleton - * \date 2000-2002 + * \date 2000-2003 * * Hamlib interface is a frontend implementing wrapper functions. */ @@ -380,6 +380,21 @@ int rig_open(RIG *rig) status = serial_open(&rs->rigport); if (status != 0) return status; + if (rs->rigport.parm.serial.rts_state != RIG_SIGNAL_UNSET && + rs->rigport.type.ptt != RIG_PTT_SERIAL_RTS && + rs->rigport.parm.serial.handshake != RIG_HANDSHAKE_HARDWARE) { + status = ser_set_rts(&rs->rigport, + rs->rigport.parm.serial.rts_state == RIG_SIGNAL_ON); + } + if (status != 0) + return status; + if (rs->rigport.parm.serial.dtr_state != RIG_SIGNAL_UNSET && + rs->rigport.type.ptt != RIG_PTT_SERIAL_DTR) { + status = ser_set_dtr(&rs->rigport, + rs->rigport.parm.serial.dtr_state == RIG_SIGNAL_ON); + } + if (status != 0) + return status; break; case RIG_PORT_DEVICE: diff --git a/src/token.h b/src/token.h index 8969c9bc8..69d6e2b47 100644 --- a/src/token.h +++ b/src/token.h @@ -1,8 +1,8 @@ /* * Hamlib Interface - token header - * Copyright (c) 2000,2001,2002 by Stephane Fillod + * Copyright (c) 2000-2003 by Stephane Fillod * - * $Id: token.h,v 1.1 2002-01-27 14:48:49 fillods Exp $ + * $Id: token.h,v 1.2 2003-02-23 22:38:54 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -47,6 +47,8 @@ #define TOK_STOP_BITS TOKEN_FRONTEND(22) #define TOK_PARITY TOKEN_FRONTEND(23) #define TOK_HANDSHAKE TOKEN_FRONTEND(24) +#define TOK_RTS_STATE TOKEN_FRONTEND(25) +#define TOK_DTR_STATE TOKEN_FRONTEND(26) /* * rig specific tokens