ALARMA GSM01

Dependencies:   GPS7 mbed

Fork of Tarea_6_GPS by procesadores FAC

Files at this revision

API Documentation at this revision

Comitter:
procesadores_FAC
Date:
Fri Jun 19 17:45:34 2015 +0000
Commit message:
Tarea UnalMed;

Changed in this revision

DebouncedIn.cpp Show annotated file Show diff for this revision Revisions of this file
DebouncedIn.h Show annotated file Show diff for this revision Revisions of this file
GPS_G.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r b2a6aa7c0c8c DebouncedIn.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DebouncedIn.cpp	Fri Jun 19 17:45:34 2015 +0000
@@ -0,0 +1,93 @@
+#include "DebouncedIn.h"
+#include "mbed.h"
+
+/*
+ * Constructor
+ */
+DebouncedIn::DebouncedIn(PinName in) 
+    : _in(in) {    
+        
+    // reset all the flags and counters    
+    _samples = 0;
+    _output = 0;
+    _output_last = 0;
+    _rising_flag = 0;
+    _falling_flag = 0;
+    _state_counter = 0;
+    
+    // Attach ticker
+    _ticker.attach(this, &DebouncedIn::_sample, 0.005);     
+}
+  
+void DebouncedIn::_sample() {
+
+    // take a sample
+    _samples = _samples >> 1; // shift left
+      
+    if (_in) {
+        _samples |= 0x80;
+    }  
+      
+    // examine the sample window, look for steady state
+    if (_samples == 0x00) {
+        _output = 0;
+    } 
+    else if (_samples == 0xFF) {
+        _output = 1;
+    }
+
+
+    // Rising edge detection
+    if ((_output == 1) && (_output_last == 0)) {
+        _rising_flag++;
+        _state_counter = 0;
+    }
+
+    // Falling edge detection
+    else if ((_output == 0) && (_output_last == 1)) {
+        _falling_flag++;
+        _state_counter = 0;
+    }
+    
+    // steady state
+    else {
+        _state_counter++;
+    }
+    
+   // update the output
+    _output_last = _output;
+    
+}
+
+
+
+// return number of rising edges
+int DebouncedIn::rising(void) {
+    int return_value = _rising_flag; 
+    _rising_flag = 0;
+    return(return_value);
+}
+
+// return number of falling edges
+int DebouncedIn::falling(void) {
+    int return_value = _falling_flag; 
+    _falling_flag = 0;
+    return(return_value);
+}
+
+// return number of ticsk we've bene steady for
+int DebouncedIn::steady(void) {
+return(_state_counter);
+}
+
+// return the debounced status
+int DebouncedIn::read(void) {
+    return(_output);
+}
+
+// shorthand for read()
+DebouncedIn::operator int() {
+    return read();
+}
+
+
diff -r 000000000000 -r b2a6aa7c0c8c DebouncedIn.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DebouncedIn.h	Fri Jun 19 17:45:34 2015 +0000
@@ -0,0 +1,31 @@
+#include "mbed.h"
+
+    class DebouncedIn {
+        public:      
+             DebouncedIn(PinName in);
+
+             int read (void);
+             operator int();
+              
+             int rising(void);
+             int falling(void);
+             int steady(void);
+              
+        private :    
+               // objects
+               DigitalIn _in;    
+               Ticker _ticker;
+
+               // function to take a sample, and update flags
+               void _sample(void);
+
+               // counters and flags
+               int _samples;
+               int _output;
+               int _output_last;
+               int _rising_flag;
+               int _falling_flag;
+               int _state_counter;
+
+    };
+    
\ No newline at end of file
diff -r 000000000000 -r b2a6aa7c0c8c GPS_G.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GPS_G.lib	Fri Jun 19 17:45:34 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/tony63/code/GPS7/#8d7c7165ffe2
diff -r 000000000000 -r b2a6aa7c0c8c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jun 19 17:45:34 2015 +0000
@@ -0,0 +1,375 @@
+//programa para celular siemens que recibe un mensaje de texto t activa una salida en formato
+//pdu hex
+#include "mbed.h"
+#include "DebouncedIn.h"
+#include "stdio.h"
+#include "string.h"
+#include "GPS.h"
+
+
+
+
+Timer t;
+DigitalOut LedVerde(LED2);
+DigitalOut LedRojo(LED1);
+DigitalOut LedAzul(LED3);
+
+///////////////////////////////////////////
+ 
+Serial GSM(PTE0,PTE1);  //puertos del FRDM para el modem
+Serial pc(USBTX,USBRX);
+GPS gps(PTE22, PTE23);   // Puerto del FDRM para el gps 
+
+////////////////////////////
+//PARAMETROS
+////////////////////////////////
+
+
+short DE[255];
+short DS[255];
+
+char buffer[512];
+char buffermsg[100];
+char buffer1[13];
+char mensaje[100];
+int count;
+int i,K,LENOUT,LENIN,C;
+
+char Tel[15];
+char cel[15];
+char ojala[15]; // OJO
+
+int c=0;
+int cont=0;
+unsigned char CtrlZ = 0x1A; 
+bool Flag = false; 
+char r[]=""; 
+char msg[256];
+char char1;
+
+int index;
+
+//////
+//longitud  y latitud 
+////
+
+
+float lo,la;
+char clo[255], cla[255];   //
+int LENINlo,LENINla,LENINla_lo;
+char la_lo[255];
+
+char http2[255];
+char http[] = "http://maps.google.com/maps?q=";
+
+
+
+//////////////
+// convercion oct sept 
+////////////
+
+
+int iht,Kht,ChtLENOUTht,LENINht;
+int ioct,Koct,LENOUToct,LENINoct,Coct;
+char DEoct[255];
+char DSoct[255];
+char buf[100];
+
+/////////////////////////
+//cocanteo rellenos y numero 
+//////////////////////////
+
+char relle1[]=  "0011000A91";
+char relle2[]=  "10000AA";
+char relle3[]=     "68";
+
+/////////////////////////////////////////////
+// funciones  
+////////////////////////////////////////////
+ 
+int readBuffer(char *buffer,int count)
+{
+    int i=0; 
+    t.start(); 
+    while(1) {
+        while (GSM.readable()) {
+            char c = GSM.getc();
+            if (c == '\r' || c == '\n') c = '$';
+            buffer[i++] = c;
+            if(i > count)break;
+        }
+       if(i > count)break;     // ojooo
+        if(t.read() > 3) {
+            t.stop();
+            t.reset();
+            break;
+        }
+    }
+    
+    wait(0.5);
+    while(GSM.readable()) {  
+        char c = GSM.getc();
+    }
+    return 0;
+}
+
+///////////////////////////////////////////////
+//Programass
+///////////////////////////////////////////////
+    
+int main(void)
+       { 
+       
+       LedVerde=1;
+       LedRojo=1;
+       LedAzul=1;
+ 
+   
+       GSM.baud(9600);
+       GSM.format(8,Serial::None,1); 
+
+       GSM.printf("AT\r\n");
+       wait(0.5);
+       GSM.printf("AT+CNMI=1,1\r\n");
+       wait(0.5);
+       GSM.printf("AT+CMGF=0\r\n");
+       wait(0.5);
+       GSM.printf("ATE\r\n");
+       wait(0.5);
+       GSM.printf("CBST=0,0,1\r\n");
+       wait(0.5);  
+             
+     
+     while(1){ 
+          
+       if (GSM.readable()) {
+            readBuffer(buffer,100);
+            pc.printf("buffer= %s\n\r ",buffer);
+            pc.printf("buffer= %c  %c\n\r ",buffer[10],buffer[11]);
+                if(buffer[67]=='A'){for(i=0;i<86;i++)
+                 {buffermsg[i]=buffer[i];}
+                 pc.printf("mensaje= %s\n\r ",buffermsg); 
+                 pc.printf("mensaje[72]= %c mensaje[73]=%c\n\r ",buffermsg[72],buffermsg[73]);        
+                 buffer[67]='c';
+                 
+                 if (buffermsg[69] == '2'){    // PARA CUANDO LA CLAVE ES On
+                        LENIN=2; //numero de caracteres de abajo son los octetos
+                        DE[0]=0x47;
+                        DE[1]=0x37;
+                     }
+                 if (buffermsg[69] == '3'&& buffermsg[70] == '4'){  // PARA CUANDO LA CLAVE ES Off
+                        LENIN=3; //numero de caracteres de abajo son los octetos
+                        DE[0]=0x4F;
+                        DE[1]=0xB3;
+                        DE[2]=0x19;
+                    }
+                  if (buffermsg[69] == '3'&& buffermsg[70] == 'C'){  // PARA CUANDO LA CLAVE ES Cor
+                        LENIN=3; //numero de caracteres de abajo son los octetos
+                        DE[0]=0xC3;
+                        DE[1]=0xB7;
+                        DE[2]=0x1C;
+                    }
+                 
+                    LENOUT= LENIN*8/7;
+                    K=7;
+                    C=0;
+                    DS[0]=DE[0] & 0x7F;  // la primera sola
+                    pc.printf("%2X\n",DS[0]);
+                   
+                    for (i=1;i < LENOUT;i++){  // inicia el algoritmo
+                        DS[i]=(DE[i-1-C]>>K | DE[i-C]<<(8-K))& 0x7F;  //valido para todos
+                        pc.printf("%2X\n",DS[i]);
+                        
+                        if (K==0) {K=8;C++;}
+                    K--;
+                    }
+                    
+                    for (i=0 ;i<=9;i++)  
+                    {
+                     Tel[i] = buffermsg[40+i];
+                    }   
+                    pc.printf("\n");
+                    pc.printf("%c%c%c%c%c%c%c%c%c%c",Tel[1],Tel[0],Tel[3],Tel[2],Tel[5],Tel[4],Tel[7],Tel[6],Tel[9],Tel[8]);
+            
+                 }
+                      
+        if(buffer[10]=='S'&& buffer[11]=='M'){
+             for(i=0;i<5;i++)
+             {buffer1[i]=buffer[2+i];}
+             pc.printf("buffer1= %s\n\r ",buffer1);         
+             buffer[10]='c';
+             buffer[11]='c';
+             }
+        if(buffer1[3]=='T'){pc.printf("AT+CMGL=0\n\r");
+            wait(0.5);
+            GSM.printf("AT+CMGL=0\r\n");
+            buffer1[3]='p';
+            }
+            
+       
+        if(DS[0]-67 == 0&& DS[1]-111==0)   // Cor en octetos es 436f72
+        {
+        pc.printf("\n");
+        LedAzul=0;
+        
+        DS[0] = '\0';
+        DS[1] = '\0';
+           
+           if(gps.sample())
+            {
+               lo =gps.longitude;
+               la =gps.latitude;
+               pc.printf("longitud_entera=%f, Latitud entera=%f\n", lo, la);
+         
+                  wait(0.5);         
+            //LONGITUD/        
+            sprintf (clo, "%f", lo); 
+            pc.printf ( "\nlongitud = %s\n",clo);
+            LENINlo=strlen(clo);  
+            
+            /*  for (ilo=0;ilo<LENINlo;ilo++){
+                pc.printf("%c,",clo[ilo]);       
+            } */        
+            
+           wait(0.5);
+           //LATITUD/
+           sprintf (cla, "%f", la); 
+           pc.printf ( "\nlatitud = %s\n",cla);
+           LENINla=strlen(cla); 
+            
+           /*for (ila1=0;ila1<LENINla1;ila1++){
+                pc.printf("%c,",cla[ila1]);       
+           }*/
+
+          
+        ///////////////////////////////////////////////////            
+        // CONCATENO LONGITUD Y LATITUD
+        ///////////////////////////////////////////////////
+
+           strcpy(la_lo,cla);
+           strcat(la_lo,",");
+           strcat(la_lo,clo);
+               
+           pc.printf ( "\nla_lo: %s\n",la_lo);
+           
+           LENINla_lo=strlen(la_lo);
+
+           /*for (j=0;j<LENINla_lo;j++){
+                pc.printf("%c\n",la_lo[j]);       
+           }*/    
+           
+         ////////////////////////////////////////////////////////      
+        // CONCATENO LONGITUD, LATITUD Y EL http//:
+        ////////////////////////////////////////////////////////
+            strcpy(http2,http);
+            strcat(http2,la_lo);         
+            pc.printf ( "%s\n",http2);
+            pc.printf ( "\n" );
+           
+           
+        //////////////////////////////////////////////////////////////////////
+        // convierto http2 de oct a sep
+        ////////////////////////////////////////////////////////////////////////       
+       
+        LENINht=strlen(http2);
+        pc.printf("%d\n",LENINht); 
+        for (iht=0;iht<LENINht;iht++){
+             pc.printf("%2X",http2[iht]);       
+            } 
+        pc.printf ( "\n" );
+      
+        /////////////////////////////////////
+
+        LENINoct=strlen(http2);
+        pc.printf("%d\n",LENINoct);
+            for (ioct=0;ioct<LENINoct;ioct++)
+          {
+                DEoct[ioct]=http2[ioct];
+                pc.printf("%2X,%d\n",DEoct[ioct],ioct);       
+           }
+        ////////////////////////////////////////        
+       
+         Koct=0;
+         Coct=0;
+        
+         for (ioct=0;ioct < LENINoct;ioct++)
+         {
+                DSoct[ioct]=DEoct[ioct+Coct]>>Koct | DEoct[ioct+Coct+1]<<(7-Koct);
+                if (DSoct[ioct]==0x00){
+                    LENOUToct=ioct; 
+                    pc.printf("\n");
+                    pc.printf("%s",DEoct);
+                    pc.printf("out =%d",LENOUToct);
+                        for (ioct=0;ioct<LENOUToct;ioct++){
+                            pc.printf("%2X,%d\r\n",DSoct[ioct]&0x000000FF,ioct);
+                        }
+                  }
+       //             pc.printf("LENOUT:%d,LENIN:%d\r\n",LENOUToct,strlen(DEoct));
+                  
+                  //}
+                 Koct++;
+                if (Koct==7)
+                {
+                Koct=0;Coct++;
+                } // se chequea que ya se acabaron los bits en un ciclo de conversion.
+         }  
+        
+        /////////////////////////////////////////////////////////
+        // CONCATENO LOS RELLENOS Y EL NUMERO DEL CELULAR 
+        ////////////////////////////////////////////////////////
+        
+        
+        
+        
+        wait(5);
+        index=56;
+        GSM.printf("AT+CMGS=%d\r\n",index);
+        pc.printf("AT+CMGS=%d\r\n",index);
+        pc.printf("0011000A91");
+         GSM.printf("0011000A91");
+             for (i=0 ;i<=9;i++)  
+                    {
+                    pc.printf("%c",Tel[i]);
+                    GSM.printf("%c",Tel[i]);
+                    }  
+        pc.printf("10000AA");
+        GSM.printf("0000AA");
+         pc.printf("31");
+        GSM.printf("31");
+                 
+           for (ioct=0;ioct<=((LENOUToct*7)/8);ioct++)
+         {
+           pc.printf("%02X",DSoct[ioct]);
+           GSM.printf("%02X",DSoct[ioct]);
+         }
+         wait(0.5);
+         GSM.putc((char)0x1A);
+          GSM.scanf("%s",buf);
+            GSM.scanf("%s",buf);
+            GSM.scanf("%s",buf);
+            //GSM.scanf("%s",buf);
+            pc.printf(">%s\n",buf);
+          pc.printf("\n");
+          
+           }  // if 
+            
+            
+    
+        }
+
+        if(DS[0]-79==0 && DS[1]-102==0)     // Off en octetos es 4F6666
+        {
+               LedAzul=1; //apaga con Lgeverde
+               LedVerde = 0;
+               LedRojo=1;
+        }   
+        
+        if(DS[0]-71==0 && DS[1]-110==0)  // On en octetos es 476E
+        {
+               LedAzul=1;  //apaga con Lgeverde
+               LedRojo =0;
+               LedVerde = 1;
+        } 
+     }           
+}
+}
diff -r 000000000000 -r b2a6aa7c0c8c mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jun 19 17:45:34 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7
\ No newline at end of file