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@2:c724ff3a4e4d, 2015-12-30 (annotated)
- Committer:
- ptpaterson
- Date:
- Wed Dec 30 13:33:41 2015 +0000
- Revision:
- 2:c724ff3a4e4d
- Child:
- 3:12b3c25bdeba
Implement simple Object Dictionary and derived class.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ptpaterson | 2:c724ff3a4e4d | 1 | /** |
ptpaterson | 2:c724ff3a4e4d | 2 | ****************************************************************************** |
ptpaterson | 2:c724ff3a4e4d | 3 | * @file |
ptpaterson | 2:c724ff3a4e4d | 4 | * @author Paul Paterson |
ptpaterson | 2:c724ff3a4e4d | 5 | * @version |
ptpaterson | 2:c724ff3a4e4d | 6 | * @date 2015-12-14 |
ptpaterson | 2:c724ff3a4e4d | 7 | * @brief CANOpen implementation library |
ptpaterson | 2:c724ff3a4e4d | 8 | ****************************************************************************** |
ptpaterson | 2:c724ff3a4e4d | 9 | * @attention |
ptpaterson | 2:c724ff3a4e4d | 10 | * |
ptpaterson | 2:c724ff3a4e4d | 11 | * <h2><center>© COPYRIGHT(c) 2015 Paul Paterson |
ptpaterson | 2:c724ff3a4e4d | 12 | * |
ptpaterson | 2:c724ff3a4e4d | 13 | * All rights reserved. |
ptpaterson | 2:c724ff3a4e4d | 14 | |
ptpaterson | 2:c724ff3a4e4d | 15 | This program is free software: you can redistribute it and/or modify |
ptpaterson | 2:c724ff3a4e4d | 16 | it under the terms of the GNU General Public License as published by |
ptpaterson | 2:c724ff3a4e4d | 17 | the Free Software Foundation, either version 3 of the License, or |
ptpaterson | 2:c724ff3a4e4d | 18 | (at your option) any later version. |
ptpaterson | 2:c724ff3a4e4d | 19 | |
ptpaterson | 2:c724ff3a4e4d | 20 | This program is distributed in the hope that it will be useful, |
ptpaterson | 2:c724ff3a4e4d | 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
ptpaterson | 2:c724ff3a4e4d | 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ptpaterson | 2:c724ff3a4e4d | 23 | GNU General Public License for more details. |
ptpaterson | 2:c724ff3a4e4d | 24 | |
ptpaterson | 2:c724ff3a4e4d | 25 | You should have received a copy of the GNU General Public License |
ptpaterson | 2:c724ff3a4e4d | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
ptpaterson | 2:c724ff3a4e4d | 27 | */ |
ptpaterson | 2:c724ff3a4e4d | 28 | |
ptpaterson | 2:c724ff3a4e4d | 29 | #ifndef PPCAN_NODE_H |
ptpaterson | 2:c724ff3a4e4d | 30 | #define PPCAN_NODE_H |
ptpaterson | 2:c724ff3a4e4d | 31 | |
ptpaterson | 2:c724ff3a4e4d | 32 | #include "canopen_protocol.h" |
ptpaterson | 2:c724ff3a4e4d | 33 | |
ptpaterson | 2:c724ff3a4e4d | 34 | namespace ppCANOpen |
ptpaterson | 2:c724ff3a4e4d | 35 | { |
ptpaterson | 2:c724ff3a4e4d | 36 | |
ptpaterson | 2:c724ff3a4e4d | 37 | /* Avoid circular reference */ |
ptpaterson | 2:c724ff3a4e4d | 38 | class ServiceProvider; |
ptpaterson | 2:c724ff3a4e4d | 39 | class ObjectDictionary; |
ptpaterson | 2:c724ff3a4e4d | 40 | |
ptpaterson | 2:c724ff3a4e4d | 41 | /** Maintain the multitude of states for a node */ |
ptpaterson | 2:c724ff3a4e4d | 42 | typedef struct { |
ptpaterson | 2:c724ff3a4e4d | 43 | NmtState nmtState; |
ptpaterson | 2:c724ff3a4e4d | 44 | int csBoot_Up; |
ptpaterson | 2:c724ff3a4e4d | 45 | int csSDO; |
ptpaterson | 2:c724ff3a4e4d | 46 | int csEmergency; |
ptpaterson | 2:c724ff3a4e4d | 47 | int csSYNC; |
ptpaterson | 2:c724ff3a4e4d | 48 | int csLifeGuard; |
ptpaterson | 2:c724ff3a4e4d | 49 | int csPDO; |
ptpaterson | 2:c724ff3a4e4d | 50 | int csLSS; |
ptpaterson | 2:c724ff3a4e4d | 51 | } NodeState; |
ptpaterson | 2:c724ff3a4e4d | 52 | |
ptpaterson | 2:c724ff3a4e4d | 53 | /** Node Class to implement feature of a CANOpen NMT node |
ptpaterson | 2:c724ff3a4e4d | 54 | */ |
ptpaterson | 2:c724ff3a4e4d | 55 | class Node |
ptpaterson | 2:c724ff3a4e4d | 56 | { |
ptpaterson | 2:c724ff3a4e4d | 57 | public: |
ptpaterson | 2:c724ff3a4e4d | 58 | Node (void); |
ptpaterson | 2:c724ff3a4e4d | 59 | |
ptpaterson | 2:c724ff3a4e4d | 60 | /* ======================================================================== |
ptpaterson | 2:c724ff3a4e4d | 61 | * Methods to message indication and confirmation |
ptpaterson | 2:c724ff3a4e4d | 62 | * Called by a ServiceProvider when a message is received. |
ptpaterson | 2:c724ff3a4e4d | 63 | * ======================================================================== |
ptpaterson | 2:c724ff3a4e4d | 64 | */ |
ptpaterson | 2:c724ff3a4e4d | 65 | |
ptpaterson | 2:c724ff3a4e4d | 66 | /* PDO (7.2.2), MPDO (7.2.3) --------------------------------------------*/ |
ptpaterson | 2:c724ff3a4e4d | 67 | |
ptpaterson | 2:c724ff3a4e4d | 68 | int ConsumePdo (int pdoNum, char * dataIn); |
ptpaterson | 2:c724ff3a4e4d | 69 | int HandlePdoReadRequest (int pdoNum); |
ptpaterson | 2:c724ff3a4e4d | 70 | |
ptpaterson | 2:c724ff3a4e4d | 71 | |
ptpaterson | 2:c724ff3a4e4d | 72 | /* SDO (7.2.4) ----------------------------------------------------------*/ |
ptpaterson | 2:c724ff3a4e4d | 73 | |
ptpaterson | 2:c724ff3a4e4d | 74 | int HandleExpeditedDownload (int sdoNum, int index, int subIndex, int dataCount, char * data); |
ptpaterson | 2:c724ff3a4e4d | 75 | int HandleInitiateDownloadRequest (int sdoNum, int index, int subIndex, int dataCount, char * data); |
ptpaterson | 2:c724ff3a4e4d | 76 | |
ptpaterson | 2:c724ff3a4e4d | 77 | int HandleExpeditedUpload (int sdoNum, int index, int subIndex); |
ptpaterson | 2:c724ff3a4e4d | 78 | |
ptpaterson | 2:c724ff3a4e4d | 79 | |
ptpaterson | 2:c724ff3a4e4d | 80 | // TODO: express and not express |
ptpaterson | 2:c724ff3a4e4d | 81 | |
ptpaterson | 2:c724ff3a4e4d | 82 | /* SYNC object (7.2.5) --------------------------------------------------*/ |
ptpaterson | 2:c724ff3a4e4d | 83 | |
ptpaterson | 2:c724ff3a4e4d | 84 | // TODO: SYNC consumer |
ptpaterson | 2:c724ff3a4e4d | 85 | |
ptpaterson | 2:c724ff3a4e4d | 86 | /* Time Stamp object (7.2.6) --------------------------------------------*/ |
ptpaterson | 2:c724ff3a4e4d | 87 | |
ptpaterson | 2:c724ff3a4e4d | 88 | // TODO: time consumer |
ptpaterson | 2:c724ff3a4e4d | 89 | |
ptpaterson | 2:c724ff3a4e4d | 90 | /* Emergency object (7.2.7) ---------------------------------------------*/ |
ptpaterson | 2:c724ff3a4e4d | 91 | |
ptpaterson | 2:c724ff3a4e4d | 92 | int ConsumeEmergency (void);// TODO: fix params |
ptpaterson | 2:c724ff3a4e4d | 93 | |
ptpaterson | 2:c724ff3a4e4d | 94 | |
ptpaterson | 2:c724ff3a4e4d | 95 | /* Network Management (7.2.8) -------------------------------------------*/ |
ptpaterson | 2:c724ff3a4e4d | 96 | /* ---- Node Control (7.2.8.2.1) ----------------------------------------*/ |
ptpaterson | 2:c724ff3a4e4d | 97 | |
ptpaterson | 2:c724ff3a4e4d | 98 | int HandleNodeControl (void); |
ptpaterson | 2:c724ff3a4e4d | 99 | |
ptpaterson | 2:c724ff3a4e4d | 100 | |
ptpaterson | 2:c724ff3a4e4d | 101 | /* ---- Error Control (7.2.8.2.2) ---------------------------------------*/ |
ptpaterson | 2:c724ff3a4e4d | 102 | |
ptpaterson | 2:c724ff3a4e4d | 103 | int HandleNodeGuardRequest (int masterId); |
ptpaterson | 2:c724ff3a4e4d | 104 | int ConsumeHeartbeat (int producerId); |
ptpaterson | 2:c724ff3a4e4d | 105 | |
ptpaterson | 2:c724ff3a4e4d | 106 | |
ptpaterson | 2:c724ff3a4e4d | 107 | /* ======================================================================== |
ptpaterson | 2:c724ff3a4e4d | 108 | * Methods to handle operation of node device |
ptpaterson | 2:c724ff3a4e4d | 109 | * ======================================================================== |
ptpaterson | 2:c724ff3a4e4d | 110 | */ |
ptpaterson | 2:c724ff3a4e4d | 111 | |
ptpaterson | 2:c724ff3a4e4d | 112 | /** |
ptpaterson | 2:c724ff3a4e4d | 113 | * @note |
ptpaterson | 2:c724ff3a4e4d | 114 | */ |
ptpaterson | 2:c724ff3a4e4d | 115 | // TODO: pass elapsed time to Update method |
ptpaterson | 2:c724ff3a4e4d | 116 | virtual void Update (void); |
ptpaterson | 2:c724ff3a4e4d | 117 | |
ptpaterson | 2:c724ff3a4e4d | 118 | |
ptpaterson | 2:c724ff3a4e4d | 119 | /* ======================================================================== |
ptpaterson | 2:c724ff3a4e4d | 120 | * Public members |
ptpaterson | 2:c724ff3a4e4d | 121 | * ======================================================================== |
ptpaterson | 2:c724ff3a4e4d | 122 | */ |
ptpaterson | 2:c724ff3a4e4d | 123 | |
ptpaterson | 2:c724ff3a4e4d | 124 | /** Network id for the node |
ptpaterson | 2:c724ff3a4e4d | 125 | * @note May need to be a pointer, because node id is held in object dictionary |
ptpaterson | 2:c724ff3a4e4d | 126 | */ |
ptpaterson | 2:c724ff3a4e4d | 127 | int nodeId; |
ptpaterson | 2:c724ff3a4e4d | 128 | |
ptpaterson | 2:c724ff3a4e4d | 129 | /** Network and communication state of the node |
ptpaterson | 2:c724ff3a4e4d | 130 | * @note |
ptpaterson | 2:c724ff3a4e4d | 131 | */ |
ptpaterson | 2:c724ff3a4e4d | 132 | NodeState state; |
ptpaterson | 2:c724ff3a4e4d | 133 | |
ptpaterson | 2:c724ff3a4e4d | 134 | |
ptpaterson | 2:c724ff3a4e4d | 135 | protected: |
ptpaterson | 2:c724ff3a4e4d | 136 | |
ptpaterson | 2:c724ff3a4e4d | 137 | /* ======================================================================== |
ptpaterson | 2:c724ff3a4e4d | 138 | * Methods to implement node control in derived classes |
ptpaterson | 2:c724ff3a4e4d | 139 | * ======================================================================== |
ptpaterson | 2:c724ff3a4e4d | 140 | */ |
ptpaterson | 2:c724ff3a4e4d | 141 | |
ptpaterson | 2:c724ff3a4e4d | 142 | /** Perform actions when node reset |
ptpaterson | 2:c724ff3a4e4d | 143 | * @note Override to implement user application |
ptpaterson | 2:c724ff3a4e4d | 144 | */ |
ptpaterson | 2:c724ff3a4e4d | 145 | virtual void OnInitialize (void); |
ptpaterson | 2:c724ff3a4e4d | 146 | |
ptpaterson | 2:c724ff3a4e4d | 147 | /** Perform actions when state changed to pre-operational |
ptpaterson | 2:c724ff3a4e4d | 148 | * @note Override to implement user application |
ptpaterson | 2:c724ff3a4e4d | 149 | */ |
ptpaterson | 2:c724ff3a4e4d | 150 | virtual void OnPreoperational (void); |
ptpaterson | 2:c724ff3a4e4d | 151 | |
ptpaterson | 2:c724ff3a4e4d | 152 | /** Perform actions when state changed to operational |
ptpaterson | 2:c724ff3a4e4d | 153 | * @note Override to implement user application |
ptpaterson | 2:c724ff3a4e4d | 154 | */ |
ptpaterson | 2:c724ff3a4e4d | 155 | virtual void OnOperational (void); |
ptpaterson | 2:c724ff3a4e4d | 156 | |
ptpaterson | 2:c724ff3a4e4d | 157 | /** Perform actions when state changed to stop |
ptpaterson | 2:c724ff3a4e4d | 158 | * @note Override to implement user application |
ptpaterson | 2:c724ff3a4e4d | 159 | */ |
ptpaterson | 2:c724ff3a4e4d | 160 | virtual void OnStopped (void); |
ptpaterson | 2:c724ff3a4e4d | 161 | |
ptpaterson | 2:c724ff3a4e4d | 162 | |
ptpaterson | 2:c724ff3a4e4d | 163 | /* ======================================================================== |
ptpaterson | 2:c724ff3a4e4d | 164 | * Object Dictionary |
ptpaterson | 2:c724ff3a4e4d | 165 | * ======================================================================== |
ptpaterson | 2:c724ff3a4e4d | 166 | */ |
ptpaterson | 2:c724ff3a4e4d | 167 | |
ptpaterson | 2:c724ff3a4e4d | 168 | /** object dictionary */ |
ptpaterson | 2:c724ff3a4e4d | 169 | ObjectDictionary * pDictionary; |
ptpaterson | 2:c724ff3a4e4d | 170 | |
ptpaterson | 2:c724ff3a4e4d | 171 | private: |
ptpaterson | 2:c724ff3a4e4d | 172 | |
ptpaterson | 2:c724ff3a4e4d | 173 | }; |
ptpaterson | 2:c724ff3a4e4d | 174 | |
ptpaterson | 2:c724ff3a4e4d | 175 | } /* namespace ppCANOpen */ |
ptpaterson | 2:c724ff3a4e4d | 176 | |
ptpaterson | 2:c724ff3a4e4d | 177 | #endif // PPCAN_NODE_H |
ptpaterson | 2:c724ff3a4e4d | 178 |