Add length parameter to GSM7Bit decode
parent
84fbedc46b
commit
cf655b2b3c
|
@ -31,17 +31,18 @@ module Biju
|
||||||
user_data_length: string[52..53],
|
user_data_length: string[52..53],
|
||||||
}
|
}
|
||||||
res[:sender_number] = string[22..(22 + res[:address_length])]
|
res[:sender_number] = string[22..(22 + res[:address_length])]
|
||||||
res[:user_data] = PDU.decode_user_data(
|
res[:user_data] = PDU.decode_user_data(string[54..-1],
|
||||||
string[54..-1], res[:data_coding_scheme])
|
encoding: res[:data_coding_scheme],
|
||||||
|
length: res[:user_data_length].hex)
|
||||||
|
|
||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.decode_user_data(message, encoding = '00')
|
def self.decode_user_data(message, encoding: '00', length: 0)
|
||||||
encoding = data_coding_scheme(encoding) unless encoding.is_a?(Symbol)
|
encoding = data_coding_scheme(encoding) unless encoding.is_a?(Symbol)
|
||||||
|
|
||||||
raise ArgumentError, "Unknown encoding" unless ENCODING.has_key?(:gsm7bit)
|
raise ArgumentError, "Unknown encoding" unless ENCODING.has_key?(:gsm7bit)
|
||||||
ENCODING[:gsm7bit].decode(message)
|
ENCODING[:gsm7bit].decode(message, length: length)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.data_coding_scheme(dcs)
|
def self.data_coding_scheme(dcs)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
module Biju::PDU
|
module Biju
|
||||||
|
module PDU
|
||||||
class GSM7Bit
|
class GSM7Bit
|
||||||
BASIC_7BIT_CHARACTER_SET = [
|
BASIC_7BIT_CHARACTER_SET = [
|
||||||
'@', '£', '$', '¥', 'è', 'é', 'ù', 'ì', 'ò', 'Ç', "\n", 'Ø', 'ø', "\r", 'Å', 'å',
|
'@', '£', '$', '¥', 'è', 'é', 'ù', 'ì', 'ò', 'Ç', "\n", 'Ø', 'ø', "\r", 'Å', 'å',
|
||||||
|
@ -26,7 +27,7 @@ module Biju::PDU
|
||||||
0x65 => '€',
|
0x65 => '€',
|
||||||
}
|
}
|
||||||
|
|
||||||
def self.decode(string)
|
def self.decode(string, length: 0)
|
||||||
res = ''
|
res = ''
|
||||||
next_char = 0
|
next_char = 0
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ module Biju::PDU
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
res
|
res[0..(length - 1)]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.encode(string)
|
def self.encode(string)
|
||||||
|
@ -79,3 +80,4 @@ module Biju::PDU
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue