blob: 8ab6695c597af18027aa6470752ecbba8ef04072 [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
Thomas Tsoud0f3ca32013-11-09 22:05:23 -050034radioVector::radioVector(size_t size, size_t start, GSM::Time& wTime)
35 : signalVector(size, start), mTime(wTime)
36{
37}
38
kurtis.heimerl06286132011-11-26 03:18:43 +000039GSM::Time radioVector::getTime() const
kurtis.heimerl8aea56e2011-11-26 03:18:30 +000040{
41 return mTime;
42}
43
44void radioVector::setTime(const GSM::Time& wTime)
45{
46 mTime = wTime;
47}
48
49bool radioVector::operator>(const radioVector& other) const
50{
51 return mTime > other.mTime;
52}
53
Thomas Tsoufa3a7872013-10-17 21:23:34 -040054noiseVector::noiseVector(size_t n)
55{
56 this->resize(n);
57 it = this->begin();
58}
59
60float noiseVector::avg()
61{
62 float val = 0.0;
63
64 for (int i = 0; i < size(); i++)
65 val += (*this)[i];
66
67 return val / (float) size();
68}
69
70bool noiseVector::insert(float val)
71{
72 if (!size())
73 return false;
74
75 if (it == this->end())
76 it = this->begin();
77
78 *it++ = val;
79
80 return true;
81}
82
kurtis.heimerl8aea56e2011-11-26 03:18:30 +000083GSM::Time VectorQueue::nextTime() const
84{
85 GSM::Time retVal;
86 mLock.lock();
87
88 while (mQ.size()==0)
89 mWriteSignal.wait(mLock);
90
kurtis.heimerl06286132011-11-26 03:18:43 +000091 retVal = mQ.top()->getTime();
kurtis.heimerl8aea56e2011-11-26 03:18:30 +000092 mLock.unlock();
93
94 return retVal;
95}
96
97radioVector* VectorQueue::getStaleBurst(const GSM::Time& targTime)
98{
99 mLock.lock();
100 if ((mQ.size()==0)) {
101 mLock.unlock();
102 return NULL;
103 }
104
kurtis.heimerl06286132011-11-26 03:18:43 +0000105 if (mQ.top()->getTime() < targTime) {
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000106 radioVector* retVal = mQ.top();
107 mQ.pop();
108 mLock.unlock();
109 return retVal;
110 }
111 mLock.unlock();
112
113 return NULL;
114}
115
116radioVector* VectorQueue::getCurrentBurst(const GSM::Time& targTime)
117{
118 mLock.lock();
119 if ((mQ.size()==0)) {
120 mLock.unlock();
121 return NULL;
122 }
123
kurtis.heimerl06286132011-11-26 03:18:43 +0000124 if (mQ.top()->getTime() == targTime) {
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000125 radioVector* retVal = mQ.top();
126 mQ.pop();
127 mLock.unlock();
128 return retVal;
129 }
130 mLock.unlock();
131
132 return NULL;
133}