blob: ead44815c3b215d2a223097fdf76005e6b5aa45c [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 Tsoua2fe91a2013-11-13 22:48:11 -050059signalVector *radioVector::getVector(size_t chan)
60{
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 Tsoufa3a7872013-10-17 21:23:34 -040077noiseVector::noiseVector(size_t n)
78{
79 this->resize(n);
80 it = this->begin();
81}
82
83float noiseVector::avg()
84{
85 float val = 0.0;
86
87 for (int i = 0; i < size(); i++)
88 val += (*this)[i];
89
90 return val / (float) size();
91}
92
93bool noiseVector::insert(float val)
94{
95 if (!size())
96 return false;
97
98 if (it == this->end())
99 it = this->begin();
100
101 *it++ = val;
102
103 return true;
104}
105
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000106GSM::Time VectorQueue::nextTime() const
107{
108 GSM::Time retVal;
109 mLock.lock();
110
111 while (mQ.size()==0)
112 mWriteSignal.wait(mLock);
113
kurtis.heimerl06286132011-11-26 03:18:43 +0000114 retVal = mQ.top()->getTime();
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000115 mLock.unlock();
116
117 return retVal;
118}
119
120radioVector* VectorQueue::getStaleBurst(const GSM::Time& targTime)
121{
122 mLock.lock();
123 if ((mQ.size()==0)) {
124 mLock.unlock();
125 return NULL;
126 }
127
kurtis.heimerl06286132011-11-26 03:18:43 +0000128 if (mQ.top()->getTime() < targTime) {
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000129 radioVector* retVal = mQ.top();
130 mQ.pop();
131 mLock.unlock();
132 return retVal;
133 }
134 mLock.unlock();
135
136 return NULL;
137}
138
139radioVector* VectorQueue::getCurrentBurst(const GSM::Time& targTime)
140{
141 mLock.lock();
142 if ((mQ.size()==0)) {
143 mLock.unlock();
144 return NULL;
145 }
146
kurtis.heimerl06286132011-11-26 03:18:43 +0000147 if (mQ.top()->getTime() == targTime) {
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000148 radioVector* retVal = mQ.top();
149 mQ.pop();
150 mLock.unlock();
151 return retVal;
152 }
153 mLock.unlock();
154
155 return NULL;
156}