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