Class: OneWire::Request
- Inherits:
-
Object
- Object
- OneWire::Request
- Includes:
- Constants::Functions
- Defined in:
- lib/one_wire/request.rb
Constant Summary
Constants included from Constants::Functions
Constants::Functions::DIR, Constants::Functions::DIRALL, Constants::Functions::PRESENCE, Constants::Functions::READ, Constants::Functions::WRITE
Instance Method Summary collapse
-
#initialize(socket, type, path, options = {}) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(socket, type, path, options = {}) ⇒ Request
Returns a new instance of Request.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/one_wire/request.rb', line 4 def initialize(socket, type, path, = {}) version = 0 payload = path + "\000" case type when :dir request_type, data_size = DIR, 0 when :dirall request_type, data_size = DIRALL, 0 when :read request_type, data_size = READ, 8192 when :write request_type, data_size = WRITE, [:value].size payload << [:value] << "\000" when :presence request_type, data_size = PRESENCE, 0 end flags = 0x05000000 | 0x00000002 | Constants::Units.const_get(([:units] || Config.units).to_s.upcase) offset = 0 header = [ version, payload.size, request_type, flags, data_size, offset ].pack("NNNNNN") socket.write(header + payload) end |