Class: XBee::Frames::Data::Sample

Inherits:
Object
  • Object
show all
Defined in:
lib/xbee/frames/data/sample.rb

Constant Summary collapse

DIGITAL_CHANNELS =

Bit-mapping of digital channel names

[
	:na,
	:na,
	:na,
	:DIO12,
	:DIO11,
	:DIO10,
	:na,
	:na,
	:DIO7,
	:DIO6,
	:DIO5,
	:DIO4,
	:DIO3,
	:DIO2,
	:DIO1,
	:DIO0,
]
ANALOG_CHANNELS =

Bit-mapping of analog channel names

[
	:supply_voltage,
	:na,
	:na,
	:na,
	:AD3,
	:AD2,
	:AD1,
	:AD0,
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parse_bytes:) ⇒ Sample

Parses the input bytes into @digital_values and @analog_values. Consumes the bytes read, so the next sample can be constructed.

Parameters:

  • parse_bytes (Array<Integer>)

    Input data.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/xbee/frames/data/sample.rb', line 47

def initialize(parse_bytes:)
	input = parse_bytes
	@digital_channel_mask = (input.shift << 8) + input.shift
	@analog_channel_mask = input.shift

	@digital_values = {}
	if @digital_channel_mask > 0
		raw = (input.shift << 8) + input.shift
		DIGITAL_CHANNELS.reverse.each_with_index do |channel, index|
			if (@digital_channel_mask & (1 << index)) > 0
				@digital_values[channel] = (raw & (1 << index)) > 0 ? 1 : 0
			end
		end
	end

	@analog_values = {}
	ANALOG_CHANNELS.reverse.each_with_index do |channel, index|
		if (@analog_channel_mask & (1 << index)) > 0
			@analog_values[channel] = (input.shift << 8) + input.shift
		end
	end
end

Instance Attribute Details

#analog_valuesObject (readonly)

Returns the value of attribute analog_values.



41
42
43
# File 'lib/xbee/frames/data/sample.rb', line 41

def analog_values
  @analog_values
end

#digital_valuesObject (readonly)

Returns the value of attribute digital_values.



40
41
42
# File 'lib/xbee/frames/data/sample.rb', line 40

def digital_values
  @digital_values
end