programa para pasar de septetos a octetos en tramas PDU
Fork of pdu1 by
main.cpp@2:00bc5b7669c6, 2017-11-06 (annotated)
- Committer:
- tony63
- Date:
- Mon Nov 06 03:01:50 2017 +0000
- Revision:
- 2:00bc5b7669c6
- Parent:
- 1:b0989e540fff
rutina mejorada resuelve el problema de bits menores a 10F
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tony63 | 0:0d2c03fdec12 | 1 | #include "mbed.h" |
tony63 | 0:0d2c03fdec12 | 2 | Serial pc(USBTX, USBRX); // tx, rx |
tony63 | 0:0d2c03fdec12 | 3 | /* |
tony63 | 0:0d2c03fdec12 | 4 | ALGORITMO PARA PASAR DE SEPTETOS A OCTETOS |
tony63 | 0:0d2c03fdec12 | 5 | EN UNA MENSAJE DE TEXTO DE CELULAR EN FORMATO PDU |
tony63 | 0:0d2c03fdec12 | 6 | USA DOS CADENAS UNA DE ENTRADA Y OTRA DE SALIDA |
tony63 | 0:0d2c03fdec12 | 7 | LENIN ES LA LONGITUD DE ENTRADA |
tony63 | 0:0d2c03fdec12 | 8 | LENOUT LA LONGITUD DE SALIDA |
tony63 | 0:0d2c03fdec12 | 9 | SE USA PARA ENSAMBLAR UNA TRAMA PDU |
tony63 | 0:0d2c03fdec12 | 10 | ESTA CADENA DE SALIDA SE ENVIA SOBRE LA TRAMA PDU COMPLETA |
tony63 | 0:0d2c03fdec12 | 11 | VERIFIQUE CON EL DECODIFICADOR DE ESTA PAGINA:: |
tony63 | 1:b0989e540fff | 12 | PROBADA PARA CUALQUIER LONGITUD VER:abril 27 DEL 2017 |
tony63 | 0:0d2c03fdec12 | 13 | http://www.twit88.com/home/utility/sms-pdu-encode-decode |
tony63 | 0:0d2c03fdec12 | 14 | */ |
tony63 | 1:b0989e540fff | 15 | char gi[50]; |
tony63 | 1:b0989e540fff | 16 | char gs[50]; |
tony63 | 0:0d2c03fdec12 | 17 | int i,K,C,LENOUT,LENIN; |
tony63 | 1:b0989e540fff | 18 | void SepToOct(char *DE, char *DS);//se declara la funcion |
tony63 | 0:0d2c03fdec12 | 19 | int main(){ |
tony63 | 0:0d2c03fdec12 | 20 | ; //numero de caracteres de abajo |
tony63 | 1:b0989e540fff | 21 | pc.printf("prueba con gallina cafe\n"); |
tony63 | 2:00bc5b7669c6 | 22 | char gi[]="gallina cafe es una cochina"; |
tony63 | 2:00bc5b7669c6 | 23 | //en septetos es 67 61 6c 6c 69 6e 61 20 63 61 66 65 20 65 73 20 75 6e 61 20 63 6f 63 68 69 6e 61 |
tony63 | 2:00bc5b7669c6 | 24 | //en octetos es E7-30-9B-9D-76-87-41-E3-B0-B9-0C-2A-CF-41-75-77-18-34-7E-8F-D1-69-77-18 |
tony63 | 1:b0989e540fff | 25 | SepToOct(gi,gs); |
tony63 | 1:b0989e540fff | 26 | for (i=0;i<LENOUT;i++){//imprime resultados |
tony63 | 1:b0989e540fff | 27 | pc.printf("%2X",gs[i]&0x000000FF); |
tony63 | 1:b0989e540fff | 28 | } |
tony63 | 1:b0989e540fff | 29 | pc.printf("\n"); |
tony63 | 1:b0989e540fff | 30 | for (i=0;i<LENOUT;i++){ |
tony63 | 2:00bc5b7669c6 | 31 | if(gs[i]<0x10){ |
tony63 | 2:00bc5b7669c6 | 32 | pc.printf("-%X%X",0,gs[i]); |
tony63 | 2:00bc5b7669c6 | 33 | goto up1; |
tony63 | 2:00bc5b7669c6 | 34 | } |
tony63 | 1:b0989e540fff | 35 | pc.printf("-%2X",gs[i]); |
tony63 | 2:00bc5b7669c6 | 36 | up1: |
tony63 | 1:b0989e540fff | 37 | } |
tony63 | 1:b0989e540fff | 38 | pc.printf("\n"); |
tony63 | 1:b0989e540fff | 39 | pc.printf("LENOUT:%2X,LENIN:%2X\r\n",LENOUT,strlen(gi));// longitudes en hex |
tony63 | 1:b0989e540fff | 40 | } |
tony63 | 1:b0989e540fff | 41 | //------------------funcion de interes-- --------------------------- |
tony63 | 1:b0989e540fff | 42 | void SepToOct(char *DE, char *DS){ |
tony63 | 1:b0989e540fff | 43 | LENIN=strlen(DE); //se mide el tamaño de la cadena de entrada |
tony63 | 1:b0989e540fff | 44 | int K=0;int C=0; int i=0; |
tony63 | 0:0d2c03fdec12 | 45 | for (i=0;i < LENIN;i++){ |
tony63 | 0:0d2c03fdec12 | 46 | DS[i]=DE[i+C]>>K | DE[i+C+1]<<(7-K); |
tony63 | 1:b0989e540fff | 47 | if (DS[i]==0x00) {LENOUT=i; goto salir99;}// fin de la transformacion |
tony63 | 0:0d2c03fdec12 | 48 | K++; |
tony63 | 0:0d2c03fdec12 | 49 | if (K==7) {K=0;C++;} // se chequea que ya se acabaron los bits en un ciclo de conversion. |
tony63 | 1:b0989e540fff | 50 | } |
tony63 | 1:b0989e540fff | 51 | salir99: for (i=0;i<LENOUT;i++){ |
tony63 | 1:b0989e540fff | 52 | DS[i]=DS[i]&0x000000FF; |
tony63 | 0:0d2c03fdec12 | 53 | } |
tony63 | 1:b0989e540fff | 54 | return; |
tony63 | 1:b0989e540fff | 55 | } |