This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit c17d32af896b5433a16fd1403d3895a4ed726a78 Author: raiden00pl <[email protected]> AuthorDate: Mon Oct 12 13:13:36 2026 +0200 examples/lely: Read one CAN message per read() in the char backend. read() on the CAN character driver copies every queued message that fits into the buffer, but *_candev_recv() decodes only the first one, so e.g. the second of two back-to-back NMT commands was lost. Set CANIOC_SET_MSGALIGN to 0, so read() returns exactly one message. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: raiden00pl <[email protected]> --- examples/lely_master/candev_char.c | 16 ++++++++++++++++ examples/lely_slave/candev_char.c | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/examples/lely_master/candev_char.c b/examples/lely_master/candev_char.c index 3506b75d9..d4c684d10 100644 --- a/examples/lely_master/candev_char.c +++ b/examples/lely_master/candev_char.c @@ -55,6 +55,7 @@ static int g_candev_fd; int comaster_candev_init(void) { struct canioc_bittiming_s bt; + unsigned int msgalign; int ret; /* Non-blocking so the main loop keeps servicing the CANopen timers */ @@ -69,6 +70,21 @@ int comaster_candev_init(void) return ret; } + /* read() returns all queued messages that fit into the buffer by + * default. Get exactly one message per read() instead, so that no + * message is lost. + */ + + msgalign = 0; + ret = ioctl(g_candev_fd, CANIOC_SET_MSGALIGN, &msgalign); + if (ret < 0) + { + ret = -errno; + printf("ERROR: CANIOC_SET_MSGALIGN failed %d\n", errno); + close(g_candev_fd); + return ret; + } + ret = ioctl(g_candev_fd, CANIOC_GET_BITTIMING, &bt); if (ret < 0) { diff --git a/examples/lely_slave/candev_char.c b/examples/lely_slave/candev_char.c index 71c2aed11..c840781d0 100644 --- a/examples/lely_slave/candev_char.c +++ b/examples/lely_slave/candev_char.c @@ -55,6 +55,7 @@ static int g_candev_fd; int coslave_candev_init(void) { struct canioc_bittiming_s bt; + unsigned int msgalign; int ret; /* Non-blocking so the main loop keeps servicing the CANopen timers */ @@ -69,6 +70,21 @@ int coslave_candev_init(void) return ret; } + /* read() returns all queued messages that fit into the buffer by + * default. Get exactly one message per read() instead, so that no + * message is lost. + */ + + msgalign = 0; + ret = ioctl(g_candev_fd, CANIOC_SET_MSGALIGN, &msgalign); + if (ret < 0) + { + ret = -errno; + printf("ERROR: CANIOC_SET_MSGALIGN failed %d\n", errno); + close(g_candev_fd); + return ret; + } + ret = ioctl(g_candev_fd, CANIOC_GET_BITTIMING, &bt); if (ret < 0) {
