Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UAVCAN UAVCAN_Subscriber
server.cpp
00001 /* 00002 * Copyright (C) 2015 Pavel Kirienko <pavel.kirienko@gmail.com> 00003 */ 00004 00005 #include <gtest/gtest.h> 00006 #include <uavcan/protocol/dynamic_node_id_server/centralized.hpp> 00007 #include <uavcan/protocol/dynamic_node_id_client.hpp> 00008 #include "../../helpers.hpp" 00009 #include "../event_tracer.hpp" 00010 #include "../../helpers.hpp" 00011 #include "../memory_storage_backend.hpp" 00012 00013 using uavcan::dynamic_node_id_server::UniqueID; 00014 00015 00016 TEST(dynamic_node_id_server_centralized_Server, Basic) 00017 { 00018 using namespace uavcan::dynamic_node_id_server; 00019 using namespace uavcan::protocol::dynamic_node_id; 00020 using namespace uavcan::protocol::dynamic_node_id::server; 00021 00022 uavcan::GlobalDataTypeRegistry::instance().reset(); 00023 uavcan::DefaultDataTypeRegistrator<Allocation> _reg1; 00024 uavcan::DefaultDataTypeRegistrator<uavcan::protocol::GetNodeInfo> _reg2; 00025 uavcan::DefaultDataTypeRegistrator<uavcan::protocol::NodeStatus> _reg3; 00026 00027 EventTracer tracer; 00028 MemoryStorageBackend storage; 00029 00030 // Node A is Allocator, Node B is Allocatee 00031 InterlinkedTestNodesWithSysClock nodes(uavcan::NodeID(10), uavcan::NodeID::Broadcast); 00032 00033 UniqueID own_unique_id; 00034 own_unique_id[0] = 0xAA; 00035 own_unique_id[3] = 0xCC; 00036 own_unique_id[7] = 0xEE; 00037 own_unique_id[9] = 0xBB; 00038 00039 /* 00040 * Server 00041 */ 00042 uavcan::dynamic_node_id_server::CentralizedServer server(nodes.a, storage, tracer); 00043 00044 ASSERT_LE(0, server.init(own_unique_id)); 00045 00046 ASSERT_EQ(1, server.getNumAllocations()); // Server's own node ID 00047 00048 /* 00049 * Client 00050 */ 00051 uavcan::DynamicNodeIDClient client(nodes.b); 00052 uavcan::protocol::HardwareVersion::FieldTypes::unique_id unique_id; 00053 for (uavcan::uint8_t i = 0; i < unique_id.size(); i++) 00054 { 00055 unique_id[i] = i; 00056 } 00057 const uavcan::NodeID PreferredNodeID = 42; 00058 ASSERT_LE(0, client.start(unique_id, PreferredNodeID)); 00059 00060 /* 00061 * Fire 00062 */ 00063 nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(15000)); 00064 00065 ASSERT_TRUE(client.isAllocationComplete()); 00066 ASSERT_EQ(PreferredNodeID, client.getAllocatedNodeID()); 00067 00068 ASSERT_EQ(2, server.getNumAllocations()); // Server's own node ID + client 00069 } 00070 00071 00072 TEST(dynamic_node_id_server_centralized, ObjectSizes) 00073 { 00074 using namespace uavcan::dynamic_node_id_server; 00075 std::cout << "centralized::Storage: " << sizeof(centralized::Storage) << std::endl; 00076 std::cout << "centralized::Server: " << sizeof(centralized::Server) << std::endl; 00077 std::cout << "NodeDiscoverer: " << sizeof(NodeDiscoverer) << std::endl; 00078 }
Generated on Tue Jul 12 2022 17:17:34 by
1.7.2