init
Dependencies: aconno_I2C Lis2dh12 WatchdogTimer
Revision 17:ba55c026b1d6, committed 2018-12-17
- Comitter:
- pathfindr
- Date:
- Mon Dec 17 23:36:10 2018 +0000
- Parent:
- 16:3bf5f1a5f869
- Child:
- 18:22edaa7e74b1
- Commit message:
- 8
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| modem.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Dec 17 22:47:13 2018 +0000
+++ b/main.cpp Mon Dec 17 23:36:10 2018 +0000
@@ -292,25 +292,13 @@
//------------------------------------------------------------------------------
bool saveSettings(char* settingsBuffer) {
//process result
- int matchCount = 0;
- char TEMP_a[6];
- int TEMP_b = 0;
- int TEMP_c = 0;
- int TEMP_d = 0;
- int TEMP_e = 0;
- int TEMP_f = 0;
- int TEMP_g = 0;
- int TEMP_h = 0;
- int TEMP_i = 0;
- int TEMP_j = 0;
- int TEMP_k = 0;
- int TEMP_l = 0;
- int TEMP_m = 0;
- int TEMP_n = 0;
- time_t TEMP_o = 0;
- if ( (matchCount = sscanf(settingsBuffer,"a:%c%c%c%c%c%c,b:%d,c:%d,d:%d,e:%d,f:%d,g:%d,h:%d,i:%d,j:%d,k:%d,l:%d,m:%d,n:%d,0:%u",
- &TEMP_a[0],&TEMP_a[1],&TEMP_a[2],&TEMP_a[3],&TEMP_a[4],&TEMP_a[5],&TEMP_b,&TEMP_c,&TEMP_d,&TEMP_e,&TEMP_f,&TEMP_g,&TEMP_h,&TEMP_i,&TEMP_j,&TEMP_k,&TEMP_l,&TEMP_m,&TEMP_n,&TEMP_o) ) > 0 ) {
- DEBUG("VALUES: a:%s,b:%d,c:%d,d:%d,e:%d,f:%d,g:%d,h:%d,i:%d,j:%d,k:%d,l:%d,m:%d,n:%d,o:%d\n",TEMP_a,TEMP_b,TEMP_c,TEMP_d,TEMP_e,TEMP_f,TEMP_g,TEMP_h,TEMP_i,TEMP_j,TEMP_k,TEMP_l,TEMP_m,TEMP_n,TEMP_o);
+ int matchCount = 0;
+ char TEMP_a[6]; time_t TEMP_b = 0; int TEMP_c = -1; int TEMP_d = -1; int TEMP_e = -1; int TEMP_f = -1; int TEMP_g = -1; int TEMP_h = -1; int TEMP_i = -1;
+ int TEMP_j = -1; int TEMP_k = -1; int TEMP_l = -1; int TEMP_m = -1; int TEMP_n = -1; int TEMP_o = -1; int TEMP_p = -1; int TEMP_q = -1; int TEMP_r = -1; int TEMP_s = -1;
+ if ( (matchCount = sscanf(settingsBuffer,"a:%c%c%c%c%c%c,b:%u,c:%d,d:%d,e:%d,f:%d,g:%d,h:%d,i:%d,j:%d,k:%d,l:%d,m:%d,n:%d,o:%d,p:%d,q:%d,r:%d,s:%d",
+ &TEMP_a[0],&TEMP_a[1],&TEMP_a[2],&TEMP_a[3],&TEMP_a[4],&TEMP_a[5],&TEMP_b,&TEMP_c,&TEMP_d,&TEMP_e,&TEMP_f,&TEMP_g,&TEMP_h,&TEMP_i,&TEMP_j,&TEMP_k,&TEMP_l,&TEMP_m,&TEMP_n,&TEMP_o,&TEMP_p,&TEMP_q,&TEMP_r,&TEMP_s) ) > 0 ) {
+ DEBUG("VALUES: a:%s,b:%u,c:%d,d:%d,e:%d,f:%d,g:%d,h:%d,i:%d,j:%d,k:%d,l:%d,m:%d,n:%d,o:%d,p:%d,q:%d,r:%d,s:%d\n",
+ TEMP_a,TEMP_b,TEMP_c,TEMP_d,TEMP_e,TEMP_f,TEMP_g,TEMP_h,TEMP_i,TEMP_j,TEMP_k,TEMP_l,TEMP_m,TEMP_n,TEMP_o,TEMP_p,TEMP_q,TEMP_r,TEMP_s);
RET_haveSettings = true;
return true;
} else {
@@ -332,9 +320,10 @@
GLOBAL_imei = RET_imei;
DEBUG("imei: %lld \n",RET_imei);
if (modem.registerOnNetwork(3,60000)) {
- char* bytestosend;
- sprintf(bytestosend,"(im:%lld,%s,v:%.2f,fr:1,z:SETUP,c:1)\0",GLOBAL_imei,GLOBAL_defaultApi,GLOBAL_voltage);
- char* result = modem.USSDmessage(bytestosend, false, 2, GLOBAL_defaultApi);
+ char bytestosend[160];
+ snprintf(bytestosend,sizeof(bytestosend),"(%s,im:%lld,v:%.2f,fr:1,z:SETUP,c:1)\0",GLOBAL_defaultApi,GLOBAL_imei,GLOBAL_voltage);
+ char result[180];
+ snprintf(result,sizeof(result),"%s",modem.USSDmessage(bytestosend, true, 2, GLOBAL_defaultApi));
if (result != "err") {
DEBUG("result: %s \n",result);
saveSettings(result);
@@ -347,10 +336,10 @@
//FAILUREMODE Modem failed to turn on
}
- //while (1) {
- // Thread::wait(60000);
- // watchdog.kick();
- //}
+ while (1) {
+ Thread::wait(60000);
+ watchdog.kick();
+ }
//RESULT
if (pass) {
--- a/modem.cpp Mon Dec 17 22:47:13 2018 +0000
+++ b/modem.cpp Mon Dec 17 23:36:10 2018 +0000
@@ -158,7 +158,7 @@
uint32_t timeout = 15000;
int bufferIndex = 0;
int USSDmessageIndex = 0;
- char ATinBuffer[160];
+ char ATinBuffer[180];
int matchCount = 0;
Timer t;
t.start();
@@ -167,10 +167,10 @@
uint32_t runtime = 0;
while(!received && runtime < timeout) {
runtime = (t.read_ms() - startmillis);
- //runtime = 1; //REMOVE ME
if (ATwaitForWord("+CUSD: 0",5000)) {
led1 = 0;
if ( (matchCount = _uart.scanf(",\"%d#%[^#]",USSDmessageIndex,ATinBuffer) ) > 0 ) {
+ //DEBUG("got:%s \n",ATinBuffer);
if (USSDmessageIndex == messageIndex) {
//NEED TO GET THIS WORKING SO WE KNOW WE ARE DEALING WITH THE RIGT MESSAGE
//MOVE THE BELOW INTO THIS IF STAEMEBNTS
@@ -195,8 +195,8 @@
bool result;
int messageLength = strlen(message);
if (messageLength > USSD_MAXLENGTH) {
- char message_failsafe[160];
- snprintf(message_failsafe,sizeof(message_failsafe),"(im:%lld,%s,z:TOOBIG,c:%d)\0",messageIndex,GLOBAL_imei,api,messageIndex);
+ char message_failsafe[100];
+ snprintf(message_failsafe,sizeof(message_failsafe),"(%s,im:%lld,z:TOOBIG,c:%d)\0",api,messageIndex,GLOBAL_imei,messageIndex);
result = USSDsend(message_failsafe, maxAttempts);
} else {
result = USSDsend(message, maxAttempts);