Initial alpha release

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@1096 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.1.4
Stéphane Fillod, F8CFE 2002-07-06 09:27:38 +00:00
rodzic ef95000c65
commit b8dbee6114
6 zmienionych plików z 559 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,22 @@
INCLUDES = @INCLUDES@ @GNURADIO_FLAGS@
lib_LTLIBRARIES = libhamlib-gnuradio.la
libhamlib_gnuradio_la_SOURCES = gnuradio.cc gr.c
libhamlib_gnuradio_la_LDFLAGS = -no-undefined -module -version-info 0:0:0
# assumes we have libgnuradio, libfftw and c++
#libhamlib_gnuradio_la_LIBADD = ../src/libhamlib.la @GNURADIO_LIBS@ -lstdc++
libhamlib_gnuradio_la_LIBADD = ../src/libhamlib.la -L. -lgnuradio -lfftw -lrfftw -lstdc++
noinst_HEADERS = gnuradio.h gr_priv.h
noinst_PROGRAMS = testgr
testgr_SOURCES = testgr.cc
testgr_LDADD = ../src/libhamlib.la @GNURADIO_LIBS@
testgr_LDFLAGS = "-dlopen libhamlib-gnuradio.la"
testgr_DEPENDENCIES = libhamlib-gnuradio.la ../src/libhamlib.la

Wyświetl plik

@ -0,0 +1,250 @@
/* -*- Mode: c++ -*- */
/*
* Hamlib GNUradio backend - main file
* Copyright (c) 2001,2002 by Stephane Fillod
*
* $Id: gnuradio.cc,v 1.1 2002-07-06 09:27:38 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
* 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 Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/*
* Simple backend of a chirp source.
*/
#include <VrSigSource.h>
#include <VrAudioSource.h>
#include <VrNullSink.h>
#include <VrAudioSink.h>
#include <VrSum.h>
#include <VrConnect.h>
#include <VrMultiTask.h>
/* move these into struct gnuradio_priv ? */
#define SAMPLING_FREQUENCY 5e6
#define MAX_FREQUENCY (SAMPLING_FREQUENCY / 2)
#define CARRIER_FREQ 1.070e6 // AM 1070
#define AMPLITUDE 1.0
#define WAVEFORM VR_SIN_WAVE
#include <stdlib.h>
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
#include <sys/ioctl.h>
#include <math.h>
#include <hamlib/rig.h>
#include <misc.h>
#include "gnuradio.h"
#include "gr_priv.h" // struct gnuradio_priv_data
static void init_chan(RIG *rig, vfo_t vfo, channel_t *chan)
{
chan->channel_num = 0;
chan->vfo = vfo;
strcpy(chan->channel_desc, strvfo(vfo));
chan->freq = MHz(145);
chan->mode = RIG_MODE_FM;
chan->width = rig_passband_normal(rig, RIG_MODE_FM);
chan->tx_freq = chan->freq;
chan->tx_mode = chan->mode;
chan->tx_width = chan->width;
chan->split = RIG_SPLIT_OFF;
chan->rptr_shift = RIG_RPT_SHIFT_NONE;
chan->rptr_offs = 0;
chan->ctcss_tone = 0;
chan->dcs_code = 0;
chan->ctcss_sql = 0;
chan->dcs_sql = 0;
chan->rit = 0;
chan->xit = 0;
chan->tuning_step = 0;
chan->ant = 0;
chan->funcs = (setting_t)0;
memset(chan->levels, 0, RIG_SETTING_MAX*sizeof(value_t));
}
int gr_init(RIG *rig)
{
struct gnuradio_priv_data *priv;
priv = (struct gnuradio_priv_data*)malloc(sizeof(struct gnuradio_priv_data));
if (!priv)
return -RIG_ENOMEM;
rig->state.priv = (void*)priv;
rig_debug(RIG_DEBUG_VERBOSE,"%s called\n", __FUNCTION__ );
rig->state.rigport.type.rig = RIG_PORT_NONE;
memset(priv->parms, 0, RIG_SETTING_MAX*sizeof(value_t));
init_chan(rig, RIG_VFO_A, &priv->vfo_a);
priv->curr = &priv->vfo_a;
priv->curr_vfo = priv->last_vfo = RIG_VFO_A;
// or whatever
priv->source = new VrSigSource<IOTYPE>(SAMPLING_FREQUENCY, WAVEFORM, CARRIER_FREQ, 2*AMPLITUDE);
//priv->source = new VrAudioSource<short>(SAMPLING_FREQUENCY);
priv->sink = new VrNullSink<short>();
//priv->sink = new VrAudioSink<short>();
priv->m = new VrMultiTask ();
priv->m->add (priv->sink);
// now wire it all together from the sink, back to the sources
NWO_CONNECT (priv->source, priv->sink);
return RIG_OK;
}
int gr_open(RIG *rig)
{
struct gnuradio_priv_data *priv = (struct gnuradio_priv_data*)rig->state.priv;
rig_debug(RIG_DEBUG_VERBOSE,"%s called\n", __FUNCTION__);
priv->m->start();
return RIG_OK;
}
int gr_close(RIG *rig)
{
rig_debug(RIG_DEBUG_VERBOSE,"%s called\n", __FUNCTION__);
return RIG_OK;
}
int gr_cleanup(RIG *rig)
{
struct gnuradio_priv_data *priv = (struct gnuradio_priv_data*)rig->state.priv;
rig_debug(RIG_DEBUG_VERBOSE,"%s called\n", __FUNCTION__);
delete priv->m;
delete priv->sink;
delete priv->source;
if (rig->state.priv)
free(rig->state.priv);
rig->state.priv = NULL;
return RIG_OK;
}
int gr_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
{
struct gnuradio_priv_data *priv = (struct gnuradio_priv_data *)rig->state.priv;
channel_t *curr = priv->curr;
char fstr[20];
sprintf_freq(fstr, freq);
rig_debug(RIG_DEBUG_VERBOSE,"%s called: %s %s\n",
__FUNCTION__, strvfo(vfo), fstr);
curr->freq = freq;
priv->source->setFrequency(freq);
return RIG_OK;
}
int gr_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
{
struct gnuradio_priv_data *priv = (struct gnuradio_priv_data *)rig->state.priv;
channel_t *curr = priv->curr;
rig_debug(RIG_DEBUG_VERBOSE,"%s called: %s\n", __FUNCTION__, strvfo(vfo));
*freq = curr->freq;
return RIG_OK;
}
/*
* Does nothing yet
*/
int gr_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
{
struct gnuradio_priv_data *priv = (struct gnuradio_priv_data *)rig->state.priv;
channel_t *curr = priv->curr;
char buf[16];
sprintf_freq(buf, width);
rig_debug(RIG_DEBUG_VERBOSE,"%s called: %s %s %s\n",
__FUNCTION__, strvfo(vfo), strmode(mode), buf);
curr->mode = mode;
curr->width = width;
return RIG_OK;
}
int gr_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
{
struct gnuradio_priv_data *priv = (struct gnuradio_priv_data *)rig->state.priv;
channel_t *curr = priv->curr;
rig_debug(RIG_DEBUG_VERBOSE,"%s called: %s\n", __FUNCTION__, strvfo(vfo));
*mode = curr->mode;
*width = curr->width;
return RIG_OK;
}
int gr_get_vfo(RIG *rig, vfo_t *vfo)
{
struct gnuradio_priv_data *priv = (struct gnuradio_priv_data *)rig->state.priv;
*vfo = priv->curr_vfo;
rig_debug(RIG_DEBUG_VERBOSE,"%s called: %s\n", __FUNCTION__, strvfo(*vfo));
return RIG_OK;
}
int initrigs_gnuradio(void *be_handle)
{
rig_debug(RIG_DEBUG_VERBOSE, "gnuradio: _init called\n");
rig_register(&gr_caps);
return RIG_OK;
}

Wyświetl plik

@ -0,0 +1,46 @@
/*
* Hamlib GNUradio backend - main header
* Copyright (c) 2001,2002 by Stephane Fillod
*
* $Id: gnuradio.h,v 1.1 2002-07-06 09:27:38 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
* 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 Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef _GNURADIO_H
#define _GNURADIO_H 1
#include <hamlib/rig.h>
__BEGIN_DECLS
int gr_init(RIG *rig);
int gr_cleanup(RIG *rig);
int gr_open(RIG *rig);
int gr_close(RIG *rig);
int gr_set_freq(RIG *rig, vfo_t vfo, freq_t freq);
int gr_get_freq(RIG *rig, vfo_t vfo, freq_t *freq);
int gr_get_vfo(RIG *rig, vfo_t *vfo);
int gr_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width);
int gr_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width);
extern const struct rig_caps gr_caps;
extern BACKEND_EXPORT(int) initrigs_gnuradio(void *be_handle);
__END_DECLS
#endif /* _GNURADIO_H */

93
gnuradio/gr.c 100644
Wyświetl plik

@ -0,0 +1,93 @@
/*
* Hamlib GNUradio backend - main file
* Copyright (c) 2001,2002 by Stephane Fillod
*
* $Id: gr.c,v 1.1 2002-07-06 09:27:38 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
* 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 Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <hamlib/rig.h>
#include "gnuradio.h"
/*
* GNU Radio (hacking version) rig capabilities.
*/
#define GR_FUNC RIG_FUNC_NONE
#define GR_LEVEL RIG_LEVEL_NONE
#define GR_PARM RIG_PARM_NONE
#define GR_VFO_OP RIG_OP_NONE
#define GR_SCAN RIG_SCAN_NONE
#define GR_MODES (RIG_MODE_WFM)
#define GR_VFO RIG_VFO_A
const struct rig_caps gr_caps = {
rig_model: RIG_MODEL_GNURADIO,
model_name: "GNU Radio dev",
mfg_name: "GNU",
version: "0.1",
copyright: "GPL",
status: RIG_STATUS_ALPHA,
rig_type: RIG_TYPE_PCRECEIVER,
targetable_vfo: 0,
ptt_type: RIG_PTT_RIG,
dcd_type: RIG_DCD_RIG,
port_type: RIG_PORT_NONE,
has_get_func: GR_FUNC,
has_set_func: GR_FUNC,
has_get_level: GR_LEVEL,
has_set_level: RIG_LEVEL_SET(GR_LEVEL),
has_get_parm: GR_PARM,
has_set_parm: RIG_PARM_SET(GR_PARM),
ctcss_list: NULL,
dcs_list: NULL,
chan_list: {
RIG_CHAN_END,
},
scan_ops: GR_SCAN,
vfo_ops: GR_VFO_OP,
transceive: RIG_TRN_OFF,
attenuator: { RIG_DBLST_END, },
preamp: { RIG_DBLST_END, },
rx_range_list2: { {start:kHz(150),end:MHz(1500),modes:GR_MODES,
low_power:-1,high_power:-1,GR_VFO},
RIG_FRNG_END, },
tx_range_list2: { RIG_FRNG_END, },
tuning_steps: { {GR_MODES,1}, RIG_TS_END, },
priv: NULL, /* priv */
rig_init: gr_init,
rig_cleanup: gr_cleanup,
rig_open: gr_open,
rig_close: gr_close,
set_freq: gr_set_freq,
get_freq: gr_get_freq,
get_vfo: gr_get_vfo,
set_mode: gr_set_mode,
get_mode: gr_get_mode,
};

54
gnuradio/gr_priv.h 100644
Wyświetl plik

@ -0,0 +1,54 @@
/*
* Hamlib GNUradio backend - gnuradio priv structure
* Copyright (c) 2001,2002 by Stephane Fillod
*
* $Id: gr_priv.h,v 1.1 2002-07-06 09:27:38 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
* 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 Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef _GR_PRIV_H
#define _GR_PRIV_H 1
/*
* Simple backend of a chirp source.
*/
#include <VrSigSource.h>
#include <VrSink.h>
#include <VrMultiTask.h>
#include <hamlib/rig.h>
#define IOTYPE float
struct gnuradio_priv_data {
/* current vfo already in rig_state ? */
vfo_t curr_vfo;
vfo_t last_vfo; /* VFO A or VFO B, when in MEM mode */
value_t parms[RIG_SETTING_MAX];
channel_t *curr; /* points to vfo_a, vfo_b or mem[] */
channel_t vfo_a;
VrSigSource<IOTYPE> *source;
VrSink<short> *sink;
VrMultiTask *m;
};
#endif

94
gnuradio/testgr.cc 100644
Wyświetl plik

@ -0,0 +1,94 @@
/* -*- Mode: c++ -*- */
/*
* Copyright 2002 Stephane Fillod
*
* This file is part of Hamlib. Some parts from GNU radio.
*
*/
#include <stdio.h>
#include <hamlib/rig.h>
#include "gr_priv.h"
#include <VrSigSource.h>
#include <GrFFTSink.h>
#include <VrNullSink.h>
#include <GrMultiply.h>
#include <VrSum.h>
#include <VrConnect.h>
#include <VrMultiTask.h>
#include "VrGUI.h"
#define SAMPLING_FREQUENCY 5e6
#define CARRIER_FREQ 1.070e6 // AM 1070
#define MAX_FREQUENCY (SAMPLING_FREQUENCY / 2)
static RIG *my_rig;
void set_my_freq(double f)
{
rig_set_freq(my_rig, RIG_VFO_CURR, (freq_t)f);
}
int main(int argc, char *argv[])
{
int retcode; /* generic return code from functions */
struct gnuradio_priv_data *priv;
GrFFTSink<IOTYPE> *fftsink;
VrGUI *guimain = new VrGUI(argc, argv);
VrGUILayout *horiz = guimain->top->horizontal();
VrGUILayout *vert = horiz->vertical();
printf("testgr:hello, I am your main() !\n");
my_rig = rig_init(RIG_MODEL_GNURADIO);
if (!my_rig) {
fprintf(stderr,"Unknown rig num: %d\n", RIG_MODEL_GNURADIO);
fprintf(stderr,"Please check riglist.h\n");
exit(1); /* whoops! something went wrong (mem alloc?) */
}
// turn this into a macro
priv = (struct gnuradio_priv_data*)my_rig->state.priv;
if (priv == NULL) {
printf("Internal error, can't retrieve priv data!\n");
exit(3);
}
fftsink = new GrFFTSink<IOTYPE>(vert, 300, 450, 1024);
priv->m->add (fftsink);
(void) new VrGUINumber(horiz, "Carrier", "Frequency (Hz)", set_my_freq,
MAX_FREQUENCY, CARRIER_FREQ);
// now wire it all together from the sink, back to the sources
NWO_CONNECT (priv->source, fftsink);
retcode = rig_open(my_rig); /* start */
if (retcode != RIG_OK) {
printf("rig_open: error = %s\n", rigerror(retcode));
exit(2);
}
guimain->start();
while (1) {
guimain->processEvents(10 /*ms*/);
priv->m->process();
}
rig_close(my_rig); /* close port */
rig_cleanup(my_rig); /* if you care about memory */
printf("Rig closed ok\n");
return 0;
}