GNU Radio's HPSDR Package
HermesProxy.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2013-2017 Tom McDermott, N5EG
4  *
5  * This is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3, or (at your option)
8  * any later version.
9  *
10  * This software is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this software; see the file COPYING. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 // HermesProxy.h
22 //
23 // Proxy for Hermes board. Each HermesNB module communicates with
24 // only one hardware module. Multiple hardware modules need to use
25 // multiple instantiations of the HermesNB within GNURadio.
26 // Note: multiple receivers on one Hermes is not implemented.
27 //
28 // Version: December 15, 2012
29 // July 10, 2013 -- Updates for GRC 3.7
30 // December 4, 2013 -- Fix bug in free() on termination.
31 // -- Add additional parameters to constructor
32 // July 2017 -- Changes supporting up to 8 receivers
33 
34 
35 #include <gnuradio/io_signature.h>
36 
37 #ifndef HermesProxy_H
38 #define HermesProxy_H
39 
40 #define NUMRXIQBUFS 128 // number of receiver IQ buffers in circular queue.
41  // Must be integral power of 2 (2,4,8,16,32,64, etc.)
42 
43 #define RXBUFSIZE 256 // number of floats in one RxIQBuf, #complexes is half
44  // Must be integral power of 2 (2,4,8,16,32,64, etc.)
45 
46 #define NUMTXBUFS 128 // number of transmit buffers in circular queue
47  // Must be integral power of 2
48 
49 #define TXBUFSIZE 512 // number of bytes in one TxBuf
50 
51 
52 #define TXINITIALBURST 4 // Number of Ethernet frames to holdoff before bursting
53  // to fill hardware TXFIFO
54 
55 #define MAXRECEIVERS 8 // Maximum number of receivers defined by protocol specification
56 
57 
58 typedef float* IQBuf_t; // IQ buffer type (IQ samples as floats)
59 typedef unsigned char* RawBuf_t; // Raw transmit buffer type
60 
61 enum { PTTOff, // PTT disabled
62  PTTVox, // PTT vox mode (examines TxFrame to decide whether to Tx)
63  PTTOn }; // PTT force Tx on
64 
66 {
67 
68 private:
69 
70  IQBuf_t RxIQBuf[NUMRXIQBUFS]; // ReceiveIQ buffers
71  unsigned RxWriteCounter; // Which Rx buffer to write to
72  unsigned RxReadCounter; // Which Rx buffer to read from
73  unsigned RxWriteFill; // Fill level of the RxWrite buffer
74  bool TxHoldOff; // Transmit buffer holdoff flag
75 
76  RawBuf_t TxBuf[NUMTXBUFS]; // Transmit buffers
77  unsigned TxWriteCounter; // Which Tx buffer to write to
78  unsigned TxReadCounter; // Which Tx buffer to read from
79  unsigned TxControlCycler; // Which Tx control register set to send
80  unsigned TxFrameIdleCount; // How long we've gone since sending a TxFrame
81 
82  unsigned long LostRxBufCount; // Lost-buffer counter for packets we actually got
83  unsigned long TotalRxBufCount; // Total buffer count (may roll over)
84  unsigned long LostTxBufCount; //
85  unsigned long TotalTxBufCount; //
86  unsigned long CorruptRxCount; //
87  unsigned long LostEthernetRx; //
88  unsigned long CurrentEthSeqNum; // Diagnostic
89 
90  //pthread_mutex_t mutexRPG; // Rx to Proxy to Gnuradio buffer
91  //pthread_mutex_t mutexGPT; // Gnuradio to Proxy to Tx buffer
92 
93 
94 public:
95 
96  unsigned Receive0Frequency; // 1st rcvr. Corresponds to out0 in gnuradio
97  unsigned Receive1Frequency; // 2nd rcvr. Corresponds to out1 in gnuradio
98  unsigned Receive2Frequency; // 3rd rcvr. Corresponds to out2 in gnuradio
99  unsigned Receive3Frequency; // 4th rcvr. Corresponds to out3 in gnuradio
100  unsigned Receive4Frequency; // 5th rcvr. Corresponds to out4 in gnuradio
101  unsigned Receive5Frequency; // 6th rcvr. Corresponds to out5 in gnuradio
102  unsigned Receive6Frequency; // 7th rcvr. Corresponds to out6 in gnuradio
103  unsigned Receive7Frequency; // 8th rcvr. Corresponds to out7 in gnuradio
104 
108 
109  unsigned char TxDrive;
110  unsigned char RxAtten; // not yet used (requires Hermes firmware V2.0)
111 
112  unsigned int ClockSource; // upper 6-bits of clock control register
113 
114  unsigned char AlexRxAnt; // Select Alex Receive Antenna or from T/R relay
115  unsigned char AlexTxAnt; // Select Alex Tx Antenna
116  unsigned char AlexRxHPF; // Select Alex Receive High Pass Filter
117  unsigned char AlexTxLPF; // Select Alex Transmit Low Pass Filter
118 
119  int PTTMode;
120  bool RxPreamp;
121  bool ADCdither;
122  bool ADCrandom;
124  bool Duplex;
125 
126  unsigned char HermesVersion;
127  unsigned int AIN1, AIN2, AIN3, AIN4, AIN5, AIN6; // Analog inputs to Hermes
128  unsigned int AlexRevPwr;
129  unsigned int SlowCount;
130  int Verbose;
131 
132  bool TxStop;
133  bool PTTOffMutesTx; // PTT Off mutes the transmitter
134  bool PTTOnMutesRx; // PTT On receiver
135  char interface[16];
136 
137  char mactarget[18]; // Requested target's MAC address as string
138  // "HH:HH:HH:HH:HH:HH" HH is hexadecimal string.
139  unsigned int metis_entry; // Index into Metis_card MAC table
140 
141 
142  HermesProxy(int RxFreq0, int RxFreq1, int RxFreq2, int RxFreq3, int RxFreq4,
143  int RxFreq5, int RxFreq6, int RxFreq7, int TxFreq, int RxPre,
144  int PTTModeSel, int PTTTxMute, int PTTRxMute,
145  unsigned char TxDr, int RxSmp, const char* Intfc,
146  const char * ClkS, int AlexRA, int AlexTA,
147  int AlexHPF, int AlexRPF, int Verbose, int NumRx,
148  const char* MACAddr); // constructor
149 
150  ~HermesProxy(); // destructor
151 
152  void Stop(); // stop ethernet I/O
153  void Start(); // start rx stream
154 
155  void SendTxIQ(); // send an IQ buffer to Hermes transmit hardware
156  void BuildControlRegs(unsigned, RawBuf_t); // fill in the 8 byte sync+control registers from RegNum
157  int PutTxIQ(const gr_complex *, /*const gr_complex *,*/ int); // post a transmit TxIQ buffer
158  void ScheduleTxFrame(unsigned long); // Schedule a Tx frame
159  RawBuf_t GetNextTxBuf(); // get an empty Tx Buffer
160 
161  void UpdateHermes(); // update control registers in Hermes without any Tx data
162 
163  void ReceiveRxIQ(unsigned char *); // receive an IQ Ethernet frame from Hermes hardware via metis.cc thread
164  IQBuf_t GetRxIQ(); // Gnuradio pickup a received RxIQ buffer if available (next readable Rx buffer)
165  IQBuf_t GetNextRxBuf(); // get an empty output buffer, NULL if no new one available (next writable Rx buffer)
166  float Unpack2C(const unsigned char* inptr); // unpack 2's complement to float
167  unsigned int USBRowCount[MAXRECEIVERS]; // Rows (samples per receiver) for one USB frame.
168 
169  void PrintRawBuf(RawBuf_t); // for debugging
170 
171  // Not yet implemented
172  void ReceiveMicLR(); // receive an LR audio bufer from Hermes hardware
173 
174 };
175 
176 #endif // #ifndef HermesProxy_H
177 
@ PTTOff
Definition: HermesProxy.h:61
@ PTTOn
Definition: HermesProxy.h:63
@ PTTVox
Definition: HermesProxy.h:62
#define NUMTXBUFS
Definition: HermesProxy.h:46
#define NUMRXIQBUFS
Definition: HermesProxy.h:40
unsigned char * RawBuf_t
Definition: HermesProxy.h:59
#define MAXRECEIVERS
Definition: HermesProxy.h:55
float * IQBuf_t
Definition: HermesProxy.h:58
Definition: HermesProxy.h:66
unsigned Receive7Frequency
Definition: HermesProxy.h:103
bool TxStop
Definition: HermesProxy.h:132
int PTTMode
Definition: HermesProxy.h:119
void BuildControlRegs(unsigned, RawBuf_t)
char mactarget[18]
Definition: HermesProxy.h:137
unsigned int AIN6
Definition: HermesProxy.h:127
void ReceiveMicLR()
int RxSampleRate
Definition: HermesProxy.h:107
unsigned Receive2Frequency
Definition: HermesProxy.h:98
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)
unsigned char AlexRxAnt
Definition: HermesProxy.h:114
void Start()
unsigned char HermesVersion
Definition: HermesProxy.h:126
unsigned Receive0Frequency
Definition: HermesProxy.h:96
unsigned Receive4Frequency
Definition: HermesProxy.h:100
int PutTxIQ(const gr_complex *, int)
bool ADCrandom
Definition: HermesProxy.h:122
unsigned int AIN1
Definition: HermesProxy.h:127
bool PTTOnMutesRx
Definition: HermesProxy.h:134
bool ADCoverload
Definition: HermesProxy.h:123
unsigned int AIN3
Definition: HermesProxy.h:127
unsigned int AIN2
Definition: HermesProxy.h:127
bool Duplex
Definition: HermesProxy.h:124
unsigned char TxDrive
Definition: HermesProxy.h:109
IQBuf_t GetNextRxBuf()
unsigned TransmitFrequency
Definition: HermesProxy.h:105
void PrintRawBuf(RawBuf_t)
bool ADCdither
Definition: HermesProxy.h:121
unsigned char AlexTxAnt
Definition: HermesProxy.h:115
unsigned int AIN4
Definition: HermesProxy.h:127
unsigned Receive5Frequency
Definition: HermesProxy.h:101
bool RxPreamp
Definition: HermesProxy.h:120
unsigned Receive3Frequency
Definition: HermesProxy.h:99
void UpdateHermes()
unsigned char AlexRxHPF
Definition: HermesProxy.h:116
unsigned int AIN5
Definition: HermesProxy.h:127
unsigned char AlexTxLPF
Definition: HermesProxy.h:117
char interface[16]
Definition: HermesProxy.h:135
void ScheduleTxFrame(unsigned long)
void ReceiveRxIQ(unsigned char *)
float Unpack2C(const unsigned char *inptr)
RawBuf_t GetNextTxBuf()
IQBuf_t GetRxIQ()
unsigned int metis_entry
Definition: HermesProxy.h:139
unsigned char RxAtten
Definition: HermesProxy.h:110
int NumReceivers
Definition: HermesProxy.h:106
int Verbose
Definition: HermesProxy.h:130
unsigned int SlowCount
Definition: HermesProxy.h:129
unsigned int USBRowCount[MAXRECEIVERS]
Definition: HermesProxy.h:167
unsigned Receive1Frequency
Definition: HermesProxy.h:97
void SendTxIQ()
unsigned int AlexRevPwr
Definition: HermesProxy.h:128
unsigned Receive6Frequency
Definition: HermesProxy.h:102
bool PTTOffMutesTx
Definition: HermesProxy.h:133
unsigned int ClockSource
Definition: HermesProxy.h:112