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