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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
|
/* -*- c++ -*- */
/*
* Copyright 2013-2017,2020 Thomas C. McDermott, N5EG.
*
* This 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 3, or (at your option)
* any later version.
*
* This software 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
// -----------------------------------------------------------------
// Revisions
//
// Mar 1, 2015 - Additions for ALEX friendly registers.
//
// July 2017 - Modified to allow up to 8 receivers. No longer emits
// 256 sample buffers to gnuradio, rather each stream
// contains a smaller number of samples dependent on
// the number of receivers.
// February 2020 - Update to gnuradio 3.8 by AA4HS
// -----------------------------------------------------------------
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "hermesNB_impl.h"
#include "HermesProxy.h"
#include <stdio.h> // for DEBUG PRINTF's
HermesProxy* Hermes; // make it visible to metis.cc
namespace gr {
namespace hpsdr {
hermesNB::sptr
hermesNB::make(int RxFreq0, int RxFreq1, int RxFreq2, int RxFreq3,
int RxFreq4, int RxFreq5, int RxFreq6, int RxFreq7,
int TxFreq, int RxPre,
int PTTModeSel, int PTTTxMute, int PTTRxMute,
unsigned char TxDr, int RxSmp, const char* Intfc,
const char * ClkS, int AlexRA, int AlexTA,
int AlexHPF, int AlexLPF, int Verbose, int NumRx,
const char* MACAddr)
{
return gnuradio::get_initial_sptr
(new hermesNB_impl(RxFreq0, RxFreq1, RxFreq2, RxFreq3, RxFreq4, RxFreq5,
RxFreq6, RxFreq7, TxFreq, RxPre, PTTModeSel, PTTTxMute,
PTTRxMute, TxDr, RxSmp, Intfc, ClkS, AlexRA, AlexTA,
AlexHPF, AlexLPF, Verbose, NumRx, MACAddr));
}
/*
* The private constructor
*/
hermesNB_impl::hermesNB_impl(int RxFreq0, int RxFreq1, int RxFreq2, int RxFreq3,
int RxFreq4, int RxFreq5, int RxFreq6, int RxFreq7,
int TxFreq, int RxPre,
int PTTModeSel, int PTTTxMute, int PTTRxMute,
unsigned char TxDr, int RxSmp, const char* Intfc,
const char * ClkS, int AlexRA, int AlexTA,
int AlexHPF, int AlexLPF, int Verbose, int NumRx,
const char* MACAddr)
: gr::block("hermesNB",
gr::io_signature::make(1, 1, sizeof(gr_complex)), // inputs to hermesNB block
gr::io_signature::make(1, MAXRECEIVERS, sizeof(gr_complex))) // outputs from hermesNB block
{
Hermes = new HermesProxy(RxFreq0, RxFreq1, RxFreq2, RxFreq3, RxFreq4,
RxFreq5, RxFreq6, RxFreq7, TxFreq, RxPre, PTTModeSel, PTTTxMute,
PTTRxMute, TxDr, RxSmp, Intfc, ClkS, AlexRA, AlexTA,
AlexHPF, AlexLPF, Verbose, NumRx, MACAddr); // Create proxy, do Hermes ethernet discovery
//Hermes->RxSampleRate = RxSmp;
//Hermes->RxPreamp = RxPre;
gr::block::set_output_multiple(256); // process outputs in groups of at least 256 samples
//gr::block::set_relative_rate((double) NumRx); // FIXME - need to also account for Rx sample rate
}
/*
* Our virtual destructor.
* NOTE: In V3.9 of gnuradio, destructor never gets called,
* but all resources are cleaned up anyway.
* Move to ::stop() so that statistics are printed.
*/
hermesNB_impl::~hermesNB_impl()
{
//delete Hermes;
}
bool hermesNB::stop() // override base class
{
Hermes->Stop(); // stop ethernet activity on Hermes
delete Hermes; // Stop is guaranteed to be called
// by gnuradio.
return gr::block::stop(); // call base class stop()
}
bool hermesNB::start() // override base class
{
Hermes->Start(); // start rx stream on Hermes
return gr::block::start(); // call base class start()
}
void hermesNB::set_Receive0Frequency (float Rx0F) // callback to allow slider to set frequency
{
Hermes->Receive0Frequency = (unsigned)Rx0F; // slider must be of type real, convert to unsigned
}
void hermesNB::set_Receive1Frequency (float Rx1F) // callback to allow slider to set frequency
{
Hermes->Receive1Frequency = (unsigned)Rx1F; // slider must be of type real, convert to unsigned
}
void hermesNB::set_Receive2Frequency (float Rx2F) // callback to allow slider to set frequency
{
Hermes->Receive2Frequency = (unsigned)Rx2F; // slider must be of type real, convert to unsigned
}
void hermesNB::set_Receive3Frequency (float Rx3F) // callback to allow slider to set frequency
{
Hermes->Receive3Frequency = (unsigned)Rx3F; // slider must be of type real, convert to unsigned
}
void hermesNB::set_Receive4Frequency (float Rx4F) // callback to allow slider to set frequency
{
Hermes->Receive4Frequency = (unsigned)Rx4F; // slider must be of type real, convert to unsigned
}
void hermesNB::set_Receive5Frequency (float Rx5F) // callback to allow slider to set frequency
{
Hermes->Receive5Frequency = (unsigned)Rx5F; // slider must be of type real, convert to unsigned
}
void hermesNB::set_Receive6Frequency (float Rx6F) // callback to allow slider to set frequency
{
Hermes->Receive6Frequency = (unsigned)Rx6F; // slider must be of type real, convert to unsigned
}
void hermesNB::set_Receive7Frequency (float Rx7F) // callback to allow slider to set frequency
{
Hermes->Receive7Frequency = (unsigned)Rx7F; // slider must be of type real, convert to unsigned
}
void hermesNB::set_TransmitFrequency (float TxF) // callback to allow slider to set frequency
{
Hermes->TransmitFrequency = (unsigned)TxF; // slider must be of type real, convert to unsigned
}
void hermesNB::set_RxSampRate(int RxSmp) // callback to set RxSampleRate
{
Hermes->RxSampleRate = RxSmp;
}
void hermesNB::set_RxPreamp(int RxPre) // callback to set RxPreamp on or off
{
Hermes->RxPreamp = (bool)RxPre;
}
void hermesNB::set_PTTMode(int PTTmode) // callback to set PTTMode (Off, Vox, On)
{
Hermes->PTTMode = PTTmode;
}
void hermesNB::set_PTTOffMutesTx(int PTTTx) // callback to set PTTOffMmutesTx (Off, On)
{
Hermes->PTTOffMutesTx = PTTTx;
}
void hermesNB::set_PTTOnMutesRx(int PTTRx) // callback to set PTTOnMutesRx (Off, On)
{
Hermes->PTTOnMutesRx = PTTRx;
}
void hermesNB::set_TxDrive(int TxD) // callback to set Transmit Drive Level (0..255)
{
Hermes->TxDrive = (unsigned char)TxD;
}
void hermesNB::set_ClockSource(const char * ClkS) // callback to set Clock source
{
unsigned int ck;
sscanf(ClkS, "%x", &ck); // convert char string to 8 bits
ck &= 0xFC; // mask lower bits
Hermes->ClockSource = ck;
}
void hermesNB::set_AlexRxAntenna(int RxA) // callback to set Alex Rx Antenna Selector
{
Hermes->AlexRxAnt = RxA;
}
void hermesNB::set_AlexTxAntenna(int TxA) // callback to set Alex Tx Antenna Selector
{
Hermes->AlexTxAnt = TxA;
}
void hermesNB::set_AlexRxHPF(int HPF) // callback to select Alex Rx High Pass Filter
{
Hermes->AlexRxHPF = HPF;
}
void hermesNB::set_AlexTxLPF(int LPF) // callback to set Alex Tx Low Pass filter
{
Hermes->AlexTxLPF = LPF;
}
void hermesNB::set_Verbose(int Verb) // callback to turn Verbose mode on or off
{
Hermes->Verbose = Verb;
}
void
hermesNB_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required)
{
/* <+forecast+> e.g. ninput_items_required[0] = noutput_items */
}
int
hermesNB_impl::general_work (int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const gr_complex *in0 = (const gr_complex *) input_items[0]; // Tx samples
gr_complex *out = (gr_complex *) output_items[0];
// Send I and Q samples received on input port to HermesProxy, it may or may not
// consume them. Hermes needs 63 complex samples in each HPSDR-USB frame.
if ((ninput_items[0] >= 63))
{
int consumed = Hermes->PutTxIQ(in0, 63);
consume_each(consumed); // Tell runtime system how many input items we consumed on
// each input stream.
};
//
// Get partially-filled 256-float buffers. The packing level is different dependent on the
// number of receivers. The buffers are sequentially packed, all receivers IQ first
// sample then all receiver IQ second sample, etc. The global variable USBRowCount[] tells
// us how many time samples per receiver there are in one USB frame.
IQBuf_t Rx;
int NumRx = Hermes->NumReceivers;
if( (Rx = Hermes->GetRxIQ()) == NULL) //no more available from the radio
return(0); // tell gnuradio we did not produce any samples
int SamplesPerRx = Hermes->USBRowCount[NumRx-1];
// Send buffered complex samples to our block's output port(s)
for (int index=0; index<SamplesPerRx; index++)
for (int receiver=0; receiver < NumRx; receiver++)
((gr_complex *)output_items[receiver])[index] = gr_complex(*Rx++, *Rx++);
return(SamplesPerRx);
}
} /* namespace hpsdr */
} /* namespace gr */
|