lib/ardtweeno/packet.rb in ardtweeno-0.5.0 vs lib/ardtweeno/packet.rb in ardtweeno-0.6.0
- old
+ new
@@ -1,12 +1,29 @@
+=begin
####################################################################################################
-# @author David Kirwan <davidkirwanirl@gmail.com>
-# @description Packet Communication storage class for the Ardtweeno system
+# @author David Kirwan https://github.com/davidkirwan/ardtweeno
+# @description Ardtweeno Gateway
#
-# @date 14-11-2012
+# @date 2014-08-12
####################################################################################################
+This file is part of Ardtweeno.
+
+Ardtweeno is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+any later version.
+
+Ardtweeno is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+=end
+
# Imports
require 'rubygems'
require 'logger'
require 'yaml'
require 'json'
@@ -19,11 +36,11 @@
# Ardtweeno::Packet Communication storage class for the Ardtweeno system
#
class Packet
# Class fields
- attr_accessor :key, :seqNo, :date, :hour, :minute, :node, :data
+ attr_accessor :key, :seqNo, :date, :hour, :minute, :second, :node, :data
##
# Ardtweeno::Packet#new for the Packet class
# * *Args* :
# - ++ -> :seqNo, :key, :data
@@ -39,10 +56,11 @@
# 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"
@@ -66,11 +84,11 @@
# * *Raises* :
#
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
+ " " + @hour + ":" + @minute + ":" + @second + " Data: " + @data.to_s
# Returns the built string
return str
end
@@ -85,10 +103,10 @@
# * *Raises* :
#
def to_json(options={})
jsonStr = '{"date":"' + @date + '","hour":"' + @hour + '","minute":"' +
- @minute.to_s + '","node":"' + @node + '","key":"' + @key + '","seqNo":' +
+ @minute + '","second":"' + @second + '","node":"' + @node + '","key":"' + @key + '","seqNo":' +
@seqNo.to_s + ',"data":' + @data.to_json + '}'
return jsonStr
end