BusErrorHandler.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2017, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarX
19 * @author Stefan Reither( stefan dot reither at kit dot edu)
20 * @date 2021
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#pragma once
26
27#include <atomic>
28#include <thread>
29
31
33{
34 class SlaveInterface;
35 using SlaveList = std::vector<SlaveInterface*>;
36
37 class Bus;
38
39 /**
40 * @class BusErrorHandler
41 * @ingroup Library-ethercat
42 * @brief Brief description of class BusErrorHandler.
43 *
44 * Detailed description of class BusErrorHandler.
45 */
47 {
48 public:
49 BusErrorHandler(Bus* bus);
50 ~BusErrorHandler() override;
51
52 void rtHandleBusErrors();
54
55 bool hasError() const;
56 bool isReinitializationActive() const;
57
59
60 void init(int wkc);
61
62
63 private:
64 Bus* bus;
65
66 enum class SlaveState
67 {
68 Operational,
69 Lost,
70 Reinitializating
71 };
72
73 // This member must be updated whenever ...
74 // - the workCounter changes
75 // - foundAgainSlaves are fully recovered
76 // - ?
77 std::map<SlaveInterface*, SlaveState> slaveStates;
78 std::atomic_bool allSlavesReinitialized{true};
79
80 int secondLastUnexpectedWorkCounter = 0;
81 int expectedWorkCounter = -1;
82
83 bool busErrorFound = false;
84 bool slaveErrorFound = false;
85
86 void rtUpdateSlaveStates();
87
88 void rtMarkLostSlavesInSOEMStruct() const;
89
90 void reinitializeSlaves();
91
92 std::thread slaveReinitializingThread;
93 std::atomic_bool slaveReinitializingThreadRunning{true};
94 void slaveReinitializingLoop();
95
96 bool areAllSlavesReinitialized() const;
97
98 /**
99 * @brief
100 */
101 class Watchdog
102 {
103 public:
104 Watchdog(std::uint32_t minDurationUS);
105 bool expired() const;
106 void reset();
107
108 private:
109 std::uint32_t minDuration;
110 IceUtil::Time lastTime;
111 };
112
113 Watchdog workerCounterWatchdog;
114 };
115} // namespace armarx::control::ethercat
Base Class for all Logging classes.
Definition Logging.h:240
bool isSlaveLostOrDuringReinitialization(SlaveInterface *slave) const
Brief description of class Bus.
Definition Bus.h:57
Brief description of class SlaveInterface.
std::vector< SlaveInterface * > SlaveList