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/ServiceProvider.h@3:12b3c25bdeba, 2016-01-04 (annotated)
- 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?
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-22 |
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_SERVICE_PROVIDER_H |
ptpaterson | 2:c724ff3a4e4d | 30 | #define PPCAN_SERVICE_PROVIDER_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 Node; |
ptpaterson | 2:c724ff3a4e4d | 39 | |
ptpaterson | 2:c724ff3a4e4d | 40 | /** Node Class to implement feature of a CANOpen NMT node |
ptpaterson | 2:c724ff3a4e4d | 41 | */ |
ptpaterson | 2:c724ff3a4e4d | 42 | class ServiceProvider |
ptpaterson | 2:c724ff3a4e4d | 43 | { |
ptpaterson | 2:c724ff3a4e4d | 44 | public: |
ptpaterson | 2:c724ff3a4e4d | 45 | |
ptpaterson | 2:c724ff3a4e4d | 46 | ServiceProvider (void); |
ptpaterson | 3:12b3c25bdeba | 47 | ~ServiceProvider (void); |
ptpaterson | 2:c724ff3a4e4d | 48 | |
ptpaterson | 2:c724ff3a4e4d | 49 | /** Main loop |
ptpaterson | 2:c724ff3a4e4d | 50 | * @note |
ptpaterson | 2:c724ff3a4e4d | 51 | * @param |
ptpaterson | 2:c724ff3a4e4d | 52 | * @retval |
ptpaterson | 2:c724ff3a4e4d | 53 | */ |
ptpaterson | 2:c724ff3a4e4d | 54 | void Run (void); |
ptpaterson | 2:c724ff3a4e4d | 55 | |
ptpaterson | 2:c724ff3a4e4d | 56 | /** |
ptpaterson | 2:c724ff3a4e4d | 57 | * @note |
ptpaterson | 2:c724ff3a4e4d | 58 | * @param |
ptpaterson | 2:c724ff3a4e4d | 59 | * @retval |
ptpaterson | 2:c724ff3a4e4d | 60 | */ |
ptpaterson | 2:c724ff3a4e4d | 61 | int AddNode (Node * node); |
ptpaterson | 2:c724ff3a4e4d | 62 | |
ptpaterson | 2:c724ff3a4e4d | 63 | // TODO: remove node (swap pointers to fill in nicely |
ptpaterson | 2:c724ff3a4e4d | 64 | private: |
ptpaterson | 2:c724ff3a4e4d | 65 | |
ptpaterson | 2:c724ff3a4e4d | 66 | static const int SERVICE_MAX_NODES = 8; |
ptpaterson | 2:c724ff3a4e4d | 67 | |
ptpaterson | 2:c724ff3a4e4d | 68 | /* ======================================================================== |
ptpaterson | 2:c724ff3a4e4d | 69 | * Methods to handle message requests and responses |
ptpaterson | 2:c724ff3a4e4d | 70 | * Called by the node, usually during Update() or during handling of |
ptpaterson | 2:c724ff3a4e4d | 71 | * incoming messages. |
ptpaterson | 2:c724ff3a4e4d | 72 | * ======================================================================== |
ptpaterson | 2:c724ff3a4e4d | 73 | */ |
ptpaterson | 2:c724ff3a4e4d | 74 | |
ptpaterson | 2:c724ff3a4e4d | 75 | /* PDO (7.2.2), MPDO (7.2.3) --------------------------------------------*/ |
ptpaterson | 2:c724ff3a4e4d | 76 | |
ptpaterson | 2:c724ff3a4e4d | 77 | /** Build and send a PDO request |
ptpaterson | 2:c724ff3a4e4d | 78 | * @note |
ptpaterson | 2:c724ff3a4e4d | 79 | * @param |
ptpaterson | 2:c724ff3a4e4d | 80 | */ |
ptpaterson | 2:c724ff3a4e4d | 81 | void RequestPdo (int pdoNum); |
ptpaterson | 2:c724ff3a4e4d | 82 | |
ptpaterson | 2:c724ff3a4e4d | 83 | /** Build and send a PDO |
ptpaterson | 2:c724ff3a4e4d | 84 | * @note |
ptpaterson | 2:c724ff3a4e4d | 85 | * @param |
ptpaterson | 2:c724ff3a4e4d | 86 | */ |
ptpaterson | 2:c724ff3a4e4d | 87 | void ProducePdo (int pdoNum, char * data); |
ptpaterson | 2:c724ff3a4e4d | 88 | |
ptpaterson | 2:c724ff3a4e4d | 89 | |
ptpaterson | 2:c724ff3a4e4d | 90 | /* SDO (7.2.4) ----------------------------------------------------------*/ |
ptpaterson | 2:c724ff3a4e4d | 91 | |
ptpaterson | 2:c724ff3a4e4d | 92 | /** initiate SDO download |
ptpaterson | 2:c724ff3a4e4d | 93 | * @note Handles automatically whether it will be a expedited transfer or |
ptpaterson | 2:c724ff3a4e4d | 94 | * or if message will be split into |
ptpaterson | 2:c724ff3a4e4d | 95 | * @param |
ptpaterson | 2:c724ff3a4e4d | 96 | * |
ptpaterson | 2:c724ff3a4e4d | 97 | * Node will create a big data array and Service provide will have to |
ptpaterson | 2:c724ff3a4e4d | 98 | * iterate through and send all of the data. ServiceProvider will pass |
ptpaterson | 2:c724ff3a4e4d | 99 | * the confirmation to the node, and the node will free up it's buffer. |
ptpaterson | 2:c724ff3a4e4d | 100 | */ |
ptpaterson | 2:c724ff3a4e4d | 101 | void DownloadSdo (int sdoNum, int index, int subindex, int size, char * data); |
ptpaterson | 2:c724ff3a4e4d | 102 | |
ptpaterson | 2:c724ff3a4e4d | 103 | /** initiate SDO upload |
ptpaterson | 2:c724ff3a4e4d | 104 | * @note |
ptpaterson | 2:c724ff3a4e4d | 105 | * @param |
ptpaterson | 2:c724ff3a4e4d | 106 | */ |
ptpaterson | 2:c724ff3a4e4d | 107 | void UploadSdo (int sdoNum, int index, int subindex); |
ptpaterson | 2:c724ff3a4e4d | 108 | |
ptpaterson | 2:c724ff3a4e4d | 109 | /** Acknowledge that SDO was recieved properly |
ptpaterson | 2:c724ff3a4e4d | 110 | * @note |
ptpaterson | 2:c724ff3a4e4d | 111 | * @param |
ptpaterson | 2:c724ff3a4e4d | 112 | */ |
ptpaterson | 2:c724ff3a4e4d | 113 | void ConfirmSdo (int sdoNum, int bSuccess); |
ptpaterson | 2:c724ff3a4e4d | 114 | |
ptpaterson | 2:c724ff3a4e4d | 115 | /** Abort current SDO transfer |
ptpaterson | 2:c724ff3a4e4d | 116 | * @note |
ptpaterson | 2:c724ff3a4e4d | 117 | * @param |
ptpaterson | 2:c724ff3a4e4d | 118 | */ |
ptpaterson | 2:c724ff3a4e4d | 119 | void AbortSdo (int sdoNum); |
ptpaterson | 2:c724ff3a4e4d | 120 | |
ptpaterson | 2:c724ff3a4e4d | 121 | |
ptpaterson | 2:c724ff3a4e4d | 122 | /* Emergency object (7.2.7) ---------------------------------------------*/ |
ptpaterson | 2:c724ff3a4e4d | 123 | |
ptpaterson | 2:c724ff3a4e4d | 124 | // TODO: emergency producer |
ptpaterson | 2:c724ff3a4e4d | 125 | |
ptpaterson | 2:c724ff3a4e4d | 126 | |
ptpaterson | 2:c724ff3a4e4d | 127 | /* Network Management (7.2.8) -------------------------------------------*/ |
ptpaterson | 2:c724ff3a4e4d | 128 | /* ---- Node Control (7.2.8.2.1) ----------------------------------------*/ |
ptpaterson | 2:c724ff3a4e4d | 129 | |
ptpaterson | 2:c724ff3a4e4d | 130 | /** Build a CANOpen nmt control message to a node |
ptpaterson | 2:c724ff3a4e4d | 131 | * @note |
ptpaterson | 2:c724ff3a4e4d | 132 | * @param |
ptpaterson | 2:c724ff3a4e4d | 133 | */ |
ptpaterson | 2:c724ff3a4e4d | 134 | int SendNodeControl (NmtCommandSpecifier cs, unsigned int nodeId); |
ptpaterson | 2:c724ff3a4e4d | 135 | |
ptpaterson | 2:c724ff3a4e4d | 136 | |
ptpaterson | 2:c724ff3a4e4d | 137 | /* ---- Error Control (7.2.8.2.2) ---------------------------------------*/ |
ptpaterson | 2:c724ff3a4e4d | 138 | |
ptpaterson | 2:c724ff3a4e4d | 139 | /** Build a CANOpen error control request to a node |
ptpaterson | 2:c724ff3a4e4d | 140 | * @note |
ptpaterson | 2:c724ff3a4e4d | 141 | * @param |
ptpaterson | 2:c724ff3a4e4d | 142 | */ |
ptpaterson | 2:c724ff3a4e4d | 143 | int RequestErrorControl (NmtCommandSpecifier cs, unsigned int nodeId); |
ptpaterson | 2:c724ff3a4e4d | 144 | |
ptpaterson | 2:c724ff3a4e4d | 145 | /** Build a CANOpen error control response |
ptpaterson | 2:c724ff3a4e4d | 146 | * @note |
ptpaterson | 2:c724ff3a4e4d | 147 | * @param |
ptpaterson | 2:c724ff3a4e4d | 148 | */ |
ptpaterson | 2:c724ff3a4e4d | 149 | int RespondErrorControl (NmtCommandSpecifier cs, unsigned int nodeId); |
ptpaterson | 2:c724ff3a4e4d | 150 | |
ptpaterson | 2:c724ff3a4e4d | 151 | |
ptpaterson | 2:c724ff3a4e4d | 152 | /* ======================================================================== |
ptpaterson | 2:c724ff3a4e4d | 153 | * Private Members |
ptpaterson | 2:c724ff3a4e4d | 154 | * ======================================================================== |
ptpaterson | 2:c724ff3a4e4d | 155 | */ |
ptpaterson | 2:c724ff3a4e4d | 156 | |
ptpaterson | 2:c724ff3a4e4d | 157 | /** array of nodes to cycle through. |
ptpaterson | 2:c724ff3a4e4d | 158 | * @note |
ptpaterson | 2:c724ff3a4e4d | 159 | */ |
ptpaterson | 2:c724ff3a4e4d | 160 | Node * nodes[SERVICE_MAX_NODES]; |
ptpaterson | 2:c724ff3a4e4d | 161 | |
ptpaterson | 2:c724ff3a4e4d | 162 | /** Keeps count of current number of nodes. |
ptpaterson | 2:c724ff3a4e4d | 163 | * @note |
ptpaterson | 2:c724ff3a4e4d | 164 | */ |
ptpaterson | 2:c724ff3a4e4d | 165 | int nodeCount; |
ptpaterson | 3:12b3c25bdeba | 166 | |
ptpaterson | 3:12b3c25bdeba | 167 | /** stores handle for can open api */ |
ptpaterson | 3:12b3c25bdeba | 168 | CanOpenHandle * hCanOpen; |
ptpaterson | 2:c724ff3a4e4d | 169 | |
ptpaterson | 2:c724ff3a4e4d | 170 | }; |
ptpaterson | 2:c724ff3a4e4d | 171 | |
ptpaterson | 2:c724ff3a4e4d | 172 | } /* namspace ppCANOpen */ |
ptpaterson | 2:c724ff3a4e4d | 173 | |
ptpaterson | 2:c724ff3a4e4d | 174 | #endif /* PPCAN_SERVICE_PROVIDER_H */ |
ptpaterson | 2:c724ff3a4e4d | 175 |