HermesProxy.h
Go to the documentation of this file.
/* -*- c++ -*- */
/*
* Copyright 2013-2017,2020 Tom 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.
*/
// HermesProxy.h
//
// Proxy for Hermes board. Each HermesNB module communicates with
// only one hardware module. Multiple hardware modules need to use
// multiple instantiations of the HermesNB within GNURadio.
// Note: multiple receivers on one Hermes is not implemented.
//
// Version: December 15, 2012
// July 10, 2013 -- Updates for GRC 3.7
// December 4, 2013 -- Fix bug in free() on termination.
// -- Add additional parameters to constructor
// July 2017 -- Changes supporting up to 8 receivers
#include <gnuradio/io_signature.h>
#ifndef HermesProxy_H
#define HermesProxy_H
#define NUMRXIQBUFS 128 // number of receiver IQ buffers in circular queue.
// Must be integral power of 2 (2,4,8,16,32,64, etc.)
#define RXBUFSIZE 256 // number of floats in one RxIQBuf, #complexes is half
// Must be integral power of 2 (2,4,8,16,32,64, etc.)
#define NUMTXBUFS 128 // number of transmit buffers in circular queue
// Must be integral power of 2
#define TXBUFSIZE 512 // number of bytes in one TxBuf
#define TXINITIALBURST 4 // Number of Ethernet frames to holdoff before bursting
// to fill hardware TXFIFO
#define MAXRECEIVERS 8 // Maximum number of receivers defined by protocol specification
typedef float* IQBuf_t; // IQ buffer type (IQ samples as floats)
typedef unsigned char* RawBuf_t; // Raw transmit buffer type
enum { PTTOff, // PTT disabled
PTTVox, // PTT vox mode (examines TxFrame to decide whether to Tx)
PTTOn }; // PTT force Tx on
class HermesProxy
{
private:
IQBuf_t RxIQBuf[NUMRXIQBUFS]; // ReceiveIQ buffers
unsigned RxWriteCounter; // Which Rx buffer to write to
unsigned RxReadCounter; // Which Rx buffer to read from
unsigned RxWriteFill; // Fill level of the RxWrite buffer
bool TxHoldOff; // Transmit buffer holdoff flag
RawBuf_t TxBuf[NUMTXBUFS]; // Transmit buffers
unsigned TxWriteCounter; // Which Tx buffer to write to
unsigned TxReadCounter; // Which Tx buffer to read from
unsigned TxControlCycler; // Which Tx control register set to send
unsigned TxFrameIdleCount; // How long we've gone since sending a TxFrame
unsigned long LostRxBufCount; // Lost-buffer counter for packets we actually got
unsigned long TotalRxBufCount; // Total buffer count (may roll over)
unsigned long LostTxBufCount; //
unsigned long TotalTxBufCount; //
unsigned long CorruptRxCount; //
unsigned long LostEthernetRx; //
unsigned long CurrentEthSeqNum; // Diagnostic
//pthread_mutex_t mutexRPG; // Rx to Proxy to Gnuradio buffer
//pthread_mutex_t mutexGPT; // Gnuradio to Proxy to Tx buffer
public:
unsigned Receive0Frequency; // 1st rcvr. Corresponds to out0 in gnuradio
unsigned Receive1Frequency; // 2nd rcvr. Corresponds to out1 in gnuradio
unsigned Receive2Frequency; // 3rd rcvr. Corresponds to out2 in gnuradio
unsigned Receive3Frequency; // 4th rcvr. Corresponds to out3 in gnuradio
unsigned Receive4Frequency; // 5th rcvr. Corresponds to out4 in gnuradio
unsigned Receive5Frequency; // 6th rcvr. Corresponds to out5 in gnuradio
unsigned Receive6Frequency; // 7th rcvr. Corresponds to out6 in gnuradio
unsigned Receive7Frequency; // 8th rcvr. Corresponds to out7 in gnuradio
unsigned TransmitFrequency;
int NumReceivers;
int RxSampleRate;
unsigned char TxDrive;
unsigned char RxAtten; // not yet used (requires Hermes firmware V2.0)
unsigned int ClockSource; // upper 6-bits of clock control register
unsigned char AlexRxAnt; // Select Alex Receive Antenna or from T/R relay
unsigned char AlexTxAnt; // Select Alex Tx Antenna
unsigned char AlexRxHPF; // Select Alex Receive High Pass Filter
unsigned char AlexTxLPF; // Select Alex Transmit Low Pass Filter
int PTTMode;
bool RxPreamp;
bool ADCdither;
bool ADCrandom;
bool ADCoverload;
bool Duplex;
unsigned char HermesVersion;
unsigned int AIN1, AIN2, AIN3, AIN4, AIN5, AIN6; // Analog inputs to Hermes
unsigned int AlexRevPwr;
unsigned int SlowCount;
int Verbose;
bool TxStop;
bool PTTOffMutesTx; // PTT Off mutes the transmitter
bool PTTOnMutesRx; // PTT On receiver
char interface[16];
char mactarget[18]; // Requested target's MAC address as string
// "HH:HH:HH:HH:HH:HH" HH is hexadecimal string.
unsigned int metis_entry; // Index into Metis_card MAC table
HermesProxy(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 AlexRPF, int Verbose, int NumRx,
const char* MACAddr); // constructor
~HermesProxy(); // destructor
void Stop(); // stop ethernet I/O
void Start(); // start rx stream
void SendTxIQ(); // send an IQ buffer to Hermes transmit hardware
void BuildControlRegs(unsigned, RawBuf_t); // fill in the 8 byte sync+control registers from RegNum
int PutTxIQ(const gr_complex *, /*const gr_complex *,*/ int); // post a transmit TxIQ buffer
void ScheduleTxFrame(unsigned long); // Schedule a Tx frame
RawBuf_t GetNextTxBuf(); // get an empty Tx Buffer
void UpdateHermes(); // update control registers in Hermes without any Tx data
void ReceiveRxIQ(unsigned char *); // receive an IQ Ethernet frame from Hermes hardware via metis.cc thread
IQBuf_t GetRxIQ(); // Gnuradio pickup a received RxIQ buffer if available (next readable Rx buffer)
IQBuf_t GetNextRxBuf(); // get an empty output buffer, NULL if no new one available (next writable Rx buffer)
float Unpack2C(const unsigned char* inptr); // unpack 2's complement to float
unsigned int USBRowCount[MAXRECEIVERS]; // Rows (samples per receiver) for one USB frame.
void PrintRawBuf(RawBuf_t); // for debugging
// Not yet implemented
void ReceiveMicLR(); // receive an LR audio bufer from Hermes hardware
};
#endif // #ifndef HermesProxy_H
HermesProxy::ADCdither
bool ADCdither
Definition: HermesProxy.h:121
HermesProxy::GetNextTxBuf
RawBuf_t GetNextTxBuf()
HermesProxy::AlexTxAnt
unsigned char AlexTxAnt
Definition: HermesProxy.h:115
HermesProxy::GetNextRxBuf
IQBuf_t GetNextRxBuf()
HermesProxy::PTTMode
int PTTMode
Definition: HermesProxy.h:119
PTTVox
@ PTTVox
Definition: HermesProxy.h:62
HermesProxy::AlexRxHPF
unsigned char AlexRxHPF
Definition: HermesProxy.h:116
HermesProxy::Receive7Frequency
unsigned Receive7Frequency
Definition: HermesProxy.h:103
HermesProxy::AIN6
unsigned int AIN6
Definition: HermesProxy.h:127
HermesProxy::metis_entry
unsigned int metis_entry
Definition: HermesProxy.h:139
HermesProxy::AIN5
unsigned int AIN5
Definition: HermesProxy.h:127
HermesProxy::~HermesProxy
~HermesProxy()
HermesProxy::AIN4
unsigned int AIN4
Definition: HermesProxy.h:127
RawBuf_t
unsigned char * RawBuf_t
Definition: HermesProxy.h:59
HermesProxy::Receive1Frequency
unsigned Receive1Frequency
Definition: HermesProxy.h:97
HermesProxy::NumReceivers
int NumReceivers
Definition: HermesProxy.h:106
HermesProxy::interface
char interface[16]
Definition: HermesProxy.h:135
PTTOn
@ PTTOn
Definition: HermesProxy.h:63
HermesProxy::TxDrive
unsigned char TxDrive
Definition: HermesProxy.h:109
HermesProxy::RxSampleRate
int RxSampleRate
Definition: HermesProxy.h:107
HermesProxy::Receive4Frequency
unsigned Receive4Frequency
Definition: HermesProxy.h:100
HermesProxy::AlexRxAnt
unsigned char AlexRxAnt
Definition: HermesProxy.h:114
HermesProxy::SendTxIQ
void SendTxIQ()
HermesProxy::RxAtten
unsigned char RxAtten
Definition: HermesProxy.h:110
HermesProxy::AlexTxLPF
unsigned char AlexTxLPF
Definition: HermesProxy.h:117
HermesProxy::AIN2
unsigned int AIN2
Definition: HermesProxy.h:127
HermesProxy::UpdateHermes
void UpdateHermes()
HermesProxy
Definition: HermesProxy.h:66
NUMRXIQBUFS
#define NUMRXIQBUFS
Definition: HermesProxy.h:40
MAXRECEIVERS
#define MAXRECEIVERS
Definition: HermesProxy.h:55
HermesProxy::ReceiveRxIQ
void ReceiveRxIQ(unsigned char *)
HermesProxy::Receive3Frequency
unsigned Receive3Frequency
Definition: HermesProxy.h:99
HermesProxy::ADCoverload
bool ADCoverload
Definition: HermesProxy.h:123
HermesProxy::ClockSource
unsigned int ClockSource
Definition: HermesProxy.h:112
HermesProxy::AIN3
unsigned int AIN3
Definition: HermesProxy.h:127
PTTOff
@ PTTOff
Definition: HermesProxy.h:61
HermesProxy::SlowCount
unsigned int SlowCount
Definition: HermesProxy.h:129
HermesProxy::GetRxIQ
IQBuf_t GetRxIQ()
HermesProxy::TxStop
bool TxStop
Definition: HermesProxy.h:132
HermesProxy::USBRowCount
unsigned int USBRowCount[MAXRECEIVERS]
Definition: HermesProxy.h:167
HermesProxy::BuildControlRegs
void BuildControlRegs(unsigned, RawBuf_t)
HermesProxy::Receive5Frequency
unsigned Receive5Frequency
Definition: HermesProxy.h:101
HermesProxy::Receive0Frequency
unsigned Receive0Frequency
Definition: HermesProxy.h:96
HermesProxy::Start
void Start()
HermesProxy::PTTOnMutesRx
bool PTTOnMutesRx
Definition: HermesProxy.h:134
HermesProxy::AlexRevPwr
unsigned int AlexRevPwr
Definition: HermesProxy.h:128
HermesProxy::mactarget
char mactarget[18]
Definition: HermesProxy.h:137
HermesProxy::PutTxIQ
int PutTxIQ(const gr_complex *, int)
HermesProxy::PrintRawBuf
void PrintRawBuf(RawBuf_t)
HermesProxy::PTTOffMutesTx
bool PTTOffMutesTx
Definition: HermesProxy.h:133
HermesProxy::Unpack2C
float Unpack2C(const unsigned char *inptr)
HermesProxy::Receive2Frequency
unsigned Receive2Frequency
Definition: HermesProxy.h:98
HermesProxy::Receive6Frequency
unsigned Receive6Frequency
Definition: HermesProxy.h:102
HermesProxy::TransmitFrequency
unsigned TransmitFrequency
Definition: HermesProxy.h:105
HermesProxy::AIN1
unsigned int AIN1
Definition: HermesProxy.h:127
HermesProxy::ScheduleTxFrame
void ScheduleTxFrame(unsigned long)
NUMTXBUFS
#define NUMTXBUFS
Definition: HermesProxy.h:46
HermesProxy::RxPreamp
bool RxPreamp
Definition: HermesProxy.h:120
HermesProxy::ADCrandom
bool ADCrandom
Definition: HermesProxy.h:122
HermesProxy::ReceiveMicLR
void ReceiveMicLR()
HermesProxy::HermesVersion
unsigned char HermesVersion
Definition: HermesProxy.h:126
HermesProxy::Stop
void Stop()
HermesProxy::Duplex
bool Duplex
Definition: HermesProxy.h:124
HermesProxy::HermesProxy
HermesProxy(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 AlexRPF, int Verbose, int NumRx, const char *MACAddr)
HermesProxy::Verbose
int Verbose
Definition: HermesProxy.h:130
IQBuf_t
float * IQBuf_t
Definition: HermesProxy.h:58