test_emcy.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of the SCHUNK Canopen Driver suite.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 SCHUNK GmbH, Lauffen/Neckar Germany
12 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23 
25 
29 
31 
32 #include <boost/test/included/unit_test.hpp>
33 
34 
35 using namespace icl_hardware::canopen_schunk;
36 BOOST_AUTO_TEST_SUITE( ts_emcy )
37 
38 /*
39  * This test tests the basic EMCY functionality. One example message is sent and compared to what
40  * arrives at the node.
41  * Additionally, some artificially false data is tested for error handling.
42  */
43 BOOST_AUTO_TEST_CASE( message_parsing )
44 {
45  // Initializing
48  LOGGING_INFO(CanOpen, "---------------------------" << endl <<
49  "-----Running EMCY test-----" << endl <<
50  "---------------------------" << endl);
51 
52  CanOpenController my_controller("Dummy");
54  can_device = boost::dynamic_pointer_cast<icl_hardware::can::tCanDeviceDummy>(my_controller.getCanDevice());
55 
56  // Add one node
57  my_controller.addGroup<DS301Group>("testgroup");
58  my_controller.addNode<DS301Node>(1, "testgroup");
59  DS301Group::Ptr my_group = my_controller.getGroup<DS301Group>("testgroup");
60  DS301Node::Ptr node = my_group->getNodes().front();
61 
62  // create can message
63  CanMsg msg;
64  msg.id = ds301::ID_EMCY_MIN; // EMCY for first node
65  msg.dlc = 8;
66  msg.rtr = 0;
67  // error code 0x8130
68  msg.data[0] = 0x30;
69  msg.data[1] = 0x81;
70  // Error registers 0x01, 0x02, 0x03, 0x20
71  msg.data[2] = 0x27;
72 
73  // some arbitrary manufacturer-specific data
74  msg.data[3] = 0x03;
75  msg.data[4] = 0x04;
76  msg.data[5] = 0x05;
77  msg.data[6] = 0x06;
78  msg.data[7] = 0x07;
79  can_device->addResponse(msg, false);
80 
81  // wait for the response being processed
82  boost::this_thread::sleep(boost::posix_time::milliseconds(100));
83 
84  uint16_t eec_ret;
85  uint8_t error_register_ret;
86  std::vector<uint8_t> msef_ret;
87  BOOST_REQUIRE( node->m_emcy->getErrorInformation(eec_ret, error_register_ret, msef_ret));
88 
89  BOOST_REQUIRE( eec_ret == msg.data[0] + (msg.data[1] << 8) );
90  BOOST_REQUIRE( error_register_ret == msg.data[2]);
91  BOOST_REQUIRE( msef_ret[0] == msg.data[3]);
92  BOOST_REQUIRE( msef_ret[1] == msg.data[4]);
93  BOOST_REQUIRE( msef_ret[2] == msg.data[5]);
94  BOOST_REQUIRE( msef_ret[3] == msg.data[6]);
95  BOOST_REQUIRE( msef_ret[4] == msg.data[7]);
96  BOOST_REQUIRE( node->m_emcy->getEmcyStatus() == EMCY::EMCY_STATE_ERROR_OCCURED);
97 
98  // send a ERROR_FREE_EMCY
99  msg.data[0] = 0x00;
100  msg.data[1] = 0x00;
101 
102  can_device->addResponse(msg, false);
103 
104  // wait for the response being processed
105  boost::this_thread::sleep(boost::posix_time::milliseconds(100));
106 
107  // Now there should be no error
108  BOOST_REQUIRE( !(node->m_emcy->getErrorInformation(eec_ret, error_register_ret, msef_ret)));
109  BOOST_REQUIRE( node->m_emcy->getEmcyStatus() == EMCY::EMCY_STATE_ERROR_FREE);
110  std::cout << "\n";
111 
112  // WARNING: Do not remove the following 4 lines as they reset the error state to non-error. Otherwise the following tests will fail!
113  // send a ERROR_FREE_EMCY
114  msg.data[0] = 0x00;
115  msg.data[1] = 0x00;
116  can_device->addResponse(msg, false);
117  boost::this_thread::sleep(boost::posix_time::milliseconds(100));
118 
119  msg.dlc = 13; // some arbitrary illegal number
120  can_device->addResponse(msg, false);
121  BOOST_REQUIRE( !(node->m_emcy->getErrorInformation(eec_ret, error_register_ret, msef_ret)));
122  BOOST_REQUIRE( node->m_emcy->getEmcyStatus() == EMCY::EMCY_STATE_ERROR_FREE);
123  msg.dlc = 8;
124  boost::this_thread::sleep(boost::posix_time::milliseconds(100));
125  std::cout << "\n";
126 
127  msg.id = ds301::ID_EMCY_MIN + 1; // This node id does not exist
128  can_device->addResponse(msg, false);
129  BOOST_REQUIRE( !(node->m_emcy->getErrorInformation(eec_ret, error_register_ret, msef_ret)));
130  BOOST_REQUIRE( node->m_emcy->getEmcyStatus() == EMCY::EMCY_STATE_ERROR_FREE);
131  msg.id = ds301::ID_EMCY_MIN;
132  boost::this_thread::sleep(boost::posix_time::milliseconds(100));
133  std::cout << "\n";
134 
135 }
136 
137 
138 BOOST_AUTO_TEST_SUITE_END()
bool initialize(int &argc, char *argv[], bool remove_read_arguments)
BOOST_AUTO_TEST_CASE(message_parsing)
Definition: test_emcy.cpp:43
CanDevPtr getCanDevice() const
Get a handle to the current CAN device. This is basically for debugging with a Dummy Can Device...
#define LOGGING_INFO(streamname, arg)
The DS301Group class is the base Class for all canOpen device groups, providing basic interfaces to t...
Definition: DS301Group.h:41
The CanOpenController class is the main entry point for any calls to the canOpen System.
static const uint16_t ID_EMCY_MIN
Definition: ds301.h:47
unsigned char uint8_t
ThreadStream & endl(ThreadStream &stream)
void setLogLevel(icl_core::logging::LogLevel log_level)
boost::shared_ptr< GroupT > getGroup(const std::string &index="default")
Returns a shared pointer to the group with a given index if possible.
void addNode(const uint8_t node_id, const std::string &group_name="default")
Adds a new node to a group. If the group is not found (e.g. it was not created before), nothing will be done.
void addGroup(const std::string &identifier)
Adds a new node group with a given identifier. The group&#39;s type is given as template parameter...
unsigned short uint16_t
The DS301Node class Is the base class representation of canOpen devices. It is the access point to th...
Definition: DS301Node.h:67


schunk_canopen_driver
Author(s): Felix Mauch , Georg Heppner
autogenerated on Mon Jun 10 2019 15:07:49