0
|
1 |
/*
|
|
2 |
This file is part of CanFestival, a library implementing CanOpen Stack.
|
|
3 |
|
|
4 |
Copyright (C): Edouard TISSERANT and Francis DUPIN
|
|
5 |
|
|
6 |
See COPYING file for copyrights details.
|
|
7 |
|
|
8 |
This library is free software; you can redistribute it and/or
|
|
9 |
modify it under the terms of the GNU Lesser General Public
|
|
10 |
License as published by the Free Software Foundation; either
|
|
11 |
version 2.1 of the License, or (at your option) any later version.
|
|
12 |
|
|
13 |
This library is distributed in the hope that it will be useful,
|
|
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
16 |
Lesser General Public License for more details.
|
|
17 |
|
|
18 |
You should have received a copy of the GNU Lesser General Public
|
|
19 |
License along with this library; if not, write to the Free Software
|
|
20 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 |
*/
|
|
22 |
|
|
23 |
#ifndef __sdo_h__
|
|
24 |
#define __sdo_h__
|
|
25 |
|
|
26 |
typedef void (*SDOtimeoutError_t)(UNS8 line);
|
|
27 |
struct struct_s_transfer;
|
|
28 |
|
|
29 |
#include "timer.h"
|
|
30 |
|
32
|
31 |
typedef void (*SDOCallback_t)(CO_Data* d, UNS8 nodeId);
|
|
32 |
|
0
|
33 |
/* The Transfer structure
|
|
34 |
Used to store the different segments of
|
|
35 |
- a SDO received before writing in the dictionary
|
|
36 |
- the reading of the dictionary to put on a SDO to transmit
|
|
37 |
*/
|
|
38 |
|
|
39 |
struct struct_s_transfer {
|
|
40 |
UNS8 nodeId; //own ID if server, or node ID of the server if client
|
|
41 |
|
|
42 |
UNS8 whoami; // Takes the values SDO_CLIENT or SDO_SERVER
|
|
43 |
UNS8 state; // state of the transmission : Takes the values SDO_...
|
|
44 |
UNS8 toggle;
|
|
45 |
UNS32 abortCode; // Sent or received
|
|
46 |
// index and subindex of the dictionary where to store
|
|
47 |
// (for a received SDO) or to read (for a transmit SDO)
|
|
48 |
UNS16 index;
|
|
49 |
UNS8 subIndex;
|
|
50 |
UNS32 count; // Number of data received or to be sent.
|
|
51 |
UNS32 offset; // stack pointer of data[]
|
|
52 |
// Used only to tranfer part of a line to or from a SDO.
|
|
53 |
// offset is always pointing on the next free cell of data[].
|
|
54 |
// WARNING s_transfer.data is subject to ENDIANISATION
|
|
55 |
// (with respect to CANOPEN_BIG_ENDIAN)
|
|
56 |
UNS8 data [SDO_MAX_LENGTH_TRANSFERT];
|
|
57 |
UNS8 dataType; // Defined in objdictdef.h Value is visible_string
|
|
58 |
// if it is a string, any other value if it is not a string,
|
|
59 |
// like 0. In fact, it is used only if client.
|
|
60 |
TIMER_HANDLE timer; // Time counter to implement a timeout in milliseconds.
|
|
61 |
// It is automatically incremented whenever
|
|
62 |
// the line state is in SDO_DOWNLOAD_IN_PROGRESS or
|
|
63 |
// SDO_UPLOAD_IN_PROGRESS, and reseted to 0
|
|
64 |
// when the response SDO have been received.
|
32
|
65 |
SDOCallback_t Callback; // The user callback func to be called at SDO transaction end
|
0
|
66 |
};
|
|
67 |
typedef struct struct_s_transfer s_transfer;
|
|
68 |
|
|
69 |
|
|
70 |
#include "data.h"
|
|
71 |
|
|
72 |
/// The 8 bytes data of the SDO
|
|
73 |
struct BODY{
|
|
74 |
UNS8 data[8];
|
|
75 |
};
|
|
76 |
|
|
77 |
/// The SDO structure ...
|
|
78 |
struct struct_s_SDO {
|
|
79 |
UNS8 nodeId; //in any case, Node ID of the server (case sender or receiver).
|
|
80 |
struct BODY body;
|
|
81 |
};
|
|
82 |
|
|
83 |
|
|
84 |
typedef struct struct_s_SDO s_SDO;
|
|
85 |
|
53
|
86 |
/** Reset of a SDO exchange on timeout.
|
|
87 |
* Send a SDO abort
|
|
88 |
*/
|
|
89 |
void SDOTimeoutAlarm(CO_Data* d, UNS32 id);
|
|
90 |
|
0
|
91 |
/** Reset all sdo buffers
|
|
92 |
*/
|
|
93 |
void resetSDO (CO_Data* d);
|
|
94 |
|
|
95 |
|
|
96 |
/** Copy the data received from the SDO line transfert to the object dictionary
|
|
97 |
* Returns SDO error code if error. Else, returns 0;
|
|
98 |
*/
|
|
99 |
UNS32 SDOlineToObjdict (CO_Data* d, UNS8 line);
|
|
100 |
|
|
101 |
/** Copy the data from the object dictionary to the SDO line for a network transfert.
|
|
102 |
* Returns SDO error code if error. Else, returns 0;
|
|
103 |
*/
|
|
104 |
UNS32 objdictToSDOline (CO_Data* d, UNS8 line);
|
|
105 |
|
|
106 |
/** copy data from an existant line in the argument "* data"
|
|
107 |
* Returns 0xFF if error. Else, returns 0;
|
|
108 |
*/
|
|
109 |
UNS8 lineToSDO (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8 * data);
|
|
110 |
|
|
111 |
/** Add data to an existant line
|
|
112 |
* Returns 0xFF if error. Else, returns 0;
|
|
113 |
*/
|
|
114 |
UNS8 SDOtoLine (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8 * data);
|
|
115 |
|
|
116 |
/** Called when an internal SDO abort occurs.
|
|
117 |
* Release the line * Only if server *
|
|
118 |
* If client, the line must be released manually in the core application.
|
|
119 |
* The reason of that is to permit the program to read the transfers[][] structure before its reset,
|
|
120 |
* because many informations are stored on it : index, subindex, data received or trasmited, ...
|
|
121 |
* In all cases, sends a SDO abort.
|
|
122 |
* Returns 0
|
|
123 |
*/
|
|
124 |
UNS8 failedSDO (CO_Data* d, UNS8 nodeId, UNS8 whoami, UNS16 index,
|
|
125 |
UNS8 subIndex, UNS32 abortCode);
|
|
126 |
|
|
127 |
/** Reset an unused line.
|
|
128 |
*
|
|
129 |
*/
|
|
130 |
void resetSDOline (CO_Data* d, UNS8 line);
|
|
131 |
|
|
132 |
/** Initialize some fields of the structure.
|
|
133 |
* Returns 0
|
|
134 |
*/
|
|
135 |
UNS8 initSDOline (CO_Data* d, UNS8 line, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 state);
|
|
136 |
|
|
137 |
/** Search for an unused line in the transfers array
|
|
138 |
* to store a new SDO.
|
|
139 |
* ie a line which value of the field "state" is "SDO_RESET"
|
|
140 |
* An unused line have the field "state" at the value SDO_RESET
|
|
141 |
* bus_id is hardware dependant
|
|
142 |
* whoami : create the line for a SDO_SERVER or SDO_CLIENT.
|
|
143 |
* return 0xFF if all the lines are on use. Else, return 0
|
|
144 |
*/
|
|
145 |
UNS8 getSDOfreeLine (CO_Data* d, UNS8 whoami, UNS8 *line);
|
|
146 |
|
|
147 |
/** Search for the line, in the transfers array, which contains the
|
|
148 |
* beginning of the reception of a fragmented SDO
|
|
149 |
* whoami takes 2 values : look for a line opened as SDO_CLIENT or SDO_SERVER
|
|
150 |
* bus_id is hardware dependant
|
|
151 |
* nodeId correspond to the message node-id
|
|
152 |
* return 0xFF if error. Else, return 0
|
|
153 |
*/
|
|
154 |
UNS8 getSDOlineOnUse (CO_Data* d, UNS8 nodeId, UNS8 whoami, UNS8 *line);
|
|
155 |
|
|
156 |
/** Close a transmission.
|
|
157 |
* nodeId : Node id of the server if both server or client
|
|
158 |
* whoami : Line opened as SDO_CLIENT or SDO_SERVER
|
|
159 |
*/
|
|
160 |
UNS8 closeSDOtransfer (CO_Data* d, UNS8 nodeId, UNS8 whoami);
|
|
161 |
|
|
162 |
/** Bytes in the line structure which must be transmited (or received)
|
|
163 |
* bus_id is hardware dependant.
|
|
164 |
* return 0.
|
|
165 |
*/
|
|
166 |
UNS8 getSDOlineRestBytes (CO_Data* d, UNS8 line, UNS8 * nbBytes);
|
|
167 |
|
|
168 |
/** Store in the line structure the nb of bytes which must be transmited (or received)
|
|
169 |
* bus_id is hardware dependant.
|
|
170 |
* return 0 if success, 0xFF if error.
|
|
171 |
*/
|
|
172 |
UNS8 setSDOlineRestBytes (CO_Data* d, UNS8 line, UNS8 nbBytes);
|
|
173 |
|
|
174 |
/** Transmit a SDO frame on the bus bus_id
|
|
175 |
* sdo is a structure which contains the sdo to transmit
|
|
176 |
* bus_id is hardware dependant
|
|
177 |
* whoami takes 2 values : SDO_CLIENT or SDO_SERVER
|
|
178 |
* return canSend(bus_id,&m) or 0xFF if error
|
|
179 |
*/
|
|
180 |
UNS8 sendSDO (CO_Data* d, UNS8 whoami, s_SDO sdo);
|
|
181 |
|
|
182 |
/** Transmit a SDO error to the client. The reasons may be :
|
|
183 |
* Read/Write to a undefined object
|
|
184 |
* Read/Write to a undefined subindex
|
|
185 |
* Read/write a not valid length object
|
|
186 |
* Write a read only object
|
|
187 |
* whoami takes 2 values : SDO_CLIENT or SDO_SERVER
|
|
188 |
*/
|
|
189 |
UNS8 sendSDOabort (CO_Data* d, UNS8 whoami, UNS16 index, UNS8 subIndex, UNS32 abortCode);
|
|
190 |
|
|
191 |
/** Treat a SDO frame reception
|
|
192 |
* bus_id is hardware dependant
|
|
193 |
* call the function sendSDO
|
|
194 |
* return 0xFF if error
|
|
195 |
* 0x80 if transfert aborted by the server
|
|
196 |
* 0x0 ok
|
|
197 |
*/
|
|
198 |
UNS8 proceedSDO (CO_Data* d, Message *m);
|
|
199 |
|
|
200 |
/** Used by the application to send a SDO request frame to write the data *data
|
|
201 |
* at the index and subIndex indicated
|
|
202 |
* in the dictionary of the slave whose node_id is nodeId
|
|
203 |
* Count : nb of bytes to write in the dictionnary.
|
|
204 |
* datatype (defined in objdictdef.h) : put "visible_string" for strings, 0 for integers or reals or other value.
|
|
205 |
* bus_id is hardware dependant
|
|
206 |
* return 0xFF if error, else return 0
|
|
207 |
*/
|
|
208 |
UNS8 writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
|
|
209 |
UNS8 subIndex, UNS8 count, UNS8 dataType, void *data);
|
53
|
210 |
/** Used to send a SDO request frame to write in a distant node dictionnary.
|
|
211 |
* The function Callback which must be defined in the user code is called at the
|
|
212 |
* end of the exchange. (on succes or abort).
|
|
213 |
*/
|
|
214 |
UNS8 writeNetworkDictCallBack (CO_Data* d, UNS8 nodeId, UNS16 index,
|
|
215 |
UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback);
|
0
|
216 |
/** Used by the application to send a SDO request frame to read
|
|
217 |
* in the dictionary of a server node whose node_id is ID
|
|
218 |
* at the index and subIndex indicated
|
|
219 |
* bus_id is hardware dependant
|
|
220 |
* datatype (defined in objdictdef.h) : put "visible_string" for strings, 0 for integers or reals or other value.
|
|
221 |
* return 0xFF if error, else return 0
|
|
222 |
*/
|
|
223 |
UNS8 readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
|
|
224 |
UNS8 subIndex, UNS8 dataType);
|
53
|
225 |
|
|
226 |
/** Used to send a SDO request frame to read in a distant node dictionnary.
|
|
227 |
* The function Callback which must be defined in the user code is called at the
|
|
228 |
* end of the exchange. (on succes or abort).
|
|
229 |
*/
|
|
230 |
UNS8 readNetworkDictCallback (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback);
|
0
|
231 |
|
|
232 |
/** Use this function after a readNetworkDict to get the result.
|
|
233 |
Returns : SDO_FINISHED // data is available
|
|
234 |
SDO_ABORTED_RCV // Transfert failed. (abort SDO received)
|
|
235 |
SDO_ABORTED_INTERNAL // Transfert failed. Internal abort.
|
|
236 |
SDO_UPLOAD_IN_PROGRESS // Data not yet available
|
|
237 |
SDO_DOWNLOAD_IN_PROGRESS // Should not arrive !
|
|
238 |
|
|
239 |
dataType (defined in objdictdef.h) : type expected. put "visible_string" for strings, 0 for integers or reals.
|
|
240 |
abortCode : 0 = not available. Else : SDO abort code. (received if return SDO_ABORTED_RCV)
|
|
241 |
example :
|
|
242 |
UNS32 data;
|
|
243 |
UNS8 size;
|
|
244 |
readNetworkDict(0, 0x05, 0x1016, 1, 0) // get the data index 1016 subindex 1 of node 5
|
|
245 |
while (getReadResultNetworkDict (0, 0x05, &data, &size) != SDO_UPLOAD_IN_PROGRESS);
|
|
246 |
*/
|
|
247 |
UNS8 getReadResultNetworkDict (CO_Data* d, UNS8 nodeId, void* data,
|
|
248 |
UNS8 *size, UNS32 * abortCode);
|
|
249 |
|
|
250 |
/**
|
|
251 |
Use this function after a writeNetworkDict to get the result of the write
|
|
252 |
It is mandatory to call this function because it is releasing the line used for the transfer.
|
|
253 |
Returns : SDO_FINISHED // data is available
|
|
254 |
SDO_ABORTED_RCV // Transfert failed. (abort SDO received)
|
|
255 |
SDO_ABORTED_INTERNAL // Transfert failed. Internal abort.
|
|
256 |
SDO_DOWNLOAD_IN_PROGRESS // Data not yet available
|
|
257 |
SDO_UPLOAD_IN_PROGRESS // Should not arrive !
|
|
258 |
abortCode : 0 = not available. Else : SDO abort code. (received if return SDO_ABORTED_RCV)
|
|
259 |
example :
|
|
260 |
UNS32 data = 0x50;
|
|
261 |
UNS8 size;
|
|
262 |
UNS32 abortCode;
|
|
263 |
writeNetworkDict(0, 0x05, 0x1016, 1, size, &data) // write the data index 1016 subindex 1 of node 5
|
|
264 |
while ( getWriteResultNetworkDict (0, 0x05, &abortCode) != SDO_DOWNLOAD_IN_PROGRESS);
|
|
265 |
*/
|
|
266 |
UNS8 getWriteResultNetworkDict (CO_Data* d, UNS8 nodeId, UNS32 * abortCode);
|
|
267 |
|
53
|
268 |
|
|
269 |
|
|
270 |
|
0
|
271 |
#endif
|