lignite 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -52,7 +52,13 @@ TXT
52
52
  "lib/lignite/connection/replay.rb",
53
53
  "lib/lignite/connection/tap.rb",
54
54
  "lib/lignite/connection/usb.rb",
55
+ "lib/lignite/defines.rb",
56
+ "lib/lignite/defines.rb.erb",
55
57
  "lib/lignite/direct_commands.rb",
58
+ "lib/lignite/enums.rb",
59
+ "lib/lignite/enums.rb.erb",
60
+ "lib/lignite/ev3_ops.rb",
61
+ "lib/lignite/ev3_tool.rb",
56
62
  "lib/lignite/logger.rb",
57
63
  "lib/lignite/message.rb",
58
64
  "lib/lignite/motors.rb",
@@ -79,9 +85,17 @@ TXT
79
85
  "spec/data/VernierReadout.lms",
80
86
  "spec/data/VernierReadout.rb",
81
87
  "spec/data/VernierReadout.rbf",
88
+ "spec/data/ev3tool_download.yml",
89
+ "spec/data/ev3tool_list_files.yml",
90
+ "spec/data/ev3tool_start.yml",
91
+ "spec/data/ev3tool_stop.yml",
92
+ "spec/data/ev3tool_upload.yml",
93
+ "spec/data/everstorm.rbf",
82
94
  "spec/direct_commands_spec.rb",
95
+ "spec/ev3_tool_spec.rb",
83
96
  "spec/spec_helper.rb",
84
- "spec/system_commands_spec.rb"
97
+ "spec/system_commands_spec.rb",
98
+ "tools/ops_from_yml"
85
99
  ]
86
100
 
87
101
  s.executables = s.files.grep(/^bin\//) { |f| File.basename(f) }
@@ -91,8 +105,9 @@ TXT
91
105
  s.add_dependency "thor", "~> 0.19"
92
106
 
93
107
  s.add_development_dependency "coveralls", "~> 0"
94
- s.add_development_dependency "simplecov", "~> 0"
95
108
  s.add_development_dependency "rake", ">= 0", "< 99"
96
109
  s.add_development_dependency "rspec", "~> 3"
110
+ s.add_development_dependency "rubocop", "0.50.0"
111
+ s.add_development_dependency "simplecov", "~> 0"
97
112
  s.add_development_dependency "yard", "~> 0"
98
113
  end
@@ -5,8 +5,6 @@ require "fileutils"
5
5
 
6
6
  describe Lignite::Assembler do
7
7
  shared_examples "compiles" do |base, asm_version|
8
- let(:datadir) { File.expand_path("../data", __FILE__) }
9
-
10
8
  let(:in_rb) { "#{datadir}/#{base}.rb" }
11
9
  let(:actual_rbf) { "#{datadir}/#{base}.out.rbf" }
12
10
  let(:expected_rbf) { "#{datadir}/#{base}.rbf" }
@@ -0,0 +1,3 @@
1
+ ---
2
+ - SEND: 0100019400102e2e2f70726a732f6576657273746f726d2f6576657273746f726d2e72626600
3
+ - RECV: 0100039400a3040000004c45474fa304000065000e0004000000b8000000000000001a0000001a02000000000000000000002202000000000000000000003702000000000000000000004c02000000000000000000005b02000000000000000000006a02000000000000000000008302000000000000000000009c0200000000000000000000e8020000000000000a0000004c0300000000000004000000b60300000000000004000000fa03000000000000040000006e0400000000000000000000821b08841200841300820000820000841c01820000820000842e2e2f617070732f427269636b2050726f6772616d2f4f6e427269636b496d616765313200841101840500823500821900844556335253544f524d0084003000603000617c0462991d00021d000140991d0003812100014005820b0030014a30014b30014c30016364600282380068600e8232008e820000820100487d0948014e3160483000606d488202008215006948820a00820d007d02846f6b004e5194026251960548991d0000003f01443c444d414d821600424a8214009402628472696768740030014a4082030030004a991d00021d0001443c444d644d0a821500424b821300940262846c6566740030014b4082030030004b991d000381210001443c444d684d1b823500424c823300940262842e2e2f617070732f427269636b2050726f6772616d2f4f6e427269636b536f756e6430340030014c4082030030004c0b42638220ff0a300061a30007000a300061b100068164820000830000000000a600060a300061b1000681ce820000830000000000a600060a300061a5000222a500041ea600060a300061a500021ea5000422a600060aae0001816483000000008338040000830000000000a600010aae0001819c83000000008338040000830000000000a600010a300061b00006814b820000830000000000ae0001816483000000008338040000830000000000a60007aa0001ae0001819c83000000008338040000830000000000a60001aa0001a30006000a300161318132484161825700b10006816448830000000000a60006416182430036828a024085404486444161823400194882ffff484161822900b10006816448830000000000a60006416182150036821405408540448644194882ffff48426182d2ff0a300061b10006816482c80083fa00000001a60006aa0006b1000681648238ff83fa00000001a60006aa0006b10006816482c80083fa00000001a60006aa0006b1000681648238ff83fa00000001a60006aa0006a30006008583c80000004086409402628468657900960a30006194026284736e65657a6500b10006819c820000832c01000001a60006aa0006b100068164820000832c01000001a60040a30006000a300061940262846c65667400968583c8000000408640b0000681328238ff835e01000001a60006aa00068583c800000040864094026284726967687400968583c8000000408640b00006813282c80083c201000001a60006aa0006b0000681328238ff839600000001a60006aa0006a30006000a300061a3000f00940262842e2e2f617070732f427269636b2050726f6772616d2f4f6e427269636b536f756e64313100963000630a0000000000040000006e0400
@@ -0,0 +1,3 @@
1
+ ---
2
+ - SEND: 0100019900102e2e2f70726a732f6576657273746f726d00
3
+ - RECV: 010003990871010000003643413332454336363238354146383733443036453635354435373538304237203030303030344133206576657273746f726d2e7262660a353444464136454132353838303633394645343533454438414234424638413720303030303135334320736e65657a652e7273660a4636333133324538394331354433414346334432373737343639314132383134203030303031303041206865792e7273660a45314631454635413639443544424345313938304246304530374646363733442030303030313334432072696768742e7273660a3631384538383446334145423834314332354241374136463336333831384246203030303031444439206f6b302e7273660a4334333637354536383843384334343138364343444446393239353234423230203030303031354538206f6b312e7273660a4641373044304532303532413342384136413636353136454335313741314644203030303031424243206c6566742e7273660a2e2e2f0a2e2f0a
@@ -0,0 +1,4 @@
1
+ ---
2
+ - SEND: 0100019900102e2e2f70726a732f2e2e2f70726a732f6576657273746f726d00
3
+ - RECV: 010003990871010000003643413332454336363238354146383733443036453635354435373538304237203030303030344133206576657273746f726d2e7262660a353444464136454132353838303633394645343533454438414234424638413720303030303135334320736e65657a652e7273660a4636333133324538394331354433414346334432373737343639314132383134203030303031303041206865792e7273660a45314631454635413639443544424345313938304246304530374646363733442030303030313334432072696768742e7273660a3631384538383446334145423834314332354241374136463336333831384246203030303031444439206f6b302e7273660a4334333637354536383843384334343138364343444446393239353234423230203030303031354538206f6b312e7273660a4641373044304532303532413342384136413636353136454335313741314644203030303031424243206c6566742e7273660a2e2e2f0a2e2f0a
4
+ - SEND: 0200800020c00801802e2e2f70726a732f6576657273746f726d2f6576657273746f726d2e7262660040440301404400
@@ -0,0 +1,2 @@
1
+ ---
2
+ - SEND: 01008000000201
@@ -0,0 +1,5 @@
1
+ ---
2
+ - SEND: 010001923b0000002e2e2f70726a732f48656c6c6f576f726c642f48656c6c6f576f726c642e72626600
3
+ - RECV: 010003920000
4
+ - SEND: 02000193004c45474f3b0000006d000100000000001c000000000000000000000084130000008405010a81328048656c6c6f2c20776f726c642100840083030a
5
+ - RECV: 020003930800
Binary file
@@ -16,6 +16,7 @@ describe Lignite::DirectCommands do
16
16
  allow_any_instance_of(Lignite::DirectCommands).to receive(:sleep)
17
17
  ENV["LIGNITE_REPLAY"] = replay_yml
18
18
  expect { load(script) }.not_to raise_error
19
+ ENV["LIGNITE_REPLAY"] = nil
19
20
  end
20
21
  end
21
22
 
@@ -0,0 +1,71 @@
1
+ require_relative "spec_helper"
2
+ require "lignite/ev3_tool"
3
+
4
+ require "fileutils"
5
+
6
+ describe Lignite::Ev3Tool do
7
+ around(:each) do |example|
8
+ ENV["LIGNITE_REPLAY"] = replay
9
+ example.call
10
+ subject.close
11
+ ENV["LIGNITE_REPLAY"] = nil
12
+ end
13
+
14
+ before(:each) { Lignite::Message.reset_msgid }
15
+
16
+ describe "#raw_ls" do
17
+ let(:replay) { "#{datadir}/ev3tool_list_files.yml" }
18
+
19
+ it "communicates and returns the right thing" do
20
+ expected = [
21
+ "everstorm.rbf",
22
+ "sneeze.rsf",
23
+ "hey.rsf",
24
+ "right.rsf",
25
+ "ok0.rsf",
26
+ "ok1.rsf",
27
+ "left.rsf"
28
+ ]
29
+
30
+ expect(subject.raw_ls("everstorm")).to eq(expected)
31
+ end
32
+ end
33
+
34
+ describe "#start" do
35
+ let(:replay) { "#{datadir}/ev3tool_start.yml" }
36
+
37
+ it "communicates the right thing" do
38
+ expect { subject.start("everstorm") }.not_to raise_error
39
+ end
40
+ end
41
+
42
+ describe "#stop" do
43
+ let(:replay) { "#{datadir}/ev3tool_stop.yml" }
44
+
45
+ it "communicates the right thing" do
46
+ expect { subject.stop }.not_to raise_error
47
+ end
48
+ end
49
+
50
+ describe "#download" do
51
+ let(:replay) { "#{datadir}/ev3tool_download.yml" }
52
+
53
+ it "communicates the right thing" do
54
+ expected_file_contents = File.read("#{datadir}/everstorm.rbf", mode: "rb")
55
+ f = double("File")
56
+ expect(File).to receive(:open).with("everstorm.rbf", "w").and_yield(f)
57
+ allow(File).to receive(:open).and_call_original
58
+ expect(f).to receive(:write).with(expected_file_contents)
59
+
60
+ expect { subject.download("../prjs/everstorm/everstorm.rbf") }.not_to raise_error
61
+ end
62
+ end
63
+
64
+ describe "#upload" do
65
+ let(:replay) { "#{datadir}/ev3tool_upload.yml" }
66
+
67
+ it "communicates the right thing" do
68
+ expect { subject.upload("#{datadir}/HelloWorld.rbf") }.not_to raise_error
69
+ end
70
+ end
71
+ end
@@ -13,7 +13,8 @@ if ENV["COVERAGE"] || ENV["TRAVIS"]
13
13
  top = File.expand_path("../..", __FILE__)
14
14
  # track all ruby files under lib
15
15
  SimpleCov.track_files("#{top}/lib/**/*.rb")
16
- SimpleCov.track_files("bin/ev3tool")
16
+ # filter out the huge generated file
17
+ SimpleCov.add_filter("ev3_ops.rb")
17
18
 
18
19
  # use coveralls for on-line code coverage reporting at Travis CI
19
20
  if ENV["TRAVIS"]
@@ -25,3 +26,7 @@ if ENV["COVERAGE"] || ENV["TRAVIS"]
25
26
  end
26
27
  SimpleCov.start
27
28
  end
29
+
30
+ def datadir
31
+ File.expand_path("../data", __FILE__)
32
+ end
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/ruby
2
+ require "yaml"
3
+ require "erb"
4
+
5
+ class TODO < RuntimeError
6
+ end
7
+
8
+ def load_const(name, value, desc)
9
+ " # #{desc.to_s.chomp}\n" \
10
+ " Lignite::#{name} = #{value.inspect}\n\n"
11
+ end
12
+
13
+ def rendered_file(yml_hash)
14
+ op_hash = yml_hash["ops"]
15
+
16
+ result = <<RUBY
17
+ # This file is generated from ev3.yml. DO NOT EDIT.
18
+
19
+ module Lignite
20
+ # Bytecodes implemented by EV3
21
+ module Ev3Ops
22
+ #{rendered_ops(op_hash).chomp}
23
+ end
24
+ end
25
+ RUBY
26
+ result
27
+ end
28
+
29
+ # @return [String] Ruby code
30
+ def rendered_ops(op_hash)
31
+ ss = op_hash.map do |oname, odata|
32
+ rendered_op2(oname, odata)
33
+ end
34
+ ss.join "\n"
35
+ end
36
+
37
+ # @param oname [String] "PROGRAM_STOP"
38
+ # @return [String] Ruby code
39
+ def rendered_op2(oname, odata)
40
+ ovalue = odata["value"]
41
+ oparams = odata["params"]
42
+ p1 = oparams.first
43
+ if p1 && p1["type"] == "SUBP"
44
+ commands = p1["commands"]
45
+ s = ""
46
+ commands.each do |cname, cdata|
47
+ cdesc = cdata["desc"]
48
+ cvalue = cdata["value"]
49
+ s << load_const(cname, cvalue, cdesc)
50
+ cparams = cdata["params"]
51
+ s << rendered_op4("#{oname}_#{cname}".downcase, cdesc, ovalue, cvalue, cparams)
52
+ end
53
+ s << rendered_multiop(oname, commands)
54
+ s
55
+ else
56
+ rendered_op4(oname.downcase, odata["desc"], ovalue, nil, oparams)
57
+ end
58
+ end
59
+
60
+ # @return [String] Ruby code
61
+ def rendered_multiop(oname, commands)
62
+ names = commands.map do |cname, cdata|
63
+ csym = cname.downcase.to_sym
64
+ cvalue = cdata["value"]
65
+ [cvalue, csym]
66
+ end.to_h
67
+
68
+ osym = oname.downcase.to_sym
69
+
70
+ multiplex_values = names.map do |cvalue, csym|
71
+ " #{cvalue} => #{csym.inspect},\n"
72
+ end
73
+
74
+ result = <<RUBY
75
+
76
+ MULTIPLEX_#{oname} = {
77
+ #{multiplex_values.join("").chomp}
78
+ }.freeze
79
+
80
+ def #{osym}(*args)
81
+ logger.debug "called #{osym} with \#{args.inspect}"
82
+ cvalue = args.shift
83
+ csym = MULTIPLEX_#{oname}.fetch(cvalue)
84
+ __send__("#{osym}_\#{csym}", *args)
85
+ end
86
+ RUBY
87
+ result
88
+ end
89
+
90
+ def param_handler(par)
91
+ par_type = par["type"]
92
+ case par_type
93
+ when "PAR8", "PAR16", "PAR32", "PARF"
94
+ :param_simple
95
+ when "PARNO"
96
+ :param_multiple
97
+ else
98
+ raise TODO, "Unhandled param type #{par_type}"
99
+ end
100
+ end
101
+
102
+ # @return [String] Ruby code
103
+ def method_docs(odesc, params)
104
+ ss = params.map do |p|
105
+ n = p["name"].downcase
106
+ t = p["type"]
107
+ " # @param #{n} [#{t}] (#{p["dir"]}) #{p["desc"]}\n"
108
+ end
109
+ " # #{odesc.to_s.chomp}\n" + ss.join("")
110
+ end
111
+
112
+ # @param oname [String] "move32_32"
113
+ # @param ovalue [Integer] 0x3A
114
+ # @param cvalue [Integer,nil]
115
+ # @return [String] Ruby code
116
+ def rendered_op4(oname, odesc, ovalue, cvalue, params) # rubocop:disable Metrics/MethodLength
117
+ s = ""
118
+
119
+ param_handlers = params.map { |par| param_handler(par) }
120
+
121
+ param_names = params.map do |par|
122
+ (par["type"] == "PARNO" ? "*" : "") + par["name"].downcase
123
+ end
124
+ param_decl = param_names.join ", "
125
+ param_decl = "(#{param_decl})" unless param_decl.empty?
126
+
127
+ s << method_docs(odesc, params)
128
+ s << <<RUBY
129
+ def #{oname}#{param_decl}
130
+ logger.debug do
131
+ args = [#{param_names.join ", "}]
132
+ "called #{oname} with \#{args.inspect}"
133
+ end
134
+
135
+ bytes = u8(#{format("0x%02X", ovalue)})
136
+ RUBY
137
+ s << " bytes += param_simple(#{cvalue})\n" unless cvalue.nil?
138
+ param_names.zip(param_handlers).each do |pname, phand|
139
+ s << " bytes += #{phand}(#{pname})\n"
140
+ end
141
+ s << <<RUBY
142
+ logger.debug "returning bytecode: \#{bytes.inspect}"
143
+ bytes
144
+ end
145
+ RUBY
146
+ s
147
+ rescue TODO => e
148
+ " # Could not define #{oname}: #{e.message}\n"
149
+ end
150
+
151
+ def whitespace_cleanup(s)
152
+ s.lines.map(&:rstrip).join("\n") + "\n"
153
+ end
154
+
155
+ def render_erb_file(erb_filename, a_binding)
156
+ safe = nil
157
+ trim = "<>-"
158
+ erb = ERB.new(File.read(erb_filename), safe, trim)
159
+ out_filename = erb_filename.sub(/\.erb$/, "")
160
+ header = "# This file is generated from its .erb template. DO NOT EDIT.\n\n"
161
+ rendered = erb.result(a_binding)
162
+ rendered = whitespace_cleanup(rendered)
163
+ File.write(out_filename, header + rendered)
164
+ end
165
+
166
+ # run this via "rake ops"
167
+ yml = YAML.load_file(ARGV[0])
168
+ out_fn = ARGV[1]
169
+
170
+ rendered = rendered_file(yml)
171
+ rendered = whitespace_cleanup(rendered)
172
+ File.write(out_fn, rendered)
173
+
174
+ libdir = File.expand_path("..", out_fn)
175
+ render_erb_file("#{libdir}/defines.rb.erb", binding)
176
+ render_erb_file("#{libdir}/enums.rb.erb", binding)
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.3.0
4
+ version: 0.4.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-03-02 00:00:00.000000000 Z
11
+ date: 2018-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libusb
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: simplecov
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rake
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +86,34 @@ dependencies:
100
86
  - - "~>"
101
87
  - !ruby/object:Gem::Version
102
88
  version: '3'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '='
94
+ - !ruby/object:Gem::Version
95
+ version: 0.50.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '='
101
+ - !ruby/object:Gem::Version
102
+ version: 0.50.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: simplecov
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
103
117
  - !ruby/object:Gem::Dependency
104
118
  name: yard
105
119
  requirement: !ruby/object:Gem::Requirement
@@ -159,7 +173,13 @@ files:
159
173
  - lib/lignite/connection/replay.rb
160
174
  - lib/lignite/connection/tap.rb
161
175
  - lib/lignite/connection/usb.rb
176
+ - lib/lignite/defines.rb
177
+ - lib/lignite/defines.rb.erb
162
178
  - lib/lignite/direct_commands.rb
179
+ - lib/lignite/enums.rb
180
+ - lib/lignite/enums.rb.erb
181
+ - lib/lignite/ev3_ops.rb
182
+ - lib/lignite/ev3_tool.rb
163
183
  - lib/lignite/logger.rb
164
184
  - lib/lignite/message.rb
165
185
  - lib/lignite/motors.rb
@@ -186,9 +206,17 @@ files:
186
206
  - spec/data/VernierReadout.lms
187
207
  - spec/data/VernierReadout.rb
188
208
  - spec/data/VernierReadout.rbf
209
+ - spec/data/ev3tool_download.yml
210
+ - spec/data/ev3tool_list_files.yml
211
+ - spec/data/ev3tool_start.yml
212
+ - spec/data/ev3tool_stop.yml
213
+ - spec/data/ev3tool_upload.yml
214
+ - spec/data/everstorm.rbf
189
215
  - spec/direct_commands_spec.rb
216
+ - spec/ev3_tool_spec.rb
190
217
  - spec/spec_helper.rb
191
218
  - spec/system_commands_spec.rb
219
+ - tools/ops_from_yml
192
220
  homepage: https://github.com/mvidner/lignite
193
221
  licenses:
194
222
  - GPL-3.0-only