class Onewire::Client

Constants

DIR
ERROR
NOP
PRESENCE
READ
SIZE
WRITE

Public Class Methods

new(host = 'localhost', port = 4304) click to toggle source
# File lib/onewire/client.rb, line 17
def initialize(host = 'localhost', port = 4304)
  @host, @port = host, port
end

Public Instance Methods

dir(path = '') click to toggle source
# File lib/onewire/client.rb, line 21
def dir(path = '')
  interact do |c|
    c.write DIR, "#{normalize path}\0", 8192

    res = []

    while dir = c.read
      res << dir
    end

    res
  end
end
read(path) click to toggle source
# File lib/onewire/client.rb, line 35
def read(path)
  interact do |c|
    c.write READ, "#{normalize path}\0", 8192 # Default value size to read
    typecast c.read
  end
end
scope(path = '') click to toggle source
# File lib/onewire/client.rb, line 49
def scope(path = '')
  Onewire::Scope.new self, path
end
write(path, value) click to toggle source
# File lib/onewire/client.rb, line 42
def write(path, value)
  interact do |c|
    c.write WRITE, "#{normalize path}\0#{value}\0", value.size
    c.read
  end
end

Private Instance Methods

interact() { |conn| ... } click to toggle source
# File lib/onewire/client.rb, line 63
def interact
  conn = Connection.new(@host, @port)

  begin
    yield conn
  ensure
    conn.close
  end
end
normalize(path) click to toggle source
# File lib/onewire/client.rb, line 55
def normalize(path)
  path.gsub(/\A(?!\/)|\/{2,}/,'/')
end
typecast(val) click to toggle source
# File lib/onewire/client.rb, line 59
def typecast(val)
  Float(val) rescue val
end