Discussion in "Embedded GSM Development" started by    ramsesrr    Mar 23, 2013.
Sat Mar 23 2013, 12:33 am
#1
Hello all,
I managed to build an sms controller using text mode but now I m trying to build one that uses sms in pdu format (because is harder and harder for me to find phones that use text mode)
I need to decode the message because the configuration of phone to which the messages are send back is configured by sms.
I also need to encode in pdu format because I send messages with data from sensor.
For the moment I haven't managed to find how to decode pdu format using the libs I managed to find.
Did anyone managed to work with pdu format?

PS:
Here are some of my projects with GSM controller:







[ Edited Tue Mar 26 2013, 02:08 am ]
Mon Mar 25 2013, 10:17 am
#2
This page might help you...
http://www.smartposition.nl/resources/sms_pdu.html
consider using 7-bit ascii only for simplicity of implementation.
Tue Mar 26 2013, 02:04 am
#3


This page might help you...
http://www.smartposition.nl/resources/sms_pdu.html
consider using 7-bit ascii only for simplicity of implementation.

Ajay Bhargav



This is what I get from my phone (Sony Ericsson T230)

+CMGL: 1,1,,24
07910447946400F0240B910447165231F600003130910220148005537A584E07
OK

I suppose that the best solution is to detect in to my string the sequence +CMGL and after that to put in an array the piece that contains the message and after that I will decode it


[ Edited Tue Mar 26 2013, 02:09 am ]
Tue Mar 26 2013, 06:29 pm
#4
decoding is the hardest part. You need to first store in array and then convert ascii to hex and finally get the sms out of PDU bytes. I suggest you to use CMGR command instead of CMGL as CMGL will have longer list of sms whereas CMGR will give you only the sms you request to read.
Tue Mar 26 2013, 07:30 pm
#5
Ok I will start working on this and I will inform you how it works
Tue Mar 26 2013, 11:14 pm
#6
Hi.
Good news.I've managed to create some C code that I tested for the moment in VisualStudio and it seems to work.
I will start the implementation on the MCU
Here is the code for decoding :
#include "stdafx.h"
#include<iostream>

#include <string.h>

#include <conio.h>

using namespace std;

//-------------------------------------------------------------------------------------------------------------------------------------------------
void IntToHexString(short int len, char *slen)
{
  char hexchar[]={'0','1','2','3','4','5','6','7','8','9',
                  'A','B','C','D','E','F'};
  sprintf(slen, "%c%c",hexchar[(len & 0xF0)>
>
4],hexchar[len & 0x0F]);
}


void HexStrToInt(char *str, int * result)
{
  //char HexChars[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
  int high=0;
  int low=0;
  if ((str[0]>
='0') && (str[0]<='9')) high=str[0]-'0';
  if ((str[0]>
='A') && (str[0]<='F')) high=str[0]-'A'+10;
  if ((str[0]>
='a') && (str[0]<='f')) high=str[0]-'a'+10;
  if ((str[1]>
='0') && (str[1]<='9')) low=str[1]-'0';
  if ((str[1]>
='A') && (str[1]<='F')) low=str[1]-'A'+10;
  if ((str[1]>
='a') && (str[1]<='f')) low=str[1]-'a'+10;
   *result=high*16+low;
}


void EncodePDU7BitData(char* input, char*output)
{
  int pos=0;
  int c1, c2, r, temp;
  int i;
  int inputlen;
  inputlen=strlen(input);
  IntToHexString(inputlen, output+pos);
  pos+=2;
  for (i=0;i<inputlen;i++)
  {
	if (i==inputlen)
	  c2=0;
	else
	  c2=input[i+1] & 0x7F;
	c1=input[i] & 0x7F;
	r=(i+1) % 8;
	if (r!=0)
	{
	  temp=((c1 >
>
 (r - 1)) | (c2 << (8-r)))& 0xFF;
	  IntToHexString(temp, output+pos);
	  pos+=2;
	}
  }
}
void DecodePDU7BitData(char* input, char*output)
{
  int len, temp;
  char tempstr1[3], tempstr2[3];
  unsigned int tempval,i, j, pos;
  int temp1, temp2;
  int inputlen;

  inputlen=0;
  while ((input[inputlen]!=10)&&(input[inputlen]!=13)) inputlen++;
  
  
  pos=0;
  HexStrToInt(input, &len);
  j=2;
  for (i=1;i<=((inputlen-2) /2);i++)
  {
	if ((i %7)==1)
	{
	  HexStrToInt(input+j, &temp);
	  output[pos]=(temp & 0x7F);
	  //if (output[pos]==0) output[pos]=' ';
	  pos++;
	}
	else if ((i % 7) ==0)
	{
	  tempstr1[0]=input[j];tempstr1[1]=input[j+1];tempstr1[2]=0;
	  tempstr2[0]=input[j-2];tempstr2[1]=input[j-1];tempstr2[2]=0;
	  HexStrToInt(tempstr1, &temp1);
	  HexStrToInt(tempstr2, &temp2);
	  tempval=temp1*0x100+temp2;
	  output[pos]=(tempval>
>
2)& 0x7F;
	  //if (output[pos]==0) output[pos]=' ';
	  pos++;

	  output[pos]=(tempval>
>
9)&0x7F;
	  //if (output[pos]==0) output[pos]=' ';
	  pos++;
	}
	else
	{
	  tempstr1[0]=input[j];tempstr1[1]=input[j+1];tempstr1[2]=0;
	  tempstr2[0]=input[j-2];tempstr2[1]=input[j-1];tempstr2[2]=0;
	  HexStrToInt(tempstr1, &temp1);
	  HexStrToInt(tempstr2, &temp2);
	  tempval=temp1*0x100+temp2;

	  output[pos]=(tempval >
>
 (9 - (i % 7))) & 0x7F;
	  //if (output[pos]==0) output[pos]=' ';
	  pos++;
	}
	j+=2;
  }
  output[len]=0;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------



int _tmain(int argc, _TCHAR* argv[])
{
	char *string_position = 0;
	char str_res_hour[100];	
	char upper[100];	
//	char ReadBuffer[100] = "05537A584E07";
	int i = 0;
	//char ReadBuffer[100] = "+CMGL: 1,1,,24 07910447946400F0240B910447165231F600003130910220148005537A584E07";
/*	if (strstr(ReadBuffer, "+CMGL") != 0)
	{

				string_position = strstr(ReadBuffer, "+CMGL");
				strncpy(str_res_hour, string_position + 69,20);
				str_res_hour[21] = '\0';
	}
*/

	DecodePDU7BitData("08737A584E8FC966",str_res_hour);
	//_strupr(str_res_hour);
	while (str_res_hour[i])
	{
		upper[i]=toupper(str_res_hour[i]);
		i++;
	}
	upper[i]='\0';
	puts(upper);
	_getch();

	return 0;
}
Wed Mar 27 2013, 02:34 am
#7
I've got a new question it is possible to send a SMS without adding SMSC number in the PDU package?

I've the answer myself

"It is possible to tell the GSM/GPRS modem or mobile phone to use the SMSC number specified by the AT command +CSCA (command name in text: Service Centre Address) for sending SMS messages. Just assign the value 0x00 to the first sub-field and omit the second and third sub-fields, i.e. the SMSC part becomes:"


[ Edited Wed Mar 27 2013, 02:37 am ]
Fri Mar 29 2013, 11:46 am
#8
haha.. congrats first of all for progress you've made. Do share your updates with us If you want I will host your project on this website. It will be helpful for many others..

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Robertrip
Fri Apr 26 2024, 11:20 am
ArnoldDiant
Fri Apr 26 2024, 03:53 am
RodneyKnorb
Thu Apr 25 2024, 07:08 pm
Williamjef
Thu Apr 25 2024, 02:08 pm
SamuelSmise
Thu Apr 25 2024, 09:56 am
DustinErele
Thu Apr 25 2024, 08:44 am
ztaletpzca
Wed Apr 24 2024, 11:19 pm
IrardlPex
Wed Apr 24 2024, 08:42 pm