class Empp::Utils::Utils
Public Class Methods
getTimestampInt(now)
click to toggle source
MMDDHHMMSS
# File lib/empp/utils/utils.rb, line 12 def self.getTimestampInt(now) u8 = BinData::Uint8.new intVal = now.month * 10**8 + now.day * 10**6 + now.hour * 10**4 + now.min * 10**2 + now.sec end
getTimestampStr(now)
click to toggle source
# File lib/empp/utils/utils.rb, line 17 def self.getTimestampStr(now) now.month.to_s.rjust(2, "0") + now.day.to_s.rjust(2, "0") + now.hour.to_s.rjust(2, "0") + now.min.to_s.rjust(2, "0") + now.sec.to_s.rjust(2, "0") end
getUintBe(intValue)
click to toggle source
# File lib/empp/utils/utils.rb, line 27 def self.getUintBe(intValue) ibe = BinData::Uint32be.new ibe.assign( intValue ) ibe.to_binary_s end
getUintLe(intValue)
click to toggle source
# File lib/empp/utils/utils.rb, line 21 def self.getUintLe(intValue) ibe = BinData::Uint32le.new ibe.assign( intValue ) ibe.to_binary_s end
getVersion()
click to toggle source
# File lib/empp/utils/utils.rb, line 33 def self.getVersion version = 0b00010000 u8 = BinData::Uint8be.new u8.assign(version) u8.to_binary_s end
Private Class Methods
convert_gbk_to_utf8(strVal)
click to toggle source
# File lib/empp/utils/utils.rb, line 51 def self.convert_gbk_to_utf8(strVal) conv = Iconv.new("utf-8", "gbk") conv.iconv(strVal) end
convert_ucs2_to_utf8(strVal)
click to toggle source
# File lib/empp/utils/utils.rb, line 56 def self.convert_ucs2_to_utf8(strVal) conv = Iconv.new("utf-8", "utf-16") conv.iconv(strVal) end
convert_utf8_to_gbk(strVal)
click to toggle source
# File lib/empp/utils/utils.rb, line 46 def self.convert_utf8_to_gbk(strVal) conv = Iconv.new("gbk", "utf-8") conv.iconv(strVal) end
deal_with_terminal_id(terminal_id)
click to toggle source
strip the possible prefix like “86” “+86” in ## terminal_id ##
# File lib/empp/utils/utils.rb, line 65 def self.deal_with_terminal_id(terminal_id) start_index = 0 if terminal_id.start_with?"86" start_index = 2 elsif terminal_id.start_with?"+86" start_index = 3 end terminal_id[start_index .. -1] end
fill_zero(binaryStr)
click to toggle source
# File lib/empp/utils/utils.rb, line 42 def self.fill_zero(binaryStr) binaryStr.rjust(2, "\0") end
get_splitted_msgs(msg_content)
click to toggle source
split msg_content to slices which has characters<70 ## to fit empp’s requirement, msg_content is coded as gbk ##
# File lib/empp/utils/utils.rb, line 80 def self.get_splitted_msgs(msg_content) fix_len = 68 msgs = [] count, index = 0, 0; tmp_str = '' step = 1 while true if count > fix_len || index >= msg_content.length msgs << tmp_str tmp_str = '' count = 0 end break if index >= msg_content.length bt = msg_content[index] if bt.to_i < 128 && bt.to_i > 0 tmp_str << msg_content[index] step = 1 else tmp_str << msg_content[index] tmp_str << msg_content[index + 1] step = 2 end index += step count += 1 end msgs end