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

#asm(ruby_fn, rbf_fn) ⇒ Object



60
61
62
63
# File 'lib/lignite/ev3_tool.rb', line 60

def asm(ruby_fn, rbf_fn)
  a = Assembler.new
  a.assemble(ruby_fn, rbf_fn)
end

#download(brick_filename, local_filename = nil) ⇒ Object



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

def download(brick_filename, local_filename = nil)
  chunk_size = 1000 # 2000 stalls, 4096 goes out of sync in our code
  local_filename ||= File.basename(brick_filename)
  fsize, handle, data = sc.begin_upload(chunk_size, 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, chunk_size)
    end
  end
end

#list_files(name) ⇒ Object



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

def list_files(name)
  puts raw_list_files(name)
end

#ls(name) ⇒ Object



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

def ls(name)
  puts raw_ls(name)
end

#start(name) ⇒ Object

Raises:

  • (Thor::Error)


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/lignite/ev3_tool.rb', line 108

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



125
126
127
# File 'lib/lignite/ev3_tool.rb', line 125

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