![](/media/cache/profiles/IMG_2753.JPG.50x50_q85.jpg)
Can_open_masternode
framework/include/sdo.h@0:9dd7c6129683, 2011-05-30 (annotated)
- Committer:
- sam_grove
- Date:
- Mon May 30 07:36:47 2011 +0000
- Revision:
- 0:9dd7c6129683
Initial public release of master node example
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove |
0:9dd7c6129683 | 1 | /* |
sam_grove |
0:9dd7c6129683 | 2 | This file is part of CanFestival, a library implementing CanOpen Stack. |
sam_grove |
0:9dd7c6129683 | 3 | |
sam_grove |
0:9dd7c6129683 | 4 | Copyright (C): Edouard TISSERANT and Francis DUPIN |
sam_grove |
0:9dd7c6129683 | 5 | |
sam_grove |
0:9dd7c6129683 | 6 | See COPYING file for copyrights details. |
sam_grove |
0:9dd7c6129683 | 7 | |
sam_grove |
0:9dd7c6129683 | 8 | This library is free software; you can redistribute it and/or |
sam_grove |
0:9dd7c6129683 | 9 | modify it under the terms of the GNU Lesser General Public |
sam_grove |
0:9dd7c6129683 | 10 | License as published by the Free Software Foundation; either |
sam_grove |
0:9dd7c6129683 | 11 | version 2.1 of the License, or (at your option) any later version. |
sam_grove |
0:9dd7c6129683 | 12 | |
sam_grove |
0:9dd7c6129683 | 13 | This library is distributed in the hope that it will be useful, |
sam_grove |
0:9dd7c6129683 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
sam_grove |
0:9dd7c6129683 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
sam_grove |
0:9dd7c6129683 | 16 | Lesser General Public License for more details. |
sam_grove |
0:9dd7c6129683 | 17 | |
sam_grove |
0:9dd7c6129683 | 18 | You should have received a copy of the GNU Lesser General Public |
sam_grove |
0:9dd7c6129683 | 19 | License along with this library; if not, write to the Free Software |
sam_grove |
0:9dd7c6129683 | 20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
sam_grove |
0:9dd7c6129683 | 21 | */ |
sam_grove |
0:9dd7c6129683 | 22 | |
sam_grove |
0:9dd7c6129683 | 23 | /** @defgroup comobj Communication Objects |
sam_grove |
0:9dd7c6129683 | 24 | * @ingroup userapi |
sam_grove |
0:9dd7c6129683 | 25 | */ |
sam_grove |
0:9dd7c6129683 | 26 | |
sam_grove |
0:9dd7c6129683 | 27 | /** @defgroup sdo Service Data Object (SDO) |
sam_grove |
0:9dd7c6129683 | 28 | * SDOs provide the access to entries in the CANopen Object Dictionary. |
sam_grove |
0:9dd7c6129683 | 29 | * An SDO is made up of at least two CAN messages with different identifiers. |
sam_grove |
0:9dd7c6129683 | 30 | * SDO s are always confirmed point-to-point communications services. |
sam_grove |
0:9dd7c6129683 | 31 | * @ingroup comobj |
sam_grove |
0:9dd7c6129683 | 32 | */ |
sam_grove |
0:9dd7c6129683 | 33 | |
sam_grove |
0:9dd7c6129683 | 34 | #ifndef __sdo_h__ |
sam_grove |
0:9dd7c6129683 | 35 | #define __sdo_h__ |
sam_grove |
0:9dd7c6129683 | 36 | |
sam_grove |
0:9dd7c6129683 | 37 | struct struct_s_transfer; |
sam_grove |
0:9dd7c6129683 | 38 | |
sam_grove |
0:9dd7c6129683 | 39 | #include "canopen_timer.h" |
sam_grove |
0:9dd7c6129683 | 40 | |
sam_grove |
0:9dd7c6129683 | 41 | typedef void (*SDOCallback_t)(CO_Data* d, UNS8 nodeId); |
sam_grove |
0:9dd7c6129683 | 42 | |
sam_grove |
0:9dd7c6129683 | 43 | /* The Transfer structure |
sam_grove |
0:9dd7c6129683 | 44 | Used to store the different segments of |
sam_grove |
0:9dd7c6129683 | 45 | - a SDO received before writing in the dictionary |
sam_grove |
0:9dd7c6129683 | 46 | - the reading of the dictionary to put on a SDO to transmit |
sam_grove |
0:9dd7c6129683 | 47 | */ |
sam_grove |
0:9dd7c6129683 | 48 | |
sam_grove |
0:9dd7c6129683 | 49 | struct struct_s_transfer { |
sam_grove |
0:9dd7c6129683 | 50 | UNS8 nodeId; /**<own ID if server, or node ID of the server if client */ |
sam_grove |
0:9dd7c6129683 | 51 | |
sam_grove |
0:9dd7c6129683 | 52 | UNS8 whoami; /**< Takes the values SDO_CLIENT or SDO_SERVER */ |
sam_grove |
0:9dd7c6129683 | 53 | UNS8 state; /**< state of the transmission : Takes the values SDO_... */ |
sam_grove |
0:9dd7c6129683 | 54 | UNS8 toggle; |
sam_grove |
0:9dd7c6129683 | 55 | UNS32 abortCode; /**< Sent or received */ |
sam_grove |
0:9dd7c6129683 | 56 | /**< index and subindex of the dictionary where to store */ |
sam_grove |
0:9dd7c6129683 | 57 | /**< (for a received SDO) or to read (for a transmit SDO) */ |
sam_grove |
0:9dd7c6129683 | 58 | UNS16 index; |
sam_grove |
0:9dd7c6129683 | 59 | UNS8 subIndex; |
sam_grove |
0:9dd7c6129683 | 60 | UNS32 count; /**< Number of data received or to be sent. */ |
sam_grove |
0:9dd7c6129683 | 61 | UNS32 offset; /**< stack pointer of data[] |
sam_grove |
0:9dd7c6129683 | 62 | * Used only to tranfer part of a line to or from a SDO. |
sam_grove |
0:9dd7c6129683 | 63 | * offset is always pointing on the next free cell of data[]. |
sam_grove |
0:9dd7c6129683 | 64 | * WARNING s_transfer.data is subject to ENDIANISATION |
sam_grove |
0:9dd7c6129683 | 65 | * (with respect to CANOPEN_BIG_ENDIAN) |
sam_grove |
0:9dd7c6129683 | 66 | */ |
sam_grove |
0:9dd7c6129683 | 67 | UNS8 data [SDO_MAX_LENGTH_TRANSFERT]; |
sam_grove |
0:9dd7c6129683 | 68 | #ifdef SDO_DYNAMIC_BUFFER_ALLOCATION |
sam_grove |
0:9dd7c6129683 | 69 | UNS8 *dynamicData; |
sam_grove |
0:9dd7c6129683 | 70 | UNS32 dynamicDataSize; |
sam_grove |
0:9dd7c6129683 | 71 | #endif //SDO_DYNAMIC_BUFFER_ALLOCATION |
sam_grove |
0:9dd7c6129683 | 72 | UNS8 dataType; /**< Defined in objdictdef.h Value is visible_string |
sam_grove |
0:9dd7c6129683 | 73 | * if it is a string, any other value if it is not a string, |
sam_grove |
0:9dd7c6129683 | 74 | * like 0. In fact, it is used only if client. |
sam_grove |
0:9dd7c6129683 | 75 | */ |
sam_grove |
0:9dd7c6129683 | 76 | TIMER_HANDLE timer; /**< Time counter to implement a timeout in milliseconds. |
sam_grove |
0:9dd7c6129683 | 77 | * It is automatically incremented whenever |
sam_grove |
0:9dd7c6129683 | 78 | * the line state is in SDO_DOWNLOAD_IN_PROGRESS or |
sam_grove |
0:9dd7c6129683 | 79 | * SDO_UPLOAD_IN_PROGRESS, and reseted to 0 |
sam_grove |
0:9dd7c6129683 | 80 | * when the response SDO have been received. |
sam_grove |
0:9dd7c6129683 | 81 | */ |
sam_grove |
0:9dd7c6129683 | 82 | SDOCallback_t Callback; /**< The user callback func to be called at SDO transaction end */ |
sam_grove |
0:9dd7c6129683 | 83 | }; |
sam_grove |
0:9dd7c6129683 | 84 | typedef struct struct_s_transfer s_transfer; |
sam_grove |
0:9dd7c6129683 | 85 | |
sam_grove |
0:9dd7c6129683 | 86 | |
sam_grove |
0:9dd7c6129683 | 87 | #include "data.h" |
sam_grove |
0:9dd7c6129683 | 88 | |
sam_grove |
0:9dd7c6129683 | 89 | |
sam_grove |
0:9dd7c6129683 | 90 | struct BODY{ |
sam_grove |
0:9dd7c6129683 | 91 | UNS8 data[8]; /**< The 8 bytes data of the SDO */ |
sam_grove |
0:9dd7c6129683 | 92 | }; |
sam_grove |
0:9dd7c6129683 | 93 | |
sam_grove |
0:9dd7c6129683 | 94 | /* The SDO structure ...*/ |
sam_grove |
0:9dd7c6129683 | 95 | struct struct_s_SDO { |
sam_grove |
0:9dd7c6129683 | 96 | UNS8 nodeId; /**< In any case, Node ID of the server (case sender or receiver).*/ |
sam_grove |
0:9dd7c6129683 | 97 | struct BODY body; |
sam_grove |
0:9dd7c6129683 | 98 | }; |
sam_grove |
0:9dd7c6129683 | 99 | |
sam_grove |
0:9dd7c6129683 | 100 | |
sam_grove |
0:9dd7c6129683 | 101 | typedef struct struct_s_SDO s_SDO; |
sam_grove |
0:9dd7c6129683 | 102 | |
sam_grove |
0:9dd7c6129683 | 103 | /*! |
sam_grove |
0:9dd7c6129683 | 104 | ** Called by writeNetworkDict |
sam_grove |
0:9dd7c6129683 | 105 | ** |
sam_grove |
0:9dd7c6129683 | 106 | ** @param d |
sam_grove |
0:9dd7c6129683 | 107 | ** @param nodeId |
sam_grove |
0:9dd7c6129683 | 108 | ** @param index |
sam_grove |
0:9dd7c6129683 | 109 | ** @param subIndex |
sam_grove |
0:9dd7c6129683 | 110 | ** @param count |
sam_grove |
0:9dd7c6129683 | 111 | ** @param dataType |
sam_grove |
0:9dd7c6129683 | 112 | ** @param data |
sam_grove |
0:9dd7c6129683 | 113 | ** @param Callback |
sam_grove |
0:9dd7c6129683 | 114 | ** @param endianize |
sam_grove |
0:9dd7c6129683 | 115 | ** |
sam_grove |
0:9dd7c6129683 | 116 | ** @return |
sam_grove |
0:9dd7c6129683 | 117 | **/ |
sam_grove |
0:9dd7c6129683 | 118 | UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, |
sam_grove |
0:9dd7c6129683 | 119 | UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize); |
sam_grove |
0:9dd7c6129683 | 120 | |
sam_grove |
0:9dd7c6129683 | 121 | /** |
sam_grove |
0:9dd7c6129683 | 122 | * @brief Reset of a SDO exchange on timeout. |
sam_grove |
0:9dd7c6129683 | 123 | * Send a SDO abort. |
sam_grove |
0:9dd7c6129683 | 124 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 125 | * @param id |
sam_grove |
0:9dd7c6129683 | 126 | */ |
sam_grove |
0:9dd7c6129683 | 127 | void SDOTimeoutAlarm(CO_Data* d, UNS32 id); |
sam_grove |
0:9dd7c6129683 | 128 | |
sam_grove |
0:9dd7c6129683 | 129 | /** |
sam_grove |
0:9dd7c6129683 | 130 | * @brief Reset all SDO buffers. |
sam_grove |
0:9dd7c6129683 | 131 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 132 | */ |
sam_grove |
0:9dd7c6129683 | 133 | void resetSDO (CO_Data* d); |
sam_grove |
0:9dd7c6129683 | 134 | |
sam_grove |
0:9dd7c6129683 | 135 | |
sam_grove |
0:9dd7c6129683 | 136 | /** |
sam_grove |
0:9dd7c6129683 | 137 | * @brief Copy the data received from the SDO line transfert to the object dictionary. |
sam_grove |
0:9dd7c6129683 | 138 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 139 | * @param line SDO line |
sam_grove |
0:9dd7c6129683 | 140 | * @return SDO error code if error. Else, returns 0. |
sam_grove |
0:9dd7c6129683 | 141 | */ |
sam_grove |
0:9dd7c6129683 | 142 | UNS32 SDOlineToObjdict (CO_Data* d, UNS8 line); |
sam_grove |
0:9dd7c6129683 | 143 | |
sam_grove |
0:9dd7c6129683 | 144 | /** |
sam_grove |
0:9dd7c6129683 | 145 | * @brief Copy the data from the object dictionary to the SDO line for a network transfert. |
sam_grove |
0:9dd7c6129683 | 146 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 147 | * @param line SDO line |
sam_grove |
0:9dd7c6129683 | 148 | * @return SDO error code if error. Else, returns 0. |
sam_grove |
0:9dd7c6129683 | 149 | */ |
sam_grove |
0:9dd7c6129683 | 150 | UNS32 objdictToSDOline (CO_Data* d, UNS8 line); |
sam_grove |
0:9dd7c6129683 | 151 | |
sam_grove |
0:9dd7c6129683 | 152 | /** |
sam_grove |
0:9dd7c6129683 | 153 | * @brief Copy data from an existant line in the argument "* data" |
sam_grove |
0:9dd7c6129683 | 154 | * @param d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 155 | * @param line SDO line |
sam_grove |
0:9dd7c6129683 | 156 | * @param nbBytes |
sam_grove |
0:9dd7c6129683 | 157 | * @param *data Pointer on the data |
sam_grove |
0:9dd7c6129683 | 158 | * @return 0xFF if error. Else, returns 0. |
sam_grove |
0:9dd7c6129683 | 159 | */ |
sam_grove |
0:9dd7c6129683 | 160 | UNS8 lineToSDO (CO_Data* d, UNS8 line, UNS32 nbBytes, UNS8 * data); |
sam_grove |
0:9dd7c6129683 | 161 | |
sam_grove |
0:9dd7c6129683 | 162 | /** |
sam_grove |
0:9dd7c6129683 | 163 | * @brief Add data to an existant line |
sam_grove |
0:9dd7c6129683 | 164 | * @param d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 165 | * @param line SDO line |
sam_grove |
0:9dd7c6129683 | 166 | * @param nbBytes |
sam_grove |
0:9dd7c6129683 | 167 | * @param *data Pointer on the data |
sam_grove |
0:9dd7c6129683 | 168 | * @return 0xFF if error. Else, returns 0. |
sam_grove |
0:9dd7c6129683 | 169 | */ |
sam_grove |
0:9dd7c6129683 | 170 | UNS8 SDOtoLine (CO_Data* d, UNS8 line, UNS32 nbBytes, UNS8 * data); |
sam_grove |
0:9dd7c6129683 | 171 | |
sam_grove |
0:9dd7c6129683 | 172 | /** |
sam_grove |
0:9dd7c6129683 | 173 | * @brief Called when an internal SDO abort occurs. |
sam_grove |
0:9dd7c6129683 | 174 | * Release the line * Only if server * |
sam_grove |
0:9dd7c6129683 | 175 | * If client, the line must be released manually in the core application. |
sam_grove |
0:9dd7c6129683 | 176 | * The reason of that is to permit the program to read the transfers structure before its reset, |
sam_grove |
0:9dd7c6129683 | 177 | * because many informations are stored on it : index, subindex, data received or trasmited, ... |
sam_grove |
0:9dd7c6129683 | 178 | * In all cases, sends a SDO abort. |
sam_grove |
0:9dd7c6129683 | 179 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 180 | * @param nodeId |
sam_grove |
0:9dd7c6129683 | 181 | * @param whoami |
sam_grove |
0:9dd7c6129683 | 182 | * @param index |
sam_grove |
0:9dd7c6129683 | 183 | * @param subIndex |
sam_grove |
0:9dd7c6129683 | 184 | * @param abortCode |
sam_grove |
0:9dd7c6129683 | 185 | * @return 0 |
sam_grove |
0:9dd7c6129683 | 186 | */ |
sam_grove |
0:9dd7c6129683 | 187 | UNS8 failedSDO (CO_Data* d, UNS8 nodeId, UNS8 whoami, UNS16 index, UNS8 subIndex, UNS32 abortCode); |
sam_grove |
0:9dd7c6129683 | 188 | |
sam_grove |
0:9dd7c6129683 | 189 | /** |
sam_grove |
0:9dd7c6129683 | 190 | * @brief Reset an unused line. |
sam_grove |
0:9dd7c6129683 | 191 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 192 | * @param line SDO line |
sam_grove |
0:9dd7c6129683 | 193 | */ |
sam_grove |
0:9dd7c6129683 | 194 | void resetSDOline (CO_Data* d, UNS8 line); |
sam_grove |
0:9dd7c6129683 | 195 | |
sam_grove |
0:9dd7c6129683 | 196 | /** |
sam_grove |
0:9dd7c6129683 | 197 | * @brief Initialize some fields of the structure. |
sam_grove |
0:9dd7c6129683 | 198 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 199 | * @param line |
sam_grove |
0:9dd7c6129683 | 200 | * @param nodeId |
sam_grove |
0:9dd7c6129683 | 201 | * @param index |
sam_grove |
0:9dd7c6129683 | 202 | * @param subIndex |
sam_grove |
0:9dd7c6129683 | 203 | * @param state |
sam_grove |
0:9dd7c6129683 | 204 | * @return 0 |
sam_grove |
0:9dd7c6129683 | 205 | */ |
sam_grove |
0:9dd7c6129683 | 206 | UNS8 initSDOline (CO_Data* d, UNS8 line, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 state); |
sam_grove |
0:9dd7c6129683 | 207 | |
sam_grove |
0:9dd7c6129683 | 208 | /** |
sam_grove |
0:9dd7c6129683 | 209 | * @brief Search for an unused line in the transfers array |
sam_grove |
0:9dd7c6129683 | 210 | * to store a new SDO. |
sam_grove |
0:9dd7c6129683 | 211 | * ie a line which value of the field "state" is "SDO_RESET" |
sam_grove |
0:9dd7c6129683 | 212 | * An unused line have the field "state" at the value SDO_RESET |
sam_grove |
0:9dd7c6129683 | 213 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 214 | * @param whoami Create the line for a SDO_SERVER or SDO_CLIENT. |
sam_grove |
0:9dd7c6129683 | 215 | * @param *line Pointer on a SDO line |
sam_grove |
0:9dd7c6129683 | 216 | * @return 0xFF if all the lines are on use. Else, return 0. |
sam_grove |
0:9dd7c6129683 | 217 | */ |
sam_grove |
0:9dd7c6129683 | 218 | UNS8 getSDOfreeLine (CO_Data* d, UNS8 whoami, UNS8 *line); |
sam_grove |
0:9dd7c6129683 | 219 | |
sam_grove |
0:9dd7c6129683 | 220 | /** |
sam_grove |
0:9dd7c6129683 | 221 | * @brief Search for the line, in the transfers array, which contains the |
sam_grove |
0:9dd7c6129683 | 222 | * beginning of the reception of a fragmented SDO |
sam_grove |
0:9dd7c6129683 | 223 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 224 | * @param nodeId correspond to the message node-id |
sam_grove |
0:9dd7c6129683 | 225 | * @param whoami takes 2 values : look for a line opened as SDO_CLIENT or SDO_SERVER |
sam_grove |
0:9dd7c6129683 | 226 | * @param *line Pointer on a SDO line |
sam_grove |
0:9dd7c6129683 | 227 | * @return 0xFF if error. Else, return 0 |
sam_grove |
0:9dd7c6129683 | 228 | */ |
sam_grove |
0:9dd7c6129683 | 229 | UNS8 getSDOlineOnUse (CO_Data* d, UNS8 nodeId, UNS8 whoami, UNS8 *line); |
sam_grove |
0:9dd7c6129683 | 230 | |
sam_grove |
0:9dd7c6129683 | 231 | /** |
sam_grove |
0:9dd7c6129683 | 232 | * @brief Search for the line, in the transfers array, which contains the |
sam_grove |
0:9dd7c6129683 | 233 | * beginning of the reception of a fragmented SDO |
sam_grove |
0:9dd7c6129683 | 234 | * |
sam_grove |
0:9dd7c6129683 | 235 | * Because getSDOlineOnUse() does not return any line in state \c SDO_ABORTED_INTERNAL, |
sam_grove |
0:9dd7c6129683 | 236 | * this funtion is used to return them, too. |
sam_grove |
0:9dd7c6129683 | 237 | * |
sam_grove |
0:9dd7c6129683 | 238 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 239 | * @param nodeId correspond to the message node-id |
sam_grove |
0:9dd7c6129683 | 240 | * @param whoami takes 2 values : look for a line opened as SDO_CLIENT or SDO_SERVER |
sam_grove |
0:9dd7c6129683 | 241 | * @param *line Pointer on a SDO line |
sam_grove |
0:9dd7c6129683 | 242 | * @return 0xFF if error. Else, return 0 |
sam_grove |
0:9dd7c6129683 | 243 | */ |
sam_grove |
0:9dd7c6129683 | 244 | UNS8 getSDOlineToClose (CO_Data* d, UNS8 nodeId, UNS8 whoami, UNS8 *line); |
sam_grove |
0:9dd7c6129683 | 245 | |
sam_grove |
0:9dd7c6129683 | 246 | /** |
sam_grove |
0:9dd7c6129683 | 247 | * @brief Close a transmission. |
sam_grove |
0:9dd7c6129683 | 248 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 249 | * @param nodeId Node id of the server if both server or client |
sam_grove |
0:9dd7c6129683 | 250 | * @param whoami Line opened as SDO_CLIENT or SDO_SERVER |
sam_grove |
0:9dd7c6129683 | 251 | */ |
sam_grove |
0:9dd7c6129683 | 252 | UNS8 closeSDOtransfer (CO_Data* d, UNS8 nodeId, UNS8 whoami); |
sam_grove |
0:9dd7c6129683 | 253 | |
sam_grove |
0:9dd7c6129683 | 254 | /** |
sam_grove |
0:9dd7c6129683 | 255 | * @brief Bytes in the line structure which must be transmited (or received) |
sam_grove |
0:9dd7c6129683 | 256 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 257 | * @param line SDO line |
sam_grove |
0:9dd7c6129683 | 258 | * @param *nbBytes Pointer on nbBytes |
sam_grove |
0:9dd7c6129683 | 259 | * @return 0. |
sam_grove |
0:9dd7c6129683 | 260 | */ |
sam_grove |
0:9dd7c6129683 | 261 | UNS8 getSDOlineRestBytes (CO_Data* d, UNS8 line, UNS32 * nbBytes); |
sam_grove |
0:9dd7c6129683 | 262 | |
sam_grove |
0:9dd7c6129683 | 263 | /** |
sam_grove |
0:9dd7c6129683 | 264 | * @brief Store in the line structure the nb of bytes which must be transmited (or received) |
sam_grove |
0:9dd7c6129683 | 265 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 266 | * @param line SDO line |
sam_grove |
0:9dd7c6129683 | 267 | * @param nbBytes |
sam_grove |
0:9dd7c6129683 | 268 | * @return 0 if success, 0xFF if error. |
sam_grove |
0:9dd7c6129683 | 269 | */ |
sam_grove |
0:9dd7c6129683 | 270 | UNS8 setSDOlineRestBytes (CO_Data* d, UNS8 line, UNS32 nbBytes); |
sam_grove |
0:9dd7c6129683 | 271 | |
sam_grove |
0:9dd7c6129683 | 272 | /** |
sam_grove |
0:9dd7c6129683 | 273 | * @brief Transmit a SDO frame on the bus bus_id |
sam_grove |
0:9dd7c6129683 | 274 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 275 | * @param whoami Takes 2 values : SDO_CLIENT or SDO_SERVER |
sam_grove |
0:9dd7c6129683 | 276 | * @param sdo SDO Structure which contains the sdo to transmit |
sam_grove |
0:9dd7c6129683 | 277 | * @return canSend(bus_id,&m) or 0xFF if error. |
sam_grove |
0:9dd7c6129683 | 278 | */ |
sam_grove |
0:9dd7c6129683 | 279 | UNS8 sendSDO (CO_Data* d, UNS8 whoami, s_SDO sdo); |
sam_grove |
0:9dd7c6129683 | 280 | |
sam_grove |
0:9dd7c6129683 | 281 | /** |
sam_grove |
0:9dd7c6129683 | 282 | * @brief Transmit a SDO error to the client. The reasons may be : |
sam_grove |
0:9dd7c6129683 | 283 | * Read/Write to a undefined object |
sam_grove |
0:9dd7c6129683 | 284 | * Read/Write to a undefined subindex |
sam_grove |
0:9dd7c6129683 | 285 | * Read/write a not valid length object |
sam_grove |
0:9dd7c6129683 | 286 | * Write a read only object |
sam_grove |
0:9dd7c6129683 | 287 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 288 | * @param whoami takes 2 values : SDO_CLIENT or SDO_SERVER |
sam_grove |
0:9dd7c6129683 | 289 | * @param nodeId |
sam_grove |
0:9dd7c6129683 | 290 | * @param index |
sam_grove |
0:9dd7c6129683 | 291 | * @param subIndex |
sam_grove |
0:9dd7c6129683 | 292 | * @param abortCode |
sam_grove |
0:9dd7c6129683 | 293 | * @return 0 |
sam_grove |
0:9dd7c6129683 | 294 | */ |
sam_grove |
0:9dd7c6129683 | 295 | UNS8 sendSDOabort (CO_Data* d, UNS8 whoami, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS32 abortCode); |
sam_grove |
0:9dd7c6129683 | 296 | |
sam_grove |
0:9dd7c6129683 | 297 | /** |
sam_grove |
0:9dd7c6129683 | 298 | * @brief Treat a SDO frame reception |
sam_grove |
0:9dd7c6129683 | 299 | * call the function sendSDO |
sam_grove |
0:9dd7c6129683 | 300 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 301 | * @param *m Pointer on a CAN message structure |
sam_grove |
0:9dd7c6129683 | 302 | * @return code : |
sam_grove |
0:9dd7c6129683 | 303 | * - 0xFF if error |
sam_grove |
0:9dd7c6129683 | 304 | * - 0x80 if transfert aborted by the server |
sam_grove |
0:9dd7c6129683 | 305 | * - 0x0 ok |
sam_grove |
0:9dd7c6129683 | 306 | */ |
sam_grove |
0:9dd7c6129683 | 307 | UNS8 proceedSDO (CO_Data* d, Message *m); |
sam_grove |
0:9dd7c6129683 | 308 | |
sam_grove |
0:9dd7c6129683 | 309 | /** |
sam_grove |
0:9dd7c6129683 | 310 | * @ingroup sdo |
sam_grove |
0:9dd7c6129683 | 311 | * @brief Used to send a SDO request frame to write the data at the index and subIndex indicated |
sam_grove |
0:9dd7c6129683 | 312 | * @param *d Pointer to a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 313 | * @param nodeId Node Id of the slave |
sam_grove |
0:9dd7c6129683 | 314 | * @param index At index indicated |
sam_grove |
0:9dd7c6129683 | 315 | * @param subIndex At subIndex indicated |
sam_grove |
0:9dd7c6129683 | 316 | * @param count number of bytes to write in the dictionnary. |
sam_grove |
0:9dd7c6129683 | 317 | * @param dataType (defined in objdictdef.h) : put "visible_string" for strings, 0 for integers or reals or other value. |
sam_grove |
0:9dd7c6129683 | 318 | * @param *data Pointer to data |
sam_grove |
0:9dd7c6129683 | 319 | * @return |
sam_grove |
0:9dd7c6129683 | 320 | * - 0 is returned upon success. |
sam_grove |
0:9dd7c6129683 | 321 | * - 0xFE is returned when no sdo client to communicate with node. |
sam_grove |
0:9dd7c6129683 | 322 | * - 0xFF is returned when error occurs. |
sam_grove |
0:9dd7c6129683 | 323 | */ |
sam_grove |
0:9dd7c6129683 | 324 | UNS8 writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, |
sam_grove |
0:9dd7c6129683 | 325 | UNS8 subIndex, UNS32 count, UNS8 dataType, void *data); |
sam_grove |
0:9dd7c6129683 | 326 | |
sam_grove |
0:9dd7c6129683 | 327 | /** |
sam_grove |
0:9dd7c6129683 | 328 | * @ingroup sdo |
sam_grove |
0:9dd7c6129683 | 329 | * @brief Used to send a SDO request frame to write in a distant node dictionnary. |
sam_grove |
0:9dd7c6129683 | 330 | * @details The function Callback which must be defined in the user code is called at the |
sam_grove |
0:9dd7c6129683 | 331 | * end of the exchange. (on succes or abort). |
sam_grove |
0:9dd7c6129683 | 332 | * @param *d Pointer to a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 333 | * @param nodeId Node Id of the slave |
sam_grove |
0:9dd7c6129683 | 334 | * @param index At index indicated |
sam_grove |
0:9dd7c6129683 | 335 | * @param subIndex At subIndex indicated |
sam_grove |
0:9dd7c6129683 | 336 | * @param count number of bytes to write in the dictionnary. |
sam_grove |
0:9dd7c6129683 | 337 | * @param dataType (defined in objdictdef.h) : put "visible_string" for strings, 0 for integers or reals or other value. |
sam_grove |
0:9dd7c6129683 | 338 | * @param *data Pointer to data |
sam_grove |
0:9dd7c6129683 | 339 | * @param Callback Callback function |
sam_grove |
0:9dd7c6129683 | 340 | * @return |
sam_grove |
0:9dd7c6129683 | 341 | * - 0 is returned upon success. |
sam_grove |
0:9dd7c6129683 | 342 | * - 0xFE is returned when no sdo client to communicate with node. |
sam_grove |
0:9dd7c6129683 | 343 | * - 0xFF is returned when error occurs. |
sam_grove |
0:9dd7c6129683 | 344 | */ |
sam_grove |
0:9dd7c6129683 | 345 | UNS8 writeNetworkDictCallBack (CO_Data* d, UNS8 nodeId, UNS16 index, |
sam_grove |
0:9dd7c6129683 | 346 | UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback); |
sam_grove |
0:9dd7c6129683 | 347 | |
sam_grove |
0:9dd7c6129683 | 348 | /** |
sam_grove |
0:9dd7c6129683 | 349 | * @ingroup sdo |
sam_grove |
0:9dd7c6129683 | 350 | * @brief Used to send a SDO request frame to write in a distant node dictionnary. |
sam_grove |
0:9dd7c6129683 | 351 | * @details The function Callback which must be defined in the user code is called at the |
sam_grove |
0:9dd7c6129683 | 352 | * end of the exchange. (on succes or abort). First free SDO client parameter is |
sam_grove |
0:9dd7c6129683 | 353 | * automatically initialized for specific node if not already defined. |
sam_grove |
0:9dd7c6129683 | 354 | * @param *d Pointer to a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 355 | * @param nodeId Node Id of the slave |
sam_grove |
0:9dd7c6129683 | 356 | * @param index At index indicated |
sam_grove |
0:9dd7c6129683 | 357 | * @param subIndex At subIndex indicated |
sam_grove |
0:9dd7c6129683 | 358 | * @param count number of bytes to write in the dictionnary. |
sam_grove |
0:9dd7c6129683 | 359 | * @param dataType (defined in objdictdef.h) : put "visible_string" for strings, 0 for integers or reals or other value. |
sam_grove |
0:9dd7c6129683 | 360 | * @param *data Pointer to data |
sam_grove |
0:9dd7c6129683 | 361 | * @param Callback Callback function |
sam_grove |
0:9dd7c6129683 | 362 | * @param endianize When not 0, data is endianized into network byte order |
sam_grove |
0:9dd7c6129683 | 363 | * when 0, data is not endianized and copied in machine native |
sam_grove |
0:9dd7c6129683 | 364 | * endianness |
sam_grove |
0:9dd7c6129683 | 365 | * @return |
sam_grove |
0:9dd7c6129683 | 366 | * - 0 is returned upon success. |
sam_grove |
0:9dd7c6129683 | 367 | * - 0xFF is returned when error occurs. |
sam_grove |
0:9dd7c6129683 | 368 | */ |
sam_grove |
0:9dd7c6129683 | 369 | UNS8 writeNetworkDictCallBackAI (CO_Data* d, UNS8 nodeId, UNS16 index, |
sam_grove |
0:9dd7c6129683 | 370 | UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize); |
sam_grove |
0:9dd7c6129683 | 371 | |
sam_grove |
0:9dd7c6129683 | 372 | /** |
sam_grove |
0:9dd7c6129683 | 373 | * @ingroup sdo |
sam_grove |
0:9dd7c6129683 | 374 | * @brief Used to send a SDO request frame to read. |
sam_grove |
0:9dd7c6129683 | 375 | * @param *d Pointer to a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 376 | * @param nodeId Node Id of the slave |
sam_grove |
0:9dd7c6129683 | 377 | * @param index At index indicated |
sam_grove |
0:9dd7c6129683 | 378 | * @param subIndex At subIndex indicated |
sam_grove |
0:9dd7c6129683 | 379 | * @param dataType (defined in objdictdef.h) : put "visible_string" for strings, 0 for integers or reals or other value. |
sam_grove |
0:9dd7c6129683 | 380 | * @return |
sam_grove |
0:9dd7c6129683 | 381 | * - 0 is returned upon success. |
sam_grove |
0:9dd7c6129683 | 382 | * - 0xFE is returned when no sdo client to communicate with node. |
sam_grove |
0:9dd7c6129683 | 383 | * - 0xFF is returned when error occurs. |
sam_grove |
0:9dd7c6129683 | 384 | */ |
sam_grove |
0:9dd7c6129683 | 385 | UNS8 readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType); |
sam_grove |
0:9dd7c6129683 | 386 | |
sam_grove |
0:9dd7c6129683 | 387 | /** |
sam_grove |
0:9dd7c6129683 | 388 | * @ingroup sdo |
sam_grove |
0:9dd7c6129683 | 389 | * @brief Used to send a SDO request frame to read in a distant node dictionnary. |
sam_grove |
0:9dd7c6129683 | 390 | * @details The function Callback which must be defined in the user code is called at the |
sam_grove |
0:9dd7c6129683 | 391 | * end of the exchange. (on succes or abort). |
sam_grove |
0:9dd7c6129683 | 392 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 393 | * @param nodeId Node Id of the slave |
sam_grove |
0:9dd7c6129683 | 394 | * @param index At index indicated |
sam_grove |
0:9dd7c6129683 | 395 | * @param subIndex At subIndex indicated |
sam_grove |
0:9dd7c6129683 | 396 | * @param dataType (defined in objdictdef.h) : put "visible_string" for strings, 0 for integers or reals or other value. |
sam_grove |
0:9dd7c6129683 | 397 | * @param Callback Callback function |
sam_grove |
0:9dd7c6129683 | 398 | * @return |
sam_grove |
0:9dd7c6129683 | 399 | * - 0 is returned upon success. |
sam_grove |
0:9dd7c6129683 | 400 | * - 0xFE is returned when no sdo client to communicate with node. |
sam_grove |
0:9dd7c6129683 | 401 | * - 0xFF is returned when error occurs. |
sam_grove |
0:9dd7c6129683 | 402 | */ |
sam_grove |
0:9dd7c6129683 | 403 | UNS8 readNetworkDictCallback (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback); |
sam_grove |
0:9dd7c6129683 | 404 | |
sam_grove |
0:9dd7c6129683 | 405 | /** |
sam_grove |
0:9dd7c6129683 | 406 | * @ingroup sdo |
sam_grove |
0:9dd7c6129683 | 407 | * @brief Used to send a SDO request frame to read in a distant node dictionnary. |
sam_grove |
0:9dd7c6129683 | 408 | * @details The function Callback which must be defined in the user code is called at the |
sam_grove |
0:9dd7c6129683 | 409 | * end of the exchange. (on succes or abort). First free SDO client parameter is |
sam_grove |
0:9dd7c6129683 | 410 | * automatically initialized for specific node if not already defined. |
sam_grove |
0:9dd7c6129683 | 411 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 412 | * @param nodeId Node Id of the slave |
sam_grove |
0:9dd7c6129683 | 413 | * @param index At index indicated |
sam_grove |
0:9dd7c6129683 | 414 | * @param subIndex At subIndex indicated |
sam_grove |
0:9dd7c6129683 | 415 | * @param dataType (defined in objdictdef.h) : put "visible_string" for strings, 0 for integers or reals or other value. |
sam_grove |
0:9dd7c6129683 | 416 | * @param Callback Callback function |
sam_grove |
0:9dd7c6129683 | 417 | * @return |
sam_grove |
0:9dd7c6129683 | 418 | * - 0 is returned upon success. |
sam_grove |
0:9dd7c6129683 | 419 | * - 0xFF is returned when error occurs. |
sam_grove |
0:9dd7c6129683 | 420 | */ |
sam_grove |
0:9dd7c6129683 | 421 | UNS8 readNetworkDictCallbackAI (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback); |
sam_grove |
0:9dd7c6129683 | 422 | |
sam_grove |
0:9dd7c6129683 | 423 | /** |
sam_grove |
0:9dd7c6129683 | 424 | * @ingroup sdo |
sam_grove |
0:9dd7c6129683 | 425 | * @brief Use this function after calling readNetworkDict to get the result. |
sam_grove |
0:9dd7c6129683 | 426 | * |
sam_grove |
0:9dd7c6129683 | 427 | * @param *d Pointer to a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 428 | * @param nodeId Node Id of the slave |
sam_grove |
0:9dd7c6129683 | 429 | * @param *data Pointer to the datas |
sam_grove |
0:9dd7c6129683 | 430 | * @param *size Pointer to the size |
sam_grove |
0:9dd7c6129683 | 431 | * @param *abortCode Pointer to the abortcode. (0 = not available. Else : SDO abort code. (received if return SDO_ABORTED_RCV) |
sam_grove |
0:9dd7c6129683 | 432 | * |
sam_grove |
0:9dd7c6129683 | 433 | * |
sam_grove |
0:9dd7c6129683 | 434 | * @return |
sam_grove |
0:9dd7c6129683 | 435 | * - SDO_FINISHED // datas are available |
sam_grove |
0:9dd7c6129683 | 436 | * - SDO_ABORTED_RCV // Transfert failed (abort SDO received) |
sam_grove |
0:9dd7c6129683 | 437 | * - SDO_ABORTED_INTERNAL // Transfert failed (internal abort) |
sam_grove |
0:9dd7c6129683 | 438 | * - SDO_UPLOAD_IN_PROGRESS // Datas are not yet available |
sam_grove |
0:9dd7c6129683 | 439 | * - SDO_DOWNLOAD_IN_PROGRESS // Download is in progress |
sam_grove |
0:9dd7c6129683 | 440 | * \n\n |
sam_grove |
0:9dd7c6129683 | 441 | * example : |
sam_grove |
0:9dd7c6129683 | 442 | * @code |
sam_grove |
0:9dd7c6129683 | 443 | * UNS32 data; |
sam_grove |
0:9dd7c6129683 | 444 | * UNS8 size; |
sam_grove |
0:9dd7c6129683 | 445 | * readNetworkDict(0, 0x05, 0x1016, 1, 0) // get the data index 1016 subindex 1 of node 5 |
sam_grove |
0:9dd7c6129683 | 446 | * while (getReadResultNetworkDict (0, 0x05, &data, &size) == SDO_UPLOAD_IN_PROGRESS); |
sam_grove |
0:9dd7c6129683 | 447 | * @endcode |
sam_grove |
0:9dd7c6129683 | 448 | */ |
sam_grove |
0:9dd7c6129683 | 449 | UNS8 getReadResultNetworkDict (CO_Data* d, UNS8 nodeId, void* data, UNS32 *size, UNS32 * abortCode); |
sam_grove |
0:9dd7c6129683 | 450 | |
sam_grove |
0:9dd7c6129683 | 451 | /** |
sam_grove |
0:9dd7c6129683 | 452 | * @ingroup sdo |
sam_grove |
0:9dd7c6129683 | 453 | * @brief Use this function after calling writeNetworkDict function to get the result of the write. |
sam_grove |
0:9dd7c6129683 | 454 | * @details It is mandatory to call this function because it is releasing the line used for the transfer. |
sam_grove |
0:9dd7c6129683 | 455 | * @param *d Pointer to a CAN object data structure |
sam_grove |
0:9dd7c6129683 | 456 | * @param nodeId Node Id of the slave |
sam_grove |
0:9dd7c6129683 | 457 | * @param *abortCode Pointer to the abortcode |
sam_grove |
0:9dd7c6129683 | 458 | * - 0 = not available. |
sam_grove |
0:9dd7c6129683 | 459 | * - SDO abort code (received if return SDO_ABORTED_RCV) |
sam_grove |
0:9dd7c6129683 | 460 | * |
sam_grove |
0:9dd7c6129683 | 461 | * @return : |
sam_grove |
0:9dd7c6129683 | 462 | * - SDO_FINISHED // datas are available |
sam_grove |
0:9dd7c6129683 | 463 | * - SDO_ABORTED_RCV // Transfert failed (abort SDO received) |
sam_grove |
0:9dd7c6129683 | 464 | * - SDO_ABORTED_INTERNAL // Transfert failed (Internal abort) |
sam_grove |
0:9dd7c6129683 | 465 | * - SDO_DOWNLOAD_IN_PROGRESS // Datas are not yet available |
sam_grove |
0:9dd7c6129683 | 466 | * - SDO_UPLOAD_IN_PROGRESS // Upload in progress |
sam_grove |
0:9dd7c6129683 | 467 | * \n\n |
sam_grove |
0:9dd7c6129683 | 468 | * example : |
sam_grove |
0:9dd7c6129683 | 469 | * @code |
sam_grove |
0:9dd7c6129683 | 470 | * UNS32 data = 0x50; |
sam_grove |
0:9dd7c6129683 | 471 | * UNS8 size; |
sam_grove |
0:9dd7c6129683 | 472 | * UNS32 abortCode; |
sam_grove |
0:9dd7c6129683 | 473 | * writeNetworkDict(0, 0x05, 0x1016, 1, size, &data) // write the data index 1016 subindex 1 of node 5 |
sam_grove |
0:9dd7c6129683 | 474 | * while (getWriteResultNetworkDict (0, 0x05, &abortCode) == SDO_DOWNLOAD_IN_PROGRESS); |
sam_grove |
0:9dd7c6129683 | 475 | * @endcode |
sam_grove |
0:9dd7c6129683 | 476 | */ |
sam_grove |
0:9dd7c6129683 | 477 | UNS8 getWriteResultNetworkDict (CO_Data* d, UNS8 nodeId, UNS32 * abortCode); |
sam_grove |
0:9dd7c6129683 | 478 | |
sam_grove |
0:9dd7c6129683 | 479 | #endif |