blob: a9924833f2cd9fa8f2a3a1db8c227ae8480501b8 [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)
Thomas Tsoucb69f082013-04-08 14:18:26 -040026
dburgessb3a0ca42011-10-12 07:44:40 +000027/** a 64-bit virtual timestamp for radio data */
28typedef unsigned long long TIMESTAMP;
29
30/** A class to handle a USRP rev 4, with a two RFX900 daughterboards */
31class RadioDevice {
32
33 public:
kurtis.heimerle380af32011-11-26 03:18:55 +000034 /* Available transport bus types */
Thomas Tsou02d88d12013-04-05 15:36:30 -040035 enum TxWindowType { TX_WINDOW_USRP1, TX_WINDOW_FIXED };
kurtis.heimerle380af32011-11-26 03:18:55 +000036
Thomas Tsoucb69f082013-04-08 14:18:26 -040037 /* Radio interface types */
Tom Tsou05c6feb2016-06-22 16:09:44 -070038 enum InterfaceType {
39 NORMAL,
40 RESAMP_64M,
41 RESAMP_100M,
42 DIVERSITY,
43 };
Thomas Tsoucb69f082013-04-08 14:18:26 -040044
Tom Tsou05c6feb2016-06-22 16:09:44 -070045 static RadioDevice *make(size_t tx_sps, size_t rx_sps, InterfaceType type,
46 size_t chans = 1, double offset = 0.0);
kurtis.heimerl965e7572011-11-26 03:16:54 +000047
kurtis.heimerldb2aae52011-11-26 03:17:13 +000048 /** Initialize the USRP */
Alexander Chemeris50747dc2015-06-07 01:07:45 -040049 virtual int open(const std::string &args = "", bool extref = false, bool swap_channels = false)=0;
dburgessb3a0ca42011-10-12 07:44:40 +000050
Thomas Tsou8c336792013-11-15 16:26:05 -050051 virtual ~RadioDevice() { }
52
dburgessb3a0ca42011-10-12 07:44:40 +000053 /** Start the USRP */
54 virtual bool start()=0;
55
56 /** Stop the USRP */
57 virtual bool stop()=0;
58
Thomas Tsou02d88d12013-04-05 15:36:30 -040059 /** Get the Tx window type */
60 virtual enum TxWindowType getWindowType()=0;
kurtis.heimerle380af32011-11-26 03:18:55 +000061
kurtis.heimerldb2aae52011-11-26 03:17:13 +000062 /** Enable thread priority */
Thomas Tsou7553aa92013-11-08 12:50:03 -050063 virtual void setPriority(float prio = 0.5) = 0;
kurtis.heimerldb2aae52011-11-26 03:17:13 +000064
dburgessb3a0ca42011-10-12 07:44:40 +000065 /**
66 Read samples from the radio.
67 @param buf preallocated buf to contain read result
68 @param len number of samples desired
69 @param overrun Set if read buffer has been overrun, e.g. data not being read fast enough
70 @param timestamp The timestamp of the first samples to be read
71 @param underrun Set if radio does not have data to transmit, e.g. data not being sent fast enough
72 @param RSSI The received signal strength of the read result
73 @return The number of samples actually read
74 */
Thomas Tsou204a9f12013-10-29 18:34:16 -040075 virtual int readSamples(std::vector<short *> &bufs, int len, bool *overrun,
76 TIMESTAMP timestamp = 0xffffffff, bool *underrun = 0,
77 unsigned *RSSI = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +000078 /**
79 Write samples to the radio.
80 @param buf Contains the data to be written.
81 @param len number of samples to write.
82 @param underrun Set if radio does not have data to transmit, e.g. data not being sent fast enough
83 @param timestamp The timestamp of the first sample of the data buffer.
84 @param isControl Set if data is a control packet, e.g. a ping command
85 @return The number of samples actually written
86 */
Thomas Tsou204a9f12013-10-29 18:34:16 -040087 virtual int writeSamples(std::vector<short *> &bufs, int len, bool *underrun,
88 TIMESTAMP timestamp, bool isControl = false) = 0;
89
dburgessb3a0ca42011-10-12 07:44:40 +000090 /** Update the alignment between the read and write timestamps */
91 virtual bool updateAlignment(TIMESTAMP timestamp)=0;
Thomas Tsou204a9f12013-10-29 18:34:16 -040092
dburgessb3a0ca42011-10-12 07:44:40 +000093 /** Set the transmitter frequency */
Thomas Tsou204a9f12013-10-29 18:34:16 -040094 virtual bool setTxFreq(double wFreq, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +000095
96 /** Set the receiver frequency */
Thomas Tsou204a9f12013-10-29 18:34:16 -040097 virtual bool setRxFreq(double wFreq, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +000098
99 /** Returns the starting write Timestamp*/
100 virtual TIMESTAMP initialWriteTimestamp(void)=0;
101
102 /** Returns the starting read Timestamp*/
103 virtual TIMESTAMP initialReadTimestamp(void)=0;
104
105 /** returns the full-scale transmit amplitude **/
106 virtual double fullScaleInputValue()=0;
107
108 /** returns the full-scale receive amplitude **/
109 virtual double fullScaleOutputValue()=0;
110
111 /** sets the receive chan gain, returns the gain setting **/
Thomas Tsou204a9f12013-10-29 18:34:16 -0400112 virtual double setRxGain(double dB, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000113
114 /** gets the current receive gain **/
Thomas Tsou204a9f12013-10-29 18:34:16 -0400115 virtual double getRxGain(size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000116
117 /** return maximum Rx Gain **/
118 virtual double maxRxGain(void) = 0;
119
120 /** return minimum Rx Gain **/
121 virtual double minRxGain(void) = 0;
122
123 /** sets the transmit chan gain, returns the gain setting **/
Thomas Tsou204a9f12013-10-29 18:34:16 -0400124 virtual double setTxGain(double dB, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000125
126 /** return maximum Tx Gain **/
127 virtual double maxTxGain(void) = 0;
128
129 /** return minimum Tx Gain **/
130 virtual double minTxGain(void) = 0;
131
132 /** Return internal status values */
Thomas Tsou204a9f12013-10-29 18:34:16 -0400133 virtual double getTxFreq(size_t chan = 0) = 0;
134 virtual double getRxFreq(size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000135 virtual double getSampleRate()=0;
136 virtual double numberRead()=0;
137 virtual double numberWritten()=0;
138
139};
140
141#endif