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 <carlossanchez@geotab.com>
This commit is contained in:
Carlos Sanchez 2025-04-15 19:09:48 +02:00 committed by Xiang Xiao
parent 4fb47a6a6d
commit f94bccf119

View file

@ -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')
{