diff options
author | Eric <ewild@sysmocom.de> | 2023-05-02 15:21:45 +0200 |
---|---|---|
committer | Eric <ewild@sysmocom.de> | 2023-07-07 19:12:39 +0200 |
commit | ea7bd5fb9182a607a9fe19036e6290dee680266b (patch) | |
tree | 4a288f7c4a26dc8ad5f7a782d19d36e1fb9df7e3 | |
parent | 135d64b1a96438a13ca872f87cde8f15442455b2 (diff) |
ms: remove syncthing tool
Only used for testing during the first stages of development.
Change-Id: Ie97069a109324b6e96c66a4b24d03f9745b6a52e
-rw-r--r-- | Transceiver52M/Makefile.am | 19 | ||||
-rw-r--r-- | Transceiver52M/ms/ms.cpp | 196 | ||||
-rw-r--r-- | Transceiver52M/ms/ms.h | 4 | ||||
-rw-r--r-- | Transceiver52M/ms/ms_rx_burst.h | 25 | ||||
-rw-r--r-- | Transceiver52M/ms/ms_rx_burst_test.cpp | 206 | ||||
-rw-r--r-- | Transceiver52M/ms/ms_rx_lower.cpp | 21 |
6 files changed, 4 insertions, 467 deletions
diff --git a/Transceiver52M/Makefile.am b/Transceiver52M/Makefile.am index 65c8ebe..681809f 100644 --- a/Transceiver52M/Makefile.am +++ b/Transceiver52M/Makefile.am @@ -100,7 +100,6 @@ noinst_HEADERS += \ ms/ms.h \ ms/bladerf_specific.h \ ms/uhd_specific.h \ - ms/ms_rx_burst.h \ ms/ms_upper.h \ ms/ms_trxcon_if.h \ ms/itrq.h \ @@ -132,15 +131,6 @@ osmo_trx_ms_uhd_LDADD = \ $(UHD_LIBS) \ $(TRXCON_LDADD) osmo_trx_ms_uhd_CPPFLAGS = $(AM_CPPFLAGS) $(UHD_CFLAGS) -DBUILDUHD - -bin_PROGRAMS += osmo-trx-syncthing-uhd -osmo_trx_syncthing_uhd_SOURCES = $(MS_LOWER_SRC) ms/ms_rx_burst_test.cpp -osmo_trx_syncthing_uhd_LDADD = \ - $(builddir)/device/uhd/libdevice.la \ - $(COMMON_LDADD) \ - $(UHD_LIBS) \ - $(TRXCON_LDADD) -osmo_trx_syncthing_uhd_CPPFLAGS = $(AM_CPPFLAGS) $(UHD_CFLAGS) -DSYNCTHINGONLY -DBUILDUHD endif endif @@ -182,15 +172,6 @@ osmo_trx_ms_blade_LDADD = \ $(BLADE_LIBS) \ $(TRXCON_LDADD) osmo_trx_ms_blade_CPPFLAGS = $(AM_CPPFLAGS) $(BLADE_CFLAGS) -DBUILDBLADE - -bin_PROGRAMS += osmo-trx-syncthing-blade -osmo_trx_syncthing_blade_SOURCES = $(MS_LOWER_SRC) ms/ms_rx_burst_test.cpp -osmo_trx_syncthing_blade_LDADD = \ - $(builddir)/device/bladerf/libdevice.la \ - $(COMMON_LDADD) \ - $(BLADE_LIBS) \ - $(TRXCON_LDADD) -osmo_trx_syncthing_blade_CPPFLAGS = $(AM_CPPFLAGS) $(BLADE_CFLAGS) -DSYNCTHINGONLY -DBUILDBLADE -I../device/ipc endif endif diff --git a/Transceiver52M/ms/ms.cpp b/Transceiver52M/ms/ms.cpp index ca3339b..2e91cae 100644 --- a/Transceiver52M/ms/ms.cpp +++ b/Transceiver52M/ms/ms.cpp @@ -29,16 +29,10 @@ #include <thread> #include <fstream> -#include "sigProcLib.h" - #include "ms.h" -#include "ms_rx_burst.h" -#include "grgsm_vitac/grgsm_vitac.h" extern "C" { #include "sch.h" -#include "convolve.h" -#include "convert.h" } dummylog ms_trx::dummy_log; @@ -52,196 +46,6 @@ static int offset_ctr = 0; template <> std::atomic<bool> ms_trx::base::stop_lower_threads_flag(false); -void tx_test(ms_trx *t, ts_hitter_q_t *q, unsigned int *tsc) -{ - sched_param sch_params; - sch_params.sched_priority = sched_get_priority_max(SCHED_FIFO); - pthread_setschedparam(pthread_self(), SCHED_FIFO, &sch_params); - - auto burst = genRandAccessBurst(0, 4, 0); - scaleVector(*burst, t->txFullScale); - - // float -> int16 - blade_sample_type burst_buf[burst->size()]; - convert_and_scale(burst_buf, burst->begin(), burst->size() * 2, 1); - - while (1) { - GSM::Time target; - while (!q->spsc_pop(&target)) { - q->spsc_prep_pop(); - } - - std::cerr << std::endl << "\x1B[32m hitting " << target.FN() << "\033[0m" << std::endl; - - int timing_advance = 0; - int64_t now_ts; - GSM::Time now_time; - target.incTN(3); // ul dl offset - int target_fn = target.FN(); - int target_tn = target.TN(); - t->timekeeper.get_both(&now_time, &now_ts); - - auto diff_fn = GSM::FNDelta(target_fn, now_time.FN()); - int diff_tn = (target_tn - (int)now_time.TN()) % 8; - auto tosend = GSM::Time(diff_fn, 0); - - if (diff_tn > 0) - tosend.incTN(diff_tn); - else if (diff_tn < 0) - tosend.decTN(-diff_tn); - - // in thory fn equal and tn+3 equal is also a problem... - if (diff_fn < 0 || (diff_fn == 0 && (now_time.TN() - target_tn < 1))) { - std::cerr << "## TX too late?! fn DIFF:" << diff_fn << " tn LOCAL: " << now_time.TN() - << " tn OTHER: " << target_tn << std::endl; - return; - } - - auto check = now_time + tosend; - int64_t send_ts = - now_ts + tosend.FN() * 8 * ONE_TS_BURST_LEN + tosend.TN() * ONE_TS_BURST_LEN - timing_advance; - -#ifdef DBGXX - std::cerr << "## fn DIFF: " << diff_fn << " ## tn DIFF: " << diff_tn << " tn LOCAL: " << now_time.TN() - << " tn OTHER: " << target_tn << " tndiff" << diff_tn << " tosend:" << tosend.FN() << ":" - << tosend.TN() << " calc: " << check.FN() << ":" << check.TN() << " target: " << target.FN() - << ":" << target.TN() << " ts now: " << now_ts << " target ts:" << send_ts << std::endl; -#endif - - unsigned int pad = 4 * 25; - blade_sample_type buf2[burst->size() + pad]; - std::fill(buf2, buf2 + pad, 0); - - memcpy(&buf2[pad], burst_buf, burst->size() * sizeof(blade_sample_type)); - - assert(target.FN() == check.FN()); - assert(target.TN() == check.TN()); - assert(target.FN() % 51 == 21); -#ifdef DBGXX - auto this_offset = offset_start + (offset_ctr++ % offsetrange); - std::cerr << "-- O " << this_offset << std::endl; - send_ts = now_ts - timing_advance + - ((target.FN() * 8 + (int)target.TN()) - (now_time.FN() * 8 + (int)now_time.TN())) * - ONE_TS_BURST_LEN; -#endif - t->submit_burst_ts(buf2, burst->size() + pad, send_ts - pad); -#ifdef DBGXX - signalVector test(burst->size() + pad); - convert_and_scale(test.begin(), buf2, burst->size() * 2 + pad, 1.f / float(scale)); - estim_burst_params ebp; - auto det = detectAnyBurst(test, 0, 4, 4, CorrType::RACH, 40, &ebp); - if (det > 0) - std::cerr << "## Y " << ebp.toa << std::endl; - else - std::cerr << "## NOOOOOOOOO " << ebp.toa << std::endl; -#endif - } -} -#ifdef SYNCTHINGONLY -template <typename A> -auto parsec(std::vector<std::string> &v, A &itr, std::string arg, bool *rv) -{ - if (*itr == arg) { - *rv = true; - return true; - } - return false; -} - -template <typename A, typename B, typename C> -bool parsec(std::vector<std::string> &v, A &itr, std::string arg, B f, C *rv) -{ - if (*itr == arg) { - itr++; - if (itr != v.end()) { - *rv = f(itr->c_str()); - return true; - } - } - return false; -} -template <typename A> -bool parsec(std::vector<std::string> &v, A &itr, std::string arg, int scale, int *rv) -{ - return parsec( - v, itr, arg, [scale](const char *v) -> auto { return atoi(v) * scale; }, rv); -} -template <typename A> -bool parsec(std::vector<std::string> &v, A &itr, std::string arg, int scale, unsigned int *rv) -{ - return parsec( - v, itr, arg, [scale](const char *v) -> auto { return atoi(v) * scale; }, rv); -} - -int main(int argc, char *argv[]) -{ - cpu_set_t cpuset; - - CPU_ZERO(&cpuset); - CPU_SET(2, &cpuset); - - auto rv = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); - if (rv < 0) { - std::cerr << "affinity: errreur! " << std::strerror(errno); - return 0; - } - - unsigned int default_tx_freq(881000 * 1000), default_rx_freq(926000 * 1000); - unsigned int grx = 20, gtx = 20; - bool tx_flag = false; - pthread_setname_np(pthread_self(), "main"); - convolve_init(); - convert_init(); - sigProcLibSetup(); - initvita(); - - int status = 0; - auto trx = new ms_trx(); - trx->do_auto_gain = true; - - std::vector<std::string> args(argv + 1, argv + argc); - for (auto i = args.begin(); i != args.end(); ++i) { - parsec(args, i, "-r", 1000, &default_rx_freq); - parsec(args, i, "-t", 1000, &default_tx_freq); - parsec(args, i, "-gr", 1, &grx); - parsec(args, i, "-gt", 1, >x); - parsec(args, i, "-tx", &tx_flag); - } - - std::cerr << "usage: " << argv[0] << " <rxfreq in khz, i.e. 926000> [txfreq in khz, i.e. 881000] [TX]" - << std::endl - << "rx" << (argc == 1 ? " (default) " : " ") << default_rx_freq << "hz, tx " << default_tx_freq - << "hz" << std::endl - << "gain rx " << grx << " gain tx " << gtx << std::endl - << (tx_flag ? "##!!## RACH TX ACTIVE ##!!##" : "-- no rach tx --") << std::endl; - - status = trx->init_dev_and_streams(); - if (status < 0) - return status; - trx->tuneRx(default_rx_freq); - trx->tuneTx(default_tx_freq); - trx->setRxGain(grx); - trx->setTxGain(gtx); - - if (status == 0) { - // FIXME: hacks! needs exit flag for detached threads! - - std::thread(rcv_bursts_test, &trx->rxqueue, &trx->mTSC, trx->rxFullScale).detach(); - if (tx_flag) - std::thread(tx_test, trx, &trx->ts_hitter_q, &trx->mTSC).detach(); - trx->start(); - do { - sleep(1); - } while (1); - - trx->stop_threads(); - } - delete trx; - - return status; -} -#endif - int ms_trx::init_dev_and_streams() { int status = 0; diff --git a/Transceiver52M/ms/ms.h b/Transceiver52M/ms/ms.h index 3b97d1b..efccffc 100644 --- a/Transceiver52M/ms/ms.h +++ b/Transceiver52M/ms/ms.h @@ -251,9 +251,7 @@ struct ms_trx : public BASET { // provides bursts to upper rx thread rx_queue_t rxqueue; -#ifdef SYNCTHINGONLY - ts_hitter_q_t ts_hitter_q; -#endif + blade_sample_type *first_sch_buf; blade_sample_type *burst_copy_buffer; diff --git a/Transceiver52M/ms/ms_rx_burst.h b/Transceiver52M/ms/ms_rx_burst.h deleted file mode 100644 index 764a69e..0000000 --- a/Transceiver52M/ms/ms_rx_burst.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once -/* - * (C) 2022 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> - * All Rights Reserved - * - * Author: Eric Wild <ewild@sysmocom.de> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#include "ms.h" - -void rcv_bursts_test(rx_queue_t *q, unsigned int *tsc, int scale);
\ No newline at end of file diff --git a/Transceiver52M/ms/ms_rx_burst_test.cpp b/Transceiver52M/ms/ms_rx_burst_test.cpp deleted file mode 100644 index c3ba4ee..0000000 --- a/Transceiver52M/ms/ms_rx_burst_test.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/* - * (C) 2022 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> - * All Rights Reserved - * - * Author: Eric Wild <ewild@sysmocom.de> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -#include "ms.h" -#include "sigProcLib.h" -#include "signalVector.h" -#include "grgsm_vitac/grgsm_vitac.h" -extern "C" { -#include "sch.h" -} - -#if !defined(SYNCTHINGONLY) || !defined(NODAMNLOG) -#define DBGLG(...) ms_trx::dummy_log() -#else -#define DBGLG(...) std::cerr -#endif - -#if !defined(SYNCTHINGONLY) -#define DBGLG2(...) ms_trx::dummy_log() -#else -#define DBGLG2(...) std::cerr -#endif - -static bool decode_sch(float *bits, bool update_global_clock) -{ - struct sch_info sch; - ubit_t info[GSM_SCH_INFO_LEN]; - sbit_t data[GSM_SCH_CODED_LEN]; - - float_to_sbit(&bits[3], &data[0], 62, 39); - float_to_sbit(&bits[106], &data[39], 62, 39); - - if (!gsm_sch_decode(info, data)) { - gsm_sch_parse(info, &sch); - - DBGLG() << "SCH : Decoded values" << std::endl; - DBGLG() << " BSIC: " << sch.bsic << std::endl; - DBGLG() << " TSC: " << (sch.bsic & 0x7) << std::endl; - DBGLG() << " T1 : " << sch.t1 << std::endl; - DBGLG() << " T2 : " << sch.t2 << std::endl; - DBGLG() << " T3p : " << sch.t3p << std::endl; - DBGLG() << " FN : " << gsm_sch_to_fn(&sch) << std::endl; - return true; - } - return false; -} - -static void check_rcv_fn(GSM::Time t, bool first, unsigned int &lastfn, unsigned int &fnbm) -{ - if (first && t.TN() == 0) { - lastfn = t.FN(); - fnbm = 1 << 0; - first = false; - } - if (!first && t.FN() != (int)lastfn) { - if (fnbm != 255) - std::cerr << "rx " << lastfn << ":" << fnbm << " " << __builtin_popcount(fnbm) << std::endl; - lastfn = t.FN(); - fnbm = 1 << t.TN(); - } - - fnbm |= 1 << t.TN(); -} - -static void handle_it(one_burst &e, signalVector &burst, unsigned int tsc, int scale) -{ - std::fill(burst.begin(), burst.begin() + burst.size(), 0.0); - const auto is_sch = gsm_sch_check_ts(e.gsmts.TN(), e.gsmts.FN()); - const auto is_fcch = gsm_fcch_check_ts(e.gsmts.TN(), e.gsmts.FN()); - - if (is_fcch) - return; - - if (is_sch) { - char outbin[148]; - convert_and_scale(burst.begin(), e.burst, ONE_TS_BURST_LEN * 2, SAMPLE_SCALE_FACTOR); - std::stringstream dbgout; -#if 0 - { - struct estim_burst_params ebp; - auto rv2 = detectSCHBurst(burst, 4, 4, sch_detect_type::SCH_DETECT_FULL, &ebp); - auto bits = demodAnyBurst(burst, SCH, 4, &ebp); - // clamp_array(bits->begin(), 148, 1.5f); - for (auto &i : *bits) - i = (i > 0 ? 1 : -1); - - auto rv = decode_sch(bits->begin(), false); - dbgout << "U DET@" << (rv2 ? "yes " : " ") << "Timing offset " << ebp.toa - << " symbols, DECODE: " << (rv ? "yes" : "---") << " "; - - delete bits; - } -#endif - { - convert_and_scale(burst.begin(), burst.begin(), ONE_TS_BURST_LEN * 2, 1.f / float(scale)); - - std::complex<float> channel_imp_resp[CHAN_IMP_RESP_LENGTH * d_OSR]; - auto ss = reinterpret_cast<std::complex<float> *>(burst.begin()); - int d_c0_burst_start = get_sch_chan_imp_resp(ss, &channel_imp_resp[0]); - detect_burst(ss, &channel_imp_resp[0], d_c0_burst_start, outbin); - - SoftVector bits; - bits.resize(148); - for (int i = 0; i < 148; i++) { - bits[i] = (!outbin[i]); // < 1 ? -1 : 1; - } - - auto rv = decode_sch(bits.begin(), false); - dbgout << "U SCH@" - << " " << e.gsmts.FN() << ":" << e.gsmts.TN() << " " << d_c0_burst_start - << " DECODE:" << (rv ? "yes" : "---") << std::endl; - } - - DBGLG() << dbgout.str(); - return; - } -#if 1 - convert_and_scale(burst.begin(), e.burst, ONE_TS_BURST_LEN * 2, 1.f / float(scale)); - // std::cerr << "@" << tsc << " " << e.gsmts.FN() << ":" << e.gsmts.TN() << " " << ebp.toa << " " - // << std::endl; - - char outbin[148]; - auto ss = reinterpret_cast<std::complex<float> *>(burst.begin()); - float ncmax, dcmax; - std::complex<float> chan_imp_resp[CHAN_IMP_RESP_LENGTH * d_OSR], chan_imp_resp2[CHAN_IMP_RESP_LENGTH * d_OSR]; - auto normal_burst_start = get_norm_chan_imp_resp(ss, &chan_imp_resp[0], &ncmax, tsc); - auto dummy_burst_start = get_norm_chan_imp_resp(ss, &chan_imp_resp2[0], &dcmax, TS_DUMMY); - auto is_nb = ncmax > dcmax; - - DBGLG() << " U " << (is_nb ? "NB" : "DB") << "@ o nb: " << normal_burst_start << " o db: " << dummy_burst_start - << std::endl; - - if (is_nb) - detect_burst(ss, &chan_imp_resp[0], normal_burst_start, outbin); - else - detect_burst(ss, &chan_imp_resp2[0], dummy_burst_start, outbin); - ; -#ifdef DBGXX - // auto bits = SoftVector(148); - // for (int i = 0; i < 148; i++) - // (bits)[i] = outbin[i] < 1 ? -1 : 1; -#endif -#endif -} - -void rcv_bursts_test(rx_queue_t *q, unsigned int *tsc, int scale) -{ - static bool first = true; - unsigned int lastfn = 0; - unsigned int fnbm = 0; - signalVector burst(ONE_TS_BURST_LEN, 100, 100); - - cpu_set_t cpuset; - - CPU_ZERO(&cpuset); - CPU_SET(1, &cpuset); - - auto rv = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); - if (rv < 0) { - std::cerr << "affinity: errreur! " << std::strerror(errno); - exit(0); - } - - int prio = sched_get_priority_max(SCHED_RR); - struct sched_param param; - param.sched_priority = prio; - rv = sched_setscheduler(0, SCHED_RR, ¶m); - if (rv < 0) { - std::cerr << "scheduler: errreur! " << std::strerror(errno); - exit(0); - } - - while (1) { - one_burst e; - while (!q->spsc_pop(&e)) { - q->spsc_prep_pop(); - } - - check_rcv_fn(e.gsmts, first, lastfn, fnbm); - - handle_it(e, burst, *tsc, scale); -#ifdef DBGXX - rv = detectSCHBurst(*burst, 4, 4, sch_detect_type::SCH_DETECT_FULL, &ebp); - if (rv > 0) - std::cerr << "#" << e.gsmts.FN() << ":" << e.gsmts.TN() << " " << ebp.toa << std::endl; - sched_yield(); -#endif - } -}
\ No newline at end of file diff --git a/Transceiver52M/ms/ms_rx_lower.cpp b/Transceiver52M/ms/ms_rx_lower.cpp index 3a7e6ec..992591e 100644 --- a/Transceiver52M/ms/ms_rx_lower.cpp +++ b/Transceiver52M/ms/ms_rx_lower.cpp @@ -38,13 +38,13 @@ extern "C" { #undef LOG #endif -#if !defined(SYNCTHINGONLY) //|| !defined(NODAMNLOG) +#if !defined(NODAMNLOG) #define DBGLG(...) ms_trx::dummy_log() #else #define DBGLG(...) std::cerr #endif -#if !defined(SYNCTHINGONLY) || !defined(NODAMNLOG) +#if !defined(NODAMNLOG) #define DBGLG2(...) ms_trx::dummy_log() #else #define DBGLG2(...) std::cerr @@ -87,18 +87,6 @@ bool ms_trx::decode_sch(float *bits, bool update_global_clock) // global_time_keeper.FN(fn); // global_time_keeper.TN(0); } -#ifdef SYNCTHINGONLY - else { - int t3 = sch.t3p * 10 + 1; - if (t3 == 11) { - // timeslot hitter attempt @ fn 21 in mf - DBGLG2() << "sch @ " << t3 << std::endl; - auto e = GSM::Time(fn, 0); - e += 10; - ts_hitter_q.spsc_push(&e); - } - } -#endif return true; } @@ -153,14 +141,11 @@ bool ms_trx::handle_sch_or_nb() handle_sch(false); memcpy(brst.sch_bits, sch_demod_bits, sizeof(sch_demod_bits)); } -#ifndef SYNCTHINGONLY + if (upper_is_ready) { // this is blocking, so only submit if there is a reader - only if upper exists! -#endif while (!rxqueue.spsc_push(&brst)) ; -#ifndef SYNCTHINGONLY } -#endif if (do_auto_gain) maybe_update_gain(brst); |