0
|
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 |
#include "pdo.h"
|
|
23 |
#include "objacces.h"
|
149
|
24 |
#include "canfestival.h"
|
0
|
25 |
|
|
26 |
/****************************************************************************/
|
|
27 |
UNS8 sendPDO(CO_Data* d, s_PDO pdo, UNS8 req)
|
|
28 |
{
|
|
29 |
UNS8 i;
|
|
30 |
if( d->nodeState == Operational ) {
|
|
31 |
Message m;
|
|
32 |
|
|
33 |
/* Message copy for sending */
|
71
|
34 |
m.cob_id.w = pdo.cobId & 0x7FF; /* Because the cobId is 11 bytes length */
|
0
|
35 |
if ( req == NOT_A_REQUEST ) {
|
|
36 |
UNS8 i;
|
|
37 |
m.rtr = NOT_A_REQUEST;
|
|
38 |
m.len = pdo.len;
|
71
|
39 |
/* memcpy(&m.data, &pdo.data, m.len); */
|
|
40 |
/* This Memcpy depends on packing structure. Avoid */
|
0
|
41 |
for (i = 0 ; i < pdo.len ; i++)
|
|
42 |
m.data[i] = pdo.data[i];
|
|
43 |
}
|
|
44 |
else {
|
|
45 |
m.rtr = REQUEST;
|
|
46 |
m.len = 0;
|
|
47 |
}
|
|
48 |
|
|
49 |
MSG_WAR(0x3901, "sendPDO cobId :", m.cob_id.w);
|
|
50 |
MSG_WAR(0x3902, " Nb octets : ", m.len);
|
|
51 |
for (i = 0 ; i < m.len ; i++) {
|
|
52 |
MSG_WAR(0x3903," data : ", m.data[i]);
|
|
53 |
}
|
|
54 |
|
149
|
55 |
return canSend(d->canHandle,&m);
|
71
|
56 |
} /* end if */
|
0
|
57 |
return 0xFF;
|
|
58 |
}
|
|
59 |
|
|
60 |
/***************************************************************************/
|
71
|
61 |
UNS8 PDOmGR(CO_Data* d, UNS32 cobId) /* PDO Manager */
|
0
|
62 |
{
|
|
63 |
UNS8 res;
|
|
64 |
UNS8 i;
|
|
65 |
s_PDO pdo;
|
|
66 |
|
|
67 |
MSG_WAR(0x3905, "PDOmGR",0);
|
|
68 |
|
|
69 |
/* if PDO is waiting for transmission,
|
|
70 |
preparation of the message to send */
|
|
71 |
pdo.cobId = cobId;
|
|
72 |
pdo.len = d->process_var.count;
|
71
|
73 |
/* memcpy(&(pdo.data), &(process_var.data), pdo.len); */
|
|
74 |
/* Ce memcpy devrait être portable */
|
0
|
75 |
for ( i = 0 ; i < pdo.len ; i++)
|
|
76 |
pdo.data[i] = d->process_var.data[i];
|
|
77 |
|
|
78 |
res = sendPDO(d, pdo, NOT_A_REQUEST);
|
|
79 |
|
|
80 |
return res;
|
|
81 |
}
|
|
82 |
|
201
|
83 |
#if 0
|
|
84 |
/*********************************************************************/
|
|
85 |
/* TODO : implement bit mapping */
|
|
86 |
/*********************************************************************/
|
|
87 |
|
0
|
88 |
UNS8 buildPDO(CO_Data* d, UNS16 index)
|
71
|
89 |
{ /* DO NOT USE MSG_ERR because the macro may send a PDO -> infinite loop if it fails. */
|
0
|
90 |
UNS16 ind;
|
|
91 |
UNS8 subInd;
|
|
92 |
|
71
|
93 |
UNS8 * pMappingCount = NULL; /* count of mapped objects... */
|
|
94 |
/* pointer to the var which is mapped to a pdo */
|
|
95 |
/* void * pMappedAppObject = NULL; */
|
|
96 |
/* pointer fo the var which holds the mapping parameter of an mapping entry */
|
0
|
97 |
UNS32 * pMappingParameter = NULL;
|
|
98 |
|
|
99 |
UNS8 Size;
|
|
100 |
UNS8 dataType;
|
|
101 |
UNS8 offset;
|
|
102 |
UNS16 offsetObjdict;
|
|
103 |
UNS16 offsetObjdictPrm;
|
|
104 |
UNS32 objDict;
|
|
105 |
|
|
106 |
subInd=(UNS8)0x00;
|
|
107 |
offset = 0x00;
|
|
108 |
ind = index - 0x1800;
|
|
109 |
|
|
110 |
MSG_WAR(0x3910,"Prepare PDO to send index :", index);
|
|
111 |
|
|
112 |
/* only operational state allows PDO transmission */
|
|
113 |
if( d->nodeState != Operational ) {
|
|
114 |
MSG_WAR(0x2911, "Unable to send the PDO (node not in OPERATIONAL mode). Node : ", index);
|
|
115 |
return 0xFF;
|
|
116 |
}
|
|
117 |
offsetObjdictPrm = d->firstIndex->PDO_TRS;
|
|
118 |
offsetObjdict = d->firstIndex->PDO_TRS_MAP;
|
|
119 |
|
|
120 |
if (offsetObjdictPrm && offsetObjdict)
|
|
121 |
{
|
|
122 |
/* get mapped objects number to transmit with this PDO */
|
|
123 |
pMappingCount = (d->objdict + offsetObjdict + ind)->pSubindex[0].pObject;
|
|
124 |
MSG_WAR(0x3912, "Nb maped objects : ",* pMappingCount);
|
|
125 |
MSG_WAR(0x3913, " at index : ", 0x1A00 + ind);
|
71
|
126 |
while (subInd < *pMappingCount) { /* Loop on mapped variables */
|
0
|
127 |
/* get mapping parameters */
|
|
128 |
pMappingParameter = (d->objdict + offsetObjdict + ind)->pSubindex[subInd + 1].pObject;
|
|
129 |
MSG_WAR(0x3914, "Get the mapping at index : ", (UNS16)0x1A00 + ind);
|
|
130 |
MSG_WAR(0x3915, " subIndex : ", subInd + 1);
|
|
131 |
MSG_WAR(0x3916, " value : ", *(UNS32 *)pMappingParameter);
|
71
|
132 |
/* Get the mapped variable */
|
201
|
133 |
Size = ((UNS8)(((*pMappingParameter) & 0xFF) >> 3));
|
|
134 |
objDict = getODentry(d, (UNS16)((*pMappingParameter) >> 16),
|
0
|
135 |
(UNS8)(((*pMappingParameter) >> 8 ) & 0x000000FF),
|
201
|
136 |
(void *)&d->process_var.data[offset], &Size, &dataType, 0 );
|
0
|
137 |
|
|
138 |
if (objDict != OD_SUCCESSFUL) {
|
|
139 |
MSG_WAR(0x2919, "error accessing to the mapped var : ", subInd + 1);
|
|
140 |
MSG_WAR(0x2920, " Mapped at index : ", (*pMappingParameter) >> 16);
|
90
|
141 |
MSG_WAR(0x2921, " subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF);
|
0
|
142 |
return 0xFF;
|
|
143 |
}
|
|
144 |
|
|
145 |
offset += Size;
|
|
146 |
d->process_var.count = offset;
|
|
147 |
subInd++;
|
71
|
148 |
}/* end Loop on mapped variables */
|
0
|
149 |
}
|
|
150 |
return 0;
|
|
151 |
}
|
201
|
152 |
#endif
|
0
|
153 |
/**************************************************************************/
|
|
154 |
UNS8 sendPDOrequest( CO_Data* d, UNS32 cobId )
|
|
155 |
{
|
|
156 |
UNS32 * pwCobId;
|
|
157 |
UNS16 offset;
|
|
158 |
UNS16 lastIndex;
|
|
159 |
UNS8 err;
|
|
160 |
|
|
161 |
MSG_WAR(0x3930, "sendPDOrequest ",0);
|
71
|
162 |
/* Sending the request only if the cobid have been found on the PDO receive */
|
|
163 |
/* part dictionary */
|
0
|
164 |
offset = d->firstIndex->PDO_RCV;
|
|
165 |
lastIndex = d->lastIndex->PDO_RCV;
|
|
166 |
if (offset)
|
|
167 |
while (offset <= lastIndex) {
|
|
168 |
/*get the CobId*/
|
|
169 |
pwCobId = d->objdict[offset].pSubindex[1].pObject;
|
|
170 |
|
|
171 |
if ( *pwCobId == cobId ) {
|
|
172 |
s_PDO pdo;
|
|
173 |
pdo.cobId = *pwCobId;
|
|
174 |
pdo.len = 0;
|
|
175 |
err = sendPDO(d, pdo, REQUEST);
|
|
176 |
return err;
|
|
177 |
}
|
|
178 |
offset++;
|
|
179 |
}
|
|
180 |
MSG_WAR(0x1931, "sendPDOrequest : COBID not found : ", cobId);
|
|
181 |
return 0xFF;
|
|
182 |
}
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
/***********************************************************************/
|
|
187 |
UNS8 proceedPDO(CO_Data* d, Message *m)
|
|
188 |
{
|
|
189 |
UNS8 numPdo;
|
71
|
190 |
UNS8 numMap; /* Number of the mapped varable */
|
0
|
191 |
UNS8 i;
|
71
|
192 |
UNS8 * pMappingCount = NULL; /* count of mapped objects... */
|
|
193 |
/* pointer to the var which is mapped to a pdo... */
|
|
194 |
/* void * pMappedAppObject = NULL; */
|
|
195 |
/* pointer fo the var which holds the mapping parameter of an mapping entry */
|
0
|
196 |
UNS32 * pMappingParameter = NULL;
|
71
|
197 |
UNS8 * pTransmissionType = NULL; /* pointer to the transmission type */
|
0
|
198 |
UNS32 * pwCobId = NULL;
|
|
199 |
UNS8 Size;
|
|
200 |
UNS8 dataType;
|
|
201 |
UNS8 offset;
|
|
202 |
UNS8 status;
|
|
203 |
UNS32 objDict;
|
|
204 |
UNS16 offsetObjdict;
|
|
205 |
UNS16 lastIndex;
|
|
206 |
status = state1;
|
201
|
207 |
|
0
|
208 |
MSG_WAR(0x3935, "proceedPDO, cobID : ", ((*m).cob_id.w & 0x7ff));
|
|
209 |
offset = 0x00;
|
|
210 |
numPdo = 0;
|
|
211 |
numMap = 0;
|
71
|
212 |
if((*m).rtr == NOT_A_REQUEST ) { /* The PDO received is not a request. */
|
0
|
213 |
offsetObjdict = d->firstIndex->PDO_RCV;
|
|
214 |
lastIndex = d->lastIndex->PDO_RCV;
|
201
|
215 |
|
0
|
216 |
/* study of all the PDO stored in the dictionary */
|
|
217 |
if(offsetObjdict)
|
|
218 |
while (offsetObjdict <= lastIndex) {
|
201
|
219 |
|
0
|
220 |
switch( status ) {
|
|
221 |
|
|
222 |
case state1: /* data are stored in process_var array */
|
71
|
223 |
/* memcpy(&(process_var.data), &m->data, (*m).len); */
|
|
224 |
/* Ce memcpy devrait être portable. */
|
0
|
225 |
for ( i = 0 ; i < m->len ; i++)
|
|
226 |
d->process_var.data[i] = m->data[i];
|
|
227 |
d->process_var.count = (*m).len;
|
|
228 |
|
|
229 |
status = state2;
|
|
230 |
break;
|
|
231 |
|
|
232 |
case state2:
|
|
233 |
/* get CobId of the dictionary correspondant to the received PDO */
|
201
|
234 |
pwCobId = d->objdict[offsetObjdict].pSubindex[1].pObject;
|
0
|
235 |
/* check the CobId coherance */
|
71
|
236 |
/*pwCobId is the cobId read in the dictionary at the state 3 */
|
0
|
237 |
if ( *pwCobId == (*m).cob_id.w ){
|
71
|
238 |
/* The cobId is recognized */
|
0
|
239 |
status = state4;
|
|
240 |
MSG_WAR(0x3936, "cobId found at index ", 0x1400 + numPdo);
|
|
241 |
break;
|
|
242 |
}
|
|
243 |
else {
|
71
|
244 |
/* cobId received does not match with those write in the dictionnary */
|
0
|
245 |
numPdo++;
|
|
246 |
offsetObjdict++;
|
|
247 |
status = state2;
|
|
248 |
break;
|
|
249 |
}
|
|
250 |
|
|
251 |
case state4: /* get mapped objects number */
|
71
|
252 |
/* The cobId of the message received has been found in the dictionnary. */
|
0
|
253 |
offsetObjdict = d->firstIndex->PDO_RCV_MAP;
|
|
254 |
lastIndex = d->lastIndex->PDO_RCV_MAP;
|
|
255 |
pMappingCount = (d->objdict + offsetObjdict + numPdo)->pSubindex[0].pObject;
|
|
256 |
numMap = 0;
|
|
257 |
while (numMap < *pMappingCount) {
|
201
|
258 |
UNS8 tmp[]= {0,0,0,0,0,0,0,0};
|
|
259 |
UNS8 ByteSize;
|
0
|
260 |
pMappingParameter = (d->objdict + offsetObjdict + numPdo)->pSubindex[numMap + 1].pObject;
|
|
261 |
if (pMappingParameter == NULL) {
|
|
262 |
MSG_ERR(0x1937, "Couldn't get mapping parameter : ", numMap + 1);
|
|
263 |
return 0xFF;
|
|
264 |
}
|
201
|
265 |
/* Get the addresse of the mapped variable. */
|
71
|
266 |
/* detail of *pMappingParameter : */
|
|
267 |
/* The 16 hight bits contains the index, the medium 8 bits contains the subindex, */
|
|
268 |
/* and the lower 8 bits contains the size of the mapped variable. */
|
201
|
269 |
|
|
270 |
Size = (UNS8)(*pMappingParameter);
|
|
271 |
|
|
272 |
/* copy bit per bit in little endian */
|
|
273 |
CopyBits(Size, (UNS8*)&d->process_var.data[offset>>3], offset%8, 0, ((UNS8*)tmp), 0, 0);
|
|
274 |
|
|
275 |
ByteSize = 1 + ((Size - 1) >> 3); /*1->8 => 1 ; 9->16 => 2, ... */
|
|
276 |
|
0
|
277 |
objDict = setODentry(d, (UNS16)((*pMappingParameter) >> 16),
|
|
278 |
(UNS8)(((*pMappingParameter) >> 8 ) & 0xFF),
|
201
|
279 |
tmp, &ByteSize, 0 );
|
|
280 |
|
0
|
281 |
if(objDict != OD_SUCCESSFUL) {
|
|
282 |
MSG_ERR(0x1938, "error accessing to the mapped var : ", numMap + 1);
|
|
283 |
MSG_WAR(0x2939, " Mapped at index : ", (*pMappingParameter) >> 16);
|
|
284 |
MSG_WAR(0x2940, " subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF);
|
|
285 |
return 0xFF;
|
|
286 |
}
|
|
287 |
|
|
288 |
MSG_WAR(0x3942, "Variable updated with value received by PDO cobid : ", m->cob_id.w);
|
|
289 |
MSG_WAR(0x3943, " Mapped at index : ", (*pMappingParameter) >> 16);
|
|
290 |
MSG_WAR(0x3944, " subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF);
|
71
|
291 |
/* MSG_WAR(0x3945, " data : ",*((UNS32 *)pMappedAppObject)); */
|
0
|
292 |
offset += Size;
|
|
293 |
numMap++;
|
71
|
294 |
} /* end loop while on mapped variables */
|
0
|
295 |
|
|
296 |
offset=0x00;
|
|
297 |
numMap = 0;
|
|
298 |
return 0;
|
|
299 |
|
71
|
300 |
}/* end switch status */
|
|
301 |
}/* end while */
|
|
302 |
}/* end if Donnees */
|
0
|
303 |
|
|
304 |
|
|
305 |
else if ((*m).rtr == REQUEST ){
|
|
306 |
MSG_WAR(0x3946, "Receive a PDO request cobId : ", m->cob_id.w);
|
|
307 |
status = state1;
|
|
308 |
offsetObjdict = d->firstIndex->PDO_TRS;
|
|
309 |
lastIndex = d->lastIndex->PDO_TRS;
|
|
310 |
if(offsetObjdict) while( offsetObjdict <= lastIndex ){
|
|
311 |
/* study of all PDO stored in the objects dictionary */
|
|
312 |
|
|
313 |
switch( status ){
|
|
314 |
|
|
315 |
case state1: /* check the CobId */
|
|
316 |
/* get CobId of the dictionary which match to the received PDO */
|
|
317 |
pwCobId = (d->objdict + offsetObjdict)->pSubindex[1].pObject;
|
|
318 |
if ( *pwCobId == (*m).cob_id.w ) {
|
|
319 |
status = state4;
|
|
320 |
break;
|
|
321 |
}
|
|
322 |
else {
|
|
323 |
numPdo++;
|
|
324 |
offsetObjdict++;
|
|
325 |
}
|
|
326 |
status = state1;
|
|
327 |
break;
|
|
328 |
|
|
329 |
|
|
330 |
case state4: /* check transmission type (after request?) */
|
|
331 |
pTransmissionType = d->objdict[offsetObjdict].pSubindex[2].pObject;
|
|
332 |
if ( (*pTransmissionType == TRANS_RTR) || (*pTransmissionType == TRANS_RTR_SYNC ) || (*pTransmissionType == TRANS_EVENT) ) {
|
|
333 |
status = state5;
|
|
334 |
break;
|
|
335 |
}
|
|
336 |
else {
|
71
|
337 |
/* The requested PDO is not to send on request. So, does nothing. */
|
0
|
338 |
MSG_WAR(0x2947, "PDO is not to send on request : ", m->cob_id.w);
|
|
339 |
return 0xFF;
|
|
340 |
}
|
|
341 |
|
|
342 |
case state5: /* get mapped objects number */
|
|
343 |
offsetObjdict = d->firstIndex->PDO_TRS_MAP;
|
|
344 |
lastIndex = d->lastIndex->PDO_TRS_MAP;
|
|
345 |
pMappingCount = (d->objdict + offsetObjdict + numPdo)->pSubindex[0].pObject;
|
|
346 |
numMap = 0;
|
|
347 |
while (numMap < *pMappingCount) {
|
|
348 |
pMappingParameter = (d->objdict + offsetObjdict + numPdo)->pSubindex[numMap + 1].pObject;
|
71
|
349 |
/* Get the mapped variable */
|
201
|
350 |
Size = ((UNS8)(((*pMappingParameter) & 0xFF) >> 3));
|
0
|
351 |
objDict = getODentry( d, (UNS16)((*pMappingParameter) >> (UNS8)16),
|
|
352 |
(UNS8)(( (*pMappingParameter) >> (UNS8)8 ) & 0xFF),
|
|
353 |
(void *)&d->process_var.data[offset], &Size, &dataType, 0 );
|
|
354 |
if (objDict != OD_SUCCESSFUL) {
|
|
355 |
MSG_ERR(0x1948, "error accessing to the mapped var : ", numMap + 1);
|
|
356 |
MSG_WAR(0x2949, " Mapped at index : ", (*pMappingParameter) >> 16);
|
|
357 |
MSG_WAR(0x2950, " subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF);
|
|
358 |
return 0xFF;
|
|
359 |
}
|
|
360 |
offset += (UNS8) (((*pMappingParameter) & 0xFF) >> 3);
|
|
361 |
d->process_var.count = offset;
|
|
362 |
numMap++;
|
|
363 |
|
71
|
364 |
} /* end while */
|
|
365 |
PDOmGR( d, *pwCobId ); /* Transmit the PDO */
|
0
|
366 |
return 0;
|
|
367 |
|
71
|
368 |
}/* end switch status */
|
|
369 |
}/* end while */
|
|
370 |
}/* end if Requete */
|
0
|
371 |
|
|
372 |
return 0;
|
|
373 |
}
|
|
374 |
|
|
375 |
|
201
|
376 |
void CopyBits(UNS8 NbBits, UNS8* SrcByteIndex, UNS8 SrcBitIndex, UNS8 SrcBigEndian, UNS8* DestByteIndex, UNS8 DestBitIndex, UNS8 DestBigEndian)
|
|
377 |
{
|
|
378 |
//This loop copy as many bits that it can each time, crossing successively bytes
|
|
379 |
// boundaries from LSB to MSB.
|
|
380 |
while(NbBits > 0)
|
|
381 |
{
|
|
382 |
// Bit missalignement between src and dest
|
|
383 |
INTEGER8 Vect = DestBitIndex - SrcBitIndex;
|
|
384 |
|
|
385 |
// We can now get src and align it to dest
|
|
386 |
UNS8 Aligned = Vect>0 ? *SrcByteIndex << Vect : *SrcByteIndex >> -Vect;
|
|
387 |
|
|
388 |
// Compute the nb of bit we will be able to copy
|
|
389 |
UNS8 BoudaryLimit = (Vect>0 ? 8 - DestBitIndex : 8 - SrcBitIndex );
|
|
390 |
UNS8 BitsToCopy = BoudaryLimit > NbBits ? NbBits : BoudaryLimit;
|
|
391 |
|
|
392 |
// Create a mask that will serve in:
|
|
393 |
UNS8 Mask = ((0xff << (DestBitIndex + BitsToCopy)) | (0xff >> (8 - DestBitIndex)));
|
|
394 |
|
|
395 |
// - Filtering src
|
|
396 |
UNS8 Filtered = Aligned & ~Mask;
|
|
397 |
|
|
398 |
// - and erase bits where we write, preserve where we don't
|
|
399 |
*DestByteIndex &= Mask;
|
|
400 |
|
|
401 |
// Then write.
|
|
402 |
*DestByteIndex |= Filtered ;
|
|
403 |
|
|
404 |
//Compute next time cursors for src
|
|
405 |
if((SrcBitIndex += BitsToCopy)>7) // cross boundary ?
|
|
406 |
{
|
|
407 |
SrcBitIndex = 0; // First bit
|
|
408 |
SrcByteIndex += (SrcBigEndian ? -1 : 1); // Next byte
|
|
409 |
}
|
|
410 |
|
|
411 |
//Compute next time cursors for dest
|
|
412 |
if((DestBitIndex += BitsToCopy)>7)
|
|
413 |
{
|
|
414 |
DestBitIndex = 0; // First bit
|
|
415 |
DestByteIndex += (DestBigEndian ? -1 : 1);// Next byte
|
|
416 |
}
|
|
417 |
|
|
418 |
//And decrement counter.
|
|
419 |
NbBits -= BitsToCopy;
|
|
420 |
}
|
|
421 |
|
|
422 |
}
|
0
|
423 |
|
71
|
424 |
#if 0
|
|
425 |
|
0
|
426 |
/*********************************************************************/
|
|
427 |
/* TODO : reimplement this using CallBacks */
|
|
428 |
/*********************************************************************/
|
71
|
429 |
|
0
|
430 |
UNS8 sendPDOevent( CO_Data* d, void * variable )
|
71
|
431 |
{ /* DO NOT USE MSG_ERR because the macro may send a PDO -> infinite loop if it fails. */
|
0
|
432 |
UNS32 objDict = 0;
|
|
433 |
UNS8 ind, sub_ind;
|
|
434 |
UNS8 status;
|
|
435 |
UNS8 offset;
|
|
436 |
UNS8 * pMappingCount = NULL;
|
|
437 |
UNS32 * pMappingParameter = NULL;
|
|
438 |
void * pMappedAppObject = NULL;
|
71
|
439 |
UNS8 * pTransmissionType = NULL; /* pointer to the transmission type */
|
0
|
440 |
UNS32 * pwCobId = NULL;
|
|
441 |
UNS8 * pSize;
|
|
442 |
UNS8 size;
|
|
443 |
UNS8 dataType;
|
|
444 |
UNS16 offsetObjdict;
|
|
445 |
UNS16 offsetObjdictPrm;
|
|
446 |
UNS16 lastIndex;
|
|
447 |
UNS8 numMap;
|
|
448 |
ind = 0x00;
|
|
449 |
sub_ind = 1;
|
|
450 |
offset = 0x00;
|
|
451 |
pSize = &size;
|
|
452 |
status = state1;
|
|
453 |
|
71
|
454 |
/* look for the index and subindex where the variable is mapped */
|
|
455 |
/* Then, send the pdo which contains the variable. */
|
0
|
456 |
|
|
457 |
MSG_WAR (0x3960, "sendPDOevent", 0);
|
|
458 |
offsetObjdictPrm = d->firstIndex->PDO_TRS;
|
|
459 |
|
|
460 |
offsetObjdict = d->firstIndex->PDO_TRS_MAP;
|
|
461 |
lastIndex = d->lastIndex->PDO_TRS_MAP;
|
|
462 |
|
|
463 |
if (offsetObjdictPrm && offsetObjdict)
|
71
|
464 |
/* Loop on PDO Transmit */
|
0
|
465 |
while(offsetObjdict <= lastIndex){
|
71
|
466 |
/* Check the transmission mode */
|
0
|
467 |
pTransmissionType = d->objdict[offsetObjdictPrm].pSubindex[2].pObject;
|
|
468 |
if (*pTransmissionType != TRANS_EVENT) {
|
|
469 |
ind++;
|
|
470 |
offsetObjdict++;
|
|
471 |
offsetObjdictPrm++;
|
|
472 |
continue;
|
|
473 |
}
|
201
|
474 |
pMappingCount = d->objdict[offsetObjdict].pSubindex[0].pObject;
|
71
|
475 |
numMap = 1; /* mapped variable */
|
0
|
476 |
while (numMap <= *pMappingCount) {
|
|
477 |
pMappingParameter = d->objdict[offsetObjdict].pSubindex[numMap].pObject;
|
71
|
478 |
/* Get the variable */
|
0
|
479 |
objDict = getODentry( d,
|
|
480 |
(UNS16)((*pMappingParameter) >> 16),
|
|
481 |
(UNS8)(( (*pMappingParameter) >> (UNS8)8 ) & (UNS32)0x000000FF),
|
|
482 |
(void * *)&pMappedAppObject, pSize, &dataType, 0 );
|
|
483 |
if( objDict != OD_SUCCESSFUL ) {
|
|
484 |
MSG_WAR(0x2961, "Error in dict. at index : ",
|
|
485 |
(*pMappingParameter) >> (UNS8)16);
|
|
486 |
|
|
487 |
MSG_WAR(0x2962, " subindex : ",
|
|
488 |
((*pMappingParameter) >> (UNS8)8 ) & (UNS32)0x000000FF);
|
|
489 |
return 0xFF;
|
|
490 |
}
|
|
491 |
if (pMappedAppObject == variable) { // Variable found !
|
|
492 |
MSG_WAR(0x3963, "Variable to send found at index : ",
|
|
493 |
(*pMappingParameter) >> 16);
|
|
494 |
MSG_WAR(0x3964, " subIndex : ",
|
|
495 |
((*pMappingParameter) >> 8 ) & 0x000000FF);
|
|
496 |
buildPDO(d, 0x1800 + ind);
|
71
|
497 |
/* Get the cobId */
|
0
|
498 |
pwCobId = d->objdict[offsetObjdictPrm].pSubindex[1].pObject;
|
71
|
499 |
PDOmGR( d, *pwCobId ); /* Send the PDO */
|
0
|
500 |
return 0;
|
|
501 |
}
|
|
502 |
numMap++;
|
71
|
503 |
} /* End loop on mapped variable */
|
0
|
504 |
ind++;
|
|
505 |
offsetObjdict++;
|
|
506 |
offsetObjdictPrm++;
|
71
|
507 |
} /* End loop while on PDO */
|
0
|
508 |
|
|
509 |
MSG_WAR(0x2965, "Variable not found in a PDO to send on event", 0);
|
|
510 |
return 0xFF;
|
|
511 |
|
|
512 |
}
|
71
|
513 |
#endif
|