Module: SonyCameraRemoteAPI::Scripts

Included in:
Client::Main, Client::ShelfCmd
Defined in:
lib/sony_camera_remote_api/scripts.rb

Overview

Helper module for connecting to camera by wi-fi.

Class Method Summary collapse

Class Method Details

.connect(ssid, pass, interface) ⇒ Boolean

Connects to camera by Wi-Fi. This method does nothing if already connected, which is judged by ifconfig command.

Parameters:

  • interface (String)

    Interface name, e.g. wlan0

  • ssid (String)

    SSID of the camera to connect

  • pass (String)

    Password of the camera to connect

Returns:

  • (Boolean)

    true if succeeded, false otherwise.



15
16
17
# File 'lib/sony_camera_remote_api/scripts.rb', line 15

def connect(ssid, pass, interface)
  run_external_command "sudo bash #{connection_script} #{ssid} #{pass} #{interface}"
end

.connection_scriptObject

Full path of connection script



60
61
62
# File 'lib/sony_camera_remote_api/scripts.rb', line 60

def connection_script
  File.join path, 'connect.sh'
end

.pathObject

Path where scripts are located



55
56
57
# File 'lib/sony_camera_remote_api/scripts.rb', line 55

def path
  File.join root, 'scripts'
end

.restart_and_connect(ssid, pass, interface) ⇒ Boolean

Restart the interface and connect to camera by Wi-Fi.

Parameters:

  • interface (String)

    Interface name, e.g. wlan0

  • ssid (String)

    SSID of the camera to connect

  • pass (String)

    Password of the camera to connect

Returns:

  • (Boolean)

    true if succeeded, false otherwise.



25
26
27
# File 'lib/sony_camera_remote_api/scripts.rb', line 25

def restart_and_connect(ssid, pass, interface)
  run_external_command "sudo bash #{connection_script} -r #{ssid} #{pass} #{interface}"
end

.rootObject

Get gem root path (not smart)



50
51
52
# File 'lib/sony_camera_remote_api/scripts.rb', line 50

def root
  File.expand_path '../../..', __FILE__
end

.run_external_command(command) ⇒ Boolean

Run shell command. Command output are written to stdout witout buffering.

Parameters:

  • command (String)

    Command to execute

Returns:

  • (Boolean)

    true if succeeded, false otherwise.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sony_camera_remote_api/scripts.rb', line 34

def run_external_command(command)
  puts command
  Open3.popen2e(command) do |_i, oe, w|
    oe.each do |line|
      puts line
    end
    # Return code
    if w.value != 0
      return false
    else
      return true
    end
  end
end