Class: Ardtweeno::Packet

Inherits:
Object
  • Object
show all
Defined in:
lib/ardtweeno/packet.rb

Overview

Ardtweeno::Packet Communication storage class for the Ardtweeno system

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(newSeqNo, newKey, newData) ⇒ Packet

Ardtweeno::Packet#new for the Packet class

  • Args :

    • ++ -> :seqNo, :key, :data

  • Returns : -

  • Raises :



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ardtweeno/packet.rb', line 34

def initialize(newSeqNo, newKey, newData)
  
  # Create a DateTime instance
  today = DateTime.now
  theDate = today.year.to_s() + "-" + "%02d" % today.month.to_s() + "-" + "%02d" % today.day.to_s()
  
  # Default values
  @date = theDate
  @hour = ("%02d" % today.hour).to_s
  @minute = ("%02d" % today.min).to_s
  @data = newData
  @key = newKey
  
  # Need to implement a lookup function for key to node value
  @node = "defaultNode"
  
  if newSeqNo.class == Fixnum
    @seqNo = newSeqNo
  elsif newSeqNo.class == String
    @seqNo = newSeqNo.to_i
  end
  
end

Instance Attribute Details

#dataObject

Class fields



24
25
26
# File 'lib/ardtweeno/packet.rb', line 24

def data
  @data
end

#dateObject

Class fields



24
25
26
# File 'lib/ardtweeno/packet.rb', line 24

def date
  @date
end

#hourObject

Class fields



24
25
26
# File 'lib/ardtweeno/packet.rb', line 24

def hour
  @hour
end

#keyObject

Class fields



24
25
26
# File 'lib/ardtweeno/packet.rb', line 24

def key
  @key
end

#minuteObject

Class fields



24
25
26
# File 'lib/ardtweeno/packet.rb', line 24

def minute
  @minute
end

#nodeObject

Class fields



24
25
26
# File 'lib/ardtweeno/packet.rb', line 24

def node
  @node
end

#seqNoObject

Class fields



24
25
26
# File 'lib/ardtweeno/packet.rb', line 24

def seqNo
  @seqNo
end

Instance Method Details

#to_json(options = {}) ⇒ Object

Ardtweeno::Packet#to_json returns a representation of the current instance state in JSON form

  • Args :

    • ++ ->

  • Returns :

    • String

  • Raises :



87
88
89
90
91
92
93
94
# File 'lib/ardtweeno/packet.rb', line 87

def to_json(options={})
  
  jsonStr = '{"date":"' + @date + '","hour":"' + @hour + '","minute":"' +
  @minute.to_s + '","node":"' + @node + '","key":"' + @key + '","seqNo":' +
  @seqNo.to_s + ',"data":' + @data.to_json + '}'
  
  return jsonStr
end

#to_sObject

Ardtweeno::Packet#to_s returns a representation of the current instance state in String form

  • Args :

    • ++ ->

  • Returns :

    • String

  • Raises :



68
69
70
71
72
73
74
75
# File 'lib/ardtweeno/packet.rb', line 68

def to_s
  # Build the string up from field data
  str = "Packet No: " + @seqNo.to_s + " Key: " + @key + " Node: " + @node + " Date: " + @date +
        " " + @hour + ":" + @minute + " Data: " + @data.to_s  
  
  # Returns the built string
  return str
end