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