blob: 19b5a8875c28c452c1aa3b1cc746d2b2ff0d4aea [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 Tsoufe269fe2013-10-14 23:56:51 -040038 enum RadioInterfaceType { NORMAL, RESAMP_64M, RESAMP_100M };
Thomas Tsoucb69f082013-04-08 14:18:26 -040039
Thomas Tsou204a9f12013-10-29 18:34:16 -040040 static RadioDevice *make(size_t sps, size_t chans = 1);
kurtis.heimerl965e7572011-11-26 03:16:54 +000041
kurtis.heimerldb2aae52011-11-26 03:17:13 +000042 /** Initialize the USRP */
Thomas Tsou010fff72013-10-16 00:31:18 -040043 virtual int open(const std::string &args = "", bool extref = false)=0;
dburgessb3a0ca42011-10-12 07:44:40 +000044
45 /** Start the USRP */
46 virtual bool start()=0;
47
48 /** Stop the USRP */
49 virtual bool stop()=0;
50
Thomas Tsou02d88d12013-04-05 15:36:30 -040051 /** Get the Tx window type */
52 virtual enum TxWindowType getWindowType()=0;
kurtis.heimerle380af32011-11-26 03:18:55 +000053
kurtis.heimerldb2aae52011-11-26 03:17:13 +000054 /** Enable thread priority */
Thomas Tsou7553aa92013-11-08 12:50:03 -050055 virtual void setPriority(float prio = 0.5) = 0;
kurtis.heimerldb2aae52011-11-26 03:17:13 +000056
dburgessb3a0ca42011-10-12 07:44:40 +000057 /**
58 Read samples from the radio.
59 @param buf preallocated buf to contain read result
60 @param len number of samples desired
61 @param overrun Set if read buffer has been overrun, e.g. data not being read fast enough
62 @param timestamp The timestamp of the first samples to be read
63 @param underrun Set if radio does not have data to transmit, e.g. data not being sent fast enough
64 @param RSSI The received signal strength of the read result
65 @return The number of samples actually read
66 */
Thomas Tsou204a9f12013-10-29 18:34:16 -040067 virtual int readSamples(std::vector<short *> &bufs, int len, bool *overrun,
68 TIMESTAMP timestamp = 0xffffffff, bool *underrun = 0,
69 unsigned *RSSI = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +000070 /**
71 Write samples to the radio.
72 @param buf Contains the data to be written.
73 @param len number of samples to write.
74 @param underrun Set if radio does not have data to transmit, e.g. data not being sent fast enough
75 @param timestamp The timestamp of the first sample of the data buffer.
76 @param isControl Set if data is a control packet, e.g. a ping command
77 @return The number of samples actually written
78 */
Thomas Tsou204a9f12013-10-29 18:34:16 -040079 virtual int writeSamples(std::vector<short *> &bufs, int len, bool *underrun,
80 TIMESTAMP timestamp, bool isControl = false) = 0;
81
dburgessb3a0ca42011-10-12 07:44:40 +000082 /** Update the alignment between the read and write timestamps */
83 virtual bool updateAlignment(TIMESTAMP timestamp)=0;
Thomas Tsou204a9f12013-10-29 18:34:16 -040084
dburgessb3a0ca42011-10-12 07:44:40 +000085 /** Set the transmitter frequency */
Thomas Tsou204a9f12013-10-29 18:34:16 -040086 virtual bool setTxFreq(double wFreq, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +000087
88 /** Set the receiver frequency */
Thomas Tsou204a9f12013-10-29 18:34:16 -040089 virtual bool setRxFreq(double wFreq, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +000090
91 /** Returns the starting write Timestamp*/
92 virtual TIMESTAMP initialWriteTimestamp(void)=0;
93
94 /** Returns the starting read Timestamp*/
95 virtual TIMESTAMP initialReadTimestamp(void)=0;
96
97 /** returns the full-scale transmit amplitude **/
98 virtual double fullScaleInputValue()=0;
99
100 /** returns the full-scale receive amplitude **/
101 virtual double fullScaleOutputValue()=0;
102
103 /** sets the receive chan gain, returns the gain setting **/
Thomas Tsou204a9f12013-10-29 18:34:16 -0400104 virtual double setRxGain(double dB, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000105
106 /** gets the current receive gain **/
Thomas Tsou204a9f12013-10-29 18:34:16 -0400107 virtual double getRxGain(size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000108
109 /** return maximum Rx Gain **/
110 virtual double maxRxGain(void) = 0;
111
112 /** return minimum Rx Gain **/
113 virtual double minRxGain(void) = 0;
114
115 /** sets the transmit chan gain, returns the gain setting **/
Thomas Tsou204a9f12013-10-29 18:34:16 -0400116 virtual double setTxGain(double dB, size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000117
118 /** return maximum Tx Gain **/
119 virtual double maxTxGain(void) = 0;
120
121 /** return minimum Tx Gain **/
122 virtual double minTxGain(void) = 0;
123
124 /** Return internal status values */
Thomas Tsou204a9f12013-10-29 18:34:16 -0400125 virtual double getTxFreq(size_t chan = 0) = 0;
126 virtual double getRxFreq(size_t chan = 0) = 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000127 virtual double getSampleRate()=0;
128 virtual double numberRead()=0;
129 virtual double numberWritten()=0;
130
131};
132
133#endif