Link to home
Start Free TrialLog in
Avatar of jxharding
jxharding

asked on

Decode PDU for SMS

I need a function to convert the incomming message in PDU mode when using the AT+CMGL command on a Siemens S55 mobile. If the incoming string was
07 917283010010F5 040BC87238880900F10000993092516195800AE8329BFD4697D9EC37
 Does anyone have a ready-made function/s to translate all the elements, especially the sms message at the end?
Avatar of tovvenki
tovvenki

Hi,
In which language do you need the function.

regards,
Venki
Avatar of jxharding

ASKER

vb6 if possible please,  .net would do as well
thank you
Hi,
I am sorry I have not done that in Vb6 or .Net but have alook at this link on SMS Messages and PDU then try to implement the logic in vb6 or .Net
http://www.dreamfabric.com/sms/

I hope that this helps you.

Venki
thanks venki, can i ask in what language do you have it,
maybe i can have a look at the logic and implement it.
thanks!
Hi,
I had it java, but I am sorry I can't release the source code because of an agreement. But decoding the sms message is very easy. Just have alook at the url that I have mentioned you. First manually separate the messages as specified in the article. Then you can just code that manual logic in Vb or Vb.net

Regards,
Venki
Hai,

Have a look at it

Dim objDecoder As New SMSEngineLib.SMSMessageManager
Dim objSMSMessage As SMSEngineLib.SMSMessage
Dim objPictureMessage As SMSEngineLib.PictureMessage
Dim objPDU As SMSEngineLib.PDU

'Decode the incoming PDU
Set objSMSMessage = objDecoder.DecodePDU( _
    "07912121212121F2440B911313131313F100F5301071514" & _
    "521448A0605041583000000480E01000000000000000000" & _
    "0000000000000000000C00060000C1B031F00C00660000C" & _
    "1B033181E00600000633873181E1EF6C33C363873001233" & _
    "66C3661C3CF1C0333066667E1C3CF07033306666603637B" & _
    "0183F30663C606337B31861B3661866C1B33318619E3618" & _
    "3CC1B331F0000000000000000000000000000000000000")

'Do we have the complete PDU?
If objSMSMessage.State = Waiting Then Exit Sub 'Come back later with the next PDU

If objSMSMessage.MessageType = PictureMessage Then

    'Cast to a PictureMessage message to get specific properties
    Set objPictureMessage = objSMSMessage

    'Report on some of the incoming message properties
    Debug.Print "Image for Picture Message: " + objPictureMessage.BitmapFileName
    Debug.Print "Sent from: " + objPictureMessage.SenderAddress
    Debug.Print "Message arrived: " + objPictureMessage.PDUs.Item(1).ArrivalDate

End If

The SDK is present in http://www.businesms.com/samplecode_sms.htm

HAVE A LOOK AT THE FOLLOWING LINK.ITS VERY GOOD
http://www.codeproject.com/library/smpplib.asp

Also Refer

http://www.componentsource.com/Catalog.asp?fl=&bc=&sc=CS&sr=Decode%20PDU%20for%20SMS%20.net&bhcp=1

Hope this helps

Regards
Venish
ASKER CERTIFIED SOLUTION
Avatar of SimonTay
SimonTay

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi SimonTay
I have working code for the outgoing, I am looking for the incomming code. I am receiving an sms using "at+cmgl" and I need to decode the pdu message. If you could be so kind as to post the incomming code I would be grateful. Thank you for the code Venishjoe, but the sdk only demo's a send and not a receive. I have to show my prospective client the full program and once he purchases my product then I will buy the full version and incorporate it into my program. Thanks once again.

Private Function DecodeIncomingSMS() As String
 Dim s As String, pid As Integer, udl As Integer, i As Integer, of As Integer
 
 Result.Cls
 
 s = SMS_Data
 For i = 1 To Len(s) / 2: sms_deliver(i) = Val("&H" + Mid$(s, i * 2 - 1, 2)): Next i
 'Debug.Print Mid$(s, 39, 2); Val("&H" & Mid$(s, 39, 2)), sms_deliver(20)
 If sms_deliver(1) = 7 Then 'this bit is assumed - we really don't know!!!
  Result.Print "A1 PDU"
  Result.Print "Type of address "; Hex$(sms_deliver(2))
  Result.Print "Service centre ";
  For i = 1 To 6
   Result.Print Chr(48 + (sms_deliver(2 + i) And 15)); Chr(48 + Int(sms_deliver(2 + i) / 16));
  Next i: Result.Print
  of = 8
 Else
  of = 0
 End If
 Result.Print "TP-RP "; Bit(sms_deliver(of + 1), 7)
 Result.Print "TP-UDHI "; Bit(sms_deliver(of + 1), 6)
 Result.Print "TP-SRI "; Bit(sms_deliver(of + 1), 5)
 Result.Print "TP-MMS "; Bit(sms_deliver(of + 1), 2)
 Result.Print "TP-MTI "; Bit(sms_deliver(of + 1), 1); Bit(sms_deliver(of + 1), 0)
 Result.Print "TP-OA Length"; sms_deliver(of + 2)
 Result.Print "Type of address "; Hex$(sms_deliver(of + 3))
 Result.Print "Originating address ";
 For i = 1 To sms_deliver(of + 2) / 2
  Result.Print Chr(48 + (sms_deliver(of + 3 + i) And 15)); Chr(48 + Int(sms_deliver(of + 3 + i) / 16));
 Next i: Result.Print
 
 pid = sms_deliver(of + 2) / 2 + of + 4
 Result.Print "TP-PID"; sms_deliver(pid)
 Result.Print "TP-DCS"; sms_deliver(pid + 1)
 Result.Print "SCTS";
 For i = 0 To 6: Result.Print (sms_deliver(pid + 2 + i) And 15) * 10 + Int(sms_deliver(pid + 2 + i) / 16);: Next i: Result.Print
 udl = pid + 9
 Result.Print "UDL"; sms_deliver(udl)
 If Bit(sms_deliver(of + 1), 6) = 1 Then
  'message has a header
 Else
  For i = 1 To sms_deliver(udl)
   dat(i) = sms_deliver(udl + i)
  Next i
  Result.Print MessageDecode(sms_deliver(udl)); "<end"
  DecodeIncomingSMS = MessageDecode(sms_deliver(udl))
 End If
End Function
Private Sub Delay(DelayTime As Double)
 MS50 = 0
 Do While MS50 < DelayTime
  DoEvents
 Loop
End Sub

Private Function MessageDecode(udl) As String
 Dim i As Integer, Byterev As Integer, Bits As Integer, sevenbit As Integer
 Dim Msg As String, p As Integer
 p = 1
 i = 1
 While p <= udl
  Byterev = Byterev * 256       'shift left 8 bits
  Byterev = Byterev + Rev(dat(i), 8)
  i = i + 1
  Bits = Bits + 8
  While Bits >= 7
   sevenbit = Int(Byterev / 2 ^ (Bits - 7))
   Byterev = Byterev - sevenbit * 2 ^ (Bits - 7)
   Bits = Bits - 7
   Msg = Msg & Chr(Rev(sevenbit, 7))
   p = p + 1
  Wend
 Wend
 MessageDecode = Msg
End Function

Function Rev(Byted As Integer, B As Integer) As Integer
 Dim j As Integer, Value As Integer
 For j = 0 To B - 1
  If Byted And 2 ^ j Then Value = Value + 2 ^ (B - 1 - j)
 Next j
 Rev = Value
End Function

This should help!

Simon

Thank you Simon, you are a star. Could you tell me what the "bit"  function is?
It just displays a 1 or a 0 depending on the value of the bit position, so bit(8,3) would display 1, bit (8,2) would display 0.
Private Function Bit(Value, B) As Variant
 If Value And 2 ^ B Then
  Bit = "1"
 Else
  Bit = "0"
 End If
End Function
TRY this .Net component
http://www.sharkysms.com/SMSModem.zip

it will do the stuff you want