Class: XBee::Address64

Inherits:
Address show all
Defined in:
lib/xbee/address_64.rb

Constant Summary collapse

BROADCAST =
new(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff).freeze
COORDINATOR =
new(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00).freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Address

#<=>, #==, #to_a

Constructor Details

#initialize(b1, b2, b3, b4, b5, b6, b7, b8) ⇒ Address64

Returns a new instance of Address64.



6
7
8
# File 'lib/xbee/address_64.rb', line 6

def initialize(b1, b2, b3, b4, b5, b6, b7, b8)
	@bytes = [b1, b2, b3, b4, b5, b6, b7, b8]
end

Class Method Details

.from_array(array) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/xbee/address_64.rb', line 21

def from_array(array)
	if array.length == 8 && array.all? { |x| (0..255).cover? x }
		new *array
	else
		raise ArgumentError, "#{array.inspect} is not a valid 64-bit address array"
	end
end

.from_string(string) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/xbee/address_64.rb', line 12

def from_string(string)
	if (matcher = /^(\h\h)[^\h]*(\h\h)[^\h]*(\h\h)[^\h]*(\h\h)[^\h]*(\h\h)[^\h]*(\h\h)[^\h]*(\h\h)[^\h]*(\h\h)$/.match(string))
		new *(matcher[1..8].map &:hex)
	else
		raise ArgumentError, "#{string.inspect} is not a valid 64-bit address string"
	end
end

Instance Method Details

#to_sObject



32
33
34
# File 'lib/xbee/address_64.rb', line 32

def to_s
	('%02x' * 8) % @bytes
end