uses pushing box to publish to google spreadsheets with a state machine instead of a while loop
Fork of GSM_PUSHING_BOX_STATE_MACHINE by
Diff: GSMLibrary.cpp
- Revision:
- 2:8352ad91f2ee
- Parent:
- 0:41904adca656
- Child:
- 6:3ccc86304c2c
diff -r c1458b739eb6 -r 8352ad91f2ee GSMLibrary.cpp --- a/GSMLibrary.cpp Thu Mar 05 20:51:04 2015 +0000 +++ b/GSMLibrary.cpp Thu Mar 05 21:24:31 2015 +0000 @@ -1,7 +1,10 @@ #include "GSMLibrary.h" #include "gsmqueue.h" +#include <string.h> - +#define TIME_CONST 1 +#define SECONDS_TIMEOUT 10 +#define TIMEOUTLIMIT TIME_CONST //$change check with main code this will set up condition fior timeout. //definition for AT comands #define AT_OK "AT" @@ -29,48 +32,51 @@ char correct = 0; char send = 0; -char timeout = 0; +char timeout_count = 0; char received = 0; +char timeout_limit = TIMEOUTLIMIT; void gsm_tick(){ - //pre action - switch(gsm_current_state){ - case GSM_INITIALIZE: - correct = 0; - timeout = 0; - received = 0; - break; - case GSM_AT_OK: - break; - case GSM_AT_CSQ: - break; - case GSM_AT_CREG: - break; - case GSM_AT_CMGF: - break; - case GSM_AT_CMGS: - break; - case GSM_AT_SENDSMS: - break; - case GSM_SUCCESS: - break; - } //post action switch(gsm_current_state){ + //when send flag is on , send AT_OK message to gsm. case GSM_INITIALIZE: - if(send){ + pc.printf("gsm_initilize state\r\n");//&debug + correct = 0; + timeout_count = 0; + received = 0; + if(send){ //send first at_ok message + resetGSMIdleBit(); + pc.printf("sending AT_OK\r\n");//&debug gsm.puts(AT_OK); gsm.puts("\r\n"); - gsm_current_state = GSM_AT_OK; + gsm_current_state = GSM_AT_OK; } else gsm_current_state = GSM_INITIALIZE; break; + // check for repsonse to AT and if correct send AT+CSQ message case GSM_AT_OK: + timeout_count++; + pc.printf("inside AT_OK state\r\n");//&debug + if(getGSMIdleBit()){ + printQueue(); //$debug + if(findInQueue(AT_OK)){ + timeout_count = 0; + resetGSMIdleBit(); + pc.printf("sending AT_CSQ\r\n");//&debug + gsm.puts(AT_CSQ); + gsm.puts("\r\n"); + gsm_current_state = GSM_AT_CSQ; + } + else + gsm_current_state = GSM_INITIALIZE; + } + if(timeout_count >= timeout_limit) + gsm_current_state = GSM_INITIALIZE; + break; - gsm_current_state = GSM_AT_CSQ; - break; case GSM_AT_CSQ: gsm_current_state = GSM_AT_CREG; break;