Reduce flash usage up to 214k in one click (#2929)

* std::stringstream -> std::string

* Fix small issues

* Small fix 2
This commit is contained in:
Roman Savrulin
2019-07-09 19:31:17 +03:00
committed by Me No Dev
parent 20498cf8b1
commit a22ec4a978
20 changed files with 229 additions and 205 deletions

View File

@ -7,7 +7,7 @@
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#include <string.h>
#include <sstream>
#include <stdio.h>
#include "esp32-hal-log.h"
#include "BLEEddystoneTLM.h"
@ -54,62 +54,44 @@ uint32_t BLEEddystoneTLM::getTime() {
} // getTime
std::string BLEEddystoneTLM::toString() {
std::stringstream ss;
std::string out = "";
uint32_t rawsec;
ss << "Version ";
ss << std::dec << m_eddystoneData.version;
ss << "\n";
std::string out = "";
uint32_t rawsec = ENDIAN_CHANGE_U32(m_eddystoneData.tmil);
char val[6];
ss << "Battery Voltage ";
ss << std::dec << ENDIAN_CHANGE_U16(m_eddystoneData.volt);
ss << " mV\n";
out += "Version " + m_eddystoneData.version;
out += "\n";
out += "Battery Voltage " + ENDIAN_CHANGE_U16(m_eddystoneData.volt);
out += " mV\n";
ss << "Temperature ";
ss << (float) m_eddystoneData.temp;
ss << " °C\n";
out += "Temperature ";
snprintf(val, sizeof(val), "%d", m_eddystoneData.temp);
out += val;
out += ".0 °C\n";
ss << "Adv. Count ";
ss << std::dec << ENDIAN_CHANGE_U32(m_eddystoneData.advCount);
out += "Adv. Count ";
snprintf(val, sizeof(val), "%d", ENDIAN_CHANGE_U32(m_eddystoneData.advCount));
out += val;
out += "\n";
ss << "\n";
out += "Time ";
ss << "Time ";
snprintf(val, sizeof(val), "%04d", rawsec / 864000);
out += val;
out += ".";
rawsec = ENDIAN_CHANGE_U32(m_eddystoneData.tmil);
std::stringstream buffstream;
buffstream << "0000";
buffstream << std::dec << rawsec / 864000;
std::string buff = buffstream.str();
snprintf(val, sizeof(val), "%02d", (rawsec / 36000) % 24);
out += val;
out += ":";
ss << buff.substr(buff.length() - 4, buff.length());
ss << ".";
snprintf(val, sizeof(val), "%02d", (rawsec / 600) % 60);
out += val;
out += ":";
buffstream.str("");
buffstream.clear();
buffstream << "00";
buffstream << std::dec << (rawsec / 36000) % 24;
buff = buffstream.str();
ss << buff.substr(buff.length()-2, buff.length());
ss << ":";
snprintf(val, sizeof(val), "%02d", (rawsec / 10) % 60);
out += val;
out += "\n";
buffstream.str("");
buffstream.clear();
buffstream << "00";
buffstream << std::dec << (rawsec / 600) % 60;
buff = buffstream.str();
ss << buff.substr(buff.length() - 2, buff.length());
ss << ":";
buffstream.str("");
buffstream.clear();
buffstream << "00";
buffstream << std::dec << (rawsec / 10) % 60;
buff = buffstream.str();
ss << buff.substr(buff.length() - 2, buff.length());
ss << "\n";
return ss.str();
return out;
} // toString
/**