Class: Hacklet::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/hacklet/command.rb

Class Method Summary collapse

Class Method Details

.run(dongle, arguments) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/hacklet/command.rb', line 6

def self.run(dongle, arguments)
  Slop.parse(arguments, :help => true) do
    command 'on', :banner => 'Turn on the specifed socket' do
      on :n, :network=, 'The network id (ex. 0x1234)', :required => true
      on :s, :socket=, 'The socket id (ex. 0)', :required => true
      on :d, :debug, 'Enables debug logging' do
        dongle.logger.level = Logger::DEBUG
      end

      run do |opts, args|
        network_id = opts[:network][2..-1].to_i(16)
        socket_id = opts[:socket].to_i

        dongle.lock_network
        dongle.select_network(network_id)
        dongle.switch(network_id, socket_id, true)
      end
    end

    command 'off', :banner => 'Turn off the specifed socket' do
      on :n, :network=, 'The network id (ex. 0x1234)', :required => true
      on :s, :socket=, 'The socket id (ex. 0)', :required => true
      on :d, :debug, 'Enables debug logging' do
        dongle.logger.level = Logger::DEBUG
      end

      run do |opts, args|
        network_id = opts[:network][2..-1].to_i(16)
        socket_id = opts[:socket].to_i

        dongle.lock_network
        dongle.select_network(network_id)
        dongle.switch(network_id, socket_id, false)
      end
    end

    command 'read', :banner => 'Read all available samples from the specified socket' do
      on :n, :network=, 'The network id (ex. 0x1234)', :required => true
      on :s, :socket=, 'The socket id (ex. 0)', :required => true
      on :d, :debug, 'Enables debug logging' do
        dongle.logger.level = Logger::DEBUG
      end

      run do |opts, args|
        network_id = opts[:network][2..-1].to_i(16)
        socket_id = opts[:socket].to_i

        dongle.lock_network
        dongle.select_network(network_id)
        dongle.request_samples(network_id, socket_id)
      end
    end

    command 'commission', :banner => 'Add a new device to the network' do
      on :d, :debug, 'Enables debug logging' do
        dongle.logger.level = Logger::DEBUG
      end

      run do |opts, args|
        dongle.commission
      end
    end

    run do
      puts help
    end
  end
end