blob: c50cfa5858b5e6e5433a5814087a76623cd3e91c [file] [log] [blame]
kurtis.heimerl8aea56e2011-11-26 03:18:30 +00001/*
2 * Written by Thomas Tsou <ttsou@vt.edu>
3 * Based on code by Harvind S Samra <hssamra@kestrelsp.com>
4 *
5 * Copyright 2011 Free Software Foundation, Inc.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * See the COPYING file in the main directory for details.
20 */
21
22#include "radioVector.h"
23
24radioVector::radioVector(const signalVector& wVector, GSM::Time& wTime)
25 : signalVector(wVector), mTime(wTime)
26{
27}
28
Thomas Tsoue0fa2bf2013-11-09 02:46:29 -050029radioVector::radioVector(size_t size, GSM::Time& wTime)
30 : signalVector(size), mTime(wTime)
31{
32}
33
kurtis.heimerl06286132011-11-26 03:18:43 +000034GSM::Time radioVector::getTime() const
kurtis.heimerl8aea56e2011-11-26 03:18:30 +000035{
36 return mTime;
37}
38
39void radioVector::setTime(const GSM::Time& wTime)
40{
41 mTime = wTime;
42}
43
44bool radioVector::operator>(const radioVector& other) const
45{
46 return mTime > other.mTime;
47}
48
Thomas Tsoufa3a7872013-10-17 21:23:34 -040049noiseVector::noiseVector(size_t n)
50{
51 this->resize(n);
52 it = this->begin();
53}
54
55float noiseVector::avg()
56{
57 float val = 0.0;
58
59 for (int i = 0; i < size(); i++)
60 val += (*this)[i];
61
62 return val / (float) size();
63}
64
65bool noiseVector::insert(float val)
66{
67 if (!size())
68 return false;
69
70 if (it == this->end())
71 it = this->begin();
72
73 *it++ = val;
74
75 return true;
76}
77
kurtis.heimerl8aea56e2011-11-26 03:18:30 +000078GSM::Time VectorQueue::nextTime() const
79{
80 GSM::Time retVal;
81 mLock.lock();
82
83 while (mQ.size()==0)
84 mWriteSignal.wait(mLock);
85
kurtis.heimerl06286132011-11-26 03:18:43 +000086 retVal = mQ.top()->getTime();
kurtis.heimerl8aea56e2011-11-26 03:18:30 +000087 mLock.unlock();
88
89 return retVal;
90}
91
92radioVector* VectorQueue::getStaleBurst(const GSM::Time& targTime)
93{
94 mLock.lock();
95 if ((mQ.size()==0)) {
96 mLock.unlock();
97 return NULL;
98 }
99
kurtis.heimerl06286132011-11-26 03:18:43 +0000100 if (mQ.top()->getTime() < targTime) {
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000101 radioVector* retVal = mQ.top();
102 mQ.pop();
103 mLock.unlock();
104 return retVal;
105 }
106 mLock.unlock();
107
108 return NULL;
109}
110
111radioVector* VectorQueue::getCurrentBurst(const GSM::Time& targTime)
112{
113 mLock.lock();
114 if ((mQ.size()==0)) {
115 mLock.unlock();
116 return NULL;
117 }
118
kurtis.heimerl06286132011-11-26 03:18:43 +0000119 if (mQ.top()->getTime() == targTime) {
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000120 radioVector* retVal = mQ.top();
121 mQ.pop();
122 mLock.unlock();
123 return retVal;
124 }
125 mLock.unlock();
126
127 return NULL;
128}