From: Markus Messmer Date: Sat, 29 Oct 2011 18:32:03 +0200 Subject: [PATCH] fix for CAN ID byteorder The can identifier does not need to get switched when compiling for big endian machines. FIXME rsc: needs to be made architecture independend. Signed-off-by: Markus Messmer --- include/objdictdef.h | 4 ++-- src/lifegrd.c | 4 ++-- src/lss.c | 4 ++-- src/nmtMaster.c | 2 +- src/nmtSlave.c | 2 +- src/pdo.c | 20 ++++++++++---------- src/sdo.c | 4 ++-- src/states.c | 2 +- src/sync.c | 2 +- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/include/objdictdef.h b/include/objdictdef.h index 60948b85a752..1ee36e88a155 100644 --- a/include/objdictdef.h +++ b/include/objdictdef.h @@ -118,7 +118,7 @@ typedef const indextable * (*scanIndexOD_t)(UNS16 wIndex, UNS32 * errorCode, ODC /************************** MACROS *********************************/ /* CANopen usefull helpers */ -#define GET_NODE_ID(m) (UNS16_LE(m.cob_id) & 0x7f) -#define GET_FUNCTION_CODE(m) (UNS16_LE(m.cob_id) >> 7) +#define GET_NODE_ID(m) (m.cob_id & 0x7f) +#define GET_FUNCTION_CODE(m) (m.cob_id >> 7) #endif /* __objdictdef_h__ */ diff --git a/src/lifegrd.c b/src/lifegrd.c index 566a4922a491..c98c4580b532 100644 --- a/src/lifegrd.c +++ b/src/lifegrd.c @@ -99,7 +99,7 @@ void proceedNODE_GUARD(CO_Data* d, Message* m ) { Message msg; UNS16 tmp = *d->bDeviceNodeId + 0x700; - msg.cob_id = UNS16_LE(tmp); + msg.cob_id = tmp; msg.len = (UNS8)0x01; msg.rtr = 0; msg.data[0] = d->nodeState; @@ -181,7 +181,7 @@ void ProducerHeartbeatAlarm(CO_Data* d, UNS32 id) ** the node-id of this device. */ UNS16 tmp = *d->bDeviceNodeId + 0x700; - msg.cob_id = UNS16_LE(tmp); + msg.cob_id = tmp; msg.len = (UNS8)0x01; msg.rtr = 0; msg.data[0] = d->nodeState; /* No toggle for heartbeat !*/ diff --git a/src/lss.c b/src/lss.c index 2febb6229320..d244d361d351 100644 --- a/src/lss.c +++ b/src/lss.c @@ -330,7 +330,7 @@ UNS8 sendSlaveLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2) m.len = 8; m.rtr = NOT_A_REQUEST; m.data[0]=command; - m.cob_id=UNS16_LE(SLSS_ADRESS); + m.cob_id=SLSS_ADRESS; /* Tha data sent with the msg depends on the command */ switch(command){ @@ -397,7 +397,7 @@ UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2) m.len = 8; m.rtr = NOT_A_REQUEST; m.data[0]=command; - m.cob_id=UNS16_LE(MLSS_ADRESS); + m.cob_id=MLSS_ADRESS; /* Tha data sent with the msg depends on the command */ switch(command){ diff --git a/src/nmtMaster.c b/src/nmtMaster.c index ba4cb05c50d2..a2efd36d6d68 100644 --- a/src/nmtMaster.c +++ b/src/nmtMaster.c @@ -74,7 +74,7 @@ UNS8 masterSendNMTnodeguard(CO_Data* d, UNS8 nodeId) /* message configuration */ UNS16 tmp = nodeId | (NODE_GUARD << 7); - m.cob_id = UNS16_LE(tmp); + m.cob_id = tmp; m.rtr = REQUEST; m.len = 0; diff --git a/src/nmtSlave.c b/src/nmtSlave.c index 0ff2ebac5a7e..ee6efee62b91 100644 --- a/src/nmtSlave.c +++ b/src/nmtSlave.c @@ -128,7 +128,7 @@ UNS8 slaveSendBootUp(CO_Data* d) /* message configuration */ { UNS16 tmp = NODE_GUARD << 7 | *d->bDeviceNodeId; - m.cob_id = UNS16_LE(tmp); + m.cob_id = tmp; } m.rtr = NOT_A_REQUEST; m.len = 1; diff --git a/src/pdo.c b/src/pdo.c index f5174ce64a56..f4cd2cb3ff7c 100644 --- a/src/pdo.c +++ b/src/pdo.c @@ -55,7 +55,7 @@ UNS8 buildPDO (CO_Data * d, UNS8 numPdo, Message * pdo) UNS32 offset = 0x00000000; const UNS8 *pMappingCount = (UNS8 *) TPDO_map->pSubindex[0].pObject; - pdo->cob_id = (UNS16) UNS16_LE(*(UNS32*)TPDO_com->pSubindex[1].pObject & 0x7FF); + pdo->cob_id = (UNS16) *(UNS32*)TPDO_com->pSubindex[1].pObject & 0x7FF; pdo->rtr = NOT_A_REQUEST; MSG_WAR (0x3009, " PDO CobId is : ", @@ -146,7 +146,7 @@ sendPDOrequest (CO_Data * d, UNS16 RPDOIndex) MSG_WAR (0x3930, "sendPDOrequest cobId is : ", *pwCobId); { Message pdo; - pdo.cob_id = UNS16_LE(*pwCobId); + pdo.cob_id = *pwCobId; pdo.rtr = REQUEST; pdo.len = 0; return canSend (d->canHandle, &pdo); @@ -189,7 +189,7 @@ proceedPDO (CO_Data * d, Message * m) status = state2; - MSG_WAR (0x3935, "proceedPDO, cobID : ", (UNS16_LE(m->cob_id) & 0x7ff)); + MSG_WAR (0x3935, "proceedPDO, cobID : ", (m->cob_id & 0x7ff)); offset = 0x00; numPdo = 0; numMap = 0; @@ -206,7 +206,7 @@ proceedPDO (CO_Data * d, Message * m) case state2: pwCobId = d->objdict[offsetObjdict].pSubindex[1].pObject; - if (*pwCobId == UNS16_LE(m->cob_id)) + if (*pwCobId == m->cob_id) { /* The cobId is recognized */ status = state4; @@ -283,7 +283,7 @@ proceedPDO (CO_Data * d, Message * m) MSG_WAR (0x3942, "Variable updated by PDO cobid : ", - UNS16_LE(m->cob_id)); + m->cob_id); MSG_WAR (0x3943, " Mapped at index : ", (*pMappingParameter) >> 16); MSG_WAR (0x3944, " subindex : ", @@ -308,7 +308,7 @@ proceedPDO (CO_Data * d, Message * m) } /* end if Donnees */ else if ((*m).rtr == REQUEST) { - MSG_WAR (0x3946, "Receive a PDO request cobId : ", UNS16_LE(m->cob_id)); + MSG_WAR (0x3946, "Receive a PDO request cobId : ", m->cob_id); status = state1; offsetObjdict = d->firstIndex->PDO_TRS; lastIndex = d->lastIndex->PDO_TRS; @@ -326,7 +326,7 @@ proceedPDO (CO_Data * d, Message * m) pwCobId = (d->objdict + offsetObjdict)->pSubindex[1].pObject; - if (*pwCobId == UNS16_LE(m->cob_id)) + if (*pwCobId == m->cob_id) { status = state4; break; @@ -366,7 +366,7 @@ proceedPDO (CO_Data * d, Message * m) /* DS301 do not tell what to do in such a case... */ MSG_ERR (0x1947, "Not ready RTR_SYNC TPDO send current data : ", - UNS16_LE(m->cob_id)); + m->cob_id); status = state5; } break; @@ -391,7 +391,7 @@ proceedPDO (CO_Data * d, Message * m) /* The requested PDO is not to send on request. So, does nothing. */ MSG_WAR (0x2947, "PDO is not to send on request : ", - UNS16_LE(m->cob_id)); + m->cob_id); return 0xFF; } @@ -484,7 +484,7 @@ static void sendPdo(CO_Data * d, UNS32 pdoNum, Message * pdo) { /*store_as_last_message */ d->PDO_status[pdoNum].last_message = *pdo; - MSG_WAR (0x396D, "sendPDO cobId :", UNS16_LE(pdo->cob_id)); + MSG_WAR (0x396D, "sendPDO cobId :", pdo->cob_id); MSG_WAR (0x396E, " Nb octets : ", pdo->len); canSend (d->canHandle, pdo); diff --git a/src/sdo.c b/src/sdo.c index f5abb11ce5db..394e1609aa61 100644 --- a/src/sdo.c +++ b/src/sdo.c @@ -780,7 +780,7 @@ UNS8 proceedSDO (CO_Data* d, Message *m) } /* Looking for the cobid received. */ pCobId = (UNS32*) d->objdict[offset].pSubindex[1].pObject; - if ( *pCobId == UNS16_LE(m->cob_id) ) { + if ( *pCobId == m->cob_id ) { whoami = SDO_SERVER; MSG_WAR(0x3A62, "proceedSDO. I am server. index : ", 0x1200 + j); /* Defining Server number = index minus 0x1200 where the cobid received is defined. */ @@ -802,7 +802,7 @@ UNS8 proceedSDO (CO_Data* d, Message *m) } /* Looking for the cobid received. */ pCobId = (UNS32*) d->objdict[offset].pSubindex[2].pObject; - if (*pCobId == UNS16_LE(m->cob_id) ) { + if (*pCobId == m->cob_id ) { whoami = SDO_CLIENT; MSG_WAR(0x3A64, "proceedSDO. I am client index : ", 0x1280 + j); /* Defining Client number = index minus 0x1280 where the cobid received is defined. */ diff --git a/src/states.c b/src/states.c index a8fb3d3fd1a8..866f055d655f 100644 --- a/src/states.c +++ b/src/states.c @@ -62,7 +62,7 @@ e_nodeState getState(CO_Data* d) **/ void canDispatch(CO_Data* d, Message *m) { - UNS16 cob_id = UNS16_LE(m->cob_id); + UNS16 cob_id = m->cob_id; switch(cob_id >> 7) { case SYNC: /* can be a SYNC or a EMCY message */ diff --git a/src/sync.c b/src/sync.c index 52a15ac71540..a2e163d81e9f 100644 --- a/src/sync.c +++ b/src/sync.c @@ -131,7 +131,7 @@ UNS8 sendSYNCMessage(CO_Data* d) MSG_WAR(0x3001, "sendSYNC ", 0); - m.cob_id = (UNS16)UNS16_LE(*d->COB_ID_Sync); + m.cob_id = (UNS16)*d->COB_ID_Sync; m.rtr = NOT_A_REQUEST; m.len = 0;