CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PDU encode/decode

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PDU encode/decode
PostPosted: Wed May 14, 2008 1:34 pm     Reply with quote

Hi

I try encode in PDU mode an string for example "hello word" and I search on this forum but I don't find anything which work..

for example there: http://www.ccsinfo.com/forum/viewtopic.php?t=22619&highlight=pdu
I have this file pduconv.c but it not work with the CCS...

same one know as I change this code for CCS mode?

the result to send "hello word" for my phone in PDU mode with:
service center number: +962100000
mobile phone number: 965542750
is this string:

069169120000F01100099169552457F00000AA0AE8329BFD06DDDF7232

the file which I have is:

Code:

#include <string.h>
#include <stdlibm.h>     // Contains malloc() function for CCS
//#include <stdio.h>
#define VERSION 0.1

/* Define Non-Printable Characters as a question mark */
#define NPC7    63
#define NPC8    '?'

// Reduced LU table for save ROM usage

int lookup_ascii8to7[]={           
    NPC7,       /*     0      null [NUL]                              */
    NPC7,       /*     1      start of heading [SOH]                  */
    NPC7,       /*     2      start of text [STX]                     */
    NPC7,       /*     3      end of text [ETX]                       */
    NPC7,       /*     4      end of transmission [EOT]               */
    NPC7,       /*     5      enquiry [ENQ]                           */
    NPC7,       /*     6      acknowledge [ACK]                       */
    NPC7,       /*     7      bell [BEL]                              */
    NPC7,       /*     8      backspace [BS]                          */
    NPC7,       /*     9      horizontal tab [HT]                     */
    10,         /*    10      line feed [LF]                          */
    NPC7,       /*    11      vertical tab [VT]                       */
    10+256,     /*    12      form feed [FF]                          */
    13,         /*    13      carriage return [CR]                    */
    NPC7,       /*    14      shift out [SO]                          */
    NPC7,       /*    15      shift in [SI]                           */
    NPC7,       /*    16      data link escape [DLE]                  */
    NPC7,       /*    17      device control 1 [DC1]                  */
    NPC7,       /*    18      device control 2 [DC2]                  */
    NPC7,       /*    19      device control 3 [DC3]                  */
    NPC7,       /*    20      device control 4 [DC4]                  */
    NPC7,       /*    21      negative acknowledge [NAK]              */
    NPC7,       /*    22      synchronous idle [SYN]                  */
    NPC7,       /*    23      end of trans. block [ETB]               */
    NPC7,       /*    24      cancel [CAN]                            */
    NPC7,       /*    25      end of medium [EM]                      */
    NPC7,       /*    26      substitute [SUB]                        */
    NPC7,       /*    27      escape [ESC]                            */
    NPC7,       /*    28      file separator [FS]                     */
    NPC7,       /*    29      group separator [GS]                    */
    NPC7,       /*    30      record separator [RS]                   */
    NPC7,       /*    31      unit separator [US]                     */
    32,         /*    32      space                                   */
    33,         /*    33    ! exclamation mark                        */
    34,         /*    34    " double quotation mark                   */
    35,         /*    35    # number sign                             */
    2,          /*    36    $ dollar sign                             */
    37,         /*    37    % percent sign                            */
    38,         /*    38    & ampersand                               */
    39,         /*    39    ' apostrophe                              */
    40,         /*    40    ( left parenthesis                        */
    41,         /*    41    ) right parenthesis                       */
    42,         /*    42    * asterisk                                */
    43,         /*    43    + plus sign                               */
    44,         /*    44    , comma                                   */
    45,         /*    45    - hyphen                                  */
    46,         /*    46    . period                                  */
    47,         /*    47    / slash,                                  */
    48,         /*    48    0 digit 0                                 */
    49,         /*    49    1 digit 1                                 */
    50,         /*    50    2 digit 2                                 */
    51,         /*    51    3 digit 3                                 */
    52,         /*    52    4 digit 4                                 */
    53,         /*    53    5 digit 5                                 */
    54,         /*    54    6 digit 6                                 */
    55,         /*    55    7 digit 7                                 */
    56,         /*    56    8 digit 8                                 */
    57,         /*    57    9 digit 9                                 */
    58,         /*    58    : colon                                   */
    59,         /*    59    ; semicolon                               */
    60,         /*    60    < less-than sign                          */
    61,         /*    61    = equal sign                              */
    62,         /*    62    > greater-than sign                       */
    63,         /*    63    ? question mark                           */
    0,          /*    64    @ commercial at sign                      */
    65,         /*    65    A uppercase A                             */
    66,         /*    66    B uppercase B                             */
    67,         /*    67    C uppercase C                             */
    68,         /*    68    D uppercase D                             */
    69,         /*    69    E uppercase E                             */
    70,         /*    70    F uppercase F                             */
    71,         /*    71    G uppercase G                             */
    72,         /*    72    H uppercase H                             */
    73,         /*    73    I uppercase I                             */
    74,         /*    74    J uppercase J                             */
    75,         /*    75    K uppercase K                             */
    76,         /*    76    L uppercase L                             */
    77,         /*    77    M uppercase M                             */
    78,         /*    78    N uppercase N                             */
    79,         /*    79    O uppercase O                             */
    80,         /*    80    P uppercase P                             */
    81,         /*    81    Q uppercase Q                             */
    82,         /*    82    R uppercase R                             */
    83,         /*    83    S uppercase S                             */
    84,         /*    84    T uppercase T                             */
    85,         /*    85    U uppercase U                             */
    86,         /*    86    V uppercase V                             */
    87,         /*    87    W uppercase W                             */
    88,         /*    88    X uppercase X                             */
    89,         /*    89    Y uppercase Y                             */
    90,         /*    90    Z uppercase Z                             */
    60+256,     /*    91    [ left square bracket                     */
    47+256,     /*    92    \ backslash                               */
    62+256,     /*    93    ] right square bracket                    */
    20+256,     /*    94    ^ circumflex accent                       */
    17,         /*    95    _ underscore                              */
    -39,        /*    96    ` back apostrophe                         */
    97,         /*    97    a lowercase a                             */
    98,         /*    98    b lowercase b                             */
    99,         /*    99    c lowercase c                             */
    100,        /*   100    d lowercase d                             */
    101,        /*   101    e lowercase e                             */
    102,        /*   102    f lowercase f                             */
    103,        /*   103    g lowercase g                             */
    104,        /*   104    h lowercase h                             */
    105,        /*   105    i lowercase i                             */
    106,        /*   106    j lowercase j                             */
    107,        /*   107    k lowercase k                             */
    108,        /*   108    l lowercase l                             */
    109,        /*   109    m lowercase m                             */
    110,        /*   110    n lowercase n                             */
    111,        /*   111    o lowercase o                             */
    112,        /*   112    p lowercase p                             */
    113,        /*   113    q lowercase q                             */
    114,        /*   114    r lowercase r                             */
    115,        /*   115    s lowercase s                             */
    116,        /*   116    t lowercase t                             */
    117,        /*   117    u lowercase u                             */
    118,        /*   118    v lowercase v                             */
    119,        /*   119    w lowercase w                             */
    120,        /*   120    x lowercase x                             */
    121,        /*   121    y lowercase y                             */
    122,        /*   122    z lowercase z                             */

};

static int convert_ascii_to_7bit(char *ascii, char *a7bit[]) {
    int r;
    int w;
    r=0;
    w=0;

    /* Allocate sufficient memory for the result string */
    *a7bit=malloc(strlen(ascii)*2+1);

    while (ascii[r]!=0) {
        if ((lookup_ascii8to7[(unsigned char)ascii[r]])<256) {
            *a7bit[w++]=abs(lookup_ascii8to7[(unsigned char)ascii[r++]]);
        } else {
            *a7bit[w++]=27;
            *a7bit[w++]=lookup_ascii8to7[(unsigned char)ascii[r++]]-256;
        }
    }

    /* Realloc the result array to the correct size */
    *a7bit=realloc(*a7bit,w);

    return w;
}




/*
 *  Convert an ISO-8859-1 ASCII string to an array of PDU-coded bytes
 *
 *  *ascii  The ISO-cleartext to convert
 *
 *  **pdu   Pointer to an array where the pdu-bytes will be stored in, this
 *          function allocates the neccesary memory for the array
 *          Use +pdu[] for CCS
 *
 *  Returns the number of bytes stored in the pdu-array
 *
 *  Note:  Don't forget to free() the pdu-array when you're finished with it.
 *
 */

int ascii_to_pdu(char *ascii, unsigned char *pdu[]) {
    int r;
    int w;
    char *ascii7bit;
    int  len7bit;

    /* Start by converting the ISO-string to a 7bit-string */
    len7bit=convert_ascii_to_7bit(ascii,&ascii7bit);
    *pdu=malloc(len7bit);

    /* Now, we can create a PDU string by packing the 7bit-string */
    r=0;
    w=0;
    while (r<len7bit) {
        *pdu[w]=((ascii7bit[r]>>(w%7))&0x7F) | ((ascii7bit[r+1]<<(7-(w%7)))&0xFF);
        if ((w%7)==6) r++;
        r++;
        w++;
    }

    free(ascii7bit);
    return w;
}


as I can make an simple program when I have constant string "hello word" and can see them in PDU mode on terminal?

regards
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Wed May 14, 2008 2:09 pm     Reply with quote

Hi

I make this code but it don't write anything Confused and result correct without number is :
hello word=00110000910000AA0AE8329BFD06DDDF7232

Code:

#include <18F452.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOOSCSEN                 //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No Power Up Timer
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOCPD                    //No EE protection
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads

#use delay(clock=20000000)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)


code:
Code:

#include "teste_PDU.h"
#include "pduconv.c"

#build(reset=0x200)
#build(interrupt=0x208)
#org 0x0000,0x01ff
void bootloader() {
#asm
  nop
#endasm
} // Reserve space for the bootloader


void main()
{

   int i;
   int pdulen;
   unsigned char *pdu;
   char buffer[];

 while(1)
 {
 printf("string PDU: \n\r");
 
   buffer="hello word";
   pdulen=ascii_to_pdu(buffer,&pdu);
   
   
   for (i=0; i<pdulen;i++)
   {
   printf("%02X",pdu[i]);
   }
   free(pdu);
   
   printf("\n\r");
   delay_ms(1000);
 }

}


see this link about PDU code: http://twit88.com/home/utility/sms-pdu-encode-decode


if some one can help me thanks.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group