Class: ComunikaGsm::PDU::PDUDecode

Inherits:
Object
  • Object
show all
Defined in:
lib/comunika_gsm/pdu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ PDUDecode

Returns a new instance of PDUDecode.



27
28
29
30
31
32
33
# File 'lib/comunika_gsm/pdu.rb', line 27

def initialize(params)
  @id = params[:id]; @size = params[:size]; @pdu = params[:pdu]; @mtype = params[:mtype]; @smsc = params[:smsc]
  @number = params[:number]; @messageref = params[:messageref]; @send_at = params[:send_at]; @discharge_at = params[:discharge_at]
  @status = params[:status]; @tp_pid = params[:tp_pid]; @tp_dcs_popis = params[:tp_dcs_popis]; @mclass = params[:mclass]
  @alphabet = params[:alphabet]; @message = params[:message]; @length = params[:length]; @validity = params[:validity]
  @connection = params[:connection]
end

Instance Attribute Details

#alphabetObject

Returns the value of attribute alphabet.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def alphabet
  @alphabet
end

#connectionObject

Returns the value of attribute connection.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def connection
  @connection
end

#discharge_atObject



80
81
82
83
# File 'lib/comunika_gsm/pdu.rb', line 80

def discharge_at
  return if @discharge_at.nil?
  Time.parse(@discharge_at.sub(/(\d+)\D+(\d+)\D+(\d+)/, '\1/\2/20\3')).strftime('%Y/%m/%d %H:%M:%S')
end

#idObject

Returns the value of attribute id.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def id
  @id
end

#lengthObject

Returns the value of attribute length.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def length
  @length
end

#mclassObject

Returns the value of attribute mclass.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def mclass
  @mclass
end

#messageObject

Returns the value of attribute message.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def message
  @message
end

#messagerefObject

Returns the value of attribute messageref.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def messageref
  @messageref
end

#mlenghtObject

Returns the value of attribute mlenght.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def mlenght
  @mlenght
end

#mtypeObject

Returns the value of attribute mtype.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def mtype
  @mtype
end

#numberObject

Returns the value of attribute number.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def number
  @number
end

#pduObject

Returns the value of attribute pdu.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def pdu
  @pdu
end

#send_atObject



75
76
77
78
# File 'lib/comunika_gsm/pdu.rb', line 75

def send_at
  return @send_at.nil?
  Time.parse(@send_at.sub(/(\d+)\D+(\d+)\D+(\d+)/, '\1/\2/20\3')).strftime('%Y/%m/%d %H:%M:%S')
end

#sizeObject

Returns the value of attribute size.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def size
  @size
end

#smscObject

Returns the value of attribute smsc.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def smsc
  @smsc
end

#statusObject

Returns the value of attribute status.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def status
  @status
end

#tp_dcs_popisObject

Returns the value of attribute tp_dcs_popis.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def tp_dcs_popis
  @tp_dcs_popis
end

#tp_pidObject

Returns the value of attribute tp_pid.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def tp_pid
  @tp_pid
end

#validityObject

Returns the value of attribute validity.



24
25
26
# File 'lib/comunika_gsm/pdu.rb', line 24

def validity
  @validity
end

Instance Method Details

#decodeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/comunika_gsm/pdu.rb', line 35

def decode
  msg = PDU.decode(self.pdu)
  msg.downcase.split(/\n/).each do |m|
    data = m.split(/\::::/)
    case data[0].strip
    when 'type'
      set_mtype(data[1].strip)
    when 'smsc'
      @smsc = data[1].strip
    when 'sender'
      @number = data[1].strip
    when 'messageref'
      @messageref = data[1].strip
    when 'timestamp'
      @send_at = data[1].strip
    when 'timestamp2'
      @discharge_at = data[1].strip
    when 'status byte'
      @status = "0x#{data[1].strip}".to_i(16)
    when 'tp_pid'
      @tp_pid = data[1].strip
    when 'tp_pid'
      @tp_pid = data[1].strip
    when 'tp_dcs'
      @tp_dcs = data[1].strip
    when 'tp_dcs-popis'
      @tp_dcs_popis = data[1].strip
    when 'mclass'
      @mclass = data[1].strip
    when 'alphabet'
      @alphabet = data[1].strip
    when 'message'
      @message = data[1].strip
    when 'length'
      @length = data[1].strip
    end
  end
  return self
end

#deleteObject



85
86
87
# File 'lib/comunika_gsm/pdu.rb', line 85

def delete
  @connection.cmd("AT+CMGD=#{@id}\r\n")
end