]> rtime.felk.cvut.cz Git - CanFestival-3.git/blob - src/dcf.c
Some fixes suggested by Luis Jiménez, plus some minor enhancements in DCF.
[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
36
37 #include "objacces.h"
38 #include "sdo.h"
39 #include "dcf.h"
40 #include "sysdep.h"
41
42 extern UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
43                                UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize);
44
45
46 /**
47 **
48 **
49 ** @param d
50 ** @param nodeId
51 */
52 static void CheckSDOAndContinue(CO_Data* d, UNS8 nodeId)
53 {
54   UNS32 abortCode;
55
56   if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
57     {
58       MSG_ERR(0x1A01, "SDO error in consise DCF", abortCode);
59       MSG_WAR(0x2A02, "server node : ", nodeId);
60     }
61
62   closeSDOtransfer(d, nodeId, SDO_CLIENT);
63   send_consise_dcf(d,nodeId);
64 }
65
66 /**
67 **
68 **
69 ** @param d
70 ** @param nodeId
71 **
72 ** @return
73 */
74 void send_consise_dcf(CO_Data* d,UNS8 nodeId)
75 {
76   /* Fetch DCF OD entry, if not already done */
77   if(!d->dcf_odentry)
78   {
79     UNS32 errorCode;
80     ODCallback_t *Callback;
81     d->dcf_odentry = (*d->scanIndexOD)(0x1F22, &errorCode, &Callback);
82     /* If DCF entry do not exist... Nothing to do.*/
83     if (errorCode != OD_SUCCESSFUL) goto DCF_finish;
84   }
85
86   /* Loop on all DCF subindexes, corresponding to nodes ID */
87   while (nodeId < d->dcf_odentry->bSubCount){
88     UNS32 nb_entries;
89
90     UNS8 szData = d->dcf_odentry->pSubindex[nodeId].size;
91     UNS8* dcfend;
92
93     {
94       UNS8* dcf = *((UNS8**)d->dcf_odentry->pSubindex[nodeId].pObject);
95       dcfend = dcf + szData;
96       if (!d->dcf_cursor){
97         d->dcf_cursor = (UNS8*)dcf + 4;
98         d->dcf_entries_count = 0;
99       }
100       nb_entries = UNS32_LE(*((UNS32*)dcf));
101     }
102
103     /* condition on consise DCF string for NodeID, if big enough */
104     if((UNS8*)d->dcf_cursor + 7 < (UNS8*)dcfend && d->dcf_entries_count < nb_entries)
105       {
106         UNS16 target_Index;
107         UNS8 target_Subindex;
108         UNS32 target_Size;
109
110         /* pointer to the DCF string for NodeID */
111         target_Index = UNS16_LE(*((UNS16*)(d->dcf_cursor))); d->dcf_cursor += 2;
112         target_Subindex = *((UNS8*)((UNS8*)d->dcf_cursor++));
113         target_Size = UNS32_LE(*((UNS32*)(d->dcf_cursor))); d->dcf_cursor += 4;
114
115         _writeNetworkDict(d, /* CO_Data* d*/
116                                 nodeId, /* UNS8 nodeId*/
117                                 target_Index, /* UNS16 index*/
118                                 target_Subindex, /* UNS8 subindex*/
119                                 target_Size, /* UNS8 count*/
120                                 0, /* UNS8 dataType*/
121                                 d->dcf_cursor,/* void *data*/
122                                 CheckSDOAndContinue,/* SDOCallback_t
123                                                       Callback*/
124                                 0); /* no endianize*/
125         /* Push d->dcf_cursor to the end of data*/
126
127         d->dcf_cursor += target_Size;
128         d->dcf_entries_count++;
129
130         /* send_consise_dcf will be called by CheckSDOAndContinue for next DCF entry*/
131         return;
132       }
133     nodeId++;
134     d->dcf_cursor = NULL;
135   }
136  DCF_finish:
137   /*  Switch Master to preOperational state */
138   (*d->preOperational)();
139 }