class XBee::Frames::Data::Sample

Constants

ANALOG_CHANNELS

Bit-mapping of analog channel names

DIGITAL_CHANNELS

Bit-mapping of digital channel names

Attributes

analog_values[R]
digital_values[R]

Public Class Methods

new(parse_bytes:) click to toggle source

Parses the input bytes into @digital_values and @analog_values. Consumes the bytes read, so the next sample can be constructed. @param parse_bytes [Array<Integer>] Input data.

# 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