gsm
Dependencies: DebouncedIn mbed
Fork of CLASEDELGSM1 by
main.cpp@1:6b506dde0a6e, 2014-12-02 (annotated)
- Committer:
- tony63
- Date:
- Tue Dec 02 03:41:43 2014 +0000
- Revision:
- 1:6b506dde0a6e
- Parent:
- 0:edc50cf04b46
- Child:
- 2:0377af333c98
programa MEJORADO para leer la respuesta del modem, fijese en las lineas 360 a 380.. para sacar el tama?o la respuesta el numero telefonico y el mensaje, usar la misma conexion del programa CLASEDELGSM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tony63 | 0:edc50cf04b46 | 1 | // Programa para enviar desde la FRDMKL25Z un mensaje de texto en formatp PDU |
tony63 | 0:edc50cf04b46 | 2 | // Como modem usa un celular SIEMENS a56i |
tony63 | 0:edc50cf04b46 | 3 | // ENVIAR -----la palabra "ALARMA 1" |
tony63 | 0:edc50cf04b46 | 4 | // |
tony63 | 0:edc50cf04b46 | 5 | |
tony63 | 0:edc50cf04b46 | 6 | // OJO CON ESTO |
tony63 | 0:edc50cf04b46 | 7 | // conector del siemens cable verde es RX conectelo a PTE0 cable blanco es TX conectelo a PTE1 |
tony63 | 0:edc50cf04b46 | 8 | #include "mbed.h" |
tony63 | 0:edc50cf04b46 | 9 | #include "DebouncedIn.h" |
tony63 | 0:edc50cf04b46 | 10 | #include "stdio.h" |
tony63 | 0:edc50cf04b46 | 11 | #include "string.h" |
tony63 | 0:edc50cf04b46 | 12 | Timer t; |
tony63 | 0:edc50cf04b46 | 13 | DigitalOut LedVerde(LED2); |
tony63 | 0:edc50cf04b46 | 14 | DigitalOut LedRojo(LED1); |
tony63 | 0:edc50cf04b46 | 15 | DigitalOut LedAzul(LED3); |
tony63 | 0:edc50cf04b46 | 16 | DebouncedIn button1(PTC12); //señal que inicia el envio del mensaje |
tony63 | 0:edc50cf04b46 | 17 | Serial GSM(PTE0,PTE1); //Configura puerto UART de la FRDMKL25Z |
tony63 | 0:edc50cf04b46 | 18 | Serial pc(USBTX,USBRX);//Configura puerto USB a la consola serial del PC conectado. |
tony63 | 0:edc50cf04b46 | 19 | void Rx_interrupt(); |
tony63 | 0:edc50cf04b46 | 20 | int position=0; |
tony63 | 0:edc50cf04b46 | 21 | int lenpack=6; |
tony63 | 0:edc50cf04b46 | 22 | int longi=0; |
tony63 | 1:6b506dde0a6e | 23 | char tel[11]; |
tony63 | 0:edc50cf04b46 | 24 | char DE[50]; |
tony63 | 1:6b506dde0a6e | 25 | char buffer[100]; |
tony63 | 1:6b506dde0a6e | 26 | char datos[100]; |
tony63 | 0:edc50cf04b46 | 27 | char NUMBER[13]; |
tony63 | 0:edc50cf04b46 | 28 | int index; |
tony63 | 0:edc50cf04b46 | 29 | int count; |
tony63 | 0:edc50cf04b46 | 30 | int i = 0; |
tony63 | 1:6b506dde0a6e | 31 | int j = 0; |
tony63 | 0:edc50cf04b46 | 32 | int c=0; |
tony63 | 0:edc50cf04b46 | 33 | unsigned char CtrlZ = 0x1A; // comodin de emision controlZ |
tony63 | 0:edc50cf04b46 | 34 | bool Flag = false; // bandera |
tony63 | 0:edc50cf04b46 | 35 | char r[]=""; //Cadena de recepcion de la trama PDU si se usa!! |
tony63 | 0:edc50cf04b46 | 36 | char msg[256]; |
tony63 | 0:edc50cf04b46 | 37 | char char1; |
tony63 | 0:edc50cf04b46 | 38 | //Flush serial para el buffer |
tony63 | 0:edc50cf04b46 | 39 | void FlushGSM(void) { |
tony63 | 0:edc50cf04b46 | 40 | char1 = 0; |
tony63 | 0:edc50cf04b46 | 41 | while (GSM.readable()){ |
tony63 | 0:edc50cf04b46 | 42 | char1 = GSM.getc();} |
tony63 | 0:edc50cf04b46 | 43 | return;} |
tony63 | 0:edc50cf04b46 | 44 | |
tony63 | 0:edc50cf04b46 | 45 | void callback() { |
tony63 | 0:edc50cf04b46 | 46 | // Note: you need to actually read from the serial to clear the RX interrupt |
tony63 | 0:edc50cf04b46 | 47 | pc.printf("%c\n", GSM.getc()); |
tony63 | 0:edc50cf04b46 | 48 | |
tony63 | 0:edc50cf04b46 | 49 | } |
tony63 | 0:edc50cf04b46 | 50 | |
tony63 | 0:edc50cf04b46 | 51 | int readBuffer(char *buffer,int count) |
tony63 | 0:edc50cf04b46 | 52 | { |
tony63 | 0:edc50cf04b46 | 53 | int i=0; |
tony63 | 0:edc50cf04b46 | 54 | t.start(); // start timer |
tony63 | 0:edc50cf04b46 | 55 | while(1) { |
tony63 | 0:edc50cf04b46 | 56 | while (GSM.readable()) { |
tony63 | 0:edc50cf04b46 | 57 | char c = GSM.getc(); |
tony63 | 0:edc50cf04b46 | 58 | if (c == '\r' || c == '\n') c = '$'; |
tony63 | 0:edc50cf04b46 | 59 | buffer[i++] = c; |
tony63 | 0:edc50cf04b46 | 60 | if(i > count)break; |
tony63 | 0:edc50cf04b46 | 61 | } |
tony63 | 0:edc50cf04b46 | 62 | if(i > count)break; |
tony63 | 0:edc50cf04b46 | 63 | if(t.read() > 3) { |
tony63 | 0:edc50cf04b46 | 64 | t.stop(); |
tony63 | 0:edc50cf04b46 | 65 | t.reset(); |
tony63 | 0:edc50cf04b46 | 66 | break; |
tony63 | 0:edc50cf04b46 | 67 | } |
tony63 | 0:edc50cf04b46 | 68 | } |
tony63 | 0:edc50cf04b46 | 69 | wait(0.5); |
tony63 | 0:edc50cf04b46 | 70 | while(GSM.readable()) { // display the other thing.. |
tony63 | 0:edc50cf04b46 | 71 | char c = GSM.getc(); |
tony63 | 0:edc50cf04b46 | 72 | } |
tony63 | 0:edc50cf04b46 | 73 | return 0; |
tony63 | 0:edc50cf04b46 | 74 | } |
tony63 | 0:edc50cf04b46 | 75 | |
tony63 | 0:edc50cf04b46 | 76 | /* esta funcion de abajo limpia o borra todo un "buffer" de tamaño "count" |
tony63 | 0:edc50cf04b46 | 77 | lo revisa uno por un elemento y le mete el caracter null que indica fin de cadena |
tony63 | 0:edc50cf04b46 | 78 | no retorna nada |
tony63 | 0:edc50cf04b46 | 79 | */ |
tony63 | 0:edc50cf04b46 | 80 | //*************************************************************************************** |
tony63 | 0:edc50cf04b46 | 81 | void cleanBuffer(char *buffer, int count) |
tony63 | 0:edc50cf04b46 | 82 | { |
tony63 | 0:edc50cf04b46 | 83 | for(int i=0; i < count; i++) { |
tony63 | 0:edc50cf04b46 | 84 | buffer[i] = '\0'; |
tony63 | 0:edc50cf04b46 | 85 | } |
tony63 | 0:edc50cf04b46 | 86 | } |
tony63 | 0:edc50cf04b46 | 87 | /* esta funcion de abajo envia un comando parametrizado como cadena |
tony63 | 0:edc50cf04b46 | 88 | */ |
tony63 | 0:edc50cf04b46 | 89 | //*************************************************************************************** |
tony63 | 0:edc50cf04b46 | 90 | void sendCmd(char *cmd) |
tony63 | 0:edc50cf04b46 | 91 | { |
tony63 | 0:edc50cf04b46 | 92 | GSM.puts(cmd); |
tony63 | 0:edc50cf04b46 | 93 | } |
tony63 | 0:edc50cf04b46 | 94 | /* esta funcion de abajo espera la respuesta de un comando que debe ser identica a la cadena "resp" y un tiempo timeout" |
tony63 | 0:edc50cf04b46 | 95 | si todo sale bien retorna un cero que en la programacion hay que validar |
tony63 | 0:edc50cf04b46 | 96 | si algo sale mal ( no se parece o se demora mucho )retorna -1 que debera validarse con alguna expresion logica |
tony63 | 0:edc50cf04b46 | 97 | */ |
tony63 | 0:edc50cf04b46 | 98 | //*************************************************************************************** |
tony63 | 0:edc50cf04b46 | 99 | int waitForResp(char *resp, int timeout) |
tony63 | 0:edc50cf04b46 | 100 | { |
tony63 | 0:edc50cf04b46 | 101 | int len = strlen(resp); |
tony63 | 0:edc50cf04b46 | 102 | int sum=0; |
tony63 | 0:edc50cf04b46 | 103 | t.start(); |
tony63 | 0:edc50cf04b46 | 104 | |
tony63 | 0:edc50cf04b46 | 105 | while(1) { |
tony63 | 0:edc50cf04b46 | 106 | if(GSM.readable()) { |
tony63 | 0:edc50cf04b46 | 107 | char c = GSM.getc(); |
tony63 | 0:edc50cf04b46 | 108 | sum = (c==resp[sum]) ? sum+1 : 0;// esta linea de C# sum se incrementa o se hace cero segun c |
tony63 | 0:edc50cf04b46 | 109 | if(sum == len)break; //ya acabo se sale |
tony63 | 0:edc50cf04b46 | 110 | } |
tony63 | 0:edc50cf04b46 | 111 | if(t.read() > timeout) { // time out chequea el tiempo minimo antes de salir perdiendo |
tony63 | 0:edc50cf04b46 | 112 | t.stop(); |
tony63 | 0:edc50cf04b46 | 113 | t.reset(); |
tony63 | 0:edc50cf04b46 | 114 | return -1; |
tony63 | 0:edc50cf04b46 | 115 | } |
tony63 | 0:edc50cf04b46 | 116 | } |
tony63 | 0:edc50cf04b46 | 117 | t.stop(); // stop timer antes de retornar |
tony63 | 0:edc50cf04b46 | 118 | t.reset(); // clear timer |
tony63 | 0:edc50cf04b46 | 119 | while(GSM.readable()) { // display the other thing.. |
tony63 | 0:edc50cf04b46 | 120 | char c = GSM.getc(); |
tony63 | 0:edc50cf04b46 | 121 | } |
tony63 | 0:edc50cf04b46 | 122 | |
tony63 | 0:edc50cf04b46 | 123 | return 0; |
tony63 | 0:edc50cf04b46 | 124 | } |
tony63 | 0:edc50cf04b46 | 125 | /* esta funcion de abajo es muy completa e util se encarga de enviar el comando y esperar la respuesta |
tony63 | 0:edc50cf04b46 | 126 | si todo sale bien retorna un cero(herencia de las funciones contenedoras) que en la programacion hay que validar |
tony63 | 0:edc50cf04b46 | 127 | con alguna expresion logica |
tony63 | 0:edc50cf04b46 | 128 | */ |
tony63 | 0:edc50cf04b46 | 129 | //*************************************************************************************** |
tony63 | 0:edc50cf04b46 | 130 | int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout) |
tony63 | 0:edc50cf04b46 | 131 | { |
tony63 | 0:edc50cf04b46 | 132 | sendCmd(cmd); |
tony63 | 0:edc50cf04b46 | 133 | return waitForResp(resp,timeout); |
tony63 | 0:edc50cf04b46 | 134 | } |
tony63 | 0:edc50cf04b46 | 135 | /* esta funcion de abajo chequea que el modem este vivo envia AT y le contesta con OK y espera 2 segundos |
tony63 | 0:edc50cf04b46 | 136 | */ |
tony63 | 0:edc50cf04b46 | 137 | //*************************************************************************************** |
tony63 | 0:edc50cf04b46 | 138 | int powerCheck(void)// este comando se manda para verificar si el modem esta vivo o conectado |
tony63 | 0:edc50cf04b46 | 139 | { |
tony63 | 0:edc50cf04b46 | 140 | return sendCmdAndWaitForResp("AT\r\n", "OK", 2); |
tony63 | 0:edc50cf04b46 | 141 | } |
tony63 | 0:edc50cf04b46 | 142 | /* esta funcion de abajo chequea el estado de la sim card |
tony63 | 0:edc50cf04b46 | 143 | y si todo sale bien retorna un cero que en la programacion hay que validar |
tony63 | 0:edc50cf04b46 | 144 | con alguna expresion logica |
tony63 | 0:edc50cf04b46 | 145 | */ |
tony63 | 0:edc50cf04b46 | 146 | //*************************************************************************************** |
tony63 | 0:edc50cf04b46 | 147 | int checkSIMStatus(void) |
tony63 | 0:edc50cf04b46 | 148 | { |
tony63 | 0:edc50cf04b46 | 149 | char gprsBuffer[30]; |
tony63 | 0:edc50cf04b46 | 150 | int count = 0; |
tony63 | 0:edc50cf04b46 | 151 | cleanBuffer(gprsBuffer,30); |
tony63 | 0:edc50cf04b46 | 152 | while(count < 3) { |
tony63 | 0:edc50cf04b46 | 153 | sendCmd("AT+CPIN?\r\n"); |
tony63 | 0:edc50cf04b46 | 154 | readBuffer(gprsBuffer,30); |
tony63 | 0:edc50cf04b46 | 155 | if((NULL != strstr(gprsBuffer,"+CPIN: READY"))) { |
tony63 | 0:edc50cf04b46 | 156 | break; |
tony63 | 0:edc50cf04b46 | 157 | } |
tony63 | 0:edc50cf04b46 | 158 | count++; |
tony63 | 0:edc50cf04b46 | 159 | wait(1); |
tony63 | 0:edc50cf04b46 | 160 | } |
tony63 | 0:edc50cf04b46 | 161 | |
tony63 | 0:edc50cf04b46 | 162 | if(count == 3) { |
tony63 | 0:edc50cf04b46 | 163 | return -1; |
tony63 | 0:edc50cf04b46 | 164 | } |
tony63 | 0:edc50cf04b46 | 165 | return 0; |
tony63 | 0:edc50cf04b46 | 166 | } |
tony63 | 0:edc50cf04b46 | 167 | /* esta funcion de abajo chequea la calidad de la señal |
tony63 | 0:edc50cf04b46 | 168 | y si todo sale bien retorna cun el valor de señal util o un -1 si nop es aceptable, en la programacion hay que validar |
tony63 | 0:edc50cf04b46 | 169 | con alguna expresion logica |
tony63 | 0:edc50cf04b46 | 170 | */ |
tony63 | 0:edc50cf04b46 | 171 | //*************************************************************************************** |
tony63 | 0:edc50cf04b46 | 172 | int checkSignalStrength(void) |
tony63 | 0:edc50cf04b46 | 173 | { |
tony63 | 0:edc50cf04b46 | 174 | char gprsBuffer[100]; |
tony63 | 0:edc50cf04b46 | 175 | int index,count = 0; |
tony63 | 0:edc50cf04b46 | 176 | cleanBuffer(gprsBuffer,100); |
tony63 | 0:edc50cf04b46 | 177 | while(count < 3) { |
tony63 | 0:edc50cf04b46 | 178 | sendCmd("AT+CSQ\r\n"); |
tony63 | 0:edc50cf04b46 | 179 | readBuffer(gprsBuffer,25); |
tony63 | 0:edc50cf04b46 | 180 | if(sscanf(gprsBuffer, "AT+CSQ$$$$+CSQ: %d", &index)>0) { |
tony63 | 0:edc50cf04b46 | 181 | break; |
tony63 | 0:edc50cf04b46 | 182 | } |
tony63 | 0:edc50cf04b46 | 183 | count++; |
tony63 | 0:edc50cf04b46 | 184 | wait(1); |
tony63 | 0:edc50cf04b46 | 185 | } |
tony63 | 0:edc50cf04b46 | 186 | if(count == 3) { |
tony63 | 0:edc50cf04b46 | 187 | return -1; |
tony63 | 0:edc50cf04b46 | 188 | } |
tony63 | 0:edc50cf04b46 | 189 | return index; |
tony63 | 0:edc50cf04b46 | 190 | } |
tony63 | 0:edc50cf04b46 | 191 | /* esta funcion de abajo configura el modem de forma inicial con comandas AT |
tony63 | 0:edc50cf04b46 | 192 | y si todo sale bien retorna un cero que en la programacion hay que validar |
tony63 | 0:edc50cf04b46 | 193 | con alguna expresion logica pero si algo sale mal retorna un -1 |
tony63 | 0:edc50cf04b46 | 194 | */ |
tony63 | 0:edc50cf04b46 | 195 | //*************************************************************************************** |
tony63 | 0:edc50cf04b46 | 196 | /*int settingSMS() //esta funcion se invoca para configurar el modem al principio |
tony63 | 0:edc50cf04b46 | 197 | { |
tony63 | 0:edc50cf04b46 | 198 | if(0 != sendCmdAndWaitForResp("AT\r\n", "OK", 1)) { |
tony63 | 0:edc50cf04b46 | 199 | return -1; |
tony63 | 0:edc50cf04b46 | 200 | } |
tony63 | 0:edc50cf04b46 | 201 | if(0 != sendCmdAndWaitForResp("AT+CNMI=1,1\r\n", "OK", 1)) { |
tony63 | 0:edc50cf04b46 | 202 | return -1; |
tony63 | 0:edc50cf04b46 | 203 | } |
tony63 | 0:edc50cf04b46 | 204 | if(0 != sendCmdAndWaitForResp("AT+CMGF=0\r\n", "OK", 1)) { |
tony63 | 0:edc50cf04b46 | 205 | return -1; |
tony63 | 0:edc50cf04b46 | 206 | } |
tony63 | 0:edc50cf04b46 | 207 | if(0 != sendCmdAndWaitForResp("ATE\r\n", "OK", 1)) { |
tony63 | 0:edc50cf04b46 | 208 | return -1; |
tony63 | 0:edc50cf04b46 | 209 | } |
tony63 | 0:edc50cf04b46 | 210 | if(0 != sendCmdAndWaitForResp("CBST=0,0,1\r\n", "OK", 1)) { |
tony63 | 0:edc50cf04b46 | 211 | return -1; |
tony63 | 0:edc50cf04b46 | 212 | } |
tony63 | 0:edc50cf04b46 | 213 | return 0; |
tony63 | 0:edc50cf04b46 | 214 | } |
tony63 | 0:edc50cf04b46 | 215 | */ |
tony63 | 0:edc50cf04b46 | 216 | |
tony63 | 0:edc50cf04b46 | 217 | |
tony63 | 0:edc50cf04b46 | 218 | /* esta funcion de abajo inicaliza el modem se compone de un grupo de subfunciones ya definidas previamente |
tony63 | 0:edc50cf04b46 | 219 | primero chequea que este vivo |
tony63 | 0:edc50cf04b46 | 220 | segundo chequea el estado de la simcard |
tony63 | 0:edc50cf04b46 | 221 | tercero chequea la intencidad de señal celular |
tony63 | 0:edc50cf04b46 | 222 | cuarto aplica la configuracion |
tony63 | 0:edc50cf04b46 | 223 | y si todo sale bien retorna un cero que en la programacion hay que validar |
tony63 | 0:edc50cf04b46 | 224 | con alguna expresion logica |
tony63 | 0:edc50cf04b46 | 225 | */ |
tony63 | 0:edc50cf04b46 | 226 | //*************************************************************************************** |
tony63 | 0:edc50cf04b46 | 227 | int init() |
tony63 | 0:edc50cf04b46 | 228 | { |
tony63 | 0:edc50cf04b46 | 229 | for(int i = 0; i < 3; i++){ |
tony63 | 0:edc50cf04b46 | 230 | sendCmdAndWaitForResp("AT\r\n", "OK", 1); |
tony63 | 0:edc50cf04b46 | 231 | wait(0.5); |
tony63 | 0:edc50cf04b46 | 232 | } |
tony63 | 0:edc50cf04b46 | 233 | if(0 != checkSIMStatus()) { |
tony63 | 0:edc50cf04b46 | 234 | return -1; |
tony63 | 0:edc50cf04b46 | 235 | } |
tony63 | 0:edc50cf04b46 | 236 | if(checkSignalStrength()<1) { |
tony63 | 0:edc50cf04b46 | 237 | return -1; |
tony63 | 0:edc50cf04b46 | 238 | } |
tony63 | 0:edc50cf04b46 | 239 | |
tony63 | 0:edc50cf04b46 | 240 | GSM.attach(&Rx_interrupt, Serial::RxIrq); |
tony63 | 0:edc50cf04b46 | 241 | return 0; |
tony63 | 0:edc50cf04b46 | 242 | } |
tony63 | 0:edc50cf04b46 | 243 | /* esta funcion de abajo intenta leer un mensaje de texto en formato PDU o HEX |
tony63 | 0:edc50cf04b46 | 244 | y si todo sale bien retorna un cero que en la programacion hay que validar |
tony63 | 0:edc50cf04b46 | 245 | con alguna expresion logica |
tony63 | 0:edc50cf04b46 | 246 | */ |
tony63 | 0:edc50cf04b46 | 247 | //*************************************************************************************** |
tony63 | 0:edc50cf04b46 | 248 | int readSMSpdu(char *message, int index) |
tony63 | 0:edc50cf04b46 | 249 | { |
tony63 | 0:edc50cf04b46 | 250 | int i = 0; |
tony63 | 0:edc50cf04b46 | 251 | char gprsBuffer[100]; |
tony63 | 0:edc50cf04b46 | 252 | char *p,*s; |
tony63 | 0:edc50cf04b46 | 253 | GSM.printf("AT+CMGR=%d\r\n",index); |
tony63 | 0:edc50cf04b46 | 254 | cleanBuffer(gprsBuffer,100); |
tony63 | 0:edc50cf04b46 | 255 | readBuffer(gprsBuffer,100); |
tony63 | 0:edc50cf04b46 | 256 | if(NULL == ( s = strstr(gprsBuffer,"+CMGR"))) { |
tony63 | 0:edc50cf04b46 | 257 | return -1; |
tony63 | 0:edc50cf04b46 | 258 | } |
tony63 | 0:edc50cf04b46 | 259 | if(NULL != ( s = strstr(gprsBuffer,"+32"))) { |
tony63 | 0:edc50cf04b46 | 260 | p = s + 6; |
tony63 | 0:edc50cf04b46 | 261 | while((*p != '$')&&(i < 5)) { |
tony63 | 0:edc50cf04b46 | 262 | message[i++] = *(p++); |
tony63 | 0:edc50cf04b46 | 263 | } |
tony63 | 0:edc50cf04b46 | 264 | message[i] = '\0'; |
tony63 | 0:edc50cf04b46 | 265 | } |
tony63 | 0:edc50cf04b46 | 266 | return 0; |
tony63 | 0:edc50cf04b46 | 267 | } |
tony63 | 0:edc50cf04b46 | 268 | /* esta funcion de abajo borra mensajes SMS del modem |
tony63 | 0:edc50cf04b46 | 269 | y si todo sale bien retorna un cero que en la programacion hay que validar |
tony63 | 0:edc50cf04b46 | 270 | con alguna expresion logica |
tony63 | 0:edc50cf04b46 | 271 | */ |
tony63 | 0:edc50cf04b46 | 272 | //*************************************************************************************** |
tony63 | 0:edc50cf04b46 | 273 | int deleteSMS(int index) |
tony63 | 0:edc50cf04b46 | 274 | { |
tony63 | 0:edc50cf04b46 | 275 | char cmd[32]; |
tony63 | 0:edc50cf04b46 | 276 | snprintf(cmd,sizeof(cmd),"AT+CMGD=%d\r\n",index); |
tony63 | 0:edc50cf04b46 | 277 | sendCmd(cmd); |
tony63 | 0:edc50cf04b46 | 278 | return 0; |
tony63 | 0:edc50cf04b46 | 279 | } |
tony63 | 0:edc50cf04b46 | 280 | //***0********************************************************************************* |
tony63 | 0:edc50cf04b46 | 281 | |
tony63 | 0:edc50cf04b46 | 282 | // Interupt Routine to read in data from serial port |
tony63 | 0:edc50cf04b46 | 283 | void Rx_interrupt(){ |
tony63 | 0:edc50cf04b46 | 284 | } |
tony63 | 0:edc50cf04b46 | 285 | /* |
tony63 | 0:edc50cf04b46 | 286 | readBuffer(buffer,6); |
tony63 | 0:edc50cf04b46 | 287 | if(strncmp(buffer, "+CMTI", 5)){ |
tony63 | 0:edc50cf04b46 | 288 | wait(1); |
tony63 | 0:edc50cf04b46 | 289 | GSM.printf("AT+CMGL=%d\r\n",0); |
tony63 | 0:edc50cf04b46 | 290 | readBuffer(buffer,100);} |
tony63 | 0:edc50cf04b46 | 291 | if(strncmp(buffer, "+CMGL:", 5)){ |
tony63 | 0:edc50cf04b46 | 292 | for (i=0;i<31;i++){ |
tony63 | 0:edc50cf04b46 | 293 | buffer[5+i]=c; // 32 de basura |
tony63 | 0:edc50cf04b46 | 294 | } |
tony63 | 0:edc50cf04b46 | 295 | } |
tony63 | 0:edc50cf04b46 | 296 | for (i=0;i<10;i++){ |
tony63 | 0:edc50cf04b46 | 297 | buffer[36+i]=tel[i]; // numero telefonico |
tony63 | 0:edc50cf04b46 | 298 | } |
tony63 | 0:edc50cf04b46 | 299 | for (i=0;i<18;i++){ |
tony63 | 0:edc50cf04b46 | 300 | buffer[46+i]=c; // 18 de basura |
tony63 | 0:edc50cf04b46 | 301 | } |
tony63 | 0:edc50cf04b46 | 302 | for (i=0;i<2;i++){ |
tony63 | 0:edc50cf04b46 | 303 | buffer[64+i]=tel[i]; // tamaño de septetos |
tony63 | 0:edc50cf04b46 | 304 | } |
tony63 | 0:edc50cf04b46 | 305 | for (i=0;i<30;i++){ |
tony63 | 0:edc50cf04b46 | 306 | buffer[66+i]=DE[i]; // datos en octetos hex |
tony63 | 0:edc50cf04b46 | 307 | if (buffer[i]=='\0'){ |
tony63 | 0:edc50cf04b46 | 308 | } |
tony63 | 0:edc50cf04b46 | 309 | */ |
tony63 | 0:edc50cf04b46 | 310 | |
tony63 | 0:edc50cf04b46 | 311 | |
tony63 | 0:edc50cf04b46 | 312 | int main(void) |
tony63 | 0:edc50cf04b46 | 313 | { |
tony63 | 0:edc50cf04b46 | 314 | |
tony63 | 0:edc50cf04b46 | 315 | //NVIC_DisableIRQ(UART1_IRQn); |
tony63 | 0:edc50cf04b46 | 316 | //apagamos los 3 leds |
tony63 | 0:edc50cf04b46 | 317 | LedVerde=1; |
tony63 | 0:edc50cf04b46 | 318 | LedRojo=1; |
tony63 | 0:edc50cf04b46 | 319 | LedAzul=1; |
tony63 | 0:edc50cf04b46 | 320 | lenpack=6; //tamaño de "ALARMA" |
tony63 | 0:edc50cf04b46 | 321 | GSM.baud(9600);//configura los baudios de la FRDMKL25Z en 9600 |
tony63 | 0:edc50cf04b46 | 322 | GSM.format(8,Serial::None,1); //configura el formato de los datos de la UART |
tony63 | 0:edc50cf04b46 | 323 | //configuro modem GSM |
tony63 | 0:edc50cf04b46 | 324 | GSM.printf("AT\r\n"); |
tony63 | 0:edc50cf04b46 | 325 | wait(0.5); |
tony63 | 0:edc50cf04b46 | 326 | GSM.printf("AT+CNMI=1,1\r\n"); |
tony63 | 0:edc50cf04b46 | 327 | wait(0.5); |
tony63 | 0:edc50cf04b46 | 328 | GSM.printf("AT+CMGF=0\r\n"); |
tony63 | 0:edc50cf04b46 | 329 | wait(0.5); |
tony63 | 0:edc50cf04b46 | 330 | GSM.printf("ATE\r\n"); |
tony63 | 0:edc50cf04b46 | 331 | wait(0.5); |
tony63 | 0:edc50cf04b46 | 332 | GSM.printf("CBST=0,0,1\r\n"); |
tony63 | 0:edc50cf04b46 | 333 | wait(0.5); |
tony63 | 0:edc50cf04b46 | 334 | LedVerde=0; |
tony63 | 0:edc50cf04b46 | 335 | |
tony63 | 0:edc50cf04b46 | 336 | //if(0!= init()){ //se configura y chequea el modem GSM |
tony63 | 0:edc50cf04b46 | 337 | // LedRojo=0; |
tony63 | 0:edc50cf04b46 | 338 | //} |
tony63 | 0:edc50cf04b46 | 339 | while(1){ |
tony63 | 0:edc50cf04b46 | 340 | if (button1.falling()) |
tony63 | 0:edc50cf04b46 | 341 | { LedVerde=1; |
tony63 | 0:edc50cf04b46 | 342 | wait(2); |
tony63 | 0:edc50cf04b46 | 343 | if (!button1) |
tony63 | 0:edc50cf04b46 | 344 | {LedVerde=0; |
tony63 | 0:edc50cf04b46 | 345 | index=20; |
tony63 | 0:edc50cf04b46 | 346 | //GSM.printf("AT+CNMI=1,1\r\n"); //configuracion inicial del MODEM! |
tony63 | 0:edc50cf04b46 | 347 | GSM.printf("AT+CMGS=%d\r\n",index); |
tony63 | 0:edc50cf04b46 | 348 | wait(0.2); |
tony63 | 0:edc50cf04b46 | 349 | GSM.printf("0011000A9113223717370000AA08416650DA0C8262"); //esto es "ALARMA 1" |
tony63 | 0:edc50cf04b46 | 350 | wait(0.5); |
tony63 | 0:edc50cf04b46 | 351 | GSM.putc((char)0x1A); //esto es controlZ |
tony63 | 0:edc50cf04b46 | 352 | LedVerde=1; |
tony63 | 0:edc50cf04b46 | 353 | LedRojo=0; //lo prendo |
tony63 | 0:edc50cf04b46 | 354 | wait(3); |
tony63 | 0:edc50cf04b46 | 355 | LedRojo=1; //lo apago |
tony63 | 0:edc50cf04b46 | 356 | LedVerde=0; |
tony63 | 0:edc50cf04b46 | 357 | } |
tony63 | 0:edc50cf04b46 | 358 | |
tony63 | 1:6b506dde0a6e | 359 | } |
tony63 | 1:6b506dde0a6e | 360 | if(GSM.readable()) { //USE ESTE FRAGMENTO DE CODIGO PARA LEER LO QUE EL CELULAR RESPONDE |
tony63 | 1:6b506dde0a6e | 361 | while(GSM.readable()) { |
tony63 | 1:6b506dde0a6e | 362 | char c = GSM.getc(); |
tony63 | 1:6b506dde0a6e | 363 | buffer[count++] = c; |
tony63 | 1:6b506dde0a6e | 364 | if(count == 64) break; |
tony63 | 1:6b506dde0a6e | 365 | } |
tony63 | 1:6b506dde0a6e | 366 | pc.puts(buffer); |
tony63 | 1:6b506dde0a6e | 367 | |
tony63 | 1:6b506dde0a6e | 368 | |
tony63 | 1:6b506dde0a6e | 369 | for(int i = 0; i < count; i++) { |
tony63 | 1:6b506dde0a6e | 370 | buffer[i] = NULL; |
tony63 | 1:6b506dde0a6e | 371 | } |
tony63 | 1:6b506dde0a6e | 372 | |
tony63 | 1:6b506dde0a6e | 373 | count = 0; |
tony63 | 1:6b506dde0a6e | 374 | |
tony63 | 1:6b506dde0a6e | 375 | } |
tony63 | 1:6b506dde0a6e | 376 | |
tony63 | 0:edc50cf04b46 | 377 | } |
tony63 | 1:6b506dde0a6e | 378 | } |
tony63 | 1:6b506dde0a6e | 379 | |
tony63 | 1:6b506dde0a6e | 380 | // buffer[i] contiene lo que regresa |