]> rtime.felk.cvut.cz Git - CanFestival-3.git/blob - src/dcf.c
CleanUp and minor fixes
[CanFestival-3.git] / src / dcf.c
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 #include "objacces.h"
24 #include "sdo.h"
25 #include "dcf.h"
26
27 const indextable *ptrTable;
28
29 static void CheckSDOAndContinue(CO_Data* d, UNS8 nodeId)
30 {
31         UNS32 abortCode;
32         
33         if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
34         {
35                 MSG_ERR(0x1A01, "SDO error in consise DCF", abortCode);
36                 MSG_WAR(0x2A02, "server node : ", nodeId);
37         }
38
39         closeSDOtransfer(d, nodeId, SDO_CLIENT);
40         decompo_dcf(d,nodeId);
41 }
42
43 UNS32 decompo_dcf(CO_Data* d,UNS8 nodeId)
44 {
45                 UNS32 errorCode;
46                 UNS16 target_Index;
47                 UNS8 target_Subindex;
48                 UNS32 target_Size;
49                 UNS32 res;
50                 ODCallback_t *Callback;
51
52                 ptrTable = (*d->scanIndexOD)(0x1F22, &errorCode, &Callback);
53                 if (errorCode != OD_SUCCESSFUL)
54                 {
55                 return errorCode;
56                 }
57
58                 /*Loop on all Nodes supported in DCF subindexes*/
59                 while (nodeId < ptrTable->bSubCount){
60                         UNS32 nb_targets;
61                         
62                         UNS8 szData = ptrTable->pSubindex[nodeId].size;
63                         void* dcfend;
64                         
65                         {
66                                 void* dcf = *((void**)ptrTable->pSubindex[nodeId].pObject);
67                                 dcfend = dcf + szData;
68                                 if (!d->dcf_cursor)     {
69                                         d->dcf_cursor = dcf + 4;
70                                         d->dcf_count_targets = 0;
71                                 }
72         #ifdef CANOPEN_BIG_ENDIAN
73                                 nb_targets = ((UNS8*)d->dcf++) | ((UNS8*)d->dcf++) << 8 | ((UNS8*)d->dcf++) << 16 | ((UNS8*)d->dcf++) << 24;
74         #else
75                                 nb_targets = *((UNS32*)dcf);
76         #endif
77                         }
78                         
79                         // condition on consise DCF string for NodeID, if big enough
80                         if(d->dcf_cursor + 7 < dcfend && d->dcf_count_targets < nb_targets)
81                         {
82                                 // pointer to the DCF string for NodeID
83         #ifdef CANOPEN_BIG_ENDIAN
84                                 target_Index = ((UNS8*)d->dcf_cursor++) | ((UNS8*)d->dcf_cursor++) << 8;
85                                 target_Subindex = ((UNS8*)d->dcf_cursor++);
86                                 target_Size = ((UNS8*)d->dcf_cursor++) | ((UNS8*)d->dcf_cursor++) << 8 | ((UNS8*)d->dcf_cursor++) << 16 | ((UNS8*)d->dcf_cursor++) << 24;
87         #else
88                                 target_Index = *((UNS16*)(d->dcf_cursor)); d->dcf_cursor += 2;
89                                 target_Subindex = *((UNS8*)(d->dcf_cursor++));
90                                 target_Size = *((UNS32*)(d->dcf_cursor)); d->dcf_cursor += 4;
91         #endif
92                                 
93                                         /*printf("Master : ConfigureSlaveNode %2.2x (Concise DCF)\n",nodeId);*/
94                                         res = writeNetworkDictCallBack(d, /*CO_Data* d*/
95                                                         nodeId, /*UNS8 nodeId*/
96                                                         target_Index, /*UNS16 index*/
97                                                         target_Subindex, /*UNS8 subindex*/
98                                                         target_Size, /*UNS8 count*/
99                                                         0, /*UNS8 dataType*/
100                                                         d->dcf_cursor,/*void *data*/
101                                                         CheckSDOAndContinue); /*SDOCallback_t Callback*/                                        
102                                         /*Push d->dcf_cursor to the end of data*/
103                                         
104                                         d->dcf_cursor += target_Size;
105                                         d->dcf_count_targets++;
106                                         
107                                         return ;
108                         }                       
109                                 nodeId++;
110                                 d->dcf_cursor = NULL;
111                 }
112                 /* Switch Master to preOperational state */
113                 (*d->preOperational)();
114                 
115 }