Hi there.
I will try to make my little contribution in this question
Here is the my function to send SMS in PDU mode to specific port. The function works well, but optimization of the code is welcome
- Your own specific port number you can fill in UDH part with 16-bit hex number mark with comment:
// J2ME port Number: 5000 = 0x1388
- Characters that you can use in your UD Message are: “a…z”, “A…Z”, “.,:;!-/+*”, space, “0…9”. You can use other characters gsm 7-bit alphabet, but they require more several strings in code inside the function.
- Inside this func You have to use global variable SMS_Handle which you receive with adl_smsSubscribe func.
s8 SendRawPDU_SMS ( ascii * Dst_Address,
ascii * Ascii_Text)
{
s8 smsSend_Handle;
ascii telbuf[12];
ascii buf[8];
ascii out[200];
ascii Phone[12];
ascii len[2];
u16 i, j;
ascii UDLBuf[1000];
// DecToBin part variables
float del, d;
double div;
wm_memset(telbuf, '\0', 12);
wm_memset(out, '\0', 200);
wm_memset(Phone, '\0', 12);
wm_memset(len, '\0', 2);
wm_strcat(Phone, Dst_Address);
// SMSC FLAGS: 0x00
// SMSC ADDRESS: NOT SPECIFIED (USED IN SIM)
wm_strcat(out, "00");
// MESSAGE FLAGS: 0x51
// MESSAGE TYPE: SmsSubmit
// REJECT DUPLICATES: NO
// VALIDITY PERIOD: Relative
// STATUS REPORT: NO
// USER DATA HEADER: YES
// REPLY PATH: NO
wm_strcat(out, "51");
// MESSAGE REFERENCE: 0x00
wm_strcat(out, "00");
// DESTINATION ADDRESS TYPE: 0x91
// TYPE OF NUMBER: 0x01 (International)
// NUMBERING PLAN: 0x01 (ISDN/telephone)
// CONVERT IT TO PDU MODE
wm_strcat(out, "0B91");
wm_strncat(telbuf, &Phone[2], 1);
wm_strncat(telbuf, &Phone[1], 1);
wm_strncat(telbuf, &Phone[4], 1);
wm_strncat(telbuf, &Phone[3], 1);
wm_strncat(telbuf, &Phone[6], 1);
wm_strncat(telbuf, &Phone[5], 1);
wm_strncat(telbuf, &Phone[8], 1);
wm_strncat(telbuf, &Phone[7], 1);
wm_strncat(telbuf, &Phone[10], 1);
wm_strncat(telbuf, &Phone[9], 1);
wm_strcat(telbuf, "F");
wm_strncat(telbuf, &Phone[11], 1);
wm_strcat(out, telbuf);
// PROTOCOL ID: 0x00 (SME-to-SME protocol)
wm_strcat(out, "00");
// DATA CODING SCHEME: 0x00
// CODING GROUP: 0x00 (General Coding)
// COMPRESSED: NO
// CLASS SPECIFIED: NO
// ALPHABET: 0x00 (Default alphabet)
// RESERVED: 0x00
wm_strcat(out, "00");
// MESSAGE VALIDITY: 27d
wm_strcat(out, "C1");
// USER DATA LENGTH = UDH-LENGTH + UD-MESSAGE + 1
wm_itohexa(len, (7+wm_strlen(Ascii_Text)+1),2);
wm_strcat(out, len);
// UDH LENGTH: 7
// UDH: 06050413880000
// J2ME port Number: 5000 = 0x1388
wm_strcat(out, "06050413880000");
// USER DATA MESSAGE
wm_memset(UDLBuf, '\0', 1000);
// REPRESENT MESSAGE IN 7-BIT GSM ALPHABET IN UDLBuf
// AFTER THIS WE HAVE TO
for (i = 0; i < wm_strlen(Ascii_Text); ++i)
{
wm_memset(buf,'\0',8);
ascii buf2[8];
wm_memset(buf2, '\0', 8);
if ( wm_isascii(Ascii_Text[i]) ) {
j=0;
d = 2.0;
del = (u32)(Ascii_Text[i]);
while ( d >= 1 )
{
d = abs ((u32)del / 2);
div = del - (d * 2);
del = d;
wm_sprintf( &buf2[j], "%d", (u16)div );
j++;
}
} else {
// SPECIAL SYMBOLS CODE'S IN 7-BIT GSM-CODING DIFFER
// FROM GENERAL ASCII CODES AND WE HAVE TO
// REPRESENT THEM MANUALLY
if ((char)(Ascii_Text[i]) == ' ') {
wm_sprintf( buf2, "0000010");
} else if ((char)(Ascii_Text[i]) == '.') {
wm_sprintf( buf2, "0111010");
} else if ((char)(Ascii_Text[i]) == ';') {
wm_sprintf( buf2, "1101110");
} else if ((char)(Ascii_Text[i]) == '!') {
wm_sprintf( buf2, "1000010");
} else if ((char)(Ascii_Text[i]) == ',') {
wm_sprintf( buf2, "0011010");
} else if ((char)(Ascii_Text[i]) == '-') {
wm_sprintf( buf2, "1011010");
} else if ((char)(Ascii_Text[i]) == '/') {
wm_sprintf( buf2, "1111010");
} else if ((char)(Ascii_Text[i]) == '+') {
wm_sprintf( buf2, "1101010");
} else if ((char)(Ascii_Text[i]) == '*') {
wm_sprintf( buf2, "0101010");
} else if ((char)(Ascii_Text[i]) == ':') {
wm_sprintf( buf2, "0101110");
} else if ((char)(Ascii_Text[i]) == '0') {
wm_sprintf( buf2, "0000110");
} else if ((char)(Ascii_Text[i]) == '1') {
wm_sprintf( buf2, "1000110");
} else if ((char)(Ascii_Text[i]) == '2') {
wm_sprintf( buf2, "0100110");
} else if ((char)(Ascii_Text[i]) == '3') {
wm_sprintf( buf2, "1100110");
} else if ((char)(Ascii_Text[i]) == '4') {
wm_sprintf( buf2, "0010110");
} else if ((char)(Ascii_Text[i]) == '5') {
wm_sprintf( buf2, "1010110");
} else if ((char)(Ascii_Text[i]) == '6') {
wm_sprintf( buf2, "0110110");
} else if ((char)(Ascii_Text[i]) == '7') {
wm_sprintf( buf2, "1110110");
} else if ((char)(Ascii_Text[i]) == '8') {
wm_sprintf( buf2, "0001110");
} else if ((char)(Ascii_Text[i]) == '9') {
wm_sprintf( buf2, "1001110");
}
}
wm_strncat(UDLBuf, buf2, wm_strlen(buf2));
}
// LAST BYTE (MEAN 8-BIT) WE HAVE TO FILL WITH '0'
j = fmod(wm_strlen(UDLBuf),8);
if ( (8-j) != 0 ){
for (i = 1; i <= (8-j) ; ++i) {
wm_strcat(UDLBuf,"0");
}
}
i = j =0;
// AND THEN BACK REPRESENT TO HEX NUMBERS
// FROM 8-BIT BINARY STRUCTURES
for (i = 0; i < wm_strlen(UDLBuf)/8; ++i)
{
u32 m1, m2, sum;
sum =0;
for ( j = 0; j< 8; ++j)
{
m1 = m2 = 0;
m1 = pow( 2, (j) );
if ( (char)UDLBuf[ j + i*8 ] == '1' ) {
m2 = 1;
} else {
m2 = 0;
}
sum = sum + m1* m2;
}
ascii bufc[2];
wm_memset(bufc, '\0', 2);
wm_itohexa(bufc, (sum),2);
wm_strncat(out, bufc, wm_strlen(len));
}
smsSend_Handle = adl_smsSend ( SMS_Handle, NULL, out, ADL_SMS_MODE_PDU);
return smsSend_Handle;
}
- Dst_Address is TP-DA phone number in International format +XXXXXXXXXXX only!
- Ascii_Text can not contain more than 119 characters.
- Function return handle receive from adl_smsSend in PDU format.
I’ll be glad to see your comments and suggestions.