kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 24 | radioVector::radioVector(const signalVector& wVector, GSM::Time& wTime) |
| 25 | : signalVector(wVector), mTime(wTime) |
| 26 | { |
| 27 | } |
| 28 | |
Thomas Tsou | e0fa2bf | 2013-11-09 02:46:29 -0500 | [diff] [blame^] | 29 | radioVector::radioVector(size_t size, GSM::Time& wTime) |
| 30 | : signalVector(size), mTime(wTime) |
| 31 | { |
| 32 | } |
| 33 | |
kurtis.heimerl | 0628613 | 2011-11-26 03:18:43 +0000 | [diff] [blame] | 34 | GSM::Time radioVector::getTime() const |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 35 | { |
| 36 | return mTime; |
| 37 | } |
| 38 | |
| 39 | void radioVector::setTime(const GSM::Time& wTime) |
| 40 | { |
| 41 | mTime = wTime; |
| 42 | } |
| 43 | |
| 44 | bool radioVector::operator>(const radioVector& other) const |
| 45 | { |
| 46 | return mTime > other.mTime; |
| 47 | } |
| 48 | |
Thomas Tsou | fa3a787 | 2013-10-17 21:23:34 -0400 | [diff] [blame] | 49 | noiseVector::noiseVector(size_t n) |
| 50 | { |
| 51 | this->resize(n); |
| 52 | it = this->begin(); |
| 53 | } |
| 54 | |
| 55 | float 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 | |
| 65 | bool 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.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 78 | GSM::Time VectorQueue::nextTime() const |
| 79 | { |
| 80 | GSM::Time retVal; |
| 81 | mLock.lock(); |
| 82 | |
| 83 | while (mQ.size()==0) |
| 84 | mWriteSignal.wait(mLock); |
| 85 | |
kurtis.heimerl | 0628613 | 2011-11-26 03:18:43 +0000 | [diff] [blame] | 86 | retVal = mQ.top()->getTime(); |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 87 | mLock.unlock(); |
| 88 | |
| 89 | return retVal; |
| 90 | } |
| 91 | |
| 92 | radioVector* VectorQueue::getStaleBurst(const GSM::Time& targTime) |
| 93 | { |
| 94 | mLock.lock(); |
| 95 | if ((mQ.size()==0)) { |
| 96 | mLock.unlock(); |
| 97 | return NULL; |
| 98 | } |
| 99 | |
kurtis.heimerl | 0628613 | 2011-11-26 03:18:43 +0000 | [diff] [blame] | 100 | if (mQ.top()->getTime() < targTime) { |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 101 | radioVector* retVal = mQ.top(); |
| 102 | mQ.pop(); |
| 103 | mLock.unlock(); |
| 104 | return retVal; |
| 105 | } |
| 106 | mLock.unlock(); |
| 107 | |
| 108 | return NULL; |
| 109 | } |
| 110 | |
| 111 | radioVector* VectorQueue::getCurrentBurst(const GSM::Time& targTime) |
| 112 | { |
| 113 | mLock.lock(); |
| 114 | if ((mQ.size()==0)) { |
| 115 | mLock.unlock(); |
| 116 | return NULL; |
| 117 | } |
| 118 | |
kurtis.heimerl | 0628613 | 2011-11-26 03:18:43 +0000 | [diff] [blame] | 119 | if (mQ.top()->getTime() == targTime) { |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 120 | radioVector* retVal = mQ.top(); |
| 121 | mQ.pop(); |
| 122 | mLock.unlock(); |
| 123 | return retVal; |
| 124 | } |
| 125 | mLock.unlock(); |
| 126 | |
| 127 | return NULL; |
| 128 | } |