diff --git a/contrib/zephyr/samples/server-client/main.c b/contrib/zephyr/samples/server-client/main.c index 0c23e3835..c07d8ecc7 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 3d4c9353d..9ed61aa92 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 57909614f..cb3247f85 100644 --- a/include/csp/drivers/usart.h +++ b/include/csp/drivers/usart.h @@ -82,10 +82,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 51a77b6a8..5df198413 100644 --- a/src/bindings/python/pycsp.c +++ b/src/bindings/python/pycsp.c @@ -871,13 +871,14 @@ static PyObject * pycsp_kiss_init(PyObject * self, PyObject * args) { char * device; uint32_t baudrate = 500000; uint32_t mtu = 512; + uint16_t addr = 0; 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 69fa2a684..59bc889c9 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;