From fdc34db72ad3a623b633cc9a47cead93fe0a7645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Fillod=2C=20F8CFE?= Date: Thu, 21 Sep 2000 06:44:44 +0000 Subject: [PATCH] RIG_E modified, added rigerror() and new field tuning_steps available on rig. git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@135 7ae35d74-ebe9-4afe-98af-79ac388436b8 --- common/rig.c | 58 ++++++++++++++++++++++++++++++++++--------------- common/rig.h | 49 +++++++++++++++++++++++++++-------------- common/serial.c | 24 ++++++++++---------- 3 files changed, 85 insertions(+), 46 deletions(-) diff --git a/common/rig.c b/common/rig.c index 0eef9c0d4..42e092bff 100644 --- a/common/rig.c +++ b/common/rig.c @@ -43,6 +43,28 @@ static const struct rig_caps *rig_base[] = { &ft747_caps, &ic706_caps, &ic706mkiig_caps, /* ... */ NULL, }; +static const char *rigerror_table[] = { + "Command completed sucessfully", + "Invalid parameter", + "Invalid configuration", + "Memory shortage", + "Feature not implemented", + "Communication timed out", + "IO error", + "Internal Hamlib error", + "Protocol error", + "Command rejected by the rig", + "Command performed, but arg truncated, result not guaranteed" +}; + +/* + * TODO: check table bounds, use gettext + */ +const char *rigerror(int errnum) +{ + return rigerror_table[errnum]; +} + RIG *rig_init(rig_model_t rig_model) { @@ -81,7 +103,7 @@ RIG *rig_init(rig_model_t rig_model) */ rig->state.port_type = RIG_PORT_SERIAL; /* default is serial port */ - strncpy(rig->state.rig_path, DEFAULT_SERIAL_PORT, MAXRIGPATHLEN); + strncpy(rig->state.rig_path, DEFAULT_SERIAL_PORT, FILPATHLEN); rig->state.port_type = RIG_PORT_SERIAL; /* default is serial port */ rig->state.serial_rate = rig->caps->serial_rate_max; /* fastest ! */ rig->state.serial_data_bits = rig->caps->serial_data_bits; @@ -108,7 +130,7 @@ int rig_open(RIG *rig) int status; if (!rig) - return RIG_EINVAL; + return -RIG_EINVAL; switch(rig->state.port_type) { case RIG_PORT_SERIAL: @@ -119,7 +141,7 @@ int rig_open(RIG *rig) case RIG_PORT_NETWORK: /* not implemented yet! */ default: - return RIG_ENIMPL; + return -RIG_ENIMPL; } /* @@ -144,13 +166,13 @@ int rig_open(RIG *rig) int rig_set_freq(RIG *rig, freq_t freq) { if (!rig || !rig->caps) - return RIG_EINVAL; + return -RIG_EINVAL; if (rig->state.vfo_comp != 0.0) freq = (freq_t)(rig->state.vfo_comp * freq); if (rig->caps->set_freq == NULL) - return RIG_ENIMPL; /* not implemented */ + return -RIG_ENIMPL; /* not implemented */ else return rig->caps->set_freq(rig, freq); } @@ -163,10 +185,10 @@ int rig_set_freq(RIG *rig, freq_t freq) int rig_get_freq(RIG *rig, freq_t *freq) { if (!rig || !rig->caps || !freq) - return RIG_EINVAL; + return -RIG_EINVAL; if (rig->caps->get_freq == NULL) - return RIG_ENIMPL; /* not implemented */ + return -RIG_ENIMPL; /* not implemented */ else return rig->caps->get_freq(rig, freq); } @@ -180,10 +202,10 @@ int rig_get_freq(RIG *rig, freq_t *freq) int rig_set_mode(RIG *rig, rmode_t mode) { if (!rig || !rig->caps) - return RIG_EINVAL; + return -RIG_EINVAL; if (rig->caps->set_mode == NULL) - return RIG_ENIMPL; /* not implemented */ + return -RIG_ENIMPL; /* not implemented */ else return rig->caps->set_mode(rig, mode); } @@ -196,10 +218,10 @@ int rig_set_mode(RIG *rig, rmode_t mode) int rig_get_mode(RIG *rig, rmode_t *mode) { if (!rig || !rig->caps || !mode) - return RIG_EINVAL; + return -RIG_EINVAL; if (rig->caps->get_mode == NULL) - return RIG_ENIMPL; /* not implemented */ + return -RIG_ENIMPL; /* not implemented */ else return rig->caps->get_mode(rig, mode); } @@ -213,10 +235,10 @@ int rig_get_mode(RIG *rig, rmode_t *mode) int rig_set_vfo(RIG *rig, vfo_t vfo) { if (!rig || !rig->caps) - return RIG_EINVAL; + return -RIG_EINVAL; if (rig->caps->set_vfo == NULL) - return RIG_ENIMPL; /* not implemented */ + return -RIG_ENIMPL; /* not implemented */ else return rig->caps->set_vfo(rig, vfo); } @@ -229,10 +251,10 @@ int rig_set_vfo(RIG *rig, vfo_t vfo) int rig_get_vfo(RIG *rig, vfo_t *vfo) { if (!rig || !rig->caps || !vfo) - return RIG_EINVAL; + return -RIG_EINVAL; if (rig->caps->get_vfo == NULL) - return RIG_ENIMPL; /* not implemented */ + return -RIG_ENIMPL; /* not implemented */ else return rig->caps->get_vfo(rig, vfo); } @@ -251,7 +273,7 @@ int rig_get_vfo(RIG *rig, vfo_t *vfo) int rig_close(RIG *rig) { if (rig == NULL || rig->caps) - return RIG_EINVAL; + return -RIG_EINVAL; /* * Let the backend say 73s to the rig @@ -273,7 +295,7 @@ int rig_close(RIG *rig) int rig_cleanup(RIG *rig) { if (rig == NULL || rig->caps) - return RIG_EINVAL; + return -RIG_EINVAL; /* * basically free up the priv struct @@ -301,7 +323,7 @@ RIG *rig_probe(const char *port_path) for (i = 0; rig_base[i]; i++) { if (rig_base[i]->rig_probe != NULL) { rig = rig_init(rig_base[i]->rig_model); - strncpy(rig->state.rig_path, port_path, MAXRIGPATHLEN); + strncpy(rig->state.rig_path, port_path, FILPATHLEN); rig_open(rig); if (rig && rig_base[i]->rig_probe(rig) == 0) { return rig; diff --git a/common/rig.h b/common/rig.h index 25e064efb..823443b07 100644 --- a/common/rig.h +++ b/common/rig.h @@ -5,7 +5,7 @@ * will be used for obtaining rig capabilities. * * - * $Id: rig.h,v 1.11 2000-09-20 06:12:33 f4cfe Exp $ * + * $Id: rig.h,v 1.12 2000-09-21 06:44:44 f4cfe Exp $ * * * * This program is free software; you can redistribute it and/or @@ -32,16 +32,17 @@ /* * Error codes that can be returned by the Hamlib functions */ -#define RIG_OK 0 /* completed sucessfully */ -#define RIG_EINVAL -1 /* invalid parameter */ -#define RIG_ECONF -2 /* invalid configuration (serial,..) */ -#define RIG_ENOMEM -3 /* memory shortage */ -#define RIG_ENIMPL -4 /* function not implemented */ -#define RIG_ETIMEOUT -5 /* communication timed out */ -#define RIG_EIO -6 /* IO error, including open failed */ -#define RIG_EINTERNAL -7 /* Internal Hamlib error, huh! */ -#define RIG_EPROTO -8 /* Protocol error */ -#define RIG_ERJCTED -9 /* Command rejected by the rig */ +#define RIG_OK 0 /* completed sucessfully */ +#define RIG_EINVAL 1 /* invalid parameter */ +#define RIG_ECONF 2 /* invalid configuration (serial,..) */ +#define RIG_ENOMEM 3 /* memory shortage */ +#define RIG_ENIMPL 4 /* function not implemented */ +#define RIG_ETIMEOUT 5 /* communication timed out */ +#define RIG_EIO 6 /* IO error, including open failed */ +#define RIG_EINTERNAL 7 /* Internal Hamlib error, huh! */ +#define RIG_EPROTO 8 /* Protocol error */ +#define RIG_ERJCTED 9 /* Command rejected by the rig */ +#define RIG_ETRUNC 10 /* Command performed, but arg truncated */ /* Forward struct references */ @@ -189,9 +190,10 @@ typedef unsigned int rmode_t; /* radio mode */ #define RIGNAMSIZ 30 #define RIGVERSIZ 8 -#define MAXRIGPATHLEN 100 +#define FILPATHLEN 100 #define FRQRANGESIZ 30 -#define MAXCHANDESC 30 /* describe channel eg: WWV 5Mhz */ +#define MAXCHANDESC 30 /* describe channel eg: "WWV 5Mhz" */ +#define TSLSTSIZ 20 /* max tuning step list size, zero ended */ /* @@ -206,6 +208,15 @@ struct freq_range_list { int high_power; /* in mW, -1 for no power (ie. rx list) */ }; +/* + * Lists the tuning steps available for each mode + */ +struct tuning_step_list { + unsigned long modes; /* bitwise OR'ed RIG_MODE_* */ + unsigned long ts; /* tuning step in Hz */ +}; + + /* * Convenience struct, describes a freq/vfo/mode combo @@ -220,7 +231,7 @@ struct channel { vfo_t vfo; int power; /* in mW */ signed int preamp; /* in dB, if < 0, this is attenuator */ - unsigned int tuning_step; /* */ + unsigned long tuning_step; /* */ unsigned char channel_desc[MAXCHANDESC]; }; @@ -263,6 +274,7 @@ struct rig_caps { int chan_qty; /* number of channels */ struct freq_range_list rx_range_list[FRQRANGESIZ]; struct freq_range_list tx_range_list[FRQRANGESIZ]; + struct tuning_step_list tuning_steps[TSLSTSIZ]; /* * Rig Admin API @@ -326,8 +338,9 @@ struct rig_state { int timeout; /* in ms */ int retry; /* maximum number of retries, 0 to disable */ enum ptt_type_e ptt_type; /* how we will key the rig */ + char ptt_path[FILPATHLEN]; /* path to the keying device (serial,//) */ double vfo_comp; /* VFO compensation in PPM, 0.0 to disable */ - char rig_path[MAXRIGPATHLEN]; /* serial port/network path(host:port) */ + char rig_path[FILPATHLEN]; /* serial port/network path(host:port) */ int fd; /* serial port/socket file handle */ /* * Pointer to private data @@ -395,10 +408,14 @@ int rig_cleanup(RIG *rig); RIG *rig_probe(const char *rig_path); -int rig_has_func(RIG *rig, unsigned long func); +int rig_has_func(RIG *rig, unsigned long func); /* is part of capabilities? */ +int rig_set_func(RIG *rig, unsigned long func); /* activate the function(s) */ +int rig_get_func(RIG *rig, unsigned long *func); /* get the setting from rig */ const struct rig_caps *rig_get_caps(rig_model_t rig_model); +const char *rigerror(int errnum); + #endif /* _RIG_H */ diff --git a/common/serial.c b/common/serial.c index 8a349cf87..432bf12da 100644 --- a/common/serial.c +++ b/common/serial.c @@ -5,7 +5,7 @@ * Provides useful routines for read/write serial data for communicating * via serial interface . * - * $Id: serial.c,v 1.13 2000-09-19 06:59:27 f4cfe Exp $ + * $Id: serial.c,v 1.14 2000-09-21 06:44:44 f4cfe Exp $ * * * This program is free software; you can redistribute it and/or @@ -60,7 +60,7 @@ int serial_open(struct rig_state *rs) { speed_t speed; /* serial comm speed */ if (!rs) - return RIG_EINVAL; + return -RIG_EINVAL; /* * Open in Non-blocking mode. Watch for EAGAIN errors! @@ -73,7 +73,7 @@ int serial_open(struct rig_state *rs) { fprintf(stderr, "serial_open: Unable to open %s - %s\n", rs->rig_path, strerror(errno)); - return RIG_EIO; + return -RIG_EIO; } /* @@ -112,7 +112,7 @@ int serial_open(struct rig_state *rs) { fprintf(stderr, "open_serial: unsupported rate specified: %d\n", rs->serial_rate); close(fd); - return RIG_ECONF; + return -RIG_ECONF; } cfsetispeed(&options, speed); cfsetospeed(&options, speed); @@ -141,7 +141,7 @@ int serial_open(struct rig_state *rs) { printf("open_serial: unsupported serial_data_bits specified: %d\n", rs->serial_data_bits); close(fd); - return RIG_ECONF; + return -RIG_ECONF; break; } @@ -162,7 +162,7 @@ int serial_open(struct rig_state *rs) { fprintf(stderr, "open_serial: unsupported serial_stop_bits specified: %d\n", rs->serial_stop_bits); close(fd); - return RIG_ECONF; + return -RIG_ECONF; break; } @@ -187,7 +187,7 @@ int serial_open(struct rig_state *rs) { fprintf(stderr, "open_serial: unsupported serial_parity specified: %d\n", rs->serial_parity); close(fd); - return RIG_ECONF; + return -RIG_ECONF; break; } @@ -214,7 +214,7 @@ int serial_open(struct rig_state *rs) { fprintf(stderr, "open_serial: unsupported flow_control specified: %d\n", rs->serial_handshake); close(fd); - return RIG_ECONF; + return -RIG_ECONF; break; } @@ -244,7 +244,7 @@ int serial_open(struct rig_state *rs) { fprintf(stderr, "open_serial: tcsetattr failed: %s\n", strerror(errno)); close(fd); - return RIG_ECONF; /* arg, so close! */ + return -RIG_ECONF; /* arg, so close! */ } rs->fd = fd; @@ -318,7 +318,7 @@ int write_block(int fd, const unsigned char *txbuffer, size_t count, int write_d for (i=0; i < count; i++) { if (write(fd, txbuffer+i, 1) < 0) { fprintf(stderr,"write_block() failed - %s\n", strerror(errno)); - return RIG_EIO; + return -RIG_EIO; } usleep(write_delay*1000); } @@ -363,7 +363,7 @@ int read_block(int fd, unsigned char *rxbuffer, size_t count, int timeout ) if (!retval) { fprintf(stderr,"rig timeout after %d chars or select error - %s!\n", total_count, strerror(errno)); - return RIG_ETIMEOUT; + return -RIG_ETIMEOUT; } /* @@ -374,7 +374,7 @@ int read_block(int fd, unsigned char *rxbuffer, size_t count, int timeout ) if (rd_count < 0) { fprintf(stderr, "read_block: read failed - %s\n", strerror(errno)); - return RIG_EIO; + return -RIG_EIO; } total_count += rd_count; count -= rd_count;