From 2ff07d29e3d725952d9890f8cee0c725848aac01 Mon Sep 17 00:00:00 2001 From: thelsing Date: Thu, 18 Jun 2020 11:26:59 +0200 Subject: [PATCH] Update bits.h --- src/knx/bits.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/knx/bits.h b/src/knx/bits.h index ec12e9a..0308ffe 100644 --- a/src/knx/bits.h +++ b/src/knx/bits.h @@ -36,13 +36,13 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode); #elif ARDUINO_ARCH_SAMD #include -#define htons(x) ( (((x)<<8)&0xFF00) | (((x)>>8)&0xFF) ) + +#define getbyte(x,n) (*(((uint8_t*)&(x))+n)) +#define htons(x) ( (getbyte(x,0)<<8) | getbyte(x,1) ) +#define htonl(x) ( (getbyte(x,0)<<24) | getbyte(x,1)<<16) | (getbyte(x,2)<<8) | getbyte(x,3) ) #define ntohs(x) htons(x) -#define htonl(x) ( ((x)<<24 & 0xFF000000UL) | \ - ((x)<< 8 & 0x00FF0000UL) | \ - ((x)>> 8 & 0x0000FF00UL) | \ - ((x)>>24 & 0x000000FFUL) ) #define ntohl(x) htonl(x) + #elif ARDUINO_ARCH_ESP8266 #include #include @@ -84,4 +84,4 @@ uint8_t* pushInt(uint32_t i, uint8_t* data); uint8_t* pushByteArray(const uint8_t* src, uint32_t size, uint8_t* data); uint16_t getWord(const uint8_t* data); uint32_t getInt(const uint8_t* data); -void printHex(const char* suffix, const uint8_t *data, size_t length); \ No newline at end of file +void printHex(const char* suffix, const uint8_t *data, size_t length);