Class: XBee::Frame::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/apimode/frame/frame.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_identifierObject

Returns the value of attribute api_identifier.



113
114
115
# File 'lib/apimode/frame/frame.rb', line 113

def api_identifier
  @api_identifier
end

#cmd_dataObject

Returns the value of attribute cmd_data.



113
114
115
# File 'lib/apimode/frame/frame.rb', line 113

def cmd_data
  @cmd_data
end

#frame_idObject

Returns the value of attribute frame_id.



113
114
115
# File 'lib/apimode/frame/frame.rb', line 113

def frame_id
  @frame_id
end

Instance Method Details

#_dump(api_mode = :API1) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/apimode/frame/frame.rb', line 125

def _dump(api_mode = :API1)
  unless api_mode == :API1 or api_mode == :API2
    raise "XBee api_mode must be either :API1 (non-escaped) or :API2 (escaped, default)"
  end
  raise "Too much data (#{self.length} bytes) to fit into one frame!" if (self.length > 0xFFFF)

  if (api_mode == :API1)
    "~" + [length].pack("n") + data + [Frame.checksum(data)].pack("C")
  elsif (api_mode == :API2)
    "~" + [length].pack("n").xb_escape + data.xb_escape + [Frame.checksum(data)].pack("C")
  end
end

#dataObject



121
122
123
# File 'lib/apimode/frame/frame.rb', line 121

def data
  Array(api_identifier).pack("C") + cmd_data
end

#lengthObject



119
# File 'lib/apimode/frame/frame.rb', line 119

def length ; data.length ; end