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 | |
Alexander Chemeris | f931cf2 | 2016-06-18 10:42:33 +0300 | [diff] [blame] | 25 | #define GSMRATE (1625e3/6) |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 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 */ |
Tom Tsou | 05c6feb | 2016-06-22 16:09:44 -0700 | [diff] [blame^] | 38 | enum InterfaceType { |
| 39 | NORMAL, |
| 40 | RESAMP_64M, |
| 41 | RESAMP_100M, |
| 42 | DIVERSITY, |
| 43 | }; |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 44 | |
Tom Tsou | 05c6feb | 2016-06-22 16:09:44 -0700 | [diff] [blame^] | 45 | static RadioDevice *make(size_t tx_sps, size_t rx_sps, InterfaceType type, |
| 46 | size_t chans = 1, double offset = 0.0); |
kurtis.heimerl | 965e757 | 2011-11-26 03:16:54 +0000 | [diff] [blame] | 47 | |
kurtis.heimerl | db2aae5 | 2011-11-26 03:17:13 +0000 | [diff] [blame] | 48 | /** Initialize the USRP */ |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 49 | 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] | 50 | |
Thomas Tsou | 8c33679 | 2013-11-15 16:26:05 -0500 | [diff] [blame] | 51 | virtual ~RadioDevice() { } |
| 52 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 53 | /** Start the USRP */ |
| 54 | virtual bool start()=0; |
| 55 | |
| 56 | /** Stop the USRP */ |
| 57 | virtual bool stop()=0; |
| 58 | |
Thomas Tsou | 02d88d1 | 2013-04-05 15:36:30 -0400 | [diff] [blame] | 59 | /** Get the Tx window type */ |
| 60 | virtual enum TxWindowType getWindowType()=0; |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 61 | |
kurtis.heimerl | db2aae5 | 2011-11-26 03:17:13 +0000 | [diff] [blame] | 62 | /** Enable thread priority */ |
Thomas Tsou | 7553aa9 | 2013-11-08 12:50:03 -0500 | [diff] [blame] | 63 | virtual void setPriority(float prio = 0.5) = 0; |
kurtis.heimerl | db2aae5 | 2011-11-26 03:17:13 +0000 | [diff] [blame] | 64 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 65 | /** |
| 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 Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 75 | virtual int readSamples(std::vector<short *> &bufs, int len, bool *overrun, |
| 76 | TIMESTAMP timestamp = 0xffffffff, bool *underrun = 0, |
| 77 | unsigned *RSSI = 0) = 0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 78 | /** |
| 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 Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 87 | virtual int writeSamples(std::vector<short *> &bufs, int len, bool *underrun, |
| 88 | TIMESTAMP timestamp, bool isControl = false) = 0; |
| 89 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 90 | /** Update the alignment between the read and write timestamps */ |
| 91 | virtual bool updateAlignment(TIMESTAMP timestamp)=0; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 92 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 93 | /** Set the transmitter frequency */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 94 | virtual bool setTxFreq(double wFreq, size_t chan = 0) = 0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 95 | |
| 96 | /** Set the receiver frequency */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 97 | virtual bool setRxFreq(double wFreq, size_t chan = 0) = 0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 98 | |
| 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 Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 112 | virtual double setRxGain(double dB, size_t chan = 0) = 0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 113 | |
| 114 | /** gets the current receive gain **/ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 115 | virtual double getRxGain(size_t chan = 0) = 0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 116 | |
| 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 Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 124 | virtual double setTxGain(double dB, size_t chan = 0) = 0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 125 | |
| 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 Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 133 | virtual double getTxFreq(size_t chan = 0) = 0; |
| 134 | virtual double getRxFreq(size_t chan = 0) = 0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 135 | virtual double getSampleRate()=0; |
| 136 | virtual double numberRead()=0; |
| 137 | virtual double numberWritten()=0; |
| 138 | |
| 139 | }; |
| 140 | |
| 141 | #endif |