From c8ca4bf2220a1a5955924acb18f8bbc7551376c8 Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Fri, 26 Apr 2024 10:14:26 +0900 Subject: [PATCH 01/20] driver: kiss: Add addr parameter In commit 0d4dac28a5bf75390bdd1ef26e1c109094e0a032, we added a CSP address parameter to the csp_can_socketcan_open_and_add_interface() function. The address is assigned to ctx->iface.addr. This commit similarly adds an addr parameter for the CSP address to csp_usart_open_and_add_kiss_interface(), allowing us to specify the address for the given interface. Signed-off-by: Gaetan Perrot --- contrib/zephyr/samples/server-client/main.c | 2 +- examples/csp_client.c | 3 +-- examples/csp_server.c | 3 +-- include/csp/drivers/usart.h | 3 ++- src/bindings/python/pycsp.c | 5 +++-- src/csp_yaml.c | 2 +- src/drivers/usart/usart_kiss.c | 3 ++- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/contrib/zephyr/samples/server-client/main.c b/contrib/zephyr/samples/server-client/main.c index cda729711..49747bd6c 100644 --- a/contrib/zephyr/samples/server-client/main.c +++ b/contrib/zephyr/samples/server-client/main.c @@ -162,7 +162,7 @@ int main(void) { .stopbits = 1, .paritysetting = 0, }; - int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, &default_iface); + int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, addr, &default_iface); if (error != CSP_ERR_NONE) { LOG_ERR("failed to add KISS interface [%s], error: %d", kiss_device, error); exit(1); diff --git a/examples/csp_client.c b/examples/csp_client.c index 93b0ec4c3..37625a31a 100644 --- a/examples/csp_client.c +++ b/examples/csp_client.c @@ -98,12 +98,11 @@ csp_iface_t * add_interface(enum DeviceType device_type, const char * device_nam .stopbits = 1, .paritysetting = 0, }; - int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, &default_iface); + int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, client_address, &default_iface); if (error != CSP_ERR_NONE) { csp_print("failed to add KISS interface [%s], error: %d\n", device_name, error); exit(1); } - default_iface->addr = client_address; default_iface->is_default = 1; } diff --git a/examples/csp_server.c b/examples/csp_server.c index 18f85462d..e124c28dd 100644 --- a/examples/csp_server.c +++ b/examples/csp_server.c @@ -146,12 +146,11 @@ csp_iface_t * add_interface(enum DeviceType device_type, const char * device_nam .stopbits = 1, .paritysetting = 0, }; - int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, &default_iface); + int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, server_address, &default_iface); if (error != CSP_ERR_NONE) { csp_print("failed to add KISS interface [%s], error: %d\n", device_name, error); exit(1); } - default_iface->addr = server_address; default_iface->is_default = 1; } diff --git a/include/csp/drivers/usart.h b/include/csp/drivers/usart.h index 41206a9e3..2a68df9f2 100644 --- a/include/csp/drivers/usart.h +++ b/include/csp/drivers/usart.h @@ -95,10 +95,11 @@ void csp_usart_unlock(void * driver_data); * * @param[in] conf UART configuration. * @param[in] ifname internface name (will be copied), or use NULL for default name. + * @param[in] addr CSP address of the interface. * @param[out] return_iface the added interface. * @return #CSP_ERR_NONE on success, otherwise an error code. */ -int csp_usart_open_and_add_kiss_interface(const csp_usart_conf_t * conf, const char * ifname, csp_iface_t ** return_iface); +int csp_usart_open_and_add_kiss_interface(const csp_usart_conf_t * conf, const char * ifname, uint16_t addr, csp_iface_t ** return_iface); #ifdef __cplusplus } diff --git a/src/bindings/python/pycsp.c b/src/bindings/python/pycsp.c index 7803de25e..efff44eb0 100644 --- a/src/bindings/python/pycsp.c +++ b/src/bindings/python/pycsp.c @@ -875,13 +875,14 @@ static PyObject * pycsp_kiss_init(PyObject * self, PyObject * args) { char * device; uint32_t baudrate = 500000; uint32_t mtu = 512; + uint16_t addr; const char * if_name = CSP_IF_KISS_DEFAULT_NAME; - if (!PyArg_ParseTuple(args, "s|IIs", &device, &baudrate, &mtu, &if_name)) { + if (!PyArg_ParseTuple(args, "sH|IIs", &device, &addr, &baudrate, &mtu, &if_name)) { return NULL; // TypeError is thrown } csp_usart_conf_t conf = {.device = device, .baudrate = baudrate}; - int res = csp_usart_open_and_add_kiss_interface(&conf, if_name, NULL); + int res = csp_usart_open_and_add_kiss_interface(&conf, if_name, addr, NULL); if (res != CSP_ERR_NONE) { return PyErr_Error("csp_usart_open_and_add_kiss_interface()", res); } diff --git a/src/csp_yaml.c b/src/csp_yaml.c index 797eeb418..c7af1fb72 100644 --- a/src/csp_yaml.c +++ b/src/csp_yaml.c @@ -70,7 +70,7 @@ static void csp_yaml_end_if(struct data_s * data, unsigned int * dfl_addr) { .stopbits = 1, .paritysetting = 0, }; - int error = csp_usart_open_and_add_kiss_interface(&conf, data->name, &iface); + int error = csp_usart_open_and_add_kiss_interface(&conf, data->name, addr, &iface); if (error != CSP_ERR_NONE) { return; } diff --git a/src/drivers/usart/usart_kiss.c b/src/drivers/usart/usart_kiss.c index ef0320757..bd9238862 100644 --- a/src/drivers/usart/usart_kiss.c +++ b/src/drivers/usart/usart_kiss.c @@ -30,7 +30,7 @@ static void kiss_driver_rx(void * user_data, uint8_t * data, size_t data_size, v csp_kiss_rx(&ctx->iface, data, data_size, pxTaskWoken); } -int csp_usart_open_and_add_kiss_interface(const csp_usart_conf_t * conf, const char * ifname, csp_iface_t ** return_iface) { +int csp_usart_open_and_add_kiss_interface(const csp_usart_conf_t * conf, const char * ifname, uint16_t addr, csp_iface_t ** return_iface) { if (ifname == NULL) { ifname = CSP_IF_KISS_DEFAULT_NAME; @@ -43,6 +43,7 @@ int csp_usart_open_and_add_kiss_interface(const csp_usart_conf_t * conf, const c strncpy(ctx->name, ifname, sizeof(ctx->name) - 1); ctx->iface.name = ctx->name; + ctx->iface.addr = addr; ctx->iface.driver_data = ctx; ctx->iface.interface_data = &ctx->ifdata; ctx->ifdata.tx_func = kiss_driver_tx; From d9a74665373a121b7d0d82a8773813ff2f012b16 Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Wed, 21 Aug 2024 16:20:58 +0900 Subject: [PATCH 02/20] examples: python: server: Add command line options for zmq Previously, only the ZMQ interface was supported by default. This update introduces command line options for ZMQ. The `get_options()` function now supports `--zmq` as interface options. The server initialization and routing table setup have been updated to handle the selected interface based on the command line arguments provided. We just add zmq parameter to the server python binding example, so we also have to modify the current usage in the python workflow. Signed-off-by: Gaetan Perrot --- .github/workflows/build-test-python.yml | 2 +- examples/python_bindings_example_server.py | 40 +++++++++++++--------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build-test-python.yml b/.github/workflows/build-test-python.yml index f7500f688..fe88d164d 100644 --- a/.github/workflows/build-test-python.yml +++ b/.github/workflows/build-test-python.yml @@ -59,6 +59,6 @@ jobs: - name: Run ZMQ Python binding Test run: | build/examples/zmqproxy & - PYTHONPATH=builddir python3 examples/python_bindings_example_server.py & + PYTHONPATH=builddir python3 examples/python_bindings_example_server.py -z localhost -a 27 & PYTHONPATH=builddir python3 examples/python_bindings_example_client.py -z localhost -s 27 -a 2 pkill zmqproxy diff --git a/examples/python_bindings_example_server.py b/examples/python_bindings_example_server.py index 84989fbf6..45961c309 100644 --- a/examples/python_bindings_example_server.py +++ b/examples/python_bindings_example_server.py @@ -15,8 +15,16 @@ import sys import threading +import argparse + import libcsp_py3 as libcsp +def get_options(): + parser = argparse.ArgumentParser(description="Parses command.") + parser.add_argument("-a", "--address", type=int, default=10, help="Local CSP address") + parser.add_argument("-z", "--zmq", help="Add ZMQ interface") + return parser.parse_args() + def csp_server(): # parameters: {options} - bit flag corresponding to socket options (see "include\csp\csp_types.h" lines 167-180) @@ -58,21 +66,21 @@ def csp_server(): # extract the data payload from the packet # see "include\csp\csp_types.h" line 215-239 for packet structure data = bytearray(libcsp.packet_get_data(packet)) - + # get length of the data (not the whole packet, just the data length) length = libcsp.packet_get_length(packet) print ("got packet, len=" + str(length) + ", data=" + ''.join('{:02x}'.format(x) for x in data)) - + # send back "input data + 1" data[0] = data[0] + 1 - + # free up a buffer to hold the reply # parameters: {buffer size (# of 4-byte doublewords)} reply = libcsp.buffer_get(0) - + # store the data into the reply buffer libcsp.packet_set_data(reply, data) - + # Send packet as a reply # uses the info (address/port) from the original packet to reply # parameters: @@ -92,6 +100,7 @@ def csp_server(): if __name__ == "__main__": + options = get_options() #initialize libcsp with params: # 27 - CSP address of the system (default=1) # "test_service" - Host name, returned by CSP identity requests @@ -100,18 +109,15 @@ def csp_server(): # See "include\csp\csp.h" - lines 42-80 for more detail # See "src\bindings\python\pycsp.c" - lines 128-156 for more detail libcsp.init("test_service", "bindings", "1.2.3") - - # init zmqhub with parameters: {address (using 255 means all addresses)} {host name/ip} - # subscribe and publish endpoints are created on the default ports using the {host} - # subscribe port = 6000, subscribe port = 7000 - libcsp.zmqhub_init(27, "localhost") - - # params: - # {address} - dest address/node - # {netmask} - number of bits in netmask - # {interface name} - name of interface - # optional{via} - associated with address - libcsp.rtable_set(0, 0, "ZMQHUB") + + if options.zmq: + # add ZMQ interface - (address, host) + # creates publish and subrcribe endpoints from the host + libcsp.zmqhub_init(options.address, options.zmq) + + # Format: \[/mask] \ [via][, next entry] + # Examples: "0/0 CAN, 8 KISS, 10 I2C 10", same as "0/0 CAN, 8/5 KISS, 10/5 I2C 10" + libcsp.rtable_load("0/0 ZMQHUB") # Parameters: {priority} - 0 (critical), 1 (high), 2 (norm), 3 (low) ---- default=2 # Start the router task - creates routing thread From e4fe47d815de493369971c4e85b1805c9c0db9ba Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Wed, 21 Aug 2024 16:41:00 +0900 Subject: [PATCH 03/20] examples: python: server: Add command line options for kiss This update introduces command line options for KISS. Signed-off-by: Gaetan Perrot --- examples/python_bindings_example_server.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/python_bindings_example_server.py b/examples/python_bindings_example_server.py index 45961c309..49e89c69f 100644 --- a/examples/python_bindings_example_server.py +++ b/examples/python_bindings_example_server.py @@ -23,6 +23,7 @@ def get_options(): parser = argparse.ArgumentParser(description="Parses command.") parser.add_argument("-a", "--address", type=int, default=10, help="Local CSP address") parser.add_argument("-z", "--zmq", help="Add ZMQ interface") + parser.add_argument("-k", "--kiss", help="Add KISS interface") return parser.parse_args() @@ -119,6 +120,10 @@ def csp_server(): # Examples: "0/0 CAN, 8 KISS, 10 I2C 10", same as "0/0 CAN, 8/5 KISS, 10/5 I2C 10" libcsp.rtable_load("0/0 ZMQHUB") + if options.kiss: + libcsp.kiss_init(options.kiss, options.address) + libcsp.rtable_load("0/0 KISS") + # Parameters: {priority} - 0 (critical), 1 (high), 2 (norm), 3 (low) ---- default=2 # Start the router task - creates routing thread libcsp.route_start_task() From 4318e03814e3d480130a694552d0daeee855c32c Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Thu, 22 Aug 2024 11:10:53 +0900 Subject: [PATCH 04/20] examples: python: client: Add command line parameter for kiss Add command line parameter options for kiss to python version of client. Signed-off-by: Gaetan Perrot --- examples/python_bindings_example_client.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/python_bindings_example_client.py b/examples/python_bindings_example_client.py index ea9de49e0..3ab35a760 100644 --- a/examples/python_bindings_example_client.py +++ b/examples/python_bindings_example_client.py @@ -22,6 +22,7 @@ def getOptions(): parser = argparse.ArgumentParser(description="Parses command.") parser.add_argument("-a", "--address", type=int, default=10, help="Local CSP address") parser.add_argument("-c", "--can", help="Add CAN interface") + parser.add_argument("-k", "--kiss", help="Add KISS interface") parser.add_argument("-z", "--zmq", help="Add ZMQ interface") parser.add_argument("-s", "--server-address", type=int, default=27, help="Server address") parser.add_argument("-R", "--routing-table", help="Routing table") @@ -53,7 +54,11 @@ def getOptions(): # Format: \[/mask] \ [via][, next entry] # Examples: "0/0 CAN, 8 KISS, 10 I2C 10", same as "0/0 CAN, 8/5 KISS, 10/5 I2C 10" libcsp.rtable_load("0/0 ZMQHUB") - + + if options.kiss: + libcsp.kiss_init(options.kiss, options.address) + libcsp.rtable_load("0/0 KISS") + if options.routing_table: # same format/use as line above libcsp.rtable_load(options.routing_table) From 43edf21ebf8efe1bbf916c5cf6ea5049238882d0 Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Wed, 21 Aug 2024 18:50:35 +0900 Subject: [PATCH 05/20] examples: python: client: Fix camel case in python client example Fix camel case in python client example, `getOptions` to ``get_options``. Signed-off-by: Gaetan Perrot --- examples/python_bindings_example_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/python_bindings_example_client.py b/examples/python_bindings_example_client.py index 3ab35a760..ef39861be 100644 --- a/examples/python_bindings_example_client.py +++ b/examples/python_bindings_example_client.py @@ -18,7 +18,7 @@ import libcsp_py3 as libcsp -def getOptions(): +def get_options(): parser = argparse.ArgumentParser(description="Parses command.") parser.add_argument("-a", "--address", type=int, default=10, help="Local CSP address") parser.add_argument("-c", "--can", help="Add CAN interface") @@ -31,7 +31,7 @@ def getOptions(): if __name__ == "__main__": - options = getOptions() + options = get_options() #initialize libcsp with params: # options.address - CSP address of the system (default=1) From 371a8068fc77d4e33b33b21d56185ec9b05d210e Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Fri, 16 Aug 2024 18:53:36 +0900 Subject: [PATCH 06/20] github: workflow: python: Update test python binding example parameter In the previous commit, we added parameters to the server python binding example, in order to test that address parameter take the parameter and not the default value. I changed the address in zmq test to test the option parameter, introduce by previous commit. Signed-off-by: Gaetan Perrot --- .github/workflows/build-test-python.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-test-python.yml b/.github/workflows/build-test-python.yml index fe88d164d..a16ce8130 100644 --- a/.github/workflows/build-test-python.yml +++ b/.github/workflows/build-test-python.yml @@ -59,6 +59,6 @@ jobs: - name: Run ZMQ Python binding Test run: | build/examples/zmqproxy & - PYTHONPATH=builddir python3 examples/python_bindings_example_server.py -z localhost -a 27 & - PYTHONPATH=builddir python3 examples/python_bindings_example_client.py -z localhost -s 27 -a 2 + PYTHONPATH=builddir python3 examples/python_bindings_example_server.py -z localhost -a 3 & + PYTHONPATH=builddir python3 examples/python_bindings_example_client.py -z localhost -s 3 -a 2 pkill zmqproxy From 2f5df64d24883bd0bf1f1c1bd67df39e2da19c7a Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Wed, 21 Aug 2024 16:44:24 +0900 Subject: [PATCH 07/20] github: workflow: python: Add kiss test support In the previous commit, we add kiss parameter to the server python binding example, so we also have to modify the python workflow to be able to test kiss interface as well. Signed-off-by: Gaetan Perrot --- .github/workflows/build-test-python.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-test-python.yml b/.github/workflows/build-test-python.yml index a16ce8130..62ed362c2 100644 --- a/.github/workflows/build-test-python.yml +++ b/.github/workflows/build-test-python.yml @@ -27,7 +27,7 @@ jobs: - name: Setup packages on Linux run: | sudo apt-get update - sudo apt-get install libzmq3-dev libsocketcan-dev + sudo apt-get install libzmq3-dev libsocketcan-dev socat - name: Setup build system packages on Linux run: | @@ -62,3 +62,11 @@ jobs: PYTHONPATH=builddir python3 examples/python_bindings_example_server.py -z localhost -a 3 & PYTHONPATH=builddir python3 examples/python_bindings_example_client.py -z localhost -s 3 -a 2 pkill zmqproxy + + - name: Run KISS Python binding Test + run: | + socat -d -d -d pty,raw,echo=0,link=/tmp/pty1 pty,raw,echo=0,link=/tmp/pty2 & + sleep 1 + PYTHONPATH=builddir python3 examples/python_bindings_example_server.py -k /tmp/pty2 -a 1 & + PYTHONPATH=builddir python3 examples/python_bindings_example_client.py -k /tmp/pty1 -a 2 -s 1 + pkill socat From 484ebb188ef857ab94775d4dd3937a606c0f7a08 Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Thu, 22 Aug 2024 17:21:09 +0900 Subject: [PATCH 08/20] github: workflow: Add CAN interface testing Added steps to set up a virtual CAN (vcan0) interface in the CI environment. Included tests for the CAN interface using the `csp_server` and `csp_client` examples. Ensured the CAN interface is correctly configured with `modprobe vcan`and `ip link add dev vcan0 type vcan`. Implemented both server and client tests to validate CAN communication. This change enables automated testing of the CAN interface within the CI pipeline, improving test coverage for CAN-related functionality. Signed-off-by: Gaetan Perrot --- .github/workflows/build-test.yml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 0fa60653e..1ab5cad58 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -24,7 +24,8 @@ jobs: if: ${{ runner.os == 'Linux' }} run: | sudo apt-get update - sudo apt-get install libzmq3-dev libsocketcan-dev socat + sudo apt-get install libzmq3-dev libsocketcan-dev socat iproute2 + sudo apt-get install linux-modules-extra-$(uname -r) - name: Setup build system packages on Linux if: ${{ runner.os == 'Linux' && matrix.buildsystem != 'waf' }} @@ -81,3 +82,24 @@ jobs: ./build/examples/csp_client -z localhost -a 2 -C 1 -T 10 & ./build/examples/csp_server -z localhost -a 1 -t pkill zmqproxy + + - name: Setup vcan0 + run: | + sudo modprobe vcan + sudo ip link add dev vcan0 type vcan + sudo ip link set up vcan0 + echo "Waiting for vcan0 to be up..." + while ! ip -br link show vcan0 | grep -q "UP"; do + sleep 0.1 + done + echo "vcan0 is up" + + - name: Run CAN Server Test + run: | + ./build/examples/csp_server -c vcan0 -a 1 -T 10 & + ./build/examples/csp_client -c vcan0 -a 2 -C 1 -t + + - name: Run CAN Client Test + run: | + ./build/examples/csp_client -c vcan0 -a 2 -C 1 -T 10 & + ./build/examples/csp_server -c vcan0 -a 1 -t From b1133e7718dd8a98f39548906f14765ee179b1d9 Mon Sep 17 00:00:00 2001 From: dimitrovand Date: Sat, 31 Aug 2024 10:38:56 +0300 Subject: [PATCH 09/20] csp_rdp: Remove undefined function The `csp_rdp_conn_print` function has no implementation, documentation, or usage. This commit removes its declaration. --- src/csp_rdp.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/csp_rdp.h b/src/csp_rdp.h index ceeaae5ed..87802ce82 100644 --- a/src/csp_rdp.h +++ b/src/csp_rdp.h @@ -10,5 +10,3 @@ int csp_rdp_connect(csp_conn_t * conn); int csp_rdp_close(csp_conn_t * conn, uint8_t closed_by); int csp_rdp_send(csp_conn_t * conn, csp_packet_t * packet); int csp_rdp_check_ack(csp_conn_t * conn); - -void csp_rdp_conn_print(csp_conn_t * conn); From 8f9903e1c4f4da44065434d1a669ab7c6c5d43d5 Mon Sep 17 00:00:00 2001 From: dimitrovand Date: Sat, 31 Aug 2024 10:48:36 +0300 Subject: [PATCH 10/20] csp_rdp_queue: Fix undefined return value When `__csp_rdp_queue_flush` encounters an empty queue (i.e., `csp_queue_size(queue) == 0`), the function would return an undefined value due to the uninitialized variable `ret`. This commit resolves the issue by initializing `ret` to `CSP_ERR_NONE`. `CSP_ERR_NONE` is a suitable value since an empty queue is equivalent to a successfully flushed queue. Although the return value is not currently used, this change ensures future robustness if the return value is utilized later. --- src/csp_rdp_queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/csp_rdp_queue.c b/src/csp_rdp_queue.c index 72c93ff9f..df384d792 100644 --- a/src/csp_rdp_queue.c +++ b/src/csp_rdp_queue.c @@ -5,7 +5,7 @@ static int __csp_rdp_queue_flush(csp_queue_handle_t queue, csp_conn_t * conn) { - int ret; + int ret = CSP_ERR_NONE; int size; size = csp_queue_size(queue); From 57e2a682d07193085de7d7d63db06b8dab759b9f Mon Sep 17 00:00:00 2001 From: dimitrovand Date: Sat, 31 Aug 2024 10:24:53 +0300 Subject: [PATCH 11/20] csp_qfifo: Make qfifo_queue_buffer static This commit changes the scope of `qfifo_queue_buffer` from global to local. There appears to be no clear reason for exposing the internal implementation details of the queue. --- src/csp_qfifo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/csp_qfifo.c b/src/csp_qfifo.c index 1fdbbf50e..476d51315 100644 --- a/src/csp_qfifo.c +++ b/src/csp_qfifo.c @@ -8,7 +8,7 @@ static csp_static_queue_t qfifo_queue __noinit; static csp_queue_handle_t qfifo_queue_handle __noinit; -char qfifo_queue_buffer[sizeof(csp_qfifo_t) * CSP_QFIFO_LEN] __noinit; +static char qfifo_queue_buffer[sizeof(csp_qfifo_t) * CSP_QFIFO_LEN] __noinit; void csp_qfifo_init(void) { qfifo_queue_handle = csp_queue_create_static(CSP_QFIFO_LEN, sizeof(csp_qfifo_t), qfifo_queue_buffer, &qfifo_queue); From 913fc1713a95d088d8ac0a5fa858fec8926d9ef2 Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Tue, 3 Sep 2024 00:23:10 +0900 Subject: [PATCH 12/20] csp_if_zmqhub: Handle return value of csp_iflist_add Update the code to capture the return value of `csp_iflist_add` in the variable `ret`. This allows for proper error handling by ensuring that the result of `csp_iflist_add` is returned by the function. Previously, the return value was ignored, which could lead to missing error information. The return value is now used to confirm successful interface addition, and if an error occurs, it can be properly propagated. Signed-off-by: Gaetan Perrot --- src/interfaces/csp_if_zmqhub.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/interfaces/csp_if_zmqhub.c b/src/interfaces/csp_if_zmqhub.c index f7324f21c..903a477d3 100644 --- a/src/interfaces/csp_if_zmqhub.c +++ b/src/interfaces/csp_if_zmqhub.c @@ -208,13 +208,13 @@ int csp_zmqhub_init_w_name_endpoints_rxfilter(const char * ifname, uint16_t addr assert(ret == 0); /* Register interface */ - csp_iflist_add(&drv->iface); + ret = csp_iflist_add(&drv->iface); - if (return_interface) { + if (ret == CSP_ERR_NONE && return_interface) { *return_interface = &drv->iface; } - return CSP_ERR_NONE; + return ret; } int csp_zmqhub_init_filter2(const char * ifname, const char * host, uint16_t addr, uint16_t netmask, int promisc, csp_iface_t ** return_interface, char * sec_key, uint16_t subport, uint16_t pubport) { @@ -310,13 +310,13 @@ int csp_zmqhub_init_filter2(const char * ifname, const char * host, uint16_t add assert(ret == 0); /* Register interface */ - csp_iflist_add(&drv->iface); + ret = csp_iflist_add(&drv->iface); - if (return_interface) { + if (ret == CSP_ERR_NONE && return_interface) { *return_interface = &drv->iface; } - return CSP_ERR_NONE; + return ret; } From e643c3a9ba67b8e813eb600b935972e2f5b277d5 Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Thu, 5 Sep 2024 03:24:41 +0900 Subject: [PATCH 13/20] csp_if_kiss: Increment frame drop count on interface overflow Added a line to increment the `drop` counter on the KISS interface when a frame is lost due to overflow. This ensures that frame loss is properly tracked. Signed-off-by: Gaetan Perrot --- src/interfaces/csp_if_kiss.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/interfaces/csp_if_kiss.c b/src/interfaces/csp_if_kiss.c index 2ea547a27..b1b1e35f9 100644 --- a/src/interfaces/csp_if_kiss.c +++ b/src/interfaces/csp_if_kiss.c @@ -101,6 +101,7 @@ void csp_kiss_rx(csp_iface_t * iface, const uint8_t * buf, size_t len, void * px /* If no more memory, skip frame */ if (ifdata->rx_packet == NULL) { ifdata->rx_mode = KISS_MODE_SKIP_FRAME; + iface->drop++; break; } From 5766a2c14e2f9c832511ee95b035e7b5d1828269 Mon Sep 17 00:00:00 2001 From: dimitrovand Date: Wed, 4 Sep 2024 18:01:14 +0300 Subject: [PATCH 14/20] interfaces: csp_if_eth: Add to cmake build Adds 'csp_if_eth.c' and 'csp_if_eth_pbuf.c' to the cmake build process. --- src/interfaces/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/interfaces/CMakeLists.txt b/src/interfaces/CMakeLists.txt index 01bcc55bd..50ca4c8d7 100644 --- a/src/interfaces/CMakeLists.txt +++ b/src/interfaces/CMakeLists.txt @@ -5,6 +5,8 @@ target_sources(csp PRIVATE csp_if_tun.c csp_if_can.c csp_if_can_pbuf.c + csp_if_eth.c + csp_if_eth_pbuf.c ) if(LIBZMQ_FOUND) From a0d6fa8e9b99aa85691577b65a8cc27054ba47bd Mon Sep 17 00:00:00 2001 From: dimitrovand Date: Wed, 4 Sep 2024 18:09:38 +0300 Subject: [PATCH 15/20] interfaces: csp_if_eth_pbuf: Replace printf usage Replacing the usage of printf with csp_printf since not all platforms have direct support for printf. --- src/interfaces/csp_if_eth_pbuf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interfaces/csp_if_eth_pbuf.c b/src/interfaces/csp_if_eth_pbuf.c index c0b415c3c..cdf54ca5c 100644 --- a/src/interfaces/csp_if_eth_pbuf.c +++ b/src/interfaces/csp_if_eth_pbuf.c @@ -100,7 +100,7 @@ void csp_if_eth_pbuf_list_cleanup(csp_packet_t ** plist) { void csp_if_eth_pbuf_print(const char * descr, csp_packet_t * packet) { if (packet) { - printf("%s %p id:%u Age:%lu,%lu,%lu flen:%u\n", + csp_print("%s %p id:%u Age:%lu,%lu,%lu flen:%u\n", descr, (void *)packet, (unsigned)packet->cfpid, (unsigned long)csp_get_ms(), @@ -108,7 +108,7 @@ void csp_if_eth_pbuf_print(const char * descr, csp_packet_t * packet) { (unsigned long)(csp_get_ms() - packet->last_used), (unsigned)packet->frame_length); } else { - printf("Packet is null\n"); + csp_print("Packet is null\n"); } } From 188aca63b26219b05d410013c6016402d2f90f38 Mon Sep 17 00:00:00 2001 From: dimitrovand Date: Wed, 4 Sep 2024 18:13:00 +0300 Subject: [PATCH 16/20] drivers: eth_linux: Add to cmake build Adds 'eth_linux.c' to the cmake build. --- src/drivers/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/drivers/CMakeLists.txt b/src/drivers/CMakeLists.txt index e05208860..8d3082971 100644 --- a/src/drivers/CMakeLists.txt +++ b/src/drivers/CMakeLists.txt @@ -15,6 +15,7 @@ endif() if(CMAKE_SYSTEM_NAME STREQUAL "Linux") target_sources(csp PRIVATE usart/usart_linux.c) + target_sources(csp PRIVATE eth/eth_linux.c) elseif(CMAKE_SYSTEM_NAME STREQUAL "Zephyr") target_sources(csp PRIVATE usart/usart_zephyr.c) endif() From 1ab1ebd5f68143caf2e3f545bc8ff25a51bfb5a0 Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Fri, 6 Sep 2024 21:43:59 +0900 Subject: [PATCH 17/20] csp_yaml: Replace printf usage Replacing the usage of printf with csp_printf since not all platforms have direct support for printf. Signed-off-by: Gaetan Perrot --- src/csp_yaml.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/csp_yaml.c b/src/csp_yaml.c index c7af1fb72..f77c2b6cb 100644 --- a/src/csp_yaml.c +++ b/src/csp_yaml.c @@ -206,7 +206,7 @@ void csp_yaml_init(char * filename, unsigned int * dfl_addr) { csp_print(" Reading config from %s\n", filename); FILE * file = fopen(filename, "rb"); if (file == NULL) { - printf(" ERROR: failed to find CSP config file\n"); + csp_print(" ERROR: failed to find CSP config file\n"); return; } From 51c177b65c8df108beb30d9b04bd273facd8492a Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Fri, 6 Sep 2024 23:05:29 +0900 Subject: [PATCH 18/20] drivers: eth_linux: Replace printf usage Replacing the usage of printf with csp_printf since not all platforms have direct support for printf. Signed-off-by: Gaetan Perrot --- src/drivers/eth/eth_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/eth/eth_linux.c b/src/drivers/eth/eth_linux.c index 6f52d6245..590526795 100644 --- a/src/drivers/eth/eth_linux.c +++ b/src/drivers/eth/eth_linux.c @@ -98,7 +98,7 @@ int csp_eth_init(const char * device, const char * ifname, int mtu, unsigned int /* Open RAW socket to send on */ if ((ctx->sockfd = socket(AF_PACKET, SOCK_RAW, htobe16(CSP_ETH_TYPE_CSP))) == -1) { perror("socket"); - printf("Use command 'setcap cap_net_raw+ep ./csh'\n"); + csp_print("Use command 'setcap cap_net_raw+ep ./csh'\n"); return CSP_ERR_INVAL; } From aa2b28b1842c84e349b3b77fa22d71f0155bbd04 Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Fri, 6 Sep 2024 23:06:06 +0900 Subject: [PATCH 19/20] drivers: can_socketcan: Replace printf usage Replacing the usage of printf with csp_printf since not all platforms have direct support for printf. Signed-off-by: Gaetan Perrot --- src/drivers/can/can_socketcan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/can/can_socketcan.c b/src/drivers/can/can_socketcan.c index ab662a78b..b5c456574 100644 --- a/src/drivers/can/can_socketcan.c +++ b/src/drivers/can/can_socketcan.c @@ -48,7 +48,7 @@ static void * socketcan_rx_thread(void * arg) { timeout.tv_sec = 10; int n = select(ctx->socket + 1, &input, NULL, NULL, &timeout); if (n == -1) { - printf("CAN read error\n"); + csp_print("CAN read error\n"); continue; } else if (n == 0) { //printf("CAN idle\n"); From cc71d1ad4156d63e6fee1ce2a10825fca394268c Mon Sep 17 00:00:00 2001 From: dimitrovand Date: Fri, 6 Sep 2024 16:47:40 +0300 Subject: [PATCH 20/20] csp_rdp_queue: Fix order of parameters Fix wrong order of input parameters to '__csp_rdp_queue_flush()'. --- src/csp_rdp_queue.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/csp_rdp_queue.c b/src/csp_rdp_queue.c index df384d792..ceb7576c1 100644 --- a/src/csp_rdp_queue.c +++ b/src/csp_rdp_queue.c @@ -85,8 +85,8 @@ void csp_rdp_queue_flush(csp_conn_t * conn) { csp_queue_empty(tx_queue); csp_queue_empty(rx_queue); } else { - (void)__csp_rdp_queue_flush(conn, tx_queue); - (void)__csp_rdp_queue_flush(conn, rx_queue); + (void)__csp_rdp_queue_flush(tx_queue, conn); + (void)__csp_rdp_queue_flush(rx_queue, conn); } }