Hoernchen has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-trx/+/32762 )

Change subject: transceiver: pass cfg struct instead of args
......................................................................

transceiver: pass cfg struct instead of args

Passing 7 args is a bit much, just pass the config struct instead.

Change-Id: I48386900d15ff4d770c70a4efc246d32f921904b
---
M CommonLibs/trx_vty.c
M Transceiver52M/device/bladerf/bladerf.cpp
M Transceiver52M/device/bladerf/bladerf.h
M Transceiver52M/device/common/radioDevice.h
M Transceiver52M/device/ipc/IPCDevice.cpp
M Transceiver52M/device/ipc/IPCDevice.h
M Transceiver52M/device/ipc/uhdwrap.cpp
M Transceiver52M/device/ipc/uhdwrap.h
M Transceiver52M/device/lms/LMSDevice.cpp
M Transceiver52M/device/lms/LMSDevice.h
M Transceiver52M/device/uhd/UHDDevice.cpp
M Transceiver52M/device/uhd/UHDDevice.h
M Transceiver52M/device/usrp1/USRPDevice.cpp
M Transceiver52M/device/usrp1/USRPDevice.h
M Transceiver52M/osmo-trx.cpp
15 files changed, 161 insertions(+), 180 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, but someone else must approve
  fixeria: Looks good to me, approved




diff --git a/CommonLibs/trx_vty.c b/CommonLibs/trx_vty.c
index ba55f92..6724189 100644
--- a/CommonLibs/trx_vty.c
+++ b/CommonLibs/trx_vty.c
@@ -607,7 +607,7 @@
                vty_out(vty, " remote-ip %s%s", trx->cfg.remote_addr, 
VTY_NEWLINE);
        if (trx->cfg.base_port != DEFAULT_TRX_PORT)
                vty_out(vty, " base-port %u%s", trx->cfg.base_port, 
VTY_NEWLINE);
-       if (trx->cfg.dev_args)
+       if (strlen(trx->cfg.dev_args))
                vty_out(vty, " dev-args %s%s", trx->cfg.dev_args, VTY_NEWLINE);
        if (trx->cfg.tx_sps != DEFAULT_TX_SPS)
                vty_out(vty, " tx-sps %u%s", trx->cfg.tx_sps, VTY_NEWLINE);
@@ -760,6 +760,7 @@
        trx->cfg.rx_sps = DEFAULT_RX_SPS;
        trx->cfg.filler = FILLER_ZERO;
        trx->cfg.rssi_offset = 0.0f;
+       trx->cfg.dev_args = "";

        return trx;
 }
diff --git a/Transceiver52M/device/bladerf/bladerf.cpp 
b/Transceiver52M/device/bladerf/bladerf.cpp
index 4f0110b..3d9aab9 100644
--- a/Transceiver52M/device/bladerf/bladerf.cpp
+++ b/Transceiver52M/device/bladerf/bladerf.cpp
@@ -84,11 +84,10 @@
        return desc.nom_uhd_tx_gain - (desc.nom_out_tx_power - tx_power_dbm);
 }

-blade_device::blade_device(size_t tx_sps, size_t rx_sps, InterfaceType iface, 
size_t chan_num, double lo_offset,
-                          const std::vector<std::string> &tx_paths, const 
std::vector<std::string> &rx_paths)
-       : RadioDevice(tx_sps, rx_sps, iface, chan_num, lo_offset, tx_paths, 
rx_paths), dev(nullptr), rx_gain_min(0.0),
-         rx_gain_max(0.0), band_ass_curr_sess(false), band((enum gsm_band)0), 
tx_spp(0), rx_spp(0), started(false),
-         aligned(false), drop_cnt(0), prev_ts(0), ts_initial(0), ts_offset(0), 
async_event_thrd(NULL)
+blade_device::blade_device(InterfaceType iface, const struct trx_cfg *cfg)
+       : RadioDevice(iface, cfg), dev(nullptr), rx_gain_min(0.0), 
rx_gain_max(0.0), band_ass_curr_sess(false),
+         band((enum gsm_band)0), tx_spp(0), rx_spp(0), started(false), 
aligned(false), drop_cnt(0), prev_ts(0),
+         ts_initial(0), ts_offset(0), async_event_thrd(NULL)
 {
 }

@@ -312,15 +311,15 @@
        return desc.nom_out_tx_power;
 }

-int blade_device::open(const std::string &args, int ref, bool swap_channels)
+int blade_device::open()
 {
        bladerf_log_set_verbosity(BLADERF_LOG_LEVEL_VERBOSE);
        bladerf_set_usb_reset_on_open(true);
-       auto success = bladerf_open(&dev, args.c_str());
+       auto success = bladerf_open(&dev, cfg->dev_args);
        if (success != 0) {
                struct bladerf_devinfo *info;
                auto num_devs = bladerf_get_device_list(&info);
-               LOGC(DDEV, ALERT) << "No bladerf devices found with identifier 
'" << args << "'";
+               LOGC(DDEV, ALERT) << "No bladerf devices found with identifier 
'" << cfg->dev_args << "'";
                if (num_devs) {
                        for (int i = 0; i < num_devs; i++)
                                LOGC(DDEV, ALERT) << "Found device:" << 
info[i].product << " serial " << info[i].serial;
@@ -346,7 +345,7 @@
        rx_gains.resize(chans);
        rx_buffers.resize(chans);

-       switch (ref) {
+       switch (cfg->clock_ref) {
        case REF_INTERNAL:
        case REF_EXTERNAL:
                break;
@@ -355,7 +354,7 @@
                return -1;
        }

-       if (ref == REF_EXTERNAL) {
+       if (cfg->clock_ref == REF_EXTERNAL) {
                bool is_locked;
                int status = bladerf_set_pll_enable(dev, true);
                CHKRET()
@@ -374,7 +373,8 @@
                }
        }

-       LOGC(DDEV, INFO) << "Selected clock source is " << ((ref == 
REF_INTERNAL) ? "internal" : "external 10Mhz");
+       LOGC(DDEV, INFO)
+               << "Selected clock source is " << ((cfg->clock_ref == 
REF_INTERNAL) ? "internal" : "external 10Mhz");

        set_rates();

@@ -687,8 +687,7 @@
        return (double)2047;
 }

-RadioDevice *RadioDevice::make(size_t tx_sps, size_t rx_sps, InterfaceType 
iface, size_t chans, double lo_offset,
-                              const std::vector<std::string> &tx_paths, const 
std::vector<std::string> &rx_paths)
+RadioDevice *RadioDevice::make(InterfaceType type, const struct trx_cfg *cfg)
 {
-       return new blade_device(tx_sps, rx_sps, iface, chans, lo_offset, 
tx_paths, rx_paths);
+       return new blade_device(type, cfg);
 }
diff --git a/Transceiver52M/device/bladerf/bladerf.h 
b/Transceiver52M/device/bladerf/bladerf.h
index 07b7d6a..4db2569 100644
--- a/Transceiver52M/device/bladerf/bladerf.h
+++ b/Transceiver52M/device/bladerf/bladerf.h
@@ -54,11 +54,10 @@

 class blade_device : public RadioDevice {
     public:
-       blade_device(size_t tx_sps, size_t rx_sps, InterfaceType type, size_t 
chan_num, double offset,
-                    const std::vector<std::string> &tx_paths, const 
std::vector<std::string> &rx_paths);
+       blade_device(InterfaceType iface, const struct trx_cfg *cfg);
        ~blade_device();

-       int open(const std::string &args, int ref, bool swap_channels);
+       int open();
        bool start();
        bool stop();
        bool restart();
diff --git a/Transceiver52M/device/common/radioDevice.h 
b/Transceiver52M/device/common/radioDevice.h
index 404ef75..5c962d1 100644
--- a/Transceiver52M/device/common/radioDevice.h
+++ b/Transceiver52M/device/common/radioDevice.h
@@ -51,13 +51,10 @@
     MULTI_ARFCN,
   };

-  static RadioDevice *make(size_t tx_sps, size_t rx_sps, InterfaceType type,
-                           size_t chans = 1, double offset = 0.0,
-                           const std::vector<std::string>& tx_paths = 
std::vector<std::string>(1, ""),
-                           const std::vector<std::string>& rx_paths = 
std::vector<std::string>(1, ""));
+  static RadioDevice *make(InterfaceType type, const struct trx_cfg *cfg);

   /** Initialize the USRP */
-  virtual int open(const std::string &args, int ref, bool swap_channels)=0;
+  virtual int open() = 0;

   virtual ~RadioDevice() { }

@@ -164,23 +161,30 @@
   double lo_offset;
   std::vector<std::string> tx_paths, rx_paths;
   std::vector<struct device_counters> m_ctr;
+  const struct trx_cfg *cfg;

-  RadioDevice(size_t tx_sps, size_t rx_sps, InterfaceType type, size_t 
chan_num, double offset,
-              const std::vector<std::string>& tx_paths,
-              const std::vector<std::string>& rx_paths):
-               tx_sps(tx_sps), rx_sps(rx_sps), iface(type), chans(chan_num), 
lo_offset(offset),
-               tx_paths(tx_paths), rx_paths(rx_paths), m_ctr(chans)
-       {
-               if (iface == MULTI_ARFCN) {
-                       LOGC(DDEV, INFO) << "Multi-ARFCN: "<< chan_num << " 
logical chans -> 1 physical chans";
-                       chans = 1;
-               }
+#define charp2str(a) ((a) ? std::string(a) : std::string(""))

-               for (size_t i = 0; i < chans; i++) {
-                       memset(&m_ctr[i], 0, sizeof(m_ctr[i]));
-                       m_ctr[i].chan = i;
-               }
-       }
+  RadioDevice(InterfaceType type, const struct trx_cfg *cfg)
+         : tx_sps(cfg->tx_sps), rx_sps(cfg->rx_sps), iface(type), 
chans(cfg->num_chans), lo_offset(cfg->offset),
+           m_ctr(chans), cfg(cfg)
+  {
+         /* Generate vector of rx/tx_path: */
+         for (unsigned int i = 0; i < cfg->num_chans; i++) {
+                 rx_paths.push_back(charp2str(cfg->chans[i].rx_path));
+                 tx_paths.push_back(charp2str(cfg->chans[i].tx_path));
+         }
+
+         if (iface == MULTI_ARFCN) {
+                 LOGC(DDEV, INFO) << "Multi-ARFCN: " << chans << " logical 
chans -> 1 physical chans";
+                 chans = 1;
+         }
+
+         for (size_t i = 0; i < chans; i++) {
+                 memset(&m_ctr[i], 0, sizeof(m_ctr[i]));
+                 m_ctr[i].chan = i;
+         }
+  }

   bool set_antennas() {
        unsigned int i;
diff --git a/Transceiver52M/device/ipc/IPCDevice.cpp 
b/Transceiver52M/device/ipc/IPCDevice.cpp
index 4b4ba37..1d2b89a 100644
--- a/Transceiver52M/device/ipc/IPCDevice.cpp
+++ b/Transceiver52M/device/ipc/IPCDevice.cpp
@@ -56,11 +56,10 @@

 static int ipc_chan_sock_cb(struct osmo_fd *bfd, unsigned int flags);

-IPCDevice::IPCDevice(size_t tx_sps, size_t rx_sps, InterfaceType iface, size_t 
chan_num, double lo_offset,
-                    const std::vector<std::string> &tx_paths, const 
std::vector<std::string> &rx_paths)
-       : RadioDevice(tx_sps, rx_sps, iface, chan_num, lo_offset, tx_paths, 
rx_paths), sk_chan_state(chans, ipc_per_trx_sock_state()),
-         tx_attenuation(), tmp_state(IPC_IF_MSG_GREETING_REQ), shm(NULL), 
shm_dec(0),
-         rx_buffers(chans), started(false), tx_gains(chans), rx_gains(chans)
+IPCDevice::IPCDevice(InterfaceType iface, const struct trx_cfg *cfg)
+       : RadioDevice(iface, cfg), sk_chan_state(chans, 
ipc_per_trx_sock_state()), tx_attenuation(),
+         tmp_state(IPC_IF_MSG_GREETING_REQ), shm(NULL), shm_dec(0), 
rx_buffers(chans), started(false), tx_gains(chans),
+         rx_gains(chans)
 {
        LOGC(DDEV, INFO) << "creating IPC device...";

@@ -771,11 +770,12 @@
        return rc;
 }

-int IPCDevice::open(const std::string &args, int ref, bool swap_channels)
+int IPCDevice::open()
 {
        std::string k, v;
        std::string::size_type keyend;
        int rc;
+       std::string args(cfg->dev_args);

        if ((keyend = args.find('=')) != std::string::npos) {
                k = args.substr(0, keyend++);
@@ -810,7 +810,7 @@
        while (tmp_state != IPC_IF_MSG_INFO_CNF)
                osmo_select_main(0);

-       ipc_tx_open_req(&master_sk_state, chans, ref);
+       ipc_tx_open_req(&master_sk_state, chans, cfg->clock_ref);
        /* Wait until confirmation is recieved */
        while (tmp_state != IPC_IF_MSG_OPEN_CNF)
                osmo_select_main(0);
@@ -1259,16 +1259,15 @@
        return send_chan_wait_rsp(chan, msg, IPC_IF_MSG_SETFREQ_CNF);
 }

-RadioDevice *RadioDevice::make(size_t tx_sps, size_t rx_sps, InterfaceType 
iface, size_t chans, double lo_offset,
-                              const std::vector<std::string> &tx_paths, const 
std::vector<std::string> &rx_paths)
+RadioDevice *RadioDevice::make(InterfaceType type, const struct trx_cfg *cfg)
 {
-       if (tx_sps != rx_sps) {
+       if (cfg->tx_sps != cfg->rx_sps) {
                LOGC(DDEV, ERROR) << "IPC Requires tx_sps == rx_sps";
                return NULL;
        }
-       if (lo_offset != 0.0) {
+       if (cfg->offset != 0.0) {
                LOGC(DDEV, ERROR) << "IPC doesn't support lo_offset";
                return NULL;
        }
-       return new IPCDevice(tx_sps, rx_sps, iface, chans, lo_offset, tx_paths, 
rx_paths);
+       return new IPCDevice(type, cfg);
 }
diff --git a/Transceiver52M/device/ipc/IPCDevice.h 
b/Transceiver52M/device/ipc/IPCDevice.h
index f70c95e..0cf3d46 100644
--- a/Transceiver52M/device/ipc/IPCDevice.h
+++ b/Transceiver52M/device/ipc/IPCDevice.h
@@ -115,12 +115,11 @@
        int ipc_chan_sock_write(osmo_fd *bfd);

        /** Object constructor */
-       IPCDevice(size_t tx_sps, size_t rx_sps, InterfaceType iface, size_t 
chan_num, double lo_offset,
-                 const std::vector<std::string> &tx_paths, const 
std::vector<std::string> &rx_paths);
+       IPCDevice(InterfaceType iface, const struct trx_cfg *cfg);
        virtual ~IPCDevice() override;

        /** Instantiate the IPC */
-       virtual int open(const std::string &args, int ref, bool swap_channels) 
override;
+       virtual int open() override;

        /** Start the IPC */
        virtual bool start() override;
diff --git a/Transceiver52M/device/ipc/uhdwrap.cpp 
b/Transceiver52M/device/ipc/uhdwrap.cpp
index d7114da..302f763 100644
--- a/Transceiver52M/device/ipc/uhdwrap.cpp
+++ b/Transceiver52M/device/ipc/uhdwrap.cpp
@@ -35,9 +35,12 @@
 #include "Threads.h"
 #include "Utils.h"

-int uhd_wrap::open(const std::string &args, int ref, bool swap_channels)
+// no vty source for cfg params here, so we have to build our own
+static struct trx_cfg actual_cfg = {};
+
+int uhd_wrap::open()
 {
-       int rv = uhd_device::open(args, ref, swap_channels);
+       int rv = uhd_device::open();
        samps_per_buff_rx = rx_stream->get_max_num_samps();
        samps_per_buff_tx = tx_stream->get_max_num_samps();
        channel_count = usrp_dev->get_rx_num_channels();
@@ -84,36 +87,33 @@

 extern "C" void *uhdwrap_open(struct ipc_sk_if_open_req *open_req)
 {
-       unsigned int rx_sps, tx_sps;
+       actual_cfg.num_chans = open_req->num_chans;
+       actual_cfg.swap_channels = false;
+       /* FIXME: this is actually the sps value, not the sample rate!
+        * sample rate is looked up according to the sps rate by uhd backend */
+       actual_cfg.rx_sps = open_req->rx_sample_freq_num / 
open_req->rx_sample_freq_den;
+       actual_cfg.tx_sps = open_req->tx_sample_freq_num / 
open_req->tx_sample_freq_den;

        /* FIXME: dev arg string* */
        /* FIXME: rx frontend bw? */
        /* FIXME: tx frontend bw? */
-       ReferenceType cref;
        switch (open_req->clockref) {
        case FEATURE_MASK_CLOCKREF_EXTERNAL:
-               cref = ReferenceType::REF_EXTERNAL;
+               actual_cfg.clock_ref = ReferenceType::REF_EXTERNAL;
                break;
        case FEATURE_MASK_CLOCKREF_INTERNAL:
        default:
-               cref = ReferenceType::REF_INTERNAL;
+               actual_cfg.clock_ref = ReferenceType::REF_INTERNAL;
                break;
        }

-       std::vector<std::string> tx_paths;
-       std::vector<std::string> rx_paths;
        for (unsigned int i = 0; i < open_req->num_chans; i++) {
-               tx_paths.push_back(open_req->chan_info[i].tx_path);
-               rx_paths.push_back(open_req->chan_info[i].rx_path);
+               actual_cfg.chans[i].rx_path = open_req->chan_info[i].tx_path;
+               actual_cfg.chans[i].tx_path = open_req->chan_info[i].rx_path;
        }

-       /* FIXME: this is actually the sps value, not the sample rate!
-        * sample rate is looked up according to the sps rate by uhd backend */
-       rx_sps = open_req->rx_sample_freq_num / open_req->rx_sample_freq_den;
-       tx_sps = open_req->tx_sample_freq_num / open_req->tx_sample_freq_den;
-       uhd_wrap *uhd_wrap_dev =
-               new uhd_wrap(tx_sps, rx_sps, RadioDevice::NORMAL, 
open_req->num_chans, 0.0, tx_paths, rx_paths);
-       uhd_wrap_dev->open("", cref, false);
+       uhd_wrap *uhd_wrap_dev = new uhd_wrap(RadioDevice::NORMAL, &actual_cfg);
+       uhd_wrap_dev->open();

        return uhd_wrap_dev;
 }
diff --git a/Transceiver52M/device/ipc/uhdwrap.h 
b/Transceiver52M/device/ipc/uhdwrap.h
index e235fe7..44cd9aa 100644
--- a/Transceiver52M/device/ipc/uhdwrap.h
+++ b/Transceiver52M/device/ipc/uhdwrap.h
@@ -41,7 +41,7 @@

        //    void ipc_sock_close() override {};
        int wrap_read(TIMESTAMP *timestamp);
-       virtual int open(const std::string &args, int ref, bool swap_channels) 
override;
+       virtual int open() override;

        //      bool start() override;
        //      bool stop() override;
diff --git a/Transceiver52M/device/lms/LMSDevice.cpp 
b/Transceiver52M/device/lms/LMSDevice.cpp
index d1ec2e4..e336e77 100644
--- a/Transceiver52M/device/lms/LMSDevice.cpp
+++ b/Transceiver52M/device/lms/LMSDevice.cpp
@@ -131,12 +131,9 @@
        return LMS_DEV_UNKNOWN;
 }

-LMSDevice::LMSDevice(size_t tx_sps, size_t rx_sps, InterfaceType iface, size_t 
chan_num, double lo_offset,
-                    const std::vector<std::string>& tx_paths,
-                    const std::vector<std::string>& rx_paths):
-                    RadioDevice(tx_sps, rx_sps, iface, chan_num, lo_offset, 
tx_paths, rx_paths),
-                    m_lms_dev(NULL), started(false), 
band_ass_curr_sess(false), band((enum gsm_band)0),
-                    m_dev_type(LMS_DEV_UNKNOWN)
+LMSDevice::LMSDevice(InterfaceType iface, const struct trx_cfg *cfg)
+       : RadioDevice(iface, cfg), m_lms_dev(NULL), started(false), 
band_ass_curr_sess(false), band((enum gsm_band)0),
+         m_dev_type(LMS_DEV_UNKNOWN)
 {
        LOGC(DDEV, INFO) << "creating LMS device...";

@@ -264,7 +261,7 @@
        desc = band_desc;
 }

-int LMSDevice::open(const std::string &args, int ref, bool swap_channels)
+int LMSDevice::open()
 {
        lms_info_str_t* info_list;
        lms_range_t range_sr;
@@ -292,9 +289,9 @@
        for (i = 0; i < n; i++)
                LOGC(DDEV, INFO) << "Device [" << i << "]: " << info_list[i];

-       dev_id = info_list_find(info_list, n, args);
+       dev_id = info_list_find(info_list, n, cfg->dev_args);
        if (dev_id == -1) {
-               LOGC(DDEV, ERROR) << "No LMS device found with address '" << 
args << "'";
+               LOGC(DDEV, ERROR) << "No LMS device found with address '" << 
cfg->dev_args << "'";
                delete[] info_list;
                return -1;
        }
@@ -312,13 +309,13 @@
        m_dev_type = parse_dev_type(m_lms_dev);
        dev_desc = dev_param_map.at(m_dev_type);

-       if ((ref != REF_EXTERNAL) && (ref != REF_INTERNAL)){
+       if ((cfg->clock_ref != REF_EXTERNAL) && (cfg->clock_ref != 
REF_INTERNAL)) {
                LOGC(DDEV, ERROR) << "Invalid reference type";
                goto out_close;
        }

        /* if reference clock is external, setup must happen _before_ calling 
LMS_Init */
-       if (ref == REF_EXTERNAL) {
+       if (cfg->clock_ref == REF_EXTERNAL) {
                LOGC(DDEV, INFO) << "Setting External clock reference to 10MHz";
                /* FIXME: Assume an external 10 MHz reference clock. make
                   external reference frequency configurable */
@@ -333,7 +330,7 @@
        }

        /* if reference clock is internal, setup must happen _after_ calling 
LMS_Init */
-       if (ref == REF_INTERNAL) {
+       if (cfg->clock_ref == REF_INTERNAL) {
                LOGC(DDEV, INFO) << "Setting Internal clock reference";
                /* Internal freq param is not used */
                if (!do_clock_src_freq(REF_INTERNAL, 0))
@@ -1060,18 +1057,15 @@
        return true;
 }

-RadioDevice *RadioDevice::make(size_t tx_sps, size_t rx_sps,
-                              InterfaceType iface, size_t chans, double 
lo_offset,
-                              const std::vector < std::string > &tx_paths,
-                              const std::vector < std::string > &rx_paths)
+RadioDevice *RadioDevice::make(InterfaceType type, const struct trx_cfg *cfg)
 {
-       if (tx_sps != rx_sps) {
-               LOGC(DDEV, ERROR) << "LMS Requires tx_sps == rx_sps";
+       if (cfg->tx_sps != cfg->rx_sps) {
+               LOGC(DDEV, ERROR) << "LMS requires tx_sps == rx_sps";
                return NULL;
        }
-       if (lo_offset != 0.0) {
+       if (cfg->offset != 0.0) {
                LOGC(DDEV, ERROR) << "LMS doesn't support lo_offset";
                return NULL;
        }
-       return new LMSDevice(tx_sps, rx_sps, iface, chans, lo_offset, tx_paths, 
rx_paths);
+       return new LMSDevice(type, cfg);
 }
diff --git a/Transceiver52M/device/lms/LMSDevice.h 
b/Transceiver52M/device/lms/LMSDevice.h
index ab28250..75d11cf 100644
--- a/Transceiver52M/device/lms/LMSDevice.h
+++ b/Transceiver52M/device/lms/LMSDevice.h
@@ -107,23 +107,22 @@
 public:

        /** Object constructor */
-       LMSDevice(size_t tx_sps, size_t rx_sps, InterfaceType iface, size_t 
chan_num, double lo_offset,
-                 const std::vector<std::string>& tx_paths,
-                 const std::vector<std::string>& rx_paths);
-       ~LMSDevice();
+    LMSDevice(InterfaceType iface, const struct trx_cfg *cfg);
+    ~LMSDevice();

-       /** Instantiate the LMS */
-       int open(const std::string &args, int ref, bool swap_channels);
+    /** Instantiate the LMS */
+    int open();

-       /** Start the LMS */
-       bool start();
+    /** Start the LMS */
+    bool start();

-       /** Stop the LMS */
-       bool stop();
+    /** Stop the LMS */
+    bool stop();
 
-       enum TxWindowType getWindowType() {
-               return TX_WINDOW_LMS1;
-       }
+    enum TxWindowType getWindowType()
+    {
+           return TX_WINDOW_LMS1;
+    }

        /**
        Read samples from the LMS.
diff --git a/Transceiver52M/device/uhd/UHDDevice.cpp 
b/Transceiver52M/device/uhd/UHDDevice.cpp
index f109660..a0021db 100644
--- a/Transceiver52M/device/uhd/UHDDevice.cpp
+++ b/Transceiver52M/device/uhd/UHDDevice.cpp
@@ -220,15 +220,10 @@
        return desc.nom_uhd_tx_gain - (desc.nom_out_tx_power - tx_power_dbm);
 }

-uhd_device::uhd_device(size_t tx_sps, size_t rx_sps,
-                      InterfaceType iface, size_t chan_num, double lo_offset,
-                      const std::vector<std::string>& tx_paths,
-                      const std::vector<std::string>& rx_paths)
-       : RadioDevice(tx_sps, rx_sps, iface, chan_num, lo_offset, tx_paths, 
rx_paths),
-         rx_gain_min(0.0), rx_gain_max(0.0), band_ass_curr_sess(false),
-         band((enum gsm_band)0), tx_spp(0), rx_spp(0),
-         started(false), aligned(false), drop_cnt(0),
-         prev_ts(0,0), ts_initial(0), ts_offset(0), async_event_thrd(NULL)
+uhd_device::uhd_device(InterfaceType iface, const struct trx_cfg *cfg)
+       : RadioDevice(iface, cfg), rx_gain_min(0.0), rx_gain_max(0.0), 
band_ass_curr_sess(false),
+         band((enum gsm_band)0), tx_spp(0), rx_spp(0), started(false), 
aligned(false), drop_cnt(0), prev_ts(0, 0),
+         ts_initial(0), ts_offset(0), async_event_thrd(NULL)
 {
 }

@@ -548,7 +543,7 @@
        }
 }

-int uhd_device::open(const std::string &args, int ref, bool swap_channels)
+int uhd_device::open()
 {
        const char *refstr;
        int clock_lock_attempts = 15;
@@ -564,10 +559,10 @@
 #endif

        // Find UHD devices
-       uhd::device_addr_t addr(args);
+       uhd::device_addr_t addr(cfg->dev_args);
        uhd::device_addrs_t dev_addrs = uhd::device::find(addr);
        if (dev_addrs.size() == 0) {
-               LOGC(DDEV, ALERT) << "No UHD devices found with address '" << 
args << "'";
+               LOGC(DDEV, ALERT) << "No UHD devices found with address '" << 
cfg->dev_args << "'";
                return -1;
        }

@@ -576,7 +571,7 @@
        try {
                usrp_dev = uhd::usrp::multi_usrp::make(addr);
        } catch(uhd::key_error::exception &e) {
-               LOGC(DDEV, ALERT) << "UHD make failed, device " << args << ", 
exception:\n" << e.what();
+               LOGC(DDEV, ALERT) << "UHD make failed, device " << 
cfg->dev_args << ", exception:\n" << e.what();
                return -1;
        }

@@ -590,8 +585,8 @@
        }

        try {
-               set_channels(swap_channels);
-        } catch (const std::exception &e) {
+               set_channels(cfg->swap_channels);
+       } catch (const std::exception &e) {
                LOGC(DDEV, ALERT) << "Channel setting failed - " << e.what();
                return -1;
        }
@@ -607,7 +602,7 @@
        rx_gains.resize(chans);
        rx_buffers.resize(chans);

-       switch (ref) {
+       switch (cfg->clock_ref) {
        case REF_INTERNAL:
                refstr = "internal";
                break;
@@ -1378,11 +1373,8 @@
 }

 #ifndef IPCMAGIC
-RadioDevice *RadioDevice::make(size_t tx_sps, size_t rx_sps,
-                              InterfaceType iface, size_t chans, double 
lo_offset,
-                              const std::vector<std::string>& tx_paths,
-                              const std::vector<std::string>& rx_paths)
+RadioDevice *RadioDevice::make(InterfaceType type, const struct trx_cfg *cfg)
 {
-       return new uhd_device(tx_sps, rx_sps, iface, chans, lo_offset, 
tx_paths, rx_paths);
+       return new uhd_device(type, cfg);
 }
 #endif
diff --git a/Transceiver52M/device/uhd/UHDDevice.h 
b/Transceiver52M/device/uhd/UHDDevice.h
index 659fd18..299d98c 100644
--- a/Transceiver52M/device/uhd/UHDDevice.h
+++ b/Transceiver52M/device/uhd/UHDDevice.h
@@ -80,17 +80,17 @@
 */
 class uhd_device : public RadioDevice {
 public:
-       uhd_device(size_t tx_sps, size_t rx_sps, InterfaceType type,
-                  size_t chan_num, double offset,
-                  const std::vector<std::string>& tx_paths,
-                  const std::vector<std::string>& rx_paths);
-       ~uhd_device();
+    uhd_device(InterfaceType iface, const struct trx_cfg *cfg);
+    ~uhd_device();

-       int open(const std::string &args, int ref, bool swap_channels);
-       bool start();
-       bool stop();
-       bool restart();
-       enum TxWindowType getWindowType() { return tx_window; }
+    int open();
+    bool start();
+    bool stop();
+    bool restart();
+    enum TxWindowType getWindowType()
+    {
+           return tx_window;
+    }

        int readSamples(std::vector<short *> &bufs, int len, bool *overrun,
                        TIMESTAMP timestamp, bool *underrun);
diff --git a/Transceiver52M/device/usrp1/USRPDevice.cpp 
b/Transceiver52M/device/usrp1/USRPDevice.cpp
index 852b715..63a9bcc 100644
--- a/Transceiver52M/device/usrp1/USRPDevice.cpp
+++ b/Transceiver52M/device/usrp1/USRPDevice.cpp
@@ -60,11 +60,7 @@

 const double USRPDevice::masterClockRate = 52.0e6;

-USRPDevice::USRPDevice(size_t tx_sps, size_t rx_sps, InterfaceType iface,
-                      size_t chan_num, double lo_offset,
-                      const std::vector<std::string>& tx_paths,
-                      const std::vector<std::string>& rx_paths):
-               RadioDevice(tx_sps, rx_sps, iface, chan_num, lo_offset, 
tx_paths, rx_paths)
+USRPDevice::USRPDevice(InterfaceType iface, const struct trx_cfg *cfg) : 
RadioDevice(iface, cfg)
 {
   LOGC(DDEV, INFO) << "creating USRP device...";

@@ -94,7 +90,7 @@
 #endif
 }

-int USRPDevice::open(const std::string &, int, bool)
+int USRPDevice::open()
 {
   writeLock.unlock();

@@ -658,22 +654,19 @@
 bool USRPDevice::setRxFreq(double wFreq) { return true;};
 #endif

-RadioDevice *RadioDevice::make(size_t tx_sps, size_t rx_sps,
-                              InterfaceType iface, size_t chans, double 
lo_offset,
-                              const std::vector<std::string>& tx_paths,
-                              const std::vector<std::string>& rx_paths)
+RadioDevice *RadioDevice::make(InterfaceType type, const struct trx_cfg *cfg)
 {
-       if (tx_sps != rx_sps) {
-               LOGC(DDEV, ERROR) << "USRP1 requires tx_sps == rx_sps";
-               return NULL;
-       }
-       if (chans != 1) {
-               LOGC(DDEV, ERROR) << "USRP1 supports only 1 channel";
-               return NULL;
-       }
-       if (lo_offset != 0.0) {
-               LOGC(DDEV, ERROR) << "USRP1 doesn't support lo_offset";
-               return NULL;
-       }
-       return new USRPDevice(tx_sps, rx_sps, iface, chans, lo_offset, 
tx_paths, rx_paths);
+  if (cfg->tx_sps != cfg->rx_sps) {
+    LOGC(DDEV, ERROR) << "USRP1 requires tx_sps == rx_sps";
+    return NULL;
+  }
+  if (cfg->num_chans != 1) {
+    LOGC(DDEV, ERROR) << "USRP1 supports only 1 channel";
+    return NULL;
+  }
+  if (cfg->offset != 0.0) {
+    LOGC(DDEV, ERROR) << "USRP1 doesn't support lo_offset";
+    return NULL;
+  }
+  return new USRPDevice(type, cfg);
 }
diff --git a/Transceiver52M/device/usrp1/USRPDevice.h 
b/Transceiver52M/device/usrp1/USRPDevice.h
index aa8dc69..4957ee6 100644
--- a/Transceiver52M/device/usrp1/USRPDevice.h
+++ b/Transceiver52M/device/usrp1/USRPDevice.h
@@ -104,20 +104,21 @@
  public:

   /** Object constructor */
-  USRPDevice(size_t tx_sps, size_t rx_sps, InterfaceType iface, size_t 
chan_num, double lo_offset,
-               const std::vector<std::string>& tx_paths,
-               const std::vector<std::string>& rx_paths);
+     USRPDevice(InterfaceType iface, const struct trx_cfg *cfg);

-  /** Instantiate the USRP */
-  int open(const std::string &, int, bool);
+     /** Instantiate the USRP */
+     int open();

-  /** Start the USRP */
-  bool start();
+     /** Start the USRP */
+     bool start();

-  /** Stop the USRP */
-  bool stop();
+     /** Stop the USRP */
+     bool stop();

-  enum TxWindowType getWindowType() { return TX_WINDOW_USRP1; }
+     enum TxWindowType getWindowType()
+     {
+            return TX_WINDOW_USRP1;
+     }

   /**
        Read samples from the USRP.
diff --git a/Transceiver52M/osmo-trx.cpp b/Transceiver52M/osmo-trx.cpp
index ad41338..89a577b 100644
--- a/Transceiver52M/osmo-trx.cpp
+++ b/Transceiver52M/osmo-trx.cpp
@@ -571,24 +571,14 @@
 static int trx_start(struct trx_ctx *trx)
 {
        int type, chans;
-       unsigned int i;
-       std::vector<std::string> rx_paths, tx_paths;
        RadioDevice::InterfaceType iface = RadioDevice::NORMAL;

        /* Create the low level device object */
        if (trx->cfg.multi_arfcn)
                iface = RadioDevice::MULTI_ARFCN;

-       /* Generate vector of rx/tx_path: */
-       for (i = 0; i < trx->cfg.num_chans; i++) {
-               rx_paths.push_back(charp2str(trx->cfg.chans[i].rx_path));
-               tx_paths.push_back(charp2str(trx->cfg.chans[i].tx_path));
-       }
-
-       usrp = RadioDevice::make(trx->cfg.tx_sps, trx->cfg.rx_sps, iface,
-                                trx->cfg.num_chans, trx->cfg.offset,
-                                tx_paths, rx_paths);
-       type = usrp->open(charp2str(trx->cfg.dev_args), trx->cfg.clock_ref, 
trx->cfg.swap_channels);
+       usrp = RadioDevice::make(iface, &trx->cfg);
+       type = usrp->open();
        if (type < 0) {
                LOG(ALERT) << "Failed to create radio device" << std::endl;
                goto shutdown;

--
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/32762
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Change-Id: I48386900d15ff4d770c70a4efc246d32f921904b
Gerrit-Change-Number: 32762
Gerrit-PatchSet: 4
Gerrit-Owner: Hoernchen <[email protected]>
Gerrit-Reviewer: Hoernchen <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-CC: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to