From 680caf31254a14e6be3c6ce386451c816a946cf1 Mon Sep 17 00:00:00 2001 From: gotocoffee Date: Wed, 2 May 2018 12:55:44 +0200 Subject: [PATCH] - changed unnamed struct CO_LSS_address_t - added missing support for big endian in LSSslave --- stack/CO_LSS.h | 10 +++++----- stack/CO_LSSslave.c | 28 +++++++++++++++------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/stack/CO_LSS.h b/stack/CO_LSS.h index 41985d4..45b790d 100644 --- a/stack/CO_LSS.h +++ b/stack/CO_LSS.h @@ -189,7 +189,7 @@ typedef union { uint32_t productCode; uint32_t revisionNumber; uint32_t serialNumber; - }; + } identity; } CO_LSS_address_t; /** @@ -258,10 +258,10 @@ static const uint16_t CO_LSS_bitTimingTableLookup[] = { * Macro to check if two LSS addresses are equal */ #define CO_LSS_ADDRESS_EQUAL(/*CO_LSS_address_t*/ a1, /*CO_LSS_address_t*/ a2) \ - (a1.productCode == a2.productCode && \ - a1.revisionNumber == a2.revisionNumber && \ - a1.serialNumber == a2.serialNumber && \ - a1.vendorID == a2.vendorID) + (a1.identity.productCode == a2.identity.productCode && \ + a1.identity.revisionNumber == a2.identity.revisionNumber && \ + a1.identity.serialNumber == a2.identity.serialNumber && \ + a1.identity.vendorID == a2.identity.vendorID) #endif /* CO_NO_LSS_CLIENT == 1 || CO_NO_LSS_SERVER == 1 */ diff --git a/stack/CO_LSSslave.c b/stack/CO_LSSslave.c index 29eb0d6..4a31251 100644 --- a/stack/CO_LSSslave.c +++ b/stack/CO_LSSslave.c @@ -79,7 +79,8 @@ static void CO_LSSslave_serviceSwitchStateSelective( CO_LSS_cs_t service, const CO_CANrxMsg_t *msg) { - uint32_t value = CO_getUint32(&msg->data[1]); + uint32_t value; + CO_memcpySwap4(&value, &msg->data[1]); if(LSSslave->lssState != CO_LSS_STATE_WAITING) { return; @@ -87,16 +88,16 @@ static void CO_LSSslave_serviceSwitchStateSelective( switch (service) { case CO_LSS_SWITCH_STATE_SEL_VENDOR: - LSSslave->lssSelect.vendorID = value; + LSSslave->lssSelect.identity.vendorID = value; break; case CO_LSS_SWITCH_STATE_SEL_PRODUCT: - LSSslave->lssSelect.productCode = value; + LSSslave->lssSelect.identity.productCode = value; break; case CO_LSS_SWITCH_STATE_SEL_REV: - LSSslave->lssSelect.revisionNumber = value; + LSSslave->lssSelect.identity.revisionNumber = value; break; case CO_LSS_SWITCH_STATE_SEL_SERIAL: - LSSslave->lssSelect.serialNumber = value; + LSSslave->lssSelect.identity.serialNumber = value; if (CO_LSS_ADDRESS_EQUAL(LSSslave->lssAddress, LSSslave->lssSelect)) { LSSslave->lssState = CO_LSS_STATE_CONFIGURATION; @@ -193,7 +194,8 @@ static void CO_LSSslave_serviceConfig( /* notify application */ if (LSSslave->pFunctLSSactivateBitRate != NULL) { - uint16_t delay = CO_getUint16(&msg->data[1]); + uint16_t delay; + CO_memcpySwap2(&delay, &msg->data[1]); LSSslave->pFunctLSSactivateBitRate( LSSslave->functLSSactivateBitRateObject, delay); } @@ -243,16 +245,16 @@ static void CO_LSSslave_serviceInquire( switch (service) { case CO_LSS_INQUIRE_VENDOR: - value = LSSslave->lssAddress.vendorID; + value = LSSslave->lssAddress.identity.vendorID; break; case CO_LSS_INQUIRE_PRODUCT: - value = LSSslave->lssAddress.productCode; + value = LSSslave->lssAddress.identity.productCode; break; case CO_LSS_INQUIRE_REV: - value = LSSslave->lssAddress.revisionNumber; + value = LSSslave->lssAddress.identity.revisionNumber; break; case CO_LSS_INQUIRE_SERIAL: - value = LSSslave->lssAddress.serialNumber; + value = LSSslave->lssAddress.identity.serialNumber; break; case CO_LSS_INQUIRE_NODE_ID: value = (uint32_t)LSSslave->activeNodeID; @@ -262,7 +264,7 @@ static void CO_LSSslave_serviceInquire( } /* send response */ LSSslave->TXbuff->data[0] = service; - CO_setUint32(&LSSslave->TXbuff->data[1], value); + CO_memcpySwap4(&LSSslave->TXbuff->data[1], &value); CO_memset(&LSSslave->TXbuff->data[5], 0, 4); CO_CANsend(LSSslave->CANdevTx, LSSslave->TXbuff); } @@ -295,7 +297,7 @@ static void CO_LSSslave_serviceIdent( return; } - idNumber = CO_getUint32(&msg->data[1]); + CO_memcpySwap4(&idNumber, &msg->data[1]); bitCheck = msg->data[5]; lssSub = msg->data[6]; lssNext = msg->data[7]; @@ -396,7 +398,7 @@ CO_ReturnError_t CO_LSSslave_init( /* check LSS address for plausibility. As a bare minimum, the vendor * ID and serial number must be set */ - if (lssAddress.vendorID==0 || lssAddress.serialNumber==0) { + if (lssAddress.identity.vendorID==0 || lssAddress.identity.serialNumber==0) { return CO_ERROR_ILLEGAL_ARGUMENT; }