blob: 6fd10db6fe7c1fadad030bfa6cd19925c7028674 [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
Thomas Tsoucb69f082013-04-08 14:18:26 -040025#define GSMRATE 1625e3/6
26
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 */
Thomas Tsoue90a42b2013-11-13 23:38:09 -050038 enum RadioInterfaceType { NORMAL, RESAMP_64M, RESAMP_100M, DIVERSITY };
Thomas Tsoucb69f082013-04-08 14:18:26 -040039
Thomas Tsoue90a42b2013-11-13 23:38:09 -050040 static RadioDevice *make(size_t sps, size_t chans = 1,
41 bool diversity = false);
kurtis.heimerl965e7572011-11-26 03:16:54 +000042
kurtis.heimerldb2aae52011-11-26 03:17:13 +000043 /** Initialize the USRP */
Thomas Tsou010fff72013-10-16 00:31:18 -040044 virtual int open(const std::string &args = "", bool extref = false)=0;
dburgessb3a0ca42011-10-12 07:44:40 +000045
Thomas Tsou8c336792013-11-15 16:26:05 -050046 virtual ~RadioDevice() { }
47
dburgessb3a0ca42011-10-12 07:44:40 +000048 /** Start the USRP */
49 virtual bool start()=0;
50
51 /** Stop the USRP */
52 virtual bool stop()=0;
53
Thomas Tsou02d88d12013-04-05 15:36:30 -040054 /** Get the Tx window type */
55 virtual enum TxWindowType getWindowType()=0;
kurtis.heimerle380af32011-11-26 03:18:55 +000056
kurtis.heimerldb2aae52011-11-26 03:17:13 +000057 /** Enable thread priority */
Thomas Tsou7553aa92013-11-08 12:50:03 -050058 virtual void setPriority(float prio = 0.5) = 0;
kurtis.heimerldb2aae52011-11-26 03:17:13 +000059
dburgessb3a0ca42011-10-12 07:44:40 +000060 /**
61 Read samples from the radio.
62 @param buf preallocated buf to contain read result
63 @param len number of samples desired
64 @param overrun Set if read buffer has been overrun, e.g. data not being read fast enough
65 @param timestamp The timestamp of the first samples to be read
66 @param underrun Set if radio does not have data to transmit, e.g. data not being sent fast enough
67 @param RSSI The received signal strength of the read result
68 @return The number of samples actually read
69 */
Thomas Tsou204a9f12013-10-29 18:34:16 -040070 virtual int readSamples(std::vector<short *> &bufs, int len, bool *overrun,
71 TIMESTAMP timestamp = 0xffffffff, bool *underrun = 0,
72 unsigned *RSSI = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +000073 /**
74 Write samples to the radio.
75 @param buf Contains the data to be written.
76 @param len number of samples to write.
77 @param underrun Set if radio does not have data to transmit, e.g. data not being sent fast enough
78 @param timestamp The timestamp of the first sample of the data buffer.
79 @param isControl Set if data is a control packet, e.g. a ping command
80 @return The number of samples actually written
81 */
Thomas Tsou204a9f12013-10-29 18:34:16 -040082 virtual int writeSamples(std::vector<short *> &bufs, int len, bool *underrun,
83 TIMESTAMP timestamp, bool isControl = false) = 0;
84
dburgessb3a0ca42011-10-12 07:44:40 +000085 /** Update the alignment between the read and write timestamps */
86 virtual bool updateAlignment(TIMESTAMP timestamp)=0;
Thomas Tsou204a9f12013-10-29 18:34:16 -040087
dburgessb3a0ca42011-10-12 07:44:40 +000088 /** Set the transmitter frequency */
Thomas Tsou204a9f12013-10-29 18:34:16 -040089 virtual bool setTxFreq(double wFreq, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +000090
91 /** Set the receiver frequency */
Thomas Tsou204a9f12013-10-29 18:34:16 -040092 virtual bool setRxFreq(double wFreq, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +000093
94 /** Returns the starting write Timestamp*/
95 virtual TIMESTAMP initialWriteTimestamp(void)=0;
96
97 /** Returns the starting read Timestamp*/
98 virtual TIMESTAMP initialReadTimestamp(void)=0;
99
100 /** returns the full-scale transmit amplitude **/
101 virtual double fullScaleInputValue()=0;
102
103 /** returns the full-scale receive amplitude **/
104 virtual double fullScaleOutputValue()=0;
105
106 /** sets the receive chan gain, returns the gain setting **/
Thomas Tsou204a9f12013-10-29 18:34:16 -0400107 virtual double setRxGain(double dB, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000108
109 /** gets the current receive gain **/
Thomas Tsou204a9f12013-10-29 18:34:16 -0400110 virtual double getRxGain(size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000111
112 /** return maximum Rx Gain **/
113 virtual double maxRxGain(void) = 0;
114
115 /** return minimum Rx Gain **/
116 virtual double minRxGain(void) = 0;
117
118 /** sets the transmit chan gain, returns the gain setting **/
Thomas Tsou204a9f12013-10-29 18:34:16 -0400119 virtual double setTxGain(double dB, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000120
121 /** return maximum Tx Gain **/
122 virtual double maxTxGain(void) = 0;
123
124 /** return minimum Tx Gain **/
125 virtual double minTxGain(void) = 0;
126
127 /** Return internal status values */
Thomas Tsou204a9f12013-10-29 18:34:16 -0400128 virtual double getTxFreq(size_t chan = 0) = 0;
129 virtual double getRxFreq(size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000130 virtual double getSampleRate()=0;
131 virtual double numberRead()=0;
132 virtual double numberWritten()=0;
133
134};
135
136#endif