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