From 22b6ea2e3976aac6d838552aeb108ae8851c6c32 Mon Sep 17 00:00:00 2001 From: Ron Unrau Date: Mon, 30 Jan 2023 13:56:04 -0700 Subject: [PATCH 1/5] python bindings: add ability to change receiver --- src/bindings/python/pycsp.c | 30 ++++++++++++++++++++++++++++-- wscript | 3 ++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/bindings/python/pycsp.c b/src/bindings/python/pycsp.c index 17d7ec97a..22e4bd2fd 100644 --- a/src/bindings/python/pycsp.c +++ b/src/bindings/python/pycsp.c @@ -878,6 +878,9 @@ static PyObject* pycsp_sband_init(PyObject *self, PyObject *args) { } +static sdr_interface_data_t *uhf_ifdata; +static sdr_conf_t sdr_conf_backup; + static PyObject* pycsp_uhf_init(PyObject *self, PyObject *args) { char* device; uint32_t uart_baudrate = 0; @@ -889,15 +892,36 @@ static PyObject* pycsp_uhf_init(PyObject *self, PyObject *args) { } sdr_conf_t sdr_conf = {0}; + csp_iface_t *uhf_iface; sdr_conf.use_fec = use_fec; sdr_conf.uhf_conf.uhf_baudrate = uhf_baudrate; sdr_conf.uhf_conf.uart_baudrate = uart_baudrate; sdr_conf.uhf_conf.device_file = device; - int res = csp_sdr_open_and_add_interface(&sdr_conf, if_name, NULL); + int res = csp_sdr_open_and_add_interface(&sdr_conf, if_name, &uhf_iface); if (res != CSP_ERR_NONE) { return PyErr_Error("csp_sdr_open_and_add_interface()", res); } + uhf_ifdata = (sdr_interface_data_t *) uhf_iface->interface_data; + sdr_conf_backup.rx_callback = uhf_ifdata->sdr_conf->rx_callback; + sdr_conf_backup.rx_callback_data = uhf_ifdata->sdr_conf->rx_callback_data; + + Py_RETURN_NONE; +} + +void sdr_rx_fwd_init(sdr_interface_data_t*); + +static PyObject* pycsp_set_sdr_rx(PyObject *self, PyObject *args) { + fprintf(stderr, "setting SDR RX (current cb %p)\n", uhf_ifdata->sdr_conf->rx_callback); + sdr_rx_fwd_init(uhf_ifdata); + Py_RETURN_NONE; +} + +static PyObject* pycsp_set_backup_rx(PyObject *self, PyObject *args) { + fprintf(stderr, "set OLD RX\n"); + uhf_ifdata->sdr_conf->rx_callback = sdr_conf_backup.rx_callback; + uhf_ifdata->sdr_conf->rx_callback_data = sdr_conf_backup.rx_callback_data; + Py_RETURN_NONE; } @@ -1016,7 +1040,9 @@ static PyMethodDef methods[] = { {"kiss_init", pycsp_kiss_init, METH_VARARGS, ""}, {"sdr_init", pycsp_sdr_init, METH_VARARGS, ""}, {"uhf_init", pycsp_uhf_init, METH_VARARGS, ""}, - {"sband_init", pycsp_sband_init, METH_VARARGS, ""}, + {"sband_init", pycsp_sband_init, METH_VARARGS, ""}, + {"set_sdr_rx", pycsp_set_sdr_rx, METH_VARARGS, ""}, + {"set_backup_rx", pycsp_set_backup_rx, METH_VARARGS, ""}, /* csp/drivers/can_socketcan.h */ diff --git a/wscript b/wscript index 86844af68..c02035dcd 100644 --- a/wscript +++ b/wscript @@ -103,7 +103,7 @@ def configure(ctx): # Setup CFLAGS if (len(ctx.stack_path) <= 1) and (len(ctx.env.CFLAGS) == 0): - ctx.env.prepend_value('CFLAGS', ["-std=gnu99", "-g", "-Os", "-Wall", "-Wextra", "-Wshadow", "-Wcast-align", + ctx.env.prepend_value('CFLAGS', ["-std=gnu99", "-g", "-O3", "-Wall", "-Wextra", "-Wshadow", "-Wcast-align", "-Wwrite-strings", "-Wno-unused-parameter", "-Werror", "-lstdc++", "-fPIC"]) # Setup default include path and any extra defined @@ -167,6 +167,7 @@ def configure(ctx): 'ex2_sdr/lib/driver/fec.c', 'ex2_sdr/lib/driver/sdr_init.c', 'ex2_sdr/lib/driver/gnuradio.c', + 'ex2_sdr/lib/driver/sdr_rx_fwd.c', 'ex2_sdr/lib/wrapper/MACWrapper.cpp', 'ex2_sdr/lib/error_control/error_correction.cpp', 'ex2_sdr/lib/error_control/ConvolutionalCodecHD.cpp', From 06ee243028570b8c1ff836e2414b254ec4ff78a0 Mon Sep 17 00:00:00 2001 From: Ron Unrau Date: Sat, 18 Feb 2023 10:34:42 -0700 Subject: [PATCH 2/5] pycsp.c: don't need to reset RX callback anymore --- src/bindings/python/pycsp.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/bindings/python/pycsp.c b/src/bindings/python/pycsp.c index 22e4bd2fd..ff430c3dd 100644 --- a/src/bindings/python/pycsp.c +++ b/src/bindings/python/pycsp.c @@ -879,7 +879,6 @@ static PyObject* pycsp_sband_init(PyObject *self, PyObject *args) { } static sdr_interface_data_t *uhf_ifdata; -static sdr_conf_t sdr_conf_backup; static PyObject* pycsp_uhf_init(PyObject *self, PyObject *args) { char* device; @@ -903,8 +902,6 @@ static PyObject* pycsp_uhf_init(PyObject *self, PyObject *args) { } uhf_ifdata = (sdr_interface_data_t *) uhf_iface->interface_data; - sdr_conf_backup.rx_callback = uhf_ifdata->sdr_conf->rx_callback; - sdr_conf_backup.rx_callback_data = uhf_ifdata->sdr_conf->rx_callback_data; Py_RETURN_NONE; } @@ -917,14 +914,6 @@ static PyObject* pycsp_set_sdr_rx(PyObject *self, PyObject *args) { Py_RETURN_NONE; } -static PyObject* pycsp_set_backup_rx(PyObject *self, PyObject *args) { - fprintf(stderr, "set OLD RX\n"); - uhf_ifdata->sdr_conf->rx_callback = sdr_conf_backup.rx_callback; - uhf_ifdata->sdr_conf->rx_callback_data = sdr_conf_backup.rx_callback_data; - - Py_RETURN_NONE; -} - static PyObject* pycsp_sdr_init(PyObject *self, PyObject *args) { return pycsp_uhf_init(self, args); } @@ -1042,8 +1031,6 @@ static PyMethodDef methods[] = { {"uhf_init", pycsp_uhf_init, METH_VARARGS, ""}, {"sband_init", pycsp_sband_init, METH_VARARGS, ""}, {"set_sdr_rx", pycsp_set_sdr_rx, METH_VARARGS, ""}, - {"set_backup_rx", pycsp_set_backup_rx, METH_VARARGS, ""}, - /* csp/drivers/can_socketcan.h */ {"can_socketcan_init", pycsp_can_socketcan_init, METH_VARARGS, ""}, From 225fa5c89a7b63e3364ce2956fb3ff03c5ec9a7d Mon Sep 17 00:00:00 2001 From: Ron Unrau Date: Sat, 18 Feb 2023 10:35:08 -0700 Subject: [PATCH 3/5] wscript: add codec2 library --- wscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wscript b/wscript index c02035dcd..1b4e45d73 100644 --- a/wscript +++ b/wscript @@ -114,7 +114,7 @@ def configure(ctx): # Platform/OS specifics if ctx.options.with_os == 'posix': - ctx.env.append_unique('LIBS', ['rt', 'pthread', 'util']) + ctx.env.append_unique('LIBS', ['rt', 'pthread', 'util', 'codec2']) elif ctx.options.with_os == 'macosx': ctx.env.append_unique('LIBS', ['pthread']) elif ctx.options.with_os == 'windows': From b97b82e56b635fe67477daa5c8a83be3c11b9f62 Mon Sep 17 00:00:00 2001 From: Ron Unrau Date: Tue, 21 Feb 2023 09:17:35 -0700 Subject: [PATCH 4/5] pycsp.c: set_sdr_rx tweaks --- src/bindings/python/pycsp.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/bindings/python/pycsp.c b/src/bindings/python/pycsp.c index ff430c3dd..91e0e9269 100644 --- a/src/bindings/python/pycsp.c +++ b/src/bindings/python/pycsp.c @@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #include #include @@ -878,6 +879,7 @@ static PyObject* pycsp_sband_init(PyObject *self, PyObject *args) { } +// Used by sdr_rx_fwd_init static sdr_interface_data_t *uhf_ifdata; static PyObject* pycsp_uhf_init(PyObject *self, PyObject *args) { @@ -906,11 +908,16 @@ static PyObject* pycsp_uhf_init(PyObject *self, PyObject *args) { Py_RETURN_NONE; } -void sdr_rx_fwd_init(sdr_interface_data_t*); - static PyObject* pycsp_set_sdr_rx(PyObject *self, PyObject *args) { - fprintf(stderr, "setting SDR RX (current cb %p)\n", uhf_ifdata->sdr_conf->rx_callback); - sdr_rx_fwd_init(uhf_ifdata); + /* The forwarder argument can be used (eventually) to exercise different + * forwarder apps. + */ + int forwarder = 0; + if (!PyArg_ParseTuple(args, "|I", &forwarder)) { + return NULL; // TypeError is thrown + } + + sdr_rx_fwd_init(uhf_ifdata, NULL); Py_RETURN_NONE; } @@ -1155,4 +1162,3 @@ PyMODINIT_FUNC PyInit_libcsp_py3(void) { return m; } - From b3e169cd2984e9aaeaad926af7a31342b9b71dff Mon Sep 17 00:00:00 2001 From: Ron Unrau Date: Tue, 21 Feb 2023 20:48:59 -0700 Subject: [PATCH 5/5] Don't add codec2 library yet --- wscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wscript b/wscript index 1b4e45d73..c02035dcd 100644 --- a/wscript +++ b/wscript @@ -114,7 +114,7 @@ def configure(ctx): # Platform/OS specifics if ctx.options.with_os == 'posix': - ctx.env.append_unique('LIBS', ['rt', 'pthread', 'util', 'codec2']) + ctx.env.append_unique('LIBS', ['rt', 'pthread', 'util']) elif ctx.options.with_os == 'macosx': ctx.env.append_unique('LIBS', ['pthread']) elif ctx.options.with_os == 'windows':