Class: Lignite::Ev3Tool

Inherits:
Thor
  • Object
show all
Includes:
Bytes
Defined in:
lib/lignite/ev3_tool.rb

Overview

Implements the ‘ev3tool` command line interface

Constant Summary collapse

EV3TOOL_HOME =

The VM current working directory is /home/root/lms2012/sys which is not very useful. A better default is /home/root/lms2012/prjs which is displayed on the 2nd tab of the brick UI.

"../prjs".freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Bytes

#bin_to_hex, #f32, #hex_to_bin, #u16, #u32, #u8, #unpack_f32, #unpack_u16, #unpack_u32, #unpack_u8

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/lignite/ev3_tool.rb', line 16

def self.exit_on_failure?
  true
end

Instance Method Details

#download(brick_filename, local_filename = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/lignite/ev3_tool.rb', line 34

def download(brick_filename, local_filename = nil)
  local_filename ||= File.basename(brick_filename)
  fsize, handle, data = sc.begin_upload(4096, brick_filename)
  File.open(local_filename, "w") do |f|
    loop do
      f.write(data)
      fsize -= data.bytesize
      break if fsize.zero?
      handle, data = sc.continue_upload(handle, 4096)
    end
  end
end

#list_files(name) ⇒ Object



49
50
51
# File 'lib/lignite/ev3_tool.rb', line 49

def list_files(name)
  puts raw_list_files(name)
end

#ls(name) ⇒ Object



54
55
56
# File 'lib/lignite/ev3_tool.rb', line 54

def ls(name)
  puts raw_ls(name)
end

#start(name) ⇒ Object

Raises:

  • (Thor::Error)


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/lignite/ev3_tool.rb', line 101

def start(name)
  name = runnable_name(name)

  raise Thor::Error, "File #{name.inspect} not found on the brick" unless file_exist?(name)

  slot = Lignite::USER_SLOT
  no_debug = 0
  dc.block do
    # these are local variables
    data32 :size
    data32 :ip
    file_load_image(slot, name, :size, :ip)
    program_start(slot, :size, :ip, no_debug)
  end
end

#stopObject



118
119
120
# File 'lib/lignite/ev3_tool.rb', line 118

def stop
  dc.program_stop(Lignite::USER_SLOT)
end

#upload(local_filename, brick_filename = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/lignite/ev3_tool.rb', line 22

def upload(local_filename, brick_filename = nil)
  data = File.read(local_filename, encoding: Encoding::BINARY)
  unless brick_filename
    prj = File.basename(local_filename, ".rbf")
    brick_filename = "#{EV3TOOL_HOME}/#{prj}/#{prj}.rbf"
  end
  handle = sc.begin_download(data.bytesize, brick_filename)
  sc.continue_download(handle, data)
end