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.

Committer:
ptpaterson
Date:
Mon Jan 04 06:10:49 2016 +0000
Revision:
3:12b3c25bdeba
Parent:
2:c724ff3a4e4d
Child:
4:2034b04c86d2
Echo communication verified

Who changed what in which revision?

UserRevisionLine numberNew 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>&copy; 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 /** Node Class to implement feature of a CANOpen NMT node
ptpaterson 2:c724ff3a4e4d 42 */
ptpaterson 2:c724ff3a4e4d 43 class Node
ptpaterson 2:c724ff3a4e4d 44 {
ptpaterson 2:c724ff3a4e4d 45 public:
ptpaterson 3:12b3c25bdeba 46
ptpaterson 3:12b3c25bdeba 47 /** Maintain the multitude of states for a node */
ptpaterson 3:12b3c25bdeba 48 typedef struct {
ptpaterson 3:12b3c25bdeba 49 NmtState nmtState;
ptpaterson 3:12b3c25bdeba 50 int bBoot;
ptpaterson 3:12b3c25bdeba 51 int bSDO;
ptpaterson 3:12b3c25bdeba 52 int bEmergency;
ptpaterson 3:12b3c25bdeba 53 int bSYNC;
ptpaterson 3:12b3c25bdeba 54 int bLifeGuard;
ptpaterson 3:12b3c25bdeba 55 int bPDO;
ptpaterson 3:12b3c25bdeba 56 int bLSS;
ptpaterson 3:12b3c25bdeba 57 } State;
ptpaterson 3:12b3c25bdeba 58
ptpaterson 3:12b3c25bdeba 59 Node (ServiceProvider * provider);
ptpaterson 3:12b3c25bdeba 60
ptpaterson 3:12b3c25bdeba 61 /* ========================================================================
ptpaterson 3:12b3c25bdeba 62 * Methods to handle operation of node device
ptpaterson 3:12b3c25bdeba 63 * ========================================================================
ptpaterson 3:12b3c25bdeba 64 */
ptpaterson 3:12b3c25bdeba 65
ptpaterson 3:12b3c25bdeba 66 // TODO: pass elapsed time to Update method
ptpaterson 3:12b3c25bdeba 67 virtual void Update (void);
ptpaterson 2:c724ff3a4e4d 68
ptpaterson 2:c724ff3a4e4d 69 /* ========================================================================
ptpaterson 3:12b3c25bdeba 70 * Message indication
ptpaterson 3:12b3c25bdeba 71 * Called by a ServiceProvider when a message is received.
ptpaterson 3:12b3c25bdeba 72 * ========================================================================
ptpaterson 3:12b3c25bdeba 73 */
ptpaterson 3:12b3c25bdeba 74
ptpaterson 3:12b3c25bdeba 75 /**
ptpaterson 3:12b3c25bdeba 76 * @note
ptpaterson 3:12b3c25bdeba 77 */
ptpaterson 3:12b3c25bdeba 78 int DispatchMessage(CanOpenMessage *canOpenMsg);
ptpaterson 3:12b3c25bdeba 79
ptpaterson 3:12b3c25bdeba 80
ptpaterson 3:12b3c25bdeba 81 protected:
ptpaterson 3:12b3c25bdeba 82
ptpaterson 3:12b3c25bdeba 83 /* ========================================================================
ptpaterson 3:12b3c25bdeba 84 * Methods to handle various messages
ptpaterson 2:c724ff3a4e4d 85 * Called by a ServiceProvider when a message is received.
ptpaterson 2:c724ff3a4e4d 86 * ========================================================================
ptpaterson 2:c724ff3a4e4d 87 */
ptpaterson 2:c724ff3a4e4d 88
ptpaterson 2:c724ff3a4e4d 89 /* PDO (7.2.2), MPDO (7.2.3) --------------------------------------------*/
ptpaterson 2:c724ff3a4e4d 90
ptpaterson 2:c724ff3a4e4d 91 int ConsumePdo (int pdoNum, char * dataIn);
ptpaterson 2:c724ff3a4e4d 92 int HandlePdoReadRequest (int pdoNum);
ptpaterson 2:c724ff3a4e4d 93
ptpaterson 2:c724ff3a4e4d 94
ptpaterson 2:c724ff3a4e4d 95 /* SDO (7.2.4) ----------------------------------------------------------*/
ptpaterson 2:c724ff3a4e4d 96
ptpaterson 2:c724ff3a4e4d 97 int HandleExpeditedDownload (int sdoNum, int index, int subIndex, int dataCount, char * data);
ptpaterson 2:c724ff3a4e4d 98 int HandleInitiateDownloadRequest (int sdoNum, int index, int subIndex, int dataCount, char * data);
ptpaterson 2:c724ff3a4e4d 99
ptpaterson 2:c724ff3a4e4d 100 int HandleExpeditedUpload (int sdoNum, int index, int subIndex);
ptpaterson 2:c724ff3a4e4d 101
ptpaterson 2:c724ff3a4e4d 102
ptpaterson 2:c724ff3a4e4d 103 // TODO: express and not express
ptpaterson 2:c724ff3a4e4d 104
ptpaterson 2:c724ff3a4e4d 105 /* SYNC object (7.2.5) --------------------------------------------------*/
ptpaterson 2:c724ff3a4e4d 106
ptpaterson 2:c724ff3a4e4d 107 // TODO: SYNC consumer
ptpaterson 2:c724ff3a4e4d 108
ptpaterson 2:c724ff3a4e4d 109 /* Time Stamp object (7.2.6) --------------------------------------------*/
ptpaterson 2:c724ff3a4e4d 110
ptpaterson 2:c724ff3a4e4d 111 // TODO: time consumer
ptpaterson 2:c724ff3a4e4d 112
ptpaterson 2:c724ff3a4e4d 113 /* Emergency object (7.2.7) ---------------------------------------------*/
ptpaterson 2:c724ff3a4e4d 114
ptpaterson 2:c724ff3a4e4d 115 int ConsumeEmergency (void);// TODO: fix params
ptpaterson 2:c724ff3a4e4d 116
ptpaterson 2:c724ff3a4e4d 117
ptpaterson 2:c724ff3a4e4d 118 /* Network Management (7.2.8) -------------------------------------------*/
ptpaterson 2:c724ff3a4e4d 119 /* ---- Node Control (7.2.8.2.1) ----------------------------------------*/
ptpaterson 3:12b3c25bdeba 120 int HandleNodeControl (int commandSpecifier);
ptpaterson 2:c724ff3a4e4d 121
ptpaterson 2:c724ff3a4e4d 122
ptpaterson 2:c724ff3a4e4d 123 /* ---- Error Control (7.2.8.2.2) ---------------------------------------*/
ptpaterson 2:c724ff3a4e4d 124
ptpaterson 2:c724ff3a4e4d 125 int HandleNodeGuardRequest (int masterId);
ptpaterson 2:c724ff3a4e4d 126 int ConsumeHeartbeat (int producerId);
ptpaterson 2:c724ff3a4e4d 127
ptpaterson 2:c724ff3a4e4d 128
ptpaterson 2:c724ff3a4e4d 129 /* ========================================================================
ptpaterson 3:12b3c25bdeba 130 * Methods to implement node control in derived classes
ptpaterson 2:c724ff3a4e4d 131 * ========================================================================
ptpaterson 2:c724ff3a4e4d 132 */
ptpaterson 3:12b3c25bdeba 133
ptpaterson 3:12b3c25bdeba 134 /** Perform actions every cycle
ptpaterson 3:12b3c25bdeba 135 * @note Override to implement user application
ptpaterson 3:12b3c25bdeba 136 */
ptpaterson 3:12b3c25bdeba 137 virtual void OnUpdate(void) = 0;
ptpaterson 2:c724ff3a4e4d 138
ptpaterson 3:12b3c25bdeba 139 /** Perform actions when node reset
ptpaterson 3:12b3c25bdeba 140 * @note Override to implement user application
ptpaterson 3:12b3c25bdeba 141 */
ptpaterson 3:12b3c25bdeba 142 virtual void OnInitialize (void) = 0;
ptpaterson 3:12b3c25bdeba 143
ptpaterson 3:12b3c25bdeba 144 /** Perform actions when state changed to pre-operational
ptpaterson 3:12b3c25bdeba 145 * @note Override to implement user application
ptpaterson 3:12b3c25bdeba 146 */
ptpaterson 3:12b3c25bdeba 147 virtual void OnPreoperational (void) = 0;
ptpaterson 2:c724ff3a4e4d 148
ptpaterson 3:12b3c25bdeba 149 /** Perform actions when state changed to operational
ptpaterson 3:12b3c25bdeba 150 * @note Override to implement user application
ptpaterson 3:12b3c25bdeba 151 */
ptpaterson 3:12b3c25bdeba 152 virtual void OnOperational (void) = 0;
ptpaterson 3:12b3c25bdeba 153
ptpaterson 3:12b3c25bdeba 154 /** Perform actions when state changed to stop
ptpaterson 3:12b3c25bdeba 155 * @note Override to implement user application
ptpaterson 3:12b3c25bdeba 156 */
ptpaterson 3:12b3c25bdeba 157 virtual void OnStopped (void) = 0;
ptpaterson 2:c724ff3a4e4d 158
ptpaterson 2:c724ff3a4e4d 159 /* ========================================================================
ptpaterson 3:12b3c25bdeba 160 * Protected Members
ptpaterson 3:12b3c25bdeba 161 * ========================================================================
ptpaterson 3:12b3c25bdeba 162 */
ptpaterson 3:12b3c25bdeba 163
ptpaterson 3:12b3c25bdeba 164 ServiceProvider * pMyProvider;
ptpaterson 3:12b3c25bdeba 165
ptpaterson 3:12b3c25bdeba 166 /** object dictionary */
ptpaterson 3:12b3c25bdeba 167 ObjectDictionary * pMyDictionary;
ptpaterson 3:12b3c25bdeba 168
ptpaterson 3:12b3c25bdeba 169 private:
ptpaterson 3:12b3c25bdeba 170
ptpaterson 3:12b3c25bdeba 171 /* ========================================================================
ptpaterson 3:12b3c25bdeba 172 * Private members
ptpaterson 2:c724ff3a4e4d 173 * ========================================================================
ptpaterson 2:c724ff3a4e4d 174 */
ptpaterson 2:c724ff3a4e4d 175
ptpaterson 2:c724ff3a4e4d 176 /** Network id for the node
ptpaterson 2:c724ff3a4e4d 177 * @note May need to be a pointer, because node id is held in object dictionary
ptpaterson 2:c724ff3a4e4d 178 */
ptpaterson 2:c724ff3a4e4d 179 int nodeId;
ptpaterson 2:c724ff3a4e4d 180
ptpaterson 2:c724ff3a4e4d 181 /** Network and communication state of the node
ptpaterson 2:c724ff3a4e4d 182 * @note
ptpaterson 2:c724ff3a4e4d 183 */
ptpaterson 3:12b3c25bdeba 184 State state;
ptpaterson 2:c724ff3a4e4d 185 };
ptpaterson 2:c724ff3a4e4d 186
ptpaterson 2:c724ff3a4e4d 187 } /* namespace ppCANOpen */
ptpaterson 2:c724ff3a4e4d 188
ptpaterson 2:c724ff3a4e4d 189 #endif // PPCAN_NODE_H
ptpaterson 2:c724ff3a4e4d 190