Sha256: b93ebdb05e96657bdc36d920f32c2bd9638c01fff7ffae73d5643a3f9d721db7

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

#!/usr/bin/env ruby
require "lignite"
include Lignite::Bytes

def phandles
  handles = $sc.list_open_handles
  puts "OPEN HANDLES: ", hexdump(handles)
end

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 = "../prjs/#{prj}/#{prj}.rbf"
  end
  handle = $sc.begin_download(data.bytesize, brick_filename)
  $sc.continue_download(handle, data)
end

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

def list_files(name)
  name ||= "../prjs"
  result = ""
  fsize, handle, data = $sc.list_files(4096, name)
  loop do
    result += data
    fsize -= data.bytesize
    break if fsize.zero?
    handle, data = $sc.continue_list_files(handle, 4096)
  end
  result
end

def run(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

$sc = Lignite::SystemCommands.new
$dc = Lignite::DirectCommands.new

case ARGV[0]
when "upload", "ul"
  upload(ARGV[1], ARGV[2])
when "download", "dl"
  download(ARGV[1], ARGV[2])
when "list", "ls"
  print list_files(ARGV[1])
when "run"
  run(ARGV[1])
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lignite-0.1.0 bin/ev3tool