dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008, 2009, 2010 Free Software Foundation, Inc. |
| 3 | * |
| 4 | * This software is distributed under the terms of the GNU Public License. |
| 5 | * See the COPYING file in the main directory for details. |
| 6 | * |
| 7 | * This use of this software may be subject to additional restrictions. |
| 8 | * See the LEGAL file in the main directory for details. |
| 9 | |
| 10 | This program is free software: you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation, either version 3 of the License, or |
| 13 | (at your option) any later version. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | */ |
| 23 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 24 | #include <stdio.h> |
| 25 | #include "Transceiver.h" |
| 26 | #include <Logger.h> |
| 27 | |
ttsou | 2173abf | 2012-08-08 00:51:31 +0000 | [diff] [blame] | 28 | #ifdef HAVE_CONFIG_H |
| 29 | #include "config.h" |
| 30 | #endif |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 31 | |
Alexander Chemeris | d734e2d | 2013-06-16 14:30:58 +0400 | [diff] [blame] | 32 | using namespace GSM; |
| 33 | |
kurtis.heimerl | ec842de | 2012-11-23 08:37:32 +0000 | [diff] [blame] | 34 | #define USB_LATENCY_INTRVL 10,0 |
ttsou | 2173abf | 2012-08-08 00:51:31 +0000 | [diff] [blame] | 35 | |
| 36 | #if USE_UHD |
kurtis.heimerl | ec842de | 2012-11-23 08:37:32 +0000 | [diff] [blame] | 37 | # define USB_LATENCY_MIN 6,7 |
ttsou | 2173abf | 2012-08-08 00:51:31 +0000 | [diff] [blame] | 38 | #else |
kurtis.heimerl | ec842de | 2012-11-23 08:37:32 +0000 | [diff] [blame] | 39 | # define USB_LATENCY_MIN 1,1 |
ttsou | 2173abf | 2012-08-08 00:51:31 +0000 | [diff] [blame] | 40 | #endif |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 41 | |
Thomas Tsou | fa3a787 | 2013-10-17 21:23:34 -0400 | [diff] [blame] | 42 | /* Number of running values use in noise average */ |
| 43 | #define NOISE_CNT 20 |
ttsou | e8dde02 | 2012-12-06 15:43:55 +0000 | [diff] [blame] | 44 | |
Thomas Tsou | f078273 | 2013-10-29 15:55:47 -0400 | [diff] [blame] | 45 | TransceiverState::TransceiverState() |
Tom Tsou | a4d1a41 | 2014-11-25 15:46:56 -0800 | [diff] [blame] | 46 | : mRetrans(false), mNoiseLev(0.0), mNoises(NOISE_CNT), mPower(0.0) |
Thomas Tsou | f078273 | 2013-10-29 15:55:47 -0400 | [diff] [blame] | 47 | { |
| 48 | for (int i = 0; i < 8; i++) { |
| 49 | chanType[i] = Transceiver::NONE; |
| 50 | fillerModulus[i] = 26; |
| 51 | chanResponse[i] = NULL; |
| 52 | DFEForward[i] = NULL; |
| 53 | DFEFeedback[i] = NULL; |
| 54 | |
| 55 | for (int n = 0; n < 102; n++) |
| 56 | fillerTable[n][i] = NULL; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | TransceiverState::~TransceiverState() |
| 61 | { |
| 62 | for (int i = 0; i < 8; i++) { |
| 63 | delete chanResponse[i]; |
| 64 | delete DFEForward[i]; |
| 65 | delete DFEFeedback[i]; |
| 66 | |
| 67 | for (int n = 0; n < 102; n++) |
| 68 | delete fillerTable[n][i]; |
| 69 | } |
| 70 | } |
| 71 | |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame^] | 72 | static BitVector *genRandNormalBurst(size_t tsc) |
Thomas Tsou | f078273 | 2013-10-29 15:55:47 -0400 | [diff] [blame] | 73 | { |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame^] | 74 | if (tsc > 7) |
| 75 | return NULL; |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 76 | |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame^] | 77 | BitVector *bits = new BitVector(148); |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 78 | |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame^] | 79 | size_t i = 0; |
| 80 | |
| 81 | /* Tail bits */ |
| 82 | for (; i < 4; i++) |
| 83 | (*bits)[i] = 0; |
| 84 | |
| 85 | /* Random bits */ |
| 86 | for (; i < 61; i++) |
| 87 | (*bits)[i] = rand() % 2; |
| 88 | |
| 89 | /* Training sequence */ |
| 90 | for (; i < 87; i++) |
| 91 | (*bits)[i] = GSM::gTrainingSequence[tsc][i]; |
| 92 | |
| 93 | /* Random bits */ |
| 94 | for (; i < 144; i++) |
| 95 | (*bits)[i] = rand() % 2; |
| 96 | |
| 97 | /* Tail bits */ |
| 98 | for (; i < 148; i++) |
| 99 | (*bits)[i] = 0; |
| 100 | |
| 101 | return bits; |
| 102 | } |
| 103 | |
| 104 | bool TransceiverState::init(int filler, size_t sps, float scale, size_t rtsc) |
| 105 | { |
| 106 | BitVector *bits; |
| 107 | signalVector *burst; |
| 108 | |
| 109 | if ((sps != 1) && (sps != 4)) |
| 110 | return false; |
| 111 | |
| 112 | for (size_t n = 0; n < 8; n++) { |
| 113 | size_t guard = 8 + !(n % 4); |
| 114 | size_t len = sps == 4 ? 625 : 148 + guard; |
| 115 | |
| 116 | for (size_t i = 0; i < 102; i++) { |
| 117 | switch (filler) { |
| 118 | case Transceiver::FILLER_DUMMY: |
| 119 | burst = modulateBurst(gDummyBurst, guard, sps); |
| 120 | break; |
| 121 | case Transceiver::FILLER_RAND: |
| 122 | bits = genRandNormalBurst(rtsc); |
| 123 | burst = modulateBurst(*bits, guard, sps); |
| 124 | delete bits; |
| 125 | break; |
| 126 | case Transceiver::FILLER_ZERO: |
| 127 | default: |
| 128 | burst = new signalVector(len); |
| 129 | } |
| 130 | |
| 131 | scaleVector(*burst, scale); |
| 132 | fillerTable[i][n] = burst; |
| 133 | } |
| 134 | |
| 135 | if (filler == Transceiver::FILLER_RAND) |
| 136 | chanType[n] = Transceiver::TSC; |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 137 | } |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame^] | 138 | |
| 139 | return false; |
Thomas Tsou | f078273 | 2013-10-29 15:55:47 -0400 | [diff] [blame] | 140 | } |
| 141 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 142 | Transceiver::Transceiver(int wBasePort, |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 143 | const char *wTRXAddress, |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 144 | size_t wSPS, size_t wChans, |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 145 | GSM::Time wTransmitLatency, |
| 146 | RadioInterface *wRadioInterface) |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 147 | : mBasePort(wBasePort), mAddr(wTRXAddress), |
| 148 | mClockSocket(wBasePort, wTRXAddress, mBasePort + 100), |
| 149 | mTransmitLatency(wTransmitLatency), mRadioInterface(wRadioInterface), |
| 150 | mSPSTx(wSPS), mSPSRx(1), mChans(wChans), mOn(false), |
| 151 | mTxFreq(0.0), mRxFreq(0.0), mMaxExpectedDelay(0) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 152 | { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 153 | txFullScale = mRadioInterface->fullScaleInputValue(); |
| 154 | rxFullScale = mRadioInterface->fullScaleOutputValue(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | Transceiver::~Transceiver() |
| 158 | { |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 159 | stop(); |
| 160 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 161 | sigProcLibDestroy(); |
Thomas Tsou | d647ec5 | 2013-10-29 15:17:34 -0400 | [diff] [blame] | 162 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 163 | for (size_t i = 0; i < mChans; i++) { |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 164 | mControlServiceLoopThreads[i]->cancel(); |
| 165 | mControlServiceLoopThreads[i]->join(); |
| 166 | delete mControlServiceLoopThreads[i]; |
| 167 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 168 | mTxPriorityQueues[i].clear(); |
| 169 | delete mCtrlSockets[i]; |
| 170 | delete mDataSockets[i]; |
| 171 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 172 | } |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 173 | |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 174 | /* |
| 175 | * Initialize transceiver |
| 176 | * |
| 177 | * Start or restart the control loop. Any further control is handled through the |
| 178 | * socket API. Randomize the central radio clock set the downlink burst |
| 179 | * counters. Note that the clock will not update until the radio starts, but we |
| 180 | * are still expected to report clock indications through control channel |
| 181 | * activity. |
| 182 | */ |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame^] | 183 | bool Transceiver::init(int filler, size_t rtsc) |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 184 | { |
Thomas Tsou | e1ce925 | 2013-11-13 22:40:44 -0500 | [diff] [blame] | 185 | int d_srcport, d_dstport, c_srcport, c_dstport; |
Thomas Tsou | f078273 | 2013-10-29 15:55:47 -0400 | [diff] [blame] | 186 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 187 | if (!mChans) { |
| 188 | LOG(ALERT) << "No channels assigned"; |
| 189 | return false; |
| 190 | } |
| 191 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 192 | if (!sigProcLibSetup(mSPSTx)) { |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 193 | LOG(ALERT) << "Failed to initialize signal processing library"; |
| 194 | return false; |
| 195 | } |
| 196 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 197 | mDataSockets.resize(mChans); |
| 198 | mCtrlSockets.resize(mChans); |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 199 | mControlServiceLoopThreads.resize(mChans); |
| 200 | mTxPriorityQueueServiceLoopThreads.resize(mChans); |
| 201 | mRxServiceLoopThreads.resize(mChans); |
| 202 | |
| 203 | mTxPriorityQueues.resize(mChans); |
| 204 | mReceiveFIFO.resize(mChans); |
| 205 | mStates.resize(mChans); |
| 206 | |
Thomas Tsou | ccb73e1 | 2014-04-15 17:41:28 -0400 | [diff] [blame] | 207 | /* Filler table retransmissions - support only on channel 0 */ |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame^] | 208 | if (filler == FILLER_DUMMY) |
Thomas Tsou | ccb73e1 | 2014-04-15 17:41:28 -0400 | [diff] [blame] | 209 | mStates[0].mRetrans = true; |
| 210 | |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 211 | /* Setup sockets */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 212 | for (size_t i = 0; i < mChans; i++) { |
Thomas Tsou | e1ce925 | 2013-11-13 22:40:44 -0500 | [diff] [blame] | 213 | c_srcport = mBasePort + 2 * i + 1; |
| 214 | c_dstport = mBasePort + 2 * i + 101; |
| 215 | d_srcport = mBasePort + 2 * i + 2; |
| 216 | d_dstport = mBasePort + 2 * i + 102; |
| 217 | |
| 218 | mCtrlSockets[i] = new UDPSocket(c_srcport, mAddr.c_str(), c_dstport); |
| 219 | mDataSockets[i] = new UDPSocket(d_srcport, mAddr.c_str(), d_dstport); |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 220 | } |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 221 | |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 222 | /* Randomize the central clock */ |
| 223 | GSM::Time startTime(random() % gHyperframe, 0); |
| 224 | mRadioInterface->getClock()->set(startTime); |
| 225 | mTransmitDeadlineClock = startTime; |
| 226 | mLastClockUpdateTime = startTime; |
| 227 | mLatencyUpdateTime = startTime; |
| 228 | |
| 229 | /* Start control threads */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 230 | for (size_t i = 0; i < mChans; i++) { |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 231 | TransceiverChannel *chan = new TransceiverChannel(this, i); |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 232 | mControlServiceLoopThreads[i] = new Thread(32768); |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 233 | mControlServiceLoopThreads[i]->start((void * (*)(void*)) |
| 234 | ControlServiceLoopAdapter, (void*) chan); |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 235 | |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame^] | 236 | if (i && filler == FILLER_DUMMY) |
| 237 | filler = FILLER_ZERO; |
| 238 | |
| 239 | mStates[i].init(filler, mSPSTx, txFullScale, rtsc); |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | return true; |
| 243 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 244 | |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 245 | /* |
| 246 | * Start the transceiver |
| 247 | * |
| 248 | * Submit command(s) to the radio device to commence streaming samples and |
| 249 | * launch threads to handle sample I/O. Re-synchronize the transmit burst |
| 250 | * counters to the central radio clock here as well. |
| 251 | */ |
| 252 | bool Transceiver::start() |
| 253 | { |
| 254 | ScopedLock lock(mLock); |
| 255 | |
| 256 | if (mOn) { |
| 257 | LOG(ERR) << "Transceiver already running"; |
| 258 | return false; |
| 259 | } |
| 260 | |
| 261 | LOG(NOTICE) << "Starting the transceiver"; |
| 262 | |
| 263 | GSM::Time time = mRadioInterface->getClock()->get(); |
| 264 | mTransmitDeadlineClock = time; |
| 265 | mLastClockUpdateTime = time; |
| 266 | mLatencyUpdateTime = time; |
| 267 | |
| 268 | if (!mRadioInterface->start()) { |
| 269 | LOG(ALERT) << "Device failed to start"; |
| 270 | return false; |
| 271 | } |
| 272 | |
| 273 | /* Device is running - launch I/O threads */ |
| 274 | mRxLowerLoopThread = new Thread(32768); |
| 275 | mTxLowerLoopThread = new Thread(32768); |
| 276 | mTxLowerLoopThread->start((void * (*)(void*)) |
| 277 | TxLowerLoopAdapter,(void*) this); |
| 278 | mRxLowerLoopThread->start((void * (*)(void*)) |
| 279 | RxLowerLoopAdapter,(void*) this); |
| 280 | |
| 281 | /* Launch uplink and downlink burst processing threads */ |
| 282 | for (size_t i = 0; i < mChans; i++) { |
| 283 | TransceiverChannel *chan = new TransceiverChannel(this, i); |
| 284 | mRxServiceLoopThreads[i] = new Thread(32768); |
| 285 | mRxServiceLoopThreads[i]->start((void * (*)(void*)) |
| 286 | RxUpperLoopAdapter, (void*) chan); |
| 287 | |
| 288 | chan = new TransceiverChannel(this, i); |
| 289 | mTxPriorityQueueServiceLoopThreads[i] = new Thread(32768); |
| 290 | mTxPriorityQueueServiceLoopThreads[i]->start((void * (*)(void*)) |
| 291 | TxUpperLoopAdapter, (void*) chan); |
| 292 | } |
| 293 | |
| 294 | writeClockInterface(); |
| 295 | mOn = true; |
| 296 | return true; |
| 297 | } |
| 298 | |
| 299 | /* |
| 300 | * Stop the transceiver |
| 301 | * |
| 302 | * Perform stopping by disabling receive streaming and issuing cancellation |
| 303 | * requests to running threads. Most threads will timeout and terminate once |
| 304 | * device is disabled, but the transmit loop may block waiting on the central |
| 305 | * UMTS clock. Explicitly signal the clock to make sure that the transmit loop |
| 306 | * makes it to the thread cancellation point. |
| 307 | */ |
| 308 | void Transceiver::stop() |
| 309 | { |
| 310 | ScopedLock lock(mLock); |
| 311 | |
| 312 | if (!mOn) |
| 313 | return; |
| 314 | |
| 315 | LOG(NOTICE) << "Stopping the transceiver"; |
| 316 | mTxLowerLoopThread->cancel(); |
| 317 | mRxLowerLoopThread->cancel(); |
| 318 | |
| 319 | for (size_t i = 0; i < mChans; i++) { |
| 320 | mRxServiceLoopThreads[i]->cancel(); |
| 321 | mTxPriorityQueueServiceLoopThreads[i]->cancel(); |
| 322 | } |
| 323 | |
| 324 | LOG(INFO) << "Stopping the device"; |
| 325 | mRadioInterface->stop(); |
| 326 | |
| 327 | for (size_t i = 0; i < mChans; i++) { |
| 328 | mRxServiceLoopThreads[i]->join(); |
| 329 | mTxPriorityQueueServiceLoopThreads[i]->join(); |
| 330 | delete mRxServiceLoopThreads[i]; |
| 331 | delete mTxPriorityQueueServiceLoopThreads[i]; |
| 332 | |
| 333 | mTxPriorityQueues[i].clear(); |
| 334 | } |
| 335 | |
| 336 | mTxLowerLoopThread->join(); |
| 337 | mRxLowerLoopThread->join(); |
| 338 | delete mTxLowerLoopThread; |
| 339 | delete mRxLowerLoopThread; |
| 340 | |
| 341 | mOn = false; |
| 342 | LOG(NOTICE) << "Transceiver stopped"; |
| 343 | } |
| 344 | |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame] | 345 | void Transceiver::addRadioVector(size_t chan, BitVector &bits, |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 346 | int RSSI, GSM::Time &wTime) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 347 | { |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame] | 348 | signalVector *burst; |
| 349 | radioVector *radio_burst; |
| 350 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 351 | if (chan >= mTxPriorityQueues.size()) { |
| 352 | LOG(ALERT) << "Invalid channel " << chan; |
| 353 | return; |
| 354 | } |
| 355 | |
Thomas Tsou | 2d0c00b | 2013-11-14 15:28:23 -0500 | [diff] [blame] | 356 | if (wTime.TN() > 7) { |
| 357 | LOG(ALERT) << "Received burst with invalid slot " << wTime.TN(); |
| 358 | return; |
| 359 | } |
| 360 | |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame] | 361 | burst = modulateBurst(bits, 8 + (wTime.TN() % 4 == 0), mSPSTx); |
| 362 | scaleVector(*burst, txFullScale * pow(10, -RSSI / 10)); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 363 | |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame] | 364 | radio_burst = new radioVector(wTime, burst); |
| 365 | |
| 366 | mTxPriorityQueues[chan].write(radio_burst); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 369 | void Transceiver::updateFillerTable(size_t chan, radioVector *burst) |
| 370 | { |
| 371 | int TN, modFN; |
| 372 | TransceiverState *state = &mStates[chan]; |
| 373 | |
| 374 | TN = burst->getTime().TN(); |
| 375 | modFN = burst->getTime().FN() % state->fillerModulus[TN]; |
| 376 | |
| 377 | delete state->fillerTable[modFN][TN]; |
| 378 | state->fillerTable[modFN][TN] = burst->getVector(); |
| 379 | burst->setVector(NULL); |
| 380 | } |
| 381 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 382 | void Transceiver::pushRadioVector(GSM::Time &nowTime) |
| 383 | { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 384 | int TN, modFN; |
| 385 | radioVector *burst; |
| 386 | TransceiverState *state; |
| 387 | std::vector<signalVector *> bursts(mChans); |
| 388 | std::vector<bool> zeros(mChans); |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 389 | std::vector<bool> filler(mChans, true); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 390 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 391 | for (size_t i = 0; i < mChans; i ++) { |
| 392 | state = &mStates[i]; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 393 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 394 | while ((burst = mTxPriorityQueues[i].getStaleBurst(nowTime))) { |
| 395 | LOG(NOTICE) << "dumping STALE burst in TRX->USRP interface"; |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 396 | if (state->mRetrans) |
| 397 | updateFillerTable(i, burst); |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame] | 398 | delete burst; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | TN = nowTime.TN(); |
| 402 | modFN = nowTime.FN() % state->fillerModulus[TN]; |
| 403 | |
| 404 | bursts[i] = state->fillerTable[modFN][TN]; |
| 405 | zeros[i] = state->chanType[TN] == NONE; |
| 406 | |
| 407 | if ((burst = mTxPriorityQueues[i].getCurrentBurst(nowTime))) { |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame] | 408 | bursts[i] = burst->getVector(); |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 409 | |
| 410 | if (state->mRetrans) { |
| 411 | updateFillerTable(i, burst); |
| 412 | } else { |
| 413 | burst->setVector(NULL); |
| 414 | filler[i] = false; |
| 415 | } |
| 416 | |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame] | 417 | delete burst; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 418 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 421 | mRadioInterface->driveTransmitRadio(bursts, zeros); |
| 422 | |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 423 | for (size_t i = 0; i < mChans; i++) { |
| 424 | if (!filler[i]) |
| 425 | delete bursts[i]; |
| 426 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 427 | } |
| 428 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 429 | void Transceiver::setModulus(size_t timeslot, size_t chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 430 | { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 431 | TransceiverState *state = &mStates[chan]; |
| 432 | |
| 433 | switch (state->chanType[timeslot]) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 434 | case NONE: |
| 435 | case I: |
| 436 | case II: |
| 437 | case III: |
| 438 | case FILL: |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 439 | state->fillerModulus[timeslot] = 26; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 440 | break; |
| 441 | case IV: |
| 442 | case VI: |
| 443 | case V: |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 444 | state->fillerModulus[timeslot] = 51; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 445 | break; |
| 446 | //case V: |
| 447 | case VII: |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 448 | state->fillerModulus[timeslot] = 102; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 449 | break; |
ttsou | fc40a84 | 2013-06-09 22:38:18 +0000 | [diff] [blame] | 450 | case XIII: |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 451 | state->fillerModulus[timeslot] = 52; |
ttsou | fc40a84 | 2013-06-09 22:38:18 +0000 | [diff] [blame] | 452 | break; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 453 | default: |
| 454 | break; |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 459 | Transceiver::CorrType Transceiver::expectedCorrType(GSM::Time currTime, |
| 460 | size_t chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 461 | { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 462 | TransceiverState *state = &mStates[chan]; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 463 | unsigned burstTN = currTime.TN(); |
| 464 | unsigned burstFN = currTime.FN(); |
| 465 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 466 | switch (state->chanType[burstTN]) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 467 | case NONE: |
| 468 | return OFF; |
| 469 | break; |
| 470 | case FILL: |
| 471 | return IDLE; |
| 472 | break; |
| 473 | case I: |
| 474 | return TSC; |
| 475 | /*if (burstFN % 26 == 25) |
| 476 | return IDLE; |
| 477 | else |
| 478 | return TSC;*/ |
| 479 | break; |
| 480 | case II: |
ttsou | 2064297 | 2013-03-27 22:00:25 +0000 | [diff] [blame] | 481 | return TSC; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 482 | break; |
| 483 | case III: |
| 484 | return TSC; |
| 485 | break; |
| 486 | case IV: |
| 487 | case VI: |
| 488 | return RACH; |
| 489 | break; |
| 490 | case V: { |
| 491 | int mod51 = burstFN % 51; |
| 492 | if ((mod51 <= 36) && (mod51 >= 14)) |
| 493 | return RACH; |
| 494 | else if ((mod51 == 4) || (mod51 == 5)) |
| 495 | return RACH; |
| 496 | else if ((mod51 == 45) || (mod51 == 46)) |
| 497 | return RACH; |
| 498 | else |
| 499 | return TSC; |
| 500 | break; |
| 501 | } |
| 502 | case VII: |
| 503 | if ((burstFN % 51 <= 14) && (burstFN % 51 >= 12)) |
| 504 | return IDLE; |
| 505 | else |
| 506 | return TSC; |
| 507 | break; |
ttsou | fc40a84 | 2013-06-09 22:38:18 +0000 | [diff] [blame] | 508 | case XIII: { |
| 509 | int mod52 = burstFN % 52; |
| 510 | if ((mod52 == 12) || (mod52 == 38)) |
| 511 | return RACH; |
| 512 | else if ((mod52 == 25) || (mod52 == 51)) |
| 513 | return IDLE; |
| 514 | else |
| 515 | return TSC; |
| 516 | break; |
| 517 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 518 | case LOOPBACK: |
| 519 | if ((burstFN % 51 <= 50) && (burstFN % 51 >=48)) |
| 520 | return IDLE; |
| 521 | else |
| 522 | return TSC; |
| 523 | break; |
| 524 | default: |
| 525 | return OFF; |
| 526 | break; |
| 527 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 528 | } |
Thomas Tsou | fa3a787 | 2013-10-17 21:23:34 -0400 | [diff] [blame] | 529 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 530 | /* |
| 531 | * Detect RACH synchronization sequence within a burst. No equalization |
| 532 | * is used or available on the RACH channel. |
| 533 | */ |
| 534 | bool Transceiver::detectRACH(TransceiverState *state, |
| 535 | signalVector &burst, |
| 536 | complex &, float &toa) |
| 537 | { |
| 538 | float threshold = 6.0; |
| 539 | |
| 540 | return detectRACHBurst(burst, threshold, mSPSRx, &, &toa); |
| 541 | } |
| 542 | |
| 543 | /* |
| 544 | * Detect normal burst training sequence midamble. Update equalization |
| 545 | * state information and channel estimate if necessary. Equalization |
| 546 | * is currently disabled. |
| 547 | */ |
Thomas Tsou | a0179e3 | 2013-11-14 15:52:04 -0500 | [diff] [blame] | 548 | bool Transceiver::detectTSC(TransceiverState *state, signalVector &burst, |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 549 | complex &, float &toa, GSM::Time &time) |
| 550 | { |
| 551 | int tn = time.TN(); |
| 552 | float chanOffset, threshold = 5.0; |
Thomas Tsou | a0179e3 | 2013-11-14 15:52:04 -0500 | [diff] [blame] | 553 | bool noise, needDFE = false, estimateChan = false; |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 554 | double elapsed = time - state->chanEstimateTime[tn]; |
| 555 | signalVector *chanResp; |
| 556 | |
| 557 | /* Check equalization update state */ |
Thomas Tsou | fb827d0 | 2013-11-16 16:14:12 -0500 | [diff] [blame] | 558 | if (needDFE && ((elapsed > 50) || (!state->chanResponse[tn]))) { |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 559 | delete state->DFEForward[tn]; |
| 560 | delete state->DFEFeedback[tn]; |
| 561 | state->DFEForward[tn] = NULL; |
| 562 | state->DFEFeedback[tn] = NULL; |
| 563 | |
| 564 | estimateChan = true; |
| 565 | } |
| 566 | |
| 567 | /* Detect normal burst midambles */ |
| 568 | if (!analyzeTrafficBurst(burst, mTSC, threshold, mSPSRx, &, |
| 569 | &toa, mMaxExpectedDelay, estimateChan, |
| 570 | &chanResp, &chanOffset)) { |
| 571 | return false; |
| 572 | } |
| 573 | |
Thomas Tsou | a0179e3 | 2013-11-14 15:52:04 -0500 | [diff] [blame] | 574 | noise = state->mNoiseLev; |
| 575 | state->SNRestimate[tn] = amp.norm2() / (noise * noise + 1.0); |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 576 | |
| 577 | /* Set equalizer if unabled */ |
| 578 | if (needDFE && estimateChan) { |
| 579 | state->chanResponse[tn] = chanResp; |
| 580 | state->chanRespOffset[tn] = chanOffset; |
| 581 | state->chanRespAmplitude[tn] = amp; |
| 582 | |
| 583 | scaleVector(*chanResp, complex(1.0, 0.0) / amp); |
| 584 | |
| 585 | designDFE(*chanResp, state->SNRestimate[tn], |
| 586 | 7, &state->DFEForward[tn], &state->DFEFeedback[tn]); |
| 587 | |
| 588 | state->chanEstimateTime[tn] = time; |
| 589 | } |
| 590 | |
| 591 | return true;; |
| 592 | } |
| 593 | |
| 594 | /* |
| 595 | * Demodulate GMSK burst using equalization if requested. Otherwise |
| 596 | * demodulate by direct rotation and soft slicing. |
| 597 | */ |
| 598 | SoftVector *Transceiver::demodulate(TransceiverState *state, |
| 599 | signalVector &burst, complex amp, |
| 600 | float toa, size_t tn, bool equalize) |
| 601 | { |
| 602 | if (equalize) { |
| 603 | scaleVector(burst, complex(1.0, 0.0) / amp); |
| 604 | return equalizeBurst(burst, |
| 605 | toa - state->chanRespOffset[tn], |
| 606 | mSPSRx, |
| 607 | *state->DFEForward[tn], |
| 608 | *state->DFEFeedback[tn]); |
| 609 | } |
| 610 | |
| 611 | return demodulateBurst(burst, mSPSRx, amp, toa); |
| 612 | } |
| 613 | |
| 614 | /* |
| 615 | * Pull bursts from the FIFO and handle according to the slot |
| 616 | * and burst correlation type. Equalzation is currently disabled. |
| 617 | */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 618 | SoftVector *Transceiver::pullRadioVector(GSM::Time &wTime, int &RSSI, |
| 619 | int &timingOffset, size_t chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 620 | { |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 621 | bool success, equalize = false; |
| 622 | complex amp; |
| 623 | float toa, pow, max = -1.0, avg = 0.0; |
Thomas Tsou | e90a42b | 2013-11-13 23:38:09 -0500 | [diff] [blame] | 624 | int max_i = -1; |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 625 | signalVector *burst; |
Thomas Tsou | ef25dba | 2013-11-14 15:31:24 -0500 | [diff] [blame] | 626 | SoftVector *bits = NULL; |
Thomas Tsou | a0179e3 | 2013-11-14 15:52:04 -0500 | [diff] [blame] | 627 | TransceiverState *state = &mStates[chan]; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 628 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 629 | /* Blocking FIFO read */ |
| 630 | radioVector *radio_burst = mReceiveFIFO[chan]->read(); |
| 631 | if (!radio_burst) |
| 632 | return NULL; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 633 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 634 | /* Set time and determine correlation type */ |
| 635 | GSM::Time time = radio_burst->getTime(); |
| 636 | CorrType type = expectedCorrType(time, chan); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 637 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 638 | if ((type == OFF) || (type == IDLE)) { |
| 639 | delete radio_burst; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 640 | return NULL; |
| 641 | } |
kurtis.heimerl | 3ed6fb7 | 2011-11-26 03:17:52 +0000 | [diff] [blame] | 642 | |
Thomas Tsou | e90a42b | 2013-11-13 23:38:09 -0500 | [diff] [blame] | 643 | /* Select the diversity channel with highest energy */ |
| 644 | for (size_t i = 0; i < radio_burst->chans(); i++) { |
| 645 | energyDetect(*radio_burst->getVector(i), 20 * mSPSRx, 0.0, &pow); |
| 646 | if (pow > max) { |
| 647 | max = pow; |
| 648 | max_i = i; |
| 649 | } |
| 650 | avg += pow; |
| 651 | } |
| 652 | |
| 653 | if (max_i < 0) { |
| 654 | LOG(ALERT) << "Received empty burst"; |
| 655 | delete radio_burst; |
| 656 | return NULL; |
| 657 | } |
| 658 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 659 | /* Average noise on diversity paths and update global levels */ |
Thomas Tsou | e90a42b | 2013-11-13 23:38:09 -0500 | [diff] [blame] | 660 | burst = radio_burst->getVector(max_i); |
Thomas Tsou | ef25dba | 2013-11-14 15:31:24 -0500 | [diff] [blame] | 661 | avg = sqrt(avg / radio_burst->chans()); |
Thomas Tsou | a0179e3 | 2013-11-14 15:52:04 -0500 | [diff] [blame] | 662 | state->mNoiseLev = state->mNoises.avg(); |
Thomas Tsou | fa3a787 | 2013-10-17 21:23:34 -0400 | [diff] [blame] | 663 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 664 | /* Detect normal or RACH bursts */ |
| 665 | if (type == TSC) |
Thomas Tsou | a0179e3 | 2013-11-14 15:52:04 -0500 | [diff] [blame] | 666 | success = detectTSC(state, *burst, amp, toa, time); |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 667 | else |
Thomas Tsou | a0179e3 | 2013-11-14 15:52:04 -0500 | [diff] [blame] | 668 | success = detectRACH(state, *burst, amp, toa); |
Thomas Tsou | f078273 | 2013-10-29 15:55:47 -0400 | [diff] [blame] | 669 | |
Tom Tsou | 577cd02 | 2015-05-18 13:57:54 -0700 | [diff] [blame] | 670 | /* Update noise average if no bust detected or alert on error */ |
| 671 | if (success <= 0) { |
| 672 | if (!success) { |
| 673 | state->mNoises.insert(avg); |
| 674 | } else if (success == -SIGERR_CLIP) { |
| 675 | LOG(ALERT) << "Clipping detected on RACH input"; |
| 676 | } else if (success < 0) { |
| 677 | LOG(ALERT) << "Unhandled RACH error"; |
| 678 | } |
| 679 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 680 | delete radio_burst; |
| 681 | return NULL; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 682 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 683 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 684 | /* Demodulate and set output info */ |
| 685 | if (equalize && (type != TSC)) |
| 686 | equalize = false; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 687 | |
Thomas Tsou | a0179e3 | 2013-11-14 15:52:04 -0500 | [diff] [blame] | 688 | if (avg - state->mNoiseLev > 0.0) |
| 689 | bits = demodulate(state, *burst, amp, toa, time.TN(), equalize); |
Thomas Tsou | ef25dba | 2013-11-14 15:31:24 -0500 | [diff] [blame] | 690 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 691 | wTime = time; |
| 692 | RSSI = (int) floor(20.0 * log10(rxFullScale / avg)); |
| 693 | timingOffset = (int) round(toa * 256.0 / mSPSRx); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 694 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 695 | delete radio_burst; |
| 696 | |
| 697 | return bits; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 698 | } |
| 699 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 700 | void Transceiver::reset() |
| 701 | { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 702 | for (size_t i = 0; i < mTxPriorityQueues.size(); i++) |
| 703 | mTxPriorityQueues[i].clear(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 707 | void Transceiver::driveControl(size_t chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 708 | { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 709 | int MAX_PACKET_LENGTH = 100; |
| 710 | |
| 711 | // check control socket |
| 712 | char buffer[MAX_PACKET_LENGTH]; |
| 713 | int msgLen = -1; |
| 714 | buffer[0] = '\0'; |
Thomas Tsou | d647ec5 | 2013-10-29 15:17:34 -0400 | [diff] [blame] | 715 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 716 | msgLen = mCtrlSockets[chan]->read(buffer); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 717 | |
| 718 | if (msgLen < 1) { |
| 719 | return; |
| 720 | } |
| 721 | |
| 722 | char cmdcheck[4]; |
| 723 | char command[MAX_PACKET_LENGTH]; |
| 724 | char response[MAX_PACKET_LENGTH]; |
| 725 | |
| 726 | sscanf(buffer,"%3s %s",cmdcheck,command); |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 727 | |
| 728 | if (!chan) |
| 729 | writeClockInterface(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 730 | |
| 731 | if (strcmp(cmdcheck,"CMD")!=0) { |
| 732 | LOG(WARNING) << "bogus message on control interface"; |
| 733 | return; |
| 734 | } |
| 735 | LOG(INFO) << "command is " << buffer; |
| 736 | |
| 737 | if (strcmp(command,"POWEROFF")==0) { |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 738 | stop(); |
| 739 | sprintf(response,"RSP POWEROFF 0"); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 740 | } |
| 741 | else if (strcmp(command,"POWERON")==0) { |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 742 | if (!start()) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 743 | sprintf(response,"RSP POWERON 1"); |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 744 | else |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 745 | sprintf(response,"RSP POWERON 0"); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 746 | } |
| 747 | else if (strcmp(command,"SETMAXDLY")==0) { |
| 748 | //set expected maximum time-of-arrival |
| 749 | int maxDelay; |
| 750 | sscanf(buffer,"%3s %s %d",cmdcheck,command,&maxDelay); |
| 751 | mMaxExpectedDelay = maxDelay; // 1 GSM symbol is approx. 1 km |
| 752 | sprintf(response,"RSP SETMAXDLY 0 %d",maxDelay); |
| 753 | } |
| 754 | else if (strcmp(command,"SETRXGAIN")==0) { |
| 755 | //set expected maximum time-of-arrival |
| 756 | int newGain; |
| 757 | sscanf(buffer,"%3s %s %d",cmdcheck,command,&newGain); |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 758 | newGain = mRadioInterface->setRxGain(newGain, chan); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 759 | sprintf(response,"RSP SETRXGAIN 0 %d",newGain); |
| 760 | } |
| 761 | else if (strcmp(command,"NOISELEV")==0) { |
| 762 | if (mOn) { |
Thomas Tsou | a0179e3 | 2013-11-14 15:52:04 -0500 | [diff] [blame] | 763 | float lev = mStates[chan].mNoiseLev; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 764 | sprintf(response,"RSP NOISELEV 0 %d", |
Thomas Tsou | a0179e3 | 2013-11-14 15:52:04 -0500 | [diff] [blame] | 765 | (int) round(20.0 * log10(rxFullScale / lev))); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 766 | } |
| 767 | else { |
| 768 | sprintf(response,"RSP NOISELEV 1 0"); |
| 769 | } |
Thomas Tsou | cb269a3 | 2013-11-15 14:15:47 -0500 | [diff] [blame] | 770 | } |
| 771 | else if (!strcmp(command, "SETPOWER")) { |
Tom Tsou | a4d1a41 | 2014-11-25 15:46:56 -0800 | [diff] [blame] | 772 | int power; |
| 773 | sscanf(buffer, "%3s %s %d", cmdcheck, command, &power); |
| 774 | power = mRadioInterface->setPowerAttenuation(power, chan); |
| 775 | mStates[chan].mPower = power; |
| 776 | sprintf(response, "RSP SETPOWER 0 %d", power); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 777 | } |
Thomas Tsou | cb269a3 | 2013-11-15 14:15:47 -0500 | [diff] [blame] | 778 | else if (!strcmp(command,"ADJPOWER")) { |
Tom Tsou | a4d1a41 | 2014-11-25 15:46:56 -0800 | [diff] [blame] | 779 | int power, step; |
| 780 | sscanf(buffer, "%3s %s %d", cmdcheck, command, &step); |
| 781 | power = mStates[chan].mPower + step; |
| 782 | power = mRadioInterface->setPowerAttenuation(power, chan); |
| 783 | mStates[chan].mPower = power; |
| 784 | sprintf(response, "RSP ADJPOWER 0 %d", power); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 785 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 786 | else if (strcmp(command,"RXTUNE")==0) { |
| 787 | // tune receiver |
| 788 | int freqKhz; |
| 789 | sscanf(buffer,"%3s %s %d",cmdcheck,command,&freqKhz); |
Thomas Tsou | 477b77c | 2013-11-15 16:13:59 -0500 | [diff] [blame] | 790 | mRxFreq = freqKhz * 1e3; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 791 | if (!mRadioInterface->tuneRx(mRxFreq, chan)) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 792 | LOG(ALERT) << "RX failed to tune"; |
| 793 | sprintf(response,"RSP RXTUNE 1 %d",freqKhz); |
| 794 | } |
| 795 | else |
| 796 | sprintf(response,"RSP RXTUNE 0 %d",freqKhz); |
| 797 | } |
| 798 | else if (strcmp(command,"TXTUNE")==0) { |
| 799 | // tune txmtr |
| 800 | int freqKhz; |
| 801 | sscanf(buffer,"%3s %s %d",cmdcheck,command,&freqKhz); |
Thomas Tsou | 477b77c | 2013-11-15 16:13:59 -0500 | [diff] [blame] | 802 | mTxFreq = freqKhz * 1e3; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 803 | if (!mRadioInterface->tuneTx(mTxFreq, chan)) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 804 | LOG(ALERT) << "TX failed to tune"; |
| 805 | sprintf(response,"RSP TXTUNE 1 %d",freqKhz); |
| 806 | } |
| 807 | else |
| 808 | sprintf(response,"RSP TXTUNE 0 %d",freqKhz); |
| 809 | } |
Thomas Tsou | d3fccea | 2013-11-15 14:22:53 -0500 | [diff] [blame] | 810 | else if (!strcmp(command,"SETTSC")) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 811 | // set TSC |
Thomas Tsou | 3f32ab5 | 2013-11-15 16:32:54 -0500 | [diff] [blame] | 812 | unsigned TSC; |
Thomas Tsou | d3fccea | 2013-11-15 14:22:53 -0500 | [diff] [blame] | 813 | sscanf(buffer, "%3s %s %d", cmdcheck, command, &TSC); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 814 | if (mOn) |
Thomas Tsou | d3fccea | 2013-11-15 14:22:53 -0500 | [diff] [blame] | 815 | sprintf(response, "RSP SETTSC 1 %d", TSC); |
| 816 | else if (chan && (TSC != mTSC)) |
| 817 | sprintf(response, "RSP SETTSC 1 %d", TSC); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 818 | else { |
| 819 | mTSC = TSC; |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 820 | generateMidamble(mSPSRx, TSC); |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 821 | sprintf(response,"RSP SETTSC 0 %d", TSC); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 822 | } |
| 823 | } |
| 824 | else if (strcmp(command,"SETSLOT")==0) { |
| 825 | // set TSC |
| 826 | int corrCode; |
| 827 | int timeslot; |
| 828 | sscanf(buffer,"%3s %s %d %d",cmdcheck,command,×lot,&corrCode); |
| 829 | if ((timeslot < 0) || (timeslot > 7)) { |
| 830 | LOG(WARNING) << "bogus message on control interface"; |
| 831 | sprintf(response,"RSP SETSLOT 1 %d %d",timeslot,corrCode); |
| 832 | return; |
| 833 | } |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 834 | mStates[chan].chanType[timeslot] = (ChannelCombination) corrCode; |
| 835 | setModulus(timeslot, chan); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 836 | sprintf(response,"RSP SETSLOT 0 %d %d",timeslot,corrCode); |
| 837 | |
| 838 | } |
| 839 | else { |
| 840 | LOG(WARNING) << "bogus command " << command << " on control interface."; |
| 841 | } |
| 842 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 843 | mCtrlSockets[chan]->write(response, strlen(response) + 1); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 844 | } |
| 845 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 846 | bool Transceiver::driveTxPriorityQueue(size_t chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 847 | { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 848 | char buffer[gSlotLen+50]; |
| 849 | |
| 850 | // check data socket |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 851 | size_t msgLen = mDataSockets[chan]->read(buffer); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 852 | |
| 853 | if (msgLen!=gSlotLen+1+4+1) { |
| 854 | LOG(ERR) << "badly formatted packet on GSM->TRX interface"; |
| 855 | return false; |
| 856 | } |
| 857 | |
| 858 | int timeSlot = (int) buffer[0]; |
| 859 | uint64_t frameNum = 0; |
| 860 | for (int i = 0; i < 4; i++) |
| 861 | frameNum = (frameNum << 8) | (0x0ff & buffer[i+1]); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 862 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 863 | // periodically update GSM core clock |
| 864 | LOG(DEBUG) << "mTransmitDeadlineClock " << mTransmitDeadlineClock |
| 865 | << " mLastClockUpdateTime " << mLastClockUpdateTime; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 866 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 867 | if (!chan) { |
| 868 | if (mTransmitDeadlineClock > mLastClockUpdateTime + GSM::Time(216,0)) |
| 869 | writeClockInterface(); |
| 870 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 871 | |
| 872 | LOG(DEBUG) << "rcvd. burst at: " << GSM::Time(frameNum,timeSlot); |
| 873 | |
| 874 | int RSSI = (int) buffer[5]; |
| 875 | static BitVector newBurst(gSlotLen); |
| 876 | BitVector::iterator itr = newBurst.begin(); |
| 877 | char *bufferItr = buffer+6; |
| 878 | while (itr < newBurst.end()) |
| 879 | *itr++ = *bufferItr++; |
| 880 | |
| 881 | GSM::Time currTime = GSM::Time(frameNum,timeSlot); |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 882 | |
| 883 | addRadioVector(chan, newBurst, RSSI, currTime); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 884 | |
| 885 | return true; |
| 886 | |
| 887 | |
| 888 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 889 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 890 | void Transceiver::driveReceiveRadio() |
| 891 | { |
| 892 | if (!mRadioInterface->driveReceiveRadio()) |
| 893 | usleep(100000); |
| 894 | } |
| 895 | |
| 896 | void Transceiver::driveReceiveFIFO(size_t chan) |
| 897 | { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 898 | SoftVector *rxBurst = NULL; |
| 899 | int RSSI; |
| 900 | int TOA; // in 1/256 of a symbol |
| 901 | GSM::Time burstTime; |
| 902 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 903 | rxBurst = pullRadioVector(burstTime, RSSI, TOA, chan); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 904 | |
| 905 | if (rxBurst) { |
| 906 | |
| 907 | LOG(DEBUG) << "burst parameters: " |
| 908 | << " time: " << burstTime |
| 909 | << " RSSI: " << RSSI |
| 910 | << " TOA: " << TOA |
| 911 | << " bits: " << *rxBurst; |
| 912 | |
| 913 | char burstString[gSlotLen+10]; |
| 914 | burstString[0] = burstTime.TN(); |
| 915 | for (int i = 0; i < 4; i++) |
| 916 | burstString[1+i] = (burstTime.FN() >> ((3-i)*8)) & 0x0ff; |
| 917 | burstString[5] = RSSI; |
| 918 | burstString[6] = (TOA >> 8) & 0x0ff; |
| 919 | burstString[7] = TOA & 0x0ff; |
| 920 | SoftVector::iterator burstItr = rxBurst->begin(); |
| 921 | |
| 922 | for (unsigned int i = 0; i < gSlotLen; i++) { |
| 923 | burstString[8+i] =(char) round((*burstItr++)*255.0); |
| 924 | } |
| 925 | burstString[gSlotLen+9] = '\0'; |
| 926 | delete rxBurst; |
| 927 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 928 | mDataSockets[chan]->write(burstString,gSlotLen+10); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 929 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 930 | } |
| 931 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 932 | void Transceiver::driveTxFIFO() |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 933 | { |
| 934 | |
| 935 | /** |
| 936 | Features a carefully controlled latency mechanism, to |
| 937 | assure that transmit packets arrive at the radio/USRP |
| 938 | before they need to be transmitted. |
| 939 | |
| 940 | Deadline clock indicates the burst that needs to be |
| 941 | pushed into the FIFO right NOW. If transmit queue does |
| 942 | not have a burst, stick in filler data. |
| 943 | */ |
| 944 | |
| 945 | |
| 946 | RadioClock *radioClock = (mRadioInterface->getClock()); |
| 947 | |
| 948 | if (mOn) { |
| 949 | //radioClock->wait(); // wait until clock updates |
| 950 | LOG(DEBUG) << "radio clock " << radioClock->get(); |
| 951 | while (radioClock->get() + mTransmitLatency > mTransmitDeadlineClock) { |
| 952 | // if underrun, then we're not providing bursts to radio/USRP fast |
| 953 | // enough. Need to increase latency by one GSM frame. |
Thomas Tsou | 02d88d1 | 2013-04-05 15:36:30 -0400 | [diff] [blame] | 954 | if (mRadioInterface->getWindowType() == RadioDevice::TX_WINDOW_USRP1) { |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 955 | if (mRadioInterface->isUnderrun()) { |
ttsou | 2173abf | 2012-08-08 00:51:31 +0000 | [diff] [blame] | 956 | // only update latency at the defined frame interval |
| 957 | if (radioClock->get() > mLatencyUpdateTime + GSM::Time(USB_LATENCY_INTRVL)) { |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 958 | mTransmitLatency = mTransmitLatency + GSM::Time(1,0); |
| 959 | LOG(INFO) << "new latency: " << mTransmitLatency; |
| 960 | mLatencyUpdateTime = radioClock->get(); |
| 961 | } |
| 962 | } |
| 963 | else { |
| 964 | // if underrun hasn't occurred in the last sec (216 frames) drop |
| 965 | // transmit latency by a timeslot |
ttsou | 2173abf | 2012-08-08 00:51:31 +0000 | [diff] [blame] | 966 | if (mTransmitLatency > GSM::Time(USB_LATENCY_MIN)) { |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 967 | if (radioClock->get() > mLatencyUpdateTime + GSM::Time(216,0)) { |
| 968 | mTransmitLatency.decTN(); |
| 969 | LOG(INFO) << "reduced latency: " << mTransmitLatency; |
| 970 | mLatencyUpdateTime = radioClock->get(); |
| 971 | } |
| 972 | } |
| 973 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 974 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 975 | // time to push burst to transmit FIFO |
| 976 | pushRadioVector(mTransmitDeadlineClock); |
| 977 | mTransmitDeadlineClock.incTN(); |
| 978 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 979 | } |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 980 | |
| 981 | radioClock->wait(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | |
| 985 | |
| 986 | void Transceiver::writeClockInterface() |
| 987 | { |
| 988 | char command[50]; |
| 989 | // FIXME -- This should be adaptive. |
| 990 | sprintf(command,"IND CLOCK %llu",(unsigned long long) (mTransmitDeadlineClock.FN()+2)); |
| 991 | |
| 992 | LOG(INFO) << "ClockInterface: sending " << command; |
| 993 | |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 994 | mClockSocket.write(command, strlen(command) + 1); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 995 | |
| 996 | mLastClockUpdateTime = mTransmitDeadlineClock; |
| 997 | |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 998 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 999 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1000 | void *RxUpperLoopAdapter(TransceiverChannel *chan) |
| 1001 | { |
| 1002 | Transceiver *trx = chan->trx; |
| 1003 | size_t num = chan->num; |
| 1004 | |
| 1005 | delete chan; |
| 1006 | |
Thomas Tsou | 7553aa9 | 2013-11-08 12:50:03 -0500 | [diff] [blame] | 1007 | trx->setPriority(0.42); |
| 1008 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1009 | while (1) { |
| 1010 | trx->driveReceiveFIFO(num); |
| 1011 | pthread_testcancel(); |
| 1012 | } |
| 1013 | return NULL; |
| 1014 | } |
| 1015 | |
| 1016 | void *RxLowerLoopAdapter(Transceiver *transceiver) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1017 | { |
Thomas Tsou | 7553aa9 | 2013-11-08 12:50:03 -0500 | [diff] [blame] | 1018 | transceiver->setPriority(0.45); |
kurtis.heimerl | 6b495a5 | 2011-11-26 03:17:21 +0000 | [diff] [blame] | 1019 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1020 | while (1) { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1021 | transceiver->driveReceiveRadio(); |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 1022 | pthread_testcancel(); |
| 1023 | } |
| 1024 | return NULL; |
| 1025 | } |
| 1026 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1027 | void *TxLowerLoopAdapter(Transceiver *transceiver) |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 1028 | { |
Thomas Tsou | 7553aa9 | 2013-11-08 12:50:03 -0500 | [diff] [blame] | 1029 | transceiver->setPriority(0.44); |
| 1030 | |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 1031 | while (1) { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1032 | transceiver->driveTxFIFO(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1033 | pthread_testcancel(); |
| 1034 | } |
| 1035 | return NULL; |
| 1036 | } |
| 1037 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1038 | void *ControlServiceLoopAdapter(TransceiverChannel *chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1039 | { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1040 | Transceiver *trx = chan->trx; |
| 1041 | size_t num = chan->num; |
| 1042 | |
| 1043 | delete chan; |
| 1044 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1045 | while (1) { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1046 | trx->driveControl(num); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1047 | pthread_testcancel(); |
| 1048 | } |
| 1049 | return NULL; |
| 1050 | } |
| 1051 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1052 | void *TxUpperLoopAdapter(TransceiverChannel *chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1053 | { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1054 | Transceiver *trx = chan->trx; |
| 1055 | size_t num = chan->num; |
| 1056 | |
| 1057 | delete chan; |
| 1058 | |
Thomas Tsou | a4cf48c | 2013-11-09 21:44:26 -0500 | [diff] [blame] | 1059 | trx->setPriority(0.40); |
| 1060 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1061 | while (1) { |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 1062 | trx->driveTxPriorityQueue(num); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1063 | pthread_testcancel(); |
| 1064 | } |
| 1065 | return NULL; |
| 1066 | } |