new port_t design

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@523 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.1.2
Stéphane Fillod, F8CFE 2001-06-04 17:01:21 +00:00
rodzic 7ffe3fbe22
commit da19dd9a47
19 zmienionych plików z 467 dodań i 351 usunięć

Wyświetl plik

@ -6,7 +6,7 @@
* via serial interface to a Kenwood radio. * via serial interface to a Kenwood radio.
* *
* *
* $Id: alinco.c,v 1.1 2001-06-03 17:39:59 f4cfe Exp $ * $Id: alinco.c,v 1.2 2001-06-04 17:01:21 f4cfe Exp $
* *
* *
* *
@ -104,7 +104,7 @@ int alinco_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *
rs = &rig->state; rs = &rig->state;
write_block(rs->fd, cmd, cmd_len, rs->write_delay, rs->post_write_delay); write_block(&rs->rigport, cmd, cmd_len);
/* no data expected, TODO: flush input? */ /* no data expected, TODO: flush input? */
if (!data || !data_len) if (!data || !data_len)
@ -115,7 +115,7 @@ int alinco_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *
*/ */
i = 0; i = 0;
do { do {
count = fread_block(rs->stream, data+i, 1, rs->timeout); count = fread_block(&rs->rigport, data+i, 1);
if (count > 0) if (count > 0)
i += count; i += count;
} while (count > 0); } while (count > 0);
@ -331,10 +331,10 @@ int alinco_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
} }
/* /*
* icom_set_split * alinco_set_split
* Assumes rig!=NULL * Assumes rig!=NULL
*/ */
int icom_set_split(RIG *rig, vfo_t vfo, split_t split) int alinco_set_split(RIG *rig, vfo_t vfo, split_t split)
{ {
int cmd_len; int cmd_len;
char cmdbuf[32]; char cmdbuf[32];
@ -346,10 +346,10 @@ int icom_set_split(RIG *rig, vfo_t vfo, split_t split)
} }
/* /*
* icom_get_split * alinco_get_split
* Assumes rig!=NULL, split!=NULL * Assumes rig!=NULL, split!=NULL
*/ */
int icom_get_split(RIG *rig, vfo_t vfo, split_t *split) int alinco_get_split(RIG *rig, vfo_t vfo, split_t *split)
{ {
int splt_len; int splt_len;
char spltbuf[32]; char spltbuf[32];
@ -428,10 +428,10 @@ int alinco_get_split_freq(RIG *rig, vfo_t vfo, freq_t *rx_freq, freq_t *tx_freq)
/* /*
* icom_get_rit * alinco_get_rit
* Assumes rig!=NULL, split!=NULL * Assumes rig!=NULL, split!=NULL
*/ */
int icom_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) int alinco_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit)
{ {
int rit_len; int rit_len;
char ritbuf[32]; char ritbuf[32];

Wyświetl plik

@ -6,7 +6,7 @@
* via serial interface to an AOR scanner. * via serial interface to an AOR scanner.
* *
* *
* $Id: aor.c,v 1.7 2001-04-26 21:28:59 f4cfe Exp $ * $Id: aor.c,v 1.8 2001-06-04 17:01:21 f4cfe Exp $
* *
* *
* *
@ -77,8 +77,8 @@ int aor_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *dat
rs = &rig->state; rs = &rig->state;
write_block(rs->fd, cmd, cmd_len, rs->write_delay, rs->post_write_delay); write_block(&rs->rigport, cmd, cmd_len);
write_block(rs->fd, "\n", 1, rs->write_delay, rs->post_write_delay); write_block(&rs->rigport, "\n", 1);
/* /*
* buffered read are quite helpful here! * buffered read are quite helpful here!
@ -86,7 +86,7 @@ int aor_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *dat
*/ */
i = 0; i = 0;
do { do {
fread_block(rs->stream, data+i, 1, rs->timeout); fread_block(&rs->rigport, data+i, 1);
} while (data[i++] != CR); } while (data[i++] != CR);
*data_len = i; *data_len = i;

Wyświetl plik

@ -7,7 +7,7 @@
* purpose mainly. * purpose mainly.
* *
* *
* $Id: dummy.c,v 1.9 2001-06-03 19:54:05 f4cfe Exp $ * $Id: dummy.c,v 1.10 2001-06-04 17:01:21 f4cfe Exp $
* *
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -119,7 +119,7 @@ static unsigned char *decode_freq(freq_t freq)
static int dummy_init(RIG *rig) { static int dummy_init(RIG *rig) {
rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n"); rig_debug(RIG_DEBUG_VERBOSE,__FUNCTION__ " called\n");
rig->state.port_type = RIG_PORT_NONE; rig->state.rigport.type.rig = RIG_PORT_NONE;
return RIG_OK; return RIG_OK;
} }

Wyświetl plik

@ -6,7 +6,7 @@
* CI-V interface, used in serial communication to ICOM radios. * CI-V interface, used in serial communication to ICOM radios.
* *
* *
* $Id: frame.c,v 1.11 2001-05-04 22:39:47 f4cfe Exp $ * $Id: frame.c,v 1.12 2001-06-04 17:01:21 f4cfe Exp $
* *
* *
* *
@ -44,7 +44,7 @@
#include "frame.h" #include "frame.h"
/* Prototypes */ /* Prototypes */
int read_icom_block(FILE *stream, unsigned char *rxbuffer, size_t count, int timeout); int read_icom_block(port_t *p, unsigned char *rxbuffer, size_t count);
/* /*
* Build a CI-V frame. * Build a CI-V frame.
@ -109,7 +109,7 @@ int icom_transaction (RIG *rig, int cmd, int subcmd, const char *payload, int pa
/* /*
* should check return code and that write wrote cmd_len chars! * should check return code and that write wrote cmd_len chars!
*/ */
write_block(rs->fd, buf, frm_len, rs->write_delay, rs->post_write_delay); write_block(&rs->rigport, buf, frm_len);
/* /*
* read what we just sent, because TX and RX are looped, * read what we just sent, because TX and RX are looped,
@ -121,14 +121,14 @@ int icom_transaction (RIG *rig, int cmd, int subcmd, const char *payload, int pa
*/ */
Hold_Decode(rig); Hold_Decode(rig);
read_icom_block(rs->stream, buf, frm_len, rs->timeout); read_icom_block(&rs->rigport, buf, frm_len);
/* /*
* wait for ACK ... * wait for ACK ...
* FIXME: handle pading/collisions * FIXME: handle pading/collisions
* ACKFRMLEN is the smallest frame we can expect from the rig * ACKFRMLEN is the smallest frame we can expect from the rig
*/ */
frm_len = read_icom_frame(rs->stream, buf, rs->timeout); frm_len = read_icom_frame(&rs->rigport, buf);
Unhold_Decode(rig); Unhold_Decode(rig);
*data_len = frm_len-(ACKFRMLEN-1); *data_len = frm_len-(ACKFRMLEN-1);
@ -146,11 +146,11 @@ int icom_transaction (RIG *rig, int cmd, int subcmd, const char *payload, int pa
* FIXME: check return codes/bytes read * FIXME: check return codes/bytes read
* this function will be deprecated soon! * this function will be deprecated soon!
*/ */
int read_icom_block(FILE *stream, unsigned char *rxbuffer, size_t count, int timeout) int read_icom_block(port_t *p, unsigned char *rxbuffer, size_t count)
{ {
int i; int i;
fread_block(stream, rxbuffer, count, timeout); fread_block(p, rxbuffer, count);
#if 0 #if 0
for (i=0; i<count; i++) { for (i=0; i<count; i++) {
@ -171,7 +171,7 @@ int read_icom_block(FILE *stream, unsigned char *rxbuffer, size_t count, int tim
* TODO: strips padding/collisions * TODO: strips padding/collisions
* FIXME: check return codes/bytes read * FIXME: check return codes/bytes read
*/ */
int read_icom_frame(FILE *stream, unsigned char rxbuffer[], int timeout) int read_icom_frame(port_t *p, unsigned char rxbuffer[])
{ {
int i; int i;
@ -180,14 +180,14 @@ int read_icom_frame(FILE *stream, unsigned char rxbuffer[], int timeout)
* we can expected on the CI-V bus * we can expected on the CI-V bus
* FIXME: a COL is smaller!! * FIXME: a COL is smaller!!
*/ */
fread_block(stream, rxbuffer, ACKFRMLEN, timeout); fread_block(p, rxbuffer, ACKFRMLEN);
/* /*
* buffered read are quite helpful here! * buffered read are quite helpful here!
* However, an automate with a state model would be more efficient.. * However, an automate with a state model would be more efficient..
*/ */
for (i=ACKFRMLEN; rxbuffer[i-1]!=FI; i++) { for (i=ACKFRMLEN; rxbuffer[i-1]!=FI; i++) {
fread_block(stream, rxbuffer+i, 1, timeout); fread_block(p, rxbuffer+i, 1);
} }
return i; return i;

Wyświetl plik

@ -6,7 +6,7 @@
* via serial interface to an ICOM using the "CI-V" interface. * via serial interface to an ICOM using the "CI-V" interface.
* *
* *
* $Id: icom.c,v 1.27 2001-06-03 19:54:05 f4cfe Exp $ * $Id: icom.c,v 1.28 2001-06-04 17:01:21 f4cfe Exp $
* *
* *
* *
@ -193,7 +193,7 @@ static const struct icom_addr icom_addr_list[] = {
* You might want to define yours, so you can customize it for your rig * You might want to define yours, so you can customize it for your rig
* *
* Basically, it sets up *priv * Basically, it sets up *priv
* REM: serial port is already open (rig->state->fd) * REM: serial port is already open (rig->state.rigport.fd)
*/ */
int icom_init(RIG *rig) int icom_init(RIG *rig)
{ {
@ -1977,7 +1977,7 @@ int icom_decode_event(RIG *rig)
rs = &rig->state; rs = &rig->state;
priv = (struct icom_priv_data*)rs->priv; priv = (struct icom_priv_data*)rs->priv;
frm_len = read_icom_frame(rs->stream, buf, rs->timeout); frm_len = read_icom_frame(&rs->rigport, buf);
/* /*
* the first 2 bytes must be 0xfe * the first 2 bytes must be 0xfe
* the 3rd one the emitter * the 3rd one the emitter

Wyświetl plik

@ -5,7 +5,7 @@
* will be used for obtaining rig capabilities. * will be used for obtaining rig capabilities.
* *
* *
* $Id: rig.h,v 1.33 2001-06-03 19:50:30 f4cfe Exp $ * $Id: rig.h,v 1.34 2001-06-04 17:01:21 f4cfe Exp $
* *
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -805,6 +805,49 @@ struct rig_caps {
/* more to come... */ /* more to come... */
}; };
/*
* yeah, looks like OO painstakingly programmed in C, sigh
*/
typedef struct {
union {
enum rig_port_e rig; /* serial, network, etc. */
enum ptt_type_e ptt;
enum dcd_type_e dcd;
} type;
int fd;
FILE *stream;
#ifdef _WIN32
int handle; /* for serial special handling (PTT,DCD,..) */
#endif
int write_delay; /* delay in ms between each byte sent out */
int post_write_delay; /* for some yaesu rigs */
struct timeval post_write_date; /* hamlib internal use */
int timeout; /* in ms */
int retry; /* maximum number of retries, 0 to disable */
char path[FILPATHLEN];
union {
struct {
int rate;
int data_bits;
int stop_bits;
enum serial_parity_e parity;
enum serial_handshake_e handshake;
} serial;
struct {
int pin;
} parallel;
struct {
/* place holder? */
} device;
#ifdef NET
struct {
struct sockaddr saddr;
} network;
#endif
} parm;
} port_t;
/* /*
* Rig state * Rig state
@ -816,6 +859,7 @@ struct rig_caps {
* not be initialized like caps are. * not be initialized like caps are.
*/ */
struct rig_state { struct rig_state {
#ifdef WANT_OLD_PORT_STUFF
enum rig_port_e port_type; /* serial, network, etc. */ enum rig_port_e port_type; /* serial, network, etc. */
int serial_rate; int serial_rate;
@ -835,11 +879,17 @@ struct rig_state {
char ptt_path[FILPATHLEN]; /* path to the keying device (serial,//) */ char ptt_path[FILPATHLEN]; /* path to the keying device (serial,//) */
char rig_path[FILPATHLEN]; /* serial port/network path(host:port) */ char rig_path[FILPATHLEN]; /* serial port/network path(host:port) */
double vfo_comp; /* VFO compensation in PPM, 0.0 to disable */
int fd; /* serial port/socket file handle */ int fd; /* serial port/socket file handle */
int ptt_fd; /* ptt port file handle */ int ptt_fd; /* ptt port file handle */
FILE *stream; /* serial port/socket (buffered) stream handle */ FILE *stream; /* serial port/socket (buffered) stream handle */
#else
port_t rigport;
port_t pttport;
port_t dcdport;
#endif
double vfo_comp; /* VFO compensation in PPM, 0.0 to disable */
int transceive; /* whether the transceive mode is on */ int transceive; /* whether the transceive mode is on */
int hold_decode;/* set to 1 to hold the event decoder (async) otherwise 0 */ int hold_decode;/* set to 1 to hold the event decoder (async) otherwise 0 */

Wyświetl plik

@ -6,7 +6,7 @@
* via serial interface to a Kenwood radio. * via serial interface to a Kenwood radio.
* *
* *
* $Id: kenwood.c,v 1.6 2001-05-22 21:59:26 f4cfe Exp $ * $Id: kenwood.c,v 1.7 2001-06-04 17:01:21 f4cfe Exp $
* *
* *
* *
@ -105,7 +105,7 @@ int kenwood_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int
rs = &rig->state; rs = &rig->state;
write_block(rs->fd, cmd, cmd_len, rs->write_delay, rs->post_write_delay); write_block(&rs->rigport, cmd, cmd_len);
/* /*
* buffered read are quite helpful here! * buffered read are quite helpful here!
@ -113,7 +113,7 @@ int kenwood_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int
*/ */
i = 0; i = 0;
do { do {
fread_block(rs->stream, data+i, 1, rs->timeout); fread_block(&rs->rigport, data+i, 1);
} while (data[i++] != EOM); } while (data[i++] != EOM);
*data_len = i; *data_len = i;

Wyświetl plik

@ -6,7 +6,7 @@
* via serial interface to an Icom PCR-1xxx radio. * via serial interface to an Icom PCR-1xxx radio.
* *
* *
* $Id: pcr.c,v 1.4 2001-06-02 17:52:55 f4cfe Exp $ * $Id: pcr.c,v 1.5 2001-06-04 17:01:21 f4cfe Exp $
* *
* *
* *
@ -100,7 +100,7 @@ int pcr_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *dat
rs = &rig->state; rs = &rig->state;
write_block(rs->fd, cmd, cmd_len, rs->write_delay, rs->post_write_delay); write_block(&rs->rigport, cmd, cmd_len);
/* /*
* buffered read are quite helpful here! * buffered read are quite helpful here!
@ -108,7 +108,7 @@ int pcr_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *dat
*/ */
i = 0; i = 0;
do { do {
fread_block(rs->stream, data+i, 1, rs->timeout); fread_block(&rs->rigport, data+i, 1);
} while (data[i++] != ';'); } while (data[i++] != ';');
*data_len = i; *data_len = i;

Wyświetl plik

@ -2,7 +2,7 @@
Copyright (C) 2000,2001 Stephane Fillod and Frank Singleton Copyright (C) 2000,2001 Stephane Fillod and Frank Singleton
This file is part of the hamlib package. This file is part of the hamlib package.
$Id: event.c,v 1.4 2001-06-02 17:56:37 f4cfe Exp $ $Id: event.c,v 1.5 2001-06-04 17:01:21 f4cfe Exp $
Hamlib is free software; you can redistribute it and/or modify it Hamlib is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -81,18 +81,18 @@ int add_trn_rig(RIG *rig)
rig_debug(RIG_DEBUG_ERR,"rig_open sigaction failed: %s\n", rig_debug(RIG_DEBUG_ERR,"rig_open sigaction failed: %s\n",
strerror(errno)); strerror(errno));
status = fcntl(rig->state.fd, F_SETOWN, getpid()); status = fcntl(rig->state.rigport.fd, F_SETOWN, getpid());
if (status < 0) if (status < 0)
rig_debug(RIG_DEBUG_ERR,"rig_open fcntl SETOWN failed: %s\n", rig_debug(RIG_DEBUG_ERR,"rig_open fcntl SETOWN failed: %s\n",
strerror(errno)); strerror(errno));
#ifndef _WIN32 #ifndef _WIN32
status = fcntl(rig->state.fd, F_SETSIG, SIGIO); status = fcntl(rig->state.rigport.fd, F_SETSIG, SIGIO);
if (status < 0) if (status < 0)
rig_debug(RIG_DEBUG_ERR,"rig_open fcntl SETSIG failed: %s\n", rig_debug(RIG_DEBUG_ERR,"rig_open fcntl SETSIG failed: %s\n",
strerror(errno)); strerror(errno));
status = fcntl(rig->state.fd, F_SETFL, O_ASYNC); status = fcntl(rig->state.rigport.fd, F_SETFL, O_ASYNC);
if (status < 0) if (status < 0)
rig_debug(RIG_DEBUG_ERR,"rig_open fcntl SETASYNC failed: %s\n", rig_debug(RIG_DEBUG_ERR,"rig_open fcntl SETASYNC failed: %s\n",
strerror(errno)); strerror(errno));
@ -116,7 +116,7 @@ int remove_trn_rig(RIG *rig)
* to find out which rig generated this event, * to find out which rig generated this event,
* and decode/process it. * and decode/process it.
* *
* assumes rig!=NULL, rig->state.fd>=0 * assumes rig!=NULL, rig->state.rigport.fd>=0
*/ */
static int search_rig_and_decode(RIG *rig, void *data) static int search_rig_and_decode(RIG *rig, void *data)
{ {
@ -126,11 +126,11 @@ static int search_rig_and_decode(RIG *rig, void *data)
#if 0 #if 0
siginfo_t *si = (siginfo_t*)data; siginfo_t *si = (siginfo_t*)data;
if (rig->state.fd != si->si_fd) if (rig->state.rigport.fd != si->si_fd)
return -1; return -1;
#else #else
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(rig->state.fd, &rfds); FD_SET(rig->state.rigport.fd, &rfds);
/* Read status immediately. */ /* Read status immediately. */
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 0; tv.tv_usec = 0;
@ -139,7 +139,7 @@ static int search_rig_and_decode(RIG *rig, void *data)
* since it is less portable than select * since it is less portable than select
* REM: EINTR possible with 0sec timeout? retval==0? * REM: EINTR possible with 0sec timeout? retval==0?
*/ */
retval = select(rig->state.fd+1, &rfds, NULL, NULL, &tv); retval = select(rig->state.rigport.fd+1, &rfds, NULL, NULL, &tv);
if (retval < 0) { if (retval < 0) {
rig_debug(RIG_DEBUG_ERR, "search_rig_and_decode: select: %s\n", rig_debug(RIG_DEBUG_ERR, "search_rig_and_decode: select: %s\n",
strerror(errno)); strerror(errno));

143
src/rig.c
Wyświetl plik

@ -2,7 +2,7 @@
Copyright (C) 2000,2001 Stephane Fillod and Frank Singleton Copyright (C) 2000,2001 Stephane Fillod and Frank Singleton
This file is part of the hamlib package. This file is part of the hamlib package.
$Id: rig.c,v 1.30 2001-06-03 19:54:05 f4cfe Exp $ $Id: rig.c,v 1.31 2001-06-04 17:01:21 f4cfe Exp $
Hamlib is free software; you can redistribute it and/or modify it Hamlib is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -257,24 +257,24 @@ RIG *rig_init(rig_model_t rig_model)
rs = &rig->state; rs = &rig->state;
rs->port_type = caps->port_type; /* default from caps */ rs->rigport.type.rig = caps->port_type; /* default from caps */
strncpy(rs->rig_path, DEFAULT_SERIAL_PORT, FILPATHLEN); strncpy(rs->rigport.path, DEFAULT_SERIAL_PORT, FILPATHLEN);
rs->serial_rate = caps->serial_rate_max; /* fastest ! */ rs->rigport.parm.serial.rate = caps->serial_rate_max; /* fastest ! */
rs->serial_data_bits = caps->serial_data_bits; rs->rigport.parm.serial.data_bits = caps->serial_data_bits;
rs->serial_stop_bits = caps->serial_stop_bits; rs->rigport.parm.serial.stop_bits = caps->serial_stop_bits;
rs->serial_parity = caps->serial_parity; rs->rigport.parm.serial.parity = caps->serial_parity;
rs->serial_handshake = caps->serial_handshake; rs->rigport.parm.serial.handshake = caps->serial_handshake;
rs->write_delay = caps->write_delay; rs->rigport.write_delay = caps->write_delay;
rs->post_write_delay = caps->post_write_delay; rs->rigport.post_write_delay = caps->post_write_delay;
rs->rigport.timeout = caps->timeout;
rs->rigport.retry = caps->retry;
rs->pttport.type.ptt = caps->ptt_type;
rs->dcdport.type.dcd = caps->dcd_type;
rs->timeout = caps->timeout;
rs->retry = caps->retry;
rs->transceive = caps->transceive;
rs->ptt_type = caps->ptt_type;
rs->dcd_type = caps->dcd_type;
rs->vfo_comp = 0.0; /* override it with preferences */ rs->vfo_comp = 0.0; /* override it with preferences */
rs->current_vfo = RIG_VFO_CURR; /* we don't know yet! */ rs->current_vfo = RIG_VFO_CURR; /* we don't know yet! */
rs->transceive = caps->transceive;
/* should it be a parameter to rig_init ? --SF */ /* should it be a parameter to rig_init ? --SF */
rs->itu_region = RIG_ITU_REGION2; rs->itu_region = RIG_ITU_REGION2;
@ -325,8 +325,7 @@ RIG *rig_init(rig_model_t rig_model)
rs->max_ifshift = caps->max_ifshift; rs->max_ifshift = caps->max_ifshift;
rs->announces = caps->announces; rs->announces = caps->announces;
rs->fd = -1; rs->rigport.fd = rs->pttport.fd = rs->dcdport.fd = -1;
rs->ptt_fd = -1;
/* /*
* let the backend a chance to setup his private data * let the backend a chance to setup his private data
@ -367,9 +366,9 @@ int rig_open(RIG *rig)
return -RIG_EINVAL; return -RIG_EINVAL;
caps = rig->caps; caps = rig->caps;
rig->state.fd = -1; rig->state.rigport.fd = -1;
switch(rig->state.port_type) { switch(rig->state.rigport.type.rig) {
case RIG_PORT_SERIAL: case RIG_PORT_SERIAL:
status = serial_open(&rig->state); status = serial_open(&rig->state);
if (status != 0) if (status != 0)
@ -377,10 +376,10 @@ int rig_open(RIG *rig)
break; break;
case RIG_PORT_DEVICE: case RIG_PORT_DEVICE:
status = open(rig->state.rig_path, O_RDWR, 0); status = open(rig->state.rigport.path, O_RDWR, 0);
if (status < 0) if (status < 0)
return -RIG_EIO; return -RIG_EIO;
rig->state.fd = status; rig->state.rigport.fd = status;
break; break;
case RIG_PORT_NONE: case RIG_PORT_NONE:
@ -392,32 +391,55 @@ int rig_open(RIG *rig)
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (rig->state.fd >= 0) if (rig->state.rigport.fd >= 0)
rig->state.stream = fdopen(rig->state.fd, "r+b"); rig->state.rigport.stream = fdopen(rig->state.rigport.fd, "r+b");
/* /*
* FIXME: what to do if PTT open fails or PTT unsupported? * FIXME: what to do if PTT open fails or PTT unsupported?
* fail rig_open? remember unallocating.. * fail rig_open? remember unallocating..
*/ */
switch(rig->state.ptt_type) { switch(rig->state.pttport.type.ptt) {
case RIG_PTT_NONE: case RIG_PTT_NONE:
case RIG_PTT_RIG:
break; break;
case RIG_PTT_SERIAL_RTS: case RIG_PTT_SERIAL_RTS:
case RIG_PTT_SERIAL_DTR: case RIG_PTT_SERIAL_DTR:
rig->state.ptt_fd = ser_ptt_open(&rig->state); rig->state.pttport.fd = ser_open(&rig->state.pttport);
if (rig->state.ptt_fd < 0) if (rig->state.pttport.fd < 0)
rig_debug(RIG_DEBUG_ERR, "Cannot open PTT device \"%s\"\n", rig_debug(RIG_DEBUG_ERR, "Cannot open PTT device \"%s\"\n",
rig->state.ptt_path); rig->state.pttport.path);
break; break;
case RIG_PTT_PARALLEL: case RIG_PTT_PARALLEL:
rig->state.ptt_fd = par_ptt_open(&rig->state); rig->state.pttport.fd = par_open(&rig->state.pttport);
if (rig->state.ptt_fd < 0) if (rig->state.pttport.fd < 0)
rig_debug(RIG_DEBUG_ERR, "Cannot open PTT device \"%s\"\n", rig_debug(RIG_DEBUG_ERR, "Cannot open PTT device \"%s\"\n",
rig->state.ptt_path); rig->state.pttport.path);
break; break;
default: default:
rig_debug(RIG_DEBUG_ERR, "Unsupported PTT type %d\n", rig_debug(RIG_DEBUG_ERR, "Unsupported PTT type %d\n",
rig->state.ptt_type); rig->state.pttport.type.ptt);
}
switch(rig->state.dcdport.type.dcd) {
case RIG_DCD_NONE:
case RIG_DCD_RIG:
break;
case RIG_DCD_SERIAL_DSR:
case RIG_DCD_SERIAL_CTS:
rig->state.dcdport.fd = ser_open(&rig->state.dcdport);
if (rig->state.dcdport.fd < 0)
rig_debug(RIG_DEBUG_ERR, "Cannot open DCD device \"%s\"\n",
rig->state.dcdport.path);
break;
case RIG_DCD_PARALLEL:
rig->state.dcdport.fd = par_open(&rig->state.dcdport);
if (rig->state.dcdport.fd < 0)
rig_debug(RIG_DEBUG_ERR, "Cannot open DCD device \"%s\"\n",
rig->state.dcdport.path);
break;
default:
rig_debug(RIG_DEBUG_ERR, "Unsupported DCD type %d\n",
rig->state.dcdport.type.dcd);
} }
add_opened_rig(rig); add_opened_rig(rig);
@ -471,30 +493,47 @@ int rig_close(RIG *rig)
* FIXME: what happens if PTT and rig ports are the same? * FIXME: what happens if PTT and rig ports are the same?
* (eg. ptt_type = RIG_PTT_SERIAL) * (eg. ptt_type = RIG_PTT_SERIAL)
*/ */
switch(rs->ptt_type) { switch(rs->pttport.type.ptt) {
case RIG_PTT_NONE: case RIG_PTT_NONE:
case RIG_PTT_RIG:
break; break;
case RIG_PTT_SERIAL_RTS: case RIG_PTT_SERIAL_RTS:
case RIG_PTT_SERIAL_DTR: case RIG_PTT_SERIAL_DTR:
ser_ptt_close(rs); ser_close(&rs->pttport);
break; break;
case RIG_PTT_PARALLEL: case RIG_PTT_PARALLEL:
par_ptt_close(rs); par_close(&rs->pttport);
break; break;
default: default:
rig_debug(RIG_DEBUG_ERR, "Unsupported PTT type %d\n", rig_debug(RIG_DEBUG_ERR, "Unsupported PTT type %d\n",
rs->ptt_type); rs->pttport.type.ptt);
} }
rs->ptt_fd = -1; switch(rs->dcdport.type.dcd) {
case RIG_DCD_NONE:
case RIG_DCD_RIG:
break;
case RIG_DCD_SERIAL_DSR:
case RIG_DCD_SERIAL_CTS:
ser_close(&rs->dcdport);
break;
case RIG_DCD_PARALLEL:
par_close(&rs->dcdport);
break;
default:
rig_debug(RIG_DEBUG_ERR, "Unsupported DCD type %d\n",
rs->dcdport.type.dcd);
}
if (rs->fd != -1) { rs->dcdport.fd = rs->pttport.fd = -1;
if (!rs->stream)
fclose(rs->stream); /* this closes also fd */ if (rs->rigport.fd != -1) {
if (!rs->rigport.stream)
fclose(rs->rigport.stream); /* this closes also fd */
else else
close(rs->fd); close(rs->rigport.fd);
rs->fd = -1; rs->rigport.fd = -1;
rs->stream = NULL; rs->rigport.stream = NULL;
} }
remove_opened_rig(rig); remove_opened_rig(rig);
@ -942,7 +981,7 @@ int rig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt)
caps = rig->caps; caps = rig->caps;
switch (rig->state.ptt_type) { switch (rig->state.pttport.type.ptt) {
case RIG_PTT_RIG: case RIG_PTT_RIG:
if (caps->set_ptt == NULL) if (caps->set_ptt == NULL)
return -RIG_ENIMPL; return -RIG_ENIMPL;
@ -966,10 +1005,10 @@ int rig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt)
case RIG_PTT_SERIAL_DTR: case RIG_PTT_SERIAL_DTR:
case RIG_PTT_SERIAL_RTS: case RIG_PTT_SERIAL_RTS:
ser_ptt_set(&rig->state, ptt); ser_ptt_set(&rig->state.pttport, ptt);
break; break;
case RIG_PTT_PARALLEL: case RIG_PTT_PARALLEL:
par_ptt_set(&rig->state, ptt); par_ptt_set(&rig->state.pttport, ptt);
break; break;
case RIG_PTT_NONE: case RIG_PTT_NONE:
@ -1007,7 +1046,7 @@ int rig_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
caps = rig->caps; caps = rig->caps;
switch (rig->state.ptt_type) { switch (rig->state.pttport.type.ptt) {
case RIG_PTT_RIG: case RIG_PTT_RIG:
if (caps->get_ptt == NULL) if (caps->get_ptt == NULL)
return -RIG_ENIMPL; return -RIG_ENIMPL;
@ -1031,10 +1070,10 @@ int rig_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
case RIG_PTT_SERIAL_RTS: case RIG_PTT_SERIAL_RTS:
case RIG_PTT_SERIAL_DTR: case RIG_PTT_SERIAL_DTR:
ser_ptt_get(&rig->state, ptt); ser_ptt_get(&rig->state.pttport, ptt);
break; break;
case RIG_PTT_PARALLEL: case RIG_PTT_PARALLEL:
par_ptt_get(&rig->state, ptt); par_ptt_get(&rig->state.pttport, ptt);
break; break;
case RIG_PTT_NONE: case RIG_PTT_NONE:
@ -1072,7 +1111,7 @@ int rig_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd)
caps = rig->caps; caps = rig->caps;
switch (rig->state.dcd_type) { switch (rig->state.dcdport.type.dcd) {
case RIG_DCD_RIG: case RIG_DCD_RIG:
if (caps->get_dcd == NULL) if (caps->get_dcd == NULL)
return -RIG_ENIMPL; return -RIG_ENIMPL;
@ -1096,10 +1135,10 @@ int rig_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd)
case RIG_DCD_SERIAL_CTS: case RIG_DCD_SERIAL_CTS:
case RIG_DCD_SERIAL_DSR: case RIG_DCD_SERIAL_DSR:
ser_dcd_get(&rig->state, dcd); ser_dcd_get(&rig->state.dcdport, dcd);
break; break;
case RIG_DCD_PARALLEL: case RIG_DCD_PARALLEL:
par_dcd_get(&rig->state, dcd); par_dcd_get(&rig->state.dcdport, dcd);
break; break;
case RIG_DCD_NONE: case RIG_DCD_NONE:

Wyświetl plik

@ -10,7 +10,7 @@
* ham packet softmodem written by Thomas Sailer, HB9JNX. * ham packet softmodem written by Thomas Sailer, HB9JNX.
* *
* *
* $Id: serial.c,v 1.10 2001-06-02 17:56:37 f4cfe Exp $ * $Id: serial.c,v 1.11 2001-06-04 17:01:21 f4cfe Exp $
* *
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -89,6 +89,7 @@ int serial_open(struct rig_state *rs) {
int fd; /* File descriptor for the port */ int fd; /* File descriptor for the port */
speed_t speed; /* serial comm speed */ speed_t speed; /* serial comm speed */
port_t *rp;
#ifdef HAVE_TERMIOS_H #ifdef HAVE_TERMIOS_H
struct termios options; struct termios options;
@ -103,17 +104,19 @@ int serial_open(struct rig_state *rs) {
if (!rs) if (!rs)
return -RIG_EINVAL; return -RIG_EINVAL;
rp = &rs->rigport;
/* /*
* Open in Non-blocking mode. Watch for EAGAIN errors! * Open in Non-blocking mode. Watch for EAGAIN errors!
*/ */
fd = open(rs->rig_path, O_RDWR | O_NOCTTY | O_NDELAY); fd = open(rp->path, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1) { if (fd == -1) {
/* Could not open the port. */ /* Could not open the port. */
rig_debug(RIG_DEBUG_ERR, "serial_open: Unable to open %s - %s\n", rig_debug(RIG_DEBUG_ERR, "serial_open: Unable to open %s - %s\n",
rs->rig_path, strerror(errno)); rp->path, strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
@ -133,7 +136,7 @@ int serial_open(struct rig_state *rs) {
* Set the baud rates to requested values * Set the baud rates to requested values
*/ */
switch(rs->serial_rate) { switch(rp->parm.serial.rate) {
case 300: case 300:
speed = B300; /* yikes... */ speed = B300; /* yikes... */
break; break;
@ -163,7 +166,7 @@ int serial_open(struct rig_state *rs) {
break; break;
default: default:
rig_debug(RIG_DEBUG_ERR, "open_serial: unsupported rate specified: %d\n", rig_debug(RIG_DEBUG_ERR, "open_serial: unsupported rate specified: %d\n",
rs->serial_rate); rp->parm.serial.rate);
close(fd); close(fd);
return -RIG_ECONF; return -RIG_ECONF;
} }
@ -182,7 +185,7 @@ int serial_open(struct rig_state *rs) {
* *
*/ */
switch(rs->serial_data_bits) { switch(rp->parm.serial.data_bits) {
case 7: case 7:
options.c_cflag &= ~CSIZE; options.c_cflag &= ~CSIZE;
options.c_cflag |= CS7; options.c_cflag |= CS7;
@ -192,8 +195,8 @@ int serial_open(struct rig_state *rs) {
options.c_cflag |= CS8; options.c_cflag |= CS8;
break; break;
default: default:
rig_debug(RIG_DEBUG_ERR,"open_serial: unsupported serial_data_bits specified: %d\n", rig_debug(RIG_DEBUG_ERR,"open_serial: unsupported serial_data_bits "
rs->serial_data_bits); "specified: %d\n", rp->parm.serial.data_bits);
close(fd); close(fd);
return -RIG_ECONF; return -RIG_ECONF;
break; break;
@ -204,7 +207,7 @@ int serial_open(struct rig_state *rs) {
* *
*/ */
switch(rs->serial_stop_bits) { switch(rp->parm.serial.stop_bits) {
case 1: case 1:
options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSTOPB;
break; break;
@ -213,8 +216,9 @@ int serial_open(struct rig_state *rs) {
break; break;
default: default:
rig_debug(RIG_DEBUG_ERR, "open_serial: unsupported serial_stop_bits specified: %d\n", rig_debug(RIG_DEBUG_ERR, "open_serial: unsupported serial_stop_bits "
rs->serial_stop_bits); "specified: %d\n",
rp->parm.serial.stop_bits);
close(fd); close(fd);
return -RIG_ECONF; return -RIG_ECONF;
break; break;
@ -225,7 +229,7 @@ int serial_open(struct rig_state *rs) {
* *
*/ */
switch(rs->serial_parity) { switch(rp->parm.serial.parity) {
case RIG_PARITY_NONE: case RIG_PARITY_NONE:
options.c_cflag &= ~PARENB; options.c_cflag &= ~PARENB;
break; break;
@ -238,8 +242,9 @@ int serial_open(struct rig_state *rs) {
options.c_cflag |= PARODD; options.c_cflag |= PARODD;
break; break;
default: default:
rig_debug(RIG_DEBUG_ERR, "open_serial: unsupported serial_parity specified: %d\n", rig_debug(RIG_DEBUG_ERR, "open_serial: unsupported serial_parity "
rs->serial_parity); "specified: %d\n",
rp->parm.serial.parity);
close(fd); close(fd);
return -RIG_ECONF; return -RIG_ECONF;
break; break;
@ -251,7 +256,7 @@ int serial_open(struct rig_state *rs) {
* *
*/ */
switch(rs->serial_handshake) { switch(rp->parm.serial.handshake) {
case RIG_HANDSHAKE_NONE: case RIG_HANDSHAKE_NONE:
options.c_cflag &= ~CRTSCTS; options.c_cflag &= ~CRTSCTS;
options.c_iflag &= ~IXON; options.c_iflag &= ~IXON;
@ -265,8 +270,9 @@ int serial_open(struct rig_state *rs) {
options.c_iflag &= ~IXON; options.c_iflag &= ~IXON;
break; break;
default: default:
rig_debug(RIG_DEBUG_ERR, "open_serial: unsupported flow_control specified: %d\n", rig_debug(RIG_DEBUG_ERR, "open_serial: unsupported flow_control "
rs->serial_handshake); "specified: %d\n",
rp->parm.serial.handshake);
close(fd); close(fd);
return -RIG_ECONF; return -RIG_ECONF;
break; break;
@ -323,8 +329,7 @@ int serial_open(struct rig_state *rs) {
} }
#endif #endif
rp->fd = fd;
rs->fd = fd;
return RIG_OK; return RIG_OK;
} }
@ -410,54 +415,55 @@ int read_sleep(int fd, unsigned char *rxbuffer, int num , int read_delay) {
* it could work very well also with any file handle, like a socket. * it could work very well also with any file handle, like a socket.
*/ */
int write_block(int fd, const unsigned char *txbuffer, size_t count, int write_delay, int post_write_delay /* , struct timeval *post_write_date */ ) int write_block(port_t *p, const char *txbuffer, size_t count)
{ {
int i; int i;
#ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY #ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY
if (post_write_date->tv_sec != 0) { if (p->post_write_date.tv_sec != 0) {
signed int date_delay; /* in us */ signed int date_delay; /* in us */
struct timeval tv; struct timeval tv;
/* FIXME in Y2038 ... */ /* FIXME in Y2038 ... */
gettimeofday(tv, NULL); gettimeofday(tv, NULL);
date_delay = post_write_delay*1000 - date_delay = p->post_write_delay*1000 -
((tv.tv_sec - post_write_date->tv_sec)*1000000 + ((tv.tv_sec - p->post_write_date->tv_sec)*1000000 +
(tv.tv_usec - post_write_date->tv_usec)); (tv.tv_usec - p->post_write_date->tv_usec));
if (date_delay > 0) { if (date_delay > 0) {
/* /*
* optional delay after last write * optional delay after last write
*/ */
usleep(date_delay); usleep(date_delay);
} }
post_write_date->tv_sec = 0; p->post_write_date.tv_sec = 0;
} }
#endif #endif
if (write_delay > 0) { if (p->write_delay > 0) {
for (i=0; i < count; i++) { for (i=0; i < count; i++) {
if (write(fd, txbuffer+i, 1) < 0) { if (write(p->fd, txbuffer+i, 1) < 0) {
rig_debug(RIG_DEBUG_ERR,"write_block() failed - %s\n", rig_debug(RIG_DEBUG_ERR,"write_block() failed - %s\n",
strerror(errno)); strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
usleep(write_delay*1000); usleep(p->write_delay*1000);
} }
} else { } else {
write(fd, txbuffer, count); write(p->fd, txbuffer, count);
} }
if (post_write_delay > 0) { if (p->post_write_delay > 0) {
#ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY #ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY
#define POST_WRITE_DELAY_TRSHLD 10 #define POST_WRITE_DELAY_TRSHLD 10
if (post_write_delay > POST_WRITE_DELAY_TRSHLD) if (p->post_write_delay > POST_WRITE_DELAY_TRSHLD)
gettimeofday(post_write_date, NULL); gettimeofday(p->post_write_date, NULL);
else else
#endif #else
usleep(post_write_delay*1000); /* optional delay after last write */ usleep(p->post_write_delay*1000); /* optional delay after last write */
/* otherwise some yaesu rigs get confused */ /* otherwise some yaesu rigs get confused */
/* with sequential fast writes*/ /* with sequential fast writes*/
#endif
} }
rig_debug(RIG_DEBUG_TRACE,"TX %d bytes\n",count); rig_debug(RIG_DEBUG_TRACE,"TX %d bytes\n",count);
dump_hex(txbuffer,count); dump_hex(txbuffer,count);
@ -477,7 +483,7 @@ int write_block(int fd, const unsigned char *txbuffer, size_t count, int write_d
* it could work very well also with any file handle, like a socket. * it could work very well also with any file handle, like a socket.
*/ */
int read_block(int fd, unsigned char *rxbuffer, size_t count, int timeout ) int read_block(port_t *p, char *rxbuffer, size_t count)
{ {
fd_set rfds; fd_set rfds;
struct timeval tv, tv_timeout; struct timeval tv, tv_timeout;
@ -485,18 +491,18 @@ int read_block(int fd, unsigned char *rxbuffer, size_t count, int timeout )
int retval; int retval;
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(fd, &rfds); FD_SET(p->fd, &rfds);
/* /*
* Wait up to timeout ms. * Wait up to timeout ms.
*/ */
tv_timeout.tv_sec = timeout/1000; tv_timeout.tv_sec = p->timeout/1000;
tv_timeout.tv_usec = (timeout%1000)*1000; tv_timeout.tv_usec = (p->timeout%1000)*1000;
while (count > 0) { while (count > 0) {
tv = tv_timeout; /* select may have updated it */ tv = tv_timeout; /* select may have updated it */
retval = select(fd+1, &rfds, NULL, NULL, &tv); retval = select(p->fd+1, &rfds, NULL, NULL, &tv);
if (!retval) { if (!retval) {
rig_debug(RIG_DEBUG_ERR,"rig timeout after %d chars or " rig_debug(RIG_DEBUG_ERR,"rig timeout after %d chars or "
"select error - %s!\n", "select error - %s!\n",
@ -508,7 +514,7 @@ int read_block(int fd, unsigned char *rxbuffer, size_t count, int timeout )
* grab bytes from the rig * grab bytes from the rig
* The file descriptor must have been set up non blocking. * The file descriptor must have been set up non blocking.
*/ */
rd_count = read(fd, rxbuffer+total_count, count); rd_count = read(p->fd, rxbuffer+total_count, count);
if (rd_count < 0) { if (rd_count < 0) {
rig_debug(RIG_DEBUG_ERR, "read_block: read failed - %s\n", rig_debug(RIG_DEBUG_ERR, "read_block: read failed - %s\n",
strerror(errno)); strerror(errno));
@ -523,7 +529,7 @@ int read_block(int fd, unsigned char *rxbuffer, size_t count, int timeout )
return total_count; /* return bytes count read */ return total_count; /* return bytes count read */
} }
int fread_block(FILE *stream, unsigned char *rxbuffer, size_t count, int timeout ) int fread_block(port_t *p, char *rxbuffer, size_t count)
{ {
fd_set rfds; fd_set rfds;
struct timeval tv, tv_timeout; struct timeval tv, tv_timeout;
@ -531,7 +537,7 @@ int fread_block(FILE *stream, unsigned char *rxbuffer, size_t count, int timeout
int retval; int retval;
int fd; int fd;
fd = fileno(stream); fd = fileno(p->stream);
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(fd, &rfds); FD_SET(fd, &rfds);
@ -539,15 +545,15 @@ int fread_block(FILE *stream, unsigned char *rxbuffer, size_t count, int timeout
/* /*
* Wait up to timeout ms. * Wait up to timeout ms.
*/ */
tv_timeout.tv_sec = timeout/1000; tv_timeout.tv_sec = p->timeout/1000;
tv_timeout.tv_usec = (timeout%1000)*1000; tv_timeout.tv_usec = (p->timeout%1000)*1000;
/* /*
* grab bytes from the rig * grab bytes from the rig
* The file descriptor must have been set up non blocking. * The file descriptor must have been set up non blocking.
*/ */
rd_count = fread(rxbuffer, 1, count, stream); rd_count = fread(rxbuffer, 1, count, p->stream);
if (rd_count < 0) { if (rd_count < 0) {
rig_debug(RIG_DEBUG_ERR, "read_block: read failed - %s\n", rig_debug(RIG_DEBUG_ERR, "read_block: read failed - %s\n",
strerror(errno)); strerror(errno));
@ -571,7 +577,7 @@ int fread_block(FILE *stream, unsigned char *rxbuffer, size_t count, int timeout
* grab bytes from the rig * grab bytes from the rig
* The file descriptor must have been set up non blocking. * The file descriptor must have been set up non blocking.
*/ */
rd_count = fread(rxbuffer+total_count, 1, count, stream); rd_count = fread(rxbuffer+total_count, 1, count, p->stream);
if (rd_count < 0) { if (rd_count < 0) {
rig_debug(RIG_DEBUG_ERR, "read_block: read failed - %s\n", rig_debug(RIG_DEBUG_ERR, "read_block: read failed - %s\n",
strerror(errno)); strerror(errno));
@ -590,17 +596,20 @@ int fread_block(FILE *stream, unsigned char *rxbuffer, size_t count, int timeout
* ser_ptt_set and par_ptt_set * ser_ptt_set and par_ptt_set
* ser_ptt_open/ser_ptt_close & par_ptt_open/par_ptt_close * ser_ptt_open/ser_ptt_close & par_ptt_open/par_ptt_close
* *
* assumes: rs is not NULL * ser_open/ser_close,par_open/par_close to be used for PTT and DCD
*
* assumes: p is not NULL
*/ */
#ifdef _WIN32 #ifdef _WIN32
int ser_ptt_open(struct rig_state *rs) int ser_open(port_t *p)
{ {
const char *path = rs->ptt_path; const char *path = p->path;
HANDLE h; HANDLE h;
DCB dcb; DCB dcb;
h = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); h = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, 0, NULL);
if (h == INVALID_HANDLE_VALUE) { if (h == INVALID_HANDLE_VALUE) {
rig_debug(RIG_DEBUG_ERR, "Cannot open PTT device \"%s\"\n", path); rig_debug(RIG_DEBUG_ERR, "Cannot open PTT device \"%s\"\n", path);
return -1; return -1;
@ -611,132 +620,199 @@ int ser_ptt_open(struct rig_state *rs)
CloseHandle(h); CloseHandle(h);
return -1; return -1;
} }
return (int)h; p->handle = h;
return 0;
} }
#else #else
int ser_ptt_open(struct rig_state *rs) int ser_open(port_t *p)
{ {
return open(rs->ptt_path, O_RDWR | O_NOCTTY); return (p->fd = open(p->path, O_RDWR | O_NOCTTY));
} }
#endif #endif
int ser_close(port_t *p)
{
#ifdef _WIN32
return CloseHandle(p->handle);
#else
return close(p->fd);
#endif
}
/*
* p is supposed to be &rig->state.pttport
*/
int ser_ptt_set(port_t *p, ptt_t pttx)
{
switch(p->type.ptt) {
#ifdef _WIN32
/*
* TODO: log error with 0x%lx GetLastError()
*/
case RIG_PTT_SERIAL_RTS:
return !EscapeCommFunction(p->handle, pttx==RIG_PTT_ON ?
SETRTS : CLRRTS);
case RIG_PTT_SERIAL_DTR:
return !EscapeCommFunction(p->handle, pttx==RIG_PTT_ON ?
SETDTR : CLRDTR);
#else
case RIG_PTT_SERIAL_RTS:
{
unsigned char y = TIOCM_RTS;
return ioctl(p->fd, pttx==RIG_PTT_ON ? TIOCMBIS : TIOCMBIC, &y);
}
case RIG_PTT_SERIAL_DTR:
{
unsigned char y = TIOCM_DTR;
return ioctl(p->fd, pttx==RIG_PTT_ON ? TIOCMBIS : TIOCMBIC, &y);
}
#endif
default:
rig_debug(RIG_DEBUG_ERR,"Unsupported PTT type %d\n",
p->type.ptt);
return -RIG_EINVAL;
}
return RIG_OK;
}
/*
* assumes pttx not NULL
*/
int ser_ptt_get(port_t *p, ptt_t *pttx)
{
unsigned char y;
int status;
switch(p->type.ptt) {
#ifdef _WIN32
/* TODO... */
#else
case RIG_PTT_SERIAL_RTS:
status = ioctl(p->fd, TIOCMGET, &y);
*pttx = y & TIOCM_RTS ? RIG_PTT_ON:RIG_PTT_OFF;
return status;
case RIG_PTT_SERIAL_DTR:
status = ioctl(p->fd, TIOCMGET, &y);
*pttx = y & TIOCM_DTR ? RIG_PTT_ON:RIG_PTT_OFF;
return status;
#endif
default:
rig_debug(RIG_DEBUG_ERR,"Unsupported PTT type %d\n",
p->type.ptt);
return -RIG_EINVAL;
}
return RIG_OK;
}
/*
* assumes dcdx not NULL
* p is supposed to be &rig->state.dcdport
*/
int ser_dcd_get(port_t *p, dcd_t *dcdx)
{
unsigned char y;
int status;
switch(p->type.dcd) {
#ifdef _WIN32
/* TODO... */
#else
case RIG_DCD_SERIAL_CTS:
status = ioctl(p->fd, TIOCMGET, &y);
*dcdx = y & TIOCM_CTS ? RIG_DCD_ON:RIG_DCD_OFF;
return status;
case RIG_DCD_SERIAL_DSR:
status = ioctl(p->fd, TIOCMGET, &y);
*dcdx = y & TIOCM_DSR ? RIG_DCD_ON:RIG_DCD_OFF;
return status;
#endif
default:
rig_debug(RIG_DEBUG_ERR,"Unsupported DCD type %d\n",
p->type.dcd);
return -RIG_EINVAL;
}
return RIG_OK;
}
/* /*
* TODO: to be called before exiting: atexit(parport_cleanup) * TODO: to be called before exiting: atexit(parport_cleanup)
* void parport_cleanup() { ioctl(fd, PPRELEASE); } * void parport_cleanup() { ioctl(fd, PPRELEASE); }
*/ */
int par_ptt_open(struct rig_state *rs) int par_open(port_t *p)
{ {
int ptt_fd; int fd;
ptt_fd = open(rs->ptt_path, O_RDWR); fd = open(p->path, O_RDWR);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
ioctl(ptt_fd, PPCLAIM); ioctl(fd, PPCLAIM);
#endif #endif
return ptt_fd; p->fd = fd;
return fd;
} }
int ser_ptt_set(struct rig_state *rs, ptt_t pttx) int par_close(port_t *p)
{ {
unsigned char y;
switch(rs->ptt_type) {
#ifdef _WIN32
/* TODO: log error with 0x%lx GetLastError() */
case RIG_PTT_SERIAL_RTS:
return !EscapeCommFunction((HANDLE)rs->ptt_fd, pttx ? SETRTS : CLRRTS);
case RIG_PTT_SERIAL_DTR:
return !EscapeCommFunction((HANDLE)rs->ptt_fd, pttx ? SETDTR : CLRDTR);
#else
case RIG_PTT_SERIAL_RTS:
y = TIOCM_RTS;
return ioctl(rs->ptt_fd, pttx ? TIOCMBIS : TIOCMBIC, &y);
case RIG_PTT_SERIAL_DTR:
y = TIOCM_DTR;
return ioctl(rs->ptt_fd, pttx ? TIOCMBIS : TIOCMBIC, &y);
#endif
default:
rig_debug(RIG_DEBUG_ERR,"Unsupported PTT type %d\n",
rs->ptt_type);
return -RIG_EINVAL;
}
return RIG_OK;
}
int par_ptt_set(struct rig_state *rs, ptt_t pttx)
{
switch(rs->ptt_type) {
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
case RIG_PTT_PARALLEL: ioctl(p->fd, PPRELEASE);
{
unsigned char reg;
reg = pttx ? 0x01:0x00;
return ioctl(rs->ptt_fd, PPWDATA, &reg);
}
#endif #endif
default: return close(p->fd);
rig_debug(RIG_DEBUG_ERR,"Unsupported PTT type %d\n",
rs->ptt_type);
return -RIG_EINVAL;
}
return RIG_OK;
} }
/* int par_ptt_set(port_t *p, ptt_t pttx)
* assumes pttx not NULL
*/
int ser_ptt_get(struct rig_state *rs, ptt_t *pttx)
{ {
unsigned char y; switch(p->type.ptt) {
int status;
switch(rs->ptt_type) {
#ifdef _WIN32
#else
case RIG_PTT_SERIAL_RTS:
status = ioctl(rs->ptt_fd, TIOCMGET, &y);
*pttx = y & TIOCM_RTS ? RIG_PTT_ON:RIG_PTT_OFF;
return status;
case RIG_PTT_SERIAL_DTR:
return -RIG_ENIMPL;
status = ioctl(rs->ptt_fd, TIOCMGET, &y);
*pttx = y & TIOCM_DTR ? RIG_PTT_ON:RIG_PTT_OFF;
return status;
#endif
default:
rig_debug(RIG_DEBUG_ERR,"Unsupported PTT type %d\n",
rs->ptt_type);
return -RIG_EINVAL;
}
return RIG_OK;
}
/*
* assumes pttx not NULL
*/
int par_ptt_get(struct rig_state *rs, ptt_t *pttx)
{
switch(rs->ptt_type) {
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
case RIG_PTT_PARALLEL: case RIG_PTT_PARALLEL:
{ {
unsigned char reg; unsigned char reg;
int status; int status;
status = ioctl(rs->ptt_fd, PPRDATA, &reg); status = ioctl(p->fd, PPRDATA, &reg);
*pttx = reg & 0x01 ? RIG_PTT_ON:RIG_PTT_OFF; if (pttx == RIG_PTT_ON)
reg |= 1 << p->parm.parallel.pin;
else
reg &= ~(1 << p->parm.parallel.pin);
return ioctl(p->fd, PPWDATA, &reg);
}
#endif
default:
rig_debug(RIG_DEBUG_ERR,"Unsupported PTT type %d\n",
p->type.ptt);
return -RIG_EINVAL;
}
return RIG_OK;
}
/*
* assumes pttx not NULL
*/
int par_ptt_get(port_t *p, ptt_t *pttx)
{
switch(p->type.ptt) {
#ifdef HAVE_LINUX_PPDEV_H
case RIG_PTT_PARALLEL:
{
unsigned char reg;
int status;
status = ioctl(p->fd, PPRDATA, &reg);
*pttx = reg & (1<<p->parm.parallel.pin) ?
RIG_PTT_ON:RIG_PTT_OFF;
return status; return status;
} }
#endif #endif
default: default:
rig_debug(RIG_DEBUG_ERR,"Unsupported PTT type %d\n", rig_debug(RIG_DEBUG_ERR,"Unsupported PTT type %d\n",
rs->ptt_type); p->type.ptt);
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
return RIG_OK; return RIG_OK;
@ -744,79 +820,27 @@ int par_ptt_get(struct rig_state *rs, ptt_t *pttx)
/* /*
* assumes dcdx not NULL * assumes dcdx not NULL
* FIXME: currently using state.ptt_fd. Should dcd_fd be opened instead?
*/ */
int ser_dcd_get(struct rig_state *rs, dcd_t *dcdx) int par_dcd_get(port_t *p, dcd_t *dcdx)
{ {
unsigned char y; switch(p->type.dcd) {
int status;
switch(rs->dcd_type) {
#ifdef _WIN32
#else
case RIG_DCD_SERIAL_CTS:
status = ioctl(rs->ptt_fd, TIOCMGET, &y);
*dcdx = y & TIOCM_CTS ? RIG_DCD_ON:RIG_DCD_OFF;
return status;
case RIG_DCD_SERIAL_DSR:
return -RIG_ENIMPL;
status = ioctl(rs->ptt_fd, TIOCMGET, &y);
*dcdx = y & TIOCM_DSR ? RIG_DCD_ON:RIG_DCD_OFF;
return status;
#endif
default:
rig_debug(RIG_DEBUG_ERR,"Unsupported DCD type %d\n",
rs->dcd_type);
return -RIG_EINVAL;
}
return RIG_OK;
}
/*
* assumes dcdx not NULL
* FIXME: currently using state.ptt_fd. Should dcd_fd be opened instead?
*/
int par_dcd_get(struct rig_state *rs, dcd_t *dcdx)
{
switch(rs->dcd_type) {
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
case RIG_DCD_PARALLEL: case RIG_DCD_PARALLEL:
{ {
unsigned char reg; unsigned char reg;
int status; int status;
status = ioctl(rs->ptt_fd, PPRDATA, &reg); status = ioctl(p->fd, PPRDATA, &reg);
*dcdx = reg & 0x01 ? RIG_DCD_ON:RIG_DCD_OFF; *dcdx = reg & (1<<p->parm.parallel.pin) ?
RIG_DCD_ON:RIG_DCD_OFF;
return status; return status;
} }
#endif #endif
default: default:
rig_debug(RIG_DEBUG_ERR,"Unsupported DCD type %d\n", rig_debug(RIG_DEBUG_ERR,"Unsupported DCD type %d\n",
rs->dcd_type); p->type.dcd);
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
return RIG_OK; return RIG_OK;
} }
#ifdef _WIN32
int ser_ptt_close(struct rig_state *rs)
{
return CloseHandle((HANDLE)rs->ptt_fd);
}
#else
int ser_ptt_close(struct rig_state *rs)
{
return close(rs->ptt_fd);
}
#endif
int par_ptt_close(struct rig_state *rs)
{
#ifdef HAVE_LINUX_PPDEV_H
ioctl(rs->ptt_fd, PPRELEASE);
#endif
return close(rs->ptt_fd);
}

Wyświetl plik

@ -6,7 +6,7 @@
* Provides useful routines for read/write serial data for communicating * Provides useful routines for read/write serial data for communicating
* via serial interface . * via serial interface .
* *
* $Id: serial.h,v 1.6 2001-06-02 17:56:37 f4cfe Exp $ * $Id: serial.h,v 1.7 2001-06-04 17:01:21 f4cfe Exp $
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -36,21 +36,21 @@ int serial_open(struct rig_state *rs);
#if 0 #if 0
int read_sleep(int fd, unsigned char *rxbuffer, int num , int read_delay); int read_sleep(int fd, unsigned char *rxbuffer, int num , int read_delay);
#endif #endif
int read_block(int fd, unsigned char *rxbuffer, size_t count, int timeout); int read_block(port_t *p, char *rxbuffer, size_t count);
int write_block(int fd, const unsigned char *txbuffer, size_t count, int write_delay, int post_write_delay); int write_block(port_t *p, const char *txbuffer, size_t count);
int fread_block(FILE *stream, unsigned char *rxbuffer, size_t count, int timeout); int fread_block(port_t *p, char *rxbuffer, size_t count);
/* Hamlib internal use, see rig.c */ /* Hamlib internal use, see rig.c */
int ser_ptt_open(struct rig_state *rs); int ser_open(port_t *p);
int par_ptt_open(struct rig_state *rs); int ser_close(port_t *p);
int ser_ptt_set(struct rig_state *rs, ptt_t pttx); int ser_ptt_set(port_t *p, ptt_t pttx);
int par_ptt_set(struct rig_state *rs, ptt_t pttx); int ser_ptt_get(port_t *p, ptt_t *pttx);
int ser_ptt_get(struct rig_state *rs, ptt_t *pttx); int ser_dcd_get(port_t *p, dcd_t *dcdx);
int par_ptt_get(struct rig_state *rs, ptt_t *pttx); int par_open(port_t *p);
int ser_dcd_get(struct rig_state *rs, dcd_t *dcdx); int par_close(port_t *p);
int par_dcd_get(struct rig_state *rs, dcd_t *dcdx); int par_ptt_set(port_t *p, ptt_t pttx);
int ser_ptt_close(struct rig_state *rs); int par_ptt_get(port_t *p, ptt_t *pttx);
int par_ptt_close(struct rig_state *rs); int par_dcd_get(port_t *p, dcd_t *dcdx);
#endif /* _SERIAL_H */ #endif /* _SERIAL_H */

Wyświetl plik

@ -3,7 +3,7 @@
* This programs dumps the mmeory contents of a rig. * This programs dumps the mmeory contents of a rig.
* *
* *
* $Id: dumpmem.c,v 1.1 2001-05-04 22:47:35 f4cfe Exp $ * $Id: dumpmem.c,v 1.2 2001-06-04 17:01:21 f4cfe Exp $
* *
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -67,7 +67,7 @@ int main (int argc, char *argv[])
exit(1); /* whoops! something went wrong (mem alloc?) */ exit(1); /* whoops! something went wrong (mem alloc?) */
} }
strncpy(my_rig->state.rig_path, SERIAL_PORT, FILPATHLEN); strncpy(my_rig->state.rigport.path, SERIAL_PORT, FILPATHLEN);
if (rig_open(my_rig)) if (rig_open(my_rig))
exit(2); exit(2);

Wyświetl plik

@ -7,7 +7,7 @@
* TODO: be more generic and add command line option to run * TODO: be more generic and add command line option to run
* in non-interactive mode * in non-interactive mode
* *
* $Id: rigctl.c,v 1.13 2001-06-03 19:54:05 f4cfe Exp $ * $Id: rigctl.c,v 1.14 2001-06-04 17:01:21 f4cfe Exp $
* *
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -221,11 +221,11 @@ printf("%s\n",opt_string);
if (!my_rig) if (!my_rig)
exit(1); /* whoops! something went wrong (mem alloc?) */ exit(1); /* whoops! something went wrong (mem alloc?) */
strncpy(my_rig->state.rig_path,SERIAL_PORT,FILPATHLEN); strncpy(my_rig->state.rigport.path, SERIAL_PORT, FILPATHLEN);
/* TODO: make this a parameter */ /* TODO: make this a parameter */
my_rig->state.ptt_type = RIG_PTT_PARALLEL; my_rig->state.pttport.type.ptt = RIG_PTT_PARALLEL;
strncpy(my_rig->state.ptt_path,"/dev/parport0",FILPATHLEN); strncpy(my_rig->state.pttport.path, "/dev/parport0", FILPATHLEN);
if ((retcode = rig_open(my_rig)) != RIG_OK) { if ((retcode = rig_open(my_rig)) != RIG_OK) {
fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode)); fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode));

Wyświetl plik

@ -43,7 +43,7 @@ int main (int argc, char *argv[])
exit(1); /* whoops! something went wrong (mem alloc?) */ exit(1); /* whoops! something went wrong (mem alloc?) */
} }
strncpy(my_rig->state.rig_path,SERIAL_PORT,FILPATHLEN); strncpy(my_rig->state.rigport.path,SERIAL_PORT,FILPATHLEN);
if (rig_open(my_rig)) if (rig_open(my_rig))
exit(2); exit(2);

Wyświetl plik

@ -39,7 +39,7 @@ int main ()
if (!my_rig) if (!my_rig)
exit(1); /* whoops! something went wrong (mem alloc?) */ exit(1); /* whoops! something went wrong (mem alloc?) */
strncpy(my_rig->state.rig_path,SERIAL_PORT,FILPATHLEN); strncpy(my_rig->state.rigport.path, SERIAL_PORT, FILPATHLEN);
if (rig_open(my_rig)) if (rig_open(my_rig))
exit(2); exit(2);

Wyświetl plik

@ -8,7 +8,7 @@
* /dev/winradio API. * /dev/winradio API.
* *
* *
* $Id: winradio.c,v 1.9 2001-06-02 18:08:40 f4cfe Exp $ * $Id: winradio.c,v 1.10 2001-06-04 17:01:21 f4cfe Exp $
* *
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -48,8 +48,8 @@
#define DEFAULT_WINRADIO_PATH "/dev/winradio0" #define DEFAULT_WINRADIO_PATH "/dev/winradio0"
int wr_rig_init(RIG *rig) { int wr_rig_init(RIG *rig) {
rig->state.port_type = RIG_PORT_DEVICE; rig->state.rigport.type.rig = RIG_PORT_DEVICE;
strncpy(rig->state.rig_path, DEFAULT_WINRADIO_PATH, FILPATHLEN); strncpy(rig->state.rigport.path, DEFAULT_WINRADIO_PATH, FILPATHLEN);
return RIG_OK; return RIG_OK;
} }
@ -59,13 +59,13 @@ int wr_set_freq(RIG *rig, vfo_t vfo, freq_t freq) {
if (freq > GHz(4.2)) if (freq > GHz(4.2))
return -RIG_EINVAL; return -RIG_EINVAL;
f = (unsigned long)freq; f = (unsigned long)freq;
if ( ioctl(rig->state.fd, RADIO_SET_FREQ, &f) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_SET_FREQ, &f) ) return -RIG_EINVAL;
return RIG_OK; return RIG_OK;
} }
int wr_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { int wr_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) {
unsigned long f; unsigned long f;
if ( ioctl(rig->state.fd, RADIO_GET_FREQ, &f) < 0 ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_GET_FREQ, &f) < 0 ) return -RIG_EINVAL;
*freq = (freq_t)f; *freq = (freq_t)f;
return RIG_OK; return RIG_OK;
} }
@ -90,13 +90,13 @@ int wr_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) {
} }
default: return -RIG_EINVAL; default: return -RIG_EINVAL;
} }
if ( ioctl(rig->state.fd, RADIO_SET_MODE, &m) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_SET_MODE, &m) ) return -RIG_EINVAL;
return RIG_OK; return RIG_OK;
} }
int wr_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { int wr_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) {
unsigned long m; unsigned long m;
if ( ioctl(rig->state.fd, RADIO_GET_MODE, &m) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_GET_MODE, &m) ) return -RIG_EINVAL;
*width = RIG_PASSBAND_NORMAL; *width = RIG_PASSBAND_NORMAL;
switch ( m ) { switch ( m ) {
@ -119,12 +119,12 @@ int wr_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) {
int wr_set_powerstat(RIG *rig, powerstat_t status) { int wr_set_powerstat(RIG *rig, powerstat_t status) {
unsigned long p = 1; unsigned long p = 1;
p = status==RIG_POWER_ON ? 1 : 0; p = status==RIG_POWER_ON ? 1 : 0;
if ( ioctl(rig->state.fd, RADIO_SET_POWER, &p) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_SET_POWER, &p) ) return -RIG_EINVAL;
return RIG_OK; return RIG_OK;
} }
int wr_get_powerstat(RIG *rig, powerstat_t *status) { int wr_get_powerstat(RIG *rig, powerstat_t *status) {
unsigned long p; unsigned long p;
if ( ioctl(rig->state.fd, RADIO_GET_POWER, &p) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_GET_POWER, &p) ) return -RIG_EINVAL;
*status = p ? RIG_POWER_ON : RIG_POWER_OFF; *status = p ? RIG_POWER_ON : RIG_POWER_OFF;
return RIG_OK; return RIG_OK;
} }
@ -133,7 +133,7 @@ int wr_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) {
switch ( func ) { switch ( func ) {
case RIG_FUNC_FAGC: { case RIG_FUNC_FAGC: {
unsigned long v = status ? 1 : 0; unsigned long v = status ? 1 : 0;
if ( ioctl(rig->state.fd, RADIO_SET_AGC, &v) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_SET_AGC, &v) ) return -RIG_EINVAL;
return RIG_OK; return RIG_OK;
} }
default: default:
@ -145,7 +145,7 @@ int wr_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) {
switch ( func ) { switch ( func ) {
case RIG_FUNC_FAGC: { case RIG_FUNC_FAGC: {
unsigned long v; unsigned long v;
if ( ioctl(rig->state.fd, RADIO_GET_AGC, &v) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_GET_AGC, &v) ) return -RIG_EINVAL;
*status = v; *status = v;
return RIG_OK; return RIG_OK;
} }
@ -159,24 +159,24 @@ int wr_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) {
switch ( level ) { switch ( level ) {
case RIG_LEVEL_AF: { case RIG_LEVEL_AF: {
unsigned long v; unsigned long v;
if ( ioctl(rig->state.fd, RADIO_GET_MAXVOL, &v) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_GET_MAXVOL, &v) ) return -RIG_EINVAL;
v *= val.f; v *= val.f;
if ( ioctl(rig->state.fd, RADIO_SET_VOL, &v) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_SET_VOL, &v) ) return -RIG_EINVAL;
return RIG_OK; return RIG_OK;
} }
case RIG_LEVEL_ATT: { case RIG_LEVEL_ATT: {
unsigned long v = val.i ? 1 : 0; unsigned long v = val.i ? 1 : 0;
if ( ioctl(rig->state.fd, RADIO_SET_ATTN, &v) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_SET_ATTN, &v) ) return -RIG_EINVAL;
return RIG_OK; return RIG_OK;
} }
case RIG_LEVEL_IF: { case RIG_LEVEL_IF: {
long v = val.i; long v = val.i;
if ( ioctl(rig->state.fd, RADIO_SET_IFS, &v) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_SET_IFS, &v) ) return -RIG_EINVAL;
return RIG_OK; return RIG_OK;
} }
case RIG_LEVEL_RF: { case RIG_LEVEL_RF: {
long v = val.f*100; /* iMaxIFGain on wHWVer > RHV_3150 */ long v = val.f*100; /* iMaxIFGain on wHWVer > RHV_3150 */
if ( ioctl(rig->state.fd, RADIO_SET_IFG, &v) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_SET_IFG, &v) ) return -RIG_EINVAL;
return RIG_OK; return RIG_OK;
} }
default: default:
@ -188,32 +188,32 @@ int wr_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) {
switch ( level ) { switch ( level ) {
case RIG_LEVEL_AF: { case RIG_LEVEL_AF: {
unsigned long v, mv; unsigned long v, mv;
if ( ioctl(rig->state.fd, RADIO_GET_MAXVOL, &mv) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_GET_MAXVOL, &mv) ) return -RIG_EINVAL;
if ( ioctl(rig->state.fd, RADIO_GET_VOL, &v) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_GET_VOL, &v) ) return -RIG_EINVAL;
val->f = (float)v / mv; val->f = (float)v / mv;
return RIG_OK; return RIG_OK;
} }
case RIG_LEVEL_ATT: { case RIG_LEVEL_ATT: {
unsigned long v; unsigned long v;
if ( ioctl(rig->state.fd, RADIO_GET_VOL, &v) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_GET_VOL, &v) ) return -RIG_EINVAL;
val->i = v ? rig->state.attenuator[0] : 0; val->i = v ? rig->state.attenuator[0] : 0;
return RIG_OK; return RIG_OK;
} }
case RIG_LEVEL_STRENGTH: { case RIG_LEVEL_STRENGTH: {
unsigned long v; unsigned long v;
if ( ioctl(rig->state.fd, RADIO_GET_SS, &v) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_GET_SS, &v) ) return -RIG_EINVAL;
val->i = v-60; /* 0..120, Hamlib assumes S9 = 0dB */ val->i = v-60; /* 0..120, Hamlib assumes S9 = 0dB */
return RIG_OK; return RIG_OK;
} }
case RIG_LEVEL_IF: { case RIG_LEVEL_IF: {
long v; long v;
if ( ioctl(rig->state.fd, RADIO_GET_IFS, &v) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_GET_IFS, &v) ) return -RIG_EINVAL;
val->i = v; val->i = v;
return RIG_OK; return RIG_OK;
} }
case RIG_LEVEL_RF: { case RIG_LEVEL_RF: {
long v; long v;
if ( ioctl(rig->state.fd, RADIO_GET_IFG, &v) ) return -RIG_EINVAL; if ( ioctl(rig->state.rigport.fd, RADIO_GET_IFG, &v) ) return -RIG_EINVAL;
val->f = (float)v/100; /* iMaxIFGain on wHWVer > RHV_3150 */ val->f = (float)v/100; /* iMaxIFGain on wHWVer > RHV_3150 */
return RIG_OK; return RIG_OK;
} }
@ -227,7 +227,7 @@ int wr_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) {
*/ */
const char *wr_get_info(RIG *rig) { const char *wr_get_info(RIG *rig) {
static char buf[100]; static char buf[100];
if ( ioctl(rig->state.fd, RADIO_GET_DESCR, buf) < 0 ) return "?"; if ( ioctl(rig->state.rigport.fd, RADIO_GET_DESCR, buf) < 0 ) return "?";
return buf; return buf;
} }

Wyświetl plik

@ -7,7 +7,7 @@
* box (FIF-232C) or similar * box (FIF-232C) or similar
* *
* *
* $Id: ft747.c,v 1.13 2001-05-06 01:34:25 javabear Exp $ * $Id: ft747.c,v 1.14 2001-06-04 17:01:21 f4cfe Exp $
* *
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -335,8 +335,10 @@ int ft747_open(RIG *rig) {
rig_s = &rig->state; rig_s = &rig->state;
rig_debug(RIG_DEBUG_VERBOSE,"ft747:rig_open: write_delay = %i msec \n", rig_s->write_delay); rig_debug(RIG_DEBUG_VERBOSE,"ft747:rig_open: write_delay = %i msec \n",
rig_debug(RIG_DEBUG_VERBOSE,"ft747:rig_open: post_write_delay = %i msec \n", rig_s->post_write_delay); rig_s->rigport.write_delay);
rig_debug(RIG_DEBUG_VERBOSE,"ft747:rig_open: post_write_delay = %i msec \n",
rig_s->rigport.post_write_delay);
/* TODO */ /* TODO */
@ -400,7 +402,7 @@ int ft747_set_freq(RIG *rig, vfo_t vfo, freq_t freq) {
rig_debug(RIG_DEBUG_VERBOSE,"ft747: requested freq after conversion = %Li Hz \n", from_bcd(p->p_cmd,8)* 10 ); rig_debug(RIG_DEBUG_VERBOSE,"ft747: requested freq after conversion = %Li Hz \n", from_bcd(p->p_cmd,8)* 10 );
cmd = p->p_cmd; /* get native sequence */ cmd = p->p_cmd; /* get native sequence */
write_block(rig_s->fd, cmd, YAESU_CMD_LENGTH, rig_s->write_delay, rig_s->post_write_delay); write_block(&rig_s->rigport, cmd, YAESU_CMD_LENGTH);
return RIG_OK; return RIG_OK;
} }
@ -780,14 +782,15 @@ static int ft747_get_update_data(RIG *rig) {
/* send PACING cmd to rig */ /* send PACING cmd to rig */
cmd = p->p_cmd; cmd = p->p_cmd;
write_block(rig_s->fd, cmd, YAESU_CMD_LENGTH, rig_s->write_delay, rig_s->post_write_delay); write_block(&rig_s->rigport, cmd, YAESU_CMD_LENGTH);
/* send UPDATE comand to fetch data*/ /* send UPDATE comand to fetch data*/
ft747_send_priv_cmd(rig,FT_747_NATIVE_UPDATE); ft747_send_priv_cmd(rig,FT_747_NATIVE_UPDATE);
/* n = read_sleep(rig_s->fd,p->update_data, FT747_STATUS_UPDATE_DATA_LENGTH, FT747_DEFAULT_READ_TIMEOUT); */ /* n = read_sleep(rig_s->fd,p->update_data, FT747_STATUS_UPDATE_DATA_LENGTH, FT747_DEFAULT_READ_TIMEOUT); */
n = read_block(rig_s->fd,p->update_data, FT747_STATUS_UPDATE_DATA_LENGTH, FT747_DEFAULT_READ_TIMEOUT); n = read_block(&rig_s->rigport, p->update_data,
FT747_STATUS_UPDATE_DATA_LENGTH);
return 0; return 0;
@ -835,7 +838,7 @@ static int ft747_send_priv_cmd(RIG *rig, unsigned char ci) {
} }
cmd = (unsigned char *) p->pcs[cmd_index].nseq; /* get native sequence */ cmd = (unsigned char *) p->pcs[cmd_index].nseq; /* get native sequence */
write_block(rig_s->fd, cmd, YAESU_CMD_LENGTH, rig_s->write_delay, rig_s->post_write_delay); write_block(&rig_s->rigport, cmd, YAESU_CMD_LENGTH);
return RIG_OK; return RIG_OK;

Wyświetl plik

@ -6,7 +6,7 @@
* via serial interface to an FT-847 using the "CAT" interface. * via serial interface to an FT-847 using the "CAT" interface.
* *
* *
* $Id: ft847.c,v 1.12 2001-05-22 18:05:29 f4cfe Exp $ * $Id: ft847.c,v 1.13 2001-06-04 17:01:21 f4cfe Exp $
* *
* *
* *
@ -422,7 +422,7 @@ static int ft847_send_priv_cmd(RIG *rig, unsigned char ci) {
} }
cmd = (unsigned char *) p->pcs[cmd_index].nseq; /* get native sequence */ cmd = (unsigned char *) p->pcs[cmd_index].nseq; /* get native sequence */
write_block(rig_s->fd, cmd, YAESU_CMD_LENGTH, rig_s->write_delay, rig_s->post_write_delay); write_block(&rig_s->rigport, cmd, YAESU_CMD_LENGTH);
return RIG_OK; return RIG_OK;
@ -487,7 +487,7 @@ int ft847_set_freq(RIG *rig, vfo_t vfo, freq_t freq) {
rig_debug(RIG_DEBUG_VERBOSE,"ft847: requested freq after conversion = %Li Hz \n", from_bcd_be(p->p_cmd,8)* 10 ); rig_debug(RIG_DEBUG_VERBOSE,"ft847: requested freq after conversion = %Li Hz \n", from_bcd_be(p->p_cmd,8)* 10 );
cmd = p->p_cmd; /* get native sequence */ cmd = p->p_cmd; /* get native sequence */
write_block(rig_s->fd, cmd, YAESU_CMD_LENGTH, rig_s->write_delay, rig_s->post_write_delay); write_block(&rig_s->rigport, cmd, YAESU_CMD_LENGTH);
return RIG_OK; return RIG_OK;
} }