NMT.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of the SCHUNK Canopen Driver suite.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 SCHUNK GmbH, Lauffen/Neckar Germany
00012 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00022 //----------------------------------------------------------------------
00023 
00024 #ifndef NMT_H
00025 #define NMT_H
00026 
00027 #include <stdint.h>
00028 #include "helper.h"
00029 #include "ds301.h"
00030 #include <map>
00031 
00032 namespace icl_hardware {
00033 namespace canopen_schunk {
00034 
00042 class NMT
00043 {
00044 public:
00045 
00047   static const uint8_t NMT_ALL_NODES = 0x00;
00048 
00050   enum eNMT_Command
00051   {
00052       NMT_STARTREMOTENODE     = 0x01, // #1
00053       NMT_STOPREMOTENODE      = 0x02, // #2
00054       NMT_ENTERPREOPERATIONAL = 0x80, // #128
00055       NMT_RESETNODE           = 0x81, // #129
00056       NMT_RESETCOMMUNICATION  = 0x82  // #139
00057   };
00058 
00060   enum eNMT_State
00061   {
00062     NMTS_STOPPED          = 0x04,
00063     NMTS_PRE_OPERATIONAL  = 0x7F,
00064     NMTS_OPERATIONAL      = 0x05,
00065     NMTS_INITIALISATION   = 0x00    // Value given arbitrarily, not defined in protocol
00066   };
00067 
00069   enum eNMT_SubState
00070   {
00071     NMTSS_INITIALISING,
00072     NMTSS_RESET_APPLICATION,
00073     NMTSS_RESET_COMMUNICATION
00074   };
00075 
00081   NMT(const uint8_t& node_id,const CanDevPtr& can_device);
00082 
00109   void update(const CanMsg& msg);
00110 
00114   void start();
00115 
00119   void stop();
00120 
00124   void preOperational();
00125 
00129   void reset();
00130 
00134   void resetCommunication();
00135 
00136 
00137 
00138 private:
00139 
00146   const std::string nmtCommandToString(const eNMT_Command& cmd)
00147   {
00148     std::string ret;
00149     switch (cmd)
00150     {
00151       case NMT_STARTREMOTENODE: ret = "start remote node"; break;
00152       case NMT_STOPREMOTENODE: ret = "stop remote node"; break;
00153       case NMT_ENTERPREOPERATIONAL: ret = "enter pre-operational"; break;
00154       case NMT_RESETNODE: ret = "reset node"; break;
00155       case NMT_RESETCOMMUNICATION: ret = "reset communication"; break;
00156       default: ret = "undefined"; break;
00157     }
00158     return ret;
00159   }
00160 
00167   const std::string nmtStateToString(const eNMT_State& state)
00168   {
00169     std::string ret;
00170     switch (state) {
00171       case NMTS_STOPPED: ret = "stopped" ; break;
00172       case NMTS_PRE_OPERATIONAL: ret = "pre operational" ; break;
00173       case NMTS_OPERATIONAL: ret = "operational" ; break;
00174       case NMTS_INITIALISATION: ret = "initialisation" ; break;
00175       default:ret = "undefined"; break;
00176     }
00177     return ret;
00178   }
00179 
00185   bool isValidNmtState(const uint8_t& state)
00186   {
00187     return ((state == NMTS_STOPPED) ||  (state == NMTS_PRE_OPERATIONAL) || (state == NMTS_OPERATIONAL) || (state == NMTS_INITIALISATION));
00188   }
00189 
00195   void sendCommand(const eNMT_Command& cmd);
00196 
00197 
00198 
00199 
00200 
00202   CanDevPtr m_can_device;
00203 
00205   uint8_t m_node_id;
00206 
00208   eNMT_State m_state;
00209 
00210 
00211 
00212 };
00213 
00214 
00215 }}//end of NS
00216 
00217 #endif // NMT_H


schunk_canopen_driver
Author(s): Felix Mauch , Georg Heppner
autogenerated on Thu Jun 6 2019 20:17:24