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.



24
25
26
27
28
29
30
# File 'lib/comunika_gsm/pdu.rb', line 24

def initialize(params)
  @id = params[:id]; @size = params[:size]; @pdu = params[:pdu]; @mtype = params[:mtype]; @smsc = params[:smsc]
  @number = params[:number]; @sms_id = params[:sms_id]; @sent_at = params[:sent_at]; @discharge_at = params[:receipt_at]
  @status = params[:status]; @tp_pid = params[:tp_pid]; @tp_dcs_popis = params[:tp_dcs_popis]; @message = params[:message]
  @length = params[:mlength]; @validity = params[:validity]; @mtype = params[:mtype]
  @connection = params[:connection]
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



21
22
23
# File 'lib/comunika_gsm/pdu.rb', line 21

def connection
  @connection
end

#idObject

Returns the value of attribute id.



21
22
23
# File 'lib/comunika_gsm/pdu.rb', line 21

def id
  @id
end

#lengthObject

Returns the value of attribute length.



21
22
23
# File 'lib/comunika_gsm/pdu.rb', line 21

def length
  @length
end

#messageObject

Returns the value of attribute message.



21
22
23
# File 'lib/comunika_gsm/pdu.rb', line 21

def message
  @message
end

#mlenghtObject

Returns the value of attribute mlenght.



21
22
23
# File 'lib/comunika_gsm/pdu.rb', line 21

def mlenght
  @mlenght
end

#mtypeObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/comunika_gsm/pdu.rb', line 45

def mtype
  case @mtype
  when 'Receipt requested'
    'INCOMING'
  when 'Status Report'
    'REPORT'
  when 'Unknown Message'
    'REPORT'
  when 'Receive message'
    'INCOMING'
  when 'Data Header'
    'MULTIPART'
  else
    'UNKNOWN'
  end
end

#numberObject

Returns the value of attribute number.



21
22
23
# File 'lib/comunika_gsm/pdu.rb', line 21

def number
  @number
end

#pduObject

Returns the value of attribute pdu.



21
22
23
# File 'lib/comunika_gsm/pdu.rb', line 21

def pdu
  @pdu
end

#receipt_atObject



41
42
43
# File 'lib/comunika_gsm/pdu.rb', line 41

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

#sent_atObject



37
38
39
# File 'lib/comunika_gsm/pdu.rb', line 37

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

#sizeObject

Returns the value of attribute size.



21
22
23
# File 'lib/comunika_gsm/pdu.rb', line 21

def size
  @size
end

#sms_idObject

Returns the value of attribute sms_id.



21
22
23
# File 'lib/comunika_gsm/pdu.rb', line 21

def sms_id
  @sms_id
end

#smscObject

Returns the value of attribute smsc.



21
22
23
# File 'lib/comunika_gsm/pdu.rb', line 21

def smsc
  @smsc
end

#statusObject

Returns the value of attribute status.



21
22
23
# File 'lib/comunika_gsm/pdu.rb', line 21

def status
  @status
end

#tp_dcs_popisObject

Returns the value of attribute tp_dcs_popis.



21
22
23
# File 'lib/comunika_gsm/pdu.rb', line 21

def tp_dcs_popis
  @tp_dcs_popis
end

#tp_pidObject

Returns the value of attribute tp_pid.



21
22
23
# File 'lib/comunika_gsm/pdu.rb', line 21

def tp_pid
  @tp_pid
end

#validityObject

Returns the value of attribute validity.



21
22
23
# File 'lib/comunika_gsm/pdu.rb', line 21

def validity
  @validity
end

Instance Method Details

#decodeObject



32
33
34
35
# File 'lib/comunika_gsm/pdu.rb', line 32

def decode
  PDU.decode(self.pdu).each {|k,v| instance_variable_set("@#{k.to_s}",v)}
  self
end

#deleteObject



62
63
64
# File 'lib/comunika_gsm/pdu.rb', line 62

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