From c6ff9122b4f68858c17b08692fbd05842960ce9e Mon Sep 17 00:00:00 2001 From: Olivier Date: Sat, 5 Nov 2016 09:50:18 +0100 Subject: [PATCH] Harmonize definition ins core (#628) --- MyConfig.h | 9 +++++++++ core/MyHwATMega328.cpp | 8 ++++---- core/MyHwATMega328.h | 14 ++++++-------- core/MyHwESP8266.cpp | 8 ++++---- core/MyHwESP8266.h | 1 - core/MyHwSAMD.cpp | 8 ++++---- core/MyHwSAMD.h | 9 --------- 7 files changed, 27 insertions(+), 30 deletions(-) diff --git a/MyConfig.h b/MyConfig.h index ff8ba70..7002e84 100644 --- a/MyConfig.h +++ b/MyConfig.h @@ -67,6 +67,15 @@ #ifndef MY_BAUD_RATE #define MY_BAUD_RATE 115200 #endif + /** + * @def MY_SERIAL_OUTPUT_SIZE + * @brief Max. characters for serial output. + */ +#ifndef MY_SERIAL_OUTPUT_SIZE +#define MY_SERIAL_OUTPUT_SIZE (120u) +#endif + + // Disables over-the-air reset of node //#define MY_DISABLE_REMOTE_RESET diff --git a/core/MyHwATMega328.cpp b/core/MyHwATMega328.cpp index 5705590..6619747 100644 --- a/core/MyHwATMega328.cpp +++ b/core/MyHwATMega328.cpp @@ -219,7 +219,7 @@ uint16_t hwFreeMem() { #ifdef MY_DEBUG void hwDebugPrint(const char *fmt, ... ) { - char fmtBuffer[MY_DEBUG_BUFFER_SIZE]; + char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_FEATURE // prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE) snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE); @@ -233,9 +233,9 @@ void hwDebugPrint(const char *fmt, ... ) { va_start (args, fmt ); #ifdef MY_GATEWAY_FEATURE // Truncate message if this is gateway node - vsnprintf_P(fmtBuffer, MY_GATEWAY_MAX_SEND_LENGTH, fmt, args); - fmtBuffer[MY_GATEWAY_MAX_SEND_LENGTH-1] = '\n'; - fmtBuffer[MY_GATEWAY_MAX_SEND_LENGTH] = '\0'; + vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args); + fmtBuffer[sizeof(fmtBuffer) - 2] = '\n'; + fmtBuffer[sizeof(fmtBuffer) - 1] = '\0'; #else vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args); #endif diff --git a/core/MyHwATMega328.h b/core/MyHwATMega328.h index b8e64d1..bf38a24 100644 --- a/core/MyHwATMega328.h +++ b/core/MyHwATMega328.h @@ -35,7 +35,6 @@ #endif #define MY_SERIALDEVICE Serial -#define MY_DEBUG_BUFFER_SIZE 300 #if defined __AVR_ATmega328P__ #ifndef sleep_bod_disable @@ -73,21 +72,20 @@ do { \ #define hwReboot() wdt_enable(WDTO_15MS); while (1) #define hwMillis() millis() #define hwRandomNumberInit() randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN)) -#define hwReadConfig(__pos) (eeprom_read_byte((uint8_t*)(__pos))) +#define hwReadConfig(__pos) eeprom_read_byte((uint8_t*)(__pos)) #ifndef eeprom_update_byte - #define hwWriteConfig(loc, val) if((uint8_t)(val) != eeprom_read_byte((uint8_t*)(loc))) { eeprom_write_byte((uint8_t*)(loc), (val)); } + #define hwWriteConfig(__loc, __val) if((uint8_t)(__val) != eeprom_read_byte((uint8_t*)(__loc))) { eeprom_write_byte((uint8_t*)(__loc), (__val)); } #else - #define hwWriteConfig(__pos, __value) (eeprom_update_byte((uint8_t*)(__pos), (__value))) + #define hwWriteConfig(__pos, __val) eeprom_update_byte((uint8_t*)(__pos), (__val)) #endif -#define hwReadConfigBlock(__buf, __pos, __length) (eeprom_read_block((__buf), (void*)(__pos), (__length))) -#define hwWriteConfigBlock(__buf, __pos, __length) (eeprom_write_block((void*)(__buf), (void*)(__pos), (__length))) +#define hwReadConfigBlock(__buf, __pos, __length) eeprom_read_block((void*)(__buf), (void*)(__pos), (__length)) +#define hwWriteConfigBlock(__buf, __pos, __length) eeprom_write_block((void*)(__buf), (void*)(__pos), (__length)) -enum period_t -{ +enum period_t { SLEEP_15MS, SLEEP_30MS, SLEEP_60MS, diff --git a/core/MyHwESP8266.cpp b/core/MyHwESP8266.cpp index 5c48a0b..7901e4d 100644 --- a/core/MyHwESP8266.cpp +++ b/core/MyHwESP8266.cpp @@ -134,7 +134,7 @@ uint16_t hwFreeMem() { #ifdef MY_DEBUG void hwDebugPrint(const char *fmt, ... ) { - char fmtBuffer[MY_DEBUG_BUFFER_SIZE]; + char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_FEATURE // prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE) snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE); @@ -144,9 +144,9 @@ void hwDebugPrint(const char *fmt, ... ) { va_start (args, fmt ); #ifdef MY_GATEWAY_FEATURE // Truncate message if this is gateway node - vsnprintf_P(fmtBuffer, MY_GATEWAY_MAX_SEND_LENGTH, fmt, args); - fmtBuffer[MY_GATEWAY_MAX_SEND_LENGTH-1] = '\n'; - fmtBuffer[MY_GATEWAY_MAX_SEND_LENGTH] = '\0'; + vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args); + fmtBuffer[sizeof(fmtBuffer) - 2] = '\n'; + fmtBuffer[sizeof(fmtBuffer) - 1] = '\0'; #else vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args); #endif diff --git a/core/MyHwESP8266.h b/core/MyHwESP8266.h index 0f53ced..3b92169 100644 --- a/core/MyHwESP8266.h +++ b/core/MyHwESP8266.h @@ -26,7 +26,6 @@ #endif #define MY_SERIALDEVICE Serial -#define MY_DEBUG_BUFFER_SIZE 300 #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) diff --git a/core/MyHwSAMD.cpp b/core/MyHwSAMD.cpp index 3d79a48..ddd1919 100644 --- a/core/MyHwSAMD.cpp +++ b/core/MyHwSAMD.cpp @@ -160,7 +160,7 @@ uint16_t hwFreeMem() { #ifdef MY_DEBUG void hwDebugPrint(const char *fmt, ... ) { if (MY_SERIALDEVICE) { - char fmtBuffer[MY_DEBUG_BUFFER_SIZE]; + char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_FEATURE // prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE) snprintf(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE); @@ -170,9 +170,9 @@ void hwDebugPrint(const char *fmt, ... ) { va_start (args, fmt ); #ifdef MY_GATEWAY_FEATURE // Truncate message if this is gateway node - vsnprintf(fmtBuffer, 60, fmt, args); - fmtBuffer[59] = '\n'; - fmtBuffer[60] = '\0'; + vsnprintf(fmtBuffer, sizeof(fmtBuffer), fmt, args); + fmtBuffer[sizeof(fmtBuffer) - 2] = '\n'; + fmtBuffer[sizeof(fmtBuffer) - 1] = '\0'; #else vsnprintf(fmtBuffer, sizeof(fmtBuffer), fmt, args); #endif diff --git a/core/MyHwSAMD.h b/core/MyHwSAMD.h index 00ac1d6..7d23e07 100644 --- a/core/MyHwSAMD.h +++ b/core/MyHwSAMD.h @@ -52,15 +52,6 @@ void hwWriteConfig(int adr, uint8_t value); uint8_t hwReadConfig(int adr); #define MY_SERIALDEVICE SerialUSB -#define MY_DEBUG_BUFFER_SIZE 300 - - -/* -#define hwReadConfigBlock(__buf, __adr, __length) ( __length = __length) -#define hwWriteConfigBlock(__buf, __adr, __length) ( __length = __length) -#define hwWriteConfig(__adr, __value) ( __value = __value) -#define hwReadConfig(__adr) (0) -*/ /** * Disable all interrupts.