From 8c86da79c0db4e705809e97d270134ee4b366ab4 Mon Sep 17 00:00:00 2001 From: Thomas Tsou Date: Fri, 6 May 2011 14:22:47 -0400 Subject: [PATCH] uhd: move non-52MHz transceiver to common radio device interface Use the same header files for the device and start moving toward a commmon transceiver without so much redundant code. Signed-off-by: Thomas Tsou --- public-trunk/Transceiver/Device.h | 91 --------------------- public-trunk/Transceiver/Makefile.am | 3 +- public-trunk/Transceiver/UHDDevice.cpp | 6 +- public-trunk/Transceiver/USRPping.cpp | 2 +- public-trunk/Transceiver/radioInterface.cpp | 2 +- public-trunk/Transceiver/radioInterface.h | 8 +- public-trunk/Transceiver/runTransceiver.cpp | 2 +- public-trunk/Transceiver52M/radioDevice.h | 4 + 8 files changed, 15 insertions(+), 103 deletions(-) delete mode 100644 public-trunk/Transceiver/Device.h diff --git a/public-trunk/Transceiver/Device.h b/public-trunk/Transceiver/Device.h deleted file mode 100644 index 6e22378..0000000 --- a/public-trunk/Transceiver/Device.h +++ /dev/null @@ -1,91 +0,0 @@ -/* -* Copyright 2008, 2009, 2010 Free Software Foundation, Inc. -* -* This software is distributed under the terms of the GNU Affero Public License. -* See the COPYING file in the main directory for details. -* -* This use of this software may be subject to additional restrictions. -* See the LEGAL file in the main directory for details. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - -*/ - -#ifndef _DEVICE_H_ -#define _DEVICE_H_ - -/** a 64-bit virtual timestamp for device data */ -typedef unsigned long long TIMESTAMP; - -class Device { -public: - /** Factory method */ - static Device *make(double desiredSampleRate, bool skipRx = false); - - /** Open, start, and stop the device - @return success or fail - */ - virtual bool open() = 0; - virtual bool start() = 0; - virtual bool stop() = 0; - virtual void setPriority() = 0; - - /** Read samples from the USRP. - @param buf preallocated buf to contain read result - @param len number of samples desired - @param overrun set if read buffer has been overrun - @param timestamp time of the first samples to be read - @param underrun set if USRP does not have data to transmit - @param RSSI received signal strength of the read result - @return number of samples actually read - */ - virtual int readSamples(short *buf, int len, bool *overrun, - TIMESTAMP timestamp = 0xffffffff, - bool *underrun = 0, - unsigned *RSSI = 0) = 0; - - /** Write samples to the USRP. - @param buf contains the data to be written - @param len number of samples to write - @param underrun set if USRP does not have data to transmit - @param timestamp time of the first sample of the data buffer - @param isControl set if data is a control packet - @return number of samples actually written - */ - virtual int writeSamples(short *buf, int len, bool *underrun, - TIMESTAMP timestamp = 0xffffffff, - bool isControl = false) = 0; - - /** Update the alignment between the read and write timestamps - @return success or fail - */ - virtual bool updateAlignment(TIMESTAMP timestamp) = 0; - - /** Set transmit and receive frequencies - @param freq desired frequency - @return success or fail - */ - virtual bool setTxFreq(double freq) = 0; - virtual bool setRxFreq(double freq) = 0; - - /** Return internal status values */ - virtual double getSampleRate() = 0; - virtual double numberRead() = 0; - virtual double numberWritten() = 0; - - /** Virtual destructor */ - virtual ~Device() { } -}; - -#endif // _DEVICE_H_ diff --git a/public-trunk/Transceiver/Makefile.am b/public-trunk/Transceiver/Makefile.am index db59c9f..046098d 100644 --- a/public-trunk/Transceiver/Makefile.am +++ b/public-trunk/Transceiver/Makefile.am @@ -55,8 +55,7 @@ noinst_HEADERS = \ sendLPF_961.h \ sigProcLib.h \ Transceiver.h \ - USRPDevice.h \ - Device.h + USRPDevice.h USRPping_SOURCES = USRPping.cpp USRPping_LDADD = \ diff --git a/public-trunk/Transceiver/UHDDevice.cpp b/public-trunk/Transceiver/UHDDevice.cpp index dc20d64..6686c2c 100644 --- a/public-trunk/Transceiver/UHDDevice.cpp +++ b/public-trunk/Transceiver/UHDDevice.cpp @@ -22,7 +22,7 @@ */ -#include "Device.h" +#include "../Transceiver52M/radioDevice.h" #include "Threads.h" #include "Logger.h" #include @@ -133,7 +133,7 @@ private: Events and errors such as underruns are reported asynchronously by the device and received in a separate thread. */ -class uhd_device : public Device { +class uhd_device : public RadioDevice { public: uhd_device(double rate, bool skip_rx); ~uhd_device(); @@ -819,7 +819,7 @@ std::string smpl_buf::str_code(ssize_t code) } } -Device *Device::make(double smpl_rt, bool skip_rx) +RadioDevice *RadioDevice::make(double smpl_rt, bool skip_rx) { return new uhd_device(smpl_rt, skip_rx); } diff --git a/public-trunk/Transceiver/USRPping.cpp b/public-trunk/Transceiver/USRPping.cpp index 101834f..3a8c706 100644 --- a/public-trunk/Transceiver/USRPping.cpp +++ b/public-trunk/Transceiver/USRPping.cpp @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) { else gLogInit("INFO"); if (argc>2) gSetLogFile(argv[2]); - Device *usrp = Device::make(400e3); + RadioDevice *usrp = RadioDevice::make(400e3); if (!usrp->open()) { cerr << "Device open failed. Exiting..." << endl; exit(1); diff --git a/public-trunk/Transceiver/radioInterface.cpp b/public-trunk/Transceiver/radioInterface.cpp index 021df31..29c9457 100644 --- a/public-trunk/Transceiver/radioInterface.cpp +++ b/public-trunk/Transceiver/radioInterface.cpp @@ -38,7 +38,7 @@ GSM::Time VectorQueue::nextTime() const return retVal; } -RadioInterface::RadioInterface(Device *wUsrp, +RadioInterface::RadioInterface(RadioDevice *wUsrp, int wReceiveOffset, int wSamplesPerSymbol, GSM::Time wStartTime) diff --git a/public-trunk/Transceiver/radioInterface.h b/public-trunk/Transceiver/radioInterface.h index ad9687b..eea18af 100644 --- a/public-trunk/Transceiver/radioInterface.h +++ b/public-trunk/Transceiver/radioInterface.h @@ -25,7 +25,7 @@ #include "sigProcLib.h" -#include "Device.h" +#include "../Transceiver52M/radioDevice.h" #include "GSMCommon.h" #include "Interthread.h" @@ -119,7 +119,7 @@ private: signalVector* sendHistory; ///< block of previous transmitted samples signalVector* rcvHistory; ///< block of previous received samples - Device *usrp; ///< the USRP object + RadioDevice *usrp; ///< the USRP object signalVector* sendBuffer; ///< block of samples to be transmitted signalVector* rcvBuffer; ///< block of received samples to be processed @@ -160,7 +160,7 @@ public: void start(); /** constructor */ - RadioInterface(Device* wUsrp = NULL, + RadioInterface(RadioDevice* wUsrp = NULL, int receiveOffset = 3, int wSamplesPerSymbol = SAMPSPERSYM, GSM::Time wStartTime = GSM::Time(0)); @@ -172,7 +172,7 @@ public: bool isUnderrun() { bool retVal = underrun; underrun = false; return retVal;} /** attach an existing USRP to this interface */ - void attach(Device *wUsrp) {if (!mOn) usrp = wUsrp;} + void attach(RadioDevice *wUsrp) {if (!mOn) usrp = wUsrp;} /** return the transmit FIFO */ VectorFIFO* transmitFIFO() { return &mTransmitFIFO;} diff --git a/public-trunk/Transceiver/runTransceiver.cpp b/public-trunk/Transceiver/runTransceiver.cpp index 89a2274..1373fc1 100644 --- a/public-trunk/Transceiver/runTransceiver.cpp +++ b/public-trunk/Transceiver/runTransceiver.cpp @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) { srandom(time(NULL)); - Device *usrp = Device::make(400.0e3); + RadioDevice *usrp = RadioDevice::make(400.0e3); if (!usrp->open()) { cerr << "Device open failed. Exiting..." << endl; exit(1); diff --git a/public-trunk/Transceiver52M/radioDevice.h b/public-trunk/Transceiver52M/radioDevice.h index 6eed491..264e7f9 100644 --- a/public-trunk/Transceiver52M/radioDevice.h +++ b/public-trunk/Transceiver52M/radioDevice.h @@ -39,6 +39,7 @@ class RadioDevice { public: static RadioDevice *make(double desiredSampleRate, bool skipRx = false); + /** Initialize the USRP */ virtual bool open()=0; /** Start the USRP */ @@ -47,6 +48,9 @@ class RadioDevice { /** Stop the USRP */ virtual bool stop()=0; + /** Enable thread priority */ + virtual void setPriority()=0; + /** Read samples from the radio. @param buf preallocated buf to contain read result