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; |
Thomas Tsou | a0179e3 | 2013-11-14 15:52:04 -0500 | [diff] [blame] | 561 | TransceiverState *state = &mStates[chan]; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 562 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 563 | /* Blocking FIFO read */ |
| 564 | radioVector *radio_burst = mReceiveFIFO[chan]->read(); |
| 565 | if (!radio_burst) |
Pau Espin Pedrol | ddd18a5 | 2019-06-28 17:01:16 +0200 | [diff] [blame] | 566 | return false; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 567 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 568 | /* Set time and determine correlation type */ |
Pau Espin Pedrol | ddd18a5 | 2019-06-28 17:01:16 +0200 | [diff] [blame] | 569 | bi->burstTime = radio_burst->getTime(); |
| 570 | CorrType type = expectedCorrType(bi->burstTime, chan); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 571 | |
Tom Tsou | 64464e6 | 2016-07-01 03:46:46 -0700 | [diff] [blame] | 572 | /* Enable 8-PSK burst detection if EDGE is enabled */ |
| 573 | if (mEdge && (type == TSC)) |
| 574 | type = EDGE; |
| 575 | |
Alexander Chemeris | e692ce9 | 2015-06-12 00:15:31 -0400 | [diff] [blame] | 576 | /* Debug: dump bursts to disk */ |
| 577 | /* bits 0-7 - chan 0 timeslots |
| 578 | * bits 8-15 - chan 1 timeslots */ |
Pau Espin Pedrol | ddd18a5 | 2019-06-28 17:01:16 +0200 | [diff] [blame] | 579 | if (mWriteBurstToDiskMask & ((1<<bi->burstTime.TN()) << (8*chan))) |
Alexander Chemeris | e692ce9 | 2015-06-12 00:15:31 -0400 | [diff] [blame] | 580 | writeToFile(radio_burst, chan); |
| 581 | |
Alexander Chemeris | 2b54210 | 2015-06-08 22:46:38 -0400 | [diff] [blame] | 582 | /* No processing if the timeslot is off. |
| 583 | * Not even power level or noise calculation. */ |
| 584 | if (type == OFF) { |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 585 | delete radio_burst; |
Pau Espin Pedrol | ddd18a5 | 2019-06-28 17:01:16 +0200 | [diff] [blame] | 586 | return false; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 587 | } |
kurtis.heimerl | 3ed6fb7 | 2011-11-26 03:17:52 +0000 | [diff] [blame] | 588 | |
Thomas Tsou | e90a42b | 2013-11-13 23:38:09 -0500 | [diff] [blame] | 589 | /* Select the diversity channel with highest energy */ |
| 590 | for (size_t i = 0; i < radio_burst->chans(); i++) { |
Alexander Chemeris | 1dd05cf | 2017-03-15 23:23:36 +0300 | [diff] [blame] | 591 | float pow = energyDetect(*radio_burst->getVector(i), 20 * mSPSRx); |
Thomas Tsou | e90a42b | 2013-11-13 23:38:09 -0500 | [diff] [blame] | 592 | if (pow > max) { |
| 593 | max = pow; |
| 594 | max_i = i; |
| 595 | } |
| 596 | avg += pow; |
| 597 | } |
| 598 | |
| 599 | if (max_i < 0) { |
| 600 | LOG(ALERT) << "Received empty burst"; |
| 601 | delete radio_burst; |
Pau Espin Pedrol | ddd18a5 | 2019-06-28 17:01:16 +0200 | [diff] [blame] | 602 | return false; |
Thomas Tsou | e90a42b | 2013-11-13 23:38:09 -0500 | [diff] [blame] | 603 | } |
| 604 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 605 | /* Average noise on diversity paths and update global levels */ |
Thomas Tsou | e90a42b | 2013-11-13 23:38:09 -0500 | [diff] [blame] | 606 | burst = radio_burst->getVector(max_i); |
Thomas Tsou | ef25dba | 2013-11-14 15:31:24 -0500 | [diff] [blame] | 607 | avg = sqrt(avg / radio_burst->chans()); |
Alexander Chemeris | 2b54210 | 2015-06-08 22:46:38 -0400 | [diff] [blame] | 608 | |
Pau Espin Pedrol | 607a414 | 2019-07-01 13:56:17 +0200 | [diff] [blame] | 609 | bi->rssi = 20.0 * log10(rxFullScale / avg) + rssiOffset; |
Alexander Chemeris | 2b54210 | 2015-06-08 22:46:38 -0400 | [diff] [blame] | 610 | |
Alexander Chemeris | 2b54210 | 2015-06-08 22:46:38 -0400 | [diff] [blame] | 611 | if (type == IDLE) { |
| 612 | /* Update noise levels */ |
| 613 | state->mNoises.insert(avg); |
| 614 | state->mNoiseLev = state->mNoises.avg(); |
Pau Espin Pedrol | 607a414 | 2019-07-01 13:56:17 +0200 | [diff] [blame] | 615 | bi->noise = 20.0 * log10(rxFullScale / state->mNoiseLev) + rssiOffset; |
Alexander Chemeris | 2b54210 | 2015-06-08 22:46:38 -0400 | [diff] [blame] | 616 | |
| 617 | delete radio_burst; |
Pau Espin Pedrol | ddd18a5 | 2019-06-28 17:01:16 +0200 | [diff] [blame] | 618 | return false; |
Alexander Chemeris | 2b54210 | 2015-06-08 22:46:38 -0400 | [diff] [blame] | 619 | } else { |
| 620 | /* Do not update noise levels */ |
Pau Espin Pedrol | 607a414 | 2019-07-01 13:56:17 +0200 | [diff] [blame] | 621 | bi->noise = 20.0 * log10(rxFullScale / state->mNoiseLev) + rssiOffset; |
Alexander Chemeris | 2b54210 | 2015-06-08 22:46:38 -0400 | [diff] [blame] | 622 | } |
Thomas Tsou | fa3a787 | 2013-10-17 21:23:34 -0400 | [diff] [blame] | 623 | |
Vadim Yanitskiy | a8b3565 | 2018-10-22 02:52:18 +0200 | [diff] [blame] | 624 | unsigned max_toa = (type == RACH || type == EXT_RACH) ? |
| 625 | mMaxExpectedDelayAB : mMaxExpectedDelayNB; |
| 626 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 627 | /* Detect normal or RACH bursts */ |
Vadim Yanitskiy | a8b3565 | 2018-10-22 02:52:18 +0200 | [diff] [blame] | 628 | rc = detectAnyBurst(*burst, mTSC, BURST_THRESH, mSPSRx, type, amp, toa, max_toa); |
Thomas Tsou | f078273 | 2013-10-29 15:55:47 -0400 | [diff] [blame] | 629 | |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 630 | if (rc > 0) { |
| 631 | type = (CorrType) rc; |
| 632 | } else if (rc <= 0) { |
| 633 | if (rc == -SIGERR_CLIP) { |
Alexander Chemeris | 954b118 | 2015-06-04 15:39:41 -0400 | [diff] [blame] | 634 | LOG(WARNING) << "Clipping detected on received RACH or Normal Burst"; |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 635 | } else if (rc != SIGERR_NONE) { |
Alexander Chemeris | 954b118 | 2015-06-04 15:39:41 -0400 | [diff] [blame] | 636 | LOG(WARNING) << "Unhandled RACH or Normal Burst detection error"; |
Tom Tsou | 577cd02 | 2015-05-18 13:57:54 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 639 | delete radio_burst; |
Pau Espin Pedrol | ddd18a5 | 2019-06-28 17:01:16 +0200 | [diff] [blame] | 640 | return false; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 641 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 642 | |
Pau Espin Pedrol | ddd18a5 | 2019-06-28 17:01:16 +0200 | [diff] [blame] | 643 | bi->toa = toa; |
| 644 | bi->rxBurst = demodAnyBurst(*burst, mSPSRx, amp, toa, type); |
Thomas Tsou | ef25dba | 2013-11-14 15:31:24 -0500 | [diff] [blame] | 645 | |
Pau Espin Pedrol | 0e67cf2 | 2019-07-02 14:59:47 +0200 | [diff] [blame] | 646 | /* EDGE demodulator returns 444 (gSlotLen * 3) bits */ |
| 647 | if (bi->rxBurst->size() == EDGE_BURST_NBITS) |
| 648 | bi->nbits = EDGE_BURST_NBITS; |
| 649 | else /* size() here is actually gSlotLen + 8, due to guard periods */ |
| 650 | bi->nbits = gSlotLen; |
| 651 | |
Pau Espin Pedrol | 25ae190 | 2019-07-01 16:40:44 +0200 | [diff] [blame^] | 652 | // Convert -1..+1 soft bits to 0..1 soft bits |
| 653 | vectorSlicer(bi->rxBurst); |
| 654 | |
Thomas Tsou | 30421a7 | 2013-11-13 23:14:48 -0500 | [diff] [blame] | 655 | delete radio_burst; |
Pau Espin Pedrol | ddd18a5 | 2019-06-28 17:01:16 +0200 | [diff] [blame] | 656 | return true; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 657 | } |
| 658 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 659 | void Transceiver::reset() |
| 660 | { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 661 | for (size_t i = 0; i < mTxPriorityQueues.size(); i++) |
| 662 | mTxPriorityQueues[i].clear(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 663 | } |
| 664 | |
Pau Espin Pedrol | 7c405a0 | 2017-07-04 16:24:06 +0200 | [diff] [blame] | 665 | |
Vadim Yanitskiy | bd0efb0 | 2018-03-09 02:45:07 +0700 | [diff] [blame] | 666 | #define MAX_PACKET_LENGTH 100 |
| 667 | |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 668 | /** |
| 669 | * Matches a buffer with a command. |
| 670 | * @param buf a buffer to look command in |
| 671 | * @param cmd a command to look in buffer |
| 672 | * @param params pointer to arguments, or NULL |
| 673 | * @return true if command matches, otherwise false |
| 674 | */ |
| 675 | static bool match_cmd(char *buf, |
| 676 | const char *cmd, char **params) |
| 677 | { |
| 678 | size_t cmd_len = strlen(cmd); |
| 679 | |
| 680 | /* Check a command itself */ |
| 681 | if (strncmp(buf, cmd, cmd_len)) |
| 682 | return false; |
| 683 | |
| 684 | /* A command has arguments */ |
| 685 | if (params != NULL) { |
| 686 | /* Make sure there is a space */ |
| 687 | if (buf[cmd_len] != ' ') |
| 688 | return false; |
| 689 | |
| 690 | /* Update external pointer */ |
| 691 | *params = buf + cmd_len + 1; |
| 692 | } |
| 693 | |
| 694 | return true; |
| 695 | } |
| 696 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 697 | void Transceiver::driveControl(size_t chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 698 | { |
Vadim Yanitskiy | 4d9b59c | 2018-03-09 02:54:45 +0700 | [diff] [blame] | 699 | char buffer[MAX_PACKET_LENGTH + 1]; |
| 700 | char response[MAX_PACKET_LENGTH + 1]; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 701 | char *command, *params; |
Vadim Yanitskiy | 4d9b59c | 2018-03-09 02:54:45 +0700 | [diff] [blame] | 702 | int msgLen; |
Thomas Tsou | d647ec5 | 2013-10-29 15:17:34 -0400 | [diff] [blame] | 703 | |
Vadim Yanitskiy | 4d9b59c | 2018-03-09 02:54:45 +0700 | [diff] [blame] | 704 | /* Attempt to read from control socket */ |
| 705 | msgLen = mCtrlSockets[chan]->read(buffer, MAX_PACKET_LENGTH); |
| 706 | if (msgLen < 1) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 707 | return; |
Vadim Yanitskiy | 4d9b59c | 2018-03-09 02:54:45 +0700 | [diff] [blame] | 708 | |
| 709 | /* Zero-terminate received string */ |
| 710 | buffer[msgLen] = '\0'; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 711 | |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 712 | /* Verify a command signature */ |
| 713 | if (strncmp(buffer, "CMD ", 4)) { |
Pau Espin Pedrol | 441d82a | 2018-12-04 16:37:24 +0100 | [diff] [blame] | 714 | LOGC(DTRXCTRL, WARNING) << "bogus message on control interface"; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 715 | return; |
| 716 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 717 | |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 718 | /* Set command pointer */ |
| 719 | command = buffer + 4; |
Pau Espin Pedrol | fc73c07 | 2019-05-03 19:40:00 +0200 | [diff] [blame] | 720 | LOGCHAN(chan, DTRXCTRL, INFO) << "command is '" << command << "'"; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 721 | |
| 722 | if (match_cmd(command, "POWEROFF", NULL)) { |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 723 | stop(); |
| 724 | sprintf(response,"RSP POWEROFF 0"); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 725 | } else if (match_cmd(command, "POWERON", NULL)) { |
Tom Tsou | 365bc38 | 2016-10-19 15:26:04 -0700 | [diff] [blame] | 726 | if (!start()) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 727 | sprintf(response,"RSP POWERON 1"); |
Tom Tsou | 365bc38 | 2016-10-19 15:26:04 -0700 | [diff] [blame] | 728 | } else { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 729 | sprintf(response,"RSP POWERON 0"); |
Alexander Chemeris | 5a06806 | 2015-06-20 01:38:47 +0300 | [diff] [blame] | 730 | for (int i = 0; i < 8; i++) { |
| 731 | for (int j = 0; j < 8; j++) |
| 732 | mHandover[i][j] = false; |
| 733 | } |
Tom Tsou | 365bc38 | 2016-10-19 15:26:04 -0700 | [diff] [blame] | 734 | } |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 735 | } else if (match_cmd(command, "HANDOVER", ¶ms)) { |
Vadim Yanitskiy | c0c6d70 | 2018-03-09 05:08:23 +0700 | [diff] [blame] | 736 | unsigned ts = 0, ss = 0; |
| 737 | sscanf(params, "%u %u", &ts, &ss); |
| 738 | if (ts > 7 || ss > 7) { |
| 739 | sprintf(response, "RSP NOHANDOVER 1 %u %u", ts, ss); |
| 740 | } else { |
| 741 | mHandover[ts][ss] = true; |
| 742 | sprintf(response, "RSP HANDOVER 0 %u %u", ts, ss); |
| 743 | } |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 744 | } else if (match_cmd(command, "NOHANDOVER", ¶ms)) { |
Vadim Yanitskiy | c0c6d70 | 2018-03-09 05:08:23 +0700 | [diff] [blame] | 745 | unsigned ts = 0, ss = 0; |
| 746 | sscanf(params, "%u %u", &ts, &ss); |
| 747 | if (ts > 7 || ss > 7) { |
| 748 | sprintf(response, "RSP NOHANDOVER 1 %u %u", ts, ss); |
| 749 | } else { |
| 750 | mHandover[ts][ss] = false; |
| 751 | sprintf(response, "RSP NOHANDOVER 0 %u %u", ts, ss); |
| 752 | } |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 753 | } else if (match_cmd(command, "SETMAXDLY", ¶ms)) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 754 | //set expected maximum time-of-arrival |
| 755 | int maxDelay; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 756 | sscanf(params, "%d", &maxDelay); |
Alexander Chemeris | 78d1fc9 | 2016-03-19 21:16:22 +0300 | [diff] [blame] | 757 | mMaxExpectedDelayAB = maxDelay; // 1 GSM symbol is approx. 1 km |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 758 | sprintf(response,"RSP SETMAXDLY 0 %d",maxDelay); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 759 | } else if (match_cmd(command, "SETMAXDLYNB", ¶ms)) { |
Alexander Chemeris | 78d1fc9 | 2016-03-19 21:16:22 +0300 | [diff] [blame] | 760 | //set expected maximum time-of-arrival |
| 761 | int maxDelay; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 762 | sscanf(params, "%d", &maxDelay); |
Alexander Chemeris | 78d1fc9 | 2016-03-19 21:16:22 +0300 | [diff] [blame] | 763 | mMaxExpectedDelayNB = maxDelay; // 1 GSM symbol is approx. 1 km |
| 764 | sprintf(response,"RSP SETMAXDLYNB 0 %d",maxDelay); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 765 | } else if (match_cmd(command, "SETRXGAIN", ¶ms)) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 766 | //set expected maximum time-of-arrival |
| 767 | int newGain; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 768 | sscanf(params, "%d", &newGain); |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 769 | newGain = mRadioInterface->setRxGain(newGain, chan); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 770 | sprintf(response,"RSP SETRXGAIN 0 %d",newGain); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 771 | } else if (match_cmd(command, "NOISELEV", NULL)) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 772 | if (mOn) { |
Thomas Tsou | a0179e3 | 2013-11-14 15:52:04 -0500 | [diff] [blame] | 773 | float lev = mStates[chan].mNoiseLev; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 774 | sprintf(response,"RSP NOISELEV 0 %d", |
Thomas Tsou | a0179e3 | 2013-11-14 15:52:04 -0500 | [diff] [blame] | 775 | (int) round(20.0 * log10(rxFullScale / lev))); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 776 | } |
| 777 | else { |
| 778 | sprintf(response,"RSP NOISELEV 1 0"); |
| 779 | } |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 780 | } else if (match_cmd(command, "SETPOWER", ¶ms)) { |
Tom Tsou | a4d1a41 | 2014-11-25 15:46:56 -0800 | [diff] [blame] | 781 | int power; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 782 | sscanf(params, "%d", &power); |
Tom Tsou | a4d1a41 | 2014-11-25 15:46:56 -0800 | [diff] [blame] | 783 | power = mRadioInterface->setPowerAttenuation(power, chan); |
| 784 | mStates[chan].mPower = power; |
| 785 | sprintf(response, "RSP SETPOWER 0 %d", power); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 786 | } else if (match_cmd(command, "ADJPOWER", ¶ms)) { |
Tom Tsou | a4d1a41 | 2014-11-25 15:46:56 -0800 | [diff] [blame] | 787 | int power, step; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 788 | sscanf(params, "%d", &step); |
Tom Tsou | a4d1a41 | 2014-11-25 15:46:56 -0800 | [diff] [blame] | 789 | power = mStates[chan].mPower + step; |
| 790 | power = mRadioInterface->setPowerAttenuation(power, chan); |
| 791 | mStates[chan].mPower = power; |
| 792 | sprintf(response, "RSP ADJPOWER 0 %d", power); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 793 | } else if (match_cmd(command, "RXTUNE", ¶ms)) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 794 | // tune receiver |
| 795 | int freqKhz; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 796 | sscanf(params, "%d", &freqKhz); |
Thomas Tsou | 477b77c | 2013-11-15 16:13:59 -0500 | [diff] [blame] | 797 | mRxFreq = freqKhz * 1e3; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 798 | if (!mRadioInterface->tuneRx(mRxFreq, chan)) { |
Pau Espin Pedrol | 441d82a | 2018-12-04 16:37:24 +0100 | [diff] [blame] | 799 | LOGC(DTRXCTRL, ALERT) << "RX failed to tune"; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 800 | sprintf(response,"RSP RXTUNE 1 %d",freqKhz); |
| 801 | } |
| 802 | else |
| 803 | sprintf(response,"RSP RXTUNE 0 %d",freqKhz); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 804 | } else if (match_cmd(command, "TXTUNE", ¶ms)) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 805 | // tune txmtr |
| 806 | int freqKhz; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 807 | sscanf(params, "%d", &freqKhz); |
Thomas Tsou | 477b77c | 2013-11-15 16:13:59 -0500 | [diff] [blame] | 808 | mTxFreq = freqKhz * 1e3; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 809 | if (!mRadioInterface->tuneTx(mTxFreq, chan)) { |
Pau Espin Pedrol | 441d82a | 2018-12-04 16:37:24 +0100 | [diff] [blame] | 810 | LOGC(DTRXCTRL, ALERT) << "TX failed to tune"; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 811 | sprintf(response,"RSP TXTUNE 1 %d",freqKhz); |
| 812 | } |
| 813 | else |
| 814 | sprintf(response,"RSP TXTUNE 0 %d",freqKhz); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 815 | } else if (match_cmd(command, "SETTSC", ¶ms)) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 816 | // set TSC |
Thomas Tsou | 3f32ab5 | 2013-11-15 16:32:54 -0500 | [diff] [blame] | 817 | unsigned TSC; |
Vadim Yanitskiy | 8c6c5d2 | 2018-03-09 05:01:21 +0700 | [diff] [blame] | 818 | sscanf(params, "%u", &TSC); |
Tom Tsou | 6031734 | 2017-03-30 19:36:41 -0700 | [diff] [blame] | 819 | if (TSC > 7) { |
Thomas Tsou | d3fccea | 2013-11-15 14:22:53 -0500 | [diff] [blame] | 820 | sprintf(response, "RSP SETTSC 1 %d", TSC); |
Tom Tsou | 6031734 | 2017-03-30 19:36:41 -0700 | [diff] [blame] | 821 | } else { |
Pau Espin Pedrol | 441d82a | 2018-12-04 16:37:24 +0100 | [diff] [blame] | 822 | LOGC(DTRXCTRL, NOTICE) << "Changing TSC from " << mTSC << " to " << TSC; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 823 | mTSC = TSC; |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 824 | sprintf(response,"RSP SETTSC 0 %d", TSC); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 825 | } |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 826 | } else if (match_cmd(command, "SETSLOT", ¶ms)) { |
Alexander Chemeris | 1fe5282 | 2015-05-20 12:02:29 -0700 | [diff] [blame] | 827 | // set slot type |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 828 | int corrCode; |
| 829 | int timeslot; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 830 | sscanf(params, "%d %d", ×lot, &corrCode); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 831 | if ((timeslot < 0) || (timeslot > 7)) { |
Pau Espin Pedrol | 441d82a | 2018-12-04 16:37:24 +0100 | [diff] [blame] | 832 | LOGC(DTRXCTRL, WARNING) << "bogus message on control interface"; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 833 | sprintf(response,"RSP SETSLOT 1 %d %d",timeslot,corrCode); |
| 834 | return; |
Pau Espin Pedrol | 7c405a0 | 2017-07-04 16:24:06 +0200 | [diff] [blame] | 835 | } |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 836 | mStates[chan].chanType[timeslot] = (ChannelCombination) corrCode; |
| 837 | setModulus(timeslot, chan); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 838 | sprintf(response,"RSP SETSLOT 0 %d %d",timeslot,corrCode); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 839 | } else if (match_cmd(command, "_SETBURSTTODISKMASK", ¶ms)) { |
Alexander Chemeris | e692ce9 | 2015-06-12 00:15:31 -0400 | [diff] [blame] | 840 | // debug command! may change or disapear without notice |
| 841 | // set a mask which bursts to dump to disk |
| 842 | int mask; |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 843 | sscanf(params, "%d", &mask); |
Alexander Chemeris | e692ce9 | 2015-06-12 00:15:31 -0400 | [diff] [blame] | 844 | mWriteBurstToDiskMask = mask; |
| 845 | sprintf(response,"RSP _SETBURSTTODISKMASK 0 %d",mask); |
Vadim Yanitskiy | a62fcf7 | 2018-03-09 03:24:08 +0700 | [diff] [blame] | 846 | } else { |
Pau Espin Pedrol | 441d82a | 2018-12-04 16:37:24 +0100 | [diff] [blame] | 847 | LOGC(DTRXCTRL, WARNING) << "bogus command " << command << " on control interface."; |
Alexander Chemeris | 4438a9f | 2013-04-08 00:14:08 +0200 | [diff] [blame] | 848 | sprintf(response,"RSP ERR 1"); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 849 | } |
| 850 | |
Pau Espin Pedrol | fc73c07 | 2019-05-03 19:40:00 +0200 | [diff] [blame] | 851 | LOGCHAN(chan, DTRXCTRL, INFO) << "response is '" << response << "'"; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 852 | mCtrlSockets[chan]->write(response, strlen(response) + 1); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 853 | } |
| 854 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 855 | bool Transceiver::driveTxPriorityQueue(size_t chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 856 | { |
Tom Tsou | e887108 | 2016-07-01 02:46:04 -0700 | [diff] [blame] | 857 | int burstLen; |
| 858 | char buffer[EDGE_BURST_NBITS + 50]; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 859 | |
| 860 | // check data socket |
Tom Tsou | 2c650a6 | 2016-04-28 21:55:17 -0700 | [diff] [blame] | 861 | size_t msgLen = mDataSockets[chan]->read(buffer, sizeof(buffer)); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 862 | |
Tom Tsou | e887108 | 2016-07-01 02:46:04 -0700 | [diff] [blame] | 863 | if (msgLen == gSlotLen + 1 + 4 + 1) { |
| 864 | burstLen = gSlotLen; |
| 865 | } else if (msgLen == EDGE_BURST_NBITS + 1 + 4 + 1) { |
| 866 | if (mSPSTx != 4) |
| 867 | return false; |
| 868 | |
| 869 | burstLen = EDGE_BURST_NBITS; |
| 870 | } else { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 871 | LOG(ERR) << "badly formatted packet on GSM->TRX interface"; |
| 872 | return false; |
| 873 | } |
| 874 | |
| 875 | int timeSlot = (int) buffer[0]; |
| 876 | uint64_t frameNum = 0; |
| 877 | for (int i = 0; i < 4; i++) |
| 878 | frameNum = (frameNum << 8) | (0x0ff & buffer[i+1]); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 879 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 880 | LOG(DEBUG) << "rcvd. burst at: " << GSM::Time(frameNum,timeSlot); |
Pau Espin Pedrol | 7c405a0 | 2017-07-04 16:24:06 +0200 | [diff] [blame] | 881 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 882 | int RSSI = (int) buffer[5]; |
Tom Tsou | 7c741ec | 2016-07-19 11:20:59 -0700 | [diff] [blame] | 883 | BitVector newBurst(burstLen); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 884 | BitVector::iterator itr = newBurst.begin(); |
| 885 | char *bufferItr = buffer+6; |
Pau Espin Pedrol | 7c405a0 | 2017-07-04 16:24:06 +0200 | [diff] [blame] | 886 | while (itr < newBurst.end()) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 887 | *itr++ = *bufferItr++; |
Pau Espin Pedrol | 7c405a0 | 2017-07-04 16:24:06 +0200 | [diff] [blame] | 888 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 889 | GSM::Time currTime = GSM::Time(frameNum,timeSlot); |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 890 | |
| 891 | addRadioVector(chan, newBurst, RSSI, currTime); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 892 | |
| 893 | return true; |
| 894 | |
| 895 | |
| 896 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 897 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 898 | void Transceiver::driveReceiveRadio() |
| 899 | { |
Pau Espin Pedrol | db936b9 | 2018-09-03 16:50:49 +0200 | [diff] [blame] | 900 | int rc = mRadioInterface->driveReceiveRadio(); |
| 901 | if (rc == 0) { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 902 | usleep(100000); |
Pau Espin Pedrol | db936b9 | 2018-09-03 16:50:49 +0200 | [diff] [blame] | 903 | } else if (rc < 0) { |
| 904 | LOG(FATAL) << "radio Interface receive failed, requesting stop."; |
Pau Espin Pedrol | b426e4a | 2019-06-04 12:39:28 +0200 | [diff] [blame] | 905 | osmo_signal_dispatch(SS_MAIN, S_MAIN_STOP_REQUIRED, NULL); |
Pau Espin Pedrol | 934da48 | 2017-07-04 16:25:20 +0200 | [diff] [blame] | 906 | } else if (mForceClockInterface || mTransmitDeadlineClock > mLastClockUpdateTime + GSM::Time(216,0)) { |
| 907 | mForceClockInterface = false; |
| 908 | writeClockInterface(); |
Alexander Chemeris | 6a2bf0d | 2015-05-24 19:28:09 -0400 | [diff] [blame] | 909 | } |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 910 | } |
| 911 | |
Pau Espin Pedrol | 607a414 | 2019-07-01 13:56:17 +0200 | [diff] [blame] | 912 | 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] | 913 | { |
| 914 | LOG(DEBUG) << std::fixed << std::right |
Alexander Chemeris | 58e9591 | 2016-03-25 18:20:28 +0300 | [diff] [blame] | 915 | << " chan: " << chan |
Pau Espin Pedrol | ddd18a5 | 2019-06-28 17:01:16 +0200 | [diff] [blame] | 916 | << " time: " << bi->burstTime |
Pau Espin Pedrol | 607a414 | 2019-07-01 13:56:17 +0200 | [diff] [blame] | 917 | << " RSSI: " << std::setw(5) << std::setprecision(1) << (bi->rssi - rssiOffset) |
| 918 | << "dBFS/" << std::setw(6) << -bi->rssi << "dBm" |
| 919 | << " noise: " << std::setw(5) << std::setprecision(1) << (bi->noise - rssiOffset) |
| 920 | << "dBFS/" << std::setw(6) << -bi->noise << "dBm" |
Pau Espin Pedrol | ddd18a5 | 2019-06-28 17:01:16 +0200 | [diff] [blame] | 921 | << " TOA: " << std::setw(5) << std::setprecision(2) << bi->toa |
| 922 | << " bits: " << *(bi->rxBurst); |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 923 | } |
| 924 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 925 | void Transceiver::driveReceiveFIFO(size_t chan) |
| 926 | { |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 927 | int TOAint; // in 1/256 symbols |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 928 | |
Pau Espin Pedrol | ddd18a5 | 2019-06-28 17:01:16 +0200 | [diff] [blame] | 929 | struct trx_ul_burst_ind bi; |
| 930 | |
| 931 | if (!pullRadioVector(chan, &bi)) |
| 932 | return; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 933 | |
Pau Espin Pedrol | 607a414 | 2019-07-01 13:56:17 +0200 | [diff] [blame] | 934 | logRxBurst(chan, &bi); |
Alexander Chemeris | dbe26ab | 2015-06-04 00:14:51 -0400 | [diff] [blame] | 935 | |
Pau Espin Pedrol | ddd18a5 | 2019-06-28 17:01:16 +0200 | [diff] [blame] | 936 | TOAint = (int) (bi.toa * 256.0 + 0.5); // round to closest integer |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 937 | |
Pau Espin Pedrol | 0e67cf2 | 2019-07-02 14:59:47 +0200 | [diff] [blame] | 938 | char burstString[sizeof(struct trxd_hdr_v0) + bi.nbits + 2]; |
Pau Espin Pedrol | 778b30a | 2019-06-28 13:27:24 +0200 | [diff] [blame] | 939 | struct trxd_hdr_v0* pkt = (struct trxd_hdr_v0*)burstString; |
| 940 | pkt->common.version = 0; |
| 941 | pkt->common.reserved = 0; |
Pau Espin Pedrol | ddd18a5 | 2019-06-28 17:01:16 +0200 | [diff] [blame] | 942 | pkt->common.tn = bi.burstTime.TN(); |
| 943 | osmo_store32be(bi.burstTime.FN(), &pkt->common.fn); |
Pau Espin Pedrol | 607a414 | 2019-07-01 13:56:17 +0200 | [diff] [blame] | 944 | pkt->v0.rssi = bi.rssi; |
Pau Espin Pedrol | 778b30a | 2019-06-28 13:27:24 +0200 | [diff] [blame] | 945 | osmo_store16be(TOAint, &pkt->v0.toa); |
Pau Espin Pedrol | ddd18a5 | 2019-06-28 17:01:16 +0200 | [diff] [blame] | 946 | SoftVector::iterator burstItr = bi.rxBurst->begin(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 947 | |
Pau Espin Pedrol | 0e67cf2 | 2019-07-02 14:59:47 +0200 | [diff] [blame] | 948 | for (unsigned i = 0; i < bi.nbits; i++) |
Pau Espin Pedrol | 778b30a | 2019-06-28 13:27:24 +0200 | [diff] [blame] | 949 | pkt->soft_bits[i] = (char) round((*burstItr++) * 255.0); |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 950 | |
Pau Espin Pedrol | 778b30a | 2019-06-28 13:27:24 +0200 | [diff] [blame] | 951 | /* +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] | 952 | pkt->soft_bits[bi.nbits + 1] = '\0'; |
Pau Espin Pedrol | ddd18a5 | 2019-06-28 17:01:16 +0200 | [diff] [blame] | 953 | delete bi.rxBurst; |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 954 | |
Pau Espin Pedrol | 0e67cf2 | 2019-07-02 14:59:47 +0200 | [diff] [blame] | 955 | mDataSockets[chan]->write(burstString, sizeof(struct trxd_hdr_v0) + bi.nbits + 2); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 956 | } |
| 957 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 958 | void Transceiver::driveTxFIFO() |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 959 | { |
| 960 | |
| 961 | /** |
Pau Espin Pedrol | 7c405a0 | 2017-07-04 16:24:06 +0200 | [diff] [blame] | 962 | Features a carefully controlled latency mechanism, to |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 963 | assure that transmit packets arrive at the radio/USRP |
| 964 | before they need to be transmitted. |
| 965 | |
| 966 | Deadline clock indicates the burst that needs to be |
| 967 | pushed into the FIFO right NOW. If transmit queue does |
| 968 | not have a burst, stick in filler data. |
| 969 | */ |
| 970 | |
| 971 | |
| 972 | RadioClock *radioClock = (mRadioInterface->getClock()); |
Pau Espin Pedrol | 7c405a0 | 2017-07-04 16:24:06 +0200 | [diff] [blame] | 973 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 974 | if (mOn) { |
| 975 | //radioClock->wait(); // wait until clock updates |
| 976 | LOG(DEBUG) << "radio clock " << radioClock->get(); |
| 977 | while (radioClock->get() + mTransmitLatency > mTransmitDeadlineClock) { |
| 978 | // if underrun, then we're not providing bursts to radio/USRP fast |
| 979 | // enough. Need to increase latency by one GSM frame. |
Thomas Tsou | 02d88d1 | 2013-04-05 15:36:30 -0400 | [diff] [blame] | 980 | if (mRadioInterface->getWindowType() == RadioDevice::TX_WINDOW_USRP1) { |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 981 | if (mRadioInterface->isUnderrun()) { |
ttsou | 2173abf | 2012-08-08 00:51:31 +0000 | [diff] [blame] | 982 | // only update latency at the defined frame interval |
| 983 | if (radioClock->get() > mLatencyUpdateTime + GSM::Time(USB_LATENCY_INTRVL)) { |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 984 | mTransmitLatency = mTransmitLatency + GSM::Time(1,0); |
Pau Espin Pedrol | 74bcc56 | 2018-10-02 17:30:28 +0200 | [diff] [blame] | 985 | LOG(INFO) << "new latency: " << mTransmitLatency << " (underrun " |
| 986 | << radioClock->get() << " vs " << mLatencyUpdateTime + GSM::Time(USB_LATENCY_INTRVL) << ")"; |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 987 | mLatencyUpdateTime = radioClock->get(); |
| 988 | } |
| 989 | } |
| 990 | else { |
| 991 | // if underrun hasn't occurred in the last sec (216 frames) drop |
| 992 | // transmit latency by a timeslot |
Pau Espin Pedrol | e564f0f | 2018-04-24 18:43:51 +0200 | [diff] [blame] | 993 | if (mTransmitLatency > mRadioInterface->minLatency()) { |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 994 | if (radioClock->get() > mLatencyUpdateTime + GSM::Time(216,0)) { |
| 995 | mTransmitLatency.decTN(); |
| 996 | LOG(INFO) << "reduced latency: " << mTransmitLatency; |
| 997 | mLatencyUpdateTime = radioClock->get(); |
| 998 | } |
| 999 | } |
| 1000 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1001 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1002 | // time to push burst to transmit FIFO |
| 1003 | pushRadioVector(mTransmitDeadlineClock); |
| 1004 | mTransmitDeadlineClock.incTN(); |
| 1005 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1006 | } |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 1007 | |
| 1008 | radioClock->wait(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | |
| 1012 | |
| 1013 | void Transceiver::writeClockInterface() |
| 1014 | { |
| 1015 | char command[50]; |
| 1016 | // FIXME -- This should be adaptive. |
| 1017 | sprintf(command,"IND CLOCK %llu",(unsigned long long) (mTransmitDeadlineClock.FN()+2)); |
| 1018 | |
| 1019 | LOG(INFO) << "ClockInterface: sending " << command; |
| 1020 | |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 1021 | mClockSocket.write(command, strlen(command) + 1); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1022 | |
| 1023 | mLastClockUpdateTime = mTransmitDeadlineClock; |
| 1024 | |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 1025 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1026 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1027 | void *RxUpperLoopAdapter(TransceiverChannel *chan) |
| 1028 | { |
Pau Espin Pedrol | 5b60c98 | 2018-09-20 18:04:46 +0200 | [diff] [blame] | 1029 | char thread_name[16]; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1030 | Transceiver *trx = chan->trx; |
| 1031 | size_t num = chan->num; |
| 1032 | |
| 1033 | delete chan; |
| 1034 | |
Pau Espin Pedrol | 5b60c98 | 2018-09-20 18:04:46 +0200 | [diff] [blame] | 1035 | snprintf(thread_name, 16, "RxUpper%zu", num); |
| 1036 | set_selfthread_name(thread_name); |
| 1037 | |
Thomas Tsou | 7553aa9 | 2013-11-08 12:50:03 -0500 | [diff] [blame] | 1038 | trx->setPriority(0.42); |
| 1039 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1040 | while (1) { |
| 1041 | trx->driveReceiveFIFO(num); |
| 1042 | pthread_testcancel(); |
| 1043 | } |
| 1044 | return NULL; |
| 1045 | } |
| 1046 | |
| 1047 | void *RxLowerLoopAdapter(Transceiver *transceiver) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1048 | { |
Pau Espin Pedrol | 5b60c98 | 2018-09-20 18:04:46 +0200 | [diff] [blame] | 1049 | set_selfthread_name("RxLower"); |
| 1050 | |
Thomas Tsou | 7553aa9 | 2013-11-08 12:50:03 -0500 | [diff] [blame] | 1051 | transceiver->setPriority(0.45); |
kurtis.heimerl | 6b495a5 | 2011-11-26 03:17:21 +0000 | [diff] [blame] | 1052 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1053 | while (1) { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1054 | transceiver->driveReceiveRadio(); |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 1055 | pthread_testcancel(); |
| 1056 | } |
| 1057 | return NULL; |
| 1058 | } |
| 1059 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1060 | void *TxLowerLoopAdapter(Transceiver *transceiver) |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 1061 | { |
Pau Espin Pedrol | 5b60c98 | 2018-09-20 18:04:46 +0200 | [diff] [blame] | 1062 | set_selfthread_name("TxLower"); |
| 1063 | |
Thomas Tsou | 7553aa9 | 2013-11-08 12:50:03 -0500 | [diff] [blame] | 1064 | transceiver->setPriority(0.44); |
| 1065 | |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 1066 | while (1) { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1067 | transceiver->driveTxFIFO(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1068 | pthread_testcancel(); |
| 1069 | } |
| 1070 | return NULL; |
| 1071 | } |
| 1072 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1073 | void *ControlServiceLoopAdapter(TransceiverChannel *chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1074 | { |
Pau Espin Pedrol | 5b60c98 | 2018-09-20 18:04:46 +0200 | [diff] [blame] | 1075 | char thread_name[16]; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1076 | Transceiver *trx = chan->trx; |
| 1077 | size_t num = chan->num; |
| 1078 | |
| 1079 | delete chan; |
| 1080 | |
Pau Espin Pedrol | 5b60c98 | 2018-09-20 18:04:46 +0200 | [diff] [blame] | 1081 | snprintf(thread_name, 16, "CtrlService%zu", num); |
| 1082 | set_selfthread_name(thread_name); |
| 1083 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1084 | while (1) { |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1085 | trx->driveControl(num); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1086 | pthread_testcancel(); |
| 1087 | } |
| 1088 | return NULL; |
| 1089 | } |
| 1090 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1091 | void *TxUpperLoopAdapter(TransceiverChannel *chan) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1092 | { |
Pau Espin Pedrol | 5b60c98 | 2018-09-20 18:04:46 +0200 | [diff] [blame] | 1093 | char thread_name[16]; |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 1094 | Transceiver *trx = chan->trx; |
| 1095 | size_t num = chan->num; |
| 1096 | |
| 1097 | delete chan; |
| 1098 | |
Pau Espin Pedrol | 5b60c98 | 2018-09-20 18:04:46 +0200 | [diff] [blame] | 1099 | snprintf(thread_name, 16, "TxUpper%zu", num); |
| 1100 | set_selfthread_name(thread_name); |
| 1101 | |
Thomas Tsou | a4cf48c | 2013-11-09 21:44:26 -0500 | [diff] [blame] | 1102 | trx->setPriority(0.40); |
| 1103 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1104 | while (1) { |
Tom Tsou | eb54bdd | 2014-11-25 16:06:32 -0800 | [diff] [blame] | 1105 | trx->driveTxPriorityQueue(num); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1106 | pthread_testcancel(); |
| 1107 | } |
| 1108 | return NULL; |
| 1109 | } |