Sha256: 8294b79195a4576b1aa5ac947491eee330cbfc0f3b81ca7685f33b4ebb970af8

Contents?: true

Size: 1001 Bytes

Versions: 1

Compression:

Stored size: 1001 Bytes

Contents

module Gom
  class SensorPorts < Gom::Remote::Entry

    Defaults = {
      :interface    => '0.0.0.0',
      :sensor_port  => 76001,
      :mode         => :udp,
    }

    include OAttr
    oattr :interface, :sensor_port, :mode

    def initialize path, options = {}
      @path = path
      @options = Defaults.merge(gnode @path).merge(options)
      puts " -- new sensor port: #{self.inspect}"
    end

    def listen
      puts " -- listen: #{self.inspect}"
      self.send "listen_#{mode}"
    end

    def listen_udp
      socket = UDPSocket.new
      socket.bind(interface, sensor_port)
      loop do
        msg, sender = socket.recvfrom(1024)
        puts "-->#{msg}<-- #{sender.inspect}"
      end
    ensure
      socket.close rescue nil
    end

    def status
      puts @options.inspect
      #t = Net::Telnet::new(
      #  "Host" => device_ip, "Timeout" => 10, "Prompt" => /[$%#>] \z/n
      #)
      #t.login(user, password) { |c| puts c }
      "not implemented"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gom-sensor-ports-0.1.1 lib/gom-sensor-ports/sensor-ports.rb