blob: 142fcf6b1f6d347f593823b6c358f56cf1c53c8f [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
21#ifdef HAVE_CONFIG_H
22#include "config.h"
23#endif
24
Alexander Chemerisf931cf22016-06-18 10:42:33 +030025#define GSMRATE (1625e3/6)
Tom Tsou76764272016-06-24 14:25:39 -070026#define MCBTS_SPACING 800000.0
Thomas Tsoucb69f082013-04-08 14:18:26 -040027
dburgessb3a0ca42011-10-12 07:44:40 +000028/** a 64-bit virtual timestamp for radio data */
29typedef unsigned long long TIMESTAMP;
30
31/** A class to handle a USRP rev 4, with a two RFX900 daughterboards */
32class RadioDevice {
33
34 public:
kurtis.heimerle380af32011-11-26 03:18:55 +000035 /* Available transport bus types */
Thomas Tsou02d88d12013-04-05 15:36:30 -040036 enum TxWindowType { TX_WINDOW_USRP1, TX_WINDOW_FIXED };
kurtis.heimerle380af32011-11-26 03:18:55 +000037
Thomas Tsoucb69f082013-04-08 14:18:26 -040038 /* Radio interface types */
Tom Tsou05c6feb2016-06-22 16:09:44 -070039 enum InterfaceType {
40 NORMAL,
41 RESAMP_64M,
42 RESAMP_100M,
Tom Tsou76764272016-06-24 14:25:39 -070043 MULTI_ARFCN,
Tom Tsou05c6feb2016-06-22 16:09:44 -070044 DIVERSITY,
45 };
Thomas Tsoucb69f082013-04-08 14:18:26 -040046
Tom Tsou05c6feb2016-06-22 16:09:44 -070047 static RadioDevice *make(size_t tx_sps, size_t rx_sps, InterfaceType type,
48 size_t chans = 1, double offset = 0.0);
kurtis.heimerl965e7572011-11-26 03:16:54 +000049
kurtis.heimerldb2aae52011-11-26 03:17:13 +000050 /** Initialize the USRP */
Alexander Chemeris50747dc2015-06-07 01:07:45 -040051 virtual int open(const std::string &args = "", bool extref = false, bool swap_channels = false)=0;
dburgessb3a0ca42011-10-12 07:44:40 +000052
Thomas Tsou8c336792013-11-15 16:26:05 -050053 virtual ~RadioDevice() { }
54
dburgessb3a0ca42011-10-12 07:44:40 +000055 /** Start the USRP */
56 virtual bool start()=0;
57
58 /** Stop the USRP */
59 virtual bool stop()=0;
60
Thomas Tsou02d88d12013-04-05 15:36:30 -040061 /** Get the Tx window type */
62 virtual enum TxWindowType getWindowType()=0;
kurtis.heimerle380af32011-11-26 03:18:55 +000063
kurtis.heimerldb2aae52011-11-26 03:17:13 +000064 /** Enable thread priority */
Thomas Tsou7553aa92013-11-08 12:50:03 -050065 virtual void setPriority(float prio = 0.5) = 0;
kurtis.heimerldb2aae52011-11-26 03:17:13 +000066
dburgessb3a0ca42011-10-12 07:44:40 +000067 /**
68 Read samples from the radio.
69 @param buf preallocated buf to contain read result
70 @param len number of samples desired
71 @param overrun Set if read buffer has been overrun, e.g. data not being read fast enough
72 @param timestamp The timestamp of the first samples to be read
73 @param underrun Set if radio does not have data to transmit, e.g. data not being sent fast enough
74 @param RSSI The received signal strength of the read result
75 @return The number of samples actually read
76 */
Thomas Tsou204a9f12013-10-29 18:34:16 -040077 virtual int readSamples(std::vector<short *> &bufs, int len, bool *overrun,
78 TIMESTAMP timestamp = 0xffffffff, bool *underrun = 0,
79 unsigned *RSSI = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +000080 /**
81 Write samples to the radio.
82 @param buf Contains the data to be written.
83 @param len number of samples to write.
84 @param underrun Set if radio does not have data to transmit, e.g. data not being sent fast enough
85 @param timestamp The timestamp of the first sample of the data buffer.
86 @param isControl Set if data is a control packet, e.g. a ping command
87 @return The number of samples actually written
88 */
Thomas Tsou204a9f12013-10-29 18:34:16 -040089 virtual int writeSamples(std::vector<short *> &bufs, int len, bool *underrun,
90 TIMESTAMP timestamp, bool isControl = false) = 0;
91
dburgessb3a0ca42011-10-12 07:44:40 +000092 /** Update the alignment between the read and write timestamps */
93 virtual bool updateAlignment(TIMESTAMP timestamp)=0;
Thomas Tsou204a9f12013-10-29 18:34:16 -040094
dburgessb3a0ca42011-10-12 07:44:40 +000095 /** Set the transmitter frequency */
Thomas Tsou204a9f12013-10-29 18:34:16 -040096 virtual bool setTxFreq(double wFreq, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +000097
98 /** Set the receiver frequency */
Thomas Tsou204a9f12013-10-29 18:34:16 -040099 virtual bool setRxFreq(double wFreq, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000100
101 /** Returns the starting write Timestamp*/
102 virtual TIMESTAMP initialWriteTimestamp(void)=0;
103
104 /** Returns the starting read Timestamp*/
105 virtual TIMESTAMP initialReadTimestamp(void)=0;
106
107 /** returns the full-scale transmit amplitude **/
108 virtual double fullScaleInputValue()=0;
109
110 /** returns the full-scale receive amplitude **/
111 virtual double fullScaleOutputValue()=0;
112
113 /** sets the receive chan gain, returns the gain setting **/
Thomas Tsou204a9f12013-10-29 18:34:16 -0400114 virtual double setRxGain(double dB, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000115
116 /** gets the current receive gain **/
Thomas Tsou204a9f12013-10-29 18:34:16 -0400117 virtual double getRxGain(size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000118
119 /** return maximum Rx Gain **/
120 virtual double maxRxGain(void) = 0;
121
122 /** return minimum Rx Gain **/
123 virtual double minRxGain(void) = 0;
124
125 /** sets the transmit chan gain, returns the gain setting **/
Thomas Tsou204a9f12013-10-29 18:34:16 -0400126 virtual double setTxGain(double dB, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000127
128 /** return maximum Tx Gain **/
129 virtual double maxTxGain(void) = 0;
130
131 /** return minimum Tx Gain **/
132 virtual double minTxGain(void) = 0;
133
134 /** Return internal status values */
Thomas Tsou204a9f12013-10-29 18:34:16 -0400135 virtual double getTxFreq(size_t chan = 0) = 0;
136 virtual double getRxFreq(size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000137 virtual double getSampleRate()=0;
138 virtual double numberRead()=0;
139 virtual double numberWritten()=0;
140
141};
142
143#endif