diff options
author | Eric <ewild@sysmocom.de> | 2020-04-19 23:53:00 +0200 |
---|---|---|
committer | Eric <ewild@sysmocom.de> | 2020-04-20 00:02:50 +0200 |
commit | ac857587632392dfc6da5b9eec1f903cd1ce4971 (patch) | |
tree | 00d6f5c8c955bc9c3ec78242ff3fac917b796661 | |
parent | a1d2b1f8229a7953034ce5bf81682e55eb283617 (diff) |
spawn the client as a thread
Change-Id: I86cd659e74ebdbf43c4352e83e5adb78f8fe6de5
-rw-r--r-- | Transceiver52M/device/ipc/IPCDevice.cpp | 16 | ||||
-rw-r--r-- | Transceiver52M/device/ipc/IPCDevice.h | 74 | ||||
-rw-r--r-- | Transceiver52M/device/ipc/Makefile.am | 4 | ||||
-rw-r--r-- | Transceiver52M/device/ipc/ipc-driver-test.c | 8 | ||||
-rw-r--r-- | Transceiver52M/device/ipc/ipcb210.cpp | 26 | ||||
-rw-r--r-- | Transceiver52M/device/ipc/ipcb210.h | 24 | ||||
-rw-r--r-- | Transceiver52M/device/ipc/magicwrap.cpp | 20 | ||||
-rw-r--r-- | Transceiver52M/device/ipc/magicwrap.h | 14 |
8 files changed, 131 insertions, 55 deletions
diff --git a/Transceiver52M/device/ipc/IPCDevice.cpp b/Transceiver52M/device/ipc/IPCDevice.cpp index 5b05e3d..1c04558 100644 --- a/Transceiver52M/device/ipc/IPCDevice.cpp +++ b/Transceiver52M/device/ipc/IPCDevice.cpp @@ -724,18 +724,4 @@ bool IPCDevice::setRxFreq(double wFreq, size_t chan) 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) -{ - if (tx_sps != rx_sps) { - LOGC(DDEV, ERROR) << "IPC Requires tx_sps == rx_sps"; - return NULL; - } - if (lo_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); -} + diff --git a/Transceiver52M/device/ipc/IPCDevice.h b/Transceiver52M/device/ipc/IPCDevice.h index 934bc54..c7a2a1b 100644 --- a/Transceiver52M/device/ipc/IPCDevice.h +++ b/Transceiver52M/device/ipc/IPCDevice.h @@ -77,28 +77,28 @@ private: bool do_clock_src_freq(enum ReferenceType ref, double freq); public: - void ipc_sock_close(); - int ipc_sock_read(struct osmo_fd *bfd); - int ipc_sock_write(struct osmo_fd *bfd); - int ipc_rx(uint8_t msg_type, struct ipc_sk_if *ipc_prim); - int ipc_rx_greeting_cnf(const struct ipc_sk_if_greeting *greeting_cnf); - int ipc_rx_info_cnf(const struct ipc_sk_if_info_cnf *info_cnf); - int ipc_rx_open_cnf(const struct ipc_sk_if_open_cnf *open_cnf); + virtual void ipc_sock_close(); + virtual int ipc_sock_read(struct osmo_fd *bfd); + virtual int ipc_sock_write(struct osmo_fd *bfd); + virtual int ipc_rx(uint8_t msg_type, struct ipc_sk_if *ipc_prim); + virtual int ipc_rx_greeting_cnf(const struct ipc_sk_if_greeting *greeting_cnf); + virtual int ipc_rx_info_cnf(const struct ipc_sk_if_info_cnf *info_cnf); + virtual int ipc_rx_open_cnf(const struct ipc_sk_if_open_cnf *open_cnf); /** 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(); + virtual ~IPCDevice(); /** Instantiate the LMS */ - int open(const std::string &args, int ref, bool swap_channels); + virtual int open(const std::string &args, int ref, bool swap_channels); /** Start the LMS */ - bool start(); + virtual bool start(); /** Stop the LMS */ - bool stop(); + virtual bool stop(); enum TxWindowType getWindowType() { return TX_WINDOW_LMS1; @@ -113,7 +113,7 @@ public: @param underrun Set if LMS does not have data to transmit, e.g. data not being sent fast enough @return The number of samples actually read */ - int readSamples(std::vector < short *>&buf, int len, bool * overrun, + virtual int readSamples(std::vector < short *>&buf, int len, bool * overrun, TIMESTAMP timestamp = 0xffffffff, bool * underrun = NULL); /** @@ -124,93 +124,93 @@ public: @param timestamp The timestamp of the first sample of the data buffer. @return The number of samples actually written */ - int writeSamples(std::vector < short *>&bufs, int len, bool * underrun, + virtual int writeSamples(std::vector < short *>&bufs, int len, bool * underrun, TIMESTAMP timestamp = 0xffffffff); /** Update the alignment between the read and write timestamps */ - bool updateAlignment(TIMESTAMP timestamp); + virtual bool updateAlignment(TIMESTAMP timestamp); /** Set the transmitter frequency */ - bool setTxFreq(double wFreq, size_t chan = 0); + virtual bool setTxFreq(double wFreq, size_t chan = 0); /** Set the receiver frequency */ - bool setRxFreq(double wFreq, size_t chan = 0); + virtual bool setRxFreq(double wFreq, size_t chan = 0); /** Returns the starting write Timestamp*/ - TIMESTAMP initialWriteTimestamp(void) { + virtual TIMESTAMP initialWriteTimestamp(void) { return ts_initial; } /** Returns the starting read Timestamp*/ - TIMESTAMP initialReadTimestamp(void) { + virtual TIMESTAMP initialReadTimestamp(void) { return ts_initial; } /** returns the full-scale transmit amplitude **/ - double fullScaleInputValue() { + virtual double fullScaleInputValue() { #define LIMESDR_TX_AMPL 0.3 return(double) SHRT_MAX * LIMESDR_TX_AMPL; } /** returns the full-scale receive amplitude **/ - double fullScaleOutputValue() { + virtual double fullScaleOutputValue() { return (double) SHRT_MAX; } /** sets the receive chan gain, returns the gain setting **/ - double setRxGain(double dB, size_t chan = 0); + virtual double setRxGain(double dB, size_t chan = 0); /** get the current receive gain */ - double getRxGain(size_t chan = 0) { + virtual double getRxGain(size_t chan = 0) { return rx_gains[chan]; } /** return maximum Rx Gain **/ - double maxRxGain(void); + virtual double maxRxGain(void); /** return minimum Rx Gain **/ - double minRxGain(void); + virtual double minRxGain(void); /** sets the transmit chan gain, returns the gain setting **/ - double setTxGain(double dB, size_t chan = 0); + virtual double setTxGain(double dB, size_t chan = 0); /** get transmit gain */ - double getTxGain(size_t chan = 0) { + virtual double getTxGain(size_t chan = 0) { return tx_gains[chan]; } /** return maximum Tx Gain **/ - double maxTxGain(void); + virtual double maxTxGain(void); /** return minimum Rx Gain **/ - double minTxGain(void); + virtual double minTxGain(void); /** sets the RX path to use, returns true if successful and false otherwise */ - bool setRxAntenna(const std::string & ant, size_t chan = 0); + virtual bool setRxAntenna(const std::string & ant, size_t chan = 0); /* return the used RX path */ - std::string getRxAntenna(size_t chan = 0); + virtual std::string getRxAntenna(size_t chan = 0); /** sets the RX path to use, returns true if successful and false otherwise */ - bool setTxAntenna(const std::string & ant, size_t chan = 0); + virtual bool setTxAntenna(const std::string & ant, size_t chan = 0); /* return the used RX path */ - std::string getTxAntenna(size_t chan = 0); + virtual std::string getTxAntenna(size_t chan = 0); /** return whether user drives synchronization of Tx/Rx of USRP */ - bool requiresRadioAlign(); + virtual bool requiresRadioAlign(); /** return whether user drives synchronization of Tx/Rx of USRP */ - virtual GSM::Time minLatency(); + virtual GSM::Time minLatency(); /** Return internal status values */ - inline double getTxFreq(size_t chan = 0) { + virtual inline double getTxFreq(size_t chan = 0) { return 0; } - inline double getRxFreq(size_t chan = 0) { + virtual inline double getRxFreq(size_t chan = 0) { return 0; } - inline double getSampleRate() { + virtual inline double getSampleRate() { return actualSampleRate; } }; diff --git a/Transceiver52M/device/ipc/Makefile.am b/Transceiver52M/device/ipc/Makefile.am index 84f8602..40146f7 100644 --- a/Transceiver52M/device/ipc/Makefile.am +++ b/Transceiver52M/device/ipc/Makefile.am @@ -5,11 +5,11 @@ AM_CFLAGS = -lpthread $(LIBOSMOCORE_CFLAGS) $(LIBOSMOCTRL_CFLAGS) $(LIBOSMOVTY_C AM_CXXFLAGS = -lpthread $(LIBOSMOCORE_CFLAGS) $(LIBOSMOCTRL_CFLAGS) $(LIBOSMOVTY_CFLAGS) AM_LDFLAGS = -lpthread -lrt -noinst_HEADERS = IPCDevice.h shm.h +noinst_HEADERS = IPCDevice.h shm.h ipcb210.h magicwrap.h noinst_LTLIBRARIES = libdevice.la -libdevice_la_SOURCES = IPCDevice.cpp shm.c +libdevice_la_SOURCES = ipcb210.cpp IPCDevice.cpp shm.c magicwrap.cpp libdevice_la_LIBADD = $(top_builddir)/Transceiver52M/device/common/libdevice_common.la diff --git a/Transceiver52M/device/ipc/ipc-driver-test.c b/Transceiver52M/device/ipc/ipc-driver-test.c index a342603..55a8a09 100644 --- a/Transceiver52M/device/ipc/ipc-driver-test.c +++ b/Transceiver52M/device/ipc/ipc-driver-test.c @@ -492,8 +492,14 @@ int ipc_sock_init(const char *path) return 0; } - +#ifdef IPCMAGIC +extern "C" int osmo_ctx_init ( const char * id ); +int magicmain(int argc, char** argv) { + osmo_ctx_init("main"); + osmo_select_init(); +#else int main(int argc, char** argv) { +#endif tall_ctx = talloc_named_const(NULL, 0, "OsmoTRX"); msgb_talloc_ctx_init(tall_ctx, 0); osmo_init_logging2(tall_ctx, &log_info); diff --git a/Transceiver52M/device/ipc/ipcb210.cpp b/Transceiver52M/device/ipc/ipcb210.cpp new file mode 100644 index 0000000..7d030bb --- /dev/null +++ b/Transceiver52M/device/ipc/ipcb210.cpp @@ -0,0 +1,26 @@ +#include "ipcb210.h" + +#include "trx_vty.h" +#include "Logger.h" +#include "Threads.h" +#include "Utils.h" +#include "IPCDevice.h" + + + + +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) +{ + if (tx_sps != rx_sps) { + LOGC(DDEV, ERROR) << "IPC Requires tx_sps == rx_sps"; + return NULL; + } + if (lo_offset != 0.0) { + LOGC(DDEV, ERROR) << "IPC doesn't support lo_offset"; + return NULL; + } + return new IPC_b210(tx_sps, rx_sps, iface, chans, lo_offset, tx_paths, rx_paths); +} diff --git a/Transceiver52M/device/ipc/ipcb210.h b/Transceiver52M/device/ipc/ipcb210.h new file mode 100644 index 0000000..fbcf1da --- /dev/null +++ b/Transceiver52M/device/ipc/ipcb210.h @@ -0,0 +1,24 @@ +#ifndef IPC_B210_H +#define IPC_B210_H + +#include "magicwrap.h" +#include "IPCDevice.h" +#include "../uhd/UHDDevice.h" + + + + +class IPC_b210 : public IPCDevice { + magicwrap m; + public: + template<typename... Args> + IPC_b210(Args... args): IPCDevice(args...){ + //drvtest::main(0,0); + } + virtual ~IPC_b210() {}; + + int foo(){return 32;} +// void ipc_sock_close() override {}; +}; + +#endif // IPC_B210_H diff --git a/Transceiver52M/device/ipc/magicwrap.cpp b/Transceiver52M/device/ipc/magicwrap.cpp new file mode 100644 index 0000000..bc4eb26 --- /dev/null +++ b/Transceiver52M/device/ipc/magicwrap.cpp @@ -0,0 +1,20 @@ +//has to come first outside of NS, or wrapping of c headers fails due to wrong order +#include <cstdlib> +#include <chrono> +#include "magicwrap.h" + +namespace drvtest +{ +extern "C" { +#define IPCMAGIC +#include "ipc-driver-test.c" +} +} // namespace drvtest + +char *argv[] = { { "magic" } }; +magicwrap::magicwrap() +{ + t = new std::thread([] { drvtest::magicmain(1, argv); }); + // give the thread some time to start and set up + std::this_thread::sleep_for(std::chrono::seconds(1)); +} diff --git a/Transceiver52M/device/ipc/magicwrap.h b/Transceiver52M/device/ipc/magicwrap.h new file mode 100644 index 0000000..2aa6d23 --- /dev/null +++ b/Transceiver52M/device/ipc/magicwrap.h @@ -0,0 +1,14 @@ +#ifndef MAGICWRAP_H +#define MAGICWRAP_H + +#include <thread> + + +class magicwrap +{ + std::thread* t; +public: + magicwrap(); +}; + +#endif // MAGICWRAP_H |