]> rtime.felk.cvut.cz Git - CanFestival-3.git/blob - src/dcf.c
Manual and Documentation finish
[CanFestival-3.git] / src / dcf.c
1 /*
2   This file is part of CanFestival, a library implementing CanOpen
3   Stack.
4
5   Copyright (C): Edouard TISSERANT and Francis DUPIN
6
7   See COPYING file for copyrights details.
8
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.
13
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.
18
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
23 */
24
25
26 /**
27 ** @file   dcf.c
28 ** @author Edouard TISSERANT and Francis DUPIN
29 ** @date   Mon Jun  4 17:06:12 2007
30 **
31 ** @brief EXEMPLE OF SOMMARY
32 **
33 **
34 */
35 #include "objacces.h"
36 #include "sdo.h"
37 #include "dcf.h"
38 #include "sysdep.h"
39
40
41 /**
42 **
43 **
44 ** @param d fuck fuck fuck
45 ** @param nodeId
46 ** @param index
47 ** @param subIndex
48 ** @param count
49 ** @param dataType
50 ** @param data
51 ** @param Callback
52 ** @param endianize
53 */
54 extern UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
55                                UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize);
56
57 const indextable *ptrTable;
58
59 /**
60 **
61 **
62 ** @param d
63 ** @param nodeId
64 */
65 static void CheckSDOAndContinue(CO_Data* d, UNS8 nodeId)
66 {
67   UNS32 abortCode;
68
69   if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
70     {
71       MSG_ERR(0x1A01, "SDO error in consise DCF", abortCode);
72       MSG_WAR(0x2A02, "server node : ", nodeId);
73     }
74
75   closeSDOtransfer(d, nodeId, SDO_CLIENT);
76   decompo_dcf(d,nodeId);
77 }
78
79 /**
80 **
81 **
82 ** @param d
83 ** @param nodeId
84 **
85 ** @return
86 */
87 UNS32 decompo_dcf(CO_Data* d,UNS8 nodeId)
88 {
89   UNS32 errorCode;
90   UNS16 target_Index;
91   UNS8 target_Subindex;
92   UNS32 target_Size;
93   UNS32 res;
94   ODCallback_t *Callback;
95
96   ptrTable = (*d->scanIndexOD)(0x1F22, &errorCode, &Callback);
97   if (errorCode != OD_SUCCESSFUL)
98     {
99       return errorCode;
100     }
101
102   /** Loop on all Nodes supported in DCF subindexes*/
103   while (nodeId < ptrTable->bSubCount){
104     UNS32 nb_targets;
105
106     UNS8 szData = ptrTable->pSubindex[nodeId].size;
107     UNS8* dcfend;
108
109     {
110       UNS8* dcf = *((UNS8**)ptrTable->pSubindex[nodeId].pObject);
111       dcfend = dcf + szData;
112       if (!d->dcf_cursor){
113         d->dcf_cursor = (UNS8*)dcf + 4;
114         d->dcf_count_targets = 0;
115       }
116       nb_targets = UNS32_LE(*((UNS32*)dcf));
117     }
118
119     /** condition on consise DCF string for NodeID, if big enough */
120     if((UNS8*)d->dcf_cursor + 7 < (UNS8*)dcfend && d->dcf_count_targets < nb_targets)
121       {
122         /** pointer to the DCF string for NodeID */
123         target_Index = UNS16_LE(*((UNS16*)(d->dcf_cursor))); d->dcf_cursor += 2;
124         target_Subindex = *((UNS8*)(((UNS8*)d->dcf_cursor)++));
125         target_Size = UNS32_LE(*((UNS32*)(d->dcf_cursor))); d->dcf_cursor += 4;
126
127         /* printf("Master : ConfigureSlaveNode %2.2x (Concise
128           DCF)\n",nodeId);*/
129         res = _writeNetworkDict(d, /** CO_Data* d*/
130                                 nodeId, /** UNS8 nodeId*/
131                                 target_Index, /** UNS16 index*/
132                                 target_Subindex, /** UNS8 subindex*/
133                                 target_Size, /** UNS8 count*/
134                                 0, /** UNS8 dataType*/
135                                 d->dcf_cursor,/** void *data*/
136                                 CheckSDOAndContinue,/** SDOCallback_t
137                                                       Callback*/
138                                 0); /** no endianize*/
139         /** Push d->dcf_cursor to the end of data*/
140
141         d->dcf_cursor += target_Size;
142         d->dcf_count_targets++;
143
144         return ;
145       }
146     nodeId++;
147     d->dcf_cursor = NULL;
148   }
149   /**  Switch Master to preOperational state */
150   (*d->preOperational)();
151
152 }