blob: ee78407fb62b94a64cdf74b0e97ecf11933193d5 [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
Thomas Tsoua2fe91a2013-11-13 22:48:11 -050024radioVector::radioVector(GSM::Time &time, size_t size,
25 size_t start, size_t chans)
26 : vectors(chans), mTime(time)
kurtis.heimerl8aea56e2011-11-26 03:18:30 +000027{
Thomas Tsoua2fe91a2013-11-13 22:48:11 -050028 for (size_t i = 0; i < vectors.size(); i++)
29 vectors[i] = new signalVector(size, start);
kurtis.heimerl8aea56e2011-11-26 03:18:30 +000030}
31
Thomas Tsoua2fe91a2013-11-13 22:48:11 -050032radioVector::radioVector(GSM::Time& wTime, signalVector *vector)
33 : vectors(1), mTime(wTime)
Thomas Tsoue0fa2bf2013-11-09 02:46:29 -050034{
Thomas Tsoua2fe91a2013-11-13 22:48:11 -050035 vectors[0] = vector;
Thomas Tsoue0fa2bf2013-11-09 02:46:29 -050036}
37
Thomas Tsoua2fe91a2013-11-13 22:48:11 -050038radioVector::~radioVector()
Thomas Tsoud0f3ca32013-11-09 22:05:23 -050039{
Thomas Tsoua2fe91a2013-11-13 22:48:11 -050040 for (size_t i = 0; i < vectors.size(); i++)
41 delete vectors[i];
Thomas Tsoud0f3ca32013-11-09 22:05:23 -050042}
43
kurtis.heimerl06286132011-11-26 03:18:43 +000044GSM::Time radioVector::getTime() const
kurtis.heimerl8aea56e2011-11-26 03:18:30 +000045{
46 return mTime;
47}
48
49void radioVector::setTime(const GSM::Time& wTime)
50{
51 mTime = wTime;
52}
53
54bool radioVector::operator>(const radioVector& other) const
55{
56 return mTime > other.mTime;
57}
58
Thomas Tsou18820992013-11-14 18:04:10 -050059signalVector *radioVector::getVector(size_t chan) const
Thomas Tsoua2fe91a2013-11-13 22:48:11 -050060{
61 if (chan >= vectors.size())
62 return NULL;
63
64 return vectors[chan];
65}
66
67bool radioVector::setVector(signalVector *vector, size_t chan)
68{
69 if (chan >= vectors.size())
70 return false;
71
72 vectors[chan] = vector;
73
74 return true;
75}
76
Thomas Tsoua0179e32013-11-14 15:52:04 -050077noiseVector::noiseVector(size_t size)
78 : std::vector<float>(size), itr(0)
Thomas Tsoufa3a7872013-10-17 21:23:34 -040079{
Thomas Tsoufa3a7872013-10-17 21:23:34 -040080}
81
Thomas Tsou18820992013-11-14 18:04:10 -050082float noiseVector::avg() const
Thomas Tsoufa3a7872013-10-17 21:23:34 -040083{
84 float val = 0.0;
85
86 for (int i = 0; i < size(); i++)
87 val += (*this)[i];
88
89 return val / (float) size();
90}
91
92bool noiseVector::insert(float val)
93{
94 if (!size())
95 return false;
96
Thomas Tsoua0179e32013-11-14 15:52:04 -050097 if (itr >= this->size())
98 itr = 0;
Thomas Tsoufa3a7872013-10-17 21:23:34 -040099
Thomas Tsoua0179e32013-11-14 15:52:04 -0500100 (*this)[itr++] = val;
Thomas Tsoufa3a7872013-10-17 21:23:34 -0400101
102 return true;
103}
104
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000105GSM::Time VectorQueue::nextTime() const
106{
107 GSM::Time retVal;
108 mLock.lock();
109
110 while (mQ.size()==0)
111 mWriteSignal.wait(mLock);
112
kurtis.heimerl06286132011-11-26 03:18:43 +0000113 retVal = mQ.top()->getTime();
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000114 mLock.unlock();
115
116 return retVal;
117}
118
119radioVector* VectorQueue::getStaleBurst(const GSM::Time& targTime)
120{
121 mLock.lock();
122 if ((mQ.size()==0)) {
123 mLock.unlock();
124 return NULL;
125 }
126
kurtis.heimerl06286132011-11-26 03:18:43 +0000127 if (mQ.top()->getTime() < targTime) {
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000128 radioVector* retVal = mQ.top();
129 mQ.pop();
130 mLock.unlock();
131 return retVal;
132 }
133 mLock.unlock();
134
135 return NULL;
136}
137
138radioVector* VectorQueue::getCurrentBurst(const GSM::Time& targTime)
139{
140 mLock.lock();
141 if ((mQ.size()==0)) {
142 mLock.unlock();
143 return NULL;
144 }
145
kurtis.heimerl06286132011-11-26 03:18:43 +0000146 if (mQ.top()->getTime() == targTime) {
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000147 radioVector* retVal = mQ.top();
148 mQ.pop();
149 mLock.unlock();
150 return retVal;
151 }
152 mLock.unlock();
153
154 return NULL;
155}