lib/ardtweeno/dispatcher.rb in ardtweeno-0.5.0 vs lib/ardtweeno/dispatcher.rb in ardtweeno-0.6.0
- old
+ new
@@ -1,12 +1,29 @@
+=begin
####################################################################################################
# @author David Kirwan https://github.com/davidkirwan/ardtweeno
-# @description Ardtweeno dispatcher system
+# @description Ardtweeno Gateway
#
-# @date 2013-08-18
+# @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 'serialport'
require 'logger'
require 'yaml'
require 'json'
@@ -72,10 +89,28 @@
end
##
+ # Ardtweeno::Dispatcher#constructLineplot method for constructing the line plot graph
+ #
+ # * *Args* :
+ # - ++ ->
+ # * *Returns* :
+ # - Array data containing the 168 hourly packet totals for the last week,
+ # Array of strings containing the names of the last 7 days
+ # * *Raises* :
+ #
+ #
+ def construct_lineplot(params)
+ theData = Ardtweeno::API.buildLineplot(@nodeManager.nodeList, params)
+
+ return theData
+ end
+
+
+ ##
# Ardtweeno::Dispatcher#constructTopology method for constructing the topology graph
#
# * *Args* :
# - ++ -> Hash params, not really used for the moment
# * *Returns* :
@@ -356,11 +391,13 @@
node = @nodeManager.search({:key=>payload["key"]})
@log.debug "This packet belongs to a valid node.."
@log.debug "Constructing a new Ardtweeno::Packet from the payload.."
packet = Ardtweeno::Packet.new(Ardtweeno.nextSeq(), payload["key"], payload["data"])
-
+
+ if packet.data.size > node.sensors.size then raise Ardtweeno::SensorException, "Mismatch between sensors and sensor data counts"; end
+
@log.debug "Adding packet to the node.."
node.enqueue(packet)
@log.debug "Check if its being watched"
if @nodeManager.watched?(node.node)
@@ -494,31 +531,13 @@
@log.debug "SerialParser system is inactive.. ignoring.."
return false
end
-
-
- ##
- # Ardtweeno::Dispatcher#reboot which flushes data then reboots the Ardtweeno Gateway host
- #
- # * *Args* :
- # - ++ ->
- # * *Returns* :
- # -
- # * *Raises* :
- #
- def reboot()
- @log.debug "Dispatcher#reboot has been called, restarting the gateway host.."
-
- cmd = 'ls -l' #'sudo reboot'
- sh "#{cmd}"
- end
-
##
# Ardtweeno::Dispatcher#bootstrap which configures the Dispatcher instance for initial operation
#
# * *Args* :
# - ++ ->
@@ -555,17 +574,17 @@
start = now - (rawdata.size * 10000) # Get the milliseconds from the start of the buffer
rawdata.each do |i|
cpu << [start, i[:cpuload]]
mem << [start, i[:memload]]
- running << [start, i[:running]]
+ if i[:running] then running << [start, 100]; else running << [start, 0]; end
start += 10000
end
cpuseries = {:label=>"CPU %", :data=>cpu, :color=>"#ED0E0E"}
memseries = {:label=>"MEM %", :data=>mem, :color=>"#0E7AED"}
- runningseries = {:label=>"Active", :data=>running}
+ runningseries = {:label=>"Parser Active", :data=>running, :color=>"#088A08"}
return [cpuseries, memseries, runningseries]
rescue Exception => e
raise e