Skip to content

Commit eb93d7c

Browse files
authored
Merge branch 'libcsp:develop' into develop
2 parents 4a16199 + 2f5df64 commit eb93d7c

File tree

10 files changed

+58
-33
lines changed

10 files changed

+58
-33
lines changed

.github/workflows/build-test-python.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Setup packages on Linux
2828
run: |
2929
sudo apt-get update
30-
sudo apt-get install libzmq3-dev libsocketcan-dev
30+
sudo apt-get install libzmq3-dev libsocketcan-dev socat
3131
3232
- name: Setup build system packages on Linux
3333
run: |
@@ -59,6 +59,14 @@ jobs:
5959
- name: Run ZMQ Python binding Test
6060
run: |
6161
build/examples/zmqproxy &
62-
PYTHONPATH=builddir python3 examples/python_bindings_example_server.py &
63-
PYTHONPATH=builddir python3 examples/python_bindings_example_client.py -z localhost -s 27 -a 2
62+
PYTHONPATH=builddir python3 examples/python_bindings_example_server.py -z localhost -a 3 &
63+
PYTHONPATH=builddir python3 examples/python_bindings_example_client.py -z localhost -s 3 -a 2
6464
pkill zmqproxy
65+
66+
- name: Run KISS Python binding Test
67+
run: |
68+
socat -d -d -d pty,raw,echo=0,link=/tmp/pty1 pty,raw,echo=0,link=/tmp/pty2 &
69+
sleep 1
70+
PYTHONPATH=builddir python3 examples/python_bindings_example_server.py -k /tmp/pty2 -a 1 &
71+
PYTHONPATH=builddir python3 examples/python_bindings_example_client.py -k /tmp/pty1 -a 2 -s 1
72+
pkill socat

contrib/zephyr/samples/server-client/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ int main(void) {
162162
.stopbits = 1,
163163
.paritysetting = 0,
164164
};
165-
int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, &default_iface);
165+
int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, addr, &default_iface);
166166
if (error != CSP_ERR_NONE) {
167167
LOG_ERR("failed to add KISS interface [%s], error: %d", kiss_device, error);
168168
exit(1);

examples/csp_client.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,11 @@ csp_iface_t * add_interface(enum DeviceType device_type, const char * device_nam
125125
.stopbits = 1,
126126
.paritysetting = 0,
127127
};
128-
int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, &default_iface);
128+
int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, client_address, &default_iface);
129129
if (error != CSP_ERR_NONE) {
130130
csp_print("failed to add KISS interface [%s], error: %d\n", device_name, error);
131131
exit(1);
132132
}
133-
default_iface->addr = client_address;
134133
default_iface->is_default = 1;
135134
}
136135

examples/csp_server.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,11 @@ csp_iface_t * add_interface(enum DeviceType device_type, const char * device_nam
470470
.stopbits = 1,
471471
.paritysetting = 0,
472472
};
473-
int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, &default_iface);
473+
int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, server_address, &default_iface);
474474
if (error != CSP_ERR_NONE) {
475475
csp_print("failed to add KISS interface [%s], error: %d\n", device_name, error);
476476
exit(1);
477477
}
478-
default_iface->addr = server_address;
479478
default_iface->is_default = 1;
480479
}
481480

examples/python_bindings_example_client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
import libcsp_py3 as libcsp
1919

2020

21-
def getOptions():
21+
def get_options():
2222
parser = argparse.ArgumentParser(description="Parses command.")
2323
parser.add_argument("-a", "--address", type=int, default=10, help="Local CSP address")
2424
parser.add_argument("-c", "--can", help="Add CAN interface")
25+
parser.add_argument("-k", "--kiss", help="Add KISS interface")
2526
parser.add_argument("-z", "--zmq", help="Add ZMQ interface")
2627
parser.add_argument("-s", "--server-address", type=int, default=27, help="Server address")
2728
parser.add_argument("-R", "--routing-table", help="Routing table")
@@ -30,7 +31,7 @@ def getOptions():
3031

3132
if __name__ == "__main__":
3233

33-
options = getOptions()
34+
options = get_options()
3435

3536
#initialize libcsp with params:
3637
# options.address - CSP address of the system (default=1)
@@ -53,7 +54,11 @@ def getOptions():
5354
# Format: \<address\>[/mask] \<interface\> [via][, next entry]
5455
# Examples: "0/0 CAN, 8 KISS, 10 I2C 10", same as "0/0 CAN, 8/5 KISS, 10/5 I2C 10"
5556
libcsp.rtable_load("0/0 ZMQHUB")
56-
57+
58+
if options.kiss:
59+
libcsp.kiss_init(options.kiss, options.address)
60+
libcsp.rtable_load("0/0 KISS")
61+
5762
if options.routing_table:
5863
# same format/use as line above
5964
libcsp.rtable_load(options.routing_table)

examples/python_bindings_example_server.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,17 @@
1515
import sys
1616
import threading
1717

18+
import argparse
19+
1820
import libcsp_py3 as libcsp
1921

22+
def get_options():
23+
parser = argparse.ArgumentParser(description="Parses command.")
24+
parser.add_argument("-a", "--address", type=int, default=10, help="Local CSP address")
25+
parser.add_argument("-z", "--zmq", help="Add ZMQ interface")
26+
parser.add_argument("-k", "--kiss", help="Add KISS interface")
27+
return parser.parse_args()
28+
2029

2130
def csp_server():
2231
# parameters: {options} - bit flag corresponding to socket options (see "include\csp\csp_types.h" lines 167-180)
@@ -58,21 +67,21 @@ def csp_server():
5867
# extract the data payload from the packet
5968
# see "include\csp\csp_types.h" line 215-239 for packet structure
6069
data = bytearray(libcsp.packet_get_data(packet))
61-
70+
6271
# get length of the data (not the whole packet, just the data length)
6372
length = libcsp.packet_get_length(packet)
6473
print ("got packet, len=" + str(length) + ", data=" + ''.join('{:02x}'.format(x) for x in data))
65-
74+
6675
# send back "input data + 1"
6776
data[0] = data[0] + 1
68-
77+
6978
# free up a buffer to hold the reply
7079
# parameters: {buffer size (# of 4-byte doublewords)}
7180
reply = libcsp.buffer_get(0)
72-
81+
7382
# store the data into the reply buffer
7483
libcsp.packet_set_data(reply, data)
75-
84+
7685
# Send packet as a reply
7786
# uses the info (address/port) from the original packet to reply
7887
# parameters:
@@ -92,6 +101,7 @@ def csp_server():
92101

93102
if __name__ == "__main__":
94103

104+
options = get_options()
95105
#initialize libcsp with params:
96106
# 27 - CSP address of the system (default=1)
97107
# "test_service" - Host name, returned by CSP identity requests
@@ -100,18 +110,19 @@ def csp_server():
100110
# See "include\csp\csp.h" - lines 42-80 for more detail
101111
# See "src\bindings\python\pycsp.c" - lines 128-156 for more detail
102112
libcsp.init("test_service", "bindings", "1.2.3")
103-
104-
# init zmqhub with parameters: {address (using 255 means all addresses)} {host name/ip}
105-
# subscribe and publish endpoints are created on the default ports using the {host}
106-
# subscribe port = 6000, subscribe port = 7000
107-
libcsp.zmqhub_init(27, "localhost")
108-
109-
# params:
110-
# {address} - dest address/node
111-
# {netmask} - number of bits in netmask
112-
# {interface name} - name of interface
113-
# optional{via} - associated with address
114-
libcsp.rtable_set(0, 0, "ZMQHUB")
113+
114+
if options.zmq:
115+
# add ZMQ interface - (address, host)
116+
# creates publish and subrcribe endpoints from the host
117+
libcsp.zmqhub_init(options.address, options.zmq)
118+
119+
# Format: \<address\>[/mask] \<interface\> [via][, next entry]
120+
# Examples: "0/0 CAN, 8 KISS, 10 I2C 10", same as "0/0 CAN, 8/5 KISS, 10/5 I2C 10"
121+
libcsp.rtable_load("0/0 ZMQHUB")
122+
123+
if options.kiss:
124+
libcsp.kiss_init(options.kiss, options.address)
125+
libcsp.rtable_load("0/0 KISS")
115126

116127
# Parameters: {priority} - 0 (critical), 1 (high), 2 (norm), 3 (low) ---- default=2
117128
# Start the router task - creates routing thread

include/csp/drivers/usart.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ void csp_usart_unlock(void * driver_data);
9595
*
9696
* @param[in] conf UART configuration.
9797
* @param[in] ifname internface name (will be copied), or use NULL for default name.
98+
* @param[in] addr CSP address of the interface.
9899
* @param[out] return_iface the added interface.
99100
* @return #CSP_ERR_NONE on success, otherwise an error code.
100101
*/
101-
int csp_usart_open_and_add_kiss_interface(const csp_usart_conf_t * conf, const char * ifname, csp_iface_t ** return_iface);
102+
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);
102103

103104
#ifdef __cplusplus
104105
}

src/bindings/python/pycsp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,13 +875,14 @@ static PyObject * pycsp_kiss_init(PyObject * self, PyObject * args) {
875875
char * device;
876876
uint32_t baudrate = 500000;
877877
uint32_t mtu = 512;
878+
uint16_t addr;
878879
const char * if_name = CSP_IF_KISS_DEFAULT_NAME;
879-
if (!PyArg_ParseTuple(args, "s|IIs", &device, &baudrate, &mtu, &if_name)) {
880+
if (!PyArg_ParseTuple(args, "sH|IIs", &device, &addr, &baudrate, &mtu, &if_name)) {
880881
return NULL; // TypeError is thrown
881882
}
882883

883884
csp_usart_conf_t conf = {.device = device, .baudrate = baudrate};
884-
int res = csp_usart_open_and_add_kiss_interface(&conf, if_name, NULL);
885+
int res = csp_usart_open_and_add_kiss_interface(&conf, if_name, addr, NULL);
885886
if (res != CSP_ERR_NONE) {
886887
return PyErr_Error("csp_usart_open_and_add_kiss_interface()", res);
887888
}

src/csp_yaml.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static void csp_yaml_end_if(struct data_s * data, unsigned int * dfl_addr) {
7070
.stopbits = 1,
7171
.paritysetting = 0,
7272
};
73-
int error = csp_usart_open_and_add_kiss_interface(&conf, data->name, &iface);
73+
int error = csp_usart_open_and_add_kiss_interface(&conf, data->name, addr, &iface);
7474
if (error != CSP_ERR_NONE) {
7575
return;
7676
}

src/drivers/usart/usart_kiss.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void kiss_driver_rx(void * user_data, uint8_t * data, size_t data_size, v
3030
csp_kiss_rx(&ctx->iface, data, data_size, pxTaskWoken);
3131
}
3232

33-
int csp_usart_open_and_add_kiss_interface(const csp_usart_conf_t * conf, const char * ifname, csp_iface_t ** return_iface) {
33+
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) {
3434

3535
if (ifname == NULL) {
3636
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
4343

4444
strncpy(ctx->name, ifname, sizeof(ctx->name) - 1);
4545
ctx->iface.name = ctx->name;
46+
ctx->iface.addr = addr;
4647
ctx->iface.driver_data = ctx;
4748
ctx->iface.interface_data = &ctx->ifdata;
4849
ctx->ifdata.tx_func = kiss_driver_tx;

0 commit comments

Comments
 (0)