1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
/*
* Hamlib KIT backend - Universal Software Radio Peripheral
* Copyright (c) 2010 by Stephane Fillod
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <hamlib/config.h>
/*
* Compile only this model if usrp is available
*/
#if defined(HAVE_USRP)
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <usrp/usrp_standard.h>
#include "usrp_impl.h"
#include "token.h"
struct usrp_priv_data {
usrp_standard_rx *urx;
usrp_standard_tx *utx;
freq_t if_mix_freq;
};
int usrp_init(RIG *rig)
{
// cppcheck-suppress leakReturnValNotUsed
STATE(rig)->priv = static_cast<struct usrp_priv_data*>(malloc(sizeof(struct usrp_priv_data)));
if (!STATE(rig)->priv) {
/* whoops! memory shortage! */
return -RIG_ENOMEM;
}
return RIG_OK;
}
int usrp_cleanup(RIG *rig)
{
if (!rig)
return -RIG_EINVAL;
if (STATE(rig)->priv)
free(STATE(rig)->priv);
STATE(rig)->priv = NULL;
return RIG_OK;
}
int usrp_open(RIG *rig)
{
struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
int which_board = 0;
int decim = 125;
priv->urx = usrp_standard_rx::make (which_board, decim, 1, -1, usrp_standard_rx::FPGA_MODE_NORMAL).get();
if (priv->urx == 0)
return -RIG_EIO;
return RIG_OK;
}
int usrp_close(RIG *rig)
{
struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
if (!priv)
{
rig_debug(RIG_DEBUG_ERR, "%s: priv == NULL?\n", __func__);
return -RIG_EARG;
}
delete priv->urx;
return RIG_OK;
}
/*
* Assumes rig!=NULL, STATE(rig)->priv!=NULL
*/
int usrp_set_conf(RIG *rig, hamlib_token_t token, const char *val)
{
struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
if (!priv)
{
rig_debug(RIG_DEBUG_ERR, "%s: priv == NULL?\n", __func__);
return -RIG_EARG;
}
switch(token) {
case TOK_IFMIXFREQ:
sscanf(val, "%" SCNfreq, &priv->if_mix_freq);
break;
default:
return -RIG_EINVAL;
}
return RIG_OK;
}
/*
* assumes rig!=NULL,
* Assumes rig!=NULL, STATE(rig)->priv!=NULL
* and val points to a buffer big enough to hold the conf value.
*/
int usrp_get_conf(RIG *rig, hamlib_token_t token, char *val)
{
const struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
if (!priv)
{
rig_debug(RIG_DEBUG_ERR, "%s: priv == NULL?\n", __func__);
return -RIG_EARG;
}
switch(token) {
case TOK_IFMIXFREQ:
sprintf(val, "%" PRIfreq, priv->if_mix_freq);
break;
default:
return -RIG_EINVAL;
}
return RIG_OK;
}
int usrp_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
{
const struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
int chan = 0;
if (!priv)
{
rig_debug(RIG_DEBUG_ERR, "%s: priv == NULL?\n", __func__);
return -RIG_EARG;
}
if (!priv->urx->set_rx_freq (chan, freq))
return -RIG_EPROTO;
return RIG_OK;
}
int usrp_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
{
const struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
int chan = 0;
if (!priv)
{
rig_debug(RIG_DEBUG_ERR, "%s: priv == NULL?\n", __func__);
return -RIG_EARG;
}
*freq = priv->urx->rx_freq (chan);
return RIG_OK;
}
const char * usrp_get_info(RIG *rig)
{
return NULL;
}
#endif /* HAVE_USRP */
|