blob: c5cd461964a70c07e6d9090f57effec76e8d4f39 [file] [log] [blame]
dburgessb3a0ca42011-10-12 07:44:40 +00001/*
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#ifndef __RADIO_DEVICE_H__
16#define __RADIO_DEVICE_H__
17
ttsouf60dafa2012-10-22 00:07:14 +000018#include <string>
Thomas Tsou204a9f12013-10-29 18:34:16 -040019#include <vector>
dburgessb3a0ca42011-10-12 07:44:40 +000020
Pau Espin Pedrole564f0f2018-04-24 18:43:51 +020021#include "GSMCommon.h"
22
Pau Espin Pedrolefac20b2018-02-21 14:59:19 +010023extern "C" {
24#include "config_defs.h"
25}
26
dburgessb3a0ca42011-10-12 07:44:40 +000027#ifdef HAVE_CONFIG_H
28#include "config.h"
29#endif
30
Alexander Chemerisf931cf22016-06-18 10:42:33 +030031#define GSMRATE (1625e3/6)
Tom Tsou76764272016-06-24 14:25:39 -070032#define MCBTS_SPACING 800000.0
Thomas Tsoucb69f082013-04-08 14:18:26 -040033
dburgessb3a0ca42011-10-12 07:44:40 +000034/** a 64-bit virtual timestamp for radio data */
35typedef unsigned long long TIMESTAMP;
36
37/** A class to handle a USRP rev 4, with a two RFX900 daughterboards */
38class RadioDevice {
39
40 public:
kurtis.heimerle380af32011-11-26 03:18:55 +000041 /* Available transport bus types */
Pau Espin Pedrolc7a0bf12018-04-25 12:17:10 +020042 enum TxWindowType { TX_WINDOW_USRP1, TX_WINDOW_FIXED, TX_WINDOW_LMS1 };
kurtis.heimerle380af32011-11-26 03:18:55 +000043
Thomas Tsoucb69f082013-04-08 14:18:26 -040044 /* Radio interface types */
Tom Tsou05c6feb2016-06-22 16:09:44 -070045 enum InterfaceType {
46 NORMAL,
47 RESAMP_64M,
48 RESAMP_100M,
Tom Tsou76764272016-06-24 14:25:39 -070049 MULTI_ARFCN,
Tom Tsou05c6feb2016-06-22 16:09:44 -070050 };
Thomas Tsoucb69f082013-04-08 14:18:26 -040051
Tom Tsou05c6feb2016-06-22 16:09:44 -070052 static RadioDevice *make(size_t tx_sps, size_t rx_sps, InterfaceType type,
Pau Espin Pedrol77ce99a2018-02-05 13:05:06 +010053 size_t chans = 1, double offset = 0.0,
54 const std::vector<std::string>& tx_paths = std::vector<std::string>(1, ""),
55 const std::vector<std::string>& rx_paths = std::vector<std::string>(1, ""));
kurtis.heimerl965e7572011-11-26 03:16:54 +000056
kurtis.heimerldb2aae52011-11-26 03:17:13 +000057 /** Initialize the USRP */
Tom Tsou2f3e60b2016-07-17 19:29:08 -070058 virtual int open(const std::string &args, int ref, bool swap_channels)=0;
dburgessb3a0ca42011-10-12 07:44:40 +000059
Thomas Tsou8c336792013-11-15 16:26:05 -050060 virtual ~RadioDevice() { }
61
dburgessb3a0ca42011-10-12 07:44:40 +000062 /** Start the USRP */
63 virtual bool start()=0;
64
65 /** Stop the USRP */
66 virtual bool stop()=0;
67
Thomas Tsou02d88d12013-04-05 15:36:30 -040068 /** Get the Tx window type */
69 virtual enum TxWindowType getWindowType()=0;
kurtis.heimerle380af32011-11-26 03:18:55 +000070
kurtis.heimerldb2aae52011-11-26 03:17:13 +000071 /** Enable thread priority */
Thomas Tsou7553aa92013-11-08 12:50:03 -050072 virtual void setPriority(float prio = 0.5) = 0;
kurtis.heimerldb2aae52011-11-26 03:17:13 +000073
dburgessb3a0ca42011-10-12 07:44:40 +000074 /**
75 Read samples from the radio.
76 @param buf preallocated buf to contain read result
77 @param len number of samples desired
78 @param overrun Set if read buffer has been overrun, e.g. data not being read fast enough
79 @param timestamp The timestamp of the first samples to be read
80 @param underrun Set if radio does not have data to transmit, e.g. data not being sent fast enough
81 @param RSSI The received signal strength of the read result
82 @return The number of samples actually read
83 */
Thomas Tsou204a9f12013-10-29 18:34:16 -040084 virtual int readSamples(std::vector<short *> &bufs, int len, bool *overrun,
85 TIMESTAMP timestamp = 0xffffffff, bool *underrun = 0,
86 unsigned *RSSI = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +000087 /**
88 Write samples to the radio.
89 @param buf Contains the data to be written.
90 @param len number of samples to write.
91 @param underrun Set if radio does not have data to transmit, e.g. data not being sent fast enough
92 @param timestamp The timestamp of the first sample of the data buffer.
93 @param isControl Set if data is a control packet, e.g. a ping command
94 @return The number of samples actually written
95 */
Thomas Tsou204a9f12013-10-29 18:34:16 -040096 virtual int writeSamples(std::vector<short *> &bufs, int len, bool *underrun,
97 TIMESTAMP timestamp, bool isControl = false) = 0;
98
dburgessb3a0ca42011-10-12 07:44:40 +000099 /** Update the alignment between the read and write timestamps */
100 virtual bool updateAlignment(TIMESTAMP timestamp)=0;
Thomas Tsou204a9f12013-10-29 18:34:16 -0400101
dburgessb3a0ca42011-10-12 07:44:40 +0000102 /** Set the transmitter frequency */
Thomas Tsou204a9f12013-10-29 18:34:16 -0400103 virtual bool setTxFreq(double wFreq, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000104
105 /** Set the receiver frequency */
Thomas Tsou204a9f12013-10-29 18:34:16 -0400106 virtual bool setRxFreq(double wFreq, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000107
108 /** Returns the starting write Timestamp*/
109 virtual TIMESTAMP initialWriteTimestamp(void)=0;
110
111 /** Returns the starting read Timestamp*/
112 virtual TIMESTAMP initialReadTimestamp(void)=0;
113
114 /** returns the full-scale transmit amplitude **/
115 virtual double fullScaleInputValue()=0;
116
117 /** returns the full-scale receive amplitude **/
118 virtual double fullScaleOutputValue()=0;
119
120 /** sets the receive chan gain, returns the gain setting **/
Thomas Tsou204a9f12013-10-29 18:34:16 -0400121 virtual double setRxGain(double dB, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000122
123 /** gets the current receive gain **/
Thomas Tsou204a9f12013-10-29 18:34:16 -0400124 virtual double getRxGain(size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000125
126 /** return maximum Rx Gain **/
127 virtual double maxRxGain(void) = 0;
128
129 /** return minimum Rx Gain **/
130 virtual double minRxGain(void) = 0;
131
132 /** sets the transmit chan gain, returns the gain setting **/
Thomas Tsou204a9f12013-10-29 18:34:16 -0400133 virtual double setTxGain(double dB, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000134
135 /** return maximum Tx Gain **/
136 virtual double maxTxGain(void) = 0;
137
138 /** return minimum Tx Gain **/
139 virtual double minTxGain(void) = 0;
140
Pau Espin Pedrol77ce99a2018-02-05 13:05:06 +0100141 /** sets the RX path to use, returns true if successful and false otherwise */
142 virtual bool setRxAntenna(const std::string &ant, size_t chan = 0) = 0;
143
144 /** return the used RX path */
145 virtual std::string getRxAntenna(size_t chan = 0) = 0;
146
147 /** sets the RX path to use, returns true if successful and false otherwise */
148 virtual bool setTxAntenna(const std::string &ant, size_t chan = 0) = 0;
149
150 /** return the used RX path */
151 virtual std::string getTxAntenna(size_t chan = 0) = 0;
152
Pau Espin Pedrol0fc20d12018-04-24 17:48:52 +0200153 /** return whether user drives synchronization of Tx/Rx of USRP */
154 virtual bool requiresRadioAlign() = 0;
155
Pau Espin Pedrole564f0f2018-04-24 18:43:51 +0200156 /** Minimum latency that the device can achieve */
157 virtual GSM::Time minLatency() = 0;
158
dburgessb3a0ca42011-10-12 07:44:40 +0000159 /** Return internal status values */
Thomas Tsou204a9f12013-10-29 18:34:16 -0400160 virtual double getTxFreq(size_t chan = 0) = 0;
161 virtual double getRxFreq(size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000162 virtual double getSampleRate()=0;
163 virtual double numberRead()=0;
164 virtual double numberWritten()=0;
165
166};
167
168#endif