GNU Radio's HIQSDRTRX Package
source_impl.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2013 Stefan Goerg stefan@dl2stg.de
4  * Copyright 2021 Karsten Schmidt dg1vs@darc.de
5  *
6  * This is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3, or (at your option)
9  * any later version.
10  *
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this software; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef INCLUDED_HIQSDRTRX_SOURCE_IMPL_H
23 #define INCLUDED_HIQSDRTRX_SOURCE_IMPL_H
24 
25 #include <hiqsdrtrx/source.h>
26 
27 #define NLUT 128
28 
29 typedef std::complex<double> dcplx;
30 extern dcplx lut1[NLUT];
31 extern dcplx lut[NLUT];
32 extern int lutn[NLUT];
33 extern double lutPartAv[NLUT];
34 extern int lutPartUsed[NLUT];
35 extern int gr_hiqsdr_tx_samples;
36 extern int dpdState;
37 extern int testSig;
38 
39 #define DPD_OFF 0
40 #define DPD_SYNC_SEARCH_CORR 1
41 #define DPD_SYNC_SEARCH_FINE 2
42 #define DPD_LEARN 3
43 #define DPD_READY 4
44 #define DPD_READY_OFF 5
45 
46 #define TEST_SIG_NONE 0
47 #define TEST_SIG_TONE 1
48 #define TEST_SIG_2TONE 2
49 #define TEST_SIG_FM_NOICE 3
50 
51 
52 namespace gr {
53  namespace hiqsdrtrx {
54 
55  class source_impl : public source
56  {
57  private:
58  // Nothing to declare in this block.
59  size_t d_itemsize;
60  int d_payload_size; // maximum transmission unit (packet length)
61  bool d_eof; // zero-length packet is EOF
62  int d_socket; // handle to socket
63  // gruel::mutex d_mutex; // protects d_socket and d_connected
64  unsigned char *d_temp_buff; // hold buffer between between call
65  int byteMode;
66  unsigned char seqNr;
67  gr_complex outBuf[8192];
68  int outBufPos;
69  int rxRate,txRate;
70 
71  unsigned char ctlBuf[22];
72  unsigned char firBuf[80];
73  int c_socket;
74  int rx_fir_socket;
75  int tx_fir_socket;
76  int firmVersion;
77  bool cwMode;
78  int clockCorr;
79  bool dpd;
80  int lutParts;
81 
82  void hiqSend();
83  void closeSocket(int socket);
84  int openSocket (const char *host, unsigned short port);
85  void printDPDState();
86 
87  //void connect( const char *host, unsigned short port );
88 
89  void disconnect();
90  void calcDPD(std::vector<dcplx> rxData, std::vector<dcplx> txData);
91  std::vector<dcplx> rxData;
92  std::vector<dcplx> txData;
93  std::vector<dcplx> rxDelay;
94  std::vector<dcplx> fracDelay(std::vector<dcplx> &in, int fDelay);
95  int maxIdx1;
96  int rxDel,rxDel1,rxDel2;
97  double maxRx;
98  int cnt,found,sStep;
99 
100 
101  public:
102  source_impl(size_t itemsize, const char *host,unsigned short port, unsigned short c_port, unsigned short rx_fir_port, unsigned short tx_fir_port, int payload_size,bool eof, bool wait, int rxfreq, int txfreq, int rate,bool ant, int presel, int att, int txLevel, bool ptt, int txRate, int clockCorr,std::vector<gr_complex> rxFirTaps , std::vector<gr_complex> txFirTaps, bool dpd);
103  ~source_impl();
104 
105  // Where all the action really happens
106  int work(
107  int noutput_items,
108  gr_vector_const_void_star &input_items,
109  gr_vector_void_star &output_items
110  );
111 
112  int payload_size() { return d_payload_size; }
113  int get_port();
114  void setRXFreq(int f);
115  void setTXFreq(int f);
116  void setSampleRate(int rate);
117  void setAnt(bool);
118  void setPresel(int);
119  void setAttenuator(int);
120  void setTXLevel(int l);
121  void setPtt(bool on);
122  void setTXRate(int);
123  void setCWMode(bool);
124  void setFilter(std::vector<gr_complex> coef, int dest=0);
125  void setClockCorr(int diff);
126  void setDPD(bool on);
127 
128  };
129 
130  } // namespace hiqsdrtrx
131 } // namespace gr
132 
133 #endif /* INCLUDED_HIQSDRTRX_SOURCE_IMPL_H */
134 
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
<+description of block+>
Definition: source.h:51
int lutn[NLUT]
dcplx lut[NLUT]
void setClockCorr(int diff)
int gr_hiqsdr_tx_samples
int dpdState
void setFilter(std::vector< gr_complex > coef, int dest=0)
Definition: sink.h:28
int payload_size()
Definition: source_impl.h:112
std::complex< double > dcplx
Definition: source_impl.h:29
void setSampleRate(int rate)
#define NLUT
Definition: source_impl.h:27
dcplx lut1[NLUT]
Definition: source_impl.h:55
int testSig
source_impl(size_t itemsize, const char *host, unsigned short port, unsigned short c_port, unsigned short rx_fir_port, unsigned short tx_fir_port, int payload_size, bool eof, bool wait, int rxfreq, int txfreq, int rate, bool ant, int presel, int att, int txLevel, bool ptt, int txRate, int clockCorr, std::vector< gr_complex > rxFirTaps, std::vector< gr_complex > txFirTaps, bool dpd)
int lutPartUsed[NLUT]
double lutPartAv[NLUT]