MIRA
CANToolsView.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 MetraLabs GmbH (MLAB), GERMANY.
3  * All rights reserved.
4  * Contact: info@MetraLabs.com
5  *
6  * Commercial Usage:
7  * Licensees holding valid commercial licenses may use this file in
8  * accordance with the commercial license agreement provided with the
9  * software or, alternatively, in accordance with the terms contained in
10  * a written agreement between you and MetraLabs.
11  *
12  * GNU General Public License Usage:
13  * Alternatively, this file may be used under the terms of the GNU
14  * General Public License version 3.0 as published by the Free Software
15  * Foundation and appearing in the file LICENSE.GPL3 included in the
16  * packaging of this file. Please review the following information to
17  * ensure the GNU General Public License version 3.0 requirements will be
18  * met: http://www.gnu.org/copyleft/gpl.html.
19  * Alternatively you may (at your option) use any later version of the GNU
20  * General Public License if such license has been publicly approved by
21  * MetraLabs (or its successors, if any).
22  *
23  * IN NO EVENT SHALL "MLAB" BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
24  * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE
25  * OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLABS" HAS BEEN
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * "MLAB" SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
31  * "AS IS" BASIS, AND "MLAB" HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
32  * SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
33  */
34 
43 #ifndef _MLAB_CANTOOLSVIEW_H_
44 #define _MLAB_CANTOOLSVIEW_H_
45 
46 #include <fw/Framework.h>
47 #include <rcp/EditorPart.h>
48 #include <views/PropertyViewPage.h>
50 
52 #include <can/CANOpenSDOClient.h>
53 #include <can/CANOpenNMTMaster.h>
55 
56 #include <QTabWidget>
57 #include <QTimer>
58 
59 namespace mira { namespace can {
60 
62 
67 {
68  Q_OBJECT
69 
71  ("Name", "CAN tools view")
72  ("Category", "CAN")
73  ("Description", "Tools for monitoring and setting up CANOpen modules"));
74 
75 public:
78 
79  CANToolsView();
80  ~CANToolsView();
81 
83 
85  template<typename Reflector>
86  void reflect(Reflector& r)
87  {}
88 
90  void reflect(XMLDeserializer& r);
91 
93  void reflect(XMLSerializer& r);
94 
95 public:
98 
101  {
102  return mCANInterface;
103  }
104 
107  {
108  return mAuthority;
109  }
110 
113  {
114  return mSDOClient;
115  }
116 
119  {
120  return mNMTMaster;
121  }
122 
124  {
125  return mState;
126  }
127 
129 
130 public:
131  template <typename T>
132  void addProperties(const std::string& name, T* CLASS)
133  {
135  PropertyNode* p = s.reflectProperties(name, CLASS);
136  mProperties.push_back(boost::shared_ptr<PropertyNode>(p));
137  }
138 
140  virtual Object* getAdapter(const Class& adapter)
141  {
142  if(adapter == PropertyViewPage::CLASS())
143  {
144  if (!mProperties.empty())
145  {
146  mControl->clearPropertyNodes();
147  foreach(auto& p, mProperties)
148  mControl->addPropertyNode(p);
149  mControl->setWindowTitle(this->windowTitle());
150  return mControl;
151  }
152  else
153  return EditorPart::getAdapter(adapter);
154  }
155 
156  return EditorPart::getAdapter(adapter);
157  }
158 
159 public slots:
160  void watchDogTimeout();
161 
162 protected:
165 
166  virtual QWidget* createPartControl();
167 
169 
170 protected:
171  void onHeartbeat(uint8 node, can::CANOpenNodeStatus status);
172  void startModule(const can::CANOpenNodeInfo& nodeInfo);
173  bool pluginSupportsNode(CANToolsViewPlugin* plugin, const CANOpenNodeInfo& nodeInfo);
174 
175  CANOpenNodeInfo mAllNodes[255];
176  uint16 mHeartbeatRates[255];
177  uint8 mHeartbeatTimeoutCount[255];
178 
179 protected:
181  QTabWidget* mTabWidget;
182  QTimer *mWatchDogTimer;
183  uint32 mHeartbeatID;
184  std::map<std::string, QTabWidget*> mCategories;
185  std::list<CANToolsViewPlugin*> mPlugins;
186  std::list<boost::shared_ptr<PropertyNode>> mProperties;
189  std::map<std::string, int> mTabIndex;
190 
194 };
195 
197 
198 }} // namespaces
199 
200 #endif
void reflect(Reflector &r)
Reflect method for serialization.
Definition: CANToolsView.h:86
QTabWidget * mTabWidget
Definition: CANToolsView.h:181
The base class for all CAN tools.
Definition: CANToolsViewPlugin.h:61
PropertyViewPage * mControl
Definition: CANToolsView.h:187
std::list< CANToolsViewPlugin * > mPlugins
Definition: CANToolsView.h:185
mira::can::CANOpenSDOClientPtr mSDOClient
Definition: CANToolsView.h:192
An implementation of a basic CANopen NMT master.
boost::shared_ptr< CANOpenNMTMaster > CANOpenNMTMasterPtr
A shared pointer of the CANOpenNMTMaster.
Definition: CANOpenNMTMaster.h:335
std::map< std::string, QTabWidget * > mCategories
Definition: CANToolsView.h:184
QTimer * mWatchDogTimer
Definition: CANToolsView.h:182
void addProperties(const std::string &name, T *CLASS)
Definition: CANToolsView.h:132
Implementation of a CANOpen SDO client.
boost::shared_ptr< CANOpenSDOClient > CANOpenSDOClientPtr
A shared pointer of the CANOpenSDOClient.
Definition: CANOpenSDOClient.h:306
virtual Object * getAdapter(const Class &adapter)
Implementation of mira::IAdaptable.
Definition: CANToolsView.h:140
#define MIRA_META_OBJECT(classIdentifier, MetaInfo)
std::map< std::string, int > mTabIndex
Definition: CANToolsView.h:189
Authority & getAuthority()
Return the authority.
Definition: CANToolsView.h:106
CANOpenNodeStatus
The different CANopen node states.
Definition: CANOpenDefs.h:154
mira::can::CANOpenNMTMasterPtr mNMTMaster
Definition: CANToolsView.h:193
void reflect(Reflector &r, LogRecord &record)
XMLDom mState
Definition: CANToolsView.h:188
#define MLAB_CANGUI_EXPORT
Definition: CANGUIExports.h:57
boost::shared_ptr< CANChannelInterface > CANChannelInterfacePtr
A shared pointer for CANChannelInterface.
Definition: CANChannelInterface.h:120
XMLDom & getSavedState()
Definition: CANToolsView.h:123
mira::can::CANOpenSDOClientPtr getSDOClient() const
Return the CANOpen SDO interface.
Definition: CANToolsView.h:112
mira::can::CANOpenNMTMasterPtr getNMTMaster() const
Return the CANOpen NMT master.
Definition: CANToolsView.h:118
A struct, which contains standard information about a CANopen node.
Definition: CANOpenDefs.h:165
Authority mAuthority
Definition: CANToolsView.h:180
virtual Object * getAdapter(const Class &adapter)
uint32 mHeartbeatID
Definition: CANToolsView.h:183
void reflectProperties(PropertyNode *root, const std::string &name, T &object)
The base class for CAN tools.
The base class for all graphical CAN tools.
Definition: CANToolsView.h:66
An interface for providing CAN messages with the MIRA framework.
static PseudoClass const & CLASS()
std::list< boost::shared_ptr< PropertyNode > > mProperties
Definition: CANToolsView.h:186
mira::can::CANChannelInterfacePtr getCANInterface() const
Return the CAN interface.
Definition: CANToolsView.h:100
mira::can::CANChannelInterfacePtr mCANInterface
Definition: CANToolsView.h:191