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> |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 19 | |
| 20 | #ifdef HAVE_CONFIG_H |
| 21 | #include "config.h" |
| 22 | #endif |
| 23 | |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 24 | #define GSMRATE 1625e3/6 |
| 25 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 26 | /** a 64-bit virtual timestamp for radio data */ |
| 27 | typedef unsigned long long TIMESTAMP; |
| 28 | |
| 29 | /** A class to handle a USRP rev 4, with a two RFX900 daughterboards */ |
| 30 | class RadioDevice { |
| 31 | |
| 32 | public: |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 33 | /* Available transport bus types */ |
Thomas Tsou | 02d88d1 | 2013-04-05 15:36:30 -0400 | [diff] [blame] | 34 | enum TxWindowType { TX_WINDOW_USRP1, TX_WINDOW_FIXED }; |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 35 | |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 36 | /* Radio interface types */ |
Thomas Tsou | fe269fe | 2013-10-14 23:56:51 -0400 | [diff] [blame^] | 37 | enum RadioInterfaceType { NORMAL, RESAMP_64M, RESAMP_100M }; |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 38 | |
| 39 | static RadioDevice *make(int sps, bool skipRx = false); |
kurtis.heimerl | 965e757 | 2011-11-26 03:16:54 +0000 | [diff] [blame] | 40 | |
kurtis.heimerl | db2aae5 | 2011-11-26 03:17:13 +0000 | [diff] [blame] | 41 | /** Initialize the USRP */ |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 42 | virtual int open(const std::string &args)=0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 43 | |
| 44 | /** Start the USRP */ |
| 45 | virtual bool start()=0; |
| 46 | |
| 47 | /** Stop the USRP */ |
| 48 | virtual bool stop()=0; |
| 49 | |
Thomas Tsou | 02d88d1 | 2013-04-05 15:36:30 -0400 | [diff] [blame] | 50 | /** Get the Tx window type */ |
| 51 | virtual enum TxWindowType getWindowType()=0; |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 52 | |
kurtis.heimerl | db2aae5 | 2011-11-26 03:17:13 +0000 | [diff] [blame] | 53 | /** Enable thread priority */ |
| 54 | virtual void setPriority()=0; |
| 55 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 56 | /** |
| 57 | Read samples from the radio. |
| 58 | @param buf preallocated buf to contain read result |
| 59 | @param len number of samples desired |
| 60 | @param overrun Set if read buffer has been overrun, e.g. data not being read fast enough |
| 61 | @param timestamp The timestamp of the first samples to be read |
| 62 | @param underrun Set if radio does not have data to transmit, e.g. data not being sent fast enough |
| 63 | @param RSSI The received signal strength of the read result |
| 64 | @return The number of samples actually read |
| 65 | */ |
| 66 | virtual int readSamples(short *buf, int len, bool *overrun, |
kurtis.heimerl | 965e757 | 2011-11-26 03:16:54 +0000 | [diff] [blame] | 67 | TIMESTAMP timestamp = 0xffffffff, |
| 68 | bool *underrun = 0, |
| 69 | unsigned *RSSI = 0)=0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 70 | /** |
| 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 | */ |
| 79 | virtual int writeSamples(short *buf, int len, bool *underrun, |
| 80 | TIMESTAMP timestamp, |
| 81 | bool isControl=false)=0; |
| 82 | |
| 83 | /** Update the alignment between the read and write timestamps */ |
| 84 | virtual bool updateAlignment(TIMESTAMP timestamp)=0; |
| 85 | |
| 86 | /** Set the transmitter frequency */ |
| 87 | virtual bool setTxFreq(double wFreq)=0; |
| 88 | |
| 89 | /** Set the receiver frequency */ |
| 90 | virtual bool setRxFreq(double wFreq)=0; |
| 91 | |
| 92 | /** Returns the starting write Timestamp*/ |
| 93 | virtual TIMESTAMP initialWriteTimestamp(void)=0; |
| 94 | |
| 95 | /** Returns the starting read Timestamp*/ |
| 96 | virtual TIMESTAMP initialReadTimestamp(void)=0; |
| 97 | |
| 98 | /** returns the full-scale transmit amplitude **/ |
| 99 | virtual double fullScaleInputValue()=0; |
| 100 | |
| 101 | /** returns the full-scale receive amplitude **/ |
| 102 | virtual double fullScaleOutputValue()=0; |
| 103 | |
| 104 | /** sets the receive chan gain, returns the gain setting **/ |
| 105 | virtual double setRxGain(double dB)=0; |
| 106 | |
| 107 | /** gets the current receive gain **/ |
| 108 | virtual double getRxGain(void)=0; |
| 109 | |
| 110 | /** return maximum Rx Gain **/ |
| 111 | virtual double maxRxGain(void) = 0; |
| 112 | |
| 113 | /** return minimum Rx Gain **/ |
| 114 | virtual double minRxGain(void) = 0; |
| 115 | |
| 116 | /** sets the transmit chan gain, returns the gain setting **/ |
| 117 | virtual double setTxGain(double dB)=0; |
| 118 | |
| 119 | /** return maximum Tx Gain **/ |
| 120 | virtual double maxTxGain(void) = 0; |
| 121 | |
| 122 | /** return minimum Tx Gain **/ |
| 123 | virtual double minTxGain(void) = 0; |
| 124 | |
| 125 | /** Return internal status values */ |
| 126 | virtual double getTxFreq()=0; |
| 127 | virtual double getRxFreq()=0; |
| 128 | virtual double getSampleRate()=0; |
| 129 | virtual double numberRead()=0; |
| 130 | virtual double numberWritten()=0; |
| 131 | |
| 132 | }; |
| 133 | |
| 134 | #endif |