Class: ComunikaGsm::PDU::PDUDecode
- Inherits:
-
Object
- Object
- ComunikaGsm::PDU::PDUDecode
- Defined in:
- lib/comunika_gsm/pdu.rb
Instance Attribute Summary collapse
-
#alphabet ⇒ Object
Returns the value of attribute alphabet.
-
#connection ⇒ Object
Returns the value of attribute connection.
- #discharge_at ⇒ Object
-
#id ⇒ Object
Returns the value of attribute id.
-
#length ⇒ Object
Returns the value of attribute length.
-
#mclass ⇒ Object
Returns the value of attribute mclass.
-
#message ⇒ Object
Returns the value of attribute message.
-
#messageref ⇒ Object
Returns the value of attribute messageref.
-
#mlenght ⇒ Object
Returns the value of attribute mlenght.
-
#mtype ⇒ Object
Returns the value of attribute mtype.
-
#number ⇒ Object
Returns the value of attribute number.
-
#pdu ⇒ Object
Returns the value of attribute pdu.
- #send_at ⇒ Object
-
#size ⇒ Object
Returns the value of attribute size.
-
#smsc ⇒ Object
Returns the value of attribute smsc.
-
#status ⇒ Object
Returns the value of attribute status.
-
#tp_dcs_popis ⇒ Object
Returns the value of attribute tp_dcs_popis.
-
#tp_pid ⇒ Object
Returns the value of attribute tp_pid.
-
#validity ⇒ Object
Returns the value of attribute validity.
Instance Method Summary collapse
- #decode ⇒ Object
- #delete ⇒ Object
-
#initialize(params) ⇒ PDUDecode
constructor
A new instance of PDUDecode.
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
#alphabet ⇒ Object
Returns the value of attribute alphabet.
24 25 26 |
# File 'lib/comunika_gsm/pdu.rb', line 24 def alphabet @alphabet end |
#connection ⇒ Object
Returns the value of attribute connection.
24 25 26 |
# File 'lib/comunika_gsm/pdu.rb', line 24 def connection @connection end |
#discharge_at ⇒ Object
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 |
#id ⇒ Object
Returns the value of attribute id.
24 25 26 |
# File 'lib/comunika_gsm/pdu.rb', line 24 def id @id end |
#length ⇒ Object
Returns the value of attribute length.
24 25 26 |
# File 'lib/comunika_gsm/pdu.rb', line 24 def length @length end |
#mclass ⇒ Object
Returns the value of attribute mclass.
24 25 26 |
# File 'lib/comunika_gsm/pdu.rb', line 24 def mclass @mclass end |
#message ⇒ Object
Returns the value of attribute message.
24 25 26 |
# File 'lib/comunika_gsm/pdu.rb', line 24 def @message end |
#messageref ⇒ Object
Returns the value of attribute messageref.
24 25 26 |
# File 'lib/comunika_gsm/pdu.rb', line 24 def @messageref end |
#mlenght ⇒ Object
Returns the value of attribute mlenght.
24 25 26 |
# File 'lib/comunika_gsm/pdu.rb', line 24 def mlenght @mlenght end |
#mtype ⇒ Object
Returns the value of attribute mtype.
24 25 26 |
# File 'lib/comunika_gsm/pdu.rb', line 24 def mtype @mtype end |
#number ⇒ Object
Returns the value of attribute number.
24 25 26 |
# File 'lib/comunika_gsm/pdu.rb', line 24 def number @number end |
#pdu ⇒ Object
Returns the value of attribute pdu.
24 25 26 |
# File 'lib/comunika_gsm/pdu.rb', line 24 def pdu @pdu end |
#send_at ⇒ Object
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 |
#size ⇒ Object
Returns the value of attribute size.
24 25 26 |
# File 'lib/comunika_gsm/pdu.rb', line 24 def size @size end |
#smsc ⇒ Object
Returns the value of attribute smsc.
24 25 26 |
# File 'lib/comunika_gsm/pdu.rb', line 24 def smsc @smsc end |
#status ⇒ Object
Returns the value of attribute status.
24 25 26 |
# File 'lib/comunika_gsm/pdu.rb', line 24 def status @status end |
#tp_dcs_popis ⇒ Object
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_pid ⇒ Object
Returns the value of attribute tp_pid.
24 25 26 |
# File 'lib/comunika_gsm/pdu.rb', line 24 def tp_pid @tp_pid end |
#validity ⇒ Object
Returns the value of attribute validity.
24 25 26 |
# File 'lib/comunika_gsm/pdu.rb', line 24 def validity @validity end |
Instance Method Details
#decode ⇒ Object
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 |
#delete ⇒ Object
85 86 87 |
# File 'lib/comunika_gsm/pdu.rb', line 85 def delete @connection.cmd("AT+CMGD=#{@id}\r\n") end |