lignite 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8074515f5e1914a0a56146c77bd2a6119d225e47
4
- data.tar.gz: bdcddbb0e36882d3c6f13b1886d120777fabc301
3
+ metadata.gz: 69c552fbf1d67d88480d8d1ffd3909ea41eebadf
4
+ data.tar.gz: c53de990e8d76b4960bfa8157f5aabb14c652fbf
5
5
  SHA512:
6
- metadata.gz: 021fdf25c04f71348c3a66c88d18d100e7581f649c13e45838f47e282d2c003e1f959876b6fc0c6532f8a0d9d4e12c0b1e9bce3c3c5457356ab8d15409a0a7fc
7
- data.tar.gz: c0967937b3ce7af363bc5ee23de719989edc5b3a5f7f957bf3476f52781f2e722497decc0e96d67a1eea5db7058e9ccdcc9222af663df50677fce3dd4e02c977
6
+ metadata.gz: fb091ed264555daa9ea360e59cd3c27b097710d4d0f33105445a83d2640d8259a19f83e40cdd9625dd52588606a36a47f721384e2511b3ccf92b2dc5202b0fb2
7
+ data.tar.gz: 865cb7e2dadc5614708fde9aa728f7b9af07b78c5e0de4ac1642480c344026d986356a4500980ed24f15e449fefc534fb6aa69dd5b650c74f1c0da8c469a5aa8
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/bin/ev3tool CHANGED
@@ -3,6 +3,11 @@ require "lignite"
3
3
  require "fileutils"
4
4
  include Lignite::Bytes
5
5
 
6
+ # The VM current working directory is /home/root/lms2012/sys
7
+ # which is not very useful. A better default is /home/root/lms2012/prjs
8
+ # which is displayed on the 2nd tab of the brick UI.
9
+ EV3TOOL_HOME = "../prjs"
10
+
6
11
  def phandles
7
12
  handles = $sc.list_open_handles
8
13
  puts "OPEN HANDLES: ", hexdump(handles)
@@ -12,7 +17,7 @@ def upload(local_filename, brick_filename = nil)
12
17
  data = File.read(local_filename, encoding: Encoding::BINARY)
13
18
  unless brick_filename
14
19
  prj = File.basename(local_filename, ".rbf")
15
- brick_filename = "../prjs/#{prj}/#{prj}.rbf"
20
+ brick_filename = "#{EV3TOOL_HOME}/#{prj}/#{prj}.rbf"
16
21
  end
17
22
  handle = $sc.begin_download(data.bytesize, brick_filename)
18
23
  $sc.continue_download(handle, data)
@@ -32,7 +37,11 @@ def download(brick_filename, local_filename = nil)
32
37
  end
33
38
 
34
39
  def list_files(name)
35
- name ||= "../prjs"
40
+ name ||= EV3TOOL_HOME
41
+ unless name.start_with?("/")
42
+ name = "#{EV3TOOL_HOME}/#{name}"
43
+ end
44
+
36
45
  result = ""
37
46
  fsize, handle, data = $sc.list_files(4096, name)
38
47
  loop do
@@ -42,9 +51,44 @@ def list_files(name)
42
51
  handle, data = $sc.continue_list_files(handle, 4096)
43
52
  end
44
53
  result
54
+ rescue Lignite::VMError
55
+ nil
56
+ end
57
+
58
+ def ls(name)
59
+ raw = list_files(name)
60
+ return nil if raw.nil?
61
+
62
+ raw.lines.map do |l|
63
+ l = l.chomp
64
+ next nil if l == "./" || l == "../"
65
+ next l if l.end_with?("/")
66
+ # skip checksum + space + size + space
67
+ l[32 + 1 + 8 + 1 .. -1]
68
+ end.compact
69
+ end
70
+
71
+ def file_exist?(name)
72
+ dirname = File.dirname(name)
73
+ filename = File.basename(name)
74
+ files = ls(dirname) || []
75
+ files.include?(filename)
45
76
  end
46
77
 
47
78
  def run(name)
79
+ if name.include?("/")
80
+ unless name.start_with?("/")
81
+ name = "#{EV3TOOL_HOME}/#{name}"
82
+ end
83
+ else
84
+ name = "#{EV3TOOL_HOME}/#{name}/#{name}.rbf"
85
+ end
86
+
87
+ unless file_exist?(name)
88
+ $stderr.puts "File #{name.inspect} not found"
89
+ exit 1
90
+ end
91
+
48
92
  slot = Lignite::USER_SLOT
49
93
  no_debug = 0
50
94
  $dc.block do
@@ -56,6 +100,10 @@ def run(name)
56
100
  end
57
101
  end
58
102
 
103
+ def stop
104
+ $dc.program_stop(Lignite::USER_SLOT)
105
+ end
106
+
59
107
  def assisted_connection
60
108
  Lignite::Connection.create
61
109
  rescue => e
@@ -86,7 +134,11 @@ when "upload", "ul"
86
134
  when "download", "dl"
87
135
  download(ARGV[1], ARGV[2])
88
136
  when "list", "ls"
89
- print list_files(ARGV[1])
137
+ puts ls(ARGV[1])
138
+ when "ls-l"
139
+ puts list_files(ARGV[1])
90
140
  when "run"
91
141
  run(ARGV[1])
142
+ when "stop"
143
+ stop
92
144
  end
@@ -13,9 +13,13 @@ module Lignite
13
13
  channel = 1
14
14
  sockaddr = [AF_BLUETOOTH, 0, *addr_b.reverse, channel, 0].pack("C*")
15
15
  # common exceptions:
16
- # "Errno::EHOSTUNREACH: No route to host": BT is disabled;
17
- # use `hciconfig hci0 up`
18
- # "Errno::EHOSTDOWN: Host is down": Turn the brick on, enable BT
16
+ # "Errno::EHOSTUNREACH: No route to host":
17
+ # - No BT adapter
18
+ # - BT is disabled; use `hciconfig hci0 up`
19
+ # "Errno::EHOSTDOWN: Host is down":
20
+ # - Turn the brick on
21
+ # - enable BT on the brick
22
+ # - disconnect other programming apps
19
23
  @sock.connect(sockaddr)
20
24
  end
21
25
 
@@ -1,4 +1,6 @@
1
1
  module Lignite
2
+ class VMError < RuntimeError
3
+ end
2
4
 
3
5
  # FIXME: Possibly merge with Connection (UsbConnection)
4
6
  class MessageSender
@@ -26,7 +28,7 @@ module Lignite
26
28
  reply = Message.reply_from_bytes(receive)
27
29
  assert_match(reply.msgid, cmd.msgid, "Reply id")
28
30
  if reply.error?
29
- raise "VMError" # no details?
31
+ raise VMError # no details?
30
32
  end
31
33
 
32
34
  reply.data
@@ -40,7 +42,7 @@ module Lignite
40
42
  assert_match(reply.msgid, cmd.msgid, "Reply id")
41
43
  assert_match(reply.command, unpack_u8(instr_bytes[0]), "Command num")
42
44
  if reply.error?
43
- raise "VMError, %u" % reply.status
45
+ raise VMError, "Error: %u" % reply.status
44
46
  end
45
47
 
46
48
  reply.data
data/spec/spec_helper.rb CHANGED
@@ -10,9 +10,10 @@ end
10
10
 
11
11
  if ENV["COVERAGE"] || ENV["TRAVIS"]
12
12
  require "simplecov"
13
- lib = File.expand_path("../../lib", __FILE__)
14
- # track all ruby files under src
15
- SimpleCov.track_files("#{lib}/**/*.rb")
13
+ top = File.expand_path("../..", __FILE__)
14
+ # track all ruby files under lib
15
+ SimpleCov.track_files("#{top}/lib/**/*.rb")
16
+ SimpleCov.track_files("bin/ev3tool")
16
17
 
17
18
  # use coveralls for on-line code coverage reporting at Travis CI
18
19
  if ENV["TRAVIS"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lignite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Vidner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-19 00:00:00.000000000 Z
11
+ date: 2018-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libusb