View Single Post
NerdKnight's Avatar
Posts: 113 | Thanked: 334 times | Joined on Oct 2010 @ Argentina
#435
Originally Posted by digitalvoid View Post
@ NerdKnight:

I didn't develop the SMSreceive code myself (It found it on maemo.org).

Could you explain to more?

In The Netherlands we use a 10 digit number: 06-12345678 (locally used, 06 is prefix for mobile number)

In international format this is: 0031-612345678 or +31-612345678
In Argentine we use 10 digits too, but if the sender's number length change (international numbers or send-free-sms webpages) will not work.
Here is the full specifications of the PDU messages:
http://www.dreamfabric.com/sms/
It seems that the tree first parts are not used on n900, so at 2nd. position in the array is the length of the senders number (in decimal digits, 2 digits per octet)
Code:
n=int(PDUmessage[1])
so we can calculate the starting position of the message as follow:
Code:
n=n//2+n%2+13
13 are the fixed positions before the message and we have to add the length in octets of the sender's number.
To support different sender number lengths, I suggest the function should be like this:
Code:
def SMSreceive(PDUmessage, MessageCenter, SomeString, Number):
    """
    Receive SMS command and execute command.
    """
    n=int(PDUmessage[1])
    n=n//2+n%2+13
    MessageArray  = PDUmessage[n:len(PDUmessage)]

    Message = DeOctifyMessage(MessageArray) # decode sms message as plain text

    ProcessCommand(Message, Number) # process sms command