dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
ttsou | f60dafa | 2012-10-22 00:07:14 +0000 | [diff] [blame] | 18 | #include <string> |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 19 | #include <vector> |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 20 | |
| 21 | #ifdef HAVE_CONFIG_H |
| 22 | #include "config.h" |
| 23 | #endif |
| 24 | |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 25 | #define GSMRATE 1625e3/6 |
| 26 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 27 | /** a 64-bit virtual timestamp for radio data */ |
| 28 | typedef unsigned long long TIMESTAMP; |
| 29 | |
| 30 | /** A class to handle a USRP rev 4, with a two RFX900 daughterboards */ |
| 31 | class RadioDevice { |
| 32 | |
| 33 | public: |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 34 | /* Available transport bus types */ |
Thomas Tsou | 02d88d1 | 2013-04-05 15:36:30 -0400 | [diff] [blame] | 35 | enum TxWindowType { TX_WINDOW_USRP1, TX_WINDOW_FIXED }; |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 36 | |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 37 | /* Radio interface types */ |
Thomas Tsou | e90a42b | 2013-11-13 23:38:09 -0500 | [diff] [blame] | 38 | enum RadioInterfaceType { NORMAL, RESAMP_64M, RESAMP_100M, DIVERSITY }; |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 39 | |
Thomas Tsou | e90a42b | 2013-11-13 23:38:09 -0500 | [diff] [blame] | 40 | static RadioDevice *make(size_t sps, size_t chans = 1, |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 41 | bool diversity = false, double offset = 0.0); |
kurtis.heimerl | 965e757 | 2011-11-26 03:16:54 +0000 | [diff] [blame] | 42 | |
kurtis.heimerl | db2aae5 | 2011-11-26 03:17:13 +0000 | [diff] [blame] | 43 | /** Initialize the USRP */ |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 44 | virtual int open(const std::string &args = "", bool extref = false, bool swap_channels = false)=0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 45 | |
Thomas Tsou | 8c33679 | 2013-11-15 16:26:05 -0500 | [diff] [blame] | 46 | virtual ~RadioDevice() { } |
| 47 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 48 | /** Start the USRP */ |
| 49 | virtual bool start()=0; |
| 50 | |
| 51 | /** Stop the USRP */ |
| 52 | virtual bool stop()=0; |
| 53 | |
Thomas Tsou | 02d88d1 | 2013-04-05 15:36:30 -0400 | [diff] [blame] | 54 | /** Get the Tx window type */ |
| 55 | virtual enum TxWindowType getWindowType()=0; |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 56 | |
kurtis.heimerl | db2aae5 | 2011-11-26 03:17:13 +0000 | [diff] [blame] | 57 | /** Enable thread priority */ |
Thomas Tsou | 7553aa9 | 2013-11-08 12:50:03 -0500 | [diff] [blame] | 58 | virtual void setPriority(float prio = 0.5) = 0; |
kurtis.heimerl | db2aae5 | 2011-11-26 03:17:13 +0000 | [diff] [blame] | 59 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 60 | /** |
| 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 Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 70 | virtual int readSamples(std::vector<short *> &bufs, int len, bool *overrun, |
| 71 | TIMESTAMP timestamp = 0xffffffff, bool *underrun = 0, |
| 72 | unsigned *RSSI = 0) = 0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 73 | /** |
| 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 Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 82 | virtual int writeSamples(std::vector<short *> &bufs, int len, bool *underrun, |
| 83 | TIMESTAMP timestamp, bool isControl = false) = 0; |
| 84 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 85 | /** Update the alignment between the read and write timestamps */ |
| 86 | virtual bool updateAlignment(TIMESTAMP timestamp)=0; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 87 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 88 | /** Set the transmitter frequency */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 89 | virtual bool setTxFreq(double wFreq, size_t chan = 0) = 0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 90 | |
| 91 | /** Set the receiver frequency */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 92 | virtual bool setRxFreq(double wFreq, size_t chan = 0) = 0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 93 | |
| 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 Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 107 | virtual double setRxGain(double dB, size_t chan = 0) = 0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 108 | |
| 109 | /** gets the current receive gain **/ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 110 | virtual double getRxGain(size_t chan = 0) = 0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 111 | |
| 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 Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 119 | virtual double setTxGain(double dB, size_t chan = 0) = 0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 120 | |
| 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 Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 128 | virtual double getTxFreq(size_t chan = 0) = 0; |
| 129 | virtual double getRxFreq(size_t chan = 0) = 0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 130 | virtual double getSampleRate()=0; |
| 131 | virtual double numberRead()=0; |
| 132 | virtual double numberWritten()=0; |
| 133 | |
| 134 | }; |
| 135 | |
| 136 | #endif |