diff --git a/public-trunk/Transceiver52M/Makefile.am b/public-trunk/Transceiver52M/Makefile.am index b246211..c209018 100644 --- a/public-trunk/Transceiver52M/Makefile.am +++ b/public-trunk/Transceiver52M/Makefile.am @@ -39,11 +39,16 @@ EXTRA_DIST = \ noinst_LTLIBRARIES = libtransceiver.la -libtransceiver_la_SOURCES = \ +COMMON_SOURCES = \ radioInterface.cpp \ + radioVector.cpp \ + radioClock.cpp \ sigProcLib.cpp \ Transceiver.cpp +libtransceiver_la_SOURCES = \ + $(COMMON_SOURCES) + noinst_PROGRAMS = \ USRPping \ transceiver \ @@ -52,6 +57,8 @@ noinst_PROGRAMS = \ noinst_HEADERS = \ Complex.h \ radioInterface.h \ + radioVector.h \ + radioClock.h \ radioDevice.h \ sigProcLib.h \ Transceiver.h \ diff --git a/public-trunk/Transceiver52M/radioClock.cpp b/public-trunk/Transceiver52M/radioClock.cpp new file mode 100644 index 0000000..710018a --- /dev/null +++ b/public-trunk/Transceiver52M/radioClock.cpp @@ -0,0 +1,54 @@ +/* + * Written by Thomas Tsou + * Based on code by Harvind S Samra + * + * Copyright 2011 Free Software Foundation, Inc. + * + * 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 . + * See the COPYING file in the main directory for details. + */ + +#include "radioClock.h" + +void RadioClock::set(const GSM::Time& wTime) +{ + mLock.lock(); + mClock = wTime; + updateSignal.signal(); + mLock.unlock(); +} + +void RadioClock::incTN() +{ + mLock.lock(); + mClock.incTN(); + updateSignal.signal(); + mLock.unlock(); +} + +GSM::Time RadioClock::get() +{ + mLock.lock(); + GSM::Time retVal = mClock; + mLock.unlock(); + + return retVal; +} + +void RadioClock::wait() +{ + mLock.lock(); + updateSignal.wait(mLock,1); + mLock.unlock(); +} diff --git a/public-trunk/Transceiver52M/radioClock.h b/public-trunk/Transceiver52M/radioClock.h new file mode 100644 index 0000000..9c35c44 --- /dev/null +++ b/public-trunk/Transceiver52M/radioClock.h @@ -0,0 +1,40 @@ +/* + * Written by Thomas Tsou + * Based on code by Harvind S Samra + * + * Copyright 2011 Free Software Foundation, Inc. + * + * 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 . + * See the COPYING file in the main directory for details. + */ + +#ifndef RADIOCLOCK_H +#define RADIOCLOCK_H + +#include "GSMCommon.h" + +class RadioClock { +public: + void set(const GSM::Time& wTime); + void incTN(); + GSM::Time get(); + void wait(); + +private: + GSM::Time mClock; + Mutex mLock; + Signal updateSignal; +}; + +#endif /* RADIOCLOCK_H */ diff --git a/public-trunk/Transceiver52M/radioInterface.cpp b/public-trunk/Transceiver52M/radioInterface.cpp index be578a7..0e63b7c 100644 --- a/public-trunk/Transceiver52M/radioInterface.cpp +++ b/public-trunk/Transceiver52M/radioInterface.cpp @@ -25,54 +25,6 @@ #include "radioInterface.h" #include - -GSM::Time VectorQueue::nextTime() const -{ - GSM::Time retVal; - mLock.lock(); - while (mQ.size()==0) mWriteSignal.wait(mLock); - retVal = mQ.top()->time(); - mLock.unlock(); - return retVal; -} - -radioVector* VectorQueue::getStaleBurst(const GSM::Time& targTime) -{ - mLock.lock(); - if ((mQ.size()==0)) { - mLock.unlock(); - return NULL; - } - if (mQ.top()->time() < targTime) { - radioVector* retVal = mQ.top(); - mQ.pop(); - mLock.unlock(); - return retVal; - } - mLock.unlock(); - return NULL; -} - - -radioVector* VectorQueue::getCurrentBurst(const GSM::Time& targTime) -{ - mLock.lock(); - if ((mQ.size()==0)) { - mLock.unlock(); - return NULL; - } - if (mQ.top()->time() == targTime) { - radioVector* retVal = mQ.top(); - mQ.pop(); - mLock.unlock(); - return retVal; - } - mLock.unlock(); - return NULL; -} - - - RadioInterface::RadioInterface(RadioDevice *wRadio, int wReceiveOffset, int wRadioOversampling, diff --git a/public-trunk/Transceiver52M/radioInterface.h b/public-trunk/Transceiver52M/radioInterface.h index 27dfc14..398ad0d 100644 --- a/public-trunk/Transceiver52M/radioInterface.h +++ b/public-trunk/Transceiver52M/radioInterface.h @@ -28,105 +28,14 @@ #include "GSMCommon.h" #include "LinkedLists.h" #include "radioDevice.h" +#include "radioVector.h" +#include "radioClock.h" /** samples per GSM symbol */ #define SAMPSPERSYM 1 #define INCHUNK 625 #define OUTCHUNK 625 -/** class used to organize GSM bursts by GSM timestamps */ -class radioVector : public signalVector { - -private: - - GSM::Time mTime; ///< the burst's GSM timestamp - -public: - /** constructor */ - radioVector(const signalVector& wVector, - GSM::Time& wTime): signalVector(wVector),mTime(wTime) {}; - - /** timestamp read and write operators */ - GSM::Time time() const { return mTime;} - void time(const GSM::Time& wTime) { mTime = wTime;} - - /** comparison operator, used for sorting */ - bool operator>(const radioVector& other) const {return mTime > other.mTime;} - -}; - -/** a priority queue of radioVectors, i.e. GSM bursts, sorted so that earliest element is at top */ -class VectorQueue : public InterthreadPriorityQueue { - -public: - - /** the top element of the queue */ - GSM::Time nextTime() const; - - /** - Get stale burst, if any. - @param targTime The target time. - @return Pointer to burst older than target time, removed from queue, or NULL. - */ - radioVector* getStaleBurst(const GSM::Time& targTime); - - /** - Get current burst, if any. - @param targTime The target time. - @return Pointer to burst at the target time, removed from queue, or NULL. - */ - radioVector* getCurrentBurst(const GSM::Time& targTime); - - -}; - -/** a FIFO of radioVectors */ -class VectorFIFO { - -private: - PointerFIFO mQ; - -public: - - unsigned size() {return mQ.size();} - - void put(radioVector *ptr) {mQ.put((void*) ptr);} - - radioVector *get() {return (radioVector*) mQ.get();} - -}; - - -/** the basestation clock class */ -class RadioClock { - -private: - - GSM::Time mClock; - Mutex mLock; - Signal updateSignal; - -public: - - /** Set clock */ - void set(const GSM::Time& wTime) { mLock.lock(); mClock = wTime; updateSignal.signal(); mLock.unlock();} - //void set(const GSM::Time& wTime) { mLock.lock(); mClock = wTime; updateSignal.broadcast(); mLock.unlock();} - - /** Increment clock */ - void incTN() { mLock.lock(); mClock.incTN(); updateSignal.signal(); mLock.unlock();} - //void incTN() { mLock.lock(); mClock.incTN(); updateSignal.broadcast(); mLock.unlock();} - - /** Get clock value */ - GSM::Time get() { mLock.lock(); GSM::Time retVal = mClock; mLock.unlock(); return retVal;} - - /** Wait until clock has changed */ - void wait() {mLock.lock(); updateSignal.wait(mLock,1); mLock.unlock();} - // FIXME -- If we take away the timeout, a lot of threads don't start. Why? - //void wait() {mLock.lock(); updateSignal.wait(mLock); mLock.unlock();} - -}; - - /** class to interface the transceiver with the USRP */ class RadioInterface { diff --git a/public-trunk/Transceiver52M/radioVector.cpp b/public-trunk/Transceiver52M/radioVector.cpp new file mode 100644 index 0000000..fd4e5a7 --- /dev/null +++ b/public-trunk/Transceiver52M/radioVector.cpp @@ -0,0 +1,109 @@ +/* + * Written by Thomas Tsou + * Based on code by Harvind S Samra + * + * Copyright 2011 Free Software Foundation, Inc. + * + * 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 . + * See the COPYING file in the main directory for details. + */ + +#include "radioVector.h" + +radioVector::radioVector(const signalVector& wVector, GSM::Time& wTime) + : signalVector(wVector), mTime(wTime) +{ +} + +GSM::Time radioVector::time() const +{ + return mTime; +} + +void radioVector::setTime(const GSM::Time& wTime) +{ + mTime = wTime; +} + +bool radioVector::operator>(const radioVector& other) const +{ + return mTime > other.mTime; +} + +unsigned VectorFIFO::size() +{ + return mQ.size(); +} + +void VectorFIFO::put(radioVector *ptr) +{ + mQ.put((void*) ptr); +} + +radioVector *VectorFIFO::get() +{ + return (radioVector*) mQ.get(); +} + +GSM::Time VectorQueue::nextTime() const +{ + GSM::Time retVal; + mLock.lock(); + + while (mQ.size()==0) + mWriteSignal.wait(mLock); + + retVal = mQ.top()->time(); + mLock.unlock(); + + return retVal; +} + +radioVector* VectorQueue::getStaleBurst(const GSM::Time& targTime) +{ + mLock.lock(); + if ((mQ.size()==0)) { + mLock.unlock(); + return NULL; + } + + if (mQ.top()->time() < targTime) { + radioVector* retVal = mQ.top(); + mQ.pop(); + mLock.unlock(); + return retVal; + } + mLock.unlock(); + + return NULL; +} + +radioVector* VectorQueue::getCurrentBurst(const GSM::Time& targTime) +{ + mLock.lock(); + if ((mQ.size()==0)) { + mLock.unlock(); + return NULL; + } + + if (mQ.top()->time() == targTime) { + radioVector* retVal = mQ.top(); + mQ.pop(); + mLock.unlock(); + return retVal; + } + mLock.unlock(); + + return NULL; +} diff --git a/public-trunk/Transceiver52M/radioVector.h b/public-trunk/Transceiver52M/radioVector.h new file mode 100644 index 0000000..37970ae --- /dev/null +++ b/public-trunk/Transceiver52M/radioVector.h @@ -0,0 +1,56 @@ +/* + * Written by Thomas Tsou + * Based on code by Harvind S Samra + * + * Copyright 2011 Free Software Foundation, Inc. + * + * 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 . + * See the COPYING file in the main directory for details. + */ + +#ifndef RADIOVECTOR_H +#define RADIOVECTOR_H + +#include "sigProcLib.h" +#include "GSMCommon.h" + +class radioVector : public signalVector { +public: + radioVector(const signalVector& wVector, GSM::Time& wTime); + GSM::Time time() const; + void setTime(const GSM::Time& wTime); + bool operator>(const radioVector& other) const; + +private: + GSM::Time mTime; +}; + +class VectorFIFO { +public: + unsigned size(); + void put(radioVector *ptr); + radioVector *get(); + +private: + PointerFIFO mQ; +}; + +class VectorQueue : public InterthreadPriorityQueue { +public: + GSM::Time nextTime() const; + radioVector* getStaleBurst(const GSM::Time& targTime); + radioVector* getCurrentBurst(const GSM::Time& targTime); +}; + +#endif /* RADIOVECTOR_H */ diff --git a/public-trunk/Transceiver52M/sigProcLib.h b/public-trunk/Transceiver52M/sigProcLib.h index 0cfcec2..79e1012 100644 --- a/public-trunk/Transceiver52M/sigProcLib.h +++ b/public-trunk/Transceiver52M/sigProcLib.h @@ -22,7 +22,8 @@ */ - +#ifndef SIGPROCLIB_H +#define SIGPROCLIB_H #include "Vector.h" #include "Complex.h" @@ -390,3 +391,5 @@ SoftVector *equalizeBurst(signalVector &rxBurst, int samplesPerSymbol, signalVector &w, signalVector &b); + +#endif /* SIGPROCLIB_H */