nico@207: nico@207: nico@215: CanFestival: src/pdo.c Source File nico@207: nico@207: nico@207: nico@207: nico@207:
nico@207:
nico@207:
nico@207:
nico@215: nico@215:

pdo.c

Go to the documentation of this file.
00001 /*
nico@210: 00002   This file is part of CanFestival, a library implementing CanOpen
nico@210: 00003   Stack.
nico@210: 00004 
nico@210: 00005   Copyright (C): Edouard TISSERANT and Francis DUPIN
nico@210: 00006 
nico@210: 00007   See COPYING file for copyrights details.
nico@210: 00008 
nico@210: 00009   This library is free software; you can redistribute it and/or
nico@210: 00010   modify it under the terms of the GNU Lesser General Public
nico@210: 00011   License as published by the Free Software Foundation; either
nico@210: 00012   version 2.1 of the License, or (at your option) any later version.
nico@210: 00013 
nico@210: 00014   This library is distributed in the hope that it will be useful,
nico@210: 00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
nico@210: 00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
nico@210: 00017   Lesser General Public License for more details.
nico@210: 00018 
nico@210: 00019   You should have received a copy of the GNU Lesser General Public
nico@210: 00020   License along with this library; if not, write to the Free Software
nico@210: 00021   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
nico@210: 00022   USA
nico@210: 00023 */
nico@215: 00024 #include "pdo.h"
nico@215: 00025 #include "objacces.h"
nico@215: 00026 #include "canfestival.h"
nico@210: 00027 
nico@215: 00037 UNS8 sendPDO(CO_Data* d, s_PDO pdo, UNS8 req)
nico@210: 00038 {
nico@215: 00039   UNS8 i;
nico@215: 00040   if( d->nodeState == Operational ) {
nico@215: 00041     Message m;
nico@210: 00042 
nico@215: 00043     /* Message copy for sending */
nico@215: 00044     m.cob_id.w = pdo.cobId & 0x7FF; /* Because the cobId is 11 bytes
nico@215: 00045                                       length */
nico@215: 00046     if ( req == NOT_A_REQUEST ) {
nico@215: 00047       UNS8 i;
nico@215: 00048       m.rtr = NOT_A_REQUEST;
nico@215: 00049       m.len = pdo.len;
nico@215: 00050       /* memcpy(&m.data, &pdo.data, m.len); */
nico@215: 00051       /* This Memcpy depends on packing structure. Avoid */
nico@215: 00052       for (i = 0 ; i < pdo.len ; i++)
nico@215: 00053         m.data[i] = pdo.data[i];
nico@210: 00054     }
nico@210: 00055     else {
nico@215: 00056       m.rtr = REQUEST;
nico@215: 00057       m.len = 0;
nico@210: 00058     }
nico@207: 00059 
nico@215: 00060     MSG_WAR(0x3901, "sendPDO cobId :", m.cob_id.w);
nico@215: 00061     MSG_WAR(0x3902,  "     Nb octets  : ",  m.len);
nico@215: 00062     for (i = 0 ; i < m.len ; i++) {
nico@215: 00063       MSG_WAR(0x3903,"           data : ", m.data[i]);
nico@210: 00064     }
nico@210: 00065 
nico@215: 00066     return canSend(d->canHandle,&m);
nico@215: 00067   } /* end if */
nico@210: 00068   return 0xFF;
nico@210: 00069 }
nico@210: 00070 
nico@215: 00079 UNS8 PDOmGR(CO_Data* d, UNS32 cobId)
nico@210: 00080 {
nico@215: 00081   UNS8 res;
nico@215: 00082   UNS8 i;
nico@215: 00083   s_PDO pdo;
nico@210: 00084 
nico@215: 00085   MSG_WAR(0x3905, "PDOmGR",0);
nico@210: 00086 
nico@215: 00087   /* if PDO is waiting for transmission,
nico@215: 00088     preparation of the message to send */
nico@215: 00089   pdo.cobId = cobId;
nico@215: 00090   pdo.len =  d->process_var.count;
nico@215: 00091   /* memcpy(&(pdo.data), &(process_var.data), pdo.len); */
nico@210: 00092      /* Ce memcpy devrait tre portable */
nico@215: 00093     for ( i = 0 ; i < pdo.len ; i++) 
nico@215: 00094       pdo.data[i] = d->process_var.data[i];
nico@210: 00095 
nico@215: 00096     res = sendPDO(d, pdo, NOT_A_REQUEST);
nico@210: 00097 
nico@210: 00098     return res;
nico@210: 00099 }
nico@210: 00100 
nico@210: 00101 #if 0
nico@210: 00102 /*********************************************************************/
nico@210: 00103 /* TODO : implement bit mapping                                                  */
nico@210: 00104 /*********************************************************************/
nico@207: 00105 
nico@215: 00106 UNS8 buildPDO(CO_Data* d, UNS16 index)
nico@210: 00107 { /* DO NOT USE MSG_ERR because the macro may send a PDO -> infinite loop if it fails. */       
nico@215: 00108   UNS16 ind;
nico@215: 00109   UNS8      subInd;
nico@210: 00110 
nico@215: 00111   UNS8 *     pMappingCount = NULL;      /* count of mapped objects... */
nico@210: 00112   /* pointer to the var which is mapped to a pdo */
nico@210: 00113 /*  void *     pMappedAppObject = NULL;  */
nico@210: 00114   /* pointer fo the var which holds the mapping parameter of an mapping entry  */ 
nico@210: 00115  
nico@215: 00116   UNS32 *    pMappingParameter = NULL;
nico@210: 00117 
nico@215: 00118   UNS8      Size;
nico@215: 00119   UNS8      dataType;
nico@215: 00120   UNS8      offset;
nico@215: 00121   UNS16     offsetObjdict;
nico@215: 00122   UNS16     offsetObjdictPrm;
nico@215: 00123   UNS32     objDict;
nico@210: 00124 
nico@215: 00125   subInd=(UNS8)0x00;
nico@210: 00126   offset = 0x00;
nico@210: 00127   ind = index - 0x1800;
nico@210: 00128 
nico@215: 00129   MSG_WAR(0x3910,"Prepare PDO to send index :", index);
nico@210: 00130 
nico@215: 00131   /* only operational state allows PDO transmission */
nico@215: 00132   if( d->nodeState != Operational ) {
nico@215: 00133     MSG_WAR(0x2911, "Unable to send the PDO (node not in OPERATIONAL mode). Node : ", index);
nico@210: 00134     return 0xFF;
nico@210: 00135   }
nico@215: 00136   offsetObjdictPrm = d->firstIndex->PDO_TRS;
nico@215: 00137   offsetObjdict = d->firstIndex->PDO_TRS_MAP;
nico@210: 00138 
nico@210: 00139   if (offsetObjdictPrm && offsetObjdict)
nico@210: 00140     {
nico@215: 00141       /* get mapped objects number to transmit with this PDO */
nico@215: 00142       pMappingCount = (d->objdict + offsetObjdict + ind)->pSubindex[0].pObject;
nico@215: 00143       MSG_WAR(0x3912, "Nb maped objects : ",* pMappingCount);
nico@215: 00144       MSG_WAR(0x3913, "        at index : ", 0x1A00 + ind);
nico@215: 00145       while (subInd < *pMappingCount) { /* Loop on mapped variables */
nico@215: 00146         /* get mapping parameters */
nico@215: 00147         pMappingParameter = (d->objdict + offsetObjdict + ind)->pSubindex[subInd + 1].pObject;
nico@215: 00148         MSG_WAR(0x3914, "Get the mapping      at index : ", (UNS16)0x1A00 + ind);
nico@215: 00149         MSG_WAR(0x3915, "                     subIndex : ", subInd + 1);
nico@215: 00150         MSG_WAR(0x3916, "                     value    : ", *(UNS32 *)pMappingParameter);
nico@215: 00151         /* Get the mapped variable */
nico@215: 00152         Size = ((UNS8)(((*pMappingParameter) & 0xFF) >> 3));
nico@215: 00153         objDict = getODentry(d, (UNS16)((*pMappingParameter) >> 16),
nico@215: 00154                              (UNS8)(((*pMappingParameter) >> 8 ) & 0x000000FF),
nico@215: 00155                              (void *)&d->process_var.data[offset], &Size, &dataType, 0 );
nico@210: 00156 
nico@215: 00157         if (objDict != OD_SUCCESSFUL) {
nico@215: 00158           MSG_WAR(0x2919, "error accessing to the mapped var : ", subInd + 1);
nico@215: 00159           MSG_WAR(0x2920, "         Mapped at index : ", (*pMappingParameter) >> 16);
nico@215: 00160           MSG_WAR(0x2921, "                subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF);
nico@210: 00161           return 0xFF;
nico@210: 00162         }
nico@210: 00163 
nico@210: 00164         offset += Size;
nico@215: 00165         d->process_var.count = offset;
nico@210: 00166         subInd++;
nico@215: 00167       }/* end Loop on mapped variables  */
nico@210: 00168     }
nico@210: 00169   return 0;
nico@210: 00170 }
nico@210: 00171 #endif
nico@210: 00172 
nico@215: 00181 UNS8 sendPDOrequest( CO_Data* d, UNS32 cobId )
nico@210: 00182 {
nico@215: 00183   UNS32 * pwCobId;
nico@215: 00184   UNS16          offset;
nico@215: 00185   UNS16          lastIndex;
nico@215: 00186   UNS8           err;
nico@210: 00187 
nico@215: 00188   MSG_WAR(0x3930, "sendPDOrequest ",0);
nico@215: 00189   /* Sending the request only if the cobid have been found on the PDO
nico@215: 00190      receive */
nico@215: 00191   /* part dictionary */
nico@215: 00192   offset = d->firstIndex->PDO_RCV;
nico@215: 00193   lastIndex = d->lastIndex->PDO_RCV;
nico@210: 00194   if (offset)
nico@210: 00195     while (offset <= lastIndex) {
nico@215: 00196       /* get the CobId*/
nico@215: 00197       pwCobId = d->objdict[offset].pSubindex[1].pObject;
nico@210: 00198 
nico@210: 00199       if ( *pwCobId  == cobId ) {
nico@215: 00200         s_PDO pdo;
nico@215: 00201         pdo.cobId = *pwCobId;
nico@215: 00202         pdo.len = 0;
nico@215: 00203         err  = sendPDO(d, pdo, REQUEST);
nico@210: 00204         return err;
nico@210: 00205       }
nico@210: 00206       offset++;
nico@210: 00207     }
nico@215: 00208   MSG_WAR(0x1931, "sendPDOrequest : COBID not found : ", cobId);
nico@210: 00209   return 0xFF;
nico@210: 00210 }
nico@210: 00211 
nico@210: 00212 
nico@215: 00221 UNS8 proceedPDO(CO_Data* d, Message *m)
nico@210: 00222 {
nico@215: 00223   UNS8   numPdo;
nico@215: 00224   UNS8   numMap;  /* Number of the mapped varable */
nico@215: 00225   UNS8 i;
nico@215: 00226   UNS8 *     pMappingCount = NULL;    /* count of mapped objects... */
nico@215: 00227   /* pointer to the var which is mapped to a pdo... */
nico@215: 00228   /*  void *     pMappedAppObject = NULL;   */
nico@215: 00229   /* pointer fo the var which holds the mapping parameter of an
nico@215: 00230      mapping entry */
nico@215: 00231   UNS32 *    pMappingParameter = NULL;
nico@215: 00232   UNS8  *    pTransmissionType = NULL; /* pointer to the transmission
nico@215: 00233                                          type */
nico@215: 00234   UNS32 *    pwCobId = NULL;
nico@215: 00235   UNS8       Size;
nico@215: 00236   UNS8       dataType;
nico@215: 00237   UNS8       offset;
nico@215: 00238   UNS8       status;
nico@215: 00239   UNS32      objDict;
nico@215: 00240   UNS16      offsetObjdict;
nico@215: 00241   UNS16      lastIndex;
nico@215: 00242   status = state1;
nico@210: 00243 
nico@215: 00244   MSG_WAR(0x3935, "proceedPDO, cobID : ", ((*m).cob_id.w & 0x7ff));
nico@210: 00245   offset = 0x00;
nico@210: 00246   numPdo = 0;
nico@210: 00247   numMap = 0;
nico@215: 00248   if((*m).rtr == NOT_A_REQUEST ) { /* The PDO received is not a
nico@215: 00249                                      request. */
nico@215: 00250     offsetObjdict = d->firstIndex->PDO_RCV;
nico@215: 00251     lastIndex = d->lastIndex->PDO_RCV;
nico@210: 00252 
nico@215: 00253     /* study of all the PDO stored in the dictionary */
nico@210: 00254     if(offsetObjdict)
nico@210: 00255       while (offsetObjdict <= lastIndex) {
nico@210: 00256 
nico@210: 00257         switch( status ) {
nico@210: 00258 
nico@215: 00259         case state1:/* data are stored in process_var array */
nico@215: 00260           /* memcpy(&(process_var.data), &m->data, (*m).len); */
nico@215: 00261           /* Ce memcpy devrait etre portable */
nico@215: 00262           for ( i = 0 ; i < m->len ; i++)
nico@215: 00263             d->process_var.data[i] = m->data[i];
nico@215: 00264           d->process_var.count = (*m).len;
nico@210: 00265 
nico@215: 00266           status = state2;
nico@210: 00267           break;
nico@210: 00268 
nico@215: 00269         case state2:
nico@215: 00270           /* get CobId of the dictionary correspondant to the received
nico@215: 00271              PDO */
nico@215: 00272           pwCobId = d->objdict[offsetObjdict].pSubindex[1].pObject;
nico@215: 00273           /* check the CobId coherance */
nico@215: 00274           /*pwCobId is the cobId read in the dictionary at the state 3
nico@215: 00275             */
nico@210: 00276           if ( *pwCobId == (*m).cob_id.w ){
nico@215: 00277             /* The cobId is recognized */
nico@215: 00278             status = state4;
nico@215: 00279             MSG_WAR(0x3936, "cobId found at index ", 0x1400 + numPdo);
nico@210: 00280             break;
nico@210: 00281           }
nico@210: 00282           else {
nico@215: 00283             /* cobId received does not match with those write in the
nico@215: 00284               dictionnary */
nico@210: 00285             numPdo++;
nico@210: 00286             offsetObjdict++;
nico@215: 00287             status = state2;
nico@210: 00288             break;
nico@210: 00289           }
nico@210: 00290 
nico@215: 00291             case state4:/* Get Mapped Objects Number */
nico@215: 00292                /* The cobId of the message received has been found in the
nico@215: 00293                  dictionnary. */
nico@215: 00294                offsetObjdict = d->firstIndex->PDO_RCV_MAP;
nico@215: 00295              lastIndex = d->lastIndex->PDO_RCV_MAP;
nico@215: 00296              pMappingCount = (d->objdict + offsetObjdict + numPdo)->pSubindex[0].pObject;
nico@210: 00297              numMap = 0;
nico@210: 00298              while (numMap < *pMappingCount) {
nico@215: 00299                UNS8 tmp[]= {0,0,0,0,0,0,0,0};
nico@215: 00300                UNS8 ByteSize;
nico@215: 00301                pMappingParameter = (d->objdict + offsetObjdict + numPdo)->pSubindex[numMap + 1].pObject;
nico@210: 00302                if (pMappingParameter == NULL) {
nico@215: 00303                  MSG_ERR(0x1937, "Couldn't get mapping parameter : ", numMap + 1);
nico@210: 00304                  return 0xFF;
nico@210: 00305                }
nico@215: 00306                /* Get the addresse of the mapped variable. */
nico@215: 00307                /* detail of *pMappingParameter : */
nico@215: 00308                /* The 16 hight bits contains the index, the medium 8 bits
nico@215: 00309                  contains the subindex, */
nico@215: 00310                /* and the lower 8 bits contains the size of the mapped
nico@215: 00311                  variable. */
nico@215: 00312 
nico@215: 00313                Size = (UNS8)(*pMappingParameter);
nico@207: 00314 
nico@215: 00315                /* copy bit per bit in little endian */
nico@215: 00316                CopyBits(Size, (UNS8*)&d->process_var.data[offset>>3], offset%8, 0, ((UNS8*)tmp), 0, 0);
nico@210: 00317 
nico@210: 00318                ByteSize = 1 + ((Size - 1) >> 3); /*1->8 => 1 ; 9->16 =>
nico@210: 00319                                                    2, ... */
nico@210: 00320 
nico@215: 00321                objDict = setODentry(d, (UNS16)((*pMappingParameter) >> 16),
nico@215: 00322                                     (UNS8)(((*pMappingParameter) >> 8 ) & 0xFF),
nico@210: 00323                                  tmp, &ByteSize, 0 );
nico@210: 00324 
nico@215: 00325                if(objDict != OD_SUCCESSFUL) {
nico@215: 00326                  MSG_ERR(0x1938, "error accessing to the mapped var : ", numMap + 1);
nico@215: 00327                  MSG_WAR(0x2939, "         Mapped at index : ", (*pMappingParameter) >> 16);
nico@215: 00328                  MSG_WAR(0x2940, "                subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF);
nico@210: 00329                  return 0xFF;
nico@210: 00330                }
nico@210: 00331 
nico@215: 00332                MSG_WAR(0x3942, "Variable updated with value received by PDO cobid : ", m->cob_id.w);
nico@215: 00333                MSG_WAR(0x3943, "         Mapped at index : ", (*pMappingParameter) >> 16);
nico@215: 00334                MSG_WAR(0x3944, "                subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF);
nico@215: 00335                /* MSG_WAR(0x3945, "                data : ",*((UNS32*)pMappedAppObject)); */
nico@210: 00336                offset += Size;
nico@210: 00337                numMap++;
nico@215: 00338              } /* end loop while on mapped variables */
nico@215: 00339 
nico@210: 00340              offset=0x00;
nico@210: 00341              numMap = 0;
nico@210: 00342              return 0;
nico@210: 00343 
nico@215: 00344         }/* end switch status*/
nico@215: 00345       }/* end while*/
nico@215: 00346   }/* end if Donnees */
nico@215: 00347   else if ((*m).rtr == REQUEST ){
nico@215: 00348     MSG_WAR(0x3946, "Receive a PDO request cobId : ", m->cob_id.w);
nico@215: 00349     status = state1;
nico@215: 00350     offsetObjdict = d->firstIndex->PDO_TRS;
nico@215: 00351     lastIndex = d->lastIndex->PDO_TRS;
nico@210: 00352     if(offsetObjdict) while( offsetObjdict  <= lastIndex ){
nico@215: 00353       /* study of all PDO stored in the objects dictionary */
nico@215: 00354 
nico@210: 00355       switch( status ){
nico@210: 00356 
nico@215: 00357       case state1:/* check the CobId */
nico@215: 00358         /* get CobId of the dictionary which match to the received PDO
nico@215: 00359          */
nico@215: 00360         pwCobId = (d->objdict + offsetObjdict)->pSubindex[1].pObject;
nico@210: 00361         if ( *pwCobId == (*m).cob_id.w ) {
nico@215: 00362           status = state4;
nico@210: 00363           break;
nico@210: 00364         }
nico@210: 00365         else {
nico@210: 00366           numPdo++;
nico@210: 00367           offsetObjdict++;
nico@210: 00368         }
nico@215: 00369         status = state1;
nico@210: 00370         break;
nico@210: 00371 
nico@210: 00372 
nico@215: 00373       case state4:/* check transmission type (after request?) */
nico@215: 00374         pTransmissionType = d->objdict[offsetObjdict].pSubindex[2].pObject;
nico@215: 00375         if ( (*pTransmissionType == TRANS_RTR) || (*pTransmissionType == TRANS_RTR_SYNC ) || (*pTransmissionType == TRANS_EVENT) ) {
nico@215: 00376           status = state5;
nico@210: 00377           break;
nico@210: 00378         }
nico@210: 00379         else {
nico@215: 00380           /* The requested PDO is not to send on request. So, does
nico@215: 00381             nothing. */
nico@215: 00382           MSG_WAR(0x2947, "PDO is not to send on request : ", m->cob_id.w);
nico@210: 00383           return 0xFF;
nico@210: 00384         }
nico@210: 00385 
nico@215: 00386       case state5:/* get mapped objects number */
nico@215: 00387         offsetObjdict = d->firstIndex->PDO_TRS_MAP;
nico@215: 00388         lastIndex = d->lastIndex->PDO_TRS_MAP;
nico@215: 00389         pMappingCount = (d->objdict + offsetObjdict + numPdo)->pSubindex[0].pObject;
nico@210: 00390         numMap = 0;
nico@210: 00391         while (numMap < *pMappingCount) {
nico@215: 00392           pMappingParameter = (d->objdict + offsetObjdict + numPdo)->pSubindex[numMap + 1].pObject;
nico@215: 00393           /* Get the mapped variable */
nico@215: 00394           Size = ((UNS8)(((*pMappingParameter) & 0xFF) >> 3));
nico@215: 00395           objDict = getODentry( d, (UNS16)((*pMappingParameter) >> (UNS8)16),
nico@215: 00396                                 (UNS8)(( (*pMappingParameter) >> (UNS8)8 ) & 0xFF),
nico@215: 00397                                 (void *)&d->process_var.data[offset], &Size, &dataType, 0 );
nico@215: 00398           if (objDict != OD_SUCCESSFUL) {
nico@215: 00399             MSG_ERR(0x1948, "error accessing to the mapped var : ", numMap + 1);
nico@215: 00400             MSG_WAR(0x2949, "         Mapped at index : ", (*pMappingParameter) >> 16);
nico@215: 00401             MSG_WAR(0x2950, "                subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF);
nico@210: 00402             return 0xFF;
nico@210: 00403           }
nico@215: 00404           offset += (UNS8) (((*pMappingParameter) & 0xFF) >> 3);
nico@215: 00405           d->process_var.count = offset;
nico@210: 00406           numMap++;
nico@210: 00407 
nico@215: 00408         } /* end while */
nico@215: 00409         PDOmGR( d, *pwCobId ); /* Transmit the PDO */
nico@210: 00410         return 0;
nico@210: 00411 
nico@215: 00412       }/* end switch status */
nico@215: 00413     }/* end while */
nico@215: 00414   }/* end if Requete */
nico@215: 00415 
nico@210: 00416   return 0;
nico@210: 00417 }
nico@210: 00418 
nico@215: 00430 void CopyBits(UNS8 NbBits, UNS8* SrcByteIndex, UNS8 SrcBitIndex, UNS8 SrcBigEndian, UNS8* DestByteIndex, UNS8 DestBitIndex, UNS8 DestBigEndian)
nico@210: 00431 {
nico@215: 00432   /* This loop copy as many bits that it can each time, crossing*/
nico@215: 00433   /* successively bytes*/
nico@210: 00434   // boundaries from LSB to MSB.
nico@210: 00435   while(NbBits > 0)
nico@210: 00436     {
nico@215: 00437       /* Bit missalignement between src and dest*/
nico@215: 00438       INTEGER8 Vect = DestBitIndex - SrcBitIndex;
nico@210: 00439 
nico@215: 00440       /* We can now get src and align it to dest*/
nico@215: 00441       UNS8 Aligned = Vect>0 ? *SrcByteIndex << Vect : *SrcByteIndex >> -Vect;
nico@210: 00442 
nico@215: 00443       /* Compute the nb of bit we will be able to copy*/
nico@215: 00444       UNS8 BoudaryLimit = (Vect>0 ? 8 - DestBitIndex :  8 - SrcBitIndex );
nico@215: 00445       UNS8 BitsToCopy = BoudaryLimit > NbBits ? NbBits : BoudaryLimit;
nico@210: 00446 
nico@215: 00447       /* Create a mask that will serve in:*/
nico@215: 00448       UNS8 Mask = ((0xff << (DestBitIndex + BitsToCopy)) | (0xff >> (8 - DestBitIndex)));
nico@210: 00449 
nico@215: 00450       /* - Filtering src*/
nico@215: 00451       UNS8 Filtered = Aligned & ~Mask;
nico@210: 00452 
nico@215: 00453       /* - and erase bits where we write, preserve where we don't*/
nico@210: 00454       *DestByteIndex &= Mask;
nico@210: 00455 
nico@215: 00456       /* Then write.*/
nico@210: 00457       *DestByteIndex |= Filtered ;
nico@210: 00458 
nico@215: 00459       /*Compute next time cursors for src*/
nico@215: 00460       if((SrcBitIndex += BitsToCopy)>7)/* cross boundary ?*/
nico@210: 00461         {
nico@215: 00462           SrcBitIndex = 0;/* First bit*/
nico@215: 00463           SrcByteIndex += (SrcBigEndian ? -1 : 1);/* Next byte*/
nico@210: 00464         }
nico@210: 00465 
nico@210: 00466 
nico@215: 00467       /*Compute next time cursors for dest*/
nico@210: 00468       if((DestBitIndex += BitsToCopy)>7)
nico@210: 00469         {
nico@215: 00470           DestBitIndex = 0;/* First bit*/
nico@215: 00471           DestByteIndex += (DestBigEndian ? -1 : 1);/* Next byte*/
nico@210: 00472         }
nico@210: 00473 
nico@215: 00474       /*And decrement counter.*/
nico@210: 00475       NbBits -= BitsToCopy;
nico@210: 00476     }
nico@210: 00477 
nico@210: 00478 }
nico@210: 00479 
nico@210: 00480 #if 0
nico@210: 00481 
nico@210: 00482 /*********************************************************************/
nico@210: 00483 /* TODO : reimplement this using CallBacks
nico@210: 00484  */
nico@210: 00485 /*********************************************************************/
nico@210: 00486 
nico@215: 00495 UNS8 sendPDOevent( CO_Data* d, void * variable )
nico@215: 00496 { /* DO NOT USE MSG_ERR because the macro may send a PDO -> infinite
nico@215: 00497     loop if it fails.*/
nico@215: 00498   UNS32           objDict = 0;
nico@215: 00499   UNS8            ind, sub_ind;
nico@215: 00500   UNS8            status;
nico@215: 00501   UNS8            offset;
nico@215: 00502   UNS8 *     pMappingCount = NULL;
nico@215: 00503   UNS32 *    pMappingParameter = NULL;
nico@210: 00504   void *     pMappedAppObject = NULL;
nico@215: 00505   UNS8 *     pTransmissionType = NULL; /* pointer to the transmission
nico@215: 00506                                          type */
nico@215: 00507   UNS32 *    pwCobId = NULL;
nico@215: 00508   UNS8 *     pSize;
nico@215: 00509   UNS8       size;
nico@215: 00510   UNS8       dataType;
nico@215: 00511   UNS16      offsetObjdict;
nico@215: 00512   UNS16      offsetObjdictPrm;
nico@215: 00513   UNS16      lastIndex;
nico@215: 00514   UNS8       numMap;
nico@210: 00515   ind     = 0x00;
nico@210: 00516   sub_ind = 1;
nico@210: 00517   offset  = 0x00;
nico@210: 00518   pSize   = &size;
nico@215: 00519   status  = state1;
nico@210: 00520 
nico@210: 00521 
nico@215: 00522   /* look for the index and subindex where the variable is mapped */
nico@215: 00523   /* Then, send the pdo which contains the variable. */
nico@215: 00524 
nico@215: 00525   MSG_WAR (0x3960, "sendPDOevent", 0);
nico@215: 00526   offsetObjdictPrm = d->firstIndex->PDO_TRS;
nico@210: 00527 
nico@215: 00528   offsetObjdict = d->firstIndex->PDO_TRS_MAP;
nico@215: 00529   lastIndex = d->lastIndex->PDO_TRS_MAP;
nico@210: 00530 
nico@210: 00531   if (offsetObjdictPrm && offsetObjdict)
nico@215: 00532     /* Loop on PDO Transmit */
nico@210: 00533     while(offsetObjdict <= lastIndex){
nico@215: 00534       /* Check the transmission mode */
nico@215: 00535       pTransmissionType = d->objdict[offsetObjdictPrm].pSubindex[2].pObject;
nico@215: 00536       if (*pTransmissionType != TRANS_EVENT) {
nico@210: 00537         ind++;
nico@210: 00538         offsetObjdict++;
nico@210: 00539         offsetObjdictPrm++;
nico@210: 00540         continue;
nico@210: 00541       }
nico@215: 00542       pMappingCount = d->objdict[offsetObjdict].pSubindex[0].pObject;
nico@215: 00543       numMap = 1; /* mapped variable */
nico@210: 00544       while (numMap <= *pMappingCount) {
nico@215: 00545         pMappingParameter = d->objdict[offsetObjdict].pSubindex[numMap].pObject;
nico@215: 00546         /* Get the variable */
nico@215: 00547         objDict = getODentry( d,
nico@215: 00548                               (UNS16)((*pMappingParameter) >> 16),
nico@215: 00549                               (UNS8)(( (*pMappingParameter) >> (UNS8)8 ) & (UNS32)0x000000FF),
nico@210: 00550                               (void * *)&pMappedAppObject, pSize, &dataType, 0 );
nico@215: 00551         if( objDict != OD_SUCCESSFUL ) {
nico@215: 00552           MSG_WAR(0x2961, "Error in dict. at index : ",
nico@215: 00553                   (*pMappingParameter) >> (UNS8)16);
nico@210: 00554 
nico@215: 00555           MSG_WAR(0x2962, "               subindex : ",
nico@215: 00556                   ((*pMappingParameter) >> (UNS8)8 ) & (UNS32)0x000000FF);
nico@210: 00557           return 0xFF;
nico@210: 00558         }
nico@210: 00559         if (pMappedAppObject == variable) { // Variable found !
nico@215: 00560           MSG_WAR(0x3963, "Variable to send found at index : ",
nico@210: 00561                   (*pMappingParameter) >> 16);
nico@215: 00562           MSG_WAR(0x3964, "                       subIndex : ",
nico@210: 00563                   ((*pMappingParameter) >> 8 ) & 0x000000FF);
nico@215: 00564           buildPDO(d, 0x1800 + ind);
nico@215: 00565           /* Get the cobId */
nico@215: 00566           pwCobId = d->objdict[offsetObjdictPrm].pSubindex[1].pObject;
nico@215: 00567           PDOmGR( d, *pwCobId ); /* Send the PDO */
nico@210: 00568           return 0;
nico@210: 00569         }
nico@210: 00570         numMap++;
nico@215: 00571       } /* End loop on mapped variable */
nico@210: 00572       ind++;
nico@210: 00573       offsetObjdict++;
nico@210: 00574       offsetObjdictPrm++;
nico@215: 00575     } /* End loop while on PDO */
nico@215: 00576 
nico@215: 00577   MSG_WAR(0x2965, "Variable not found in a PDO to send on event", 0);
nico@210: 00578   return 0xFF;
nico@210: 00579 
nico@210: 00580 }
nico@210: 00581 #endif
nico@210: 00582 
nico@210: 00583 
nico@210: 00584 
nico@215: 

Generated on Fri Jun 8 08:51:39 2007 for CanFestival by  nico@207: nico@207: doxygen 1.5.1
nico@207: nico@207: