Testing the module's internet connection (spoiler: it doesn't work) WARNING: this code has been written in a hurry during an hackathon. It's total crap.

Dependencies:   GPS_CanSat mbed

Testing the module's internet connection (spoiler: it doesn't work) WARNING: this code has been written in a hurry during an hackathon. It's total crap.

Committer:
gipmad
Date:
Sat Sep 19 14:47:39 2015 +0000
Revision:
1:180ed9f09775
Parent:
0:8f9b472ff818
-

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gipmad 0:8f9b472ff818 1 #include "gsm.h"
gipmad 0:8f9b472ff818 2
gipmad 0:8f9b472ff818 3 GSM::GSM(PinName tx, PinName rx) : _gsm(tx, rx) {
gipmad 0:8f9b472ff818 4 _gsm.baud(115200);
gipmad 0:8f9b472ff818 5 flag_gsm_get = 0;
gipmad 0:8f9b472ff818 6 flag_gsm_getend = 0;
gipmad 0:8f9b472ff818 7 _gsm.attach(this,&GSM::sample,Serial::RxIrq);
gipmad 0:8f9b472ff818 8 count = 0;
gipmad 0:8f9b472ff818 9 }
gipmad 0:8f9b472ff818 10
gipmad 0:8f9b472ff818 11 void GSM::sample() {
gipmad 0:8f9b472ff818 12 char *e;
gipmad 0:8f9b472ff818 13 getline();
gipmad 0:8f9b472ff818 14 if(flag_gsm_getend){
gipmad 0:8f9b472ff818 15 // pc.printf("\"%s\"\n", msg);
gipmad 0:8f9b472ff818 16
gipmad 0:8f9b472ff818 17 if(sscanf(msg, "+CMTI: \"SM\",%d", &SMSid) >= 1) {
gipmad 0:8f9b472ff818 18 pc.printf("Got SMS! ID: %d\n", SMSid);
gipmad 0:8f9b472ff818 19 }
gipmad 0:8f9b472ff818 20 else
gipmad 0:8f9b472ff818 21 {
gipmad 0:8f9b472ff818 22 //e = strchr(msg, '\n');
gipmad 0:8f9b472ff818 23 //pc.printf(".s: %s.\n", e);
gipmad 0:8f9b472ff818 24 if(sscanf(e, "OK") >= 1)
gipmad 0:8f9b472ff818 25 {
gipmad 0:8f9b472ff818 26 //GOT OK!
gipmad 0:8f9b472ff818 27 pc.printf("Got OK!\n");
gipmad 0:8f9b472ff818 28
gipmad 0:8f9b472ff818 29 }
gipmad 0:8f9b472ff818 30 }
gipmad 0:8f9b472ff818 31
gipmad 0:8f9b472ff818 32 /*if(sscanf(msg, "$GPGGA,%f,%f,%c,%f,%c,%d", &_time, &_latitude, &_ns, &_longitude, &_ew, &_lock) >= 1) {
gipmad 0:8f9b472ff818 33 flag_gga = 1;
gipmad 0:8f9b472ff818 34 strcpy(gga,msg);
gipmad 0:8f9b472ff818 35 float degrees = floor(_latitude / 100.0f);
gipmad 0:8f9b472ff818 36 float minutes = _latitude - (degrees * 100.0f);
gipmad 0:8f9b472ff818 37 _latitude = degrees + minutes / 60.0f;
gipmad 0:8f9b472ff818 38 degrees = floor(_longitude / 100.0f);
gipmad 0:8f9b472ff818 39 minutes = _longitude - (degrees * 100.0f);
gipmad 0:8f9b472ff818 40 _longitude = degrees + minutes /60.0f;
gipmad 0:8f9b472ff818 41 }*/
gipmad 0:8f9b472ff818 42 flag_gsm_getend = 0;
gipmad 0:8f9b472ff818 43 }
gipmad 0:8f9b472ff818 44 }
gipmad 0:8f9b472ff818 45
gipmad 0:8f9b472ff818 46 /*char* GPS::getGGA(){
gipmad 0:8f9b472ff818 47 if(flag_gga){
gipmad 0:8f9b472ff818 48 // strcpy(gga,msg);
gipmad 0:8f9b472ff818 49 flag_gga = 0;
gipmad 0:8f9b472ff818 50 }
gipmad 0:8f9b472ff818 51 return gga;
gipmad 0:8f9b472ff818 52 }
gipmad 0:8f9b472ff818 53
gipmad 0:8f9b472ff818 54 float GPS::longitude(){
gipmad 0:8f9b472ff818 55 return _longitude;
gipmad 0:8f9b472ff818 56 }
gipmad 0:8f9b472ff818 57
gipmad 0:8f9b472ff818 58 float GPS::latitude(){
gipmad 0:8f9b472ff818 59 return _latitude;
gipmad 0:8f9b472ff818 60 }
gipmad 0:8f9b472ff818 61
gipmad 0:8f9b472ff818 62 float GPS::time(){
gipmad 0:8f9b472ff818 63 return _time;
gipmad 0:8f9b472ff818 64 }
gipmad 0:8f9b472ff818 65
gipmad 0:8f9b472ff818 66 int GPS::ns(){
gipmad 0:8f9b472ff818 67 int d;
gipmad 0:8f9b472ff818 68 if(_ns == 'N'){
gipmad 0:8f9b472ff818 69 d = 1;
gipmad 0:8f9b472ff818 70 }else{
gipmad 0:8f9b472ff818 71 d = -1;
gipmad 0:8f9b472ff818 72 }
gipmad 0:8f9b472ff818 73 return d;
gipmad 0:8f9b472ff818 74 }
gipmad 0:8f9b472ff818 75
gipmad 0:8f9b472ff818 76 int GPS::ew(){
gipmad 0:8f9b472ff818 77 int d;
gipmad 0:8f9b472ff818 78 if(_ew == 'E'){
gipmad 0:8f9b472ff818 79 d = 1;
gipmad 0:8f9b472ff818 80 }else{
gipmad 0:8f9b472ff818 81 d = -1;
gipmad 0:8f9b472ff818 82 }
gipmad 0:8f9b472ff818 83 return d;
gipmad 0:8f9b472ff818 84 }
gipmad 0:8f9b472ff818 85
gipmad 0:8f9b472ff818 86 int GPS::lock(){
gipmad 0:8f9b472ff818 87 return _lock;
gipmad 0:8f9b472ff818 88 }*/
gipmad 0:8f9b472ff818 89
gipmad 0:8f9b472ff818 90 void GSM::getline() {
gipmad 0:8f9b472ff818 91 char temp;
gipmad 0:8f9b472ff818 92 temp = _gsm.getc();
gipmad 0:8f9b472ff818 93
gipmad 0:8f9b472ff818 94 pc.putc(temp);
gipmad 0:8f9b472ff818 95 /*if(temp == '$'){
gipmad 0:8f9b472ff818 96 flag_gsm_get = 1;
gipmad 0:8f9b472ff818 97 count = 0;
gipmad 0:8f9b472ff818 98 }*/
gipmad 0:8f9b472ff818 99 //if(flag_gsm_get)
gipmad 0:8f9b472ff818 100 {
gipmad 0:8f9b472ff818 101 // pc.printf(".%d%c.",count,temp);
gipmad 0:8f9b472ff818 102
gipmad 0:8f9b472ff818 103 msg[count] = temp;
gipmad 0:8f9b472ff818 104 if(temp == '\n'){
gipmad 0:8f9b472ff818 105 msg[count] = '\0';
gipmad 0:8f9b472ff818 106 flag_gsm_getend = 1;
gipmad 0:8f9b472ff818 107 count = 0;
gipmad 0:8f9b472ff818 108 //flag_gps_get = 0;
gipmad 0:8f9b472ff818 109 }
gipmad 0:8f9b472ff818 110 else
gipmad 0:8f9b472ff818 111 count ++;
gipmad 0:8f9b472ff818 112 }
gipmad 0:8f9b472ff818 113 }