sub_node.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Pavel Kirienko <pavel.kirienko@gmail.com>
3  */
4 
5 #include <gtest/gtest.h>
6 #include <uavcan/node/node.hpp>
9 #include "test_node.hpp"
10 #include "../protocol/helpers.hpp"
11 
12 static void registerTypes()
13 {
21 }
22 
23 
24 TEST(SubNode, Basic)
25 {
26  registerTypes();
28 
29  uavcan::protocol::SoftwareVersion swver;
30  swver.major = 0;
31  swver.minor = 1;
32  swver.vcs_commit = 0xDEADBEEF;
33 
34  std::cout << "sizeof(uavcan::SubNode<0>): " << sizeof(uavcan::SubNode<0>) << std::endl;
35 
36  /*
37  * uavcan::Node
38  */
39  uavcan::Node<1024> node1(nodes.can_a, nodes.clock_a);
40  node1.setName("com.example");
41  node1.setNodeID(1);
42  node1.setSoftwareVersion(swver);
43 
44  /*
45  * uavcan::SubNode
46  */
47  uavcan::SubNode<1024> node2(nodes.can_b, nodes.clock_b);
48 
49  BackgroundSpinner bgspinner(node2, node1);
51 
52  uavcan::NodeStatusMonitor node_status_monitor(node2);
53  ASSERT_LE(0, node_status_monitor.start());
54 
55  /*
56  * Init the first node
57  */
58  ASSERT_FALSE(node1.isStarted());
59  ASSERT_EQ(-uavcan::ErrNotInited, node1.spin(uavcan::MonotonicDuration::fromMSec(20)));
60  ASSERT_LE(0, node1.start());
61  ASSERT_TRUE(node1.isStarted());
62 
63  ASSERT_LE(0, node1.spin(uavcan::MonotonicDuration::fromMSec(2000)));
64 
65  ASSERT_EQ(1, node_status_monitor.findNodeWithWorstHealth().get());
66 
67  /*
68  * Some logging
69  */
71  ASSERT_LE(0, log_sub.start());
72 
73  node1.getLogger().setLevel(uavcan::protocol::debug::LogLevel::DEBUG);
74  node1.logInfo("test", "6 * 9 = 42");
75 
76  ASSERT_LE(0, node1.spin(uavcan::MonotonicDuration::fromMSec(20)));
77  ASSERT_LE(0, node2.spin(uavcan::MonotonicDuration::fromMSec(20)));
78 
79  ASSERT_TRUE(log_sub.collector.msg.get());
80  std::cout << *log_sub.collector.msg << std::endl;
81 }
uavcan::SubNode
Definition: sub_node.hpp:24
uavcan::DefaultDataTypeRegistrator
Definition: global_data_type_registry.hpp:186
SubscriberWithCollector
Definition: libuavcan/libuavcan/test/protocol/helpers.hpp:33
uavcan::NodeID::get
uint8_t get() const
Definition: transfer.hpp:132
node.hpp
uavcan::DurationBase< MonotonicDuration >::fromMSec
static MonotonicDuration fromMSec(int64_t ms)
Definition: time.hpp:41
InterlinkedTestNodes::can_b
PairableCanDriver can_b
Definition: test_node.hpp:154
SubscriberWithCollector::start
int start()
Definition: libuavcan/libuavcan/test/protocol/helpers.hpp:45
uavcan::NodeStatusMonitor
Definition: node_status_monitor.hpp:22
uavcan::INode::spin
int spin(MonotonicTime deadline)
Definition: abstract_node.hpp:63
uavcan::TimerBase::startPeriodic
void startPeriodic(MonotonicDuration period)
Definition: uc_timer.cpp:42
node_status_monitor.hpp
InterlinkedTestNodes
Definition: test_node.hpp:149
SubscriberWithCollector::collector
Collector collector
Definition: libuavcan/libuavcan/test/protocol/helpers.hpp:38
test_node.hpp
uavcan::NodeStatusMonitor::findNodeWithWorstHealth
NodeID findNodeWithWorstHealth() const
Definition: node_status_monitor.hpp:277
InterlinkedTestNodes::clock_b
ClockType clock_b
Definition: test_node.hpp:152
registerTypes
static void registerTypes()
Definition: sub_node.cpp:12
SubscriptionCollector::msg
std::unique_ptr< DataType > msg
Definition: libuavcan/libuavcan/test/protocol/helpers.hpp:23
InterlinkedTestNodes::clock_a
ClockType clock_a
Definition: test_node.hpp:151
uavcan::GlobalDataTypeRegistry::instance
static GlobalDataTypeRegistry & instance()
Definition: uc_global_data_type_registry.cpp:128
sub_node.hpp
BackgroundSpinner
Definition: libuavcan/libuavcan/test/protocol/helpers.hpp:119
TEST
TEST(SubNode, Basic)
Definition: sub_node.cpp:24
uavcan::Node
Definition: node.hpp:38
InterlinkedTestNodes::can_a
PairableCanDriver can_a
Definition: test_node.hpp:153
uavcan::NodeStatusMonitor::start
int start()
Definition: node_status_monitor.hpp:196


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:03