lignite 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.rubocop.yml +12 -0
- data/NEWS.md +5 -1
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bin/ev3tool +111 -104
- data/examples/bobbee.rb +7 -7
- data/examples/hello.rb +2 -0
- data/examples/hello.yml +4 -0
- data/examples/light-sensor.rb +2 -0
- data/examples/light-sensor.yml +3 -0
- data/examples/lights.rb +7 -7
- data/examples/lights.yml +4 -0
- data/examples/sys_list_files.rb +4 -2
- data/examples/sys_list_files.yml +9 -0
- data/lib/lignite.rb +5 -1
- data/lib/lignite/assembler.rb +6 -6
- data/lib/lignite/body_compiler.rb +4 -0
- data/lib/lignite/connection.rb +59 -1
- data/lib/lignite/connection/bluetooth.rb +7 -1
- data/lib/lignite/connection/replay.rb +57 -0
- data/lib/lignite/connection/tap.rb +45 -0
- data/lib/lignite/connection/usb.rb +10 -7
- data/lib/lignite/direct_commands.rb +56 -5
- data/lib/lignite/message.rb +8 -5
- data/lib/lignite/motors.rb +5 -5
- data/lib/lignite/op_compiler.rb +19 -18
- data/lib/lignite/rbf_object.rb +1 -1
- data/lib/lignite/system_commands.rb +30 -2
- data/lib/lignite/variables.rb +2 -2
- data/lignite.gemspec +14 -4
- data/rubocop-suse.yml +74 -0
- data/spec/connection_usb_spec.rb +42 -0
- data/spec/data/ColorReadout.rb +11 -12
- data/spec/data/HelloWorld-subop.rb +1 -1
- data/spec/data/HelloWorld.rb +1 -1
- data/spec/data/NoDebug.rb +1 -1
- data/spec/data/VernierReadout.rb +4 -4
- data/spec/direct_commands_spec.rb +25 -0
- data/spec/system_commands_spec.rb +22 -0
- metadata +28 -3
- data/lib/lignite/message_sender.rb +0 -94
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
require "lignite"
|
3
|
+
|
4
|
+
require "fileutils"
|
5
|
+
|
6
|
+
describe Lignite::DirectCommands do
|
7
|
+
shared_examples "example runner" do |base|
|
8
|
+
let(:example_dir) { File.expand_path("../../examples", __FILE__) }
|
9
|
+
|
10
|
+
let(:script) { "#{example_dir}/#{base}.rb" }
|
11
|
+
let(:replay_yml) { "#{example_dir}/#{base}.yml" }
|
12
|
+
|
13
|
+
before(:each) { Lignite::Message.reset_msgid }
|
14
|
+
|
15
|
+
it "correctly runs #{base}.rb" do
|
16
|
+
allow_any_instance_of(Lignite::DirectCommands).to receive(:sleep)
|
17
|
+
ENV["LIGNITE_REPLAY"] = replay_yml
|
18
|
+
expect { load(script) }.not_to raise_error
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it_behaves_like "example runner", "hello"
|
23
|
+
it_behaves_like "example runner", "lights"
|
24
|
+
it_behaves_like "example runner", "light-sensor"
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
require "lignite"
|
3
|
+
|
4
|
+
require "fileutils"
|
5
|
+
|
6
|
+
describe Lignite::SystemCommands do
|
7
|
+
shared_examples "example runner" do |base|
|
8
|
+
let(:example_dir) { File.expand_path("../../examples", __FILE__) }
|
9
|
+
|
10
|
+
let(:script) { "#{example_dir}/#{base}.rb" }
|
11
|
+
let(:replay_yml) { "#{example_dir}/#{base}.yml" }
|
12
|
+
|
13
|
+
before(:each) { Lignite::Message.reset_msgid }
|
14
|
+
|
15
|
+
it "correctly runs #{base}.rb" do
|
16
|
+
ENV["LIGNITE_REPLAY"] = replay_yml
|
17
|
+
expect { load(script) }.not_to raise_error
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it_behaves_like "example runner", "sys_list_files"
|
22
|
+
end
|
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.
|
4
|
+
version: 0.3.0
|
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
|
11
|
+
date: 2018-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: libusb
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.19'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.19'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: coveralls
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,6 +125,8 @@ extra_rdoc_files: []
|
|
111
125
|
files:
|
112
126
|
- ".coveralls.yml"
|
113
127
|
- ".gitignore"
|
128
|
+
- ".rspec"
|
129
|
+
- ".rubocop.yml"
|
114
130
|
- ".travis.yml"
|
115
131
|
- ".yardopts"
|
116
132
|
- COPYING
|
@@ -125,22 +141,27 @@ files:
|
|
125
141
|
- data/sysops.yml
|
126
142
|
- examples/bobbee.rb
|
127
143
|
- examples/hello.rb
|
144
|
+
- examples/hello.yml
|
128
145
|
- examples/light-sensor.rb
|
146
|
+
- examples/light-sensor.yml
|
129
147
|
- examples/lights.rb
|
148
|
+
- examples/lights.yml
|
130
149
|
- examples/motors.rb
|
131
150
|
- examples/sound.rb
|
132
151
|
- examples/sys_list_files.rb
|
152
|
+
- examples/sys_list_files.yml
|
133
153
|
- lib/lignite.rb
|
134
154
|
- lib/lignite/assembler.rb
|
135
155
|
- lib/lignite/body_compiler.rb
|
136
156
|
- lib/lignite/bytes.rb
|
137
157
|
- lib/lignite/connection.rb
|
138
158
|
- lib/lignite/connection/bluetooth.rb
|
159
|
+
- lib/lignite/connection/replay.rb
|
160
|
+
- lib/lignite/connection/tap.rb
|
139
161
|
- lib/lignite/connection/usb.rb
|
140
162
|
- lib/lignite/direct_commands.rb
|
141
163
|
- lib/lignite/logger.rb
|
142
164
|
- lib/lignite/message.rb
|
143
|
-
- lib/lignite/message_sender.rb
|
144
165
|
- lib/lignite/motors.rb
|
145
166
|
- lib/lignite/op_compiler.rb
|
146
167
|
- lib/lignite/rbf_object.rb
|
@@ -148,7 +169,9 @@ files:
|
|
148
169
|
- lib/lignite/variables.rb
|
149
170
|
- lib/lignite/version.rb
|
150
171
|
- lignite.gemspec
|
172
|
+
- rubocop-suse.yml
|
151
173
|
- spec/assembler_spec.rb
|
174
|
+
- spec/connection_usb_spec.rb
|
152
175
|
- spec/data/ColorReadout.lms
|
153
176
|
- spec/data/ColorReadout.rb
|
154
177
|
- spec/data/ColorReadout.rbf
|
@@ -163,7 +186,9 @@ files:
|
|
163
186
|
- spec/data/VernierReadout.lms
|
164
187
|
- spec/data/VernierReadout.rb
|
165
188
|
- spec/data/VernierReadout.rbf
|
189
|
+
- spec/direct_commands_spec.rb
|
166
190
|
- spec/spec_helper.rb
|
191
|
+
- spec/system_commands_spec.rb
|
167
192
|
homepage: https://github.com/mvidner/lignite
|
168
193
|
licenses:
|
169
194
|
- GPL-3.0-only
|
@@ -1,94 +0,0 @@
|
|
1
|
-
module Lignite
|
2
|
-
class VMError < RuntimeError
|
3
|
-
end
|
4
|
-
|
5
|
-
# FIXME: Possibly merge with Connection (UsbConnection)
|
6
|
-
class MessageSender
|
7
|
-
include Bytes
|
8
|
-
include Logger
|
9
|
-
|
10
|
-
def initialize(connection)
|
11
|
-
@c = connection
|
12
|
-
@buf = ""
|
13
|
-
end
|
14
|
-
|
15
|
-
def direct_command(instr_bytes, global_size: 0, local_size: 0)
|
16
|
-
body = u16(var_alloc(global_size: global_size, local_size: local_size)) +
|
17
|
-
instr_bytes
|
18
|
-
cmd = Message.direct_command_no_reply(body)
|
19
|
-
send(cmd.bytes)
|
20
|
-
end
|
21
|
-
|
22
|
-
def direct_command_with_reply(instr_bytes, global_size: 0, local_size: 0)
|
23
|
-
body = u16(var_alloc(global_size: global_size, local_size: local_size)) +
|
24
|
-
instr_bytes
|
25
|
-
cmd = Message.direct_command_with_reply(body)
|
26
|
-
send(cmd.bytes)
|
27
|
-
|
28
|
-
reply = Message.reply_from_bytes(receive)
|
29
|
-
assert_match(reply.msgid, cmd.msgid, "Reply id")
|
30
|
-
if reply.error?
|
31
|
-
raise VMError # no details?
|
32
|
-
end
|
33
|
-
|
34
|
-
reply.globals
|
35
|
-
end
|
36
|
-
|
37
|
-
def system_command_with_reply(instr_bytes)
|
38
|
-
cmd = Message.system_command_with_reply(instr_bytes)
|
39
|
-
send(cmd.bytes)
|
40
|
-
|
41
|
-
reply = Message.reply_from_bytes(receive)
|
42
|
-
assert_match(reply.msgid, cmd.msgid, "Reply id")
|
43
|
-
assert_match(reply.command, unpack_u8(instr_bytes[0]), "Command num")
|
44
|
-
if reply.error?
|
45
|
-
raise VMError, "Error: %u" % reply.status
|
46
|
-
end
|
47
|
-
|
48
|
-
reply.data
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def send(payload)
|
54
|
-
packet = u16(payload.bytesize) + payload
|
55
|
-
logger.debug "-> #{packet.inspect}"
|
56
|
-
@c.write(packet)
|
57
|
-
end
|
58
|
-
|
59
|
-
# read must not be called with a too low value :-/
|
60
|
-
def bufread(n)
|
61
|
-
while n > @buf.bytesize
|
62
|
-
@buf += @c.read(10000)
|
63
|
-
end
|
64
|
-
ret = @buf[0, n]
|
65
|
-
@buf = @buf[n..-1]
|
66
|
-
logger.debug "R<-(#{ret.bytesize})#{ret.inspect}"
|
67
|
-
ret
|
68
|
-
end
|
69
|
-
|
70
|
-
def receive
|
71
|
-
size = nil
|
72
|
-
loop do
|
73
|
-
lenbuf = bufread(2)
|
74
|
-
size = unpack_u16(lenbuf)
|
75
|
-
break unless size.zero?
|
76
|
-
# leftover data?
|
77
|
-
@buf = ""
|
78
|
-
end
|
79
|
-
|
80
|
-
res = bufread(size)
|
81
|
-
res
|
82
|
-
end
|
83
|
-
|
84
|
-
def var_alloc(global_size:, local_size:)
|
85
|
-
var_alloc = global_size & 0x3ff
|
86
|
-
var_alloc |= (local_size & 0x3f) << 10
|
87
|
-
end
|
88
|
-
|
89
|
-
def assert_match(actual, expected, description)
|
90
|
-
return if actual == expected
|
91
|
-
raise "#{description} does not match, expected #{expected}, actual #{actual}"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|