ESTE CORTO PROGRAMA DETECTA SI UNA CADENA ENTRANTE EN UNA NEGOCIACION GPRS LA RESPUESTA DEL COMANDO AT+CIFSR DEVUELVE UNA DIRECCION IP VALIDA EL PROGRAMA CUENTA LOS PUNTOS SI SON IGUALES A 3 LA IP ES VALIDA Y LA RESPUESTA DEL MODEN FUE CONFIABLE Y ADECUADA NO SE VERIFICO SI LOS NUMEROS SEPARADOS POR PUNTOS SON MENORES O IGUALES A 255 EL PROGRAMA SE PRUEBA ATRAVES DEL PUERTO SERIE DE LA FRDMKL25Z Y SE ENVIA DESDE UNA TERMINAL SERIE (TERMITE UNA DIR IP, EJEMPLO 255.12.3.100)
main.cpp@0:90b0b75a5d08, 2019-04-02 (annotated)
- Committer:
- tony63
- Date:
- Tue Apr 02 06:15:30 2019 +0000
- Revision:
- 0:90b0b75a5d08
ESTE CORTO PROGRAMA DETECTA SI UNA CADENA ENTRANTE EN UNA NEGOCIACION GPRS; LA RESPUESTA DEL COMANDO AT+CIFSR DEVUELVE UNA DIRECCION IP VALIDA; EL PROGRAMA CUENTA LOS PUNTOS SI SON IGUALES A 3 LA IP ES VALIDA; Y LA RESPUESTA DEL MODEN FUE CONFIABLE Y A
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tony63 | 0:90b0b75a5d08 | 1 | /* |
tony63 | 0:90b0b75a5d08 | 2 | ESTE CORTO PROGRAMA DETECTA SI UNA CADENA ENTRANTE EN UNA NEGOCIACION GPRS |
tony63 | 0:90b0b75a5d08 | 3 | LA RESPUESTA DEL COMANDO AT+CIFSR DEVUELVE UNA DIRECCION IP VALIDA |
tony63 | 0:90b0b75a5d08 | 4 | EL PROGRAMA CUENTA LOS PUNTOS SI SON IGUALES A 3 LA IP ES VALIDA |
tony63 | 0:90b0b75a5d08 | 5 | Y LA RESPUESTA DEL MODEN FUE CONFIABLE Y ADECUADA |
tony63 | 0:90b0b75a5d08 | 6 | NO SE VERIFICO SI LOS NUMEROS SEPARADOS POR PUNTOS SON MENORES O IGUALES A 255 |
tony63 | 0:90b0b75a5d08 | 7 | |
tony63 | 0:90b0b75a5d08 | 8 | EL PROGRAMA SE PRUEBA ATRAVES DEL PUERTO SERIE DE LA FRDMKL25Z |
tony63 | 0:90b0b75a5d08 | 9 | Y SE ENVIA DESDE UNA TERMINAL SERIE (TERMITE UNA DIR IP, EJEMPLO 255.12.3.100) |
tony63 | 0:90b0b75a5d08 | 10 | */ |
tony63 | 0:90b0b75a5d08 | 11 | #include "mbed.h" |
tony63 | 0:90b0b75a5d08 | 12 | #include "stdio.h" |
tony63 | 0:90b0b75a5d08 | 13 | #include "string.h" |
tony63 | 0:90b0b75a5d08 | 14 | |
tony63 | 0:90b0b75a5d08 | 15 | int i,ret; |
tony63 | 0:90b0b75a5d08 | 16 | Timer t; |
tony63 | 0:90b0b75a5d08 | 17 | char gprsBuffer[20]; |
tony63 | 0:90b0b75a5d08 | 18 | char buffer[20]; |
tony63 | 0:90b0b75a5d08 | 19 | char resp[20]; |
tony63 | 0:90b0b75a5d08 | 20 | int result; |
tony63 | 0:90b0b75a5d08 | 21 | int z=0; |
tony63 | 0:90b0b75a5d08 | 22 | |
tony63 | 0:90b0b75a5d08 | 23 | Serial pc(USBTX,USBRX);//Configura puerto USB a la consola serial del PC conectado. |
tony63 | 0:90b0b75a5d08 | 24 | //----------------------------------------------------------------------------------------------------------------------------- |
tony63 | 0:90b0b75a5d08 | 25 | // Esta funcion de abajo lee todo un bufer hasta encontrar CR o LF y el resto lo rellena de |
tony63 | 0:90b0b75a5d08 | 26 | // $, count es lo que va a leer. Lo leido lo mete en buffer que es una cadena previamente definida |
tony63 | 0:90b0b75a5d08 | 27 | // incorpora medida de tiempo si se demora mas de tres segundos retorna fracaso con -1 |
tony63 | 0:90b0b75a5d08 | 28 | int readBuffer(char *buffer,int count){ |
tony63 | 0:90b0b75a5d08 | 29 | int i=0; |
tony63 | 0:90b0b75a5d08 | 30 | t.start(); // start timer |
tony63 | 0:90b0b75a5d08 | 31 | while(1) { |
tony63 | 0:90b0b75a5d08 | 32 | while (pc.readable()) { |
tony63 | 0:90b0b75a5d08 | 33 | char c = pc.getc(); |
tony63 | 0:90b0b75a5d08 | 34 | if (c == '\r' || c == '\n') c = '$'; |
tony63 | 0:90b0b75a5d08 | 35 | buffer[i++] = c; |
tony63 | 0:90b0b75a5d08 | 36 | if(i > count)break; |
tony63 | 0:90b0b75a5d08 | 37 | } |
tony63 | 0:90b0b75a5d08 | 38 | if(i > count)break; |
tony63 | 0:90b0b75a5d08 | 39 | if(t.read() > 3) { |
tony63 | 0:90b0b75a5d08 | 40 | t.stop(); |
tony63 | 0:90b0b75a5d08 | 41 | t.reset(); |
tony63 | 0:90b0b75a5d08 | 42 | break; |
tony63 | 0:90b0b75a5d08 | 43 | } |
tony63 | 0:90b0b75a5d08 | 44 | } |
tony63 | 0:90b0b75a5d08 | 45 | wait(0.5); |
tony63 | 0:90b0b75a5d08 | 46 | while(pc.readable()){ // display the other thing.. |
tony63 | 0:90b0b75a5d08 | 47 | char c = pc.getc(); |
tony63 | 0:90b0b75a5d08 | 48 | } |
tony63 | 0:90b0b75a5d08 | 49 | return 0; |
tony63 | 0:90b0b75a5d08 | 50 | } |
tony63 | 0:90b0b75a5d08 | 51 | //-------------------------------------------------------------------------------------------------------------- |
tony63 | 0:90b0b75a5d08 | 52 | // Esta función de abajo limpia o borra todo un "buffer" de tamaño "count", |
tony63 | 0:90b0b75a5d08 | 53 | // lo revisa elemento por elemento y le mete el caracter null que indica fin de cadena. |
tony63 | 0:90b0b75a5d08 | 54 | // No retorna nada. |
tony63 | 0:90b0b75a5d08 | 55 | void cleanBuffer(char *buffer, int count){ |
tony63 | 0:90b0b75a5d08 | 56 | for(int i=0; i < count; i++) { |
tony63 | 0:90b0b75a5d08 | 57 | buffer[i] = '\0'; |
tony63 | 0:90b0b75a5d08 | 58 | } |
tony63 | 0:90b0b75a5d08 | 59 | } |
tony63 | 0:90b0b75a5d08 | 60 | //-------------------------------------------------------------------------------------------------------------- |
tony63 | 0:90b0b75a5d08 | 61 | |
tony63 | 0:90b0b75a5d08 | 62 | |
tony63 | 0:90b0b75a5d08 | 63 | int main() { |
tony63 | 0:90b0b75a5d08 | 64 | while(1){ |
tony63 | 0:90b0b75a5d08 | 65 | if (pc.readable()) { |
tony63 | 0:90b0b75a5d08 | 66 | readBuffer(buffer,15); |
tony63 | 0:90b0b75a5d08 | 67 | pc.printf("%s=\r\n",buffer); |
tony63 | 0:90b0b75a5d08 | 68 | for(i=0;i<15;i++) |
tony63 | 0:90b0b75a5d08 | 69 | { |
tony63 | 0:90b0b75a5d08 | 70 | resp[i]=buffer[i]; |
tony63 | 0:90b0b75a5d08 | 71 | } |
tony63 | 0:90b0b75a5d08 | 72 | pc.printf("respuesta=%s\r\n",resp); |
tony63 | 0:90b0b75a5d08 | 73 | //if(strcmp("255.255.255.255",resp) == 0){ |
tony63 | 0:90b0b75a5d08 | 74 | |
tony63 | 0:90b0b75a5d08 | 75 | cleanBuffer(buffer,20); |
tony63 | 0:90b0b75a5d08 | 76 | for(i=0;i<15;i++){ |
tony63 | 0:90b0b75a5d08 | 77 | if(resp[i]== '.'){ |
tony63 | 0:90b0b75a5d08 | 78 | z++; |
tony63 | 0:90b0b75a5d08 | 79 | } |
tony63 | 0:90b0b75a5d08 | 80 | } |
tony63 | 0:90b0b75a5d08 | 81 | if(z==3){ |
tony63 | 0:90b0b75a5d08 | 82 | pc.printf("llego ip=%d\r\n",z); |
tony63 | 0:90b0b75a5d08 | 83 | } |
tony63 | 0:90b0b75a5d08 | 84 | wait(10); |
tony63 | 0:90b0b75a5d08 | 85 | z=0; |
tony63 | 0:90b0b75a5d08 | 86 | |
tony63 | 0:90b0b75a5d08 | 87 | /* //leer telefono |
tony63 | 0:90b0b75a5d08 | 88 | for(i=0;i<10;i++){ |
tony63 | 0:90b0b75a5d08 | 89 | tel[i]=resp[i+40]; |
tony63 | 0:90b0b75a5d08 | 90 | } |
tony63 | 0:90b0b75a5d08 | 91 | pc.printf("%s-\r\n",tel); |
tony63 | 0:90b0b75a5d08 | 92 | //leer tamaño |
tony63 | 0:90b0b75a5d08 | 93 | for(i=0;i<2;i++){ |
tony63 | 0:90b0b75a5d08 | 94 | tam[i]=resp[i+68]; |
tony63 | 0:90b0b75a5d08 | 95 | } |
tony63 | 0:90b0b75a5d08 | 96 | pc.printf("%s-\r\n",tam); |
tony63 | 0:90b0b75a5d08 | 97 | //leer mensaje |
tony63 | 0:90b0b75a5d08 | 98 | for(i=0;i<14;i++){ |
tony63 | 0:90b0b75a5d08 | 99 | msg[i]=resp[i+70]; |
tony63 | 0:90b0b75a5d08 | 100 | } |
tony63 | 0:90b0b75a5d08 | 101 | pc.printf("%s-\r\n",msg); |
tony63 | 0:90b0b75a5d08 | 102 | |
tony63 | 0:90b0b75a5d08 | 103 | cleanBuffer(gprsBuffer,25); |
tony63 | 0:90b0b75a5d08 | 104 | readBuffer(gprsBuffer,25); |
tony63 | 0:90b0b75a5d08 | 105 | result = gprsBuffer.split(".") |
tony63 | 0:90b0b75a5d08 | 106 | if(result==3){ |
tony63 | 0:90b0b75a5d08 | 107 | */ |
tony63 | 0:90b0b75a5d08 | 108 | |
tony63 | 0:90b0b75a5d08 | 109 | } |
tony63 | 0:90b0b75a5d08 | 110 | } |
tony63 | 0:90b0b75a5d08 | 111 | } |