blob: acefc97c61f97eaec45ee2b3f36209a339124030 [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 *
Pau Espin Pedrol21d03d32019-07-22 12:05:52 +02007 * SPDX-License-Identifier: AGPL-3.0+
8 *
kurtis.heimerl8aea56e2011-11-26 03:18:30 +00009 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See the COPYING file in the main directory for details.
22 */
23
24#include "radioVector.h"
25
Thomas Tsoua2fe91a2013-11-13 22:48:11 -050026radioVector::radioVector(GSM::Time &time, size_t size,
27 size_t start, size_t chans)
28 : vectors(chans), mTime(time)
kurtis.heimerl8aea56e2011-11-26 03:18:30 +000029{
Thomas Tsoua2fe91a2013-11-13 22:48:11 -050030 for (size_t i = 0; i < vectors.size(); i++)
31 vectors[i] = new signalVector(size, start);
kurtis.heimerl8aea56e2011-11-26 03:18:30 +000032}
33
Thomas Tsoua2fe91a2013-11-13 22:48:11 -050034radioVector::radioVector(GSM::Time& wTime, signalVector *vector)
35 : vectors(1), mTime(wTime)
Thomas Tsoue0fa2bf2013-11-09 02:46:29 -050036{
Thomas Tsoua2fe91a2013-11-13 22:48:11 -050037 vectors[0] = vector;
Thomas Tsoue0fa2bf2013-11-09 02:46:29 -050038}
39
Thomas Tsoua2fe91a2013-11-13 22:48:11 -050040radioVector::~radioVector()
Thomas Tsoud0f3ca32013-11-09 22:05:23 -050041{
Thomas Tsoua2fe91a2013-11-13 22:48:11 -050042 for (size_t i = 0; i < vectors.size(); i++)
43 delete vectors[i];
Thomas Tsoud0f3ca32013-11-09 22:05:23 -050044}
45
kurtis.heimerl06286132011-11-26 03:18:43 +000046GSM::Time radioVector::getTime() const
kurtis.heimerl8aea56e2011-11-26 03:18:30 +000047{
48 return mTime;
49}
50
51void radioVector::setTime(const GSM::Time& wTime)
52{
53 mTime = wTime;
54}
55
56bool radioVector::operator>(const radioVector& other) const
57{
58 return mTime > other.mTime;
59}
60
Thomas Tsou18820992013-11-14 18:04:10 -050061signalVector *radioVector::getVector(size_t chan) const
Thomas Tsoua2fe91a2013-11-13 22:48:11 -050062{
63 if (chan >= vectors.size())
64 return NULL;
65
66 return vectors[chan];
67}
68
69bool radioVector::setVector(signalVector *vector, size_t chan)
70{
71 if (chan >= vectors.size())
72 return false;
73
74 vectors[chan] = vector;
75
76 return true;
77}
78
Eric8984d7f2022-07-19 21:15:24 +020079avgVector::avgVector(size_t size)
Thomas Tsoua0179e32013-11-14 15:52:04 -050080 : std::vector<float>(size), itr(0)
Thomas Tsoufa3a7872013-10-17 21:23:34 -040081{
Thomas Tsoufa3a7872013-10-17 21:23:34 -040082}
83
Eric8984d7f2022-07-19 21:15:24 +020084float avgVector::avg() const
Thomas Tsoufa3a7872013-10-17 21:23:34 -040085{
86 float val = 0.0;
87
Eric8984d7f2022-07-19 21:15:24 +020088 if (!size())
89 return 0.0f;
90
Thomas Tsou3f32ab52013-11-15 16:32:54 -050091 for (size_t i = 0; i < size(); i++)
Thomas Tsoufa3a7872013-10-17 21:23:34 -040092 val += (*this)[i];
93
94 return val / (float) size();
95}
96
Eric8984d7f2022-07-19 21:15:24 +020097bool avgVector::insert(float val)
Thomas Tsoufa3a7872013-10-17 21:23:34 -040098{
99 if (!size())
100 return false;
101
Thomas Tsoua0179e32013-11-14 15:52:04 -0500102 if (itr >= this->size())
103 itr = 0;
Thomas Tsoufa3a7872013-10-17 21:23:34 -0400104
Thomas Tsoua0179e32013-11-14 15:52:04 -0500105 (*this)[itr++] = val;
Thomas Tsoufa3a7872013-10-17 21:23:34 -0400106
107 return true;
108}
109
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000110GSM::Time VectorQueue::nextTime() const
111{
112 GSM::Time retVal;
113 mLock.lock();
114
115 while (mQ.size()==0)
116 mWriteSignal.wait(mLock);
117
kurtis.heimerl06286132011-11-26 03:18:43 +0000118 retVal = mQ.top()->getTime();
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000119 mLock.unlock();
120
121 return retVal;
122}
123
124radioVector* VectorQueue::getStaleBurst(const GSM::Time& targTime)
125{
Pau Espin Pedrol8b0c5362020-07-09 17:39:20 +0200126 if ((mQ.size()==0))
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000127 return NULL;
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000128
kurtis.heimerl06286132011-11-26 03:18:43 +0000129 if (mQ.top()->getTime() < targTime) {
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000130 radioVector* retVal = mQ.top();
131 mQ.pop();
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000132 return retVal;
133 }
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000134 return NULL;
135}
136
137radioVector* VectorQueue::getCurrentBurst(const GSM::Time& targTime)
138{
Pau Espin Pedrol8b0c5362020-07-09 17:39:20 +0200139 if ((mQ.size()==0))
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000140 return NULL;
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000141
kurtis.heimerl06286132011-11-26 03:18:43 +0000142 if (mQ.top()->getTime() == targTime) {
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000143 radioVector* retVal = mQ.top();
144 mQ.pop();
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000145 return retVal;
146 }
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000147 return NULL;
148}