Merged in paulpatience/nuttx-apps (pull request #12)
UAVCAN: Add example application
This commit is contained in:
commit
219fffb028
@ -159,8 +159,10 @@ libuavcan: $(LIBUAVCAN_UNPACKNAME) $(DSDL_UNPACKNAME) $(PYUAVCAN_UNPACKNAME)
|
|||||||
dsdlc_generated: libuavcan
|
dsdlc_generated: libuavcan
|
||||||
$(info $(shell $(LIBUAVCAN_DSDLC) $(UAVCAN_DSDL_DIR)))
|
$(info $(shell $(LIBUAVCAN_DSDLC) $(UAVCAN_DSDL_DIR)))
|
||||||
|
|
||||||
$(APPDIR)/include/uavcan: libuavcan/libuavcan/include/uavcan
|
$(APPDIR)/include/uavcan: libuavcan/libuavcan/include/uavcan dsdlc_generated/uavcan
|
||||||
$(Q) cp -R libuavcan/libuavcan/include/uavcan $(APPDIR)/include
|
$(Q) mkdir -p $(APPDIR)/include/uavcan
|
||||||
|
$(Q) cp -R libuavcan/libuavcan/include/uavcan/* $(APPDIR)/include/uavcan
|
||||||
|
$(Q) cp -R dsdlc_generated/uavcan/* $(APPDIR)/include/uavcan
|
||||||
|
|
||||||
$(CXXOBJS): %$(OBJEXT): %$(CXXEXT)
|
$(CXXOBJS): %$(OBJEXT): %$(CXXEXT)
|
||||||
$(call COMPILEXX, $<, $@)
|
$(call COMPILEXX, $<, $@)
|
||||||
|
@ -66,11 +66,6 @@ static void delay_callable()
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
uavcan::ISystemClock& getSystemClock()
|
|
||||||
{
|
|
||||||
return uavcan_stm32::SystemClock::instance();
|
|
||||||
}
|
|
||||||
|
|
||||||
uavcan::ICanDriver& getCanDriver()
|
uavcan::ICanDriver& getCanDriver()
|
||||||
{
|
{
|
||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
@ -83,13 +78,8 @@ uavcan::ICanDriver& getCanDriver()
|
|||||||
int retries = 0;
|
int retries = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (;;)
|
while (can.init(delay_callable, bitrate) < 0)
|
||||||
{
|
{
|
||||||
if (can.init(delay_callable, bitrate) >= 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if CONFIG_UAVCAN_INIT_RETRIES > 0
|
#if CONFIG_UAVCAN_INIT_RETRIES > 0
|
||||||
retries++;
|
retries++;
|
||||||
if (retries >= CONFIG_UAVCAN_INIT_RETRIES)
|
if (retries >= CONFIG_UAVCAN_INIT_RETRIES)
|
||||||
@ -104,3 +94,8 @@ uavcan::ICanDriver& getCanDriver()
|
|||||||
|
|
||||||
return can.driver;
|
return can.driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uavcan::ISystemClock& getSystemClock()
|
||||||
|
{
|
||||||
|
return uavcan_stm32::SystemClock::instance();
|
||||||
|
}
|
||||||
|
@ -74,6 +74,7 @@ source "$APPSDIR/examples/thttpd/Kconfig"
|
|||||||
source "$APPSDIR/examples/timer/Kconfig"
|
source "$APPSDIR/examples/timer/Kconfig"
|
||||||
source "$APPSDIR/examples/tiff/Kconfig"
|
source "$APPSDIR/examples/tiff/Kconfig"
|
||||||
source "$APPSDIR/examples/touchscreen/Kconfig"
|
source "$APPSDIR/examples/touchscreen/Kconfig"
|
||||||
|
source "$APPSDIR/examples/uavcan/Kconfig"
|
||||||
source "$APPSDIR/examples/udp/Kconfig"
|
source "$APPSDIR/examples/udp/Kconfig"
|
||||||
source "$APPSDIR/examples/udpblaster/Kconfig"
|
source "$APPSDIR/examples/udpblaster/Kconfig"
|
||||||
source "$APPSDIR/examples/discover/Kconfig"
|
source "$APPSDIR/examples/discover/Kconfig"
|
||||||
|
33
examples/uavcan/Kconfig
Normal file
33
examples/uavcan/Kconfig
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#
|
||||||
|
# For a description of the syntax of this configuration file,
|
||||||
|
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||||
|
#
|
||||||
|
|
||||||
|
config EXAMPLES_UAVCAN
|
||||||
|
bool "UAVCAN example"
|
||||||
|
default n
|
||||||
|
depends on CANUTILS_UAVCAN && LIB_BOARDCTL
|
||||||
|
---help---
|
||||||
|
Enable the UAVCAN example
|
||||||
|
|
||||||
|
if EXAMPLES_UAVCAN
|
||||||
|
|
||||||
|
config EXAMPLES_UAVCAN_NODE_MEM_POOL_SIZE
|
||||||
|
int "Node Memory Pool Size"
|
||||||
|
default 4096
|
||||||
|
---help---
|
||||||
|
Specifies the node's memory pool size
|
||||||
|
|
||||||
|
config EXAMPLES_UAVCAN_NODE_ID
|
||||||
|
int "Node ID"
|
||||||
|
default 0
|
||||||
|
---help---
|
||||||
|
Specifies the node's ID
|
||||||
|
|
||||||
|
config EXAMPLES_UAVCAN_NODE_NAME
|
||||||
|
string "Node Name"
|
||||||
|
default "org.nuttx.apps.examples.uavcan"
|
||||||
|
---help---
|
||||||
|
Specifies the node's name
|
||||||
|
|
||||||
|
endif
|
39
examples/uavcan/Make.defs
Normal file
39
examples/uavcan/Make.defs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
############################################################################
|
||||||
|
# apps/examples/uavcan/Make.defs
|
||||||
|
# Adds selected applications to apps/ build
|
||||||
|
#
|
||||||
|
# Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved.
|
||||||
|
# Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
||||||
|
#
|
||||||
|
# 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_EXAMPLES_UAVCAN),y)
|
||||||
|
CONFIGURED_APPS += examples/uavcan
|
||||||
|
endif
|
42
examples/uavcan/Makefile
Normal file
42
examples/uavcan/Makefile
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
############################################################################
|
||||||
|
# apps/examples/uavcan/Makefile
|
||||||
|
#
|
||||||
|
# Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved.
|
||||||
|
# Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
|
||||||
|
MAINSRC = uavcan_main.cxx
|
||||||
|
|
||||||
|
CXXFLAGS += -I$(TOPDIR)/include/apps
|
||||||
|
|
||||||
|
include $(APPDIR)/Application.mk
|
101
examples/uavcan/uavcan_main.cxx
Normal file
101
examples/uavcan/uavcan_main.cxx
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* examples/uavcan/uavcan_main.cxx
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved.
|
||||||
|
* Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
||||||
|
*
|
||||||
|
* 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 <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
#include <uavcan/uavcan.hpp>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CONFIG_BUILD_KERNEL
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
int uavcan_main(int argc, FAR char *argv[]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uavcan::ICanDriver& getCanDriver();
|
||||||
|
uavcan::ISystemClock& getSystemClock();
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: uavcan_main
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_BUILD_KERNEL
|
||||||
|
int main(int argc, FAR char *argv[])
|
||||||
|
#else
|
||||||
|
int uavcan_main(int argc, FAR char *argv[])
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
uavcan::Node<CONFIG_EXAMPLES_UAVCAN_NODE_MEM_POOL_SIZE>
|
||||||
|
node(getCanDriver(), getSystemClock());
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
node.setNodeID(CONFIG_EXAMPLES_UAVCAN_NODE_ID);
|
||||||
|
node.setName(CONFIG_EXAMPLES_UAVCAN_NODE_NAME);
|
||||||
|
|
||||||
|
ret = node.start();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
std::fprintf(stderr, "ERROR: node.start failed: %d\n", ret);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
node.setModeOperational();
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
ret = node.spin(uavcan::MonotonicDuration::fromMSec(100));
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
std::fprintf(stderr, "ERROR: node.spin failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user