Class: Ardtweeno::Node
- Inherits:
-
Object
- Object
- Ardtweeno::Node
- Defined in:
- lib/ardtweeno/node.rb
Overview
Ardtweeno::Node class to model an Ardtweeno mesh network node
Example YAML representation of an Ardtweeno::Node -
name: node0
key: 500d81aafe637717a52f8650e54206e64da33d27
description: This node is outside
version: 0.0.3
sensors:
- Temperature
- Barometric Pressure
- Altitude
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#key ⇒ Object
Returns the value of attribute key.
-
#log ⇒ Object
Returns the value of attribute log.
-
#node ⇒ Object
Returns the value of attribute node.
-
#packetqueue ⇒ Object
Returns the value of attribute packetqueue.
-
#sensors ⇒ Object
Returns the value of attribute sensors.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#dequeue ⇒ Object
Ardtweeno::Node#dequeue stores an Ardtweeno::Packet in the maintained packet list.
-
#enqueue(packet) ⇒ Object
Ardtweeno::Node#enqueue stores an Ardtweeno::Packet in the maintained packet list.
-
#initialize(newNode, newKey, options = {}) ⇒ Node
constructor
Ardtweeno::Node#new Constructor.
-
#to_s ⇒ Object
Ardtweeno::Node#to_s converts a Node instance to String.
Constructor Details
#initialize(newNode, newKey, options = {}) ⇒ Node
Ardtweeno::Node#new Constructor
-
Args :
-
++ -> newNode String, newKey String, options HashString,
-
:version String, :sensors Array
-
Returns : -
-
Raises :
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ardtweeno/node.rb', line 62 def initialize(newNode, newKey, ={}) @log = Ardtweeno.[:log] ||= Logger.new(STDOUT) @log.level = Ardtweeno.[:level] ||= Logger::DEBUG @node = newNode @key = newKey @description = [:description] ||= "Default Description" @version = [:version] ||= Ardtweeno::VERSION @sensors = [:sensors] ||= Array.new @packetqueue = Array.new end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
49 50 51 |
# File 'lib/ardtweeno/node.rb', line 49 def description @description end |
#key ⇒ Object
Returns the value of attribute key.
49 50 51 |
# File 'lib/ardtweeno/node.rb', line 49 def key @key end |
#log ⇒ Object
Returns the value of attribute log.
49 50 51 |
# File 'lib/ardtweeno/node.rb', line 49 def log @log end |
#node ⇒ Object
Returns the value of attribute node.
49 50 51 |
# File 'lib/ardtweeno/node.rb', line 49 def node @node end |
#packetqueue ⇒ Object
Returns the value of attribute packetqueue.
49 50 51 |
# File 'lib/ardtweeno/node.rb', line 49 def packetqueue @packetqueue end |
#sensors ⇒ Object
Returns the value of attribute sensors.
49 50 51 |
# File 'lib/ardtweeno/node.rb', line 49 def sensors @sensors end |
#version ⇒ Object
Returns the value of attribute version.
49 50 51 |
# File 'lib/ardtweeno/node.rb', line 49 def version @version end |
Instance Method Details
#dequeue ⇒ Object
Ardtweeno::Node#dequeue stores an Ardtweeno::Packet in the maintained packet list
-
Args :
-
++ ->
-
-
Returns :
-
Ardtweeno::Packet
-
-
Raises :
-
Ardtweeno::PacketListEmpty
-
110 111 112 113 114 115 116 117 118 |
# File 'lib/ardtweeno/node.rb', line 110 def dequeue() if @packetqueue.empty? raise Ardtweeno::PacketListEmpty else return @packetqueue.delete(@packetqueue.first) end end |
#enqueue(packet) ⇒ Object
Ardtweeno::Node#enqueue stores an Ardtweeno::Packet in the maintained packet list
-
Args :
-
++ -> Ardtweeno::Packet
-
-
Returns :
-
true
-
-
Raises :
-
Ardtweeno::NotAPacket
-
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/ardtweeno/node.rb', line 88 def enqueue(packet) if packet.class == Ardtweeno::Packet packet.node = @node @packetqueue << packet return true else raise Ardtweeno::NotAPacket end end |
#to_s ⇒ Object
Ardtweeno::Node#to_s converts a Node instance to String
-
Args :
-
++ ->
-
-
Returns :
-
String
-
-
Raises :
130 131 132 |
# File 'lib/ardtweeno/node.rb', line 130 def to_s return @node + ", " + @key + ", " + @description + ", " + @version + ", " + @sensors.to_s, @packetqueue.to_s end |