TareaGSMcorrecta

Dependencies:   GPS7 mbed

Files at this revision

API Documentation at this revision

Comitter:
sagilar
Date:
Wed Jun 17 16:55:03 2015 +0000
Commit message:
TareaGSM

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 349755ee209f GPS_G.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GPS_G.lib	Wed Jun 17 16:55:03 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/tony63/code/GPS7/#8d7c7165ffe2
diff -r 000000000000 -r 349755ee209f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jun 17 16:55:03 2015 +0000
@@ -0,0 +1,350 @@
+#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 Compcor[6];
+char Compon[6];
+char Compoff[6];
+char DS[255];
+char DScor[255];
+char DSon[255];
+char DSoff[255];
+char DEcor[255];
+char DEon[255];
+char DEoff[255];
+char DS1[255];
+char DS2[255];
+char DS3[255];
+char DS4[255];
+char Comp[3];
+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,LENINcor,LENINon,LENINoff,LENOUTcor,LENOUTon,LENOUToff;
+DigitalOut Rojo(LED1);
+DigitalOut Verde(LED2);
+DigitalOut Azul(LED3);
+
+int main(){
+       pc.printf("OK");
+        
+    Rojo=1;
+    Verde=0;
+    Azul=1;
+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]);
+
+int nume1cor=16*(int)bufn[1]+(int)bufn[2]+96;//+96 para cor        +96+105 para off y on
+int nume2cor=16*(int)bufn[3]+(int)bufn[4]+96;//+96 para cor            +96 para off    +80 para on
+int nume3cor=16*(int)bufn[5]+(int)bufn[6]-55;//-55 para cor            +80 para off
+DEcor[0]=("%x",nume1cor); 
+DEcor[1]=("%x",nume2cor); 
+DEcor[2]=("%x",nume3cor); 
+
+LENINcor=strlen(DEcor);
+pc.printf("LENIN:%d\n",LENINcor);
+ LENOUTcor= LENINcor*8/7;
+         K=7;
+         C=0;
+         DScor[0]=DEcor[0] & 0x7F;  // la primera sola
+         pc.printf("%2X,%d,%d\r\n",DScor[0],i,K);
+         for (i=1;i < LENOUTcor;i++){  // inicia el algoritmo
+         DScor[i]=(DEcor[i-1-C]>>K | DEcor[i-C]<<(8-K))& 0x7F;  //valido para todos
+         pc.printf("%2X,%d,%d\r\n",DScor[i],i,K);
+         if (K==0) {K=8;C++;}
+         K--;
+         }
+         pc.printf("DS:");
+         for (i=0;i < LENOUTcor;i++){
+         pc.printf("%c",DScor[i]);
+         }
+         pc.printf("  ---");
+
+int nume1on=16*(int)bufn[1]+(int)bufn[2]+96+105;//+96 para cor        +96+105 para off y on
+int nume2on=16*(int)bufn[3]+(int)bufn[4]+80;//+96 para cor            +96 para off    +80 para on
+//int nume3on=16*(int)bufn[5]+(int)bufn[6]-55;//-55 para cor            +80 para off
+DEon[0]=("%x",nume1on); 
+DEon[1]=("%x",nume2on); 
+//DEcor[2]=("%x",nume3); 
+
+LENINon=strlen(DEon);
+pc.printf("LENIN:%d\n",LENINon);
+ LENOUTon= LENINon*8/7;
+         K=7;
+         C=0;
+         DSon[0]=DEon[0] & 0x7F;  // la primera sola
+         pc.printf("%2X,%d,%d\r\n",DSon[0],i,K);
+         for (i=1;i < LENOUTon;i++){  // inicia el algoritmo
+         DSon[i]=(DEon[i-1-C]>>K | DEon[i-C]<<(8-K))& 0x7F;  //valido para todos
+         pc.printf("%2X,%d,%d\r\n",DSon[i],i,K);
+         if (K==0) {K=8;C++;}
+         K--;
+         }
+         pc.printf("DS:");
+         for (i=0;i < LENOUTon;i++){
+         pc.printf("%c",DSon[i]);
+         }
+         pc.printf("  ---");
+
+ 
+sprintf(Compon,"%c%c",DSon[0],DSon[1]);
+
+int nume1off=16*(int)bufn[1]+(int)bufn[2]+96+105;//+96 para cor        +96+105 para off y on
+int nume2off=16*(int)bufn[3]+(int)bufn[4]+96;//+96 para cor            +96 para off    +80 para on
+int nume3off=16*(int)bufn[5]+(int)bufn[6]+80;//-55 para cor            +80 para off
+DEoff[0]=("%x",nume1off); 
+DEoff[1]=("%x",nume2off); 
+DEoff[2]=("%x",nume3off);
+
+LENINoff=strlen(DEoff);
+pc.printf("LENIN:%d\n",LENINoff);
+ LENOUToff= LENINoff*8/7;
+         K=7;
+         C=0;
+         DSoff[0]=DEoff[0] & 0x7F;  // la primera sola
+         pc.printf("%2X,%d,%d\r\n",DSoff[0],i,K);
+         for (i=1;i < LENOUToff;i++){  // inicia el algoritmo
+         DSoff[i]=(DEoff[i-1-C]>>K | DEoff[i-C]<<(8-K))& 0x7F;  //valido para todos
+         pc.printf("%2X,%d,%d\r\n",DSoff[i],i,K);
+         if (K==0) {K=8;C++;}
+         K--;
+         }
+         pc.printf("DS:");
+         for (i=0;i < LENOUToff;i++){
+         pc.printf("%c",DSoff[i]);
+         }
+         pc.printf("  ---");
+
+
+char cadenaon[5]="on";
+char cadenaoff[5]="off";
+char cadenacor[5]="cor";
+    pc.printf("\n");
+    
+    
+for (i=1;i<11;i++){
+pc.printf("%c",cel[i]);
+}
+pc.printf("\n");
+
+sprintf(Compoff,"%c%c%c",DSoff[0],DSoff[1],DSoff[2]);
+sprintf(Compcor,"%c%c%c",DScor[0],DScor[1],DScor[2]);
+pc.printf("\n%s\n",Compcor);
+
+  if(strcmp(Compcor,cadenacor)==0){
+fflush(stdin);
+             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);
+//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=%d\r\n",32+LENIN/2);
+  pc.printf("AT+CMGS=%d\r\n",32+LENIN/2);
+
+     wait(0.5);
+  //CEL.scanf("%s",DS1);
+  //pc.printf("%s",DS1);
+  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);
+    char DE1[10]={"ERROR"};
+    //char DE2[10]={"1K"};
+CEL.putc((char)0x1A);
+CEL.scanf("%s",DS2);
+pc.printf("\nEstimado del envio:%s\n",DS2);
+if(strcmp(DS2,DE1)==0){
+  Azul=!Azul;
+  
+    }
+CEL.scanf("%s",DS3);
+pc.printf("\nDS3:%s\n",DS3);
+
+wait(0.2);
+wait(1);
+CEL.printf("AT+CMGD=1\r\n");
+fflush(stdin);
+wait(3);
+    }
+ }
+
+else{
+    if(strcmp(Compon,cadenaon)==0){
+       fflush(stdin);
+        Rojo=!Rojo;
+         wait(1);
+     CEL.printf("AT+CMGD=1\r\n");
+       fflush(stdin);
+       wait(3);
+        
+    }
+
+        else{
+    if(strcmp(Compoff,cadenaoff)==0){
+        fflush(stdin);
+        Verde=!Verde;
+         wait(1);
+         CEL.printf("AT+CMGD=1\r\n");
+         fflush(stdin);
+         wait(3);
+    }
+}
+}
+}
+
+}
diff -r 000000000000 -r 349755ee209f mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jun 17 16:55:03 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/cbbeb26dbd92
\ No newline at end of file