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 :



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ardtweeno/packet.rb', line 51

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
  @second = ("%02d" % today.sec).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



41
42
43
# File 'lib/ardtweeno/packet.rb', line 41

def data
  @data
end

#dateObject

Class fields



41
42
43
# File 'lib/ardtweeno/packet.rb', line 41

def date
  @date
end

#hourObject

Class fields



41
42
43
# File 'lib/ardtweeno/packet.rb', line 41

def hour
  @hour
end

#keyObject

Class fields



41
42
43
# File 'lib/ardtweeno/packet.rb', line 41

def key
  @key
end

#minuteObject

Class fields



41
42
43
# File 'lib/ardtweeno/packet.rb', line 41

def minute
  @minute
end

#nodeObject

Class fields



41
42
43
# File 'lib/ardtweeno/packet.rb', line 41

def node
  @node
end

#secondObject

Class fields



41
42
43
# File 'lib/ardtweeno/packet.rb', line 41

def second
  @second
end

#seqNoObject

Class fields



41
42
43
# File 'lib/ardtweeno/packet.rb', line 41

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 :



105
106
107
108
109
110
111
112
# File 'lib/ardtweeno/packet.rb', line 105

def to_json(options={})
  
  jsonStr = '{"date":"' + @date + '","hour":"' + @hour + '","minute":"' +
  @minute + '","second":"' + @second + '","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 :



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

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