Merge branch 'master' into dsdl_review

This commit is contained in:
Pavel Kirienko
2015-03-16 23:52:27 +03:00
88 changed files with 667 additions and 240 deletions
+2 -2
View File
@@ -10,8 +10,8 @@ __pycache__
*.pyc
# Eclipse
.metadata/*
.settings/*
.metadata
.settings
.project
.cproject
.pydevproject
+18 -2
View File
@@ -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:<coverity-build-tool-directory>/bin/
mkdir debug && cd debug
cmake <uavcan-source-directory> -DCMAKE_BUILD_TYPE=Debug
cov-build --dir cov-int make -j8
tar czvf uavcan.tgz cov-int
```
Then upload the resulting archive to Coverity.
@@ -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)
+3 -3
View File
@@ -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
+1
View File
@@ -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 ()
@@ -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):
@@ -6,7 +6,8 @@
* Source file: ${t.source_file}
*/
#pragma once
#ifndef ${t.include_guard}
#define ${t.include_guard}
#include <uavcan/build_config.hpp>
#include <uavcan/node/global_data_type_registry.hpp>
@@ -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}
+22 -3
View File
@@ -2,13 +2,14 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#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
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_DATA_TYPE_HPP_INCLUDED
#define UAVCAN_DATA_TYPE_HPP_INCLUDED
#include <cassert>
#include <cstring>
@@ -144,3 +145,5 @@ public:
};
}
#endif // UAVCAN_DATA_TYPE_HPP_INCLUDED
+4 -1
View File
@@ -3,7 +3,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_DEBUG_HPP_INCLUDED
#define UAVCAN_DEBUG_HPP_INCLUDED
#include <uavcan/build_config.hpp>
@@ -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
+4 -1
View File
@@ -3,7 +3,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_DRIVER_CAN_HPP_INCLUDED
#define UAVCAN_DRIVER_CAN_HPP_INCLUDED
#include <cassert>
#include <uavcan/stdint.hpp>
@@ -187,3 +188,5 @@ public:
};
}
#endif // UAVCAN_DRIVER_CAN_HPP_INCLUDED
@@ -3,7 +3,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_DRIVER_SYSTEM_CLOCK_HPP_INCLUDED
#define UAVCAN_DRIVER_SYSTEM_CLOCK_HPP_INCLUDED
#include <uavcan/stdint.hpp>
#include <uavcan/build_config.hpp>
@@ -44,3 +45,5 @@ public:
};
}
#endif // UAVCAN_DRIVER_SYSTEM_CLOCK_HPP_INCLUDED
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_DYNAMIC_MEMORY_HPP_INCLUDED
#define UAVCAN_DYNAMIC_MEMORY_HPP_INCLUDED
#include <cassert>
#include <cstdlib>
@@ -297,3 +298,5 @@ unsigned PoolAllocator<PoolSize, BlockSize>::getNumFreeBlocks() const
}
}
#endif // UAVCAN_DYNAMIC_MEMORY_HPP_INCLUDED
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_ERROR_HPP_INCLUDED
#define UAVCAN_ERROR_HPP_INCLUDED
#include <uavcan/build_config.hpp>
#include <uavcan/stdint.hpp>
@@ -53,3 +54,5 @@ UAVCAN_EXPORT
void handleFatalError(const char* msg);
}
#endif // UAVCAN_ERROR_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_HELPERS_COMPONENT_STATUS_MANAGER_HPP_INCLUDED
#define UAVCAN_HELPERS_COMPONENT_STATUS_MANAGER_HPP_INCLUDED
#include <uavcan/build_config.hpp>
#include <uavcan/stdint.hpp>
@@ -68,3 +69,5 @@ template <unsigned NumComponents_>
const unsigned ComponentStatusManager<NumComponents_>::NumComponents;
}
#endif // UAVCAN_HELPERS_COMPONENT_STATUS_MANAGER_HPP_INCLUDED
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_HELPERS_OSTREAM_HPP_INCLUDED
#define UAVCAN_HELPERS_OSTREAM_HPP_INCLUDED
#include <uavcan/util/templates.hpp>
#include <cstdio>
@@ -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
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_MARSHAL_ARRAY_HPP_INCLUDED
#define UAVCAN_MARSHAL_ARRAY_HPP_INCLUDED
#include <cassert>
#include <cstdio>
@@ -1034,3 +1035,5 @@ public:
};
}
#endif // UAVCAN_MARSHAL_ARRAY_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_MARSHAL_BIT_STREAM_HPP_INCLUDED
#define UAVCAN_MARSHAL_BIT_STREAM_HPP_INCLUDED
#include <cassert>
#include <uavcan/stdint.hpp>
@@ -116,3 +117,5 @@ public:
};
}
#endif // UAVCAN_MARSHAL_BIT_STREAM_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_MARSHAL_CHAR_ARRAY_FORMATTER_HPP_INCLUDED
#define UAVCAN_MARSHAL_CHAR_ARRAY_FORMATTER_HPP_INCLUDED
#include <uavcan/build_config.hpp>
#include <uavcan/marshal/array.hpp>
@@ -137,3 +138,5 @@ public:
#endif
}
#endif // UAVCAN_MARSHAL_CHAR_ARRAY_FORMATTER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_MARSHAL_FLOAT_SPEC_HPP_INCLUDED
#define UAVCAN_MARSHAL_FLOAT_SPEC_HPP_INCLUDED
#include <cmath>
#include <uavcan/stdint.hpp>
@@ -222,3 +223,5 @@ public:
};
}
#endif // UAVCAN_MARSHAL_FLOAT_SPEC_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_MARSHAL_INTEGER_SPEC_HPP_INCLUDED
#define UAVCAN_MARSHAL_INTEGER_SPEC_HPP_INCLUDED
#include <uavcan/stdint.hpp>
#include <uavcan/data_type.hpp>
@@ -164,3 +165,5 @@ public:
};
}
#endif // UAVCAN_MARSHAL_INTEGER_SPEC_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_MARSHAL_SCALAR_CODEC_HPP_INCLUDED
#define UAVCAN_MARSHAL_SCALAR_CODEC_HPP_INCLUDED
#include <cassert>
#include <uavcan/stdint.hpp>
@@ -135,3 +136,5 @@ int ScalarCodec::decode(T& value)
}
}
#endif // UAVCAN_MARSHAL_SCALAR_CODEC_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_MARSHAL_TYPE_UTIL_HPP_INCLUDED
#define UAVCAN_MARSHAL_TYPE_UTIL_HPP_INCLUDED
#include <uavcan/build_config.hpp>
#include <uavcan/util/templates.hpp>
@@ -83,3 +84,5 @@ template <typename T>
class UAVCAN_EXPORT YamlStreamer;
}
#endif // UAVCAN_MARSHAL_TYPE_UTIL_HPP_INCLUDED
+4 -1
View File
@@ -2,9 +2,12 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_MARSHAL_TYPES_HPP_INCLUDED
#define UAVCAN_MARSHAL_TYPES_HPP_INCLUDED
#include <uavcan/marshal/integer_spec.hpp>
#include <uavcan/marshal/float_spec.hpp>
#include <uavcan/marshal/array.hpp>
#include <uavcan/marshal/type_util.hpp>
#endif // UAVCAN_MARSHAL_TYPES_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_NODE_ABSTRACT_NODE_HPP_INCLUDED
#define UAVCAN_NODE_ABSTRACT_NODE_HPP_INCLUDED
#include <uavcan/build_config.hpp>
#include <uavcan/node/scheduler.hpp>
@@ -78,3 +79,5 @@ public:
};
}
#endif // UAVCAN_NODE_ABSTRACT_NODE_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_NODE_GENERIC_PUBLISHER_HPP_INCLUDED
#define UAVCAN_NODE_GENERIC_PUBLISHER_HPP_INCLUDED
#include <uavcan/error.hpp>
#include <uavcan/node/abstract_node.hpp>
@@ -172,3 +173,5 @@ int GenericPublisher<DataSpec, DataStruct>::genericPublish(const DataStruct& mes
}
}
#endif // UAVCAN_NODE_GENERIC_PUBLISHER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_NODE_GENERIC_SUBSCRIBER_HPP_INCLUDED
#define UAVCAN_NODE_GENERIC_SUBSCRIBER_HPP_INCLUDED
#include <uavcan/error.hpp>
#include <uavcan/node/abstract_node.hpp>
@@ -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<DataStruct>& getReceivedStructStorage() { return message_; }
ReceivedDataStructure<DataStruct>& getReceivedStructStorage() { return message_; }
const ReceivedDataStructure<DataStruct>& getReceivedStructStorage() const { return message_; }
};
// ----------------------------------------------------------------------------
@@ -284,3 +288,5 @@ genericStart(bool (Dispatcher::*registration_method)(TransferListenerBase*))
}
#endif // UAVCAN_NODE_GENERIC_SUBSCRIBER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_NODE_GLOBAL_DATA_TYPE_REGISTRY_HPP_INCLUDED
#define UAVCAN_NODE_GLOBAL_DATA_TYPE_REGISTRY_HPP_INCLUDED
#include <cassert>
#include <uavcan/error.hpp>
@@ -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 <typename Type>
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>(Type::DefaultDataTypeID);
const GlobalDataTypeRegistry::RegistrationResult res =
GlobalDataTypeRegistry::instance().registerDataType<Type>(Type::DefaultDataTypeID);
if (res != GlobalDataTypeRegistry::RegistResultOk)
if (res != GlobalDataTypeRegistry::RegistrationResultOk)
{
handleFatalError("Type reg failed");
}
@@ -220,24 +230,24 @@ struct UAVCAN_EXPORT DefaultDataTypeRegistrator
* GlobalDataTypeRegistry
*/
template <typename Type>
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
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_NODE_MARSHAL_BUFFER_HPP_INCLUDED
#define UAVCAN_NODE_MARSHAL_BUFFER_HPP_INCLUDED
#include <uavcan/build_config.hpp>
#include <uavcan/transport/transfer.hpp>
@@ -87,3 +88,5 @@ public:
};
}
#endif // UAVCAN_NODE_MARSHAL_BUFFER_HPP_INCLUDED
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_NODE_NODE_HPP_INCLUDED
#define UAVCAN_NODE_NODE_HPP_INCLUDED
#include <cassert>
#include <uavcan/error.hpp>
@@ -322,3 +323,5 @@ checkNetworkCompatibility(NetworkCompatibilityCheckResult& result)
#endif
}
#endif // UAVCAN_NODE_NODE_HPP_INCLUDED
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_NODE_PUBLISHER_HPP_INCLUDED
#define UAVCAN_NODE_PUBLISHER_HPP_INCLUDED
#include <uavcan/node/generic_publisher.hpp>
@@ -95,3 +96,5 @@ public:
};
}
#endif // UAVCAN_NODE_PUBLISHER_HPP_INCLUDED
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_NODE_SCHEDULER_HPP_INCLUDED
#define UAVCAN_NODE_SCHEDULER_HPP_INCLUDED
#include <uavcan/error.hpp>
#include <uavcan/util/linked_list.hpp>
@@ -130,3 +131,5 @@ public:
};
}
#endif // UAVCAN_NODE_SCHEDULER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_NODE_SERVICE_CLIENT_HPP_INCLUDED
#define UAVCAN_NODE_SERVICE_CLIENT_HPP_INCLUDED
#include <uavcan/build_config.hpp>
#include <uavcan/node/generic_publisher.hpp>
@@ -368,3 +369,5 @@ void ServiceClient<DataType_, Callback_>::cancel()
}
}
#endif // UAVCAN_NODE_SERVICE_CLIENT_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_NODE_SERVICE_SERVER_HPP_INCLUDED
#define UAVCAN_NODE_SERVICE_SERVER_HPP_INCLUDED
#include <uavcan/build_config.hpp>
#include <uavcan/node/generic_publisher.hpp>
@@ -157,3 +158,5 @@ public:
};
}
#endif // UAVCAN_NODE_SERVICE_SERVER_HPP_INCLUDED
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_NODE_SUBSCRIBER_HPP_INCLUDED
#define UAVCAN_NODE_SUBSCRIBER_HPP_INCLUDED
#include <cassert>
#include <uavcan/build_config.hpp>
@@ -115,3 +116,5 @@ public:
};
}
#endif // UAVCAN_NODE_SUBSCRIBER_HPP_INCLUDED
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_NODE_TIMER_HPP_INCLUDED
#define UAVCAN_NODE_TIMER_HPP_INCLUDED
#include <uavcan/stdint.hpp>
#include <uavcan/error.hpp>
@@ -143,3 +144,5 @@ typedef TimerEventForwarder<std::function<void (const TimerEvent& event)> > Time
#endif
}
#endif // UAVCAN_NODE_TIMER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_PROTOCOL_DATA_TYPE_INFO_PROVIDER_HPP_INCLUDED
#define UAVCAN_PROTOCOL_DATA_TYPE_INFO_PROVIDER_HPP_INCLUDED
#include <uavcan/node/service_server.hpp>
#include <uavcan/util/method_binder.hpp>
@@ -51,3 +52,5 @@ public:
};
}
#endif // UAVCAN_PROTOCOL_DATA_TYPE_INFO_PROVIDER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_PROTOCOL_GLOBAL_TIME_SYNC_MASTER_HPP_INCLUDED
#define UAVCAN_PROTOCOL_GLOBAL_TIME_SYNC_MASTER_HPP_INCLUDED
#include <uavcan/node/publisher.hpp>
#include <uavcan/node/subscriber.hpp>
@@ -92,3 +93,5 @@ public:
};
}
#endif // UAVCAN_PROTOCOL_GLOBAL_TIME_SYNC_MASTER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_PROTOCOL_GLOBAL_TIME_SYNC_SLAVE_HPP_INCLUDED
#define UAVCAN_PROTOCOL_GLOBAL_TIME_SYNC_SLAVE_HPP_INCLUDED
#include <uavcan/node/subscriber.hpp>
#include <uavcan/util/method_binder.hpp>
@@ -103,3 +104,5 @@ public:
};
}
#endif // UAVCAN_PROTOCOL_GLOBAL_TIME_SYNC_SLAVE_HPP_INCLUDED
+34 -20
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_PROTOCOL_LOGGER_HPP_INCLUDED
#define UAVCAN_PROTOCOL_LOGGER_HPP_INCLUDED
#include <uavcan/time.hpp>
#include <uavcan/protocol/debug/LogMessage.hpp>
@@ -148,52 +149,52 @@ public:
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
template <typename... Args>
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 <typename... Args>
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 <typename... Args>
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 <typename... Args>
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 <typename... Args>
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 <typename... Args>
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<typename protocol::debug::LogMessage::FieldTypes::text> 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<typename protocol::debug::LogMessage::FieldTypes::text> 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
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_PROTOCOL_NETWORK_COMPAT_CHECKER_HPP_INCLUDED
#define UAVCAN_PROTOCOL_NETWORK_COMPAT_CHECKER_HPP_INCLUDED
#include <uavcan/util/bitset.hpp>
#include <uavcan/util/method_binder.hpp>
@@ -104,3 +105,5 @@ public:
};
}
#endif // UAVCAN_PROTOCOL_NETWORK_COMPAT_CHECKER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_PROTOCOL_NODE_STATUS_MONITOR_HPP_INCLUDED
#define UAVCAN_PROTOCOL_NODE_STATUS_MONITOR_HPP_INCLUDED
#include <uavcan/util/method_binder.hpp>
#include <uavcan/node/subscriber.hpp>
@@ -128,3 +129,5 @@ public:
};
}
#endif // UAVCAN_PROTOCOL_NODE_STATUS_MONITOR_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_PROTOCOL_NODE_STATUS_PROVIDER_HPP_INCLUDED
#define UAVCAN_PROTOCOL_NODE_STATUS_PROVIDER_HPP_INCLUDED
#include <uavcan/node/publisher.hpp>
#include <uavcan/node/subscriber.hpp>
@@ -110,3 +111,5 @@ public:
};
}
#endif // UAVCAN_PROTOCOL_NODE_STATUS_PROVIDER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_PROTOCOL_PANIC_BROADCASTER_HPP_INCLUDED
#define UAVCAN_PROTOCOL_PANIC_BROADCASTER_HPP_INCLUDED
#include <uavcan/node/publisher.hpp>
#include <uavcan/node/timer.hpp>
@@ -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
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_PROTOCOL_PANIC_LISTENER_HPP_INCLUDED
#define UAVCAN_PROTOCOL_PANIC_LISTENER_HPP_INCLUDED
#include <cassert>
#include <uavcan/debug.hpp>
@@ -123,3 +124,5 @@ public:
};
}
#endif // UAVCAN_PROTOCOL_PANIC_LISTENER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_PROTOCOL_PARAM_SERVER_HPP_INCLUDED
#define UAVCAN_PROTOCOL_PARAM_SERVER_HPP_INCLUDED
#include <uavcan/protocol/param/GetSet.hpp>
#include <uavcan/protocol/param/SaveErase.hpp>
@@ -105,3 +106,5 @@ public:
};
}
#endif // UAVCAN_PROTOCOL_PARAM_SERVER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_PROTOCOL_RESTART_REQUEST_SERVER_HPP_INCLUDED
#define UAVCAN_PROTOCOL_RESTART_REQUEST_SERVER_HPP_INCLUDED
#include <uavcan/node/service_server.hpp>
#include <uavcan/util/method_binder.hpp>
@@ -66,3 +67,5 @@ public:
};
}
#endif // UAVCAN_PROTOCOL_RESTART_REQUEST_SERVER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_PROTOCOL_TRANSPORT_STATS_PROVIDER_HPP_INCLUDED
#define UAVCAN_PROTOCOL_TRANSPORT_STATS_PROVIDER_HPP_INCLUDED
#include <uavcan/node/service_server.hpp>
#include <uavcan/util/method_binder.hpp>
@@ -39,3 +40,5 @@ public:
};
}
#endif // UAVCAN_PROTOCOL_TRANSPORT_STATS_PROVIDER_HPP_INCLUDED
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_STDINT_HPP_INCLUDED
#define UAVCAN_STDINT_HPP_INCLUDED
#include <uavcan/build_config.hpp>
@@ -52,3 +53,5 @@ typedef ::int64_t int64_t;
}
#endif
#endif // UAVCAN_STDINT_HPP_INCLUDED
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_TIME_HPP_INCLUDED
#define UAVCAN_TIME_HPP_INCLUDED
#include <cstdio>
#include <uavcan/stdint.hpp>
@@ -286,3 +287,5 @@ Stream& operator<<(Stream& s, const TimeBase<T, D>& t)
}
}
#endif // UAVCAN_TIME_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_TRANSPORT_ABSTRACT_TRANSFER_BUFFER_HPP_INCLUDED
#define UAVCAN_TRANSPORT_ABSTRACT_TRANSFER_BUFFER_HPP_INCLUDED
#include <uavcan/build_config.hpp>
#include <uavcan/stdint.hpp>
@@ -22,3 +23,5 @@ public:
};
}
#endif // UAVCAN_TRANSPORT_ABSTRACT_TRANSFER_BUFFER_HPP_INCLUDED
@@ -3,7 +3,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_TRANSPORT_CAN_IO_HPP_INCLUDED
#define UAVCAN_TRANSPORT_CAN_IO_HPP_INCLUDED
#include <cassert>
#include <uavcan/error.hpp>
@@ -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
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_TRANSPORT_CRC_HPP_INCLUDED
#define UAVCAN_TRANSPORT_CRC_HPP_INCLUDED
#include <cassert>
#include <uavcan/stdint.hpp>
@@ -75,3 +76,5 @@ public:
};
}
#endif // UAVCAN_TRANSPORT_CRC_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_TRANSPORT_DISPATCHER_HPP_INCLUDED
#define UAVCAN_TRANSPORT_DISPATCHER_HPP_INCLUDED
#include <cassert>
#include <uavcan/error.hpp>
@@ -192,3 +193,5 @@ public:
};
}
#endif // UAVCAN_TRANSPORT_DISPATCHER_HPP_INCLUDED
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_TRANSPORT_FRAME_HPP_INCLUDED
#define UAVCAN_TRANSPORT_FRAME_HPP_INCLUDED
#include <cassert>
#include <uavcan/transport/transfer.hpp>
@@ -128,3 +129,5 @@ public:
};
}
#endif // UAVCAN_TRANSPORT_FRAME_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_TRANSPORT_OUTGOING_TRANSFER_REGISTRY_HPP_INCLUDED
#define UAVCAN_TRANSPORT_OUTGOING_TRANSFER_REGISTRY_HPP_INCLUDED
#include <cassert>
#include <uavcan/stdint.hpp>
@@ -174,3 +175,5 @@ void OutgoingTransferRegistry<NumStaticEntries>::cleanup(MonotonicTime ts)
}
}
#endif // UAVCAN_TRANSPORT_OUTGOING_TRANSFER_REGISTRY_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_TRANSPORT_PERF_COUNTER_HPP_INCLUDED
#define UAVCAN_TRANSPORT_PERF_COUNTER_HPP_INCLUDED
#include <uavcan/stdint.hpp>
#include <uavcan/build_config.hpp>
@@ -57,3 +58,5 @@ public:
#endif
}
#endif // UAVCAN_TRANSPORT_PERF_COUNTER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_TRANSPORT_TRANSFER_HPP_INCLUDED
#define UAVCAN_TRANSPORT_TRANSFER_HPP_INCLUDED
#include <cassert>
#include <uavcan/build_config.hpp>
@@ -100,3 +101,5 @@ public:
};
}
#endif // UAVCAN_TRANSPORT_TRANSFER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_TRANSPORT_TRANSFER_BUFFER_HPP_INCLUDED
#define UAVCAN_TRANSPORT_TRANSFER_BUFFER_HPP_INCLUDED
#include <uavcan/stdint.hpp>
#include <uavcan/error.hpp>
@@ -324,3 +325,5 @@ public:
};
}
#endif // UAVCAN_TRANSPORT_TRANSFER_BUFFER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_TRANSPORT_TRANSFER_LISTENER_HPP_INCLUDED
#define UAVCAN_TRANSPORT_TRANSFER_LISTENER_HPP_INCLUDED
#include <cassert>
#include <uavcan/error.hpp>
@@ -246,3 +247,5 @@ void ServiceResponseTransferListener<MaxBufSize>::stopAcceptingAnything()
}
}
#endif // UAVCAN_TRANSPORT_TRANSFER_LISTENER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_TRANSPORT_TRANSFER_RECEIVER_HPP_INCLUDED
#define UAVCAN_TRANSPORT_TRANSFER_RECEIVER_HPP_INCLUDED
#include <cstdlib>
#include <uavcan/build_config.hpp>
@@ -83,3 +84,5 @@ public:
UAVCAN_PACKED_END
}
#endif // UAVCAN_TRANSPORT_TRANSFER_RECEIVER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_TRANSPORT_TRANSFER_SENDER_HPP_INCLUDED
#define UAVCAN_TRANSPORT_TRANSFER_SENDER_HPP_INCLUDED
#include <cstdlib>
#include <cassert>
@@ -75,3 +76,5 @@ public:
};
}
#endif // UAVCAN_TRANSPORT_TRANSFER_SENDER_HPP_INCLUDED
+4 -1
View File
@@ -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 <uavcan/build_config.hpp>
#include <uavcan/time.hpp>
@@ -22,3 +23,5 @@
#include <uavcan/util/templates.hpp>
#include <uavcan/util/lazy_constructor.hpp>
#include <uavcan/util/method_binder.hpp>
#endif // UAVCAN_UAVCAN_HPP_INCLUDED
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_UTIL_BITSET_HPP_INCLUDED
#define UAVCAN_UTIL_BITSET_HPP_INCLUDED
#include <cassert>
#include <cstddef>
@@ -184,3 +185,5 @@ Stream& operator<<(Stream& s, const BitSet<NumBits>& x)
}
}
#endif // UAVCAN_UTIL_BITSET_HPP_INCLUDED
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_UTIL_COMPARISON_HPP_INCLUDED
#define UAVCAN_UTIL_COMPARISON_HPP_INCLUDED
#include <uavcan/util/templates.hpp>
#include <uavcan/build_config.hpp>
@@ -266,3 +267,5 @@ inline bool isCloseToZero<long double>(const long double& x)
}
}
#endif // UAVCAN_UTIL_COMPARISON_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_UTIL_LAZY_CONSTRUCTOR_HPP_INCLUDED
#define UAVCAN_UTIL_LAZY_CONSTRUCTOR_HPP_INCLUDED
#include <cstdlib>
#include <uavcan/error.hpp>
@@ -173,3 +174,5 @@ public:
};
}
#endif // UAVCAN_UTIL_LAZY_CONSTRUCTOR_HPP_INCLUDED
@@ -3,7 +3,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_UTIL_LINKED_LIST_HPP_INCLUDED
#define UAVCAN_UTIL_LINKED_LIST_HPP_INCLUDED
#include <cstdlib>
#include <cassert>
@@ -99,9 +100,9 @@ unsigned LinkedListRoot<T>::getLength() const
template <typename T>
void LinkedListRoot<T>::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 <typename T>
template <typename Predicate>
void LinkedListRoot<T>::insertBefore(T* node, Predicate predicate)
{
UAVCAN_ASSERT(node);
if (node == NULL)
{
UAVCAN_ASSERT(0);
return;
}
@@ -170,3 +171,5 @@ void LinkedListRoot<T>::remove(const T* node)
}
}
#endif // UAVCAN_UTIL_LINKED_LIST_HPP_INCLUDED
+4 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_UTIL_MAP_HPP_INCLUDED
#define UAVCAN_UTIL_MAP_HPP_INCLUDED
#include <cassert>
#include <cstdlib>
@@ -500,3 +501,5 @@ unsigned MapBase<Key, Value>::getNumDynamicPairs() const
}
}
#endif // UAVCAN_UTIL_MAP_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_UTIL_METHOD_BINDER_HPP_INCLUDED
#define UAVCAN_UTIL_METHOD_BINDER_HPP_INCLUDED
#include <uavcan/error.hpp>
#include <uavcan/build_config.hpp>
@@ -79,3 +80,5 @@ public:
};
}
#endif // UAVCAN_UTIL_METHOD_BINDER_HPP_INCLUDED
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_UTIL_PLACEMENT_NEW_HPP_INCLUDED
#define UAVCAN_UTIL_PLACEMENT_NEW_HPP_INCLUDED
#include <cstddef>
#include <uavcan/build_config.hpp>
@@ -33,3 +34,5 @@ inline void operator delete[](void*, void*) throw() { }
#else
# include <new>
#endif
#endif // UAVCAN_UTIL_PLACEMENT_NEW_HPP_INCLUDED
+5 -1
View File
@@ -2,7 +2,8 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#ifndef UAVCAN_UTIL_TEMPLATES_HPP_INCLUDED
#define UAVCAN_UTIL_TEMPLATES_HPP_INCLUDED
#include <climits>
#include <cstddef>
@@ -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
+2 -2
View File
@@ -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)
@@ -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)
@@ -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<int>(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<int>(request.id), static_cast<int>(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;
}
+18 -7
View File
@@ -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
@@ -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())
@@ -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)
@@ -95,8 +95,9 @@ TEST(GlobalDataTypeRegistry, Basic)
/*
* Runtime registrations
*/
ASSERT_EQ(GlobalDataTypeRegistry::RegistResultOk,
GlobalDataTypeRegistry::instance().regist<DataTypeAService>(DataTypeAService::DefaultDataTypeID));
ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultOk,
GlobalDataTypeRegistry::instance().registerDataType<DataTypeAService>(
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<DataTypeAService>(147));
ASSERT_EQ(GlobalDataTypeRegistry::RegistResultOk, GlobalDataTypeRegistry::instance().regist<DataTypeB>(741));
ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultOk,
GlobalDataTypeRegistry::instance().registerDataType<DataTypeAService>(147));
ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultOk,
GlobalDataTypeRegistry::instance().registerDataType<DataTypeB>(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<DataTypeC>(741)); // ID COLLISION
ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultCollision,
GlobalDataTypeRegistry::instance().registerDataType<DataTypeC>(741)); // ID COLLISION
ASSERT_EQ(GlobalDataTypeRegistry::RegistResultOk,
GlobalDataTypeRegistry::instance().regist<DataTypeC>(DataTypeC::DefaultDataTypeID));
ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultOk,
GlobalDataTypeRegistry::instance().registerDataType<DataTypeC>(DataTypeC::DefaultDataTypeID));
uavcan::DefaultDataTypeRegistrator<DataTypeD> 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<DataTypeAService>(555)); // Rejected
ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultFrozen,
GlobalDataTypeRegistry::instance().registerDataType<DataTypeAService>(555)); // Rejected
ASSERT_EQ(GlobalDataTypeRegistry::RegistResultFrozen,
GlobalDataTypeRegistry::instance().regist<DataTypeAMessage>(999)); // Rejected
ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultFrozen,
GlobalDataTypeRegistry::instance().registerDataType<DataTypeAMessage>(999)); // Rejected
ASSERT_EQ(GlobalDataTypeRegistry::RegistResultFrozen,
GlobalDataTypeRegistry::instance().regist<DataTypeB>(888)); // Rejected
ASSERT_EQ(GlobalDataTypeRegistry::RegistrationResultFrozen,
GlobalDataTypeRegistry::instance().registerDataType<DataTypeB>(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<DataTypeB>(741), *pdtd);
ASSERT_TRUE((pdtd = GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindMessage, 741)));
ASSERT_EQ(extractDescriptor<DataTypeB>(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<DataTypeAMessage>(), *pdtd);
ASSERT_TRUE((pdtd = GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindMessage, uavcan::DataTypeID(0))));
ASSERT_EQ(extractDescriptor<DataTypeAMessage>(), *pdtd);
@@ -23,22 +23,39 @@ static bool validateDataTypeInfoResponse(const std::auto_ptr<ServiceCallResult<G
{
if (!resp.get())
{
std::cout << "Null response" << std::endl;
return false;
}
if (!resp->isSuccessful())
{
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<GetDataTypeInfo>(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
+12 -6
View File
@@ -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)
+20 -12
View File
@@ -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] << " <node-id> <can-iface-name-1> [can-iface-name-N...]" << std::endl;
if (argc < 3)
{
std::cerr << "Usage:\n\t" << argv[0] << " <node-id> <can-iface-name-1> [can-iface-name-N...]" << std::endl;
return 1;
}
const int self_node_id = std::stoi(argv[1]);
std::vector<std::string> 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<std::string> 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;
}
+24 -16
View File
@@ -332,23 +332,31 @@ static void testDriver(const std::vector<std::string>& iface_names)
int main(int argc, const char** argv)
{
if (argc < 2)
try
{
std::cout << "Usage:\n\t" << argv[0] << " <can-iface-name-1> [can-iface-name-N...]" << std::endl;
if (argc < 2)
{
std::cerr << "Usage:\n\t" << argv[0] << " <can-iface-name-1> [can-iface-name-N...]" << std::endl;
return 1;
}
std::vector<std::string> 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<std::string> 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;
}
+19 -11
View File
@@ -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] << " <node-id> <can-iface-name-1> [can-iface-name-N...]" << std::endl;
if (argc < 3)
{
std::cerr << "Usage:\n\t" << argv[0] << " <node-id> <can-iface-name-1> [can-iface-name-N...]" << std::endl;
return 1;
}
const int self_node_id = std::stoi(argv[1]);
std::vector<std::string> 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<std::string> 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;
}
@@ -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<std::string>& 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] << " <node-id> <can-iface-name-1> [can-iface-name-N...]" << std::endl;
if (argc < 3)
{
std::cerr << "Usage:\n\t" << argv[0] << " <node-id> <can-iface-name-1> [can-iface-name-N...]" << std::endl;
return 1;
}
const int self_node_id = std::stoi(argv[1]);
const std::vector<std::string> 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<std::string> iface_names(argv + 2, argv + argc);
uavcan_linux::NodePtr node = initNode(iface_names, self_node_id, "org.uavcan.linux_nodetool");
runForever(node);
return 0;
}
@@ -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-1> [can-iface-name-N...]" << std::endl;
if (argc < 2)
{
std::cerr << "Usage:\n\t" << argv[0] << " <can-iface-name-1> [can-iface-name-N...]" << std::endl;
return 1;
}
std::vector<std::string> 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<std::string> 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;
}
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
#
@@ -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 \
@@ -13,7 +13,7 @@
namespace
{
typedef uavcan::Node<3136> Node;
typedef uavcan::Node<2800> Node;
Node& getNode()
{