author | Laurent Bessard |
Thu, 02 May 2013 09:42:37 +0200 | |
changeset 782 | c0869429c72a |
parent 760 | 71623bbf8093 |
permissions | -rw-r--r-- |
178 | 1 |
/* |
207 | 2 |
This file is part of CanFestival, a library implementing CanOpen |
3 |
Stack. |
|
178 | 4 |
|
207 | 5 |
Copyright (C): Edouard TISSERANT and Francis DUPIN |
178 | 6 |
|
207 | 7 |
See COPYING file for copyrights details. |
178 | 8 |
|
207 | 9 |
This library is free software; you can redistribute it and/or |
10 |
modify it under the terms of the GNU Lesser General Public |
|
11 |
License as published by the Free Software Foundation; either |
|
12 |
version 2.1 of the License, or (at your option) any later version. |
|
178 | 13 |
|
207 | 14 |
This library is distributed in the hope that it will be useful, |
15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
17 |
Lesser General Public License for more details. |
|
178 | 18 |
|
207 | 19 |
You should have received a copy of the GNU Lesser General Public |
20 |
License along with this library; if not, write to the Free Software |
|
21 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
22 |
USA |
|
178 | 23 |
*/ |
24 |
||
210 | 25 |
|
208 | 26 |
/** |
207 | 27 |
** @file dcf.c |
28 |
** @author Edouard TISSERANT and Francis DUPIN |
|
29 |
** @date Mon Jun 4 17:06:12 2007 |
|
30 |
** |
|
208 | 31 |
** @brief EXEMPLE OF SOMMARY |
207 | 32 |
** |
33 |
** |
|
34 |
*/ |
|
215 | 35 |
|
36 |
||
378
d2abf6c8c27b
As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents:
368
diff
changeset
|
37 |
#include "data.h" |
200 | 38 |
#include "sysdep.h" |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
39 |
#include "dcf.h" |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
40 |
|
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
41 |
typedef struct { |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
42 |
UNS16 Index; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
43 |
UNS8 Subindex; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
44 |
UNS32 Size; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
45 |
UNS8 *Data; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
46 |
} dcf_entry_t; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
47 |
|
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
48 |
void SaveNode(CO_Data* d, UNS8 nodeId); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
49 |
static UNS8 read_consise_dcf_next_entry(CO_Data* d, UNS8 nodeId); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
50 |
static UNS8 write_consise_dcf_next_entry(CO_Data* d, UNS8 nodeId); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
51 |
UNS8 init_consise_dcf(CO_Data* d,UNS8 nodeId); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
52 |
|
742
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
53 |
|
760 | 54 |
#ifdef _MSC_VER |
55 |
#define inline _inline |
|
56 |
#endif /* _MSC_VER */ |
|
57 |
||
58 |
||
742
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
59 |
inline void start_node(CO_Data* d, UNS8 nodeId){ |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
60 |
/* Ask slave node to go in operational mode */ |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
61 |
masterSendNMTstateChange (d, nodeId, NMT_Start_Node); |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
62 |
d->NMTable[nodeId] = Operational; |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
63 |
} |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
64 |
|
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
65 |
/** |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
66 |
** @brief Function to be called from post_SlaveBootup |
207 | 67 |
** |
68 |
** @param d |
|
69 |
** @param nodeId |
|
208 | 70 |
*/ |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
71 |
UNS8 check_and_start_node(CO_Data* d, UNS8 nodeId) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
72 |
{ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
73 |
if(d->dcf_status != DCF_STATUS_INIT) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
74 |
return 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
75 |
if((init_consise_dcf(d, nodeId) == 0) || (read_consise_dcf_next_entry(d, nodeId) == 0)){ |
742
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
76 |
start_node(d, nodeId); |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
77 |
return 1; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
78 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
79 |
d->dcf_status = DCF_STATUS_READ_CHECK; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
80 |
return 2; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
81 |
} |
349 | 82 |
|
742
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
83 |
inline void start_and_seek_node(CO_Data* d, UNS8 nodeId){ |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
84 |
UNS8 node; |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
85 |
start_node(d,nodeId); |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
86 |
/* Look for other nodes waiting to be started */ |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
87 |
for(node = 0 ; node<NMT_MAX_NODE_ID ; node++){ |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
88 |
if(d->NMTable[node] != Initialisation) |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
89 |
continue; |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
90 |
if(check_and_start_node(d, node) == 2) |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
91 |
return; |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
92 |
} |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
93 |
/* No more node to start. Let's start our own node */ |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
94 |
setState(d, Operational); |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
95 |
} |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
96 |
|
208 | 97 |
/** |
207 | 98 |
** |
99 |
** |
|
100 |
** @param d |
|
101 |
** @param nodeId |
|
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
102 |
*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
103 |
static void CheckSDOAndContinue(CO_Data* d, UNS8 nodeId) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
104 |
{ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
105 |
UNS32 abortCode = 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
106 |
UNS8 buf[4], match = 0, node; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
107 |
UNS32 size=4; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
108 |
if(d->dcf_status == DCF_STATUS_READ_CHECK){ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
109 |
// printf("DCF_STATUS_READ_CHECK \n"); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
110 |
if(getReadResultNetworkDict (d, nodeId, buf, &size, &abortCode) != SDO_FINISHED) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
111 |
goto dcferror; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
112 |
/* Check if data received match the DCF */ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
113 |
if(size == d->dcf_size){ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
114 |
match = 1; |
671
06b30f679531
bug correction in dcf.c, an entry of only one byte was not checked
Mongo
parents:
669
diff
changeset
|
115 |
while(size--) |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
116 |
if(buf[size] != d->dcf_data[size]) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
117 |
match = 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
118 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
119 |
if(match) { |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
120 |
if(read_consise_dcf_next_entry(d, nodeId) == 0){ |
742
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
121 |
start_and_seek_node(d, nodeId); |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
122 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
123 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
124 |
else { /* Data received does not match : start rewriting all */ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
125 |
if((init_consise_dcf(d, nodeId) == 0) || (write_consise_dcf_next_entry(d, nodeId) == 0)) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
126 |
goto dcferror; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
127 |
d->dcf_status = DCF_STATUS_WRITE; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
128 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
129 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
130 |
else if(d->dcf_status == DCF_STATUS_WRITE){ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
131 |
// printf("DCF_STATUS_WRITE \n"); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
132 |
if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
133 |
goto dcferror; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
134 |
if(write_consise_dcf_next_entry(d, nodeId) == 0){ |
699 | 135 |
#ifdef DCF_SAVE_NODE |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
136 |
SaveNode(d, nodeId); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
137 |
d->dcf_status = DCF_STATUS_SAVED; |
699 | 138 |
#else //DCF_SAVE_NODE |
756
4ac6fd44595b
Fixing bug in dcf.c preventing to configure more than one slave using concise dcf when Save Node option is disabled
Laurent Bessard
parents:
742
diff
changeset
|
139 |
d->dcf_status = DCF_STATUS_INIT; |
742
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
699
diff
changeset
|
140 |
start_and_seek_node(d,nodeId); |
699 | 141 |
#endif //DCF_SAVE_NODE |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
142 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
143 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
144 |
else if(d->dcf_status == DCF_STATUS_SAVED){ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
145 |
// printf("DCF_STATUS_SAVED \n"); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
146 |
if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
147 |
goto dcferror; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
148 |
masterSendNMTstateChange (d, nodeId, NMT_Reset_Node); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
149 |
d->dcf_status = DCF_STATUS_INIT; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
150 |
d->NMTable[nodeId] = Unknown_state; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
151 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
152 |
return; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
153 |
dcferror: |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
154 |
MSG_ERR(0x1A01, "SDO error in consise DCF", abortCode); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
155 |
MSG_WAR(0x2A02, "server node : ", nodeId); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
156 |
d->NMTable[nodeId] = Unknown_state; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
157 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
158 |
|
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
159 |
/** |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
160 |
** |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
161 |
** |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
162 |
** @param d |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
163 |
** @param nodeId |
207 | 164 |
** |
165 |
** @return |
|
208 | 166 |
*/ |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
167 |
UNS8 init_consise_dcf(CO_Data* d,UNS8 nodeId) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
168 |
{ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
169 |
/* Fetch DCF OD entry */ |
320
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
170 |
UNS32 errorCode; |
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
171 |
ODCallback_t *Callback; |
699 | 172 |
UNS8* dcf; |
320
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
173 |
d->dcf_odentry = (*d->scanIndexOD)(0x1F22, &errorCode, &Callback); |
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
174 |
/* If DCF entry do not exist... Nothing to do.*/ |
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
175 |
if (errorCode != OD_SUCCESSFUL) goto DCF_finish; |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
176 |
/* Fix DCF table overflow */ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
177 |
if(nodeId > d->dcf_odentry->bSubCount) goto DCF_finish; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
178 |
/* If DCF empty... Nothing to do */ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
179 |
if(! d->dcf_odentry->pSubindex[nodeId].size) goto DCF_finish; |
699 | 180 |
dcf = *(UNS8**)d->dcf_odentry->pSubindex[nodeId].pObject; |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
181 |
// printf("%.2x %.2x %.2x %.2x\n",dcf[0],dcf[1],dcf[2],dcf[3]); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
182 |
d->dcf_cursor = dcf + 4; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
183 |
d->dcf_entries_count = 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
184 |
d->dcf_status = DCF_STATUS_INIT; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
185 |
return 1; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
186 |
DCF_finish: |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
187 |
return 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
188 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
189 |
|
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
190 |
UNS8 get_next_DCF_data(CO_Data* d, dcf_entry_t *dcf_entry, UNS8 nodeId) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
191 |
{ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
192 |
UNS8* dcfend; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
193 |
UNS32 nb_entries; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
194 |
UNS32 szData; |
699 | 195 |
UNS8* dcf; |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
196 |
if(!d->dcf_odentry) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
197 |
return 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
198 |
if(nodeId > d->dcf_odentry->bSubCount) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
199 |
return 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
200 |
szData = d->dcf_odentry->pSubindex[nodeId].size; |
699 | 201 |
dcf = *(UNS8**)d->dcf_odentry->pSubindex[nodeId].pObject; |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
202 |
nb_entries = UNS32_LE(*((UNS32*)dcf)); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
203 |
dcfend = dcf + szData; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
204 |
if((UNS8*)d->dcf_cursor + 7 < (UNS8*)dcfend && d->dcf_entries_count < nb_entries){ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
205 |
/* DCF data may not be 32/16b aligned, |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
206 |
* we cannot directly dereference d->dcf_cursor |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
207 |
* as UNS16 or UNS32 |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
208 |
* Do it byte per byte taking care on endianess*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
209 |
#ifdef CANOPEN_BIG_ENDIAN |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
210 |
dcf_entry->Index = *(d->dcf_cursor++) << 8 | |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
211 |
*(d->dcf_cursor++); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
212 |
#else |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
213 |
memcpy(&dcf_entry->Index, d->dcf_cursor,2); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
214 |
d->dcf_cursor+=2; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
215 |
#endif |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
216 |
dcf_entry->Subindex = *(d->dcf_cursor++); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
217 |
#ifdef CANOPEN_BIG_ENDIAN |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
218 |
dcf_entry->Size = *(d->dcf_cursor++) << 24 | |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
219 |
*(d->dcf_cursor++) << 16 | |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
220 |
*(d->dcf_cursor++) << 8 | |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
221 |
*(d->dcf_cursor++); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
222 |
#else |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
223 |
memcpy(&dcf_entry->Size, d->dcf_cursor,4); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
224 |
d->dcf_cursor+=4; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
225 |
#endif |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
226 |
d->dcf_data = dcf_entry->Data = d->dcf_cursor; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
227 |
d->dcf_size = dcf_entry->Size; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
228 |
d->dcf_cursor += dcf_entry->Size; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
229 |
d->dcf_entries_count++; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
230 |
return 1; |
320
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
231 |
} |
349 | 232 |
return 0; |
233 |
} |
|
178 | 234 |
|
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
235 |
static UNS8 write_consise_dcf_next_entry(CO_Data* d, UNS8 nodeId) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
236 |
{ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
237 |
UNS8 Ret; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
238 |
dcf_entry_t dcf_entry; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
239 |
if(!get_next_DCF_data(d, &dcf_entry, nodeId)) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
240 |
return 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
241 |
Ret = writeNetworkDictCallBackAI(d, /* CO_Data* d*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
242 |
nodeId, /* UNS8 nodeId*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
243 |
dcf_entry.Index, /* UNS16 index*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
244 |
dcf_entry.Subindex, /* UNS8 subindex*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
245 |
(UNS8)dcf_entry.Size, /* UNS8 count*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
246 |
0, /* UNS8 dataType*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
247 |
dcf_entry.Data,/* void *data*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
248 |
CheckSDOAndContinue,/* Callback*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
249 |
0, /* no endianize*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
250 |
0); /* no block mode */ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
251 |
if(Ret) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
252 |
MSG_ERR(0x1A02,"Erreur writeNetworkDictCallBackAI",Ret); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
253 |
return 1; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
254 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
255 |
|
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
256 |
static UNS8 read_consise_dcf_next_entry(CO_Data* d, UNS8 nodeId) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
257 |
{ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
258 |
UNS8 Ret; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
259 |
dcf_entry_t dcf_entry; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
260 |
if(!get_next_DCF_data(d, &dcf_entry, nodeId)) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
261 |
return 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
262 |
Ret = readNetworkDictCallbackAI(d, /* CO_Data* d*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
263 |
nodeId, /* UNS8 nodeId*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
264 |
dcf_entry.Index, /* UNS16 index*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
265 |
dcf_entry.Subindex, /* UNS8 subindex*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
266 |
0, /* UNS8 dataType*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
267 |
CheckSDOAndContinue,/* Callback*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
268 |
0); /* no block mode */ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
269 |
if(Ret) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
270 |
MSG_ERR(0x1A03,"Erreur readNetworkDictCallbackAI",Ret); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
271 |
return 1; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
272 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
273 |
|
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
274 |
void SaveNode(CO_Data* d, UNS8 nodeId) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
275 |
{ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
276 |
UNS8 Ret; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
277 |
UNS32 data=0x65766173; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
278 |
Ret = writeNetworkDictCallBackAI(d, /* CO_Data* d*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
279 |
nodeId, /* UNS8 nodeId*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
280 |
0x1010, /* UNS16 index*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
281 |
1, /* UNS8 subindex*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
282 |
4, /* UNS8 count*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
283 |
0, /* UNS8 dataType*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
284 |
(void *)&data,/* void *data*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
285 |
CheckSDOAndContinue,/* Callback*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
286 |
0, /* no endianize*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
287 |
0); /* no block mode */ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
288 |
if(Ret) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
289 |
MSG_ERR(0x1A04,"Erreur writeNetworkDictCallBackAI",Ret); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
290 |
} |