You have to divide the process into parts to do something useful, this also helps you to create functions…
Function to convert a PDU SMSCenter part to real number
Step 1) we have aldeady the length of the PDU, 48, and the PDU itself from this:
http://forum.mikrotik.com/t/using-two-arrays-process-the-text-and-create-a-third-array/166923/1
07912180958739F1040B917120069876F000009140503223218A21D4F29C0E6A97E7F3F0B90CA2BF41412A68F86EB7C36E32885A9ED3CB72
***** done *****
Step 2) check if the length and the PDU corresponding:
:local length ($item->“length”)
:local pdu ($item->“PDU”)
:local skip (2 + ([:tonum “0x$[:pick $pdu 0 2]”] * 2))
:if ($length = (([:len $pdu] - $skip) / 2)) do={:put “OK”} else={:put “KO”}
48 is the length of SMS part, that start just after the SMSCenter number, so must be skipped the first two and the length specified on first two…
07912180958739F1 040B917120069876F000009140503223218A21D4F29C0E6A97E7F3F0B90CA2BF41412A68F86EB7C36E32885A9ED3CB72
Working function:
{
:local SMScheckPDU do={
:local length $1
:local pdu $2
:local skip (2 + ([:tonum "0x$[:pick $pdu 0 2]"] * 2))
:if ($length = (([:len $pdu] - $skip) / 2)) do={:return "OK"} else={:return "KO"}
}
:put [$SMScheckPDU 48 07912180958739F1040B917120069876F000009140503223218A21D4F29C0E6A97E7F3F0B90CA2BF41412A68F86EB7C36E32885A9ED3CB72]
}
Step 3) pick only the smsc number part
{
:local pdu 07912180958739F1040B917120069876F000009140503223218A21D4F29C0E6A97E7F3F0B90CA2BF41412A68F86EB7C36E32885A9ED3CB72
:local rawSMSC [:pick $pdu 2 (2 + ([:tonum “0x$[:pick $pdu 0 2]”] * 2))]
:put $rawSMSC
}
912180958739F1
Working function
{
:local rawSMSC do={:return [:pick $1 2 (2 + ([:tonum "0x$[:pick $1 0 2]"] * 2))]}
:put [$rawSMSC 07912180958739F1040B917120069876F000009140503223218A21D4F29C0E6A97E7F3F0B90CA2BF41412A68F86EB7C36E32885A9ED3CB72]
}
Step 4a) Identify the type of number represented, to be developed later,
actually “91” is the international numbering format, so if is “91”, the number is on deci-decimal format to be reversed, and is starting with “+”
91 + and 2180958739F1
Step 4b) reverse the number
from + and 2180958739F1 to +12085978931
The F is just a pad character when the number of digits in the phone is odd.
Each pair of deci-decimal must be swapped for obtain the right number.
{
:local rawSMSC “2180958739F1”
:local lenSMSC [:len $rawSMSC]
:local currPos 0
:local smsc “”
:while (($lenSMSC + 1) > $currPos) do={
:set smsc “$smsc$[:pick $rawSMSC ($currPos + 1) ($currPos + 2)]$[:pick $rawSMSC $currPos ($currPos + 1)]”
:set currPos ($currPos + 2)
}
:put $smsc
}
now you have + and 12085978931F, what remains to be done is the next point (except the step 4a)
Step 5) Create a function that providing the raw SMSCenter value, provide correct number (except the step 4a, for now).
Working code:
{
:local SMSCfromPDU do={
:local pdu [:tostr $1]
:local length [:tonum “0$2”]
:local skip (2 + ([:tonum “0x$[:pick $pdu 0 2]”] * 2))
:if ($length > 0) do={
:if ($length != (([:len $pdu] - $skip) / 2)) do={:return “ERROR: Provided Length does not match SMS PDU part”}
}
:local smsc “”
:local type [:pick $pdu 2 4]
:if ($type = “91”) do={
:set smsc “+”
:local SMSCraw [:pick $pdu 4 $skip]
:local lenSMSC [:len $SMSCraw]
:local currPos 0
:while (($lenSMSC + 1) > $currPos) do={
:set smsc “$smsc$[:pick $SMSCraw ($currPos + 1) ($currPos + 2)]$[:pick $SMSCraw $currPos ($currPos + 1)]”
:set currPos ($currPos + 2)
}
:if ($smsc~“F$”) do={:set smsc [:pick $smsc 0 ([:len $smsc] - 1)]}
:return $smsc
}
:return “ERROR: Unexpected SMSC number type (0x$type)”
}
:put [$SMSCfromPDU 07912180958739F1040B917120069876F000009140503223218A21D4F29C0E6A97E7F3F0B90CA2BF41412A68F86EB7C36E32885A9ED3CB72 48]
}
The length is optional, if specified the validity of the PDU is calculated.
+1912085978931