Programa para pasar de Octetos a septetos en tramas PDU usadas en mensajes de texto SMS que viajan por la red GSM

Dependencies:   mbed

Committer:
tony63
Date:
Fri Apr 28 04:08:36 2017 +0000
Revision:
1:a1fe02210bb6
Parent:
0:e74448c0b740
funcion completa y aislada

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tony63 0:e74448c0b740 1 #include "mbed.h"
tony63 0:e74448c0b740 2 Serial pc(USBTX, USBRX); // tx, rx
tony63 0:e74448c0b740 3 /*
tony63 0:e74448c0b740 4 ALGORITMO PARA PASAR DE OCTETOS A SEPTETOS
tony63 0:e74448c0b740 5 EN UN MENSAJE DE TEXTO DE CELULAR EN FORMATO PDU
tony63 0:e74448c0b740 6 SE APLICA AL RECIBIR UN MENSAJE QUE TRAE OCTETOS
tony63 0:e74448c0b740 7 SON VISIBLES EN ASCCI AL SER SEPTETOS
tony63 0:e74448c0b740 8 USA DOS CADENAS; UNA DE ENTRADA Y OTRA DE SALIDA
tony63 0:e74448c0b740 9 LENIN ES LA LONGITUD DE LA CADENA DE ENTRADA
tony63 0:e74448c0b740 10 LENOUT LA LONGITUD DE LA DE SALIDA
tony63 0:e74448c0b740 11 VERIFIQUE CON EL DECODIFICADOR DE ESTA PAGINA::
tony63 0:e74448c0b740 12 http://www.twit88.com/home/utility/sms-pdu-encode-decode
tony63 0:e74448c0b740 13 en septetos use esta....http://www.asciitohex.com/
tony63 1:a1fe02210bb6 14 LA ULTIMA VERSION ES PARA CUALQUIER NUMERO DE CARACTERES VER:abril 27 2017
tony63 0:e74448c0b740 15 tanto LENIN y LENOUT se deben especificar al ensamblar la trama PDU en el MODEM
tony63 0:e74448c0b740 16 GSM o GPRS
tony63 0:e74448c0b740 17 */
tony63 0:e74448c0b740 18
tony63 1:a1fe02210bb6 19 char gi[50];
tony63 1:a1fe02210bb6 20 char gs[50];
tony63 0:e74448c0b740 21 int i,K,LENOUT,LENIN,C;
tony63 1:a1fe02210bb6 22 // PRUEBA CON LA CADENA "gallina cafe"
tony63 1:a1fe02210bb6 23 // cadena de octetos = E7309B9D768741E3B0B90C
tony63 1:a1fe02210bb6 24 // cadena de septetos o lo que entrega esta funcion = 67 61 6c 6c 69 6e 61 20 63 61 66 65
tony63 1:a1fe02210bb6 25 void OctToSep(char *DE, char *DS);
tony63 0:e74448c0b740 26 int main(){
tony63 1:a1fe02210bb6 27
tony63 1:a1fe02210bb6 28 gi[0]=0xE7;
tony63 1:a1fe02210bb6 29 gi[1]=0x30;
tony63 1:a1fe02210bb6 30 gi[2]=0x9B;
tony63 1:a1fe02210bb6 31 gi[3]=0x9D;
tony63 1:a1fe02210bb6 32 gi[4]=0x76;
tony63 1:a1fe02210bb6 33 gi[5]=0x87;
tony63 1:a1fe02210bb6 34 gi[6]=0x41;
tony63 1:a1fe02210bb6 35 gi[7]=0xE3;
tony63 1:a1fe02210bb6 36 gi[8]=0xB0;
tony63 1:a1fe02210bb6 37 gi[9]=0xB9;
tony63 1:a1fe02210bb6 38 gi[10]=0x0C;
tony63 1:a1fe02210bb6 39 OctToSep(gi,gs);//se llama la funcion
tony63 1:a1fe02210bb6 40 for (i=0;i < LENOUT;i++){ // se imprime el resultado
tony63 1:a1fe02210bb6 41 pc.printf("%2X,%d,%d\r\n",gs[i],i,K);
tony63 1:a1fe02210bb6 42 }
tony63 1:a1fe02210bb6 43
tony63 1:a1fe02210bb6 44 }
tony63 1:a1fe02210bb6 45 //----------------funcion de interes ---------------------------
tony63 1:a1fe02210bb6 46 void OctToSep(char *DE, char *DS){
tony63 1:a1fe02210bb6 47 LENIN=strlen(DE);
tony63 0:e74448c0b740 48 LENOUT= LENIN*8/7;
tony63 0:e74448c0b740 49 K=7;
tony63 0:e74448c0b740 50 C=0;
tony63 0:e74448c0b740 51 DS[0]=DE[0] & 0x7F; // la primera sola
tony63 0:e74448c0b740 52 for (i=1;i < LENOUT;i++){ // inicia el algoritmo
tony63 0:e74448c0b740 53 DS[i]=(DE[i-1-C]>>K | DE[i-C]<<(8-K))& 0x7F; //valido para todos
tony63 0:e74448c0b740 54 if (K==0) {K=8;C++;}
tony63 0:e74448c0b740 55 K--;
tony63 0:e74448c0b740 56 }
tony63 1:a1fe02210bb6 57 return;
tony63 0:e74448c0b740 58 }