Programa donde se interactúa con un celular como Modem para la telecomunicación con el microcontrolador KL25Z

Dependencies:   GPS7 mbed

Files at this revision

API Documentation at this revision

Comitter:
sagilar
Date:
Thu May 28 01:43:30 2015 +0000
Commit message:
Programa donde se interact?a con un celular como Modem para el microcontrolador KL25Z

Changed in this revision

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 08bd67a21cc4 GPS_G.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GPS_G.lib	Thu May 28 01:43:30 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/tony63/code/GPS7/#8d7c7165ffe2
diff -r 000000000000 -r 08bd67a21cc4 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu May 28 01:43:30 2015 +0000
@@ -0,0 +1,225 @@
+#include "mbed.h"
+#include "GPS.h"
+#include<stdio.h>
+#include<string.h>
+#include<math.h>
+Serial pc(USBTX,USBRX); 
+GPS gps(PTE0,PTE1);
+Serial CEL(PTE22,PTE23); //Puertos de FRDM para el celular o modem
+char buf[100], bufn[18], celr[18], cel[18];
+char DS[255];
+char DE[255];
+char DS1[255];
+char DE1[255];
+char DENOUT[255];
+char DENIN[255];
+float longitud,lat;
+char hex[101];
+int i,K,C,LENIN,LENOUT,LENIN1,LENOUT1,LENIN2,LENOUT2,LENIN3,LENOUT3,den;
+DigitalOut Rojo(LED1);
+DigitalOut Verde(LED2);
+
+
+int main(){
+       pc.printf("OK"); 
+    Rojo=1;
+    Verde=0;
+while(1){
+     CEL.baud(9600);
+CEL.format(8,Serial::None,1);
+    CEL.printf("AT\r\n");
+       
+       wait(0.5);
+       CEL.printf("AT+CNMI=1,1\r\n");
+       wait(0.5);
+       CEL.printf("AT+CMGF=0\r\n");
+       wait(0.5);
+       CEL.printf("ATE\r\n");
+       wait(0.5);
+       CEL.printf("CBST=0,0,1\r\n");
+       wait(0.5);  
+
+     
+
+
+
+
+
+
+CEL.printf("AT\r\n");
+CEL.scanf("%s",buf);
+pc.printf("Modem %s\n",buf);
+CEL.printf("AT+CMGR=1  \r\n");
+CEL.scanf("%s",buf);
+CEL.scanf("%s",buf);
+CEL.scanf("%s",buf);
+CEL.scanf("%s",buf);
+pc.printf(">%s",buf);
+
+for(i=0;i<100;i++){
+    if((i>=22)&&(i<32)){
+     celr[i-21]=buf[i];
+     }    
+    if((i>=52)&&(i<58)){
+     bufn[i-51]=buf[i];
+     }
+ }
+  
+     for (i=1;i<12;i++){
+         if (i%2!=0){
+         cel[i]=celr[i+1];
+         }
+          if (i%2==0){
+         cel[i]=celr[i-1];
+         }
+      }
+pc.printf(">%c%c%c%c%c%c",bufn[1],bufn[2],bufn[3],bufn[4],bufn[5],bufn[6]);
+
+  if((bufn[1]-69==0)&&(bufn[2]-51==0)&&(bufn[3]-66==0)&&(bufn[4]-55==0)&&(bufn[5]-49==0)&&(bufn[6]-67==0)){
+
+             pc.printf("Si cogio COR\n");
+             if(gps.sample()) {
+                 pc.printf("Si cogio GPS\n");
+       //    float d = GPS.getc();
+           // pc.printf("longitud_entera=%d, Latitud entera=%d\n", (int)gps.longitude, (int)gps.latitude);
+            //pc.printf("Longitud Fraccionaria=%d\n", (int)abs(1000000*frac_long)); 
+           // pc.printf("Latitud fraccionaria=%d\n", (int)abs(1000000*frac_lat)); 
+       //lcd.printf("%01.6f", gps.longitude, gps.latitude);
+          //  pc.printf("%d\n", gps.longitude, gps.latitude);
+        longitud=gps.longitude;
+        lat=gps.latitude;
+        
+
+       //Código para convertir de float a char
+   // float n=lat;
+       char vector2[20];
+    char vector1[20];
+    sprintf(vector1,"%f",lat);
+    sprintf(vector2,"%f",longitud);
+   // ftoa(n, vector1, 6);
+  //  n=longitud;
+ //      char cToStr3[2];
+ 
+  //  if (n<0){
+ //n=n*(-1);
+  //n=n-50.431859;
+   // ftoa(n,vector2,6);
+//cToStr3[1] = '\0';
+//char currentChar = '-';
+//cToStr3[0] = currentChar;
+//strcat (cToStr3,vector2);
+//}
+
+     pc.printf("Lat:%s %f\n",vector1,lat);
+          pc.printf("Lon:%s   %f\n",vector2,longitud);
+    
+    //termina el código de convertir de float a char
+      
+
+         
+      char DEN[100]={"http://maps.google.com/maps?q="};//&vector1[]","&vector2[];//se concatenan los vectores a la cadena que se va a enviar
+    strcat(DEN,vector1);
+   char cToStr[2];
+cToStr[1] = '\0';
+
+char currentChar = ',';
+//cToStr will assume the string "B":
+cToStr[0] = currentChar;
+//And strcat will work!
+
+strcat (DEN,cToStr );
+strcat(DEN,vector2);
+        
+pc.printf("%s \n",DEN);
+for (i=1;i<7;i++){
+pc.printf("%c",bufn[i]);
+}
+pc.printf("\n");
+for (i=1;i<11;i++){
+pc.printf("%c",cel[i]);
+}
+pc.printf("\n");
+
+
+         
+    LENIN3=strlen(DEN);
+  pc.printf("\n DENIN: ");
+   for (i=0;i<(LENIN3);i=i+1){
+
+         DENIN[i]=DEN[i];
+           pc.printf("%x",DENIN[i]);
+  
+         }
+       pc.printf("\n");
+ pc.printf("\n %i \n",LENIN3);
+         //Y CONTINUA HASTA EL ÚLTIMO DATO
+//----------------------------------- ---------------------------
+
+int LENIN=LENIN3; 
+         K=0;C=0;
+         for (i=0;i < LENIN;i++){
+         DS[i]=DEN[i+C]>>K | DEN[i+C+1]<<(7-K);
+         if (DS[i]==0x00) {LENOUT=i; goto salir;}
+         K++;
+         if (K==7) {K=0;C++;} // se chequea que ya se acabaron los bits en un ciclo de conversion.
+         }
+
+         //--------------------------------------------------------------
+salir:        
+          for (i=0;i < LENIN;i++){
+         pc.printf("%X",DEN[i]);
+         }
+         pc.printf(":\r");
+         for (i=0;i<LENOUT;i++){
+         pc.printf("%2X,%d",DS[i]&0x000000FF,i);
+         }
+            pc.printf("\n");
+         
+         
+         wait(0.5);
+         pc.printf("0011000A91%c%c%c%c%c%c%c%c%c%c0000AA%2X",celr[1],celr[2],celr[3],celr[4],celr[5],celr[6],celr[7],celr[8],celr[9],celr[10],LENIN);
+ CEL.printf("AT+CMGS=56\r\n");
+ 
+     wait(0.5);
+  
+  CEL.printf("0011000A91%c%c%c%c%c%c%c%c%c%c0000AA%2X",celr[1],celr[2],celr[3],celr[4],celr[5],celr[6],celr[7],celr[8],celr[9],celr[10],LENIN);
+  wait(0.5);
+   for (i=0;i < LENOUT;i++){
+    CEL.printf("%02x",DS[i]); 
+    pc.printf("%02x",DS[i]); 
+    }
+    wait(0.5);
+CEL.putc((char)0x1A);
+ wait(1);
+CEL.printf("AT+CMGD=1\r\n");
+wait(30);
+
+}
+
+}
+else{
+    if((bufn[1]-54==0)&&(bufn[2]-70==0)&&(bufn[3]-51==0)&&(bufn[4]-55==0)){
+        Rojo=!Rojo;
+         wait(1);
+      CEL.printf("AT+CMGD=1\r\n");
+       wait(60);
+        
+    }
+
+        else{
+    if((bufn[1]-54==0)&&(bufn[2]-70==0)&&(bufn[3]-66==0)&&(bufn[4]-51==0)&&(bufn[5]-49==0)&&(bufn[6]-57==0)){
+        
+        Verde=!Verde;
+         wait(1);
+         CEL.printf("AT+CMGD=1\r\n");
+         wait(60);
+    }
+}
+
+}
+
+
+
+}
+
+}
\ No newline at end of file
diff -r 000000000000 -r 08bd67a21cc4 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu May 28 01:43:30 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8ab26030e058
\ No newline at end of file