RAM reduction using F() macro

This commit is contained in:
Pavel Brychta 2019-06-16 09:49:50 +02:00
parent a5ad4c4e1d
commit 68b8bf084a

View File

@ -198,6 +198,8 @@ public:
Intervals[i] = 0;
job = state = requests = 0;
//SMSo.Text.reserve(150);
//SMSi.Text.reserve(150);
}
~ThreadedGSM(){};
@ -302,6 +304,13 @@ public:
SMSo.Text = Text;
}
void sendSMS(String& Number, char *Text)
{
requests |= (REQ_OUTBOX);
SMSo.Number = Number;
SMSo.Text = Text;
}
protected:
private:
@ -349,7 +358,7 @@ private:
case STARTUP_CHK_CPIN:
if(dte.getResult() == DTE::EXPECT_RESULT)
{
if(dte.getBuffer().indexOf("+CPIN: READY") != -1)
if(dte.getBuffer().indexOf(F("+CPIN: READY")) != -1)
{
dte.SendCommand("AT+CREG?\r", THREADEDGSM_AT_TIMEOUT, "OK\r");
state = STARTUP_CHK_CREG;
@ -363,7 +372,7 @@ private:
case STARTUP_CHK_CREG:
if(dte.getResult() == DTE::EXPECT_RESULT)
{
if((dte.getBuffer().indexOf(",1") >= 0) || (dte.getBuffer().indexOf(",5") >= 0))
if((dte.getBuffer().indexOf(F(",1")) >= 0) || (dte.getBuffer().indexOf(F(",5")) >= 0))
{
dte.SendCommand("AT+CLTS=1\r", THREADEDGSM_AT_TIMEOUT, "OK\r");
state = STARTUP_CHK_CLTS;
@ -412,18 +421,18 @@ private:
state = CLOCK_VERIFY;
break;
case CLOCK_VERIFY:
int index = dte.getBuffer().indexOf("+CCLK: ");
int index = dte.getBuffer().indexOf(F("+CCLK: "));
if(index >= 0)
{
// parse clock
index+=8;
int endindex;
endindex = dte.getBuffer().indexOf("+", index);
endindex = dte.getBuffer().indexOf(F("+"), index);
if(endindex >= 0)
clockTime = dte.getBuffer().substring(index, endindex);
else
{
endindex = dte.getBuffer().indexOf("-", index);
endindex = dte.getBuffer().indexOf(F("-"), index);
if(endindex >= 0)
clockTime = dte.getBuffer().substring(index, endindex);
}
@ -460,7 +469,7 @@ private:
state = SIGNAL_VERIFY;
break;
case SIGNAL_VERIFY:
int index = dte.getBuffer().indexOf("+CSQ: ");
int index = dte.getBuffer().indexOf(F("+CSQ: "));
if(index >= 0)
{
// parse signal
@ -494,17 +503,17 @@ private:
state = BATTERY_VERIFY;
break;
case BATTERY_VERIFY:
int index = dte.getBuffer().indexOf("+CBC:");
int index = dte.getBuffer().indexOf(F("+CBC:"));
if(index >= 0)
{
BatteryInfo BattInfo;
// parse battery level
String buffer = dte.getBuffer().substring(index);
String buffer2 = buffer.substring(buffer.indexOf(",") + 1);
String buffer2 = buffer.substring(buffer.indexOf(F(",")) + 1);
buffer = buffer2;
BattInfo.Percent = buffer2.substring(0, buffer2.indexOf(",")).toInt(); // converts the result to interger
buffer2 = buffer.substring(buffer.indexOf(",") + 1);
BattInfo.Voltage = buffer2.substring(0, buffer2.indexOf("\r")).toInt(); // converts the result to interger
BattInfo.Percent = buffer2.substring(0, buffer2.indexOf(F(","))).toInt(); // converts the result to interger
buffer2 = buffer.substring(buffer.indexOf(F(",")) + 1);
BattInfo.Voltage = buffer2.substring(0, buffer2.indexOf(F("\r"))).toInt(); // converts the result to interger
if(this->configuration.battery != NULL)
this->configuration.battery(*this, BattInfo);
}
@ -558,10 +567,10 @@ private:
if(dte.getResult() == DTE::EXPECT_RESULT)
{
//fetch index
int indexStart = dte.getBuffer().indexOf("+CMGL: ");
int indexStart = dte.getBuffer().indexOf(F("+CMGL: "));
if (indexStart >= 0)
{
Message.Index = dte.getBuffer().substring(indexStart + 7, dte.getBuffer().indexOf(",")).toInt();
Message.Index = dte.getBuffer().substring(indexStart + 7, dte.getBuffer().indexOf(F(","))).toInt();
if(Message.Index != 0)
{
dte.Delay(2000);
@ -594,22 +603,22 @@ private:
case READ_CHK_CMGR:
if(dte.getResult() == DTE::EXPECT_RESULT)
{
int indexStart = dte.getBuffer().indexOf("+CMGR: ");
int indexStart = dte.getBuffer().indexOf(F("+CMGR: "));
if(indexStart >= 0)
{
int indexStartPDU = dte.getBuffer().indexOf("\r\n", indexStart);
int indexStartPDU = dte.getBuffer().indexOf(F("\r\n"), indexStart);
if (indexStartPDU >= 0)
{
indexStartPDU+=2;
int indexEndPDU = dte.getBuffer().indexOf("\r", indexStartPDU);
int indexEndPDU = dte.getBuffer().indexOf(F("\r"), indexStartPDU);
if(indexEndPDU >= 0)
SMSi.Text = dte.getBuffer().substring(indexStartPDU, indexEndPDU);
}
indexStartPDU = dte.getBuffer().indexOf(",\"", indexStart);
indexStartPDU = dte.getBuffer().indexOf(F(",\""), indexStart);
if (indexStartPDU >= 0)
{
indexStartPDU += 2;
int indexEndPDU = dte.getBuffer().indexOf("\",", indexStartPDU);
int indexEndPDU = dte.getBuffer().indexOf(F("\","), indexStartPDU);
if (indexEndPDU >= 0)
SMSi.Number = dte.getBuffer().substring(indexStartPDU, indexEndPDU);
}
@ -642,6 +651,8 @@ private:
void Outbox()
{
String CMD;
//CMD.reserve(200);
int lastState = state;
switch(state)
{