Skip to content

Commit

Permalink
kiss: Add node_id parameter
Browse files Browse the repository at this point in the history
In the commit
0d4dac2,
`csp_can_socketcan_open_and_add_interface()`
gained new parameter node_id, which is assigned
 to ctx->iface.addr in the function.
Add address / node_id parameter to
`csp_usart_open_and_add_kiss_interface()`.

Signed-off-by: Gaetan Perrot <[email protected]>
  • Loading branch information
moonlight83340 committed Apr 30, 2024
1 parent 6e7f046 commit aaf4856
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion contrib/zephyr/samples/server-client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions examples/csp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions examples/csp_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion include/csp/drivers/usart.h
Original file line number Diff line number Diff line change
Expand Up @@ -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] node_id 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 node_id, csp_iface_t ** return_iface);

#ifdef __cplusplus
}
Expand Down
5 changes: 3 additions & 2 deletions src/bindings/python/pycsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,13 +871,14 @@ static PyObject * pycsp_kiss_init(PyObject * self, PyObject * args) {
char * device;
uint32_t baudrate = 500000;
uint32_t mtu = 512;
int 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, "s|IIsI", &device, &baudrate, &mtu, &if_name, &addr)) {
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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/csp_yaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/drivers/usart/usart_kiss.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 node_id, csp_iface_t ** return_iface) {

if (ifname == NULL) {
ifname = CSP_IF_KISS_DEFAULT_NAME;
Expand All @@ -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 = node_id;
ctx->iface.driver_data = ctx;
ctx->iface.interface_data = &ctx->ifdata;
ctx->ifdata.tx_func = kiss_driver_tx;
Expand Down

0 comments on commit aaf4856

Please sign in to comment.