Class: Ardtweeno::Node

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, options={})
  @log = Ardtweeno.options[:log] ||= Logger.new(STDOUT)
  @log.level = Ardtweeno.options[:level] ||= Logger::DEBUG
  
  @node = newNode
  @key = newKey
  
  @description = options[:description] ||= "Default Description"
  @version = options[:version] ||= Ardtweeno::VERSION
  @sensors = options[:sensors] ||= Array.new
  
  @packetqueue = Array.new
  
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



49
50
51
# File 'lib/ardtweeno/node.rb', line 49

def description
  @description
end

#keyObject

Returns the value of attribute key.



49
50
51
# File 'lib/ardtweeno/node.rb', line 49

def key
  @key
end

#logObject

Returns the value of attribute log.



49
50
51
# File 'lib/ardtweeno/node.rb', line 49

def log
  @log
end

#nodeObject

Returns the value of attribute node.



49
50
51
# File 'lib/ardtweeno/node.rb', line 49

def node
  @node
end

#packetqueueObject

Returns the value of attribute packetqueue.



49
50
51
# File 'lib/ardtweeno/node.rb', line 49

def packetqueue
  @packetqueue
end

#sensorsObject

Returns the value of attribute sensors.



49
50
51
# File 'lib/ardtweeno/node.rb', line 49

def sensors
  @sensors
end

#versionObject

Returns the value of attribute version.



49
50
51
# File 'lib/ardtweeno/node.rb', line 49

def version
  @version
end

Instance Method Details

#dequeueObject

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_sObject

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