author | Christian Taedcke <hacking@taedcke.com> |
Mon, 23 Jan 2012 21:35:32 +0100 | |
changeset 707 | 4c52690c53fb |
parent 699 | c26ea35559f8 |
child 742 | 10e165c6743c |
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 |
|
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
53 |
/** |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
54 |
** @brief Function to be called from post_SlaveBootup |
207 | 55 |
** |
56 |
** @param d |
|
57 |
** @param nodeId |
|
208 | 58 |
*/ |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
59 |
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
|
60 |
{ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
61 |
if(d->dcf_status != DCF_STATUS_INIT) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
62 |
return 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
63 |
if((init_consise_dcf(d, nodeId) == 0) || (read_consise_dcf_next_entry(d, nodeId) == 0)){ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
64 |
/* Ask slave node to go in operational mode */ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
65 |
masterSendNMTstateChange (d, nodeId, NMT_Start_Node); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
66 |
d->NMTable[nodeId] = Operational; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
67 |
return 1; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
68 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
69 |
d->dcf_status = DCF_STATUS_READ_CHECK; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
70 |
return 2; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
71 |
} |
349 | 72 |
|
208 | 73 |
/** |
207 | 74 |
** |
75 |
** |
|
76 |
** @param d |
|
77 |
** @param nodeId |
|
669
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 |
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
|
80 |
{ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
81 |
UNS32 abortCode = 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
82 |
UNS8 buf[4], match = 0, node; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
83 |
UNS32 size=4; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
84 |
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
|
85 |
// printf("DCF_STATUS_READ_CHECK \n"); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
86 |
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
|
87 |
goto dcferror; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
88 |
/* Check if data received match the DCF */ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
89 |
if(size == d->dcf_size){ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
90 |
match = 1; |
671
06b30f679531
bug correction in dcf.c, an entry of only one byte was not checked
Mongo
parents:
669
diff
changeset
|
91 |
while(size--) |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
92 |
if(buf[size] != d->dcf_data[size]) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
93 |
match = 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
94 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
95 |
if(match) { |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
96 |
if(read_consise_dcf_next_entry(d, nodeId) == 0){ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
97 |
masterSendNMTstateChange (d, nodeId, NMT_Start_Node); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
98 |
d->NMTable[nodeId] = Operational; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
99 |
d->dcf_status = DCF_STATUS_INIT; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
100 |
/* Look for other nodes waiting to be started */ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
101 |
for(node = 0 ; node<NMT_MAX_NODE_ID ; node++){ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
102 |
if(d->NMTable[node] != Initialisation) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
103 |
continue; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
104 |
if(check_and_start_node(d, node) == 2) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
105 |
break; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
106 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
107 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
108 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
109 |
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
|
110 |
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
|
111 |
goto dcferror; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
112 |
d->dcf_status = DCF_STATUS_WRITE; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
113 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
114 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
115 |
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
|
116 |
// printf("DCF_STATUS_WRITE \n"); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
117 |
if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
118 |
goto dcferror; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
119 |
if(write_consise_dcf_next_entry(d, nodeId) == 0){ |
699 | 120 |
#ifdef DCF_SAVE_NODE |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
121 |
SaveNode(d, nodeId); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
122 |
d->dcf_status = DCF_STATUS_SAVED; |
699 | 123 |
#else //DCF_SAVE_NODE |
124 |
masterSendNMTstateChange (d, nodeId, NMT_Start_Node); |
|
125 |
d->NMTable[nodeId] = Operational; |
|
126 |
d->dcf_status = DCF_STATUS_INIT; |
|
127 |
/* Look for other nodes waiting to be started */ |
|
128 |
for(node = 0 ; node<NMT_MAX_NODE_ID ; node++){ |
|
129 |
if(d->NMTable[node] != Initialisation) |
|
130 |
continue; |
|
131 |
if(check_and_start_node(d, node) == 2) |
|
132 |
break; |
|
133 |
} |
|
134 |
#endif //DCF_SAVE_NODE |
|
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
135 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
136 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
137 |
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
|
138 |
// printf("DCF_STATUS_SAVED \n"); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
139 |
if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
140 |
goto dcferror; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
141 |
masterSendNMTstateChange (d, nodeId, NMT_Reset_Node); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
142 |
d->dcf_status = DCF_STATUS_INIT; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
143 |
d->NMTable[nodeId] = Unknown_state; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
144 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
145 |
return; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
146 |
dcferror: |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
147 |
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
|
148 |
MSG_WAR(0x2A02, "server node : ", nodeId); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
149 |
d->NMTable[nodeId] = Unknown_state; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
150 |
} |
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 |
/** |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
153 |
** |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
154 |
** |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
155 |
** @param d |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
156 |
** @param nodeId |
207 | 157 |
** |
158 |
** @return |
|
208 | 159 |
*/ |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
160 |
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
|
161 |
{ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
162 |
/* Fetch DCF OD entry */ |
320
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
163 |
UNS32 errorCode; |
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
164 |
ODCallback_t *Callback; |
699 | 165 |
UNS8* dcf; |
320
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
166 |
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
|
167 |
/* 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
|
168 |
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
|
169 |
/* Fix DCF table overflow */ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
170 |
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
|
171 |
/* If DCF empty... Nothing to do */ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
172 |
if(! d->dcf_odentry->pSubindex[nodeId].size) goto DCF_finish; |
699 | 173 |
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
|
174 |
// 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
|
175 |
d->dcf_cursor = dcf + 4; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
176 |
d->dcf_entries_count = 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
177 |
d->dcf_status = DCF_STATUS_INIT; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
178 |
return 1; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
179 |
DCF_finish: |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
180 |
return 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
181 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
182 |
|
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
183 |
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
|
184 |
{ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
185 |
UNS8* dcfend; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
186 |
UNS32 nb_entries; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
187 |
UNS32 szData; |
699 | 188 |
UNS8* dcf; |
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
189 |
if(!d->dcf_odentry) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
190 |
return 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
191 |
if(nodeId > d->dcf_odentry->bSubCount) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
192 |
return 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
193 |
szData = d->dcf_odentry->pSubindex[nodeId].size; |
699 | 194 |
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
|
195 |
nb_entries = UNS32_LE(*((UNS32*)dcf)); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
196 |
dcfend = dcf + szData; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
197 |
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
|
198 |
/* 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
|
199 |
* we cannot directly dereference d->dcf_cursor |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
200 |
* as UNS16 or UNS32 |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
201 |
* 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
|
202 |
#ifdef CANOPEN_BIG_ENDIAN |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
203 |
dcf_entry->Index = *(d->dcf_cursor++) << 8 | |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
204 |
*(d->dcf_cursor++); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
205 |
#else |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
206 |
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
|
207 |
d->dcf_cursor+=2; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
208 |
#endif |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
209 |
dcf_entry->Subindex = *(d->dcf_cursor++); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
210 |
#ifdef CANOPEN_BIG_ENDIAN |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
211 |
dcf_entry->Size = *(d->dcf_cursor++) << 24 | |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
212 |
*(d->dcf_cursor++) << 16 | |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
213 |
*(d->dcf_cursor++) << 8 | |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
214 |
*(d->dcf_cursor++); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
215 |
#else |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
216 |
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
|
217 |
d->dcf_cursor+=4; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
218 |
#endif |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
219 |
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
|
220 |
d->dcf_size = dcf_entry->Size; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
221 |
d->dcf_cursor += dcf_entry->Size; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
222 |
d->dcf_entries_count++; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
223 |
return 1; |
320
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
224 |
} |
349 | 225 |
return 0; |
226 |
} |
|
178 | 227 |
|
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
228 |
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
|
229 |
{ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
230 |
UNS8 Ret; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
231 |
dcf_entry_t dcf_entry; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
232 |
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
|
233 |
return 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
234 |
Ret = writeNetworkDictCallBackAI(d, /* CO_Data* d*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
235 |
nodeId, /* UNS8 nodeId*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
236 |
dcf_entry.Index, /* UNS16 index*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
237 |
dcf_entry.Subindex, /* UNS8 subindex*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
238 |
(UNS8)dcf_entry.Size, /* UNS8 count*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
239 |
0, /* UNS8 dataType*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
240 |
dcf_entry.Data,/* void *data*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
241 |
CheckSDOAndContinue,/* Callback*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
242 |
0, /* no endianize*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
243 |
0); /* no block mode */ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
244 |
if(Ret) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
245 |
MSG_ERR(0x1A02,"Erreur writeNetworkDictCallBackAI",Ret); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
246 |
return 1; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
247 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
248 |
|
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
249 |
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
|
250 |
{ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
251 |
UNS8 Ret; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
252 |
dcf_entry_t dcf_entry; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
253 |
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
|
254 |
return 0; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
255 |
Ret = readNetworkDictCallbackAI(d, /* CO_Data* d*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
256 |
nodeId, /* UNS8 nodeId*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
257 |
dcf_entry.Index, /* UNS16 index*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
258 |
dcf_entry.Subindex, /* UNS8 subindex*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
259 |
0, /* UNS8 dataType*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
260 |
CheckSDOAndContinue,/* Callback*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
261 |
0); /* no block mode */ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
262 |
if(Ret) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
263 |
MSG_ERR(0x1A03,"Erreur readNetworkDictCallbackAI",Ret); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
264 |
return 1; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
265 |
} |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
266 |
|
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
267 |
void SaveNode(CO_Data* d, UNS8 nodeId) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
268 |
{ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
269 |
UNS8 Ret; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
270 |
UNS32 data=0x65766173; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
271 |
Ret = writeNetworkDictCallBackAI(d, /* CO_Data* d*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
272 |
nodeId, /* UNS8 nodeId*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
273 |
0x1010, /* UNS16 index*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
274 |
1, /* UNS8 subindex*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
275 |
4, /* UNS8 count*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
276 |
0, /* UNS8 dataType*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
277 |
(void *)&data,/* void *data*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
278 |
CheckSDOAndContinue,/* Callback*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
279 |
0, /* no endianize*/ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
280 |
0); /* no block mode */ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
281 |
if(Ret) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
282 |
MSG_ERR(0x1A04,"Erreur writeNetworkDictCallBackAI",Ret); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
668
diff
changeset
|
283 |
} |