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:
Private Sub Command1_Click()
Dim a As String
a = sms_pdu.Text
texto_decodificado.Text = GetUserMessageDecoded(a)
End Sub
Y la librería con las funciones:
Function GetLengthSMSC(pdu As String) As Variant
Dim inicio As Integer
inicio = 1
pdu_temp = Val("&H" & (Mid(pdu, inicio, 2)))
GetLengthSMSC = pdu_temp
End Function
Function GetLengthAddress(pdu As String) As Variant
Dim posicion As Integer
posicion = (GetLengthSMSC(pdu)) * 2 + 5
pdu_temp = Val("&H" & (Mid(pdu, posicion, 2)))
GetLengthAddress = pdu_temp
End Function
Function GetUserDataLength(pdu As String) As Variant
Dim posicion As Integer
If GetLengthAddress(pdu) / 2 = Int(GetLengthAddress(pdu) / 2) Then
posicion = (GetLengthSMSC(pdu)) * 2 + 27 + GetLengthAddress(pdu)
Else
posicion = (GetLengthSMSC(pdu)) * 2 + 28 + GetLengthAddress(pdu)
End If
pdu_temp = Val("&H" & (Mid(pdu, posicion, 2)))
GetUserDataLength = pdu_temp
End Function
Function GetUserMessageDecoded(pdu As String) As String
Dim temp As Double
Dim temp_left As Double
Dim mensaje_temp As String
Dim posicion As Integer
If GetLengthAddress(pdu) / 2 = Int(GetLengthAddress(pdu) / 2) Then
posicion = (GetLengthSMSC(pdu)) * 2 + 29 + GetLengthAddress(pdu)
Else
posicion = (GetLengthSMSC(pdu)) * 2 + 30 + GetLengthAddress(pdu)
End If
For i = 0 To (Len(pdu) - posicion) / 2
If ((i Mod 7) = 0) And i <> 0 Then
mensaje_temp = mensaje_temp & Chr$(temp_left)
temp_left = 0
End If
temp = 2 ^ (i Mod 7) * (Val("&H" & (Mid(pdu, posicion + (2 * i), 2))) Mod 2 ^ (7 - (i Mod 7))) + temp_left
temp_left = Val("&H" & (Mid(pdu, posicion + (2 * i), 2))) \ 2 ^ (7 - (i Mod 7))
mensaje_temp = mensaje_temp & Chr$(temp)
Next i
GetUserMessageDecoded = Mid$(mensaje_temp, 1, GetUserDataLength(pdu))
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.