diff -r 5a17bcb520ef -r f812bf6b7237 src/sync.c --- a/src/sync.c Fri Jun 29 19:48:22 2007 +0200 +++ b/src/sync.c Fri Jun 29 19:51:39 2007 +0200 @@ -141,33 +141,7 @@ UNS8 proceedSYNC(CO_Data* d, Message *m) { - UNS8 pdoNum, /* number of the actual processed pdo-nr. */ - prp_j; - - const UNS8 * pMappingCount = NULL; /* count of mapped objects...*/ - /* pointer to the var which is mapped to a pdo */ - /* void * pMappedAppObject = NULL; */ - /* pointer fo the var which holds the mapping parameter of an mapping entry */ - UNS32 * pMappingParameter = NULL; - /* pointer to the transmissiontype...*/ - UNS8 * pTransmissionType = NULL; - UNS32 * pwCobId = NULL; - - UNS8 dataType; - UNS16 index; - UNS8 subIndex; - UNS8 offset; - UNS8 status; - UNS8 Size; - UNS32 objDict; - UNS16 offsetObjdict; - UNS16 offsetObjdictMap; - UNS16 lastIndex; - - status = state3; - pdoNum = 0x00; - prp_j = 0x00; - offset = 0x00; + UNS8 res; MSG_WAR(0x3002, "SYNC received. Proceed. ", 0); @@ -176,117 +150,14 @@ /* only operational state allows PDO transmission */ if( d->nodeState != Operational ) return 0; + + res = _sendPDOevent(d, 1 /*isSyncEvent*/ ); - /* So, the node is in operational state */ - /* study all PDO stored in the objects dictionary */ - - offsetObjdict = d->firstIndex->PDO_TRS; - lastIndex = d->lastIndex->PDO_TRS; - offsetObjdictMap = d->firstIndex->PDO_TRS_MAP; + /*Call user app callback*/ + (*d->post_TPDO)(); - if(offsetObjdict) while( offsetObjdict <= lastIndex) { - switch( status ) { - - case state3: /* get the PDO transmission type */ - if (d->objdict[offsetObjdict].bSubCount <= 2) { - MSG_ERR(0x1004, "Subindex 2 not found at index ", 0x1800 + pdoNum); - return 0xFF; - } - pTransmissionType = (UNS8*) d->objdict[offsetObjdict].pSubindex[2].pObject; - MSG_WAR(0x3005, "Reading PDO at index : ", 0x1800 + pdoNum); - status = state4; - break; - case state4: /* check if transmission type is after (this) SYNC */ - /* The message may not be transmited every SYNC but every n SYNC */ - if( (*pTransmissionType >= TRANS_SYNC_MIN) && (*pTransmissionType <= TRANS_SYNC_MAX) && - (++d->count_sync[pdoNum] == *pTransmissionType) ) { - d->count_sync[pdoNum] = 0; - MSG_WAR(0x3007, " PDO is on SYNCHRO. Trans type : ", *pTransmissionType); - status = state5; - break; - } - else { - MSG_WAR(0x3008, " Not on synchro or not at this SYNC. Trans type : ", - *pTransmissionType); - pdoNum++; - offsetObjdict++; - offsetObjdictMap++; - status = state11; - break; - } - case state5: /* get PDO CobId */ - pwCobId = (UNS32*) d->objdict[offsetObjdict].pSubindex[1].pObject; - MSG_WAR(0x3009, " PDO CobId is : ", *pwCobId); - status = state7; - break; - case state7: /* get mapped objects number to transmit with this PDO */ - pMappingCount = (UNS8*) d->objdict[offsetObjdictMap].pSubindex[0].pObject; - MSG_WAR(0x300D, " Number of objects mapped : ",*pMappingCount ); - status = state8; - case state8: /* get mapping parameters */ - pMappingParameter = (UNS32*) d->objdict[offsetObjdictMap].pSubindex[prp_j + 1].pObject; - MSG_WAR(0x300F, " got mapping parameter : ", *pMappingParameter); - MSG_WAR(0x3050, " at index : ", 0x1A00 + pdoNum); - MSG_WAR(0x3051, " sub-index : ", prp_j + 1); - status = state9; - - case state9: /* get data to transmit */ - { - UNS8 ByteSize; - UNS8 tmp[]= {0,0,0,0,0,0,0,0}; - index = (UNS16)((*pMappingParameter) >> 16); - subIndex = (UNS8)(( (*pMappingParameter) >> (UNS8)8 ) & (UNS32)0x000000FF); - Size = (UNS8)(*pMappingParameter); /* Size in bits */ - ByteSize = 1 + ((Size - 1) >> 3); /*1->8 => 1 ; 9->16 => 2, ... */ - objDict = getODentry(d, index, subIndex, tmp, &ByteSize, &dataType, 0 ); - /* copy bit per bit in little endian*/ - CopyBits(Size, ((UNS8*)tmp), 0 , 0, (UNS8*)&d->process_var.data[offset>>3], offset%8, 0); - } - if( objDict != OD_SUCCESSFUL ){ - MSG_ERR(0x1013, " Couldn't find mapped variable at index-subindex-size : ", (UNS16)(*pMappingParameter)); - return 0xFF; - } - - offset += Size ; - d->process_var.count = 1 + ((offset - 1) >> 3); - prp_j++; - status = state10; - break; - - case state10: /* loop to get all the data to transmit */ - if( prp_j < *pMappingCount ){ - MSG_WAR(0x3014, " next variable mapped : ", prp_j); - status = state8; - break; - } - else { - MSG_WAR(0x3015, " End scan mapped variable", 0); - PDOmGR( d, *pwCobId ); - MSG_WAR(0x3016, " End of this pdo. Should have been sent", 0); - pdoNum++; - offsetObjdict++; - offsetObjdictMap++; - offset = 0x00; - prp_j = 0x00; - status = state11; - break; - } - - case state11: - MSG_WAR(0x3017, "next pdo index : ", pdoNum); - status = state3; - break; - - default: - MSG_ERR(0x1019,"Unknown state has been reached : %d",status); - return 0xFF; - }/* end switch case */ - - }/* end while( prp_ipost_TPDO)(); - - return 0; + return res; + }