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:
- 15:19ae032e2e54
- Parent:
- 14:56a2c371ce18
- Child:
- 16:6807d437cd48
--- a/GSMLibrary.cpp Fri Mar 06 01:19:34 2015 +0000 +++ b/GSMLibrary.cpp Fri Mar 06 02:45:22 2015 +0000 @@ -2,9 +2,9 @@ #include "gsmqueue.h" #include <string.h> -#define TIME_CONST 1 -#define SECONDS_TIMEOUT 100 -#define TIMEOUTLIMIT TIME_CONST //$change check with main code this will set up condition fior timeout. +#define TIME_CONST .3 +#define SECONDS_TIMEOUT 40 +#define TIMEOUTLIMIT SECONDS_TIMEOUT/TIME_CONST //$change check with main code this will set up condition fior timeout. //definition for AT comands #define AT_OK "AT" @@ -13,7 +13,7 @@ #define AT_CMGF "AT+CMGF=1" #define RECEIVER_PHONE_NUMBER "\"+18014722842\"" #define AT_CMGS "AT+CMGS=" RECEIVER_PHONE_NUMBER -#define MESSAGE_BODY "how did we get 31?" +#define MESSAGE_BODY "stress test\32\32" //Definition for at repsonses //Please notice that after ":" the gsm will usually send aditional information @@ -22,8 +22,8 @@ #define AT_CREG_RESPONSE "+CREG:"//+CREG: <arg1>,<arg2> where <arg1> = 0-2(see AT command descriptions), <arg2> = 0-5, 0 not registered to nework and not looking for one. 1 is conected to network, 2 is not conected but searching #define AT_CMGF_RESPONSE "OK" #define AT_CMGS_RESPONSE ">" //Message is written aftersymbol -#define AT_SENDSMS_RESPONSE "+CMGS:" // +CMGS: <id> this will include the message id. CMGS ERROR for error and -#define AT_SUCCESS_REPSONSE "OK" +#define AT_SENDSMS_RESPONSE ">" // +CMGS: <id> this will include the message id. CMGS ERROR for error and +#define AT_SUCCESS_REPSONSE "+CMGS:" extern Serial pc; @@ -31,19 +31,15 @@ extern uint8_t buffer[BUFFER_LENGTH];//buffer storing char gsm_states gsm_current_state = GSM_INITIALIZE; -char correct = 0; char send = 0; int timeout_count = 0; -char received = 0; char timeout_limit = TIMEOUTLIMIT; void gsm_tick(){ - - //post action - //if(++timeout_count >= timeout_limit){ - // timeout_count=0; - // gsm_current_state = GSM_INITIALIZE; - //} + if(++timeout_count >= timeout_limit){ + timeout_count=0; + gsm_current_state = GSM_INITIALIZE; + } switch(gsm_current_state){ //when send flag is on , send AT_OK message to gsm. case GSM_INITIALIZE: @@ -73,6 +69,7 @@ gsm_current_state = GSM_AT_CSQ; } else{ + resetGSMIdleBit(); gsm.puts(AT_OK); gsm.puts("\r\n"); } @@ -94,6 +91,7 @@ } } else{ + resetGSMIdleBit(); gsm.puts(AT_CSQ); gsm.puts("\r\n"); } @@ -118,6 +116,7 @@ } } if(gsm_current_state == GSM_AT_CREG){ + resetGSMIdleBit(); gsm.puts(AT_CREG); gsm.puts("\r\n"); } @@ -137,6 +136,7 @@ gsm_current_state = GSM_AT_CMGS; } else{ + resetGSMIdleBit(); gsm.puts(AT_CMGF); gsm.puts("\r\n"); } @@ -152,12 +152,13 @@ resetGSMIdleBit(); pc.printf("sending MESSAGE_BODY\r\n");//&debug gsm.puts(MESSAGE_BODY); //substitute - gsm.putc((char)26); gsm.puts("\r\n"); + flushQueue(); gsm_current_state = GSM_AT_SENDSMS; } else { + resetGSMIdleBit(); gsm.puts(AT_CMGS); gsm.puts("\r\n"); } @@ -169,16 +170,17 @@ pc.printf("gsm_send_sms state\r\n");//&debug if(getGSMIdleBit()){ printQueue(); //$debug - if(findInQueue(AT_SENDSMS_RESPONSE)){ + + if(findInQueue(AT_SENDSMS_RESPONSE)){ resetGSMIdleBit(); - pc.printf("sending message ID: %iY\r\n",parseInt());//&debug gsm_current_state = GSM_SUCCESS; } else { + resetGSMIdleBit(); gsm.puts(AT_CMGF); gsm.puts("\r\n"); - gsm_current_state = GSM_AT_CMGF; + gsm_current_state = GSM_AT_CMGS; } } break; @@ -186,9 +188,14 @@ case GSM_SUCCESS: pc.printf("gsm_success state\r\n");//&debug - if(findInQueue(AT_SENDSMS_RESPONSE)) + if(findInQueue(AT_SENDSMS_RESPONSE)){ + pc.printf("sending message ID: %iY\r\n",parseInt());//&debug pc.printf("Message SENT!\r\n");//&debug - gsm_current_state = GSM_INITIALIZE; + } + resetGSMIdleBit(); + gsm.puts(AT_CMGS); + gsm.puts("\r\n"); + gsm_current_state = GSM_AT_CMGS; break; default: pc.printf("This is a state error");