kopia lustrzana https://github.com/Hamlib/Hamlib
Initial revision, very alpha stage
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@92 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.1.0
rodzic
2a57632a0f
commit
1fb830bbce
|
@ -0,0 +1,74 @@
|
|||
|
||||
#include <rigcaps.h>
|
||||
|
||||
/* These are all potential candidates that can go into the API,
|
||||
* after some cleanup, like type standardization, etc..
|
||||
*/
|
||||
|
||||
void cmd_set_ptt_on(RIG *rig);
|
||||
void cmd_set_ptt_off(RIG *rig);
|
||||
|
||||
void cmd_set_freq_main_vfo(RIG *rig, unsigned char d1, unsigned char d2,
|
||||
unsigned char d3, unsigned char d4);
|
||||
|
||||
void cmd_set_freq_sat_rx_vfo(RIG *rig, unsigned char d1, unsigned char d2,
|
||||
unsigned char d3, unsigned char d4);
|
||||
|
||||
void cmd_set_freq_sat_tx_vfo(RIG *rig, unsigned char d1, unsigned char d2,
|
||||
unsigned char d3, unsigned char d4);
|
||||
|
||||
void cmd_set_opmode_main_vfo(RIG *rig, unsigned char d1);
|
||||
void cmd_set_opmode_sat_rx_vfo(RIG *rig, unsigned char d1);
|
||||
void cmd_set_opmode_sat_tx_vfo(RIG *rig, unsigned char d1);
|
||||
|
||||
void cmd_set_ctcss_dcs_main_vfo(RIG *rig, unsigned char d1);
|
||||
void cmd_set_ctcss_dcs_sat_rx_vfo(RIG *rig, unsigned char d1);
|
||||
void cmd_set_ctcss_dcs_sat_tx_vfo(RIG *rig, unsigned char d1);
|
||||
|
||||
void cmd_set_ctcss_freq_main_vfo(RIG *rig, unsigned char d1);
|
||||
void cmd_set_ctcss_freq_sat_rx_vfo(RIG *rig, unsigned char d1);
|
||||
void cmd_set_ctcss_freq_sat_tx_vfo(RIG *rig, unsigned char d1);
|
||||
|
||||
void cmd_set_dcs_code_main_vfo(RIG *rig, unsigned char d1, unsigned char d2);
|
||||
void cmd_set_dcs_code_sat_rx_vfo(RIG *rig, unsigned char d1, unsigned char d2);
|
||||
void cmd_set_dcs_code_sat_tx_vfo(RIG *rig, unsigned char d1, unsigned char d2);
|
||||
|
||||
void cmd_set_repeater_shift_minus(RIG *rig);
|
||||
void cmd_set_repeater_shift_plus(RIG *rig);
|
||||
void cmd_set_repeater_shift_simplex(RIG *rig);
|
||||
|
||||
void cmd_set_repeater_offset(RIG *rig, unsigned char d1, unsigned char d2,
|
||||
unsigned char d3, unsigned char d4);
|
||||
|
||||
unsigned char cmd_get_rx_status(RIG *rig);
|
||||
unsigned char cmd_get_tx_status(RIG *rig);
|
||||
|
||||
/*
|
||||
* Get frequency and mode info
|
||||
*
|
||||
*/
|
||||
|
||||
long int cmd_get_freq_mode_status_main_vfo(RIG *rig, unsigned char *mode);
|
||||
long int cmd_get_freq_mode_status_sat_rx_vfo(RIG *rig, unsigned char *mode);
|
||||
long int cmd_get_freq_mode_status_sat_tx_vfo(RIG *rig, unsigned char *mode);
|
||||
|
||||
|
||||
/*
|
||||
* Set frequency in Hz and mode
|
||||
*
|
||||
*/
|
||||
|
||||
void cmd_set_freq_main_vfo_hz(RIG *rig,freq_t freq, rig_mode_t mode);
|
||||
void cmd_set_freq_sat_rx_vfo_hz(RIG *rig,freq_t freq, rig_mode_t mode);
|
||||
void cmd_set_freq_sat_tx_vfo_hz(RIG *rig,freq_t freq, rig_mode_t mode);
|
||||
|
||||
|
||||
/*
|
||||
* Set Repeater offset in Hz.
|
||||
*
|
||||
*/
|
||||
|
||||
void cmd_set_repeater_offset_hz(RIG *rig,freq_t freq);
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,185 @@
|
|||
/* hamlib - Control your rig!
|
||||
Copyright (C) 2000 Stephane Fillod
|
||||
This file is part of the hamlib package.
|
||||
|
||||
Hamlib is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Hamlib is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with sane; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
#include <rig.h>
|
||||
|
||||
|
||||
/* It would be nice to have an automatic way of referencing all the backends
|
||||
* supported by hamlib. Maybe this array should be placed in a separate file..
|
||||
*/
|
||||
extern const struct rig_caps ft847_caps;
|
||||
extern const struct rig_caps ic706_caps;
|
||||
extern const struct rig_caps ic706mkiig_caps;
|
||||
|
||||
static const struct rig_caps *rig_base[] = {
|
||||
&ft847_caps, &ic706_caps, &ic706mkiig_caps, /* ... */ NULL, };
|
||||
|
||||
|
||||
RIG *rig_open(const char *rig_path, rig_model_t rig_model)
|
||||
{
|
||||
RIG *rig;
|
||||
int i;
|
||||
|
||||
/* lookup for this rig */
|
||||
for (i=0; rig_base[i]; i++) {
|
||||
if (rig_base[i]->rig_model == rig_model)
|
||||
break;
|
||||
}
|
||||
if (rig_base[i] == NULL) {
|
||||
/* rig not supported, sorry! */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* okay, we've found it. Allocate some memory and set it to zeros, */
|
||||
/* and especially the callbacks */
|
||||
rig = calloc(1, sizeof(RIG));
|
||||
if (rig == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* remember, rig->caps is readonly */
|
||||
rig->caps = rig_base[i];
|
||||
|
||||
/* populate the rig->state here */
|
||||
switch (port_type) {
|
||||
case SERIAL_PORT:
|
||||
rig->state.serial_rate = get_from_preference_or_default();
|
||||
rig->state.serial_data_bits = get_from_preference_or_default();
|
||||
rig->state.serial_stop_bits = get_from_preference_or_default();
|
||||
rig->state.serial_parity = get_from_preference_or_default();
|
||||
strncpy(rig->state.rig_path, rig_path, MAXRIGPATHLEN);
|
||||
/* serial_open would be cool */
|
||||
rig->state.fd = serial_open(rig_path, O_RDWR /* serial parms... */);
|
||||
/* chech return code.. */
|
||||
|
||||
/* let the backend a chance to setup his private data */
|
||||
if (rig->caps->rig_init != NULL)
|
||||
rig->caps->rig_init(rig);
|
||||
break;
|
||||
|
||||
case TCP_PORT:
|
||||
/* get hostname, port name, create socket, connect, etc. */
|
||||
break;
|
||||
|
||||
default: /* bail out, port not supported! */
|
||||
break;
|
||||
}
|
||||
|
||||
#define PROBE_OK 0
|
||||
|
||||
/* check we haven't been fooled */
|
||||
if (rig->caps->rig_probe != NULL)
|
||||
if (rig->caps->rig_probe(rig) != PROBE_OK) {
|
||||
/* not what we expected! release the rig */
|
||||
rig_close(rig);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
return rig;
|
||||
}
|
||||
|
||||
|
||||
/* typicall cmd_* wrapper */
|
||||
int cmd_set_freq_main_vfo_hz(RIG *rig, freq_t freq, rig_mode_t mode)
|
||||
{
|
||||
if (rig == NULL || rig->caps)
|
||||
return -1; /* EINVAL */
|
||||
if (rig->caps->set_freq_main_vfo_hz == NULL)
|
||||
return -2; /* not implemented */
|
||||
else
|
||||
return rig->caps->set_freq_main_vfo_hz(&rig->state, freq, mode);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* close port and release memory
|
||||
*/
|
||||
int rig_close(RIG *rig)
|
||||
{
|
||||
if (rig == NULL || rig->caps)
|
||||
return -1;
|
||||
|
||||
if (rig->caps->rig_cleanup)
|
||||
rig->caps->rig_cleanup(rig);
|
||||
|
||||
free(rig);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* CAUTION: this is really Experimental, It never worked!!
|
||||
* try to guess a rig, can be very buggy! (but fun if it works!)
|
||||
* FIXME: finish me and handle nicely errors
|
||||
*/
|
||||
RIG *rig_probe(const char *port_path)
|
||||
{
|
||||
RIG *rig;
|
||||
int i;
|
||||
|
||||
for (i = 0; rig_base[i]; i++) {
|
||||
if (rig_base[i]->rig_probe != NULL) {
|
||||
rig = rig_open(port_path, rig_base[i]->rig_model);
|
||||
if (rig && rig_base[i]->rig_probe(rig) == PROBE_OK)
|
||||
return rig;
|
||||
else
|
||||
rig_close(rig);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Gets rig capabilities.
|
||||
*
|
||||
*/
|
||||
|
||||
const struct rig_caps *rig_get_caps(rig_model_t rig_model) {
|
||||
|
||||
int i;
|
||||
const struct rig_caps *rc;
|
||||
|
||||
/* lookup for this rig */
|
||||
for (i=0; rig_base[i]; i++) {
|
||||
if (rig_base[i]->rig_model == rig_model)
|
||||
break;
|
||||
}
|
||||
if (rig_base[i] == NULL) {
|
||||
/* rig not supported, sorry! */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rc = rig_base[i];
|
||||
printf("rig = %s \n", rc->model_name);
|
||||
|
||||
printf("rig serial_rate_min = = %u \n", rc->serial_rate_min);
|
||||
printf("rig serial_rate_max = = %u \n", rc->serial_rate_max);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
/* hamlib - Copyright (C) 2000 Frank Singleton
|
||||
*
|
||||
* rigcaps.h - Copyrith (C) 2000 Frank Singleton and Stephane Fillod
|
||||
* This program defines some rig capabilities structures that
|
||||
* will be used for obtaining rig capabilities,
|
||||
*
|
||||
*
|
||||
* $Id: rigcaps.h,v 1.1 2000-09-14 00:50:55 f4cfe Exp $ *
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Basic rig type, can store some useful
|
||||
* info about different radios. Each lib must
|
||||
* be able to populate this structure, so we can make
|
||||
* useful enquiries about capablilities.
|
||||
*/
|
||||
|
||||
#ifndef _RIGCAPS_H
|
||||
#define _RIGCAPS_H 1
|
||||
|
||||
#include <riglist.h> /* list in another file to not mess up w/ this one */
|
||||
|
||||
#include <rig.h>
|
||||
|
||||
typedef struct rig RIG; /* forward reference to <rig.h> */
|
||||
struct rig_state;
|
||||
|
||||
|
||||
enum serial_parity_e {
|
||||
RIG_PARITY_NONE = 0,
|
||||
RIG_PARITY_ODD,
|
||||
RIG_PARITY_EVEN
|
||||
};
|
||||
|
||||
enum rig_type_e {
|
||||
RIG_TYPE_TRANSCEIVER = 0, /* aka base station */
|
||||
RIG_TYPE_HANDHELD,
|
||||
RIG_TYPE_MOBILE,
|
||||
RIG_TYPE_RECEIVER,
|
||||
RIG_TYPE_SCANNER,
|
||||
RIG_TYPE_COMPUTER, /* eg. Pegasus */
|
||||
/* etc. */
|
||||
RIG_TYPE_OTHER
|
||||
};
|
||||
|
||||
/* development status of the backend */
|
||||
enum rig_status_e {
|
||||
RIG_STATUS_ALPHA = 0,
|
||||
RIG_STATUS_BETA,
|
||||
RIG_STATUS_STABLE,
|
||||
RIG_STATUS_NEW
|
||||
};
|
||||
|
||||
#ifdef __GNUC__
|
||||
typedef unsigned long long int freq_t; /* in Hz, must be >32bits for SHF! */
|
||||
#else
|
||||
typedef struct {
|
||||
unsigned long int val[2];
|
||||
} freq_t;
|
||||
#endif
|
||||
|
||||
typedef unsigned int rig_mode_t;
|
||||
|
||||
/* Do not use an enum since this will be used w/ rig_mode_t bit fields */
|
||||
#define RIG_MODE_AM (1<<0)
|
||||
#define RIG_MODE_CW (1<<1)
|
||||
#define RIG_MODE_USB (1<<2) /* select somewhere else the filters ? */
|
||||
#define RIG_MODE_LSB (1<<3)
|
||||
#define RIG_MODE_RTTY (1<<4)
|
||||
#define RIG_MODE_FM (1<<5)
|
||||
#define RIG_MODE_WFM (1<<6)
|
||||
#define RIG_MODE_NFM (1<<7) /* should we distinguish modes w/ filers? */
|
||||
#define RIG_MODE_NAM (1<<8) /* Narrow AM */
|
||||
#define RIG_MODE_CWR (1<<9) /* Reverse CW */
|
||||
|
||||
|
||||
#define RIGNAMSIZ 30
|
||||
#define RIGVERSIZ 8
|
||||
#define MAXRIGPATHLEN 100
|
||||
#define FRQRANGESIZ 30
|
||||
|
||||
|
||||
/* put together a buch of this struct in an array to define
|
||||
* what your have access to
|
||||
*/
|
||||
struct freq_range_list {
|
||||
freq_t start;
|
||||
freq_t end;
|
||||
unsigned long modes; /* OR'ed RIG_MODE_* */
|
||||
int low_power; /* in mW, -1 for no power (ie. rx list) */
|
||||
int high_power; /* in mW, -1 for no power (ie. rx list) */
|
||||
}
|
||||
|
||||
/* Basic rig type, can store some useful
|
||||
* info about different radios. Each lib must
|
||||
* be able to populate this structure, so we can make
|
||||
* useful enquiries about capablilities.
|
||||
*/
|
||||
|
||||
/* The main idea of this struct is that it will be defined by the backend
|
||||
* rig driver, and will remain readonly for the application
|
||||
*/
|
||||
struct rig_caps {
|
||||
rig_model_t rig_model; /* eg. RIG_MODEL_FT847 */
|
||||
char model_name[RIGNAMSIZ]; /* eg "ft847" */
|
||||
char mfg_name[RIGNAMSIZ]; /* eg "Yeasu" */
|
||||
char version[RIGVERSIZ]; /* driver version, eg "0.5" */
|
||||
enum rig_status_e status; /* among ALPHA, BETA, STABLE, NEW */
|
||||
enum rig_type_e rig_type;
|
||||
unsigned short int serial_rate_min; /* eg 4800 */
|
||||
unsigned short int serial_rate_max; /* eg 9600 */
|
||||
unsigned char serial_data_bits; /* eg 8 */
|
||||
unsigned char serial_stop_bits; /* eg 2 */
|
||||
enum serial_parity_e serial_parity; /* */
|
||||
struct freq_range_list rx_range_list[FRQRANGESIZ];
|
||||
struct freq_range_list tx_range_list[FRQRANGESIZ];
|
||||
int (*rig_init)(RIG *rig); /* setup *priv */
|
||||
int (*rig_cleanup)(RIG *rig);
|
||||
int (*rig_probe)(RIG *rig); /* Experimental: may work.. */
|
||||
int (*set_freq_main_vfo_hz)(struct rig_state *rig_s, freq_t freq, rig_mode_t mode);
|
||||
/* etc... */
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* example of 3.5MHz -> 3.8MHz, 100W transmit range
|
||||
* tx_range_list = {{3500000,3800000,RIG_MODE_AM|RIG_MODE_CW,100000},0}
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#endif /* _RIGCAPS_H */
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/* hamlib - Copyright (C) 2000 Frank Singleton
|
||||
*
|
||||
* riglist.h - Copyrith (C) 2000 Stephane Fillod
|
||||
* This program defines the list of supported rigs.
|
||||
*
|
||||
*
|
||||
* $Id: riglist.h,v 1.1 2000-09-14 00:50:55 f4cfe Exp $ *
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _RIGLIST_H
|
||||
#define _RIGLIST_H 1
|
||||
|
||||
|
||||
enum rig_model_e {
|
||||
RIG_MODEL_FT847 = 0,
|
||||
RIG_MODEL_FT1000,
|
||||
RIG_MODEL_FT1000D,
|
||||
RIG_MODEL_FT747,
|
||||
RIG_MODEL_FT840,
|
||||
RIG_MODEL_FT920,
|
||||
RIG_MODEL_TS570D,
|
||||
RIG_MODEL_TS870S,
|
||||
RIG_MODEL_TS950,
|
||||
RIG_MODEL_IC706,
|
||||
RIG_MODEL_IC706MKII,
|
||||
RIG_MODEL_IC706MKIIG
|
||||
/* etc. */
|
||||
};
|
||||
|
||||
typedef enum rig_model_e rig_model_t;
|
||||
|
||||
|
||||
#endif /* _RIGLIST_H */
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
#include <rig.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define SERIAL_PORT "/dev/ttyS1"
|
||||
|
||||
int main ()
|
||||
{
|
||||
RIG *my_rig;
|
||||
|
||||
/* allocate memory, setup & open port */
|
||||
my_rig = rig_open(SERIAL_PORT, RIG_MODEL_FT847);
|
||||
if (!my_rig) exit(1); /* whoops! smth went wrong (mem alloc?) */
|
||||
|
||||
/* at this point, the RIG* struct is automatically populated */
|
||||
|
||||
printf("Port %s opened ok\n",SERIAL_PORT);
|
||||
|
||||
cmd_set_freq_main_vfo_hz(my_rig, 439700000, RIG_MODE_FM);
|
||||
|
||||
rig_close(my_rig); /* close port and release memory */
|
||||
|
||||
printf("port %s closed ok \n",SERIAL_PORT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Ładowanie…
Reference in New Issue