Refactor ShowFreeMem

This commit is contained in:
Theo Arends 2021-06-25 17:09:53 +02:00
parent ef508c629f
commit e02b58a6ed
7 changed files with 20 additions and 22 deletions

View File

@ -154,9 +154,7 @@ void ExecuteCommand(const char *cmnd, uint32_t source)
// cmnd: "status 0" = stopic "status" and svalue " 0"
// cmnd: "var1 =1" = stopic "var1" and svalue " =1"
// cmnd: "var1=1" = stopic "var1" and svalue "=1"
#ifdef USE_DEBUG_DRIVER
ShowFreeMem(PSTR("ExecuteCommand"));
#endif
SHOW_FREE_MEM(PSTR("ExecuteCommand"));
ShowSource(source);
const char *pos = cmnd;
@ -196,9 +194,7 @@ void ExecuteCommand(const char *cmnd, uint32_t source)
void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len)
{
#ifdef USE_DEBUG_DRIVER
ShowFreeMem(PSTR("CommandHandler"));
#endif
SHOW_FREE_MEM(PSTR("CommandHandler"));
bool grpflg = false;
uint32_t real_index = SET_MQTT_GRP_TOPIC;

View File

@ -502,6 +502,11 @@ bool first_device_group_is_local = true;
#define DEBUG_TRACE_LOG(...)
#endif
#ifdef USE_DEBUG_DRIVER
#define SHOW_FREE_MEM(WHERE) ShowFreeMem(WHERE);
#else
#define SHOW_FREE_MEM(WHERE)
#endif
/*********************************************************************************************\
* Macro for SetOption synonyms

View File

@ -693,9 +693,7 @@ void WSContentBegin(int code, int ctype) {
void _WSContentSend(const char* content, size_t size) { // Lowest level sendContent for all core versions
Webserver->sendContent(content, size);
#ifdef USE_DEBUG_DRIVER
ShowFreeMem(PSTR("WSContentSend"));
#endif
SHOW_FREE_MEM(PSTR("WSContentSend"));
DEBUG_CORE_LOG(PSTR("WEB: Chunk size %d"), size);
}

View File

@ -377,6 +377,9 @@ void CmndFileDownload(void) {
*/
if (FMqtt.file_buffer) {
if (FMqtt.file_pos < FMqtt.file_size) {
#ifdef USE_TASMESH
uint32_t chunk_size = 2048;
#else
uint32_t chunk_size = 4096;
if (!FMqtt.file_binary) {
/*
@ -386,6 +389,7 @@ void CmndFileDownload(void) {
*/
chunk_size = (((ResponseSize() - FileTransferHeaderSize) / 4) * 3) -2;
}
#endif
uint32_t bytes_left = FMqtt.file_size - FMqtt.file_pos;
uint32_t write_bytes = (bytes_left < chunk_size) ? bytes_left : chunk_size;
uint8_t* buffer = FMqtt.file_buffer + FMqtt.file_pos;
@ -400,6 +404,9 @@ void CmndFileDownload(void) {
char* base64_data = (char*)malloc(encode_base64_length(write_bytes) +2);
if (base64_data) {
Response_P(PSTR("{\"Id\":%d,\"Data\":\""), FMqtt.file_id); // FileTransferHeaderSize
SHOW_FREE_MEM(PSTR("CmndFileDownload"));
encode_base64((unsigned char*)buffer, write_bytes, (unsigned char*)base64_data);
ResponseAppend_P(base64_data);
ResponseAppend_P("\"}");

View File

@ -513,9 +513,7 @@ bool MqttPublishLib(const char* topic, const uint8_t* payload, unsigned int plen
}
void MqttDataHandler(char* mqtt_topic, uint8_t* mqtt_data, unsigned int data_len) {
#ifdef USE_DEBUG_DRIVER
ShowFreeMem(PSTR("MqttDataHandler"));
#endif
SHOW_FREE_MEM(PSTR("MqttDataHandler"));
// Do not allow more data than would be feasable within stack space
if (data_len >= MQTT_MAX_PACKET_SIZE) { return; }
@ -620,9 +618,7 @@ void MqttPublishLoggingAsync(bool refresh) {
void MqttPublishPayload(const char* topic, const char* payload, uint32_t binary_length, bool retained) {
// Publish <topic> payload string or binary when binary_length set with optional retained
#ifdef USE_DEBUG_DRIVER
ShowFreeMem(PSTR("MqttPublish"));
#endif
SHOW_FREE_MEM(PSTR("MqttPublish"));
bool binary_data = (binary_length > 0);
if (!binary_data) {
@ -640,7 +636,7 @@ void MqttPublishPayload(const char* topic, const char* payload, uint32_t binary_
log_data_topic = (MESHroleNode()) ? F("MSH: ") : F(D_LOG_MQTT); // MSH: or MQT:
#else
log_data_topic = F(D_LOG_MQTT); // MQT:
#endif
#endif // USE_TASMESH
log_data_topic += topic; // stat/tasmota/STATUS2
} else {
log_data_topic = F(D_LOG_RESULT); // RSL:

View File

@ -806,9 +806,7 @@ bool RulesProcessEvent(const char *json_event)
Rules.busy = true;
bool serviced = false;
#ifdef USE_DEBUG_DRIVER
ShowFreeMem(PSTR("RulesProcessEvent"));
#endif
SHOW_FREE_MEM(PSTR("RulesProcessEvent"));
//AddLog(LOG_LEVEL_DEBUG, PSTR("RUL: ProcessEvent |%s|"), json_event);

View File

@ -1576,9 +1576,7 @@ void DisplayJsonValue(const char* topic, const char* device, const char* mkey, c
char source[Settings->display_cols[0] - Settings->display_cols[1]];
char svalue[Settings->display_cols[1] +1];
#ifdef USE_DEBUG_DRIVER
ShowFreeMem(PSTR("DisplayJsonValue"));
#endif
SHOW_FREE_MEM(PSTR("DisplayJsonValue"));
memset(spaces, 0x20, sizeof(spaces));
spaces[sizeof(spaces) -1] = '\0';