diff --git a/.gitignore b/.gitignore index 179d3cd025..0ad0dfa15d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,8 +10,8 @@ __pycache__ *.pyc # Eclipse -.metadata/* -.settings/* +.metadata +.settings .project .cproject .pydevproject diff --git a/README.md b/README.md index 26e3e21dae..14e62c21de 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,10 @@ Despite the fact that the library itself can be used on virtually any platform t Prerequisites: -* Google test library for C++ - gtest +* Google test library for C++ - gtest (see [how to install on Debian/Ubuntu](http://stackoverflow.com/questions/13513905/how-to-properly-setup-googletest-on-linux)) * C++03 *and* C++11 capable compiler with GCC-like interface (e.g. GCC, Clang) * CMake 2.8+ -* Optional: static analysis tool for C++ - cppcheck +* Optional: static analysis tool for C++ - cppcheck (use Debian/Ubuntu package `cppcheck`) Building the debug version and running the unit tests: ```bash @@ -31,4 +31,20 @@ cmake .. -DCMAKE_BUILD_TYPE=Debug make ``` +Test outputs can be found in the build directory under `libuavcan`. + Contributors, please follow the [Zubax Style Guide](https://github.com/Zubax/zubax_style_guide). + +### Submitting a coverity build + +First, [get the Coverity build tool](https://scan.coverity.com/download?tab=cxx). Then build the library with it: + +```bash +export PATH=$PATH:/bin/ +mkdir debug && cd debug +cmake -DCMAKE_BUILD_TYPE=Debug +cov-build --dir cov-int make -j8 +tar czvf uavcan.tgz cov-int +``` + +Then upload the resulting archive to Coverity. diff --git a/dsdl/uavcan/protocol/552.GetDataTypeInfo.uavcan b/dsdl/uavcan/protocol/552.GetDataTypeInfo.uavcan index 8392045c26..c744ad707a 100644 --- a/dsdl/uavcan/protocol/552.GetDataTypeInfo.uavcan +++ b/dsdl/uavcan/protocol/552.GetDataTypeInfo.uavcan @@ -1,13 +1,23 @@ # # Get the implementation details of a given data type. # +# Request is interpreted as follows: +# - If the field 'name' is empty, the fields 'kind' and 'id' will be used to identify the data type. +# - If the field 'name' is non-empty, it will be used to identify the data type; the +# fields 'kind' and 'id' will be ignored. +# -uint16 id -DataTypeKind kind +uint16 id # Ignored if 'name' is non-empty +DataTypeKind kind # Ignored if 'name' is non-empty + +uint8[<=80] name # Full data type name, e.g. "uavcan.protocol.GetDataTypeInfo" --- -uint64 signature # Data type signature +uint64 signature # Data type signature; valid only if the data type is known (see MASK_KNOWN) + +uint16 id # Valid only if the data type is known (see MASK_KNOWN) +DataTypeKind kind # Ditto uint8 MASK_KNOWN = 1 # This data type is defined uint8 MASK_SUBSCRIBED = 2 # Subscribed to messages of this type @@ -15,4 +25,4 @@ uint8 MASK_PUBLISHING = 4 # Publishing messages of this type uint8 MASK_SERVING = 8 # Providing service of this type uint8 mask -uint8[<=80] name # Full data type name, e.g. "uavcan.protocol.GetDataTypeInfo" +uint8[<=80] name # Full data type name; valid only if the data type is known (see MASK_KNOWN) diff --git a/dsdl/uavcan/protocol/DataTypeKind.uavcan b/dsdl/uavcan/protocol/DataTypeKind.uavcan index 925a575e0c..58dd68b056 100644 --- a/dsdl/uavcan/protocol/DataTypeKind.uavcan +++ b/dsdl/uavcan/protocol/DataTypeKind.uavcan @@ -2,6 +2,6 @@ # Data type kind (message or service). # -uint2 SERVICE = 0 -uint2 MESSAGE = 1 -uint2 value +uint8 SERVICE = 0 +uint8 MESSAGE = 1 +uint8 value diff --git a/libuavcan/CMakeLists.txt b/libuavcan/CMakeLists.txt index 0648b8ca14..fc4afc96ad 100644 --- a/libuavcan/CMakeLists.txt +++ b/libuavcan/CMakeLists.txt @@ -103,6 +103,7 @@ if (DEBUG_BUILD) if (COMPILER_IS_GCC_COMPATIBLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic -Wfloat-equal -Wconversion") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-conversion -Wcast-align -Wmissing-declarations") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=array-bounds") set(cpp03_flags "-std=c++03 -Wno-variadic-macros -Wno-long-long") set(optim_flags "-O3 -DNDEBUG -g0") else () diff --git a/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/__init__.py b/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/__init__.py index 88b4def241..0de8fea8a9 100644 --- a/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/__init__.py +++ b/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/__init__.py @@ -165,6 +165,7 @@ def generate_one_type(template_expander, t): t.short_name = t.full_name.split('.')[-1] t.cpp_type_name = t.short_name + '_' t.cpp_full_type_name = '::' + t.full_name.replace('.', '::') + t.include_guard = t.full_name.replace('.', '_').upper() + '_HPP_INCLUDED' # Dependencies (no duplicates) def fields_includes(fields): diff --git a/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/data_type_template.tmpl b/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/data_type_template.tmpl index 144bd58850..8b3ba7855e 100644 --- a/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/data_type_template.tmpl +++ b/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/data_type_template.tmpl @@ -6,7 +6,8 @@ * Source file: ${t.source_file} */ -#pragma once +#ifndef ${t.include_guard} +#define ${t.include_guard} #include #include @@ -385,3 +386,5 @@ ${define_streaming_operator(type_name=t.cpp_full_type_name)} % for nsc in t.cpp_namespace_components: } % endfor + +#endif // ${t.include_guard} diff --git a/libuavcan/include/uavcan/build_config.hpp b/libuavcan/include/uavcan/build_config.hpp index f9d6c65934..fac52be812 100644 --- a/libuavcan/include/uavcan/build_config.hpp +++ b/libuavcan/include/uavcan/build_config.hpp @@ -2,13 +2,14 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_BUILD_CONFIG_HPP_INCLUDED +#define UAVCAN_BUILD_CONFIG_HPP_INCLUDED /** * UAVCAN version definition */ -#define UAVCAN_VERSION_MAJOR 0 -#define UAVCAN_VERSION_MINOR 1 +#define UAVCAN_VERSION_MAJOR 1 +#define UAVCAN_VERSION_MINOR 0 /** * UAVCAN_CPP_VERSION - version of the C++ standard used during compilation. @@ -58,6 +59,22 @@ # endif #endif +/** + * This specification is used by some error reporting functions like in the Logger class. + * The default can be overriden by defining the macro UAVCAN_NOEXCEPT explicitly, e.g. via compiler options. + */ +#ifndef UAVCAN_NOEXCEPT +# if UAVCAN_EXCEPTIONS +# if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 +# define UAVCAN_NOEXCEPT noexcept +# else +# define UAVCAN_NOEXCEPT throw() +# endif +# else +# define UAVCAN_NOEXCEPT +# endif +#endif + /** * Struct layout control. * Set UAVCAN_PACK_STRUCTS=1 and define UAVCAN_PACKED_BEGIN and UAVCAN_PACKED_END to reduce memory usage. @@ -196,3 +213,5 @@ static const unsigned FloatComparisonEpsilonMult = 10; #endif } + +#endif // UAVCAN_BUILD_CONFIG_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/data_type.hpp b/libuavcan/include/uavcan/data_type.hpp index 4fb3daf12f..8e47751647 100644 --- a/libuavcan/include/uavcan/data_type.hpp +++ b/libuavcan/include/uavcan/data_type.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_DATA_TYPE_HPP_INCLUDED +#define UAVCAN_DATA_TYPE_HPP_INCLUDED #include #include @@ -144,3 +145,5 @@ public: }; } + +#endif // UAVCAN_DATA_TYPE_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/debug.hpp b/libuavcan/include/uavcan/debug.hpp index bee2dd0ad1..8b2ca17247 100644 --- a/libuavcan/include/uavcan/debug.hpp +++ b/libuavcan/include/uavcan/debug.hpp @@ -3,7 +3,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_DEBUG_HPP_INCLUDED +#define UAVCAN_DEBUG_HPP_INCLUDED #include @@ -30,3 +31,5 @@ static void UAVCAN_TRACE(const char* src, const char* fmt, ...) # define UAVCAN_TRACE(...) ((void)0) #endif + +#endif // UAVCAN_DEBUG_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/driver/can.hpp b/libuavcan/include/uavcan/driver/can.hpp index d55859d0a0..ad77abfcf7 100644 --- a/libuavcan/include/uavcan/driver/can.hpp +++ b/libuavcan/include/uavcan/driver/can.hpp @@ -3,7 +3,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_DRIVER_CAN_HPP_INCLUDED +#define UAVCAN_DRIVER_CAN_HPP_INCLUDED #include #include @@ -187,3 +188,5 @@ public: }; } + +#endif // UAVCAN_DRIVER_CAN_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/driver/system_clock.hpp b/libuavcan/include/uavcan/driver/system_clock.hpp index d19480e358..22055b457e 100644 --- a/libuavcan/include/uavcan/driver/system_clock.hpp +++ b/libuavcan/include/uavcan/driver/system_clock.hpp @@ -3,7 +3,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_DRIVER_SYSTEM_CLOCK_HPP_INCLUDED +#define UAVCAN_DRIVER_SYSTEM_CLOCK_HPP_INCLUDED #include #include @@ -44,3 +45,5 @@ public: }; } + +#endif // UAVCAN_DRIVER_SYSTEM_CLOCK_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/dynamic_memory.hpp b/libuavcan/include/uavcan/dynamic_memory.hpp index 3783f8ba8f..7c0ffb2038 100644 --- a/libuavcan/include/uavcan/dynamic_memory.hpp +++ b/libuavcan/include/uavcan/dynamic_memory.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_DYNAMIC_MEMORY_HPP_INCLUDED +#define UAVCAN_DYNAMIC_MEMORY_HPP_INCLUDED #include #include @@ -297,3 +298,5 @@ unsigned PoolAllocator::getNumFreeBlocks() const } } + +#endif // UAVCAN_DYNAMIC_MEMORY_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/error.hpp b/libuavcan/include/uavcan/error.hpp index 13935a1fd6..1cbeafcc22 100644 --- a/libuavcan/include/uavcan/error.hpp +++ b/libuavcan/include/uavcan/error.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_ERROR_HPP_INCLUDED +#define UAVCAN_ERROR_HPP_INCLUDED #include #include @@ -53,3 +54,5 @@ UAVCAN_EXPORT void handleFatalError(const char* msg); } + +#endif // UAVCAN_ERROR_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/helpers/component_status_manager.hpp b/libuavcan/include/uavcan/helpers/component_status_manager.hpp index a71610b3ce..78d700b758 100644 --- a/libuavcan/include/uavcan/helpers/component_status_manager.hpp +++ b/libuavcan/include/uavcan/helpers/component_status_manager.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_HELPERS_COMPONENT_STATUS_MANAGER_HPP_INCLUDED +#define UAVCAN_HELPERS_COMPONENT_STATUS_MANAGER_HPP_INCLUDED #include #include @@ -68,3 +69,5 @@ template const unsigned ComponentStatusManager::NumComponents; } + +#endif // UAVCAN_HELPERS_COMPONENT_STATUS_MANAGER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/helpers/ostream.hpp b/libuavcan/include/uavcan/helpers/ostream.hpp index e75f9d22fe..5add58f4f3 100644 --- a/libuavcan/include/uavcan/helpers/ostream.hpp +++ b/libuavcan/include/uavcan/helpers/ostream.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_HELPERS_OSTREAM_HPP_INCLUDED +#define UAVCAN_HELPERS_OSTREAM_HPP_INCLUDED #include #include @@ -58,3 +59,5 @@ inline OStream& operator<<(OStream& s, const char* x) { std::printf("%s", x); re inline OStream& operator<<(OStream& s, OStream&(*manip)(OStream&)) { return manip(s); } } + +#endif // UAVCAN_HELPERS_OSTREAM_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/marshal/array.hpp b/libuavcan/include/uavcan/marshal/array.hpp index 8fc64f350f..70f1c27d97 100644 --- a/libuavcan/include/uavcan/marshal/array.hpp +++ b/libuavcan/include/uavcan/marshal/array.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_MARSHAL_ARRAY_HPP_INCLUDED +#define UAVCAN_MARSHAL_ARRAY_HPP_INCLUDED #include #include @@ -1034,3 +1035,5 @@ public: }; } + +#endif // UAVCAN_MARSHAL_ARRAY_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/marshal/bit_stream.hpp b/libuavcan/include/uavcan/marshal/bit_stream.hpp index 413893e627..b7504112ec 100644 --- a/libuavcan/include/uavcan/marshal/bit_stream.hpp +++ b/libuavcan/include/uavcan/marshal/bit_stream.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_MARSHAL_BIT_STREAM_HPP_INCLUDED +#define UAVCAN_MARSHAL_BIT_STREAM_HPP_INCLUDED #include #include @@ -116,3 +117,5 @@ public: }; } + +#endif // UAVCAN_MARSHAL_BIT_STREAM_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/marshal/char_array_formatter.hpp b/libuavcan/include/uavcan/marshal/char_array_formatter.hpp index 85e9d37678..244c3b1204 100644 --- a/libuavcan/include/uavcan/marshal/char_array_formatter.hpp +++ b/libuavcan/include/uavcan/marshal/char_array_formatter.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_MARSHAL_CHAR_ARRAY_FORMATTER_HPP_INCLUDED +#define UAVCAN_MARSHAL_CHAR_ARRAY_FORMATTER_HPP_INCLUDED #include #include @@ -137,3 +138,5 @@ public: #endif } + +#endif // UAVCAN_MARSHAL_CHAR_ARRAY_FORMATTER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/marshal/float_spec.hpp b/libuavcan/include/uavcan/marshal/float_spec.hpp index ec06e53f60..ab0063056a 100644 --- a/libuavcan/include/uavcan/marshal/float_spec.hpp +++ b/libuavcan/include/uavcan/marshal/float_spec.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_MARSHAL_FLOAT_SPEC_HPP_INCLUDED +#define UAVCAN_MARSHAL_FLOAT_SPEC_HPP_INCLUDED #include #include @@ -222,3 +223,5 @@ public: }; } + +#endif // UAVCAN_MARSHAL_FLOAT_SPEC_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/marshal/integer_spec.hpp b/libuavcan/include/uavcan/marshal/integer_spec.hpp index 8561b02155..2a74218581 100644 --- a/libuavcan/include/uavcan/marshal/integer_spec.hpp +++ b/libuavcan/include/uavcan/marshal/integer_spec.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_MARSHAL_INTEGER_SPEC_HPP_INCLUDED +#define UAVCAN_MARSHAL_INTEGER_SPEC_HPP_INCLUDED #include #include @@ -164,3 +165,5 @@ public: }; } + +#endif // UAVCAN_MARSHAL_INTEGER_SPEC_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/marshal/scalar_codec.hpp b/libuavcan/include/uavcan/marshal/scalar_codec.hpp index 6bc62c8e80..b46c1b16bb 100644 --- a/libuavcan/include/uavcan/marshal/scalar_codec.hpp +++ b/libuavcan/include/uavcan/marshal/scalar_codec.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_MARSHAL_SCALAR_CODEC_HPP_INCLUDED +#define UAVCAN_MARSHAL_SCALAR_CODEC_HPP_INCLUDED #include #include @@ -135,3 +136,5 @@ int ScalarCodec::decode(T& value) } } + +#endif // UAVCAN_MARSHAL_SCALAR_CODEC_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/marshal/type_util.hpp b/libuavcan/include/uavcan/marshal/type_util.hpp index 45df4d03c4..5be02921e8 100644 --- a/libuavcan/include/uavcan/marshal/type_util.hpp +++ b/libuavcan/include/uavcan/marshal/type_util.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_MARSHAL_TYPE_UTIL_HPP_INCLUDED +#define UAVCAN_MARSHAL_TYPE_UTIL_HPP_INCLUDED #include #include @@ -83,3 +84,5 @@ template class UAVCAN_EXPORT YamlStreamer; } + +#endif // UAVCAN_MARSHAL_TYPE_UTIL_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/marshal/types.hpp b/libuavcan/include/uavcan/marshal/types.hpp index a9df753a21..4fbbe98371 100644 --- a/libuavcan/include/uavcan/marshal/types.hpp +++ b/libuavcan/include/uavcan/marshal/types.hpp @@ -2,9 +2,12 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_MARSHAL_TYPES_HPP_INCLUDED +#define UAVCAN_MARSHAL_TYPES_HPP_INCLUDED #include #include #include #include + +#endif // UAVCAN_MARSHAL_TYPES_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/node/abstract_node.hpp b/libuavcan/include/uavcan/node/abstract_node.hpp index 9b93646000..cebdcec7fc 100644 --- a/libuavcan/include/uavcan/node/abstract_node.hpp +++ b/libuavcan/include/uavcan/node/abstract_node.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_NODE_ABSTRACT_NODE_HPP_INCLUDED +#define UAVCAN_NODE_ABSTRACT_NODE_HPP_INCLUDED #include #include @@ -78,3 +79,5 @@ public: }; } + +#endif // UAVCAN_NODE_ABSTRACT_NODE_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/node/generic_publisher.hpp b/libuavcan/include/uavcan/node/generic_publisher.hpp index 38bb31826f..aece082ddb 100644 --- a/libuavcan/include/uavcan/node/generic_publisher.hpp +++ b/libuavcan/include/uavcan/node/generic_publisher.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_NODE_GENERIC_PUBLISHER_HPP_INCLUDED +#define UAVCAN_NODE_GENERIC_PUBLISHER_HPP_INCLUDED #include #include @@ -172,3 +173,5 @@ int GenericPublisher::genericPublish(const DataStruct& mes } } + +#endif // UAVCAN_NODE_GENERIC_PUBLISHER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/node/generic_subscriber.hpp b/libuavcan/include/uavcan/node/generic_subscriber.hpp index 2cb6083ddf..3ec6b87f92 100644 --- a/libuavcan/include/uavcan/node/generic_subscriber.hpp +++ b/libuavcan/include/uavcan/node/generic_subscriber.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_NODE_GENERIC_SUBSCRIBER_HPP_INCLUDED +#define UAVCAN_NODE_GENERIC_SUBSCRIBER_HPP_INCLUDED #include #include @@ -207,10 +208,13 @@ protected: TransferListenerType* getTransferListener() { return forwarder_; } /** - * Returns the mutable reference to the temporary storage for decoded received messages. + * Returns a reference to the temporary storage for decoded received messages. * Reference to this storage is used as a parameter for subscription callbacks. + * This storage is guaranteed to stay intact after the last message was decoded, i.e. + * the application can use it to access the last received message object. */ - ReceivedDataStructure& getReceivedStructStorage() { return message_; } + ReceivedDataStructure& getReceivedStructStorage() { return message_; } + const ReceivedDataStructure& getReceivedStructStorage() const { return message_; } }; // ---------------------------------------------------------------------------- @@ -284,3 +288,5 @@ genericStart(bool (Dispatcher::*registration_method)(TransferListenerBase*)) } + +#endif // UAVCAN_NODE_GENERIC_SUBSCRIBER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/node/global_data_type_registry.hpp b/libuavcan/include/uavcan/node/global_data_type_registry.hpp index 8ee9d39a95..7e27d92886 100644 --- a/libuavcan/include/uavcan/node/global_data_type_registry.hpp +++ b/libuavcan/include/uavcan/node/global_data_type_registry.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_NODE_GLOBAL_DATA_TYPE_REGISTRY_HPP_INCLUDED +#define UAVCAN_NODE_GLOBAL_DATA_TYPE_REGISTRY_HPP_INCLUDED #include #include @@ -69,12 +70,12 @@ public: /** * Result of data type registration */ - enum RegistResult + enum RegistrationResult { - RegistResultOk, ///< Success, data type is now registered and can be used. - RegistResultCollision, ///< Data type name or ID is not unique. - RegistResultInvalidParams, ///< Invalid input parameters. - RegistResultFrozen ///< Data Type Registery has been frozen and can't be modified anymore. + RegistrationResultOk, ///< Success, data type is now registered and can be used. + RegistrationResultCollision, ///< Data type name or ID is not unique. + RegistrationResultInvalidParams, ///< Invalid input parameters. + RegistrationResultFrozen ///< Data Type Registery has been frozen and can't be modified anymore. }; private: @@ -87,8 +88,8 @@ private: List* selectList(DataTypeKind kind) const; - RegistResult remove(Entry* dtd); - RegistResult registImpl(Entry* dtd); + RegistrationResult remove(Entry* dtd); + RegistrationResult registImpl(Entry* dtd); public: /** @@ -107,7 +108,7 @@ public: * @param id Data Type ID for this data type. */ template - RegistResult regist(DataTypeID id); + RegistrationResult registerDataType(DataTypeID id); /** * Data Type registry needs to be frozen before a node instance can use it in @@ -125,6 +126,15 @@ public: /** * Finds data type descriptor by full data type name, e.g. "uavcan.protocol.NodeStatus". + * Messages are searched first, then services. + * Returns null pointer if the data type with this name is not registered. + * @param name Full data type name + * @return Descriptor for this data type or null pointer if not found + */ + const DataTypeDescriptor* find(const char* name) const; + + /** + * Finds data type descriptor by full data type name, e.g. "uavcan.protocol.NodeStatus", and data type kind. * Returns null pointer if the data type with this name is not registered. * @param kind Data Type Kind - message or service * @param name Full data type name @@ -204,10 +214,10 @@ struct UAVCAN_EXPORT DefaultDataTypeRegistrator { DefaultDataTypeRegistrator() { - const GlobalDataTypeRegistry::RegistResult res = - GlobalDataTypeRegistry::instance().regist(Type::DefaultDataTypeID); + const GlobalDataTypeRegistry::RegistrationResult res = + GlobalDataTypeRegistry::instance().registerDataType(Type::DefaultDataTypeID); - if (res != GlobalDataTypeRegistry::RegistResultOk) + if (res != GlobalDataTypeRegistry::RegistrationResultOk) { handleFatalError("Type reg failed"); } @@ -220,24 +230,24 @@ struct UAVCAN_EXPORT DefaultDataTypeRegistrator * GlobalDataTypeRegistry */ template -GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::regist(DataTypeID id) +GlobalDataTypeRegistry::RegistrationResult GlobalDataTypeRegistry::registerDataType(DataTypeID id) { if (isFrozen()) { - return RegistResultFrozen; + return RegistrationResultFrozen; } static Entry entry; { - const RegistResult remove_res = remove(&entry); - if (remove_res != RegistResultOk) + const RegistrationResult remove_res = remove(&entry); + if (remove_res != RegistrationResultOk) { return remove_res; } } entry = Entry(DataTypeKind(Type::DataTypeKind), id, Type::getDataTypeSignature(), Type::getDataTypeFullName()); { - const RegistResult remove_res = remove(&entry); - if (remove_res != RegistResultOk) + const RegistrationResult remove_res = remove(&entry); + if (remove_res != RegistrationResultOk) { return remove_res; } @@ -246,3 +256,5 @@ GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::regist(DataTypeID i } } + +#endif // UAVCAN_NODE_GLOBAL_DATA_TYPE_REGISTRY_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/node/marshal_buffer.hpp b/libuavcan/include/uavcan/node/marshal_buffer.hpp index f33c037653..7e55ce49dc 100644 --- a/libuavcan/include/uavcan/node/marshal_buffer.hpp +++ b/libuavcan/include/uavcan/node/marshal_buffer.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_NODE_MARSHAL_BUFFER_HPP_INCLUDED +#define UAVCAN_NODE_MARSHAL_BUFFER_HPP_INCLUDED #include #include @@ -87,3 +88,5 @@ public: }; } + +#endif // UAVCAN_NODE_MARSHAL_BUFFER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/node/node.hpp b/libuavcan/include/uavcan/node/node.hpp index 7f20d714c3..c04bf1103b 100644 --- a/libuavcan/include/uavcan/node/node.hpp +++ b/libuavcan/include/uavcan/node/node.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_NODE_NODE_HPP_INCLUDED +#define UAVCAN_NODE_NODE_HPP_INCLUDED #include #include @@ -322,3 +323,5 @@ checkNetworkCompatibility(NetworkCompatibilityCheckResult& result) #endif } + +#endif // UAVCAN_NODE_NODE_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/node/publisher.hpp b/libuavcan/include/uavcan/node/publisher.hpp index 5d1524f4da..6abb3bd533 100644 --- a/libuavcan/include/uavcan/node/publisher.hpp +++ b/libuavcan/include/uavcan/node/publisher.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_NODE_PUBLISHER_HPP_INCLUDED +#define UAVCAN_NODE_PUBLISHER_HPP_INCLUDED #include @@ -95,3 +96,5 @@ public: }; } + +#endif // UAVCAN_NODE_PUBLISHER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/node/scheduler.hpp b/libuavcan/include/uavcan/node/scheduler.hpp index f283f72e7e..847f76b9d9 100644 --- a/libuavcan/include/uavcan/node/scheduler.hpp +++ b/libuavcan/include/uavcan/node/scheduler.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_NODE_SCHEDULER_HPP_INCLUDED +#define UAVCAN_NODE_SCHEDULER_HPP_INCLUDED #include #include @@ -130,3 +131,5 @@ public: }; } + +#endif // UAVCAN_NODE_SCHEDULER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/node/service_client.hpp b/libuavcan/include/uavcan/node/service_client.hpp index 378c0601ff..1b73c5163b 100644 --- a/libuavcan/include/uavcan/node/service_client.hpp +++ b/libuavcan/include/uavcan/node/service_client.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_NODE_SERVICE_CLIENT_HPP_INCLUDED +#define UAVCAN_NODE_SERVICE_CLIENT_HPP_INCLUDED #include #include @@ -368,3 +369,5 @@ void ServiceClient::cancel() } } + +#endif // UAVCAN_NODE_SERVICE_CLIENT_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/node/service_server.hpp b/libuavcan/include/uavcan/node/service_server.hpp index 5ca6f970b5..6d5695451c 100644 --- a/libuavcan/include/uavcan/node/service_server.hpp +++ b/libuavcan/include/uavcan/node/service_server.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_NODE_SERVICE_SERVER_HPP_INCLUDED +#define UAVCAN_NODE_SERVICE_SERVER_HPP_INCLUDED #include #include @@ -157,3 +158,5 @@ public: }; } + +#endif // UAVCAN_NODE_SERVICE_SERVER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/node/subscriber.hpp b/libuavcan/include/uavcan/node/subscriber.hpp index 62b15e11b7..1112a6abc0 100644 --- a/libuavcan/include/uavcan/node/subscriber.hpp +++ b/libuavcan/include/uavcan/node/subscriber.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_NODE_SUBSCRIBER_HPP_INCLUDED +#define UAVCAN_NODE_SUBSCRIBER_HPP_INCLUDED #include #include @@ -115,3 +116,5 @@ public: }; } + +#endif // UAVCAN_NODE_SUBSCRIBER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/node/timer.hpp b/libuavcan/include/uavcan/node/timer.hpp index 3e0b360a84..1521489f99 100644 --- a/libuavcan/include/uavcan/node/timer.hpp +++ b/libuavcan/include/uavcan/node/timer.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_NODE_TIMER_HPP_INCLUDED +#define UAVCAN_NODE_TIMER_HPP_INCLUDED #include #include @@ -143,3 +144,5 @@ typedef TimerEventForwarder > Time #endif } + +#endif // UAVCAN_NODE_TIMER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/protocol/data_type_info_provider.hpp b/libuavcan/include/uavcan/protocol/data_type_info_provider.hpp index 799dc51ac4..9ec95c73d4 100644 --- a/libuavcan/include/uavcan/protocol/data_type_info_provider.hpp +++ b/libuavcan/include/uavcan/protocol/data_type_info_provider.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_PROTOCOL_DATA_TYPE_INFO_PROVIDER_HPP_INCLUDED +#define UAVCAN_PROTOCOL_DATA_TYPE_INFO_PROVIDER_HPP_INCLUDED #include #include @@ -51,3 +52,5 @@ public: }; } + +#endif // UAVCAN_PROTOCOL_DATA_TYPE_INFO_PROVIDER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/protocol/global_time_sync_master.hpp b/libuavcan/include/uavcan/protocol/global_time_sync_master.hpp index 0d477cc0e1..e658b33730 100644 --- a/libuavcan/include/uavcan/protocol/global_time_sync_master.hpp +++ b/libuavcan/include/uavcan/protocol/global_time_sync_master.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_PROTOCOL_GLOBAL_TIME_SYNC_MASTER_HPP_INCLUDED +#define UAVCAN_PROTOCOL_GLOBAL_TIME_SYNC_MASTER_HPP_INCLUDED #include #include @@ -92,3 +93,5 @@ public: }; } + +#endif // UAVCAN_PROTOCOL_GLOBAL_TIME_SYNC_MASTER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/protocol/global_time_sync_slave.hpp b/libuavcan/include/uavcan/protocol/global_time_sync_slave.hpp index 04c4e0f955..3da6532998 100644 --- a/libuavcan/include/uavcan/protocol/global_time_sync_slave.hpp +++ b/libuavcan/include/uavcan/protocol/global_time_sync_slave.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_PROTOCOL_GLOBAL_TIME_SYNC_SLAVE_HPP_INCLUDED +#define UAVCAN_PROTOCOL_GLOBAL_TIME_SYNC_SLAVE_HPP_INCLUDED #include #include @@ -103,3 +104,5 @@ public: }; } + +#endif // UAVCAN_PROTOCOL_GLOBAL_TIME_SYNC_SLAVE_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/protocol/logger.hpp b/libuavcan/include/uavcan/protocol/logger.hpp index e7d606a630..fcacfc4801 100644 --- a/libuavcan/include/uavcan/protocol/logger.hpp +++ b/libuavcan/include/uavcan/protocol/logger.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_PROTOCOL_LOGGER_HPP_INCLUDED +#define UAVCAN_PROTOCOL_LOGGER_HPP_INCLUDED #include #include @@ -148,52 +149,52 @@ public: #if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 template - int log(LogLevel level, const char* source, const char* format, Args... args); + int log(LogLevel level, const char* source, const char* format, Args... args) UAVCAN_NOEXCEPT; template - inline int logDebug(const char* source, const char* format, Args... args) + inline int logDebug(const char* source, const char* format, Args... args) UAVCAN_NOEXCEPT { return log(protocol::debug::LogLevel::DEBUG, source, format, args...); } template - inline int logInfo(const char* source, const char* format, Args... args) + inline int logInfo(const char* source, const char* format, Args... args) UAVCAN_NOEXCEPT { return log(protocol::debug::LogLevel::INFO, source, format, args...); } template - inline int logWarning(const char* source, const char* format, Args... args) + inline int logWarning(const char* source, const char* format, Args... args) UAVCAN_NOEXCEPT { return log(protocol::debug::LogLevel::WARNING, source, format, args...); } template - inline int logError(const char* source, const char* format, Args... args) + inline int logError(const char* source, const char* format, Args... args) UAVCAN_NOEXCEPT { return log(protocol::debug::LogLevel::ERROR, source, format, args...); } #else - int log(LogLevel level, const char* source, const char* text); + int log(LogLevel level, const char* source, const char* text) UAVCAN_NOEXCEPT; - int logDebug(const char* source, const char* text) + int logDebug(const char* source, const char* text) UAVCAN_NOEXCEPT { return log(protocol::debug::LogLevel::DEBUG, source, text); } - int logInfo(const char* source, const char* text) + int logInfo(const char* source, const char* text) UAVCAN_NOEXCEPT { return log(protocol::debug::LogLevel::INFO, source, text); } - int logWarning(const char* source, const char* text) + int logWarning(const char* source, const char* text) UAVCAN_NOEXCEPT { return log(protocol::debug::LogLevel::WARNING, source, text); } - int logError(const char* source, const char* text) + int logError(const char* source, const char* text) UAVCAN_NOEXCEPT { return log(protocol::debug::LogLevel::ERROR, source, text); } @@ -207,20 +208,33 @@ public: #if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 template -int Logger::log(LogLevel level, const char* source, const char* format, Args... args) +int Logger::log(LogLevel level, const char* source, const char* format, Args... args) UAVCAN_NOEXCEPT { - if (level >= level_ || level >= getExternalSinkLevel()) +#if UAVCAN_EXCEPTIONS + try +#endif { - msg_buf_.level.value = level; - msg_buf_.source = source; - msg_buf_.text.clear(); - CharArrayFormatter formatter(msg_buf_.text); - formatter.write(format, args...); - return log(msg_buf_); + if (level >= level_ || level >= getExternalSinkLevel()) + { + msg_buf_.level.value = level; + msg_buf_.source = source; + msg_buf_.text.clear(); + CharArrayFormatter formatter(msg_buf_.text); + formatter.write(format, args...); + return log(msg_buf_); + } + return 0; } - return 0; +#if UAVCAN_EXCEPTIONS + catch (...) + { + return -ErrFailure; + } +#endif } #endif } + +#endif // UAVCAN_PROTOCOL_LOGGER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/protocol/network_compat_checker.hpp b/libuavcan/include/uavcan/protocol/network_compat_checker.hpp index 2a5799e3bc..5a39b5c6fc 100644 --- a/libuavcan/include/uavcan/protocol/network_compat_checker.hpp +++ b/libuavcan/include/uavcan/protocol/network_compat_checker.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_PROTOCOL_NETWORK_COMPAT_CHECKER_HPP_INCLUDED +#define UAVCAN_PROTOCOL_NETWORK_COMPAT_CHECKER_HPP_INCLUDED #include #include @@ -104,3 +105,5 @@ public: }; } + +#endif // UAVCAN_PROTOCOL_NETWORK_COMPAT_CHECKER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/protocol/node_status_monitor.hpp b/libuavcan/include/uavcan/protocol/node_status_monitor.hpp index 962e6f93ff..e9028e37b9 100644 --- a/libuavcan/include/uavcan/protocol/node_status_monitor.hpp +++ b/libuavcan/include/uavcan/protocol/node_status_monitor.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_PROTOCOL_NODE_STATUS_MONITOR_HPP_INCLUDED +#define UAVCAN_PROTOCOL_NODE_STATUS_MONITOR_HPP_INCLUDED #include #include @@ -128,3 +129,5 @@ public: }; } + +#endif // UAVCAN_PROTOCOL_NODE_STATUS_MONITOR_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/protocol/node_status_provider.hpp b/libuavcan/include/uavcan/protocol/node_status_provider.hpp index 22f6eb2f80..524dd43c35 100644 --- a/libuavcan/include/uavcan/protocol/node_status_provider.hpp +++ b/libuavcan/include/uavcan/protocol/node_status_provider.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_PROTOCOL_NODE_STATUS_PROVIDER_HPP_INCLUDED +#define UAVCAN_PROTOCOL_NODE_STATUS_PROVIDER_HPP_INCLUDED #include #include @@ -110,3 +111,5 @@ public: }; } + +#endif // UAVCAN_PROTOCOL_NODE_STATUS_PROVIDER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/protocol/panic_broadcaster.hpp b/libuavcan/include/uavcan/protocol/panic_broadcaster.hpp index 0fe5b9fca4..c05a55fe2e 100644 --- a/libuavcan/include/uavcan/protocol/panic_broadcaster.hpp +++ b/libuavcan/include/uavcan/protocol/panic_broadcaster.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_PROTOCOL_PANIC_BROADCASTER_HPP_INCLUDED +#define UAVCAN_PROTOCOL_PANIC_BROADCASTER_HPP_INCLUDED #include #include @@ -31,10 +32,12 @@ public: } /** - * Begin broadcasting at the standard interval. + * Begin broadcasting at the standard interval (see BROADCASTING_INTERVAL_MS). * This method does not block and can't fail. + * @param short_reason Short ASCII string that describes the reason of the panic, 7 characters max. + * If the string exceeds 7 characters, it will be truncated. */ - void panic(const char* short_reason); + void panic(const char* short_reason_description); /** * Stop broadcasting immediately. @@ -47,3 +50,5 @@ public: }; } + +#endif // UAVCAN_PROTOCOL_PANIC_BROADCASTER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/protocol/panic_listener.hpp b/libuavcan/include/uavcan/protocol/panic_listener.hpp index d39f41115f..4a93252608 100644 --- a/libuavcan/include/uavcan/protocol/panic_listener.hpp +++ b/libuavcan/include/uavcan/protocol/panic_listener.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_PROTOCOL_PANIC_LISTENER_HPP_INCLUDED +#define UAVCAN_PROTOCOL_PANIC_LISTENER_HPP_INCLUDED #include #include @@ -123,3 +124,5 @@ public: }; } + +#endif // UAVCAN_PROTOCOL_PANIC_LISTENER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/protocol/param_server.hpp b/libuavcan/include/uavcan/protocol/param_server.hpp index ad82f4f57a..f0292198a2 100644 --- a/libuavcan/include/uavcan/protocol/param_server.hpp +++ b/libuavcan/include/uavcan/protocol/param_server.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_PROTOCOL_PARAM_SERVER_HPP_INCLUDED +#define UAVCAN_PROTOCOL_PARAM_SERVER_HPP_INCLUDED #include #include @@ -105,3 +106,5 @@ public: }; } + +#endif // UAVCAN_PROTOCOL_PARAM_SERVER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/protocol/restart_request_server.hpp b/libuavcan/include/uavcan/protocol/restart_request_server.hpp index 7964f61a77..4f9a414e13 100644 --- a/libuavcan/include/uavcan/protocol/restart_request_server.hpp +++ b/libuavcan/include/uavcan/protocol/restart_request_server.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_PROTOCOL_RESTART_REQUEST_SERVER_HPP_INCLUDED +#define UAVCAN_PROTOCOL_RESTART_REQUEST_SERVER_HPP_INCLUDED #include #include @@ -66,3 +67,5 @@ public: }; } + +#endif // UAVCAN_PROTOCOL_RESTART_REQUEST_SERVER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/protocol/transport_stats_provider.hpp b/libuavcan/include/uavcan/protocol/transport_stats_provider.hpp index 3687e94015..173e9c4b7c 100644 --- a/libuavcan/include/uavcan/protocol/transport_stats_provider.hpp +++ b/libuavcan/include/uavcan/protocol/transport_stats_provider.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_PROTOCOL_TRANSPORT_STATS_PROVIDER_HPP_INCLUDED +#define UAVCAN_PROTOCOL_TRANSPORT_STATS_PROVIDER_HPP_INCLUDED #include #include @@ -39,3 +40,5 @@ public: }; } + +#endif // UAVCAN_PROTOCOL_TRANSPORT_STATS_PROVIDER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/stdint.hpp b/libuavcan/include/uavcan/stdint.hpp index a3340a0b77..4fc668a2a7 100644 --- a/libuavcan/include/uavcan/stdint.hpp +++ b/libuavcan/include/uavcan/stdint.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_STDINT_HPP_INCLUDED +#define UAVCAN_STDINT_HPP_INCLUDED #include @@ -52,3 +53,5 @@ typedef ::int64_t int64_t; } #endif + +#endif // UAVCAN_STDINT_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/time.hpp b/libuavcan/include/uavcan/time.hpp index 8158c802b9..094016fb35 100644 --- a/libuavcan/include/uavcan/time.hpp +++ b/libuavcan/include/uavcan/time.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_TIME_HPP_INCLUDED +#define UAVCAN_TIME_HPP_INCLUDED #include #include @@ -286,3 +287,5 @@ Stream& operator<<(Stream& s, const TimeBase& t) } } + +#endif // UAVCAN_TIME_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/transport/abstract_transfer_buffer.hpp b/libuavcan/include/uavcan/transport/abstract_transfer_buffer.hpp index 660ae794c7..7cc703c4c2 100644 --- a/libuavcan/include/uavcan/transport/abstract_transfer_buffer.hpp +++ b/libuavcan/include/uavcan/transport/abstract_transfer_buffer.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_TRANSPORT_ABSTRACT_TRANSFER_BUFFER_HPP_INCLUDED +#define UAVCAN_TRANSPORT_ABSTRACT_TRANSFER_BUFFER_HPP_INCLUDED #include #include @@ -22,3 +23,5 @@ public: }; } + +#endif // UAVCAN_TRANSPORT_ABSTRACT_TRANSFER_BUFFER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/transport/can_io.hpp b/libuavcan/include/uavcan/transport/can_io.hpp index 005e9825ea..cee418569d 100644 --- a/libuavcan/include/uavcan/transport/can_io.hpp +++ b/libuavcan/include/uavcan/transport/can_io.hpp @@ -3,7 +3,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_TRANSPORT_CAN_IO_HPP_INCLUDED +#define UAVCAN_TRANSPORT_CAN_IO_HPP_INCLUDED #include #include @@ -164,6 +165,9 @@ public: CanIfacePerfCounters getIfacePerfCounters(uint8_t iface_index) const; + const ICanDriver& getCanDriver() const { return driver_; } + ICanDriver& getCanDriver() { return driver_; } + /** * Returns: * 0 - rejected/timedout/enqueued @@ -176,3 +180,5 @@ public: }; } + +#endif // UAVCAN_TRANSPORT_CAN_IO_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/transport/crc.hpp b/libuavcan/include/uavcan/transport/crc.hpp index 15b19e4e97..abee099522 100644 --- a/libuavcan/include/uavcan/transport/crc.hpp +++ b/libuavcan/include/uavcan/transport/crc.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_TRANSPORT_CRC_HPP_INCLUDED +#define UAVCAN_TRANSPORT_CRC_HPP_INCLUDED #include #include @@ -75,3 +76,5 @@ public: }; } + +#endif // UAVCAN_TRANSPORT_CRC_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/transport/dispatcher.hpp b/libuavcan/include/uavcan/transport/dispatcher.hpp index 94e70a6ef4..a34789bf36 100644 --- a/libuavcan/include/uavcan/transport/dispatcher.hpp +++ b/libuavcan/include/uavcan/transport/dispatcher.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_TRANSPORT_DISPATCHER_HPP_INCLUDED +#define UAVCAN_TRANSPORT_DISPATCHER_HPP_INCLUDED #include #include @@ -192,3 +193,5 @@ public: }; } + +#endif // UAVCAN_TRANSPORT_DISPATCHER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/transport/frame.hpp b/libuavcan/include/uavcan/transport/frame.hpp index ce8d82cff7..49d1da2214 100644 --- a/libuavcan/include/uavcan/transport/frame.hpp +++ b/libuavcan/include/uavcan/transport/frame.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_TRANSPORT_FRAME_HPP_INCLUDED +#define UAVCAN_TRANSPORT_FRAME_HPP_INCLUDED #include #include @@ -128,3 +129,5 @@ public: }; } + +#endif // UAVCAN_TRANSPORT_FRAME_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/transport/outgoing_transfer_registry.hpp b/libuavcan/include/uavcan/transport/outgoing_transfer_registry.hpp index 72144e7647..9d91ac1955 100644 --- a/libuavcan/include/uavcan/transport/outgoing_transfer_registry.hpp +++ b/libuavcan/include/uavcan/transport/outgoing_transfer_registry.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_TRANSPORT_OUTGOING_TRANSFER_REGISTRY_HPP_INCLUDED +#define UAVCAN_TRANSPORT_OUTGOING_TRANSFER_REGISTRY_HPP_INCLUDED #include #include @@ -174,3 +175,5 @@ void OutgoingTransferRegistry::cleanup(MonotonicTime ts) } } + +#endif // UAVCAN_TRANSPORT_OUTGOING_TRANSFER_REGISTRY_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/transport/perf_counter.hpp b/libuavcan/include/uavcan/transport/perf_counter.hpp index 2e35fdc06e..009dfeec81 100644 --- a/libuavcan/include/uavcan/transport/perf_counter.hpp +++ b/libuavcan/include/uavcan/transport/perf_counter.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_TRANSPORT_PERF_COUNTER_HPP_INCLUDED +#define UAVCAN_TRANSPORT_PERF_COUNTER_HPP_INCLUDED #include #include @@ -57,3 +58,5 @@ public: #endif } + +#endif // UAVCAN_TRANSPORT_PERF_COUNTER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/transport/transfer.hpp b/libuavcan/include/uavcan/transport/transfer.hpp index c2ca103008..d5c3f8268f 100644 --- a/libuavcan/include/uavcan/transport/transfer.hpp +++ b/libuavcan/include/uavcan/transport/transfer.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_TRANSPORT_TRANSFER_HPP_INCLUDED +#define UAVCAN_TRANSPORT_TRANSFER_HPP_INCLUDED #include #include @@ -100,3 +101,5 @@ public: }; } + +#endif // UAVCAN_TRANSPORT_TRANSFER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/transport/transfer_buffer.hpp b/libuavcan/include/uavcan/transport/transfer_buffer.hpp index 15d337daad..d29bcce9ed 100644 --- a/libuavcan/include/uavcan/transport/transfer_buffer.hpp +++ b/libuavcan/include/uavcan/transport/transfer_buffer.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_TRANSPORT_TRANSFER_BUFFER_HPP_INCLUDED +#define UAVCAN_TRANSPORT_TRANSFER_BUFFER_HPP_INCLUDED #include #include @@ -324,3 +325,5 @@ public: }; } + +#endif // UAVCAN_TRANSPORT_TRANSFER_BUFFER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/transport/transfer_listener.hpp b/libuavcan/include/uavcan/transport/transfer_listener.hpp index 2965415735..a8210821ce 100644 --- a/libuavcan/include/uavcan/transport/transfer_listener.hpp +++ b/libuavcan/include/uavcan/transport/transfer_listener.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_TRANSPORT_TRANSFER_LISTENER_HPP_INCLUDED +#define UAVCAN_TRANSPORT_TRANSFER_LISTENER_HPP_INCLUDED #include #include @@ -246,3 +247,5 @@ void ServiceResponseTransferListener::stopAcceptingAnything() } } + +#endif // UAVCAN_TRANSPORT_TRANSFER_LISTENER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/transport/transfer_receiver.hpp b/libuavcan/include/uavcan/transport/transfer_receiver.hpp index 8fbb6865bd..737c9bc2db 100644 --- a/libuavcan/include/uavcan/transport/transfer_receiver.hpp +++ b/libuavcan/include/uavcan/transport/transfer_receiver.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_TRANSPORT_TRANSFER_RECEIVER_HPP_INCLUDED +#define UAVCAN_TRANSPORT_TRANSFER_RECEIVER_HPP_INCLUDED #include #include @@ -83,3 +84,5 @@ public: UAVCAN_PACKED_END } + +#endif // UAVCAN_TRANSPORT_TRANSFER_RECEIVER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/transport/transfer_sender.hpp b/libuavcan/include/uavcan/transport/transfer_sender.hpp index 0e5ac32a3a..27ab8a1038 100644 --- a/libuavcan/include/uavcan/transport/transfer_sender.hpp +++ b/libuavcan/include/uavcan/transport/transfer_sender.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_TRANSPORT_TRANSFER_SENDER_HPP_INCLUDED +#define UAVCAN_TRANSPORT_TRANSFER_SENDER_HPP_INCLUDED #include #include @@ -75,3 +76,5 @@ public: }; } + +#endif // UAVCAN_TRANSPORT_TRANSFER_SENDER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/uavcan.hpp b/libuavcan/include/uavcan/uavcan.hpp index cb925b139c..9a0139aeb3 100644 --- a/libuavcan/include/uavcan/uavcan.hpp +++ b/libuavcan/include/uavcan/uavcan.hpp @@ -4,7 +4,8 @@ * This header should be included by the user application. */ -#pragma once +#ifndef UAVCAN_UAVCAN_HPP_INCLUDED +#define UAVCAN_UAVCAN_HPP_INCLUDED #include #include @@ -22,3 +23,5 @@ #include #include #include + +#endif // UAVCAN_UAVCAN_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/util/bitset.hpp b/libuavcan/include/uavcan/util/bitset.hpp index 0a9c5ea43e..3ef06494bb 100644 --- a/libuavcan/include/uavcan/util/bitset.hpp +++ b/libuavcan/include/uavcan/util/bitset.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_UTIL_BITSET_HPP_INCLUDED +#define UAVCAN_UTIL_BITSET_HPP_INCLUDED #include #include @@ -184,3 +185,5 @@ Stream& operator<<(Stream& s, const BitSet& x) } } + +#endif // UAVCAN_UTIL_BITSET_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/util/comparison.hpp b/libuavcan/include/uavcan/util/comparison.hpp index d53116790d..8c8f007371 100644 --- a/libuavcan/include/uavcan/util/comparison.hpp +++ b/libuavcan/include/uavcan/util/comparison.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_UTIL_COMPARISON_HPP_INCLUDED +#define UAVCAN_UTIL_COMPARISON_HPP_INCLUDED #include #include @@ -266,3 +267,5 @@ inline bool isCloseToZero(const long double& x) } } + +#endif // UAVCAN_UTIL_COMPARISON_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/util/lazy_constructor.hpp b/libuavcan/include/uavcan/util/lazy_constructor.hpp index 3ca212d006..93152adc71 100644 --- a/libuavcan/include/uavcan/util/lazy_constructor.hpp +++ b/libuavcan/include/uavcan/util/lazy_constructor.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_UTIL_LAZY_CONSTRUCTOR_HPP_INCLUDED +#define UAVCAN_UTIL_LAZY_CONSTRUCTOR_HPP_INCLUDED #include #include @@ -173,3 +174,5 @@ public: }; } + +#endif // UAVCAN_UTIL_LAZY_CONSTRUCTOR_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/util/linked_list.hpp b/libuavcan/include/uavcan/util/linked_list.hpp index d36e83b463..9ca898e1fd 100644 --- a/libuavcan/include/uavcan/util/linked_list.hpp +++ b/libuavcan/include/uavcan/util/linked_list.hpp @@ -3,7 +3,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_UTIL_LINKED_LIST_HPP_INCLUDED +#define UAVCAN_UTIL_LINKED_LIST_HPP_INCLUDED #include #include @@ -99,9 +100,9 @@ unsigned LinkedListRoot::getLength() const template void LinkedListRoot::insert(T* node) { - UAVCAN_ASSERT(node); if (node == NULL) { + UAVCAN_ASSERT(0); return; } remove(node); // Making sure there will be no loops @@ -113,9 +114,9 @@ template template void LinkedListRoot::insertBefore(T* node, Predicate predicate) { - UAVCAN_ASSERT(node); if (node == NULL) { + UAVCAN_ASSERT(0); return; } @@ -170,3 +171,5 @@ void LinkedListRoot::remove(const T* node) } } + +#endif // UAVCAN_UTIL_LINKED_LIST_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/util/map.hpp b/libuavcan/include/uavcan/util/map.hpp index 1cedffb1cc..d72ca18578 100644 --- a/libuavcan/include/uavcan/util/map.hpp +++ b/libuavcan/include/uavcan/util/map.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_UTIL_MAP_HPP_INCLUDED +#define UAVCAN_UTIL_MAP_HPP_INCLUDED #include #include @@ -500,3 +501,5 @@ unsigned MapBase::getNumDynamicPairs() const } } + +#endif // UAVCAN_UTIL_MAP_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/util/method_binder.hpp b/libuavcan/include/uavcan/util/method_binder.hpp index 23fa476f87..5cf89e07f6 100644 --- a/libuavcan/include/uavcan/util/method_binder.hpp +++ b/libuavcan/include/uavcan/util/method_binder.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_UTIL_METHOD_BINDER_HPP_INCLUDED +#define UAVCAN_UTIL_METHOD_BINDER_HPP_INCLUDED #include #include @@ -79,3 +80,5 @@ public: }; } + +#endif // UAVCAN_UTIL_METHOD_BINDER_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/util/placement_new.hpp b/libuavcan/include/uavcan/util/placement_new.hpp index d05bac40c1..8c13308111 100644 --- a/libuavcan/include/uavcan/util/placement_new.hpp +++ b/libuavcan/include/uavcan/util/placement_new.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_UTIL_PLACEMENT_NEW_HPP_INCLUDED +#define UAVCAN_UTIL_PLACEMENT_NEW_HPP_INCLUDED #include #include @@ -33,3 +34,5 @@ inline void operator delete[](void*, void*) throw() { } #else # include #endif + +#endif // UAVCAN_UTIL_PLACEMENT_NEW_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/util/templates.hpp b/libuavcan/include/uavcan/util/templates.hpp index 8c3b3028b2..e25102790d 100644 --- a/libuavcan/include/uavcan/util/templates.hpp +++ b/libuavcan/include/uavcan/util/templates.hpp @@ -2,7 +2,8 @@ * Copyright (C) 2014 Pavel Kirienko */ -#pragma once +#ifndef UAVCAN_UTIL_TEMPLATES_HPP_INCLUDED +#define UAVCAN_UTIL_TEMPLATES_HPP_INCLUDED #include #include @@ -479,8 +480,11 @@ inline bool getSignBit(T arg) #if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 return std::signbit(arg); #else + // coverity[divide_by_zero : FALSE] return arg < T(0) || (((arg <= T(0)) && (arg >= T(0))) && (T(1) / arg < T(0))); #endif } } + +#endif // UAVCAN_UTIL_TEMPLATES_HPP_INCLUDED diff --git a/libuavcan/src/marshal/uc_bit_array_copy.cpp b/libuavcan/src/marshal/uc_bit_array_copy.cpp index ae516b1f4c..034b752584 100644 --- a/libuavcan/src/marshal/uc_bit_array_copy.cpp +++ b/libuavcan/src/marshal/uc_bit_array_copy.cpp @@ -11,7 +11,7 @@ namespace uavcan { -static const unsigned char reverse_mask[] = { 0x55U, 0x80U, 0xC0U, 0xE0U, 0xF0U, 0xF8U, 0xFCU, 0xFEU, 0xFFU }; +static const unsigned char reverse_mask[] = { 0x00U, 0x80U, 0xC0U, 0xE0U, 0xF0U, 0xF8U, 0xFCU, 0xFEU, 0xFFU }; static const unsigned char reverse_mask_xor[] = { 0xFFU, 0x7FU, 0x3FU, 0x1FU, 0x0FU, 0x07U, 0x03U, 0x01U, 0x00U }; #if UAVCAN_TINY @@ -23,7 +23,7 @@ static const unsigned char reverse_mask_xor[] = { 0xFFU, 0x7FU, 0x3FU, 0x1FU, 0x src_len -= CHAR_BIT - dst_offset_modulo; \ } else { \ *dst &= reverse_mask[dst_offset_modulo] | \ - reverse_mask_xor[dst_offset_modulo + src_len + 1]; \ + reverse_mask_xor[dst_offset_modulo + src_len]; \ c &= reverse_mask[dst_offset_modulo + src_len]; \ src_len = 0; \ } } while (0) diff --git a/libuavcan/src/node/uc_global_data_type_registry.cpp b/libuavcan/src/node/uc_global_data_type_registry.cpp index 13250d991e..aa96308d0d 100644 --- a/libuavcan/src/node/uc_global_data_type_registry.cpp +++ b/libuavcan/src/node/uc_global_data_type_registry.cpp @@ -27,22 +27,22 @@ GlobalDataTypeRegistry::List* GlobalDataTypeRegistry::selectList(DataTypeKind ki } } -GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::remove(Entry* dtd) +GlobalDataTypeRegistry::RegistrationResult GlobalDataTypeRegistry::remove(Entry* dtd) { if (!dtd) { UAVCAN_ASSERT(0); - return RegistResultInvalidParams; + return RegistrationResultInvalidParams; } if (isFrozen()) { - return RegistResultFrozen; + return RegistrationResultFrozen; } List* list = selectList(dtd->descriptor.getKind()); if (!list) { - return RegistResultInvalidParams; + return RegistrationResultInvalidParams; } list->remove(dtd); // If this call came from regist<>(), that would be enough @@ -56,25 +56,25 @@ GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::remove(Entry* dtd) } p = next; } - return RegistResultOk; + return RegistrationResultOk; } -GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::registImpl(Entry* dtd) +GlobalDataTypeRegistry::RegistrationResult GlobalDataTypeRegistry::registImpl(Entry* dtd) { if (!dtd || (dtd->descriptor.getID() > DataTypeID::Max)) { UAVCAN_ASSERT(0); - return RegistResultInvalidParams; + return RegistrationResultInvalidParams; } if (isFrozen()) { - return RegistResultFrozen; + return RegistrationResultFrozen; } List* list = selectList(dtd->descriptor.getKind()); if (!list) { - return RegistResultInvalidParams; + return RegistrationResultInvalidParams; } { // Collision check @@ -83,12 +83,12 @@ GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::registImpl(Entry* d { if (p->descriptor.getID() == dtd->descriptor.getID()) // ID collision { - return RegistResultCollision; + return RegistrationResultCollision; } if (!std::strncmp(p->descriptor.getFullName(), dtd->descriptor.getFullName(), DataTypeDescriptor::MaxFullNameLen)) // Name collision { - return RegistResultCollision; + return RegistrationResultCollision; } p = p->getNextListNode(); } @@ -122,7 +122,7 @@ GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::registImpl(Entry* d } } #endif - return RegistResultOk; + return RegistrationResultOk; } GlobalDataTypeRegistry& GlobalDataTypeRegistry::instance() @@ -141,6 +141,16 @@ void GlobalDataTypeRegistry::freeze() } } +const DataTypeDescriptor* GlobalDataTypeRegistry::find(const char* name) const +{ + const DataTypeDescriptor* desc = find(DataTypeKindMessage, name); + if (desc == NULL) + { + desc = find(DataTypeKindService, name); + } + return desc; +} + const DataTypeDescriptor* GlobalDataTypeRegistry::find(DataTypeKind kind, const char* name) const { if (!name) diff --git a/libuavcan/src/protocol/uc_data_type_info_provider.cpp b/libuavcan/src/protocol/uc_data_type_info_provider.cpp index 38a0a023b5..c736d06842 100644 --- a/libuavcan/src/protocol/uc_data_type_info_provider.cpp +++ b/libuavcan/src/protocol/uc_data_type_info_provider.cpp @@ -35,43 +35,67 @@ void DataTypeInfoProvider::handleComputeAggregateTypeSignatureRequest( void DataTypeInfoProvider::handleGetDataTypeInfoRequest(const protocol::GetDataTypeInfo::Request& request, protocol::GetDataTypeInfo::Response& response) { - const DataTypeKind kind = DataTypeKind(request.kind.value); - if (!isValidDataTypeKind(kind)) + /* + * Asking the Global Data Type Registry for the matching type descriptor, either by name or by ID + */ + const DataTypeDescriptor* desc = NULL; + + if (request.name.empty()) { - UAVCAN_TRACE("DataTypeInfoProvider", "GetDataTypeInfo request with invalid DataTypeKind %i", kind); - return; + response.id = request.id; // Pre-setting the fields so they have meaningful values even in + response.kind = request.kind; // ...case of failure. + + if (!isValidDataTypeKind(DataTypeKind(request.kind.value))) + { + UAVCAN_TRACE("DataTypeInfoProvider", "GetDataTypeInfo request with invalid DataTypeKind %i", + static_cast(request.kind.value)); + return; + } + + desc = GlobalDataTypeRegistry::instance().find(DataTypeKind(request.kind.value), request.id); + } + else + { + response.name = request.name; + + desc = GlobalDataTypeRegistry::instance().find(request.name.c_str()); } - const DataTypeDescriptor* const desc = GlobalDataTypeRegistry::instance().find(kind, request.id); - if (!desc) + if (desc == NULL) { - UAVCAN_TRACE("DataTypeInfoProvider", "Cannot process GetDataTypeInfo for nonexistent type dtid=%i dtk=%i", - int(request.id), int(request.kind.value)); + UAVCAN_TRACE("DataTypeInfoProvider", + "Cannot process GetDataTypeInfo for nonexistent type: dtid=%i dtk=%i name='%s'", + static_cast(request.id), static_cast(request.kind.value), request.name.c_str()); return; } UAVCAN_TRACE("DataTypeInfoProvider", "GetDataTypeInfo request for %s", desc->toString().c_str()); - response.signature = desc->getSignature().get(); - response.name = desc->getFullName(); - response.mask = protocol::GetDataTypeInfo::Response::MASK_KNOWN; + /* + * Filling the response struct + */ + response.signature = desc->getSignature().get(); + response.id = desc->getID().get(); + response.kind.value = desc->getKind(); + response.mask = protocol::GetDataTypeInfo::Response::MASK_KNOWN; + response.name = desc->getFullName(); const Dispatcher& dispatcher = getNode().getDispatcher(); - if (request.kind.value == protocol::DataTypeKind::SERVICE) + if (desc->getKind() == DataTypeKindService) { - if (dispatcher.hasServer(request.id)) + if (dispatcher.hasServer(desc->getID().get())) { response.mask |= protocol::GetDataTypeInfo::Response::MASK_SERVING; } } - else if (request.kind.value == protocol::DataTypeKind::MESSAGE) + else if (desc->getKind() == DataTypeKindMessage) { - if (dispatcher.hasSubscriber(request.id)) + if (dispatcher.hasSubscriber(desc->getID().get())) { response.mask |= protocol::GetDataTypeInfo::Response::MASK_SUBSCRIBED; } - if (dispatcher.hasPublisher(request.id)) + if (dispatcher.hasPublisher(desc->getID().get())) { response.mask |= protocol::GetDataTypeInfo::Response::MASK_PUBLISHING; } diff --git a/libuavcan/src/protocol/uc_logger.cpp b/libuavcan/src/protocol/uc_logger.cpp index a0e900b285..3c6661e306 100644 --- a/libuavcan/src/protocol/uc_logger.cpp +++ b/libuavcan/src/protocol/uc_logger.cpp @@ -36,16 +36,27 @@ int Logger::log(const protocol::debug::LogMessage& message) #if UAVCAN_CPP_VERSION < UAVCAN_CPP11 -int Logger::log(LogLevel level, const char* source, const char* text) +int Logger::log(LogLevel level, const char* source, const char* text) UAVCAN_NOEXCEPT { - if (level >= level_ || level >= getExternalSinkLevel()) +#if UAVCAN_EXCEPTIONS + try +#endif { - msg_buf_.level.value = level; - msg_buf_.source = source; - msg_buf_.text = text; - return log(msg_buf_); + if (level >= level_ || level >= getExternalSinkLevel()) + { + msg_buf_.level.value = level; + msg_buf_.source = source; + msg_buf_.text = text; + return log(msg_buf_); + } + return 0; } - return 0; +#if UAVCAN_EXCEPTIONS + catch (...) + { + return -ErrFailure; + } +#endif } #endif diff --git a/libuavcan/src/protocol/uc_panic_broadcaster.cpp b/libuavcan/src/protocol/uc_panic_broadcaster.cpp index 059e288320..8c73929586 100644 --- a/libuavcan/src/protocol/uc_panic_broadcaster.cpp +++ b/libuavcan/src/protocol/uc_panic_broadcaster.cpp @@ -22,10 +22,10 @@ void PanicBroadcaster::handleTimerEvent(const TimerEvent&) publishOnce(); } -void PanicBroadcaster::panic(const char* short_reason) +void PanicBroadcaster::panic(const char* short_reason_description) { msg_.reason_text.clear(); - const char* p = short_reason; + const char* p = short_reason_description; while (p && *p) { if (msg_.reason_text.size() == msg_.reason_text.capacity()) diff --git a/libuavcan/src/transport/uc_transfer_buffer.cpp b/libuavcan/src/transport/uc_transfer_buffer.cpp index f851eb05ed..4a56b75632 100644 --- a/libuavcan/src/transport/uc_transfer_buffer.cpp +++ b/libuavcan/src/transport/uc_transfer_buffer.cpp @@ -24,7 +24,8 @@ std::string TransferBufferManagerKey::toString() const /* * DynamicTransferBuffer::Block */ -DynamicTransferBufferManagerEntry::Block* DynamicTransferBufferManagerEntry::Block::instantiate(IPoolAllocator& allocator) +DynamicTransferBufferManagerEntry::Block* +DynamicTransferBufferManagerEntry::Block::instantiate(IPoolAllocator& allocator) { void* const praw = allocator.allocate(sizeof(Block)); if (praw == NULL) diff --git a/libuavcan/test/node/global_data_type_registry.cpp b/libuavcan/test/node/global_data_type_registry.cpp index 9e8db32e6a..7edf41d2b2 100644 --- a/libuavcan/test/node/global_data_type_registry.cpp +++ b/libuavcan/test/node/global_data_type_registry.cpp @@ -95,8 +95,9 @@ TEST(GlobalDataTypeRegistry, Basic) /* * Runtime registrations */ - ASSERT_EQ(GlobalDataTypeRegistry::RegistResultOk, - GlobalDataTypeRegistry::instance().regist(DataTypeAService::DefaultDataTypeID)); + ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultOk, + GlobalDataTypeRegistry::instance().registerDataType( + DataTypeAService::DefaultDataTypeID)); ASSERT_EQ(2, GlobalDataTypeRegistry::instance().getNumMessageTypes()); ASSERT_EQ(1, GlobalDataTypeRegistry::instance().getNumServiceTypes()); @@ -109,8 +110,10 @@ TEST(GlobalDataTypeRegistry, Basic) /* * Runtime re-registration */ - ASSERT_EQ(GlobalDataTypeRegistry::RegistResultOk, GlobalDataTypeRegistry::instance().regist(147)); - ASSERT_EQ(GlobalDataTypeRegistry::RegistResultOk, GlobalDataTypeRegistry::instance().regist(741)); + ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultOk, + GlobalDataTypeRegistry::instance().registerDataType(147)); + ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultOk, + GlobalDataTypeRegistry::instance().registerDataType(741)); ASSERT_EQ(2, GlobalDataTypeRegistry::instance().getNumMessageTypes()); ASSERT_EQ(1, GlobalDataTypeRegistry::instance().getNumServiceTypes()); @@ -129,11 +132,11 @@ TEST(GlobalDataTypeRegistry, Basic) /* * These types will be necessary for the aggregate signature test */ - ASSERT_EQ(GlobalDataTypeRegistry::RegistResultCollision, - GlobalDataTypeRegistry::instance().regist(741)); // ID COLLISION + ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultCollision, + GlobalDataTypeRegistry::instance().registerDataType(741)); // ID COLLISION - ASSERT_EQ(GlobalDataTypeRegistry::RegistResultOk, - GlobalDataTypeRegistry::instance().regist(DataTypeC::DefaultDataTypeID)); + ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultOk, + GlobalDataTypeRegistry::instance().registerDataType(DataTypeC::DefaultDataTypeID)); uavcan::DefaultDataTypeRegistrator reg_DataTypeD; GlobalDataTypeRegistry::instance().getDataTypeIDMask(uavcan::DataTypeKindMessage, dtmask); @@ -154,20 +157,21 @@ TEST(GlobalDataTypeRegistry, Basic) */ GlobalDataTypeRegistry::instance().freeze(); - ASSERT_EQ(GlobalDataTypeRegistry::RegistResultFrozen, - GlobalDataTypeRegistry::instance().regist(555)); // Rejected + ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultFrozen, + GlobalDataTypeRegistry::instance().registerDataType(555)); // Rejected - ASSERT_EQ(GlobalDataTypeRegistry::RegistResultFrozen, - GlobalDataTypeRegistry::instance().regist(999)); // Rejected + ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultFrozen, + GlobalDataTypeRegistry::instance().registerDataType(999)); // Rejected - ASSERT_EQ(GlobalDataTypeRegistry::RegistResultFrozen, - GlobalDataTypeRegistry::instance().regist(888)); // Rejected + ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultFrozen, + GlobalDataTypeRegistry::instance().registerDataType(888)); // Rejected /* * Searching */ const uavcan::DataTypeDescriptor* pdtd = NULL; ASSERT_FALSE(GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindMessage, "Nonexistent")); + ASSERT_FALSE(GlobalDataTypeRegistry::instance().find("Nonexistent")); ASSERT_FALSE(GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindMessage, 987)); // Asking for service, but this is a message: ASSERT_FALSE(GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindService, "my_namespace.DataTypeB")); @@ -175,12 +179,14 @@ TEST(GlobalDataTypeRegistry, Basic) ASSERT_TRUE((pdtd = GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindMessage, "my_namespace.DataTypeB"))); + ASSERT_TRUE((pdtd = GlobalDataTypeRegistry::instance().find("my_namespace.DataTypeB"))); ASSERT_EQ(extractDescriptor(741), *pdtd); ASSERT_TRUE((pdtd = GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindMessage, 741))); ASSERT_EQ(extractDescriptor(741), *pdtd); ASSERT_TRUE((pdtd = GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindMessage, "my_namespace.DataTypeA"))); + ASSERT_TRUE((pdtd = GlobalDataTypeRegistry::instance().find("my_namespace.DataTypeA"))); ASSERT_EQ(extractDescriptor(), *pdtd); ASSERT_TRUE((pdtd = GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindMessage, uavcan::DataTypeID(0)))); ASSERT_EQ(extractDescriptor(), *pdtd); diff --git a/libuavcan/test/protocol/data_type_info_provider.cpp b/libuavcan/test/protocol/data_type_info_provider.cpp index 046d6074fa..add46c17ac 100644 --- a/libuavcan/test/protocol/data_type_info_provider.cpp +++ b/libuavcan/test/protocol/data_type_info_provider.cpp @@ -23,22 +23,39 @@ static bool validateDataTypeInfoResponse(const std::auto_ptrisSuccessful()) { + std::cout << "Request was not successful" << std::endl; return false; } if (resp->response.name != DataType::getDataTypeFullName()) { + std::cout << "Type name mismatch: '" + << resp->response.name.c_str() << "' '" + << DataType::getDataTypeFullName() << "'" << std::endl; return false; } if (DataType::getDataTypeSignature().get() != resp->response.signature) { + std::cout << "Signature mismatch" << std::endl; return false; } if (resp->response.mask != mask) { + std::cout << "Mask mismatch" << std::endl; + return false; + } + if (resp->response.kind.value != DataType::DataTypeKind) + { + std::cout << "Kind mismatch" << std::endl; + return false; + } + if (resp->response.id != DataType::DefaultDataTypeID) + { + std::cout << "DTID mismatch" << std::endl; return false; } return true; @@ -75,9 +92,25 @@ TEST(DataTypeInfoProvider, Basic) GetDataTypeInfo::Response::MASK_SERVING)); ASSERT_EQ(1, gdti_cln.collector.result->server_node_id.get()); + /* + * GetDataTypeInfo request for GetDataTypeInfo by name + */ + gdti_request = GetDataTypeInfo::Request(); + gdti_request.id = 999; // Intentionally wrong + gdti_request.kind.value = DataTypeKind::MESSAGE; // Intentionally wrong + gdti_request.name = "uavcan.protocol.GetDataTypeInfo"; + ASSERT_LE(0, gdti_cln.call(1, gdti_request)); + nodes.spinBoth(MonotonicDuration::fromMSec(10)); + + ASSERT_TRUE(validateDataTypeInfoResponse(gdti_cln.collector.result, + GetDataTypeInfo::Response::MASK_KNOWN | + GetDataTypeInfo::Response::MASK_SERVING)); + ASSERT_EQ(1, gdti_cln.collector.result->server_node_id.get()); + /* * GetDataTypeInfo request for NodeStatus - not used yet */ + gdti_request = GetDataTypeInfo::Request(); gdti_request.id = NodeStatus::DefaultDataTypeID; gdti_request.kind.value = DataTypeKind::MESSAGE; ASSERT_LE(0, gdti_cln.call(1, gdti_request)); @@ -107,15 +140,37 @@ TEST(DataTypeInfoProvider, Basic) /* * Requesting a non-existent type */ + gdti_request = GetDataTypeInfo::Request(); gdti_request.id = ComputeAggregateTypeSignature::DefaultDataTypeID; - gdti_request.kind.value = 0xFF; // INVALID VALUE + gdti_request.kind.value = 3; // INVALID VALUE ASSERT_LE(0, gdti_cln.call(1, gdti_request)); nodes.spinBoth(MonotonicDuration::fromMSec(10)); ASSERT_TRUE(gdti_cln.collector.result.get()); ASSERT_TRUE(gdti_cln.collector.result->isSuccessful()); ASSERT_EQ(1, gdti_cln.collector.result->server_node_id.get()); - ASSERT_TRUE(gdti_cln.collector.result->response == GetDataTypeInfo::Response()); // Empty response + ASSERT_EQ(0, gdti_cln.collector.result->response.mask); + ASSERT_TRUE(gdti_cln.collector.result->response.name.empty()); // Empty name + ASSERT_EQ(gdti_request.id, gdti_cln.collector.result->response.id); + ASSERT_EQ(gdti_request.kind.value, gdti_cln.collector.result->response.kind.value); + + /* + * Requesting a non-existent type by name + */ + gdti_request = GetDataTypeInfo::Request(); + gdti_request.id = 999; // Intentionally wrong + gdti_request.kind.value = 3; // Intentionally wrong + gdti_request.name = "uavcan.equipment.gnss.Fix"; + ASSERT_LE(0, gdti_cln.call(1, gdti_request)); + nodes.spinBoth(MonotonicDuration::fromMSec(10)); + + ASSERT_TRUE(gdti_cln.collector.result.get()); + ASSERT_TRUE(gdti_cln.collector.result->isSuccessful()); + ASSERT_EQ(1, gdti_cln.collector.result->server_node_id.get()); + ASSERT_EQ(0, gdti_cln.collector.result->response.mask); + ASSERT_EQ("uavcan.equipment.gnss.Fix", gdti_cln.collector.result->response.name); + ASSERT_EQ(0, gdti_cln.collector.result->response.id); + ASSERT_EQ(0, gdti_cln.collector.result->response.kind.value); /* * ComputeAggregateTypeSignature test diff --git a/libuavcan_drivers/linux/CMakeLists.txt b/libuavcan_drivers/linux/CMakeLists.txt index 6069f762d0..51cbcf1c97 100644 --- a/libuavcan_drivers/linux/CMakeLists.txt +++ b/libuavcan_drivers/linux/CMakeLists.txt @@ -11,6 +11,11 @@ project(libuavcan_linux) # install(DIRECTORY include/uavcan_linux DESTINATION include) +# +# System dependecies +# +find_package(Threads REQUIRED) + # # Finding libuavcan - it will be a target if we're running from the top-level CMakeLists.txt, # otherwise try to find it in the system directories. @@ -36,27 +41,28 @@ set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -std=c++0x") # GCC or Clang # These aren't installed, an average library user should not care about them. # add_executable(test_clock apps/test_clock.cpp) -target_link_libraries(test_clock ${UAVCAN_LIB} rt) +target_link_libraries(test_clock ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) add_executable(test_socket apps/test_socket.cpp) -target_link_libraries(test_socket ${UAVCAN_LIB} rt) +target_link_libraries(test_socket ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) add_executable(test_node apps/test_node.cpp) -target_link_libraries(test_node ${UAVCAN_LIB} rt) +target_link_libraries(test_node ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) add_executable(test_time_sync apps/test_time_sync.cpp) -target_link_libraries(test_time_sync ${UAVCAN_LIB} rt) +target_link_libraries(test_time_sync ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) # # Tools # Someday they will be replaced with Python scripts (pyuavcan is not finished at the moment) # add_executable(uavcan_status_monitor apps/uavcan_status_monitor.cpp) -target_link_libraries(uavcan_status_monitor ${UAVCAN_LIB} rt) +target_link_libraries(uavcan_status_monitor ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) add_executable(uavcan_nodetool apps/uavcan_nodetool.cpp) -target_link_libraries(uavcan_nodetool ${UAVCAN_LIB} rt) +target_link_libraries(uavcan_nodetool ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) install(TARGETS uavcan_status_monitor uavcan_nodetool RUNTIME DESTINATION bin) + \ No newline at end of file diff --git a/libuavcan_drivers/linux/apps/test_node.cpp b/libuavcan_drivers/linux/apps/test_node.cpp index cb00a98c99..2241f246ca 100644 --- a/libuavcan_drivers/linux/apps/test_node.cpp +++ b/libuavcan_drivers/linux/apps/test_node.cpp @@ -102,19 +102,27 @@ static void runForever(const uavcan_linux::NodePtr& node) int main(int argc, const char** argv) { - if (argc < 3) + try { - std::cout << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; + if (argc < 3) + { + std::cerr << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; + return 1; + } + const int self_node_id = std::stoi(argv[1]); + std::vector iface_names; + for (int i = 2; i < argc; i++) + { + iface_names.emplace_back(argv[i]); + } + uavcan_linux::NodePtr node = initNode(iface_names, self_node_id, "org.uavcan.linux_test_node"); + std::cout << "Node initialized successfully" << std::endl; + runForever(node); + return 0; + } + catch (const std::exception& ex) + { + std::cerr << "Exception: " << ex.what() << std::endl; return 1; } - const int self_node_id = std::stoi(argv[1]); - std::vector iface_names; - for (int i = 2; i < argc; i++) - { - iface_names.emplace_back(argv[i]); - } - uavcan_linux::NodePtr node = initNode(iface_names, self_node_id, "org.uavcan.linux_test_node"); - std::cout << "Node initialized successfully" << std::endl; - runForever(node); - return 0; } diff --git a/libuavcan_drivers/linux/apps/test_socket.cpp b/libuavcan_drivers/linux/apps/test_socket.cpp index 5c8a33e2ce..5d62ad4fea 100644 --- a/libuavcan_drivers/linux/apps/test_socket.cpp +++ b/libuavcan_drivers/linux/apps/test_socket.cpp @@ -332,23 +332,31 @@ static void testDriver(const std::vector& iface_names) int main(int argc, const char** argv) { - if (argc < 2) + try { - std::cout << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; + if (argc < 2) + { + std::cerr << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; + return 1; + } + + std::vector iface_names; + for (int i = 1; i < argc; i++) + { + iface_names.emplace_back(argv[i]); + } + + testNonexistentIface(); + testSocketRxTx(iface_names[0]); + testSocketFilters(iface_names[0]); + + testDriver(iface_names); + + return 0; + } + catch (const std::exception& ex) + { + std::cerr << "Exception: " << ex.what() << std::endl; return 1; } - - std::vector iface_names; - for (int i = 1; i < argc; i++) - { - iface_names.emplace_back(argv[i]); - } - - testNonexistentIface(); - testSocketRxTx(iface_names[0]); - testSocketFilters(iface_names[0]); - - testDriver(iface_names); - - return 0; } diff --git a/libuavcan_drivers/linux/apps/test_time_sync.cpp b/libuavcan_drivers/linux/apps/test_time_sync.cpp index 8da3e2ad1b..c956a4912e 100644 --- a/libuavcan_drivers/linux/apps/test_time_sync.cpp +++ b/libuavcan_drivers/linux/apps/test_time_sync.cpp @@ -84,18 +84,26 @@ static void runForever(const uavcan_linux::NodePtr& node) int main(int argc, const char** argv) { - if (argc < 3) + try { - std::cout << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; + if (argc < 3) + { + std::cerr << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; + return 1; + } + const int self_node_id = std::stoi(argv[1]); + std::vector iface_names; + for (int i = 2; i < argc; i++) + { + iface_names.emplace_back(argv[i]); + } + uavcan_linux::NodePtr node = initNode(iface_names, self_node_id, "org.uavcan.linux_test_node_status_monitor"); + runForever(node); + return 0; + } + catch (const std::exception& ex) + { + std::cerr << "Exception: " << ex.what() << std::endl; return 1; } - const int self_node_id = std::stoi(argv[1]); - std::vector iface_names; - for (int i = 2; i < argc; i++) - { - iface_names.emplace_back(argv[i]); - } - uavcan_linux::NodePtr node = initNode(iface_names, self_node_id, "org.uavcan.linux_test_node_status_monitor"); - runForever(node); - return 0; } diff --git a/libuavcan_drivers/linux/apps/uavcan_nodetool.cpp b/libuavcan_drivers/linux/apps/uavcan_nodetool.cpp index 5cca98eafd..822144701b 100644 --- a/libuavcan_drivers/linux/apps/uavcan_nodetool.cpp +++ b/libuavcan_drivers/linux/apps/uavcan_nodetool.cpp @@ -104,12 +104,17 @@ void printGetSetResponseHeader() void printGetSetResponse(const uavcan::protocol::param::GetSet::Response& resp) { + const auto original_flags = std::cout.flags(); + std::cout << std::setw(41) << std::left << resp.name.c_str(); std::cout << std::setw(15) << paramValueToString(resp.value); std::cout << std::setw(15) << paramValueToString(resp.default_value); std::cout << std::setw(15) << paramValueToString(resp.min_value); std::cout << std::setw(15) << paramValueToString(resp.max_value); std::cout << std::endl; + + std::cout.width(0); // Clears the effect of std::setw() + std::cout.flags(original_flags); } uavcan_linux::NodePtr initNode(const std::vector& ifaces, uavcan::NodeID nid, const std::string& name) @@ -347,14 +352,22 @@ void runForever(const uavcan_linux::NodePtr& node) int main(int argc, const char** argv) { - if (argc < 3) + try { - std::cout << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; + if (argc < 3) + { + std::cerr << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; + return 1; + } + const int self_node_id = std::stoi(argv[1]); + const std::vector iface_names(argv + 2, argv + argc); + uavcan_linux::NodePtr node = initNode(iface_names, self_node_id, "org.uavcan.linux_app.nodetool"); + runForever(node); + return 0; + } + catch (const std::exception& ex) + { + std::cerr << "Error: " << ex.what() << std::endl; return 1; } - const int self_node_id = std::stoi(argv[1]); - const std::vector iface_names(argv + 2, argv + argc); - uavcan_linux::NodePtr node = initNode(iface_names, self_node_id, "org.uavcan.linux_nodetool"); - runForever(node); - return 0; } diff --git a/libuavcan_drivers/linux/apps/uavcan_status_monitor.cpp b/libuavcan_drivers/linux/apps/uavcan_status_monitor.cpp index 9c8b8ebdef..c8374ded0d 100644 --- a/libuavcan_drivers/linux/apps/uavcan_status_monitor.cpp +++ b/libuavcan_drivers/linux/apps/uavcan_status_monitor.cpp @@ -127,17 +127,25 @@ static void runForever(const uavcan_linux::NodePtr& node) int main(int argc, const char** argv) { - if (argc < 2) + try { - std::cout << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; + if (argc < 2) + { + std::cerr << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; + return 1; + } + std::vector iface_names; + for (int i = 1; i < argc; i++) + { + iface_names.emplace_back(argv[i]); + } + uavcan_linux::NodePtr node = initNodeInPassiveMode(iface_names, "org.uavcan.linux_app.node_status_monitor"); + runForever(node); + return 0; + } + catch (const std::exception& ex) + { + std::cerr << "Error: " << ex.what() << std::endl; return 1; } - std::vector iface_names; - for (int i = 1; i < argc; i++) - { - iface_names.emplace_back(argv[i]); - } - uavcan_linux::NodePtr node = initNodeInPassiveMode(iface_names, "org.uavcan.status_monitor"); - runForever(node); - return 0; } diff --git a/libuavcan_drivers/linux/scripts/vcan_init b/libuavcan_drivers/linux/scripts/vcan_init index 6a9bb6e4ec..ffa1c43bf0 100755 --- a/libuavcan_drivers/linux/scripts/vcan_init +++ b/libuavcan_drivers/linux/scripts/vcan_init @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # Copyright (C) 2014 Pavel Kirienko # diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/Makefile b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/Makefile index ea3df6840b..24f375c9d6 100644 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/Makefile +++ b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/Makefile @@ -49,6 +49,7 @@ DEPDIR = $(BUILDDIR)/dep DEF += -DNDEBUG -DCHIP_LPC11CXX -DCORE_M0 -DTHUMB_NO_INTERWORKING -U__STRICT_ANSI__ +# Removing -fconserve-stack reduces code size a little FLAGS = -mthumb -mcpu=cortex-m0 -mno-thumb-interwork -flto -Os -g3 -Wall -Wextra -Werror -Wundef -ffunction-sections \ -fdata-sections -fno-common -fno-exceptions -fno-unwind-tables -fno-stack-protector -fomit-frame-pointer \ -ftracer -ftree-loop-distribute-patterns -frename-registers -freorder-blocks -fconserve-stack \ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/main.cpp b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/main.cpp index a5e7e85321..22485746e3 100644 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/main.cpp +++ b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/main.cpp @@ -13,7 +13,7 @@ namespace { -typedef uavcan::Node<3136> Node; +typedef uavcan::Node<2800> Node; Node& getNode() {