Merged in slorquet/apps/canlib (pull request #46)
Basic CAN utility library
This commit is contained in:
commit
06704e041a
17
canutils/canlib/Kconfig
Normal file
17
canutils/canlib/Kconfig
Normal file
@ -0,0 +1,17 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config CANUTILS_CANLIB
|
||||
bool "CAN utility library"
|
||||
default n
|
||||
depends on CAN && LIB_BOARDCTL
|
||||
select BOARDCTL_CANINIT
|
||||
---help---
|
||||
Enable the CAN utility library
|
||||
|
||||
if CANUTILS_CANLIB
|
||||
|
||||
endif
|
||||
|
39
canutils/canlib/Make.defs
Normal file
39
canutils/canlib/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/canutils/canlib/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
# Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_CANUTILS_CANLIB),y)
|
||||
CONFIGURED_APPS += canutils/canlib
|
||||
endif
|
45
canutils/canlib/Makefile
Normal file
45
canutils/canlib/Makefile
Normal file
@ -0,0 +1,45 @@
|
||||
############################################################################
|
||||
# apps/canutils/canlib/Makefile
|
||||
#
|
||||
# Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
# Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-include $(TOPDIR)/Make.defs
|
||||
|
||||
# CAN utility library
|
||||
|
||||
ASRCS =
|
||||
CSRCS = canlib_getbaud.c canlib_setbaud.c
|
||||
CSRCS+= canlib_getloopback.c canlib_setloopback.c
|
||||
CSRCS+= canlib_getsilent.c canlib_setsilent.c
|
||||
|
||||
include $(APPDIR)/Application.mk
|
82
canutils/canlib/canlib_getbaud.c
Normal file
82
canutils/canlib/canlib_getbaud.c
Normal file
@ -0,0 +1,82 @@
|
||||
/****************************************************************************
|
||||
* canutils/canlib/canlib_getbaud.c
|
||||
*
|
||||
* Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_getbaud
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_GET_BITTIMING
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* baud - pointer to a buffer to store the current baud rate
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_getbaud(int fd, FAR int *bauds)
|
||||
{
|
||||
int ret;
|
||||
struct canioc_bittiming_s timings;
|
||||
|
||||
ret = ioctl(fd, CANIOC_GET_BITTIMING, (unsigned long)&timings);
|
||||
if (ret!=OK)
|
||||
{
|
||||
canerr("CANIOC_GET_BITTIMING failed, errno=%d\n", errno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*bauds = timings.bt_baud;
|
||||
|
||||
return ret;
|
||||
}
|
83
canutils/canlib/canlib_getloopback.c
Normal file
83
canutils/canlib/canlib_getloopback.c
Normal file
@ -0,0 +1,83 @@
|
||||
/****************************************************************************
|
||||
* canutils/canlib/canlib_getloopback.c
|
||||
*
|
||||
* Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_getloopback
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_GET_CONNMODES.
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* loopback - pointer to a buffer to store the current loopback mode state.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_getloopback(int fd, FAR bool *loopback)
|
||||
{
|
||||
int ret;
|
||||
struct canioc_connmodes_s connmodes;
|
||||
|
||||
ret = ioctl(fd, CANIOC_GET_CONNMODES, (unsigned long)&connmodes);
|
||||
if (ret!=OK)
|
||||
{
|
||||
canerr("CANIOC_GET_CONNMODES failed, errno=%d\n", errno);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*loopback = (bool)connmodes.bm_loopback;
|
||||
|
||||
return ret;
|
||||
}
|
84
canutils/canlib/canlib_getsilent.c
Normal file
84
canutils/canlib/canlib_getsilent.c
Normal file
@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
* canutils/canlib/canlib_getsilent.c
|
||||
*
|
||||
* Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_getsilent
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_GET_CONNMODES.
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* loopback - pointer to a buffer to store the current silent mode state.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_getsilent(int fd, FAR bool *silent)
|
||||
{
|
||||
int ret;
|
||||
struct canioc_connmodes_s connmodes;
|
||||
|
||||
ret = ioctl(fd, CANIOC_GET_CONNMODES, (unsigned long)&connmodes);
|
||||
if (ret!=OK)
|
||||
{
|
||||
canerr("CANIOC_GET_CONNMODES failed, errno=%d\n", errno);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*silent = (bool)connmodes.bm_silent;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
87
canutils/canlib/canlib_setbaud.c
Normal file
87
canutils/canlib/canlib_setbaud.c
Normal file
@ -0,0 +1,87 @@
|
||||
/****************************************************************************
|
||||
* canutils/canlib/canlib_setbaud.c
|
||||
*
|
||||
* Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_setbaud
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_SET_BITTIMING
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* baud - baud rate to use on the CAN bus
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_setbaud(int fd, int bauds)
|
||||
{
|
||||
int ret;
|
||||
struct canioc_bittiming_s timings;
|
||||
|
||||
ret = ioctl(fd, CANIOC_GET_BITTIMING, (unsigned long)&timings);
|
||||
if (ret!=OK)
|
||||
{
|
||||
canerr("CANIOC_GET_BITTIMING failed, errno=%d\n", errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
timings.bt_baud = bauds;
|
||||
ret = ioctl(fd, CANIOC_SET_BITTIMING, (unsigned long)&timings);
|
||||
|
||||
if (ret!=OK)
|
||||
{
|
||||
canerr("CANIOC_SET_BITTIMING failed, errno=%d\n", errno);
|
||||
}
|
||||
return ret;
|
||||
}
|
89
canutils/canlib/canlib_setloopback.c
Normal file
89
canutils/canlib/canlib_setloopback.c
Normal file
@ -0,0 +1,89 @@
|
||||
/****************************************************************************
|
||||
* canutils/canlib/canlib_setloopback.c
|
||||
*
|
||||
* Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_setloopback
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_SET_CONNMODES. When loopback mode is enabled, the CAN
|
||||
* peripheral transmits on the bus, but only receives its own sent messages.
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* loopback - wether to use loopback mode.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_setloopback(int fd, bool loopback)
|
||||
{
|
||||
int ret;
|
||||
struct canioc_connmodes_s connmodes;
|
||||
|
||||
ret = ioctl(fd, CANIOC_GET_CONNMODES, (unsigned long)&connmodes);
|
||||
if (ret!=OK)
|
||||
{
|
||||
canerr("CANIOC_GET_CONNMODES failed, errno=%d\n", errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
connmodes.bm_loopback = !!loopback;
|
||||
ret = ioctl(fd, CANIOC_SET_CONNMODES, (unsigned long)&connmodes);
|
||||
|
||||
if (ret!=OK)
|
||||
{
|
||||
canerr("CANIOC_SET_CONNMODES failed, errno=%d\n", errno);
|
||||
}
|
||||
return ret;
|
||||
}
|
89
canutils/canlib/canlib_setsilent.c
Normal file
89
canutils/canlib/canlib_setsilent.c
Normal file
@ -0,0 +1,89 @@
|
||||
/****************************************************************************
|
||||
* canutils/canlib/canlib_setsilent.c
|
||||
*
|
||||
* Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/can.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_setsilent
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_SET_CONNMODES. When silent mode is enabled, the CAN
|
||||
* peripheral never transmits on the bus, but receives all bus traffic.
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* loopback - wether to use loopback mode.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_setsilent(int fd, bool silent)
|
||||
{
|
||||
int ret;
|
||||
struct canioc_connmodes_s connmodes;
|
||||
|
||||
ret = ioctl(fd, CANIOC_GET_CONNMODES, (unsigned long)&connmodes);
|
||||
if (ret!=OK)
|
||||
{
|
||||
canerr("CANIOC_GET_CONNMODES failed, errno=%d\n", errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
connmodes.bm_silent = !!silent;
|
||||
ret = ioctl(fd, CANIOC_SET_CONNMODES, (unsigned long)&connmodes);
|
||||
|
||||
if (ret!=OK)
|
||||
{
|
||||
canerr("CANIOC_SET_CONNMODES failed, errno=%d\n", errno);
|
||||
}
|
||||
return ret;
|
||||
}
|
190
include/canutils/canlib.h
Normal file
190
include/canutils/canlib.h
Normal file
@ -0,0 +1,190 @@
|
||||
/****************************************************************************
|
||||
* apps/include/canutils/canlib.h
|
||||
* Various non-standard APIs to support canutils. All non-standard and
|
||||
* intended only for internal use.
|
||||
*
|
||||
* Copyright (C) 2016 Sebastien Lorquet Nutt. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_INCLUDE_CANUTILS_CANLIB_H
|
||||
#define __APPS_INCLUDE_CANUTILS_CANLIB_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_setbaud
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_SET_BITTIMING
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* baud - baud rate to use on the CAN bus
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_setbaud(int fd, int bauds);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_getbaud
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_GET_BITTIMING
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* baud - pointer to a buffer to store the current baud rate
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_getbaud(int fd, FAR int *bauds);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_setloopback
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_SET_CONNMODES. When loopback mode is enabled, the CAN
|
||||
* peripheral transmits on the bus, but only receives its own sent messages.
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* loopback - wether to use loopback mode.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_getloopback
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_GET_CONNMODES.
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* loopback - pointer to a buffer to store the current loopback mode state.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_setloopback(int fd, bool loop);
|
||||
|
||||
int canlib_getloopback(int fd, FAR bool *loop);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_setsilent
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_SET_CONNMODES. When silent mode is enabled, the CAN
|
||||
* peripheral never transmits on the bus, but receives all bus traffic.
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* loopback - wether to use loopback mode.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_setsilent(int fd, bool silent);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: canlib_getsilent
|
||||
*
|
||||
* Description:
|
||||
* Wrapper for CANIOC_GET_CONNMODES.
|
||||
*
|
||||
* Input Parameter:
|
||||
* fd - file descriptor of an opened can device
|
||||
* loopback - pointer to a buffer to store the current silent mode state.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. Otherwise -1 (ERROR)
|
||||
* is returned with the errno variable set to indicate the
|
||||
* nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int canlib_getsilent(int fd, FAR bool *silent);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __APPS_INCLUDE_CANUTILS_CANLIB_H */
|
Loading…
Reference in New Issue
Block a user