library for C++ CANOpen implementation. mbed independant, but is easy to attach into with mbed.
Dependents: ppCANOpen_Example DISCO-F746NG_rtos_test
Example:
Import programppCANOpen_Example
I am no longer actively working on the ppCANOpen library, however, I want to publish this project so that anyone who wants to pick up any of the pieces can have a good example. This is a a project I was working on using the ppCANOpen library. It has a pretty in deep use of the object dictionary structure. And a number of functions to control high voltage pinball drivers, if you're into that sort of thing.
include/Node.h
- Committer:
- ptpaterson
- Date:
- 2016-01-09
- Revision:
- 4:2034b04c86d2
- Parent:
- 3:12b3c25bdeba
- Child:
- 5:22a337cdc0e3
File content as of revision 4:2034b04c86d2:
/** ****************************************************************************** * @file * @author Paul Paterson * @version * @date 2015-12-14 * @brief CANOpen implementation library ****************************************************************************** * @attention * * <h2><center>© COPYRIGHT(c) 2015 Paul Paterson * * All rights reserved. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef PPCAN_NODE_H #define PPCAN_NODE_H /*========================================================================= * Forward declarations *========================================================================= */ struct CanOpenMessage; /* NMT Constants --------------------------------------------------------*/ #define NMT_STATE_TOGGLE_BIT 0x80 /* NMT Macros -----------------------------------------------------------*/ #define NMT_SET_STATE(curState, newState) (curState) = (((curState) & NMT_STATE_TOGGLE_BIT) | ((newState) & (~NMT_STATE_TOGGLE_BIT)))) namespace ppCANOpen { /* Avoid circular reference */ class ServiceProvider; class ObjectDictionary; /** Node Class to implement feature of a CANOpen NMT node */ class Node { public: /** Node network management state */ struct State { static const int INITIALIZED = 0x00; static const int DISCONNECTED = 0x01; static const int CONNECTING = 0x02; static const int PREPARING = 0x02; static const int STOPPED = 0x04; static const int OPERATIONAL = 0x05; static const int PREOPERATIONAL = 0x7F; static const int UNKNOWN = 0x0F; int nmtState; int bBoot; int bSDO; int bEmergency; int bSYNC; int bLifeGuard; int bPDO; int bLSS; int bLifeGuardToggle; }; /** Maintain the multitude of states for a node */ Node (ServiceProvider * provider); /* ======================================================================== * Methods to handle operation of node device * ======================================================================== */ // TODO: pass elapsed time to Update method virtual void Update (void); /* ======================================================================== * Message indication * Called by a ServiceProvider when a message is received. * ======================================================================== */ /** * @note */ int DispatchMessage(CanOpenMessage *canOpenMsg); protected: /* ======================================================================== * Methods to handle various messages * Called by a ServiceProvider when a message is received. * ======================================================================== */ /* PDO (7.2.2), MPDO (7.2.3) --------------------------------------------*/ int ConsumePdo (int pdoNum, char * dataIn); int HandlePdoReadRequest (int pdoNum); /* SDO (7.2.4) ----------------------------------------------------------*/ int HandleExpeditedDownload (int sdoNum, int index, int subIndex, int dataCount, char * data); int HandleInitiateDownloadRequest (int sdoNum, int index, int subIndex, int dataCount, char * data); int HandleExpeditedUpload (int sdoNum, int index, int subIndex); // TODO: express and not express /* SYNC object (7.2.5) --------------------------------------------------*/ // TODO: SYNC consumer /* Time Stamp object (7.2.6) --------------------------------------------*/ // TODO: time consumer /* Emergency object (7.2.7) ---------------------------------------------*/ int ConsumeEmergency (void);// TODO: fix params /* Network Management (7.2.8) -------------------------------------------*/ /* ---- Node Control (7.2.8.2.1) ----------------------------------------*/ int HandleNodeControl (int commandSpecifier); /* ---- Error Control (7.2.8.2.2) ---------------------------------------*/ int HandleNodeGuardRequest (int masterId); int ConsumeHeartbeat (int producerId); /* ======================================================================== * Methods to implement node control in derived classes * ======================================================================== */ /** Perform actions every cycle * @note Override to implement user application */ virtual void OnUpdate(void) = 0; /** Perform actions when node reset * @note Override to implement user application */ virtual void OnInitialize (void) = 0; /** Perform actions when state changed to pre-operational * @note Override to implement user application */ virtual void OnPreoperational (void) = 0; /** Perform actions when state changed to operational * @note Override to implement user application */ virtual void OnOperational (void) = 0; /** Perform actions when state changed to stop * @note Override to implement user application */ virtual void OnStopped (void) = 0; /* ======================================================================== * Protected Members * ======================================================================== */ /** object dictionary */ ObjectDictionary * pMyDictionary; private: /* ======================================================================== * Private members * ======================================================================== */ /** Reference to Service Provider that this node is attached to. * @note May need to be a pointer, because node id is held in object dictionary */ ServiceProvider * pMyProvider; /** Network id for the node * @note May need to be a pointer, because node id is held in object dictionary */ int nodeId; /** Network and communication state of the node * @note */ State state; }; } /* namespace ppCANOpen */ #endif // PPCAN_NODE_H