Using macro to exclude debug logs from code when compiling for production

This commit is contained in:
he.so 2020-02-26 19:17:36 +01:00
commit bc584468af
5 changed files with 47 additions and 31 deletions

View File

@ -105,9 +105,9 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t zigbee_use_names : 1; // bit 1 (v8.1.0.4) - SetOption83 - Use FriendlyNames instead of ShortAddresses when possible uint32_t zigbee_use_names : 1; // bit 1 (v8.1.0.4) - SetOption83 - Use FriendlyNames instead of ShortAddresses when possible
uint32_t awsiot_shadow : 1; // bit 2 (v8.1.0.5) - SetOption84 - (AWS IoT) publish MQTT state to a device shadow uint32_t awsiot_shadow : 1; // bit 2 (v8.1.0.5) - SetOption84 - (AWS IoT) publish MQTT state to a device shadow
uint32_t device_groups_enabled : 1; // bit 3 (v8.1.0.9) - SetOption85 - Enable Device Groups uint32_t device_groups_enabled : 1; // bit 3 (v8.1.0.9) - SetOption85 - Enable Device Groups
uint32_t spare04 : 1; uint32_t led_timeout : 1; // bit 4 (v8.1.0.9) - SetOption86 - Turn brightness LED's off 5 seconds after last change
uint32_t spare05 : 1; uint32_t powered_off_led : 1; // bit 5 (v8.1.0.9) - SetOption87 - Turn red LED on when powered off
uint32_t spare06 : 1; uint32_t remote_device_mode : 1; // bit 6 (v8.1.0.9) - SetOption88 - Buttons control remote devices
uint32_t spare07 : 1; uint32_t spare07 : 1;
uint32_t spare08 : 1; uint32_t spare08 : 1;
uint32_t spare09 : 1; uint32_t spare09 : 1;
@ -132,7 +132,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t spare28 : 1; uint32_t spare28 : 1;
uint32_t spare29 : 1; uint32_t spare29 : 1;
uint32_t spare30 : 1; uint32_t spare30 : 1;
uint32_t force_sdk_erase : 1; // bit 31 (v8.1.0.9) - SetOption113 - Force erase of SDK wifi calibrate secore on restart uint32_t spare31 : 1; // bit 31
}; };
} SysBitfield4; } SysBitfield4;
@ -465,8 +465,13 @@ struct SYSCFG {
uint8_t mqttlog_level; // F01 uint8_t mqttlog_level; // F01
uint8_t sps30_inuse_hours; // F02 uint8_t sps30_inuse_hours; // F02
uint8_t hotplug_scan; // F03 uint8_t hotplug_scan; // F03
uint8_t reserved1; // F04 - reserved for s-hadinger uint8_t bri_power_on; // F04
uint8_t free_f05[183]; // F05 uint8_t bri_min; // F05
uint8_t bri_preset_low; // F06
uint8_t bri_preset_high; // F07
uint8_t button_devices; // F08
uint8_t free_f05[179]; // F09
uint32_t keeloq_master_msb; // FBC uint32_t keeloq_master_msb; // FBC
uint32_t keeloq_master_lsb; // FC0 uint32_t keeloq_master_lsb; // FC0

View File

@ -774,6 +774,10 @@ void SettingsErase(uint8_t type)
_sectorEnd = _sectorStart +1; // SDK end of phy area and Core calibration sector (0xxFCFFF) _sectorEnd = _sectorStart +1; // SDK end of phy area and Core calibration sector (0xxFCFFF)
} }
*/ */
else {
return;
}
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_ERASE " from 0x%08X to 0x%08X"), _sectorStart * SPI_FLASH_SEC_SIZE, (_sectorEnd * SPI_FLASH_SEC_SIZE) -1); AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_ERASE " from 0x%08X to 0x%08X"), _sectorStart * SPI_FLASH_SEC_SIZE, (_sectorEnd * SPI_FLASH_SEC_SIZE) -1);
// EspErase(_sectorStart, _sectorEnd); // Arduino core and SDK - erases flash as seen by SDK // EspErase(_sectorStart, _sectorEnd); // Arduino core and SDK - erases flash as seen by SDK

View File

@ -21,7 +21,8 @@
* Wifi * Wifi
\*********************************************************************************************/ \*********************************************************************************************/
// Enable only one of two below debug options // Enable one of three below options for wifi re-connection debugging
//#define WIFI_FORCE_RF_CAL_ERASE // Erase rf calibration sector on restart only
//#define WIFI_RF_MODE_RF_CAL // Set RF_MODE to RF_CAL for restart and deepsleep during user_rf_pre_init //#define WIFI_RF_MODE_RF_CAL // Set RF_MODE to RF_CAL for restart and deepsleep during user_rf_pre_init
//#define WIFI_RF_PRE_INIT // Set RF_MODE to RF_CAL for restart, deepsleep and power on during user_rf_pre_init //#define WIFI_RF_PRE_INIT // Set RF_MODE to RF_CAL for restart, deepsleep and power on during user_rf_pre_init
@ -34,7 +35,7 @@
const uint8_t WIFI_CONFIG_SEC = 180; // seconds before restart const uint8_t WIFI_CONFIG_SEC = 180; // seconds before restart
const uint8_t WIFI_CHECK_SEC = 20; // seconds const uint8_t WIFI_CHECK_SEC = 20; // seconds
const uint8_t WIFI_RETRY_OFFSET_SEC = 20; // seconds const uint8_t WIFI_RETRY_OFFSET_SEC = 12; // seconds
#include <ESP8266WiFi.h> // Wifi, MQTT, Ota, WifiManager #include <ESP8266WiFi.h> // Wifi, MQTT, Ota, WifiManager
#if LWIP_IPV6 #if LWIP_IPV6
@ -645,7 +646,7 @@ void WifiConnect(void)
WifiSetOutputPower(); WifiSetOutputPower();
WiFi.persistent(false); // Solve possible wifi init errors WiFi.persistent(false); // Solve possible wifi init errors
Wifi.status = 0; Wifi.status = 0;
Wifi.retry_init = WIFI_RETRY_OFFSET_SEC + ((ESP.getChipId() & 0xF) * 2); Wifi.retry_init = WIFI_RETRY_OFFSET_SEC + (ESP.getChipId() & 0xF); // Add extra delay to stop overrun by simultanous re-connects
Wifi.retry = Wifi.retry_init; Wifi.retry = Wifi.retry_init;
Wifi.counter = 1; Wifi.counter = 1;
@ -659,29 +660,34 @@ void WifiConnect(void)
void WifiShutdown(bool option = false) void WifiShutdown(bool option = false)
{ {
// option = false - Legacy disconnect also used by DeepSleep // option = false - Legacy disconnect also used by DeepSleep
// option = true - Disconnect with SDK wifi calibrate sector erase // option = true - Disconnect with SDK wifi calibrate sector erase when WIFI_FORCE_RF_CAL_ERASE enabled
delay(100); // Allow time for message xfer - disabled v6.1.0b delay(100); // Allow time for message xfer - disabled v6.1.0b
#ifdef USE_EMULATION #ifdef USE_EMULATION
UdpDisconnect(); UdpDisconnect();
delay(100); // Flush anything in the network buffers.
#endif // USE_EMULATION #endif // USE_EMULATION
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
MqttDisconnect(); MqttDisconnect();
delay(100); // Flush anything in the network buffers.
} }
if (option && Settings.flag4.force_sdk_erase) { // SetOption113 - Force erase of SDK wifi calibrate sector on restart #ifdef WIFI_FORCE_RF_CAL_ERASE
if (option) {
WiFi.disconnect(false); // Disconnect wifi WiFi.disconnect(false); // Disconnect wifi
SettingsErase(4); // Delete SDK wifi config and calibrate data SettingsErase(4); // Delete SDK wifi config and calibrate data
} else { } else
#endif // WIFI_FORCE_RF_CAL_ERASE
{
// Enable from 6.0.0a until 6.1.0a - disabled due to possible cause of bad wifi connect on core 2.3.0 // Enable from 6.0.0a until 6.1.0a - disabled due to possible cause of bad wifi connect on core 2.3.0
// Re-enabled from 6.3.0.7 with ESP.restart replaced by ESP.reset // Re-enabled from 6.3.0.7 with ESP.restart replaced by ESP.reset
// Courtesy of EspEasy // Courtesy of EspEasy
WiFi.persistent(true); // use SDK storage of SSID/WPA parameters WiFi.persistent(true); // use SDK storage of SSID/WPA parameters
ETS_UART_INTR_DISABLE(); ETS_UART_INTR_DISABLE();
wifi_station_disconnect(); // this will store empty ssid/wpa into sdk storage wifi_station_disconnect(); // this will store empty ssid/wpa into sdk storage
ETS_UART_INTR_ENABLE(); ETS_UART_INTR_ENABLE();
WiFi.persistent(false); // Do not use SDK storage of SSID/WPA parameters WiFi.persistent(false); // Do not use SDK storage of SSID/WPA parameters
} }
delay(100); // Flush anything in the network buffers. delay(100); // Flush anything in the network buffers.
} }

View File

@ -1882,6 +1882,7 @@ void HandleOtherConfiguration(void)
} }
#ifdef USE_EMULATION #ifdef USE_EMULATION
#if defined(USE_EMULATION_WEMO) || defined(USE_EMULATION_HUE)
WSContentSend_P(PSTR("<p></p><fieldset><legend><b>&nbsp;" D_EMULATION "&nbsp;</b></legend><p>")); // Keep close to Friendlynames so do not use <br> WSContentSend_P(PSTR("<p></p><fieldset><legend><b>&nbsp;" D_EMULATION "&nbsp;</b></legend><p>")); // Keep close to Friendlynames so do not use <br>
for (uint32_t i = 0; i < EMUL_MAX; i++) { for (uint32_t i = 0; i < EMUL_MAX; i++) {
#ifndef USE_EMULATION_WEMO #ifndef USE_EMULATION_WEMO
@ -1899,6 +1900,7 @@ void HandleOtherConfiguration(void)
} }
} }
WSContentSend_P(PSTR("</p></fieldset>")); WSContentSend_P(PSTR("</p></fieldset>"));
#endif // USE_EMULATION_WEMO || USE_EMULATION_HUE
#endif // USE_EMULATION #endif // USE_EMULATION
WSContentSend_P(HTTP_FORM_END); WSContentSend_P(HTTP_FORM_END);
@ -1917,8 +1919,10 @@ void OtherSaveSettings(void)
SettingsUpdateText(SET_WEBPWD, (!strlen(tmp)) ? "" : (strchr(tmp,'*')) ? SettingsText(SET_WEBPWD) : tmp); SettingsUpdateText(SET_WEBPWD, (!strlen(tmp)) ? "" : (strchr(tmp,'*')) ? SettingsText(SET_WEBPWD) : tmp);
Settings.flag.mqtt_enabled = WebServer->hasArg("b1"); // SetOption3 - Enable MQTT Settings.flag.mqtt_enabled = WebServer->hasArg("b1"); // SetOption3 - Enable MQTT
#ifdef USE_EMULATION #ifdef USE_EMULATION
#if defined(USE_EMULATION_WEMO) || defined(USE_EMULATION_HUE)
WebGetArg("b2", tmp, sizeof(tmp)); WebGetArg("b2", tmp, sizeof(tmp));
Settings.flag2.emulation = (!strlen(tmp)) ? 0 : atoi(tmp); Settings.flag2.emulation = (!strlen(tmp)) ? 0 : atoi(tmp);
#endif // USE_EMULATION_WEMO || USE_EMULATION_HUE
#endif // USE_EMULATION #endif // USE_EMULATION
snprintf_P(message, sizeof(message), PSTR(D_LOG_OTHER D_MQTT_ENABLE " %s, " D_CMND_EMULATION " %d, " D_CMND_FRIENDLYNAME), GetStateText(Settings.flag.mqtt_enabled), Settings.flag2.emulation); snprintf_P(message, sizeof(message), PSTR(D_LOG_OTHER D_MQTT_ENABLE " %s, " D_CMND_EMULATION " %d, " D_CMND_FRIENDLYNAME), GetStateText(Settings.flag.mqtt_enabled), Settings.flag2.emulation);

View File

@ -51,7 +51,6 @@ struct JAROLIFT_DEVICE {
void CmdSet(void) void CmdSet(void)
{ {
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("set called, check for params master key high, low, serial, counter.."));
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
if (XdrvMailbox.payload > 0) { if (XdrvMailbox.payload > 0) {
char *p; char *p;
@ -64,7 +63,7 @@ void CmdSet(void)
for (uint32_t i = 0; i < 3; i++) { for (uint32_t i = 0; i < 3; i++) {
if (param[i] < 1) { param[i] = 1; } // msb, lsb, serial, counter if (param[i] < 1) { param[i] = 1; } // msb, lsb, serial, counter
} }
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("params: %08x %08x %08x %08x"), param[0], param[1], param[2], param[3]); DEBUG_DRIVER_LOG(LOG_LEVEL_DEBUG_MORE, PSTR("params: %08x %08x %08x %08x"), param[0], param[1], param[2], param[3]);
Settings.keeloq_master_msb = param[0]; Settings.keeloq_master_msb = param[0];
Settings.keeloq_master_lsb = param[1]; Settings.keeloq_master_lsb = param[1];
Settings.keeloq_serial = param[2]; Settings.keeloq_serial = param[2];
@ -76,10 +75,10 @@ void CmdSet(void)
GenerateDeviceCryptKey(); GenerateDeviceCryptKey();
ResponseCmndDone(); ResponseCmndDone();
} else { } else {
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("no payload")); DEBUG_DRIVER_LOG(LOG_LEVEL_DEBUG_MORE, PSTR("no payload"));
} }
} else { } else {
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("no param")); DEBUG_DRIVER_LOG(LOG_LEVEL_DEBUG_MORE, PSTR("no param"));
} }
} }
@ -89,7 +88,7 @@ void GenerateDeviceCryptKey()
jaroliftDevice.device_key_msb = k.decrypt(jaroliftDevice.serial | 0x60000000L); jaroliftDevice.device_key_msb = k.decrypt(jaroliftDevice.serial | 0x60000000L);
jaroliftDevice.device_key_lsb = k.decrypt(jaroliftDevice.serial | 0x20000000L); jaroliftDevice.device_key_lsb = k.decrypt(jaroliftDevice.serial | 0x20000000L);
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("device keys: %08x %08x"), jaroliftDevice.device_key_msb, jaroliftDevice.device_key_lsb); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("generated device keys: %08x %08x"), jaroliftDevice.device_key_msb, jaroliftDevice.device_key_lsb);
} }
void CmdSendButton(void) void CmdSendButton(void)
@ -102,11 +101,11 @@ void CmdSendButton(void)
if (XdrvMailbox.payload > 0) if (XdrvMailbox.payload > 0)
{ {
jaroliftDevice.button = strtoul(XdrvMailbox.data, nullptr, 0); jaroliftDevice.button = strtoul(XdrvMailbox.data, nullptr, 0);
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("msb: %08x"), jaroliftDevice.device_key_msb); DEBUG_DRIVER_LOG(LOG_LEVEL_DEBUG_MORE, PSTR("msb: %08x"), jaroliftDevice.device_key_msb);
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("lsb: %08x"), jaroliftDevice.device_key_lsb); DEBUG_DRIVER_LOG(LOG_LEVEL_DEBUG_MORE, PSTR("lsb: %08x"), jaroliftDevice.device_key_lsb);
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("count: %08x"), jaroliftDevice.count); DEBUG_DRIVER_LOG(LOG_LEVEL_DEBUG_MORE, PSTR("serial: %08x"), jaroliftDevice.serial);
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("serial: %08x"), jaroliftDevice.serial); DEBUG_DRIVER_LOG(LOG_LEVEL_DEBUG_MORE, PSTR("disc: %08x"), jaroliftDevice.disc);
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("disc: %08x"), jaroliftDevice.disc); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("KLQ: count: %08x"), jaroliftDevice.count);
CreateKeeloqPacket(); CreateKeeloqPacket();
jaroliftDevice.count++; jaroliftDevice.count++;
@ -114,7 +113,6 @@ void CmdSendButton(void)
for(int repeat = 0; repeat <= 1; repeat++) for(int repeat = 0; repeat <= 1; repeat++)
{ {
AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("sync frame"));
digitalWrite(TX_PORT, LOW); // CC1101 in TX Mode+ digitalWrite(TX_PORT, LOW); // CC1101 in TX Mode+
delayMicroseconds(1150); delayMicroseconds(1150);
SendSyncPreamble(13); SendSyncPreamble(13);
@ -124,7 +122,7 @@ void CmdSendButton(void)
SendBit(jaroliftDevice.pack & 0x0000000000000001); SendBit(jaroliftDevice.pack & 0x0000000000000001);
jaroliftDevice.pack >>= 1; jaroliftDevice.pack >>= 1;
} }
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("finished sending bits at %d"), micros()); DEBUG_DRIVER_LOG(LOG_LEVEL_DEBUG_MORE, PSTR("finished sending bits at %d"), micros());
delay(16); // delay in loop context is save for wdt delay(16); // delay in loop context is save for wdt
} }
@ -157,14 +155,13 @@ void SendBit(byte bitToSend)
void CmndSendRaw(void) void CmndSendRaw(void)
{ {
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("cmd send called at %d"), micros()); DEBUG_DRIVER_LOG(LOG_LEVEL_DEBUG_MORE, PSTR("cmd send called at %d"), micros());
noInterrupts(); noInterrupts();
entertx(); entertx();
for(int repeat = 0; repeat <= 1; repeat++) for(int repeat = 0; repeat <= 1; repeat++)
{ {
if (XdrvMailbox.data_len > 0) if (XdrvMailbox.data_len > 0)
{ {
AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("sync frame"));
digitalWrite(TX_PORT, LOW); digitalWrite(TX_PORT, LOW);
delayMicroseconds(1150); delayMicroseconds(1150);
SendSyncPreamble(13); SendSyncPreamble(13);
@ -174,7 +171,7 @@ void CmndSendRaw(void)
{ {
SendBit(XdrvMailbox.data[i] == '1'); SendBit(XdrvMailbox.data[i] == '1');
} }
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("finished sending bits at %d"), micros()); DEBUG_DRIVER_LOG(LOG_LEVEL_DEBUG_MORE, PSTR("finished sending bits at %d"), micros());
delay(16); // delay in loop context is save for wdt delay(16); // delay in loop context is save for wdt
} }
@ -235,7 +232,7 @@ void CreateKeeloqPacket()
void InitKeeloq() void InitKeeloq()
{ {
AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("cc1101.init()")); DEBUG_DRIVER_LOG(LOG_LEVEL_DEBUG_MORE, PSTR("cc1101.init()"));
delay(100); delay(100);
cc1101.init(); cc1101.init();
AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("CC1101 done.")); AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("CC1101 done."));
@ -261,7 +258,7 @@ bool Xdrv35(uint8_t function)
switch (function) { switch (function) {
case FUNC_INIT: case FUNC_INIT:
InitKeeloq(); InitKeeloq();
AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("init done.")); DEBUG_DRIVER_LOG(LOG_LEVEL_DEBUG_MORE, PSTR("init done."));
break; break;
case FUNC_COMMAND: case FUNC_COMMAND:
AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("calling command")); AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("calling command"));