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> |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 25 | #include <iomanip> // std::setprecision |
Alexander Chemeris | e692ce9 | 2015-06-12 00:15:31 -0400 | [diff] [blame] | 26 | #include <fstream> |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 27 | #include "Transceiver.h" |
| 28 | #include <Logger.h> |
| 29 | |
Pau Espin Pedrol | db936b9 | 2018-09-03 16:50:49 +0200 | [diff] [blame] | 30 | extern "C" { |
| 31 | #include "osmo_signal.h" |
| 32 | } |
| 33 | |
ttsou | 2173abf | 2012-08-08 00:51:31 +0000 | [diff] [blame] | 34 | #ifdef HAVE_CONFIG_H |
| 35 | #include "config.h" |
| 36 | #endif |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 37 | |
Alexander Chemeris | d734e2d | 2013-06-16 14:30:58 +0400 | [diff] [blame] | 38 | using namespace GSM; |
| 39 | |
kurtis.heimerl | ec842de | 2012-11-23 08:37:32 +0000 | [diff] [blame] | 40 | #define USB_LATENCY_INTRVL 10,0 |
ttsou | 2173abf | 2012-08-08 00:51:31 +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 | |
Pau Espin Pedrol | efac20b | 2018-02-21 14:59:19 +0100 | [diff] [blame] | 72 | bool TransceiverState::init(FillerType filler, size_t sps, float scale, size_t rtsc, unsigned rach_delay) |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 73 | { |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 74 | signalVector *burst; |
| 75 | |
| 76 | if ((sps != 1) && (sps != 4)) |
| 77 | return false; |
| 78 | |
| 79 | for (size_t n = 0; n < 8; n++) { |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 80 | for (size_t i = 0; i < 102; i++) { |
| 81 | switch (filler) { |
Pau Espin Pedrol | efac20b | 2018-02-21 14:59:19 +0100 | [diff] [blame] | 82 | case FILLER_DUMMY: |
Tom Tsou | 8ee2f38 | 2016-03-06 20:57:34 -0800 | [diff] [blame] | 83 | burst = generateDummyBurst(sps, n); |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 84 | break; |
Pau Espin Pedrol | efac20b | 2018-02-21 14:59:19 +0100 | [diff] [blame] | 85 | case FILLER_NORM_RAND: |
Tom Tsou | 8ee2f38 | 2016-03-06 20:57:34 -0800 | [diff] [blame] | 86 | burst = genRandNormalBurst(rtsc, sps, n); |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 87 | break; |
Pau Espin Pedrol | efac20b | 2018-02-21 14:59:19 +0100 | [diff] [blame] | 88 | case FILLER_EDGE_RAND: |
Tom Tsou | af717b2 | 2016-03-06 22:19:15 -0800 | [diff] [blame] | 89 | burst = generateEdgeBurst(rtsc); |
| 90 | break; |
Pau Espin Pedrol | efac20b | 2018-02-21 14:59:19 +0100 | [diff] [blame] | 91 | case FILLER_ACCESS_RAND: |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 92 | burst = genRandAccessBurst(rach_delay, sps, n); |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 93 | break; |
Pau Espin Pedrol | efac20b | 2018-02-21 14:59:19 +0100 | [diff] [blame] | 94 | case FILLER_ZERO: |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 95 | default: |
Tom Tsou | 8ee2f38 | 2016-03-06 20:57:34 -0800 | [diff] [blame] | 96 | burst = generateEmptyBurst(sps, n); |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | scaleVector(*burst, scale); |
| 100 | fillerTable[i][n] = burst; |
| 101 | } |
| 102 | |
Pau Espin Pedrol | efac20b | 2018-02-21 14:59:19 +0100 | [diff] [blame] | 103 | if ((filler == FILLER_NORM_RAND) || |
| 104 | (filler == FILLER_EDGE_RAND)) { |
Alexander Chemeris | f9e78be | 2017-03-17 15:00:34 -0700 | [diff] [blame] | 105 | chanType[n] = TSC; |
Tom Tsou | af717b2 | 2016-03-06 22:19:15 -0800 | [diff] [blame] | 106 | } |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 107 | } |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 108 | |
| 109 | return false; |
Thomas Tsou | f078273 | 2013-10-29 15:55:47 -0400 | [diff] [blame] | 110 | } |
| 111 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 112 | Transceiver::Transceiver(int wBasePort, |
Pau Espin Pedrol | 8c80095 | 2017-08-16 16:53:23 +0200 | [diff] [blame] | 113 | const char *TRXAddress, |
| 114 | const char *GSMcoreAddress, |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 115 | size_t tx_sps, size_t rx_sps, size_t chans, |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 116 | GSM::Time wTransmitLatency, |
| 117 | RadioInterface *wRadioInterface, |
| 118 | double wRssiOffset) |
Pau Espin Pedrol | 8c80095 | 2017-08-16 16:53:23 +0200 | [diff] [blame] | 119 | : mBasePort(wBasePort), mLocalAddr(TRXAddress), mRemoteAddr(GSMcoreAddress), |
| 120 | mClockSocket(TRXAddress, wBasePort, GSMcoreAddress, wBasePort + 100), |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 121 | mTransmitLatency(wTransmitLatency), mRadioInterface(wRadioInterface), |
Pau Espin Pedrol | db936b9 | 2018-09-03 16:50:49 +0200 | [diff] [blame] | 122 | rssiOffset(wRssiOffset), sig_cbfn(NULL), |
Pau Espin Pedrol | 934da48 | 2017-07-04 16:25:20 +0200 | [diff] [blame] | 123 | mSPSTx(tx_sps), mSPSRx(rx_sps), mChans(chans), mEdge(false), mOn(false), mForceClockInterface(false), |
Alexander Chemeris | 78d1fc9 | 2016-03-19 21:16:22 +0300 | [diff] [blame] | 124 | mTxFreq(0.0), mRxFreq(0.0), mTSC(0), mMaxExpectedDelayAB(0), mMaxExpectedDelayNB(0), |
| 125 | mWriteBurstToDiskMask(0) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 126 | { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 127 | txFullScale = mRadioInterface->fullScaleInputValue(); |
| 128 | rxFullScale = mRadioInterface->fullScaleOutputValue(); |
Alexander Chemeris | 5a06806 | 2015-06-20 01:38:47 +0300 | [diff] [blame] | 129 | |
| 130 | for (int i = 0; i < 8; i++) { |
| 131 | for (int j = 0; j < 8; j++) |
| 132 | mHandover[i][j] = false; |
| 133 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | Transceiver::~Transceiver() |
| 137 | { |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 138 | stop(); |
| 139 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 140 | sigProcLibDestroy(); |
Thomas Tsou | d647ec5 | 2013-10-29 15:17:34 -0400 | [diff] [blame] | 141 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 142 | for (size_t i = 0; i < mChans; i++) { |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 143 | mControlServiceLoopThreads[i]->cancel(); |
| 144 | mControlServiceLoopThreads[i]->join(); |
| 145 | delete mControlServiceLoopThreads[i]; |
| 146 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 147 | mTxPriorityQueues[i].clear(); |
| 148 | delete mCtrlSockets[i]; |
| 149 | delete mDataSockets[i]; |
| 150 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 151 | } |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 152 | |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 153 | /* |
| 154 | * Initialize transceiver |
| 155 | * |
| 156 | * Start or restart the control loop. Any further control is handled through the |
| 157 | * socket API. Randomize the central radio clock set the downlink burst |
| 158 | * counters. Note that the clock will not update until the radio starts, but we |
| 159 | * are still expected to report clock indications through control channel |
| 160 | * activity. |
| 161 | */ |
Pau Espin Pedrol | efac20b | 2018-02-21 14:59:19 +0100 | [diff] [blame] | 162 | bool Transceiver::init(FillerType filler, size_t rtsc, unsigned rach_delay, bool edge) |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 163 | { |
Thomas Tsou | e1ce925 | 2013-11-13 22:40:44 -0500 | [diff] [blame] | 164 | int d_srcport, d_dstport, c_srcport, c_dstport; |
Thomas Tsou | f078273 | 2013-10-29 15:55:47 -0400 | [diff] [blame] | 165 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 166 | if (!mChans) { |
| 167 | LOG(ALERT) << "No channels assigned"; |
| 168 | return false; |
| 169 | } |
| 170 | |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 171 | if (!sigProcLibSetup()) { |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 172 | LOG(ALERT) << "Failed to initialize signal processing library"; |
| 173 | return false; |
| 174 | } |
| 175 | |
Tom Tsou | 64464e6 | 2016-07-01 03:46:46 -0700 | [diff] [blame] | 176 | mEdge = edge; |
| 177 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 178 | mDataSockets.resize(mChans); |
| 179 | mCtrlSockets.resize(mChans); |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 180 | mControlServiceLoopThreads.resize(mChans); |
| 181 | mTxPriorityQueueServiceLoopThreads.resize(mChans); |
| 182 | mRxServiceLoopThreads.resize(mChans); |
| 183 | |
| 184 | mTxPriorityQueues.resize(mChans); |
| 185 | mReceiveFIFO.resize(mChans); |
| 186 | mStates.resize(mChans); |
| 187 | |
Thomas Tsou | ccb73e1 | 2014-04-15 17:41:28 -0400 | [diff] [blame] | 188 | /* Filler table retransmissions - support only on channel 0 */ |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 189 | if (filler == FILLER_DUMMY) |
Thomas Tsou | ccb73e1 | 2014-04-15 17:41:28 -0400 | [diff] [blame] | 190 | mStates[0].mRetrans = true; |
| 191 | |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 192 | /* Setup sockets */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 193 | for (size_t i = 0; i < mChans; i++) { |
Thomas Tsou | e1ce925 | 2013-11-13 22:40:44 -0500 | [diff] [blame] | 194 | c_srcport = mBasePort + 2 * i + 1; |
| 195 | c_dstport = mBasePort + 2 * i + 101; |
| 196 | d_srcport = mBasePort + 2 * i + 2; |
| 197 | d_dstport = mBasePort + 2 * i + 102; |
| 198 | |
Pau Espin Pedrol | 8c80095 | 2017-08-16 16:53:23 +0200 | [diff] [blame] | 199 | mCtrlSockets[i] = new UDPSocket(mLocalAddr.c_str(), c_srcport, mRemoteAddr.c_str(), c_dstport); |
| 200 | mDataSockets[i] = new UDPSocket(mLocalAddr.c_str(), d_srcport, mRemoteAddr.c_str(), d_dstport); |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 201 | } |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 202 | |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 203 | /* Randomize the central clock */ |
| 204 | GSM::Time startTime(random() % gHyperframe, 0); |
| 205 | mRadioInterface->getClock()->set(startTime); |
| 206 | mTransmitDeadlineClock = startTime; |
| 207 | mLastClockUpdateTime = startTime; |
| 208 | mLatencyUpdateTime = startTime; |
| 209 | |
| 210 | /* Start control threads */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 211 | for (size_t i = 0; i < mChans; i++) { |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 212 | TransceiverChannel *chan = new TransceiverChannel(this, i); |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 213 | mControlServiceLoopThreads[i] = new Thread(32768); |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 214 | mControlServiceLoopThreads[i]->start((void * (*)(void*)) |
| 215 | ControlServiceLoopAdapter, (void*) chan); |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 216 | |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 217 | if (i && filler == FILLER_DUMMY) |
| 218 | filler = FILLER_ZERO; |
| 219 | |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 220 | mStates[i].init(filler, mSPSTx, txFullScale, rtsc, rach_delay); |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | return true; |
| 224 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 225 | |
Pau Espin Pedrol | db936b9 | 2018-09-03 16:50:49 +0200 | [diff] [blame] | 226 | void Transceiver::setSignalHandler(osmo_signal_cbfn cbfn) |
| 227 | { |
| 228 | if (this->sig_cbfn) |
| 229 | osmo_signal_unregister_handler(SS_TRANSC, this->sig_cbfn, NULL); |
| 230 | |
| 231 | if (cbfn) { |
| 232 | this->sig_cbfn = cbfn; |
| 233 | osmo_signal_register_handler(SS_TRANSC, this->sig_cbfn, NULL); |
| 234 | } |
| 235 | } |
| 236 | |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 237 | /* |
| 238 | * Start the transceiver |
| 239 | * |
| 240 | * Submit command(s) to the radio device to commence streaming samples and |
| 241 | * launch threads to handle sample I/O. Re-synchronize the transmit burst |
| 242 | * counters to the central radio clock here as well. |
| 243 | */ |
| 244 | bool Transceiver::start() |
| 245 | { |
| 246 | ScopedLock lock(mLock); |
| 247 | |
| 248 | if (mOn) { |
| 249 | LOG(ERR) << "Transceiver already running"; |
Ivan Kluchnikov | 194a9b1 | 2015-04-23 17:08:27 +0300 | [diff] [blame] | 250 | return true; |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | LOG(NOTICE) << "Starting the transceiver"; |
| 254 | |
| 255 | GSM::Time time = mRadioInterface->getClock()->get(); |
| 256 | mTransmitDeadlineClock = time; |
| 257 | mLastClockUpdateTime = time; |
| 258 | mLatencyUpdateTime = time; |
| 259 | |
| 260 | if (!mRadioInterface->start()) { |
| 261 | LOG(ALERT) << "Device failed to start"; |
| 262 | return false; |
| 263 | } |
| 264 | |
| 265 | /* Device is running - launch I/O threads */ |
| 266 | mRxLowerLoopThread = new Thread(32768); |
| 267 | mTxLowerLoopThread = new Thread(32768); |
| 268 | mTxLowerLoopThread->start((void * (*)(void*)) |
| 269 | TxLowerLoopAdapter,(void*) this); |
| 270 | mRxLowerLoopThread->start((void * (*)(void*)) |
| 271 | RxLowerLoopAdapter,(void*) this); |
| 272 | |
| 273 | /* Launch uplink and downlink burst processing threads */ |
| 274 | for (size_t i = 0; i < mChans; i++) { |
| 275 | TransceiverChannel *chan = new TransceiverChannel(this, i); |
| 276 | mRxServiceLoopThreads[i] = new Thread(32768); |
| 277 | mRxServiceLoopThreads[i]->start((void * (*)(void*)) |
| 278 | RxUpperLoopAdapter, (void*) chan); |
| 279 | |
| 280 | chan = new TransceiverChannel(this, i); |
| 281 | mTxPriorityQueueServiceLoopThreads[i] = new Thread(32768); |
| 282 | mTxPriorityQueueServiceLoopThreads[i]->start((void * (*)(void*)) |
| 283 | TxUpperLoopAdapter, (void*) chan); |
| 284 | } |
| 285 | |
Pau Espin Pedrol | 934da48 | 2017-07-04 16:25:20 +0200 | [diff] [blame] | 286 | mForceClockInterface = true; |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 287 | mOn = true; |
| 288 | return true; |
| 289 | } |
| 290 | |
| 291 | /* |
| 292 | * Stop the transceiver |
| 293 | * |
| 294 | * Perform stopping by disabling receive streaming and issuing cancellation |
| 295 | * requests to running threads. Most threads will timeout and terminate once |
| 296 | * device is disabled, but the transmit loop may block waiting on the central |
| 297 | * UMTS clock. Explicitly signal the clock to make sure that the transmit loop |
| 298 | * makes it to the thread cancellation point. |
| 299 | */ |
| 300 | void Transceiver::stop() |
| 301 | { |
| 302 | ScopedLock lock(mLock); |
| 303 | |
| 304 | if (!mOn) |
| 305 | return; |
| 306 | |
| 307 | LOG(NOTICE) << "Stopping the transceiver"; |
| 308 | mTxLowerLoopThread->cancel(); |
| 309 | mRxLowerLoopThread->cancel(); |
Tom Tsou | d67bd60 | 2017-06-15 15:35:02 -0700 | [diff] [blame] | 310 | mTxLowerLoopThread->join(); |
| 311 | mRxLowerLoopThread->join(); |
| 312 | delete mTxLowerLoopThread; |
| 313 | delete mRxLowerLoopThread; |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 314 | |
| 315 | for (size_t i = 0; i < mChans; i++) { |
| 316 | mRxServiceLoopThreads[i]->cancel(); |
| 317 | mTxPriorityQueueServiceLoopThreads[i]->cancel(); |
| 318 | } |
| 319 | |
| 320 | LOG(INFO) << "Stopping the device"; |
| 321 | mRadioInterface->stop(); |
| 322 | |
| 323 | for (size_t i = 0; i < mChans; i++) { |
| 324 | mRxServiceLoopThreads[i]->join(); |
| 325 | mTxPriorityQueueServiceLoopThreads[i]->join(); |
| 326 | delete mRxServiceLoopThreads[i]; |
| 327 | delete mTxPriorityQueueServiceLoopThreads[i]; |
| 328 | |
| 329 | mTxPriorityQueues[i].clear(); |
| 330 | } |
| 331 | |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 332 | mOn = false; |
| 333 | LOG(NOTICE) << "Transceiver stopped"; |
| 334 | } |
| 335 | |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame] | 336 | void Transceiver::addRadioVector(size_t chan, BitVector &bits, |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 337 | int RSSI, GSM::Time &wTime) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 338 | { |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame] | 339 | signalVector *burst; |
| 340 | radioVector *radio_burst; |
| 341 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 342 | if (chan >= mTxPriorityQueues.size()) { |
| 343 | LOG(ALERT) << "Invalid channel " << chan; |
| 344 | return; |
| 345 | } |
| 346 | |
Thomas Tsou | 2d0c00b | 2013-11-14 15:28:23 -0500 | [diff] [blame] | 347 | if (wTime.TN() > 7) { |
| 348 | LOG(ALERT) << "Received burst with invalid slot " << wTime.TN(); |
| 349 | return; |
| 350 | } |
| 351 | |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 352 | /* Use the number of bits as the EDGE burst indicator */ |
| 353 | if (bits.size() == EDGE_BURST_NBITS) |
| 354 | burst = modulateEdgeBurst(bits, mSPSTx); |
| 355 | else |
| 356 | burst = modulateBurst(bits, 8 + (wTime.TN() % 4 == 0), mSPSTx); |
| 357 | |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame] | 358 | scaleVector(*burst, txFullScale * pow(10, -RSSI / 10)); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 359 | |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame] | 360 | radio_burst = new radioVector(wTime, burst); |
| 361 | |
| 362 | mTxPriorityQueues[chan].write(radio_burst); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 365 | void Transceiver::updateFillerTable(size_t chan, radioVector *burst) |
| 366 | { |
| 367 | int TN, modFN; |
| 368 | TransceiverState *state = &mStates[chan]; |
| 369 | |
| 370 | TN = burst->getTime().TN(); |
| 371 | modFN = burst->getTime().FN() % state->fillerModulus[TN]; |
| 372 | |
| 373 | delete state->fillerTable[modFN][TN]; |
| 374 | state->fillerTable[modFN][TN] = burst->getVector(); |
| 375 | burst->setVector(NULL); |
| 376 | } |
| 377 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 378 | void Transceiver::pushRadioVector(GSM::Time &nowTime) |
| 379 | { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 380 | int TN, modFN; |
| 381 | radioVector *burst; |
| 382 | TransceiverState *state; |
| 383 | std::vector<signalVector *> bursts(mChans); |
| 384 | std::vector<bool> zeros(mChans); |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 385 | std::vector<bool> filler(mChans, true); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 386 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 387 | for (size_t i = 0; i < mChans; i ++) { |
| 388 | state = &mStates[i]; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 389 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 390 | while ((burst = mTxPriorityQueues[i].getStaleBurst(nowTime))) { |
Pau Espin Pedrol | f37b0ad | 2018-04-25 18:01:27 +0200 | [diff] [blame] | 391 | LOG(NOTICE) << "chan " << i << " dumping STALE burst in TRX->USRP interface (" |
| 392 | << burst->getTime() <<" vs " << nowTime << "), retrans=" << state->mRetrans; |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 393 | if (state->mRetrans) |
| 394 | updateFillerTable(i, burst); |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame] | 395 | delete burst; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | TN = nowTime.TN(); |
| 399 | modFN = nowTime.FN() % state->fillerModulus[TN]; |
| 400 | |
| 401 | bursts[i] = state->fillerTable[modFN][TN]; |
| 402 | zeros[i] = state->chanType[TN] == NONE; |
| 403 | |
| 404 | if ((burst = mTxPriorityQueues[i].getCurrentBurst(nowTime))) { |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame] | 405 | bursts[i] = burst->getVector(); |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 406 | |
| 407 | if (state->mRetrans) { |
| 408 | updateFillerTable(i, burst); |
| 409 | } else { |
| 410 | burst->setVector(NULL); |
| 411 | filler[i] = false; |
| 412 | } |
| 413 | |
Thomas Tsou | a2fe91a | 2013-11-13 22:48:11 -0500 | [diff] [blame] | 414 | delete burst; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 415 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 418 | mRadioInterface->driveTransmitRadio(bursts, zeros); |
| 419 | |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 420 | for (size_t i = 0; i < mChans; i++) { |
| 421 | if (!filler[i]) |
| 422 | delete bursts[i]; |
| 423 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 426 | void Transceiver::setModulus(size_t timeslot, size_t chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 427 | { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 428 | TransceiverState *state = &mStates[chan]; |
| 429 | |
| 430 | switch (state->chanType[timeslot]) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 431 | case NONE: |
| 432 | case I: |
| 433 | case II: |
| 434 | case III: |
| 435 | case FILL: |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 436 | state->fillerModulus[timeslot] = 26; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 437 | break; |
| 438 | case IV: |
| 439 | case VI: |
| 440 | case V: |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 441 | state->fillerModulus[timeslot] = 51; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 442 | break; |
Pau Espin Pedrol | 7c405a0 | 2017-07-04 16:24:06 +0200 | [diff] [blame] | 443 | //case V: |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 444 | case VII: |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 445 | state->fillerModulus[timeslot] = 102; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 446 | break; |
ttsou | fc40a84 | 2013-06-09 22:38:18 +0000 | [diff] [blame] | 447 | case XIII: |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 448 | state->fillerModulus[timeslot] = 52; |
ttsou | fc40a84 | 2013-06-09 22:38:18 +0000 | [diff] [blame] | 449 | break; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 450 | default: |
| 451 | break; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | |
Alexander Chemeris | f9e78be | 2017-03-17 15:00:34 -0700 | [diff] [blame] | 456 | CorrType Transceiver::expectedCorrType(GSM::Time currTime, |
| 457 | size_t chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 458 | { |
Alexander Chemeris | 5a06806 | 2015-06-20 01:38:47 +0300 | [diff] [blame] | 459 | static int tchh_subslot[26] = { 0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,1 }; |
| 460 | static int sdcch4_subslot[102] = { 3,3,3,3,0,0,2,2,2,2,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,2,2,2,2, |
| 461 | 3,3,3,3,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,2,2,2,2 }; |
| 462 | static int sdcch8_subslot[102] = { 5,5,5,5,6,6,6,6,7,7,7,7,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,0,0,0,0, |
| 463 | 1,1,1,1,2,2,2,2,3,3,3,3,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,4,4,4,4 }; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 464 | TransceiverState *state = &mStates[chan]; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 465 | unsigned burstTN = currTime.TN(); |
| 466 | unsigned burstFN = currTime.FN(); |
Alexander Chemeris | 5a06806 | 2015-06-20 01:38:47 +0300 | [diff] [blame] | 467 | int subch; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 468 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 469 | switch (state->chanType[burstTN]) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 470 | case NONE: |
| 471 | return OFF; |
| 472 | break; |
| 473 | case FILL: |
| 474 | return IDLE; |
| 475 | break; |
| 476 | case I: |
Alexander Chemeris | 5a06806 | 2015-06-20 01:38:47 +0300 | [diff] [blame] | 477 | // TODO: Are we expecting RACH on an IDLE frame? |
| 478 | /* if (burstFN % 26 == 25) |
| 479 | return IDLE;*/ |
| 480 | if (mHandover[burstTN][0]) |
| 481 | return RACH; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 482 | return TSC; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 483 | break; |
| 484 | case II: |
Alexander Chemeris | 5a06806 | 2015-06-20 01:38:47 +0300 | [diff] [blame] | 485 | subch = tchh_subslot[burstFN % 26]; |
| 486 | if (subch == 1) |
| 487 | return IDLE; |
| 488 | if (mHandover[burstTN][0]) |
| 489 | return RACH; |
ttsou | 2064297 | 2013-03-27 22:00:25 +0000 | [diff] [blame] | 490 | return TSC; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 491 | break; |
| 492 | case III: |
Alexander Chemeris | 5a06806 | 2015-06-20 01:38:47 +0300 | [diff] [blame] | 493 | subch = tchh_subslot[burstFN % 26]; |
| 494 | if (mHandover[burstTN][subch]) |
| 495 | return RACH; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 496 | return TSC; |
| 497 | break; |
| 498 | case IV: |
| 499 | case VI: |
| 500 | return RACH; |
| 501 | break; |
| 502 | case V: { |
| 503 | int mod51 = burstFN % 51; |
| 504 | if ((mod51 <= 36) && (mod51 >= 14)) |
| 505 | return RACH; |
| 506 | else if ((mod51 == 4) || (mod51 == 5)) |
| 507 | return RACH; |
| 508 | else if ((mod51 == 45) || (mod51 == 46)) |
| 509 | return RACH; |
Alexander Chemeris | 5a06806 | 2015-06-20 01:38:47 +0300 | [diff] [blame] | 510 | else if (mHandover[burstTN][sdcch4_subslot[burstFN % 102]]) |
| 511 | return RACH; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 512 | else |
| 513 | return TSC; |
| 514 | break; |
| 515 | } |
| 516 | case VII: |
| 517 | if ((burstFN % 51 <= 14) && (burstFN % 51 >= 12)) |
| 518 | return IDLE; |
Alexander Chemeris | 5a06806 | 2015-06-20 01:38:47 +0300 | [diff] [blame] | 519 | else if (mHandover[burstTN][sdcch8_subslot[burstFN % 102]]) |
| 520 | return RACH; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 521 | else |
| 522 | return TSC; |
| 523 | break; |
ttsou | fc40a84 | 2013-06-09 22:38:18 +0000 | [diff] [blame] | 524 | case XIII: { |
| 525 | int mod52 = burstFN % 52; |
| 526 | if ((mod52 == 12) || (mod52 == 38)) |
| 527 | return RACH; |
| 528 | else if ((mod52 == 25) || (mod52 == 51)) |
| 529 | return IDLE; |
| 530 | else |
| 531 | return TSC; |
| 532 | break; |
| 533 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 534 | case LOOPBACK: |
| 535 | if ((burstFN % 51 <= 50) && (burstFN % 51 >=48)) |
| 536 | return IDLE; |
| 537 | else |
| 538 | return TSC; |
| 539 | break; |
| 540 | default: |
| 541 | return OFF; |
| 542 | break; |
| 543 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 544 | } |
Thomas Tsou | fa3a787 | 2013-10-17 21:23:34 -0400 | [diff] [blame] | 545 | |
Alexander Chemeris | e692ce9 | 2015-06-12 00:15:31 -0400 | [diff] [blame] | 546 | void writeToFile(radioVector *radio_burst, size_t chan) |
| 547 | { |
| 548 | GSM::Time time = radio_burst->getTime(); |
| 549 | std::ostringstream fname; |
| 550 | fname << chan << "_" << time.FN() << "_" << time.TN() << ".fc"; |
| 551 | std::ofstream outfile (fname.str().c_str(), std::ofstream::binary); |
| 552 | outfile.write((char*)radio_burst->getVector()->begin(), radio_burst->getVector()->size() * 2 * sizeof(float)); |
| 553 | outfile.close(); |
| 554 | } |
| 555 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 556 | /* |
| 557 | * Pull bursts from the FIFO and handle according to the slot |
Pau Espin Pedrol | 7c405a0 | 2017-07-04 16:24:06 +0200 | [diff] [blame] | 558 | * and burst correlation type. Equalzation is currently disabled. |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 559 | */ |
Alexander Chemeris | 2b54210 | 2015-06-08 22:46:38 -0400 | [diff] [blame] | 560 | SoftVector *Transceiver::pullRadioVector(GSM::Time &wTime, double &RSSI, bool &isRssiValid, |
Alexander Chemeris | dbe26ab | 2015-06-04 00:14:51 -0400 | [diff] [blame] | 561 | double &timingOffset, double &noise, |
| 562 | size_t chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 563 | { |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 564 | int rc; |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 565 | complex amp; |
Alexander Chemeris | 1dd05cf | 2017-03-15 23:23:36 +0300 | [diff] [blame] | 566 | float toa, max = -1.0, avg = 0.0; |
Thomas Tsou | e90a42b | 2013-11-13 23:38:09 -0500 | [diff] [blame] | 567 | int max_i = -1; |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 568 | signalVector *burst; |
Thomas Tsou | ef25dba | 2013-11-14 15:31:24 -0500 | [diff] [blame] | 569 | SoftVector *bits = NULL; |
Thomas Tsou | a0179e3 | 2013-11-14 15:52:04 -0500 | [diff] [blame] | 570 | TransceiverState *state = &mStates[chan]; |
Alexander Chemeris | 2b54210 | 2015-06-08 22:46:38 -0400 | [diff] [blame] | 571 | isRssiValid = false; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 572 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 573 | /* Blocking FIFO read */ |
| 574 | radioVector *radio_burst = mReceiveFIFO[chan]->read(); |
| 575 | if (!radio_burst) |
| 576 | return NULL; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 577 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 578 | /* Set time and determine correlation type */ |
| 579 | GSM::Time time = radio_burst->getTime(); |
| 580 | CorrType type = expectedCorrType(time, chan); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 581 | |
Tom Tsou | 64464e6 | 2016-07-01 03:46:46 -0700 | [diff] [blame] | 582 | /* Enable 8-PSK burst detection if EDGE is enabled */ |
| 583 | if (mEdge && (type == TSC)) |
| 584 | type = EDGE; |
| 585 | |
Alexander Chemeris | e692ce9 | 2015-06-12 00:15:31 -0400 | [diff] [blame] | 586 | /* Debug: dump bursts to disk */ |
| 587 | /* bits 0-7 - chan 0 timeslots |
| 588 | * bits 8-15 - chan 1 timeslots */ |
| 589 | if (mWriteBurstToDiskMask & ((1<<time.TN()) << (8*chan))) |
| 590 | writeToFile(radio_burst, chan); |
| 591 | |
Alexander Chemeris | 2b54210 | 2015-06-08 22:46:38 -0400 | [diff] [blame] | 592 | /* No processing if the timeslot is off. |
| 593 | * Not even power level or noise calculation. */ |
| 594 | if (type == OFF) { |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 595 | delete radio_burst; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 596 | return NULL; |
| 597 | } |
kurtis.heimerl | 3ed6fb7 | 2011-11-26 03:17:52 +0000 | [diff] [blame] | 598 | |
Thomas Tsou | e90a42b | 2013-11-13 23:38:09 -0500 | [diff] [blame] | 599 | /* Select the diversity channel with highest energy */ |
| 600 | for (size_t i = 0; i < radio_burst->chans(); i++) { |
Alexander Chemeris | 1dd05cf | 2017-03-15 23:23:36 +0300 | [diff] [blame] | 601 | float pow = energyDetect(*radio_burst->getVector(i), 20 * mSPSRx); |
Thomas Tsou | e90a42b | 2013-11-13 23:38:09 -0500 | [diff] [blame] | 602 | if (pow > max) { |
| 603 | max = pow; |
| 604 | max_i = i; |
| 605 | } |
| 606 | avg += pow; |
| 607 | } |
| 608 | |
| 609 | if (max_i < 0) { |
| 610 | LOG(ALERT) << "Received empty burst"; |
| 611 | delete radio_burst; |
| 612 | return NULL; |
| 613 | } |
| 614 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 615 | /* Average noise on diversity paths and update global levels */ |
Thomas Tsou | e90a42b | 2013-11-13 23:38:09 -0500 | [diff] [blame] | 616 | burst = radio_burst->getVector(max_i); |
Thomas Tsou | ef25dba | 2013-11-14 15:31:24 -0500 | [diff] [blame] | 617 | avg = sqrt(avg / radio_burst->chans()); |
Alexander Chemeris | 2b54210 | 2015-06-08 22:46:38 -0400 | [diff] [blame] | 618 | |
| 619 | wTime = time; |
| 620 | RSSI = 20.0 * log10(rxFullScale / avg); |
| 621 | |
| 622 | /* RSSI estimation are valid */ |
| 623 | isRssiValid = true; |
| 624 | |
| 625 | if (type == IDLE) { |
| 626 | /* Update noise levels */ |
| 627 | state->mNoises.insert(avg); |
| 628 | state->mNoiseLev = state->mNoises.avg(); |
| 629 | noise = 20.0 * log10(rxFullScale / state->mNoiseLev); |
| 630 | |
| 631 | delete radio_burst; |
| 632 | return NULL; |
| 633 | } else { |
| 634 | /* Do not update noise levels */ |
| 635 | noise = 20.0 * log10(rxFullScale / state->mNoiseLev); |
| 636 | } |
Thomas Tsou | fa3a787 | 2013-10-17 21:23:34 -0400 | [diff] [blame] | 637 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 638 | /* Detect normal or RACH bursts */ |
Alexander Chemeris | 4e6c938 | 2017-03-17 15:24:18 -0700 | [diff] [blame] | 639 | rc = detectAnyBurst(*burst, mTSC, BURST_THRESH, mSPSRx, type, amp, toa, |
| 640 | (type==RACH)?mMaxExpectedDelayAB:mMaxExpectedDelayNB); |
Thomas Tsou | f078273 | 2013-10-29 15:55:47 -0400 | [diff] [blame] | 641 | |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 642 | if (rc > 0) { |
| 643 | type = (CorrType) rc; |
| 644 | } else if (rc <= 0) { |
| 645 | if (rc == -SIGERR_CLIP) { |
Alexander Chemeris | 954b118 | 2015-06-04 15:39:41 -0400 | [diff] [blame] | 646 | LOG(WARNING) << "Clipping detected on received RACH or Normal Burst"; |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 647 | } else if (rc != SIGERR_NONE) { |
Alexander Chemeris | 954b118 | 2015-06-04 15:39:41 -0400 | [diff] [blame] | 648 | LOG(WARNING) << "Unhandled RACH or Normal Burst detection error"; |
Tom Tsou | 577cd02 | 2015-05-18 13:57:54 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 651 | delete radio_burst; |
| 652 | return NULL; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 653 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 654 | |
Tom Tsou | 4609f32 | 2016-07-19 11:28:51 -0700 | [diff] [blame] | 655 | timingOffset = toa; |
Alexander Chemeris | 2b54210 | 2015-06-08 22:46:38 -0400 | [diff] [blame] | 656 | |
Alexander Chemeris | 6e1dffd | 2017-03-17 16:13:51 -0700 | [diff] [blame] | 657 | bits = demodAnyBurst(*burst, mSPSRx, amp, toa, type); |
Thomas Tsou | ef25dba | 2013-11-14 15:31:24 -0500 | [diff] [blame] | 658 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 659 | delete radio_burst; |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 660 | return bits; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 661 | } |
| 662 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 663 | void Transceiver::reset() |
| 664 | { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 665 | for (size_t i = 0; i < mTxPriorityQueues.size(); i++) |
| 666 | mTxPriorityQueues[i].clear(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 667 | } |
| 668 | |
Pau Espin Pedrol | 7c405a0 | 2017-07-04 16:24:06 +0200 | [diff] [blame] | 669 | |
Vadim Yanitskiy | bd0efb0 | 2018-03-09 02:45:07 +0700 | [diff] [blame] | 670 | #define MAX_PACKET_LENGTH 100 |
| 671 | |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 672 | /** |
| 673 | * Matches a buffer with a command. |
| 674 | * @param buf a buffer to look command in |
| 675 | * @param cmd a command to look in buffer |
| 676 | * @param params pointer to arguments, or NULL |
| 677 | * @return true if command matches, otherwise false |
| 678 | */ |
| 679 | static bool match_cmd(char *buf, |
| 680 | const char *cmd, char **params) |
| 681 | { |
| 682 | size_t cmd_len = strlen(cmd); |
| 683 | |
| 684 | /* Check a command itself */ |
| 685 | if (strncmp(buf, cmd, cmd_len)) |
| 686 | return false; |
| 687 | |
| 688 | /* A command has arguments */ |
| 689 | if (params != NULL) { |
| 690 | /* Make sure there is a space */ |
| 691 | if (buf[cmd_len] != ' ') |
| 692 | return false; |
| 693 | |
| 694 | /* Update external pointer */ |
| 695 | *params = buf + cmd_len + 1; |
| 696 | } |
| 697 | |
| 698 | return true; |
| 699 | } |
| 700 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 701 | void Transceiver::driveControl(size_t chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 702 | { |
Vadim Yanitskiy | 4d9b59c | 2018-03-09 02:54:45 +0700 | [diff] [blame] | 703 | char buffer[MAX_PACKET_LENGTH + 1]; |
| 704 | char response[MAX_PACKET_LENGTH + 1]; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 705 | char *command, *params; |
Vadim Yanitskiy | 4d9b59c | 2018-03-09 02:54:45 +0700 | [diff] [blame] | 706 | int msgLen; |
Thomas Tsou | d647ec5 | 2013-10-29 15:17:34 -0400 | [diff] [blame] | 707 | |
Vadim Yanitskiy | 4d9b59c | 2018-03-09 02:54:45 +0700 | [diff] [blame] | 708 | /* Attempt to read from control socket */ |
| 709 | msgLen = mCtrlSockets[chan]->read(buffer, MAX_PACKET_LENGTH); |
| 710 | if (msgLen < 1) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 711 | return; |
Vadim Yanitskiy | 4d9b59c | 2018-03-09 02:54:45 +0700 | [diff] [blame] | 712 | |
| 713 | /* Zero-terminate received string */ |
| 714 | buffer[msgLen] = '\0'; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 715 | |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 716 | /* Verify a command signature */ |
| 717 | if (strncmp(buffer, "CMD ", 4)) { |
Pau Espin Pedrol | 441d82a | 2018-12-04 16:37:24 +0100 | [diff] [blame] | 718 | LOGC(DTRXCTRL, WARNING) << "bogus message on control interface"; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 719 | return; |
| 720 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 721 | |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 722 | /* Set command pointer */ |
| 723 | command = buffer + 4; |
Pau Espin Pedrol | 1595dda | 2018-12-04 16:48:50 +0100 | [diff] [blame] | 724 | LOGC(DTRXCTRL, INFO) << "chan " << chan << ": command is '" << command << "'"; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 725 | |
| 726 | if (match_cmd(command, "POWEROFF", NULL)) { |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 727 | stop(); |
| 728 | sprintf(response,"RSP POWEROFF 0"); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 729 | } else if (match_cmd(command, "POWERON", NULL)) { |
Tom Tsou | 365bc38 | 2016-10-19 15:26:04 -0700 | [diff] [blame] | 730 | if (!start()) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 731 | sprintf(response,"RSP POWERON 1"); |
Tom Tsou | 365bc38 | 2016-10-19 15:26:04 -0700 | [diff] [blame] | 732 | } else { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 733 | sprintf(response,"RSP POWERON 0"); |
Alexander Chemeris | 5a06806 | 2015-06-20 01:38:47 +0300 | [diff] [blame] | 734 | for (int i = 0; i < 8; i++) { |
| 735 | for (int j = 0; j < 8; j++) |
| 736 | mHandover[i][j] = false; |
| 737 | } |
Tom Tsou | 365bc38 | 2016-10-19 15:26:04 -0700 | [diff] [blame] | 738 | } |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 739 | } else if (match_cmd(command, "HANDOVER", ¶ms)) { |
Vadim Yanitskiy | c0c6d70 | 2018-03-09 05:08:23 +0700 | [diff] [blame] | 740 | unsigned ts = 0, ss = 0; |
| 741 | sscanf(params, "%u %u", &ts, &ss); |
| 742 | if (ts > 7 || ss > 7) { |
| 743 | sprintf(response, "RSP NOHANDOVER 1 %u %u", ts, ss); |
| 744 | } else { |
| 745 | mHandover[ts][ss] = true; |
| 746 | sprintf(response, "RSP HANDOVER 0 %u %u", ts, ss); |
| 747 | } |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 748 | } else if (match_cmd(command, "NOHANDOVER", ¶ms)) { |
Vadim Yanitskiy | c0c6d70 | 2018-03-09 05:08:23 +0700 | [diff] [blame] | 749 | unsigned ts = 0, ss = 0; |
| 750 | sscanf(params, "%u %u", &ts, &ss); |
| 751 | if (ts > 7 || ss > 7) { |
| 752 | sprintf(response, "RSP NOHANDOVER 1 %u %u", ts, ss); |
| 753 | } else { |
| 754 | mHandover[ts][ss] = false; |
| 755 | sprintf(response, "RSP NOHANDOVER 0 %u %u", ts, ss); |
| 756 | } |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 757 | } else if (match_cmd(command, "SETMAXDLY", ¶ms)) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 758 | //set expected maximum time-of-arrival |
| 759 | int maxDelay; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 760 | sscanf(params, "%d", &maxDelay); |
Alexander Chemeris | 78d1fc9 | 2016-03-19 21:16:22 +0300 | [diff] [blame] | 761 | mMaxExpectedDelayAB = maxDelay; // 1 GSM symbol is approx. 1 km |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 762 | sprintf(response,"RSP SETMAXDLY 0 %d",maxDelay); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 763 | } else if (match_cmd(command, "SETMAXDLYNB", ¶ms)) { |
Alexander Chemeris | 78d1fc9 | 2016-03-19 21:16:22 +0300 | [diff] [blame] | 764 | //set expected maximum time-of-arrival |
| 765 | int maxDelay; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 766 | sscanf(params, "%d", &maxDelay); |
Alexander Chemeris | 78d1fc9 | 2016-03-19 21:16:22 +0300 | [diff] [blame] | 767 | mMaxExpectedDelayNB = maxDelay; // 1 GSM symbol is approx. 1 km |
| 768 | sprintf(response,"RSP SETMAXDLYNB 0 %d",maxDelay); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 769 | } else if (match_cmd(command, "SETRXGAIN", ¶ms)) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 770 | //set expected maximum time-of-arrival |
| 771 | int newGain; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 772 | sscanf(params, "%d", &newGain); |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 773 | newGain = mRadioInterface->setRxGain(newGain, chan); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 774 | sprintf(response,"RSP SETRXGAIN 0 %d",newGain); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 775 | } else if (match_cmd(command, "NOISELEV", NULL)) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 776 | if (mOn) { |
Thomas Tsou | a0179e3 | 2013-11-14 15:52:04 -0500 | [diff] [blame] | 777 | float lev = mStates[chan].mNoiseLev; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 778 | sprintf(response,"RSP NOISELEV 0 %d", |
Thomas Tsou | a0179e3 | 2013-11-14 15:52:04 -0500 | [diff] [blame] | 779 | (int) round(20.0 * log10(rxFullScale / lev))); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 780 | } |
| 781 | else { |
| 782 | sprintf(response,"RSP NOISELEV 1 0"); |
| 783 | } |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 784 | } else if (match_cmd(command, "SETPOWER", ¶ms)) { |
Tom Tsou | a4d1a41 | 2014-11-25 15:46:56 -0800 | [diff] [blame] | 785 | int power; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 786 | sscanf(params, "%d", &power); |
Tom Tsou | a4d1a41 | 2014-11-25 15:46:56 -0800 | [diff] [blame] | 787 | power = mRadioInterface->setPowerAttenuation(power, chan); |
| 788 | mStates[chan].mPower = power; |
| 789 | sprintf(response, "RSP SETPOWER 0 %d", power); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 790 | } else if (match_cmd(command, "ADJPOWER", ¶ms)) { |
Tom Tsou | a4d1a41 | 2014-11-25 15:46:56 -0800 | [diff] [blame] | 791 | int power, step; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 792 | sscanf(params, "%d", &step); |
Tom Tsou | a4d1a41 | 2014-11-25 15:46:56 -0800 | [diff] [blame] | 793 | power = mStates[chan].mPower + step; |
| 794 | power = mRadioInterface->setPowerAttenuation(power, chan); |
| 795 | mStates[chan].mPower = power; |
| 796 | sprintf(response, "RSP ADJPOWER 0 %d", power); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 797 | } else if (match_cmd(command, "RXTUNE", ¶ms)) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 798 | // tune receiver |
| 799 | int freqKhz; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 800 | sscanf(params, "%d", &freqKhz); |
Thomas Tsou | 477b77c | 2013-11-15 16:13:59 -0500 | [diff] [blame] | 801 | mRxFreq = freqKhz * 1e3; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 802 | if (!mRadioInterface->tuneRx(mRxFreq, chan)) { |
Pau Espin Pedrol | 441d82a | 2018-12-04 16:37:24 +0100 | [diff] [blame] | 803 | LOGC(DTRXCTRL, ALERT) << "RX failed to tune"; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 804 | sprintf(response,"RSP RXTUNE 1 %d",freqKhz); |
| 805 | } |
| 806 | else |
| 807 | sprintf(response,"RSP RXTUNE 0 %d",freqKhz); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 808 | } else if (match_cmd(command, "TXTUNE", ¶ms)) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 809 | // tune txmtr |
| 810 | int freqKhz; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 811 | sscanf(params, "%d", &freqKhz); |
Thomas Tsou | 477b77c | 2013-11-15 16:13:59 -0500 | [diff] [blame] | 812 | mTxFreq = freqKhz * 1e3; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 813 | if (!mRadioInterface->tuneTx(mTxFreq, chan)) { |
Pau Espin Pedrol | 441d82a | 2018-12-04 16:37:24 +0100 | [diff] [blame] | 814 | LOGC(DTRXCTRL, ALERT) << "TX failed to tune"; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 815 | sprintf(response,"RSP TXTUNE 1 %d",freqKhz); |
| 816 | } |
| 817 | else |
| 818 | sprintf(response,"RSP TXTUNE 0 %d",freqKhz); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 819 | } else if (match_cmd(command, "SETTSC", ¶ms)) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 820 | // set TSC |
Thomas Tsou | 3f32ab5 | 2013-11-15 16:32:54 -0500 | [diff] [blame] | 821 | unsigned TSC; |
Vadim Yanitskiy | 8c6c5d2 | 2018-03-09 05:01:21 +0700 | [diff] [blame] | 822 | sscanf(params, "%u", &TSC); |
Tom Tsou | 6031734 | 2017-03-30 19:36:41 -0700 | [diff] [blame] | 823 | if (TSC > 7) { |
Thomas Tsou | d3fccea | 2013-11-15 14:22:53 -0500 | [diff] [blame] | 824 | sprintf(response, "RSP SETTSC 1 %d", TSC); |
Tom Tsou | 6031734 | 2017-03-30 19:36:41 -0700 | [diff] [blame] | 825 | } else { |
Pau Espin Pedrol | 441d82a | 2018-12-04 16:37:24 +0100 | [diff] [blame] | 826 | LOGC(DTRXCTRL, NOTICE) << "Changing TSC from " << mTSC << " to " << TSC; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 827 | mTSC = TSC; |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 828 | sprintf(response,"RSP SETTSC 0 %d", TSC); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 829 | } |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 830 | } else if (match_cmd(command, "SETSLOT", ¶ms)) { |
Alexander Chemeris | 1fe5282 | 2015-05-20 12:02:29 -0700 | [diff] [blame] | 831 | // set slot type |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 832 | int corrCode; |
| 833 | int timeslot; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 834 | sscanf(params, "%d %d", ×lot, &corrCode); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 835 | if ((timeslot < 0) || (timeslot > 7)) { |
Pau Espin Pedrol | 441d82a | 2018-12-04 16:37:24 +0100 | [diff] [blame] | 836 | LOGC(DTRXCTRL, WARNING) << "bogus message on control interface"; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 837 | sprintf(response,"RSP SETSLOT 1 %d %d",timeslot,corrCode); |
| 838 | return; |
Pau Espin Pedrol | 7c405a0 | 2017-07-04 16:24:06 +0200 | [diff] [blame] | 839 | } |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 840 | mStates[chan].chanType[timeslot] = (ChannelCombination) corrCode; |
| 841 | setModulus(timeslot, chan); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 842 | sprintf(response,"RSP SETSLOT 0 %d %d",timeslot,corrCode); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 843 | } else if (match_cmd(command, "_SETBURSTTODISKMASK", ¶ms)) { |
Alexander Chemeris | e692ce9 | 2015-06-12 00:15:31 -0400 | [diff] [blame] | 844 | // debug command! may change or disapear without notice |
| 845 | // set a mask which bursts to dump to disk |
| 846 | int mask; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 847 | sscanf(params, "%d", &mask); |
Alexander Chemeris | e692ce9 | 2015-06-12 00:15:31 -0400 | [diff] [blame] | 848 | mWriteBurstToDiskMask = mask; |
| 849 | sprintf(response,"RSP _SETBURSTTODISKMASK 0 %d",mask); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 850 | } else { |
Pau Espin Pedrol | 441d82a | 2018-12-04 16:37:24 +0100 | [diff] [blame] | 851 | LOGC(DTRXCTRL, WARNING) << "bogus command " << command << " on control interface."; |
Alexander Chemeris | 4438a9f | 2013-04-08 00:14:08 +0200 | [diff] [blame] | 852 | sprintf(response,"RSP ERR 1"); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 853 | } |
| 854 | |
Pau Espin Pedrol | 1595dda | 2018-12-04 16:48:50 +0100 | [diff] [blame] | 855 | LOGC(DTRXCTRL, INFO) << "chan " << chan << ": response is '" << response << "'"; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 856 | mCtrlSockets[chan]->write(response, strlen(response) + 1); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 857 | } |
| 858 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 859 | bool Transceiver::driveTxPriorityQueue(size_t chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 860 | { |
Tom Tsou | e887108 | 2016-07-01 02:46:04 -0700 | [diff] [blame] | 861 | int burstLen; |
| 862 | char buffer[EDGE_BURST_NBITS + 50]; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 863 | |
| 864 | // check data socket |
Tom Tsou | 2c650a6 | 2016-04-28 21:55:17 -0700 | [diff] [blame] | 865 | size_t msgLen = mDataSockets[chan]->read(buffer, sizeof(buffer)); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 866 | |
Tom Tsou | e887108 | 2016-07-01 02:46:04 -0700 | [diff] [blame] | 867 | if (msgLen == gSlotLen + 1 + 4 + 1) { |
| 868 | burstLen = gSlotLen; |
| 869 | } else if (msgLen == EDGE_BURST_NBITS + 1 + 4 + 1) { |
| 870 | if (mSPSTx != 4) |
| 871 | return false; |
| 872 | |
| 873 | burstLen = EDGE_BURST_NBITS; |
| 874 | } else { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 875 | LOG(ERR) << "badly formatted packet on GSM->TRX interface"; |
| 876 | return false; |
| 877 | } |
| 878 | |
| 879 | int timeSlot = (int) buffer[0]; |
| 880 | uint64_t frameNum = 0; |
| 881 | for (int i = 0; i < 4; i++) |
| 882 | frameNum = (frameNum << 8) | (0x0ff & buffer[i+1]); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 883 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 884 | LOG(DEBUG) << "rcvd. burst at: " << GSM::Time(frameNum,timeSlot); |
Pau Espin Pedrol | 7c405a0 | 2017-07-04 16:24:06 +0200 | [diff] [blame] | 885 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 886 | int RSSI = (int) buffer[5]; |
Tom Tsou | 7c741ec | 2016-07-19 11:20:59 -0700 | [diff] [blame] | 887 | BitVector newBurst(burstLen); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 888 | BitVector::iterator itr = newBurst.begin(); |
| 889 | char *bufferItr = buffer+6; |
Pau Espin Pedrol | 7c405a0 | 2017-07-04 16:24:06 +0200 | [diff] [blame] | 890 | while (itr < newBurst.end()) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 891 | *itr++ = *bufferItr++; |
Pau Espin Pedrol | 7c405a0 | 2017-07-04 16:24:06 +0200 | [diff] [blame] | 892 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 893 | GSM::Time currTime = GSM::Time(frameNum,timeSlot); |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 894 | |
| 895 | addRadioVector(chan, newBurst, RSSI, currTime); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 896 | |
| 897 | return true; |
| 898 | |
| 899 | |
| 900 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 901 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 902 | void Transceiver::driveReceiveRadio() |
| 903 | { |
Pau Espin Pedrol | db936b9 | 2018-09-03 16:50:49 +0200 | [diff] [blame] | 904 | int rc = mRadioInterface->driveReceiveRadio(); |
| 905 | if (rc == 0) { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 906 | usleep(100000); |
Pau Espin Pedrol | db936b9 | 2018-09-03 16:50:49 +0200 | [diff] [blame] | 907 | } else if (rc < 0) { |
| 908 | LOG(FATAL) << "radio Interface receive failed, requesting stop."; |
| 909 | osmo_signal_dispatch(SS_TRANSC, S_TRANSC_STOP_REQUIRED, this); |
Pau Espin Pedrol | 934da48 | 2017-07-04 16:25:20 +0200 | [diff] [blame] | 910 | } else if (mForceClockInterface || mTransmitDeadlineClock > mLastClockUpdateTime + GSM::Time(216,0)) { |
| 911 | mForceClockInterface = false; |
| 912 | writeClockInterface(); |
Alexander Chemeris | 6a2bf0d | 2015-05-24 19:28:09 -0400 | [diff] [blame] | 913 | } |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 914 | } |
| 915 | |
Alexander Chemeris | 58e9591 | 2016-03-25 18:20:28 +0300 | [diff] [blame] | 916 | void Transceiver::logRxBurst(size_t chan, SoftVector *burst, GSM::Time time, double dbm, |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 917 | double rssi, double noise, double toa) |
| 918 | { |
| 919 | LOG(DEBUG) << std::fixed << std::right |
Alexander Chemeris | 58e9591 | 2016-03-25 18:20:28 +0300 | [diff] [blame] | 920 | << " chan: " << chan |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 921 | << " time: " << time |
| 922 | << " RSSI: " << std::setw(5) << std::setprecision(1) << rssi |
| 923 | << "dBFS/" << std::setw(6) << -dbm << "dBm" |
| 924 | << " noise: " << std::setw(5) << std::setprecision(1) << noise |
| 925 | << "dBFS/" << std::setw(6) << -(noise + rssiOffset) << "dBm" |
| 926 | << " TOA: " << std::setw(5) << std::setprecision(2) << toa |
| 927 | << " bits: " << *burst; |
| 928 | } |
| 929 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 930 | void Transceiver::driveReceiveFIFO(size_t chan) |
| 931 | { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 932 | SoftVector *rxBurst = NULL; |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 933 | double RSSI; // in dBFS |
| 934 | double dBm; // in dBm |
| 935 | double TOA; // in symbols |
| 936 | int TOAint; // in 1/256 symbols |
Alexander Chemeris | dbe26ab | 2015-06-04 00:14:51 -0400 | [diff] [blame] | 937 | double noise; // noise level in dBFS |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 938 | GSM::Time burstTime; |
Alexander Chemeris | 2b54210 | 2015-06-08 22:46:38 -0400 | [diff] [blame] | 939 | bool isRssiValid; // are RSSI, noise and burstTime valid |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 940 | unsigned nbits = gSlotLen; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 941 | |
Alexander Chemeris | 2b54210 | 2015-06-08 22:46:38 -0400 | [diff] [blame] | 942 | rxBurst = pullRadioVector(burstTime, RSSI, isRssiValid, TOA, noise, chan); |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 943 | if (!rxBurst) |
| 944 | return; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 945 | |
Alexander Chemeris | b61c610 | 2017-03-17 18:22:19 -0700 | [diff] [blame] | 946 | // Convert -1..+1 soft bits to 0..1 soft bits |
| 947 | vectorSlicer(rxBurst); |
| 948 | |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 949 | /* |
| 950 | * EDGE demodulator returns 444 (148 * 3) bits |
| 951 | */ |
| 952 | if (rxBurst->size() == gSlotLen * 3) |
| 953 | nbits = gSlotLen * 3; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 954 | |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 955 | dBm = RSSI + rssiOffset; |
Alexander Chemeris | 58e9591 | 2016-03-25 18:20:28 +0300 | [diff] [blame] | 956 | logRxBurst(chan, rxBurst, burstTime, dBm, RSSI, noise, TOA); |
Alexander Chemeris | dbe26ab | 2015-06-04 00:14:51 -0400 | [diff] [blame] | 957 | |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 958 | TOAint = (int) (TOA * 256.0 + 0.5); // round to closest integer |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 959 | |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 960 | char burstString[nbits + 10]; |
| 961 | burstString[0] = burstTime.TN(); |
| 962 | for (int i = 0; i < 4; i++) |
| 963 | burstString[1+i] = (burstTime.FN() >> ((3-i)*8)) & 0x0ff; |
| 964 | burstString[5] = (int)dBm; |
| 965 | burstString[6] = (TOAint >> 8) & 0x0ff; |
| 966 | burstString[7] = TOAint & 0x0ff; |
| 967 | SoftVector::iterator burstItr = rxBurst->begin(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 968 | |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 969 | for (unsigned i = 0; i < nbits; i++) |
| 970 | burstString[8 + i] = (char) round((*burstItr++) * 255.0); |
| 971 | |
| 972 | burstString[nbits + 9] = '\0'; |
| 973 | delete rxBurst; |
| 974 | |
| 975 | mDataSockets[chan]->write(burstString, nbits + 10); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 976 | } |
| 977 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 978 | void Transceiver::driveTxFIFO() |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 979 | { |
| 980 | |
| 981 | /** |
Pau Espin Pedrol | 7c405a0 | 2017-07-04 16:24:06 +0200 | [diff] [blame] | 982 | Features a carefully controlled latency mechanism, to |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 983 | assure that transmit packets arrive at the radio/USRP |
| 984 | before they need to be transmitted. |
| 985 | |
| 986 | Deadline clock indicates the burst that needs to be |
| 987 | pushed into the FIFO right NOW. If transmit queue does |
| 988 | not have a burst, stick in filler data. |
| 989 | */ |
| 990 | |
| 991 | |
| 992 | RadioClock *radioClock = (mRadioInterface->getClock()); |
Pau Espin Pedrol | 7c405a0 | 2017-07-04 16:24:06 +0200 | [diff] [blame] | 993 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 994 | if (mOn) { |
| 995 | //radioClock->wait(); // wait until clock updates |
| 996 | LOG(DEBUG) << "radio clock " << radioClock->get(); |
| 997 | while (radioClock->get() + mTransmitLatency > mTransmitDeadlineClock) { |
| 998 | // if underrun, then we're not providing bursts to radio/USRP fast |
| 999 | // enough. Need to increase latency by one GSM frame. |
Thomas Tsou | 02d88d1 | 2013-04-05 15:36:30 -0400 | [diff] [blame] | 1000 | if (mRadioInterface->getWindowType() == RadioDevice::TX_WINDOW_USRP1) { |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 1001 | if (mRadioInterface->isUnderrun()) { |
ttsou | 2173abf | 2012-08-08 00:51:31 +0000 | [diff] [blame] | 1002 | // only update latency at the defined frame interval |
| 1003 | if (radioClock->get() > mLatencyUpdateTime + GSM::Time(USB_LATENCY_INTRVL)) { |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 1004 | mTransmitLatency = mTransmitLatency + GSM::Time(1,0); |
Pau Espin Pedrol | 74bcc56 | 2018-10-02 17:30:28 +0200 | [diff] [blame] | 1005 | LOG(INFO) << "new latency: " << mTransmitLatency << " (underrun " |
| 1006 | << radioClock->get() << " vs " << mLatencyUpdateTime + GSM::Time(USB_LATENCY_INTRVL) << ")"; |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 1007 | mLatencyUpdateTime = radioClock->get(); |
| 1008 | } |
| 1009 | } |
| 1010 | else { |
| 1011 | // if underrun hasn't occurred in the last sec (216 frames) drop |
| 1012 | // transmit latency by a timeslot |
Pau Espin Pedrol | e564f0f | 2018-04-24 18:43:51 +0200 | [diff] [blame] | 1013 | if (mTransmitLatency > mRadioInterface->minLatency()) { |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 1014 | if (radioClock->get() > mLatencyUpdateTime + GSM::Time(216,0)) { |
| 1015 | mTransmitLatency.decTN(); |
| 1016 | LOG(INFO) << "reduced latency: " << mTransmitLatency; |
| 1017 | mLatencyUpdateTime = radioClock->get(); |
| 1018 | } |
| 1019 | } |
| 1020 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1021 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1022 | // time to push burst to transmit FIFO |
| 1023 | pushRadioVector(mTransmitDeadlineClock); |
| 1024 | mTransmitDeadlineClock.incTN(); |
| 1025 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1026 | } |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 1027 | |
| 1028 | radioClock->wait(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | |
| 1032 | |
| 1033 | void Transceiver::writeClockInterface() |
| 1034 | { |
| 1035 | char command[50]; |
| 1036 | // FIXME -- This should be adaptive. |
| 1037 | sprintf(command,"IND CLOCK %llu",(unsigned long long) (mTransmitDeadlineClock.FN()+2)); |
| 1038 | |
| 1039 | LOG(INFO) << "ClockInterface: sending " << command; |
| 1040 | |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 1041 | mClockSocket.write(command, strlen(command) + 1); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1042 | |
| 1043 | mLastClockUpdateTime = mTransmitDeadlineClock; |
| 1044 | |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 1045 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1046 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1047 | void *RxUpperLoopAdapter(TransceiverChannel *chan) |
| 1048 | { |
Pau Espin Pedrol | 5b60c98 | 2018-09-20 18:04:46 +0200 | [diff] [blame] | 1049 | char thread_name[16]; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1050 | Transceiver *trx = chan->trx; |
| 1051 | size_t num = chan->num; |
| 1052 | |
| 1053 | delete chan; |
| 1054 | |
Pau Espin Pedrol | 5b60c98 | 2018-09-20 18:04:46 +0200 | [diff] [blame] | 1055 | snprintf(thread_name, 16, "RxUpper%zu", num); |
| 1056 | set_selfthread_name(thread_name); |
| 1057 | |
Thomas Tsou | 7553aa9 | 2013-11-08 12:50:03 -0500 | [diff] [blame] | 1058 | trx->setPriority(0.42); |
| 1059 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1060 | while (1) { |
| 1061 | trx->driveReceiveFIFO(num); |
| 1062 | pthread_testcancel(); |
| 1063 | } |
| 1064 | return NULL; |
| 1065 | } |
| 1066 | |
| 1067 | void *RxLowerLoopAdapter(Transceiver *transceiver) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1068 | { |
Pau Espin Pedrol | 5b60c98 | 2018-09-20 18:04:46 +0200 | [diff] [blame] | 1069 | set_selfthread_name("RxLower"); |
| 1070 | |
Thomas Tsou | 7553aa9 | 2013-11-08 12:50:03 -0500 | [diff] [blame] | 1071 | transceiver->setPriority(0.45); |
kurtis.heimerl | 6b495a5 | 2011-11-26 03:17:21 +0000 | [diff] [blame] | 1072 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1073 | while (1) { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1074 | transceiver->driveReceiveRadio(); |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 1075 | pthread_testcancel(); |
| 1076 | } |
| 1077 | return NULL; |
| 1078 | } |
| 1079 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1080 | void *TxLowerLoopAdapter(Transceiver *transceiver) |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 1081 | { |
Pau Espin Pedrol | 5b60c98 | 2018-09-20 18:04:46 +0200 | [diff] [blame] | 1082 | set_selfthread_name("TxLower"); |
| 1083 | |
Thomas Tsou | 7553aa9 | 2013-11-08 12:50:03 -0500 | [diff] [blame] | 1084 | transceiver->setPriority(0.44); |
| 1085 | |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 1086 | while (1) { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1087 | transceiver->driveTxFIFO(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1088 | pthread_testcancel(); |
| 1089 | } |
| 1090 | return NULL; |
| 1091 | } |
| 1092 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1093 | void *ControlServiceLoopAdapter(TransceiverChannel *chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1094 | { |
Pau Espin Pedrol | 5b60c98 | 2018-09-20 18:04:46 +0200 | [diff] [blame] | 1095 | char thread_name[16]; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1096 | Transceiver *trx = chan->trx; |
| 1097 | size_t num = chan->num; |
| 1098 | |
| 1099 | delete chan; |
| 1100 | |
Pau Espin Pedrol | 5b60c98 | 2018-09-20 18:04:46 +0200 | [diff] [blame] | 1101 | snprintf(thread_name, 16, "CtrlService%zu", num); |
| 1102 | set_selfthread_name(thread_name); |
| 1103 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1104 | while (1) { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1105 | trx->driveControl(num); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1106 | pthread_testcancel(); |
| 1107 | } |
| 1108 | return NULL; |
| 1109 | } |
| 1110 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1111 | void *TxUpperLoopAdapter(TransceiverChannel *chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1112 | { |
Pau Espin Pedrol | 5b60c98 | 2018-09-20 18:04:46 +0200 | [diff] [blame] | 1113 | char thread_name[16]; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1114 | Transceiver *trx = chan->trx; |
| 1115 | size_t num = chan->num; |
| 1116 | |
| 1117 | delete chan; |
| 1118 | |
Pau Espin Pedrol | 5b60c98 | 2018-09-20 18:04:46 +0200 | [diff] [blame] | 1119 | snprintf(thread_name, 16, "TxUpper%zu", num); |
| 1120 | set_selfthread_name(thread_name); |
| 1121 | |
Thomas Tsou | a4cf48c | 2013-11-09 21:44:26 -0500 | [diff] [blame] | 1122 | trx->setPriority(0.40); |
| 1123 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1124 | while (1) { |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 1125 | trx->driveTxPriorityQueue(num); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1126 | pthread_testcancel(); |
| 1127 | } |
| 1128 | return NULL; |
| 1129 | } |