class XBee::Frames::Frame

Attributes

packet[R]
XBee::Packet

if this frame was received, it'll belong to a Packet. (Frames prepped for transmit have no Packet association.)

Public Class Methods

api_id(byte) click to toggle source

Registers the frame type

# File lib/xbee/frames/frame.rb, line 19
def api_id(byte)
        @@frame_types ||= {}
        raise "Attempted to redefine API ID #{byte.inspect}" if @@frame_types.has_key? byte
        @@frame_types[byte] = self

        define_singleton_method(:frame_type) do
                byte
        end

        define_method(:frame_type) do
                byte
        end
end
from_packet(packet) click to toggle source
# File lib/xbee/frames/frame.rb, line 34
def from_packet(packet)
        raise Exceptions::UnknownFrameType, packet unless @@frame_types.has_key? packet.data[0]
        @@frame_types[packet.data[0]].new packet: packet
end
new(packet: nil) click to toggle source

Subclasses should shift +@parse_bytes+ as necessary to get their data fields.

# File lib/xbee/frames/frame.rb, line 45
def initialize(packet: nil)
        logger.trace 'Initializing...', packet: packet
        @packet = packet
        if packet
                @parse_bytes = packet.data.dup
                @frame_type = @parse_bytes.shift
        end
end

Public Instance Methods

bytes() click to toggle source
# File lib/xbee/frames/frame.rb, line 55
def bytes
        [frame_type]
end
to_packet() click to toggle source
# File lib/xbee/frames/frame.rb, line 60
def to_packet
        @packet = Packet.new bytes
end