Project

General

Profile

radioInterface.h

Vladimir, 08/10/2017 02:33 PM

 
1
/*
2
* Copyright 2008 Free Software Foundation, Inc.
3
*
4
* This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribuion.
5
*
6
* This use of this software may be subject to additional restrictions.
7
* See the LEGAL file in the main directory for details.
8

9
    This program is distributed in the hope that it will be useful,
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12

13
*/
14

    
15

    
16

    
17
#include "sigProcLib.h"  
18
#include "GSMCommon.h"
19
#include "LinkedLists.h"
20
#include "radioDevice.h"
21
#include "radioVector.h"
22
#include "radioClock.h"
23
#include "Resampler.h"
24

    
25
static const unsigned gSlotLen = 148;      ///< number of symbols per slot, not counting guard periods
26

    
27
/** class to interface the transceiver with the USRP */
28
class RadioInterface {
29

    
30
protected:
31

    
32
  Thread mAlignRadioServiceLoopThread;              ///< thread that synchronizes transmit and receive sections
33

    
34
  std::vector<VectorFIFO>  mReceiveFIFO;      ///< FIFO that holds receive  bursts
35

    
36
  RadioDevice *mRadio;                              ///< the USRP object
37

    
38
  size_t mSPSTx;
39
  size_t mSPSRx;
40
  size_t mChans;
41
  size_t mMIMO;
42

    
43
  std::vector<signalVector *> sendBuffer;
44
  std::vector<signalVector *> recvBuffer;
45
  unsigned sendCursor;
46
  unsigned recvCursor;
47

    
48
  std::vector<short *> convertRecvBuffer;
49
  std::vector<short *> convertSendBuffer;
50
  std::vector<float> powerScaling;
51
  bool underrun;                              ///< indicates writes to USRP are too slow
52
  bool overrun;                                      ///< indicates reads from USRP are too slow
53
  TIMESTAMP writeTimestamp;                      ///< sample timestamp of next packet written to USRP
54
  TIMESTAMP readTimestamp;                      ///< sample timestamp of next packet read from USRP
55

    
56
  RadioClock mClock;                          ///< the basestation clock!
57

    
58
  int receiveOffset;                          ///< offset b/w transmit and receive GSM timestamps, in timeslots
59

    
60
  bool mOn;                                      ///< indicates radio is on
61

    
62
private:
63

    
64
  /** format samples to USRP */ 
65
  int radioifyVector(signalVector &wVector,
66
                     float *floatVector,
67
                     bool zero);
68

    
69
  /** format samples from USRP */
70
  int unRadioifyVector(float *floatVector, signalVector &wVector);
71

    
72
  /** push GSM bursts into the transmit buffer */
73
  virtual void pushBuffer(void);
74

    
75
  /** pull GSM bursts from the receive buffer */
76
  virtual void pullBuffer(void);
77

    
78
public:
79

    
80
  /** start the interface */
81
  bool start();
82
  bool stop();
83

    
84
  /** intialization */
85
  virtual bool init(int type);
86
  virtual void close();
87

    
88
  /** constructor */
89
  RadioInterface(RadioDevice* wRadio = NULL, size_t sps_rx = 1, size_t sps_tx = 4,
90
                 size_t chans = 1, size_t diversity = 1,
91
                 int receiveOffset = 3, GSM::Time wStartTime = GSM::Time(0));
92

    
93
  /** destructor */
94
  virtual ~RadioInterface();
95

    
96
  /** check for underrun, resets underrun value */
97
  bool isUnderrun();
98

    
99
  /** return the radio device */
100
  RadioDevice* getDevice() { return mRadio;}
101

    
102
  /** return the receive FIFO */
103
  VectorFIFO* receiveFIFO(size_t chan = 0);
104

    
105
  /** return the basestation clock */
106
  RadioClock* getClock(void) { return &mClock;};
107

    
108
  /** set transmit frequency */
109
  bool tuneTx(double freq, size_t chan = 0);
110

    
111
  /** set receive frequency */
112
  virtual bool tuneRx(double freq, size_t chan = 0);
113

    
114
  /** set receive gain */
115
  double setRxGain(double dB, size_t chan = 0);
116

    
117
  /** get receive gain */
118
  double getRxGain(size_t chan = 0);
119

    
120
  /** drive transmission of GSM bursts */
121
  void driveTransmitRadio(std::vector<signalVector *> &bursts,
122
                          std::vector<bool> &zeros);
123

    
124
  /** drive reception of GSM bursts */
125
  bool driveReceiveRadio();
126

    
127
  int setPowerAttenuation(int atten, size_t chan = 0);
128

    
129
  /** returns the full-scale transmit amplitude **/
130
  double fullScaleInputValue();
131

    
132
  /** returns the full-scale receive amplitude **/
133
  double fullScaleOutputValue();
134

    
135
  /** set thread priority on current thread */
136
  void setPriority(float prio = 0.5) { mRadio->setPriority(prio); }
137

    
138
  /** get transport window type of attached device */ 
139
  enum RadioDevice::TxWindowType getWindowType() { return mRadio->getWindowType(); }
140

    
141
#if defined(USRP1) || defined(USE_BLADERF)
142
protected:
143

    
144
  /** drive synchronization of Tx/Rx of USRP */
145
  void alignRadio();
146

    
147
  friend void *AlignRadioServiceLoopAdapter(RadioInterface*);
148
#endif
149
};
150

    
151
#if defined(USRP1) || defined(USE_BLADERF)
152
/** synchronization thread loop */
153
void *AlignRadioServiceLoopAdapter(RadioInterface*);
154
#endif
155

    
156
class RadioInterfaceResamp : public RadioInterface {
157

    
158
private:
159
  signalVector *innerSendBuffer;
160
  signalVector *outerSendBuffer;
161
  signalVector *innerRecvBuffer;
162
  signalVector *outerRecvBuffer;
163

    
164
  void pushBuffer();
165
  void pullBuffer();
166

    
167
public:
168

    
169
  RadioInterfaceResamp(RadioDevice* wRadio, size_t wSPSTx = 4, size_t chans = 1);
170

    
171
  ~RadioInterfaceResamp();
172

    
173
  bool init(int type);
174
  void close();
175
};
176

    
177
class RadioInterfaceDiversity : public RadioInterface {
178
public:
179
  RadioInterfaceDiversity(RadioDevice* wRadio,
180
                          size_t sps_tx = 4, size_t chans = 2);
181

    
182
  ~RadioInterfaceDiversity();
183

    
184
  bool init(int type);
185
  void close();
186
  bool tuneRx(double freq, size_t chan);
187

    
188
private:
189
  std::vector<Resampler *> dnsamplers;
190
  std::vector<float> phases;
191
  signalVector *outerRecvBuffer;
192

    
193
  bool mDiversity;
194
  double mFreqSpacing;
195

    
196
  bool setupDiversityChannels();
197
  void pullBuffer();
198
};
Add picture from clipboard (Maximum size: 48.8 MB)