blob: 74a962df954817b135d88e808aa27ff90b05d5b7 [file] [log] [blame]
dburgessb3a0ca42011-10-12 07:44:40 +00001/*
2* Copyright 2008 Free Software Foundation, Inc.
3*
4* This software is distributed under the terms of the GNU Public License.
5* See the COPYING file in the main directory for details.
6*
7* This use of this software may be subject to additional restrictions.
8* See the LEGAL file in the main directory for details.
9
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
22
23*/
24
25
26#ifdef HAVE_CONFIG_H
27#include "config.h"
28#endif
29
30#include "radioDevice.h"
31
32
33#include <sys/time.h>
34#include <math.h>
35#include <string>
36#include <iostream>
37
38
39/** A class to handle a USRP rev 4, with a two RFX900 daughterboards */
40class DummyLoad: public RadioDevice {
41
42private:
43
44 double sampleRate; ///< the desired sampling rate
45 unsigned long long samplesRead; ///< number of samples read from USRP
46 unsigned long long samplesWritten; ///< number of samples sent to USRP
47
48 Mutex underrunLock;
49
50 struct timeval startTime, currTime;
51
52 TIMESTAMP currstamp;
53 short *dummyBurst;
54 int dummyBurstSz;
55 int dummyBurstCursor;
56 bool underrun;
57
58 void updateTime(void);
59
60 public:
61
62 /** Object constructor */
63 DummyLoad (double _desiredSampleRate);
64
65 int loadBurst(short *wDummyBurst, int len);
66
67 /** Instantiate the USRP */
68 bool make(bool skipRx = false);
69
70 /** Start the USRP */
71 bool start();
72
73 /** Stop the USRP */
74 bool stop();
75
76 /**
77 Read samples from the USRP.
78 @param buf preallocated buf to contain read result
79 @param len number of samples desired
80 @param overrun Set if read buffer has been overrun, e.g. data not being read fast enough
81 @param timestamp The timestamp of the first samples to be read
82 @param underrun Set if USRP does not have data to transmit, e.g. data not being sent fast enough
83 @param RSSI The received signal strength of the read result
84 @return The number of samples actually read
85 */
86 int readSamples(short *buf, int len, bool *overrun,
87 TIMESTAMP timestamp = 0xffffffff,
88 bool *underrun = NULL,
89 unsigned *RSSI = NULL);
90 /**
91 Write samples to the USRP.
92 @param buf Contains the data to be written.
93 @param len number of samples to write.
94 @param underrun Set if USRP does not have data to transmit, e.g. data not being sent fast enough
95 @param timestamp The timestamp of the first sample of the data buffer.
96 @param isControl Set if data is a control packet, e.g. a ping command
97 @return The number of samples actually written
98 */
99 int writeSamples(short *buf, int len, bool *underrun,
100 TIMESTAMP timestamp = 0xffffffff,
101 bool isControl = false);
102
103 /** Update the alignment between the read and write timestamps */
104 bool updateAlignment(TIMESTAMP timestamp);
105
106 /** Set the transmitter frequency */
107 bool setTxFreq(double wFreq);
108
109 /** Set the receiver frequency */
110 bool setRxFreq(double wFreq);
111
112 /** Returns the starting write Timestamp*/
113 TIMESTAMP initialWriteTimestamp(void) { return 20000;}
114
115 /** Returns the starting read Timestamp*/
116 TIMESTAMP initialReadTimestamp(void) { return 20000;}
117
118 /** returns the full-scale transmit amplitude **/
119 double fullScaleInputValue() {return 13500.0;}
120
121 /** returns the full-scale receive amplitude **/
122 double fullScaleOutputValue() {return 9450.0;}
123
124 /** Return internal status values */
125 inline double getTxFreq() { return 0;}
126 inline double getRxFreq() { return 0;}
127 inline double getSampleRate() {return sampleRate;}
128 inline double numberRead() { return samplesRead; }
129 inline double numberWritten() { return samplesWritten;}
130
131};
132