Class: XBee::Frames::Frame
- Inherits:
-
Object
- Object
- XBee::Frames::Frame
- Includes:
- SemanticLogger::Loggable
- Defined in:
- lib/xbee/frames/frame.rb
Direct Known Subclasses
DataSampleRXIndicator, ExplicitRXIndicator, IdentifiedFrame, ModemStatus, ReceivePacket, UnidentifiedAddressedFrame, XBeeSensorReadIndicator
Constant Summary collapse
- @@frame_types =
- <Integer, Frame>
-
Map of frame type IDs to implementation classes
{}
Instance Attribute Summary collapse
-
#packet ⇒ Object
readonly
- XBee::Packet
-
if this frame was received, it’ll belong to a Packet.
Class Method Summary collapse
-
.api_id(byte) ⇒ Object
Registers the frame type.
- .from_packet(packet) ⇒ Object
Instance Method Summary collapse
- #bytes ⇒ Object
-
#initialize(packet: nil) ⇒ Frame
constructor
Subclasses should shift @parse_bytes as necessary to get their data fields.
- #to_packet ⇒ Object
Constructor Details
#initialize(packet: nil) ⇒ Frame
Subclasses should shift @parse_bytes as necessary to get their data fields.
45 46 47 48 49 50 51 52 |
# 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 |
Instance Attribute Details
#packet ⇒ Object (readonly)
- XBee::Packet
-
if this frame was received, it’ll belong to a Packet. (Frames prepped for transmit have no Packet association.)
42 43 44 |
# File 'lib/xbee/frames/frame.rb', line 42 def packet @packet end |
Class Method Details
.api_id(byte) ⇒ Object
Registers the frame type
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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) ⇒ Object
34 35 36 37 |
# 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 |