NMT.h
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 
24 #ifndef NMT_H
25 #define NMT_H
26 
27 #include <stdint.h>
28 #include "helper.h"
29 #include "ds301.h"
30 #include <map>
31 
32 namespace icl_hardware {
33 namespace canopen_schunk {
34 
42 class NMT
43 {
44 public:
45 
47  static const uint8_t NMT_ALL_NODES = 0x00;
48 
51  {
52  NMT_STARTREMOTENODE = 0x01, // #1
53  NMT_STOPREMOTENODE = 0x02, // #2
54  NMT_ENTERPREOPERATIONAL = 0x80, // #128
55  NMT_RESETNODE = 0x81, // #129
56  NMT_RESETCOMMUNICATION = 0x82 // #139
57  };
58 
61  {
62  NMTS_STOPPED = 0x04,
65  NMTS_INITIALISATION = 0x00 // Value given arbitrarily, not defined in protocol
66  };
67 
70  {
74  };
75 
81  NMT(const uint8_t& node_id,const CanDevPtr& can_device);
82 
109  void update(const CanMsg& msg);
110 
114  void start();
115 
119  void stop();
120 
124  void preOperational();
125 
129  void reset();
130 
134  void resetCommunication();
135 
136 
137 
138 private:
139 
146  const std::string nmtCommandToString(const eNMT_Command& cmd)
147  {
148  std::string ret;
149  switch (cmd)
150  {
151  case NMT_STARTREMOTENODE: ret = "start remote node"; break;
152  case NMT_STOPREMOTENODE: ret = "stop remote node"; break;
153  case NMT_ENTERPREOPERATIONAL: ret = "enter pre-operational"; break;
154  case NMT_RESETNODE: ret = "reset node"; break;
155  case NMT_RESETCOMMUNICATION: ret = "reset communication"; break;
156  default: ret = "undefined"; break;
157  }
158  return ret;
159  }
160 
167  const std::string nmtStateToString(const eNMT_State& state)
168  {
169  std::string ret;
170  switch (state) {
171  case NMTS_STOPPED: ret = "stopped" ; break;
172  case NMTS_PRE_OPERATIONAL: ret = "pre operational" ; break;
173  case NMTS_OPERATIONAL: ret = "operational" ; break;
174  case NMTS_INITIALISATION: ret = "initialisation" ; break;
175  default:ret = "undefined"; break;
176  }
177  return ret;
178  }
179 
185  bool isValidNmtState(const uint8_t& state)
186  {
187  return ((state == NMTS_STOPPED) || (state == NMTS_PRE_OPERATIONAL) || (state == NMTS_OPERATIONAL) || (state == NMTS_INITIALISATION));
188  }
189 
195  void sendCommand(const eNMT_Command& cmd);
196 
197 
198 
199 
200 
203 
206 
209 
210 
211 
212 };
213 
214 
215 }}//end of NS
216 
217 #endif // NMT_H
void update(const CanMsg &msg)
update Updates the NMT status with newly received data
Definition: NMT.cpp:37
CanDevPtr m_can_device
can device handle for sending of NMT commands
Definition: NMT.h:202
void resetCommunication()
resetCommunication Resets the communication of a device, setting communication values to their defaul...
Definition: NMT.cpp:111
string cmd
NMT(const uint8_t &node_id, const CanDevPtr &can_device)
NMT Construct a new NMT object to manage the NMT state of a device.
Definition: NMT.cpp:30
The NMT class provides access to NMT functions of the canOpen protocol and keeps the NMT state of can...
Definition: NMT.h:42
const std::string nmtStateToString(const eNMT_State &state)
nmtStateToString Returns a string corresponding to a given NMT state
Definition: NMT.h:167
eNMT_SubState
The NMT Substate is only used during initialization of a device. Meaning the substates are only usefu...
Definition: NMT.h:69
void preOperational()
preOperational switches the device back into pre-operational state where configuration can occur ...
Definition: NMT.cpp:101
bool isValidNmtState(const uint8_t &state)
isValidNmtState Helper function to check if a received value is a valid NMT state ...
Definition: NMT.h:185
void reset()
reset Resets the device and triggers a complete reboot
Definition: NMT.cpp:106
static const uint8_t NMT_ALL_NODES
Node ID of all nodes at once.
Definition: NMT.h:47
void stop()
stop Stops the device by setting the NMT state to stopped
Definition: NMT.cpp:96
unsigned char uint8_t
const std::string nmtCommandToString(const eNMT_Command &cmd)
commandToString Returns a string corresponding to a command enum.
Definition: NMT.h:146
uint8_t m_node_id
We keep the node ID which this NMT object is corresponding to.
Definition: NMT.h:205
eNMT_Command
NMT Command specifies what the state machine shall do value = "cs" as specified in ds301 7...
Definition: NMT.h:50
void sendCommand(const eNMT_Command &cmd)
sendCommand Sends an actual NMT command to the device. This will proactively change the state of the ...
Definition: NMT.cpp:116
void start()
start Starts the device by setting the NMT state to operational
Definition: NMT.cpp:91
eNMT_State
The NMT state indicates the behavior of the communication of a device, everything else is device spec...
Definition: NMT.h:60
eNMT_State m_state
Status of the NMT state machine.
Definition: NMT.h:208


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