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 | |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame^] | 24 | radioVector::radioVector(GSM::Time &time, size_t size, |
| 25 | size_t start, size_t chans) |
| 26 | : vectors(chans), mTime(time) |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 27 | { |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame^] | 28 | for (size_t i = 0; i < vectors.size(); i++) |
| 29 | vectors[i] = new signalVector(size, start); |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame^] | 32 | radioVector::radioVector(GSM::Time& wTime, signalVector *vector) |
| 33 | : vectors(1), mTime(wTime) |
Thomas Tsou | e0fa2bf | 2013-11-09 02:46:29 -0500 | [diff] [blame] | 34 | { |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame^] | 35 | vectors[0] = vector; |
Thomas Tsou | e0fa2bf | 2013-11-09 02:46:29 -0500 | [diff] [blame] | 36 | } |
| 37 | |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame^] | 38 | radioVector::~radioVector() |
Thomas Tsou | d0f3ca3 | 2013-11-09 22:05:23 -0500 | [diff] [blame] | 39 | { |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame^] | 40 | for (size_t i = 0; i < vectors.size(); i++) |
| 41 | delete vectors[i]; |
Thomas Tsou | d0f3ca3 | 2013-11-09 22:05:23 -0500 | [diff] [blame] | 42 | } |
| 43 | |
kurtis.heimerl | 0628613 | 2011-11-26 03:18:43 +0000 | [diff] [blame] | 44 | GSM::Time radioVector::getTime() const |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 45 | { |
| 46 | return mTime; |
| 47 | } |
| 48 | |
| 49 | void radioVector::setTime(const GSM::Time& wTime) |
| 50 | { |
| 51 | mTime = wTime; |
| 52 | } |
| 53 | |
| 54 | bool radioVector::operator>(const radioVector& other) const |
| 55 | { |
| 56 | return mTime > other.mTime; |
| 57 | } |
| 58 | |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame^] | 59 | signalVector *radioVector::getVector(size_t chan) |
| 60 | { |
| 61 | if (chan >= vectors.size()) |
| 62 | return NULL; |
| 63 | |
| 64 | return vectors[chan]; |
| 65 | } |
| 66 | |
| 67 | bool 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 Tsou | fa3a787 | 2013-10-17 21:23:34 -0400 | [diff] [blame] | 77 | noiseVector::noiseVector(size_t n) |
| 78 | { |
| 79 | this->resize(n); |
| 80 | it = this->begin(); |
| 81 | } |
| 82 | |
| 83 | float 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 | |
| 93 | bool 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.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 106 | GSM::Time VectorQueue::nextTime() const |
| 107 | { |
| 108 | GSM::Time retVal; |
| 109 | mLock.lock(); |
| 110 | |
| 111 | while (mQ.size()==0) |
| 112 | mWriteSignal.wait(mLock); |
| 113 | |
kurtis.heimerl | 0628613 | 2011-11-26 03:18:43 +0000 | [diff] [blame] | 114 | retVal = mQ.top()->getTime(); |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 115 | mLock.unlock(); |
| 116 | |
| 117 | return retVal; |
| 118 | } |
| 119 | |
| 120 | radioVector* VectorQueue::getStaleBurst(const GSM::Time& targTime) |
| 121 | { |
| 122 | mLock.lock(); |
| 123 | if ((mQ.size()==0)) { |
| 124 | mLock.unlock(); |
| 125 | return NULL; |
| 126 | } |
| 127 | |
kurtis.heimerl | 0628613 | 2011-11-26 03:18:43 +0000 | [diff] [blame] | 128 | if (mQ.top()->getTime() < targTime) { |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 129 | radioVector* retVal = mQ.top(); |
| 130 | mQ.pop(); |
| 131 | mLock.unlock(); |
| 132 | return retVal; |
| 133 | } |
| 134 | mLock.unlock(); |
| 135 | |
| 136 | return NULL; |
| 137 | } |
| 138 | |
| 139 | radioVector* VectorQueue::getCurrentBurst(const GSM::Time& targTime) |
| 140 | { |
| 141 | mLock.lock(); |
| 142 | if ((mQ.size()==0)) { |
| 143 | mLock.unlock(); |
| 144 | return NULL; |
| 145 | } |
| 146 | |
kurtis.heimerl | 0628613 | 2011-11-26 03:18:43 +0000 | [diff] [blame] | 147 | if (mQ.top()->getTime() == targTime) { |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 148 | radioVector* retVal = mQ.top(); |
| 149 | mQ.pop(); |
| 150 | mLock.unlock(); |
| 151 | return retVal; |
| 152 | } |
| 153 | mLock.unlock(); |
| 154 | |
| 155 | return NULL; |
| 156 | } |