diff --git a/aor/aor.c b/aor/aor.c index 72ebba93b..04a4b2af9 100644 --- a/aor/aor.c +++ b/aor/aor.c @@ -2,7 +2,7 @@ * Hamlib AOR backend - main file * Copyright (c) 2000,2001,2002 by Stephane Fillod * - * $Id: aor.c,v 1.17 2001-12-28 20:28:03 fillods Exp $ + * $Id: aor.c,v 1.18 2002-01-09 23:11:16 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,7 @@ * Is \r portable enough? */ #define CR '\r' +#define EOM "\r" /* * modes in use by the "MD" command @@ -73,14 +74,13 @@ int aor_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *dat { int i, retval; struct rig_state *rs; + char c; rs = &rig->state; - retval = write_block(&rs->rigport, cmd, cmd_len); - if (retval != RIG_OK) - return retval; + serial_flush(&rs->rigport); - retval = write_block(&rs->rigport, "\n", 1); + retval = write_block(&rs->rigport, cmd, cmd_len); if (retval != RIG_OK) return retval; @@ -90,14 +90,17 @@ int aor_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *dat */ i = 0; do { - retval = fread_block(&rs->rigport, data+i, 1); + retval = fread_block(&rs->rigport, &c, 1); if (retval == 0) continue; /* huh!? */ if (retval != RIG_OK) return retval; - } while (data[i++] != CR); + if (data) + data[i++] = c; + } while (c != CR); - *data_len = i; + if (data_len) + *data_len = i; return RIG_OK; } @@ -108,12 +111,9 @@ int aor_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *dat */ int aor_close(RIG *rig) { - unsigned char ackbuf[16]; - int ack_len; - /* terminate remote operation via the RS-232 */ - return aor_transaction (rig, "EX", 2, ackbuf, &ack_len); + return aor_transaction (rig, "EX" EOM, 3, NULL, NULL); } @@ -125,12 +125,23 @@ int aor_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { unsigned char freqbuf[16], ackbuf[16]; int freq_len, ack_len, retval; + int lowhz; /* * actually, frequency must be like nnnnnnnnm0, * where m must be 0 or 5 (for 50Hz). */ - freq_len = sprintf(freqbuf,"RF%010Ld", freq); + lowhz = freq % 100; + freq /= 100; + if (lowhz < 25) + lowhz = 0; + else if (lowhz < 75) + lowhz = 50; + else + lowhz = 100; + freq = freq*100 + lowhz; + + freq_len = sprintf(freqbuf,"RF%010lld" EOM, freq); retval = aor_transaction (rig, freqbuf, freq_len, ackbuf, &ack_len); if (retval != RIG_OK) @@ -145,11 +156,11 @@ int aor_set_freq(RIG *rig, vfo_t vfo, freq_t freq) */ int aor_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { - unsigned char freqbuf[16]; char *rfp; int freq_len, retval; + unsigned char freqbuf[64]; - retval = aor_transaction (rig, "RX", 2, freqbuf, &freq_len); + retval = aor_transaction (rig, "RX" EOM, 3, freqbuf, &freq_len); if (retval != RIG_OK) return retval; @@ -159,6 +170,57 @@ int aor_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) return RIG_OK; } +/* + * aor_set_vfo + * Assumes rig!=NULL + */ +int aor_set_vfo(RIG *rig, vfo_t vfo) +{ + char *vfocmd; + + switch (vfo) { + case RIG_VFO_VFO: vfocmd = "VF" EOM; break; + case RIG_VFO_A: vfocmd = "VA" EOM; break; + case RIG_VFO_B: vfocmd = "VB" EOM; break; + default: + rig_debug(RIG_DEBUG_ERR,"aor_set_vfo: unsupported vfo %d\n", + vfo); + return -RIG_EINVAL; + } + + return aor_transaction (rig, vfocmd, strlen(vfocmd), NULL, NULL); +} + +/* + * aor_get_vfo + * Assumes rig!=NULL, freq!=NULL + */ +int aor_get_vfo(RIG *rig, vfo_t *vfo) +{ + int vfo_len, retval; + unsigned char vfobuf[64]; + + retval = aor_transaction (rig, "RX" EOM, 3, vfobuf, &vfo_len); + if (retval != RIG_OK) + return retval; + + switch (vfobuf[1]) { + case 'S': + case 'V': + case 'F': *vfo = RIG_VFO_VFO; break; + case 'A': *vfo = RIG_VFO_A; break; + case 'B': *vfo = RIG_VFO_B; break; + case 'R': *vfo = RIG_VFO_MEM; break; + default: + rig_debug(RIG_DEBUG_ERR,"aor_get_vfo: unknown vfo %c\n", + vfobuf[1]); + return -RIG_EINVAL; + } + + return RIG_OK; +} + + /* * aor_set_mode * Assumes rig!=NULL @@ -206,7 +268,7 @@ int aor_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) return -RIG_EINVAL; } - mdbuf_len = sprintf(mdbuf, "MD%c", aormode); + mdbuf_len = sprintf(mdbuf, "MD%c" EOM, aormode); retval = aor_transaction (rig, mdbuf, mdbuf_len, ackbuf, &ack_len); return retval; @@ -222,7 +284,7 @@ int aor_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) int ack_len, retval; - retval = aor_transaction (rig, "MD", 2, ackbuf, &ack_len); + retval = aor_transaction (rig, "MD" EOM, 3, ackbuf, &ack_len); if (retval != RIG_OK) return retval; @@ -276,7 +338,7 @@ int aor_set_ts(RIG *rig, vfo_t vfo, shortfreq_t ts) * actually, tuning step must be like nnnnm0, * where m must be 0 or 5 (for 50Hz). */ - ts_len = sprintf(tsbuf,"ST%06ld", ts); + ts_len = sprintf(tsbuf,"ST%06ld" EOM, ts); return aor_transaction (rig, tsbuf, ts_len, ackbuf, &ack_len); } @@ -287,14 +349,65 @@ int aor_set_ts(RIG *rig, vfo_t vfo, shortfreq_t ts) */ int aor_set_powerstat(RIG *rig, powerstat_t status) { - unsigned char ackbuf[16]; - int ack_len; - if (status != RIG_POWER_OFF) return -RIG_EINVAL; /* turn off power */ - return aor_transaction (rig, "QP", 2, ackbuf, &ack_len); + return aor_transaction (rig, "QP" EOM, 3, NULL, NULL); +} + +/* + * aor_vfo_op + * Assumes rig!=NULL + */ +int aor_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) +{ + char *aorcmd; + int ack_len; + char ackbuf[16]; + + switch (op) { + case RIG_OP_UP: aorcmd = "\x1e" EOM; break; + case RIG_OP_DOWN: aorcmd = "\x1f" EOM; break; + case RIG_OP_RIGHT: aorcmd = "\x1c" EOM; break; + case RIG_OP_LEFT: aorcmd = "\x1d" EOM; break; + case RIG_OP_MCL: aorcmd = "MQ" EOM; break; + default: + rig_debug(RIG_DEBUG_ERR,"aor_vfo_op: unsupported op %d\n", + op); + return -RIG_EINVAL; + } + + return aor_transaction (rig, aorcmd, strlen(aorcmd), ackbuf, &ack_len); +} + + +/* + * aor_get_info + * Assumes rig!=NULL + */ +const char *aor_get_info(RIG *rig) +{ + static char infobuf[16]; + int id_len, frm_len, retval; + char idbuf[4]; + char frmbuf[16]; + + retval = aor_transaction (rig, "\001" EOM, 2, idbuf, &id_len); + if (retval != RIG_OK) + return NULL; + + idbuf[2] = '\0'; + + retval = aor_transaction (rig, "VR" EOM, 3, frmbuf, &frm_len); + if (retval != RIG_OK || frm_len>16) + return NULL; + + frmbuf[frm_len] = '\0'; + sprintf(infobuf, "Remote ID %c%c, Firmware version %s", + idbuf[0], idbuf[1], frmbuf); + + return infobuf; } diff --git a/aor/aor.h b/aor/aor.h index a043b12c9..406c3ecaf 100644 --- a/aor/aor.h +++ b/aor/aor.h @@ -2,7 +2,7 @@ * Hamlib AOR backend - main header * Copyright (c) 2000,2001,2002 by Stephane Fillod * - * $Id: aor.h,v 1.9 2001-12-28 20:28:03 fillods Exp $ + * $Id: aor.h,v 1.10 2002-01-09 23:11:16 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 @@ -30,9 +30,13 @@ int aor_set_freq(RIG *rig, vfo_t vfo, freq_t freq); int aor_get_freq(RIG *rig, vfo_t vfo, freq_t *freq); int aor_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width); int aor_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width); +int aor_set_vfo(RIG *rig, vfo_t vfo); +int aor_get_vfo(RIG *rig, vfo_t *vfo); int aor_set_ts(RIG *rig, vfo_t vfo, shortfreq_t ts); int aor_set_powerstat(RIG *rig, powerstat_t status); +int aor_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op); +const char *aor_get_info(RIG *rig); extern const struct rig_caps ar8200_caps; extern const struct rig_caps ar8000_caps; diff --git a/aor/ar8000.c b/aor/ar8000.c index e63cc36fe..b3716d39a 100644 --- a/aor/ar8000.c +++ b/aor/ar8000.c @@ -1,8 +1,8 @@ /* * Hamlib AOR backend - AR8000 description - * Copyright (c) 2000,2001 by Stephane Fillod + * Copyright (c) 2000,2001,2002 by Stephane Fillod * - * $Id: ar8000.c,v 1.1 2001-10-22 20:22:51 f4cfe Exp $ + * $Id: ar8000.c,v 1.2 2002-01-09 23:11:16 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 @@ -24,26 +24,20 @@ #include "config.h" #endif -#include -#include /* Standard input/output definitions */ -#include /* String function definitions */ -#include /* UNIX standard function definitions */ -#include /* File control definitions */ -#include /* Error number definitions */ -#include /* POSIX terminal control definitions */ -#include - #include -#include #include "aor.h" #define AR8000_MODES (RIG_MODE_AM|RIG_MODE_CW|RIG_MODE_SSB|RIG_MODE_FM|RIG_MODE_WFM) -#define AR8000_FUNC_ALL (RIG_FUNC_TSQL) +#define AR8000_FUNC_ALL (RIG_FUNC_TSQL|RIG_FUNC_ABM) #define AR8000_LEVEL (RIG_LEVEL_ATT|RIG_LEVEL_AGC|RIG_LEVEL_SQL|RIG_LEVEL_SQLSTAT|RIG_LEVEL_STRENGTH) +#define AR8000_PARM (RIG_PARM_APO|RIG_PARM_BACKLIGHT|RIG_PARM_BEEP) + +#define AR8000_VFO_OPS (RIG_OP_MCL|RIG_OP_UP|RIG_OP_DOWN|RIG_OP_LEFT|RIG_OP_RIGHT) + #define AR8000_VFO (RIG_VFO_A|RIG_VFO_B) /* @@ -82,17 +76,18 @@ has_get_parm: RIG_PARM_NONE, has_set_parm: RIG_PARM_NONE, /* FIXME: parms */ level_gran: {}, /* FIXME: granularity */ parm_gran: {}, -ctcss_list: NULL, /* FIXME: CTCSS/DCS list */ +ctcss_list: NULL, /* FIXME: CTCSS list */ dcs_list: NULL, preamp: { RIG_DBLST_END, }, -attenuator: { RIG_DBLST_END, }, +attenuator: { 20, RIG_DBLST_END, }, /* TBC */ max_rit: Hz(0), max_xit: Hz(0), max_ifshift: Hz(0), targetable_vfo: 0, transceive: RIG_TRN_RIG, bank_qty: 20, -chan_desc_sz: 0, +chan_desc_sz: 12, +vfo_ops: AR8000_VFO_OPS, chan_list: { RIG_CHAN_END, }, /* FIXME: memory channel list: 1000 memories */ @@ -148,9 +143,14 @@ set_freq: aor_set_freq, get_freq: aor_get_freq, set_mode: aor_set_mode, get_mode: aor_get_mode, +set_vfo: aor_set_vfo, +get_vfo: aor_get_vfo, set_ts: aor_set_ts, set_powerstat: aor_set_powerstat, +vfo_op: aor_vfo_op, +get_info: aor_get_info, + }; /* diff --git a/aor/ar8200.c b/aor/ar8200.c index 343d81e68..bda3ff6a9 100644 --- a/aor/ar8200.c +++ b/aor/ar8200.c @@ -1,8 +1,8 @@ /* * Hamlib AOR backend - AR8200 description - * Copyright (c) 2000,2001 by Stephane Fillod + * Copyright (c) 2000,2001,2002 by Stephane Fillod * - * $Id: ar8200.c,v 1.13 2001-10-07 21:47:11 f4cfe Exp $ + * $Id: ar8200.c,v 1.14 2002-01-09 23:11:16 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 @@ -24,26 +24,22 @@ #include "config.h" #endif -#include -#include /* Standard input/output definitions */ -#include /* String function definitions */ -#include /* UNIX standard function definitions */ -#include /* File control definitions */ -#include /* Error number definitions */ -#include /* POSIX terminal control definitions */ -#include - #include -#include #include "aor.h" #define AR8200_MODES (RIG_MODE_AM|RIG_MODE_CW|RIG_MODE_SSB|RIG_MODE_FM|RIG_MODE_WFM) -#define AR8200_FUNC_ALL (RIG_FUNC_TSQL) +#define AR8200_FUNC (RIG_FUNC_TSQL|RIG_FUNC_ABM) #define AR8200_LEVEL (RIG_LEVEL_ATT|RIG_LEVEL_AGC|RIG_LEVEL_SQL|RIG_LEVEL_SQLSTAT|RIG_LEVEL_STRENGTH) +#define AR8200_PARM (RIG_PARM_APO|RIG_PARM_BACKLIGHT|RIG_PARM_BEEP) + +#define AR8200_VFO_OPS (RIG_OP_MCL|RIG_OP_UP|RIG_OP_DOWN|RIG_OP_LEFT|RIG_OP_RIGHT) + +#define AR8200_VFO_ALL (RIG_VFO_A|RIG_VFO_B) + /* * ar8200 rig capabilities. * Notice that some rigs share the same functions. @@ -73,31 +69,32 @@ post_write_delay: 0, timeout: 200, retry: 3, has_get_func: RIG_FUNC_NONE, -has_set_func: AR8200_FUNC_ALL, +has_set_func: AR8200_FUNC, has_get_level: AR8200_LEVEL, has_set_level: RIG_LEVEL_SET(AR8200_LEVEL), has_get_parm: RIG_PARM_NONE, has_set_parm: RIG_PARM_NONE, /* FIXME: parms */ level_gran: {}, /* FIXME: granularity */ parm_gran: {}, -ctcss_list: NULL, /* FIXME: CTCSS/DCS list */ +ctcss_list: NULL, /* FIXME: CTCSS list */ dcs_list: NULL, preamp: { RIG_DBLST_END, }, -attenuator: { RIG_DBLST_END, }, +attenuator: { 20, RIG_DBLST_END, }, /* TBC */ max_rit: Hz(0), max_xit: Hz(0), max_ifshift: Hz(0), targetable_vfo: 0, transceive: RIG_TRN_RIG, -bank_qty: 0, -chan_desc_sz: 0, +bank_qty: 20, +chan_desc_sz: 12, +vfo_ops: AR8200_VFO_OPS, chan_list: { RIG_CHAN_END, }, /* FIXME: memory channel list: 1000 memories */ rx_range_list1: { RIG_FRNG_END, }, /* FIXME: enter region 1 setting */ tx_range_list1: { RIG_FRNG_END, }, rx_range_list2: { - {kHz(100),MHz(2040),AR8200_MODES,-1,-1,RIG_VFO_A}, + {kHz(100),MHz(2040),AR8200_MODES,-1,-1,AR8200_VFO_ALL}, RIG_FRNG_END, }, /* rx range */ tx_range_list2: { RIG_FRNG_END, }, /* no tx range, this is a scanner! */ @@ -139,11 +136,16 @@ rig_close: aor_close, set_freq: aor_set_freq, get_freq: aor_get_freq, +set_vfo: aor_set_vfo, +get_vfo: aor_get_vfo, set_mode: aor_set_mode, get_mode: aor_get_mode, set_ts: aor_set_ts, set_powerstat: aor_set_powerstat, +vfo_op: aor_vfo_op, +get_info: aor_get_info, + }; /*