Autor Tema: Decodificación de mensajes de texto en formato PDU  (Leído 3586 veces)

0 Usuarios y 2 Visitantes están viendo este tema.

Desconectado jonathanPIC888

  • Colaborador
  • PIC18
  • *****
  • Mensajes: 320
Decodificación de mensajes de texto en formato PDU
« en: 07 de Agosto de 2009, 17:47:50 »
Hola a todos  :)

Quería hacerles una pregunta: Alguno sabe como se puede decodificar una trama en formato PDU proveniente desde un celular.
Mis avances han sido respecto a enviar SMS con el microcontrolador programando en C de CCS pero no he podido recibirlos.

Usando VB 6.0 si he podido decodificar la trama PDU:
El programa:

Código: Visual Basic
  1. Private Sub Command1_Click()
  2. Dim a As String
  3. a = sms_pdu.Text
  4. texto_decodificado.Text = GetUserMessageDecoded(a)
  5. End Sub

Y la librería con las funciones:

Código: Visual Basic
  1. Function GetLengthSMSC(pdu As String) As Variant
  2. Dim inicio As Integer
  3. inicio = 1
  4. pdu_temp = Val("&H" & (Mid(pdu, inicio, 2)))
  5. GetLengthSMSC = pdu_temp
  6. End Function
  7.  
  8. Function GetLengthAddress(pdu As String) As Variant
  9. Dim posicion As Integer
  10. posicion = (GetLengthSMSC(pdu)) * 2 + 5
  11.  
  12. pdu_temp = Val("&H" & (Mid(pdu, posicion, 2)))
  13. GetLengthAddress = pdu_temp
  14. End Function
  15. Function GetUserDataLength(pdu As String) As Variant
  16. Dim posicion As Integer
  17. If GetLengthAddress(pdu) / 2 = Int(GetLengthAddress(pdu) / 2) Then
  18.  posicion = (GetLengthSMSC(pdu)) * 2 + 27 + GetLengthAddress(pdu)
  19. Else
  20.  posicion = (GetLengthSMSC(pdu)) * 2 + 28 + GetLengthAddress(pdu)
  21. End If
  22.  
  23. pdu_temp = Val("&H" & (Mid(pdu, posicion, 2)))
  24. GetUserDataLength = pdu_temp
  25. End Function
  26.  
  27. Function GetUserMessageDecoded(pdu As String) As String
  28. Dim temp As Double
  29. Dim temp_left As Double
  30. Dim mensaje_temp As String
  31. Dim posicion As Integer
  32. If GetLengthAddress(pdu) / 2 = Int(GetLengthAddress(pdu) / 2) Then
  33.  posicion = (GetLengthSMSC(pdu)) * 2 + 29 + GetLengthAddress(pdu)
  34. Else
  35.  posicion = (GetLengthSMSC(pdu)) * 2 + 30 + GetLengthAddress(pdu)
  36. End If
  37.  
  38. For i = 0 To (Len(pdu) - posicion) / 2
  39. If ((i Mod 7) = 0) And i <> 0 Then
  40.  mensaje_temp = mensaje_temp & Chr$(temp_left)
  41.  temp_left = 0
  42. End If
  43. temp = 2 ^ (i Mod 7) * (Val("&H" & (Mid(pdu, posicion + (2 * i), 2))) Mod 2 ^ (7 - (i Mod 7))) + temp_left
  44. temp_left = Val("&H" & (Mid(pdu, posicion + (2 * i), 2))) \ 2 ^ (7 - (i Mod 7))
  45. mensaje_temp = mensaje_temp & Chr$(temp)
  46. Next i
  47.  
  48. GetUserMessageDecoded = Mid$(mensaje_temp, 1, GetUserDataLength(pdu))
  49. End Function

El problema es que no se como poder adaptar mi código de VB 2005 a C de CCS para poder ejecutar la misma rutina en el micro.

Espero que me puedan dar una mano  :)

Desde ya muchas gracias.


 

anything