This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit f94bccf119e8d5765ecec5dacd27708f17b87104 Author: Carlos Sanchez <[email protected]> AuthorDate: Tue Apr 15 19:09:48 2025 +0200 canutils/slcan: explicitly manage the interface. A recent change (https://github.com/apache/nuttx/pull/16199) has made the bitrate setting no longer bring the interface up. Moreover, it is now no longer possible to change bitrate of a CAN interface if it is up. Therefore, slcan needs to bring the interface down to change it. Fortunately, it already had commands to open and close the interface which map nicely to this. Signed-off-by: Carlos Sanchez <[email protected]> --- canutils/slcan/slcan.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/canutils/slcan/slcan.c b/canutils/slcan/slcan.c index e2759a20c..cd7234fa2 100644 --- a/canutils/slcan/slcan.c +++ b/canutils/slcan/slcan.c @@ -316,9 +316,22 @@ int main(int argc, char *argv[]) { /* open CAN interface */ - mode = 1; - debug_print("Open interface\n"); - ok_return(fd); + struct ifreq ifr; + + strlcpy(ifr.ifr_name, argv[1], IFNAMSIZ); + + ifr.ifr_flags = IFF_UP; + if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0) + { + syslog(LOG_ERR, "Open interface failed\n"); + fail_return(fd); + } + else + { + mode = 1; + debug_print("Open interface\n"); + ok_return(fd); + } } else if (buf[0] == 'S') { @@ -392,9 +405,22 @@ int main(int argc, char *argv[]) { /* close interface */ - mode = 0; - debug_print("Close interface\n"); - ok_return(fd); + struct ifreq ifr; + + strlcpy(ifr.ifr_name, argv[1], IFNAMSIZ); + + ifr.ifr_flags = 0; + if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0) + { + syslog(LOG_ERR, "Close interface failed\n"); + fail_return(fd); + } + else + { + mode = 0; + debug_print("Close interface\n"); + ok_return(fd); + } } else if (buf[0] == 'T') {
