lignite 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,94 +15,94 @@ module Lignite
15
15
  # Declare an 8-bit input parameter
16
16
  # @param name [Symbol] parameter name
17
17
  def in8(name)
18
- parameters.param(name, 1, PAR8, IN)
18
+ parameters.param(name, 1, 1, PAR8, IN)
19
19
  end
20
20
 
21
21
  # Declare an 8-bit output parameter
22
22
  # @param name [Symbol] parameter name
23
23
  def out8(name)
24
- parameters.param(name, 1, PAR8, OUT)
24
+ parameters.param(name, 1, 1, PAR8, OUT)
25
25
  end
26
26
 
27
27
  # Declare an 8-bit input+output parameter
28
28
  # @param name [Symbol] parameter name
29
29
  def io8(name)
30
- parameters.param(name, 1, PAR8, IN | OUT)
30
+ parameters.param(name, 1, 1, PAR8, IN | OUT)
31
31
  end
32
32
 
33
33
  # Declare a 16-bit input parameter
34
34
  # @param name [Symbol] parameter name
35
35
  def in16(name)
36
- parameters.param(name, 2, PAR16, IN)
36
+ parameters.param(name, 2, 1, PAR16, IN)
37
37
  end
38
38
 
39
39
  # Declare a 16-bit output parameter
40
40
  # @param name [Symbol] parameter name
41
41
  def out16(name)
42
- parameters.param(name, 2, PAR16, OUT)
42
+ parameters.param(name, 2, 1, PAR16, OUT)
43
43
  end
44
44
 
45
45
  # Declare a 16-bit input+output parameter
46
46
  # @param name [Symbol] parameter name
47
47
  def io16(name)
48
- parameters.param(name, 2, PAR16, IN | OUT)
48
+ parameters.param(name, 2, 1, PAR16, IN | OUT)
49
49
  end
50
50
 
51
51
  # Declare a 32-bit input parameter
52
52
  # @param name [Symbol] parameter name
53
53
  def in32(name)
54
- parameters.param(name, 4, PAR32, IN)
54
+ parameters.param(name, 4, 1, PAR32, IN)
55
55
  end
56
56
 
57
57
  # Declare a 32-bit output parameter
58
58
  # @param name [Symbol] parameter name
59
59
  def out32(name)
60
- parameters.param(name, 4, PAR32, OUT)
60
+ parameters.param(name, 4, 1, PAR32, OUT)
61
61
  end
62
62
 
63
63
  # Declare a 32-bit input+output parameter
64
64
  # @param name [Symbol] parameter name
65
65
  def io32(name)
66
- parameters.param(name, 4, PAR32, IN | OUT)
66
+ parameters.param(name, 4, 1, PAR32, IN | OUT)
67
67
  end
68
68
 
69
69
  # Declare a floating-point input parameter
70
70
  # @param name [Symbol] parameter name
71
71
  def inf(name)
72
- parameters.param(name, 4, PARF, IN)
72
+ parameters.param(name, 4, 1, PARF, IN)
73
73
  end
74
74
 
75
75
  # Declare a floating-point output parameter
76
76
  # @param name [Symbol] parameter name
77
77
  def outf(name)
78
- parameters.param(name, 4, PARF, OUT)
78
+ parameters.param(name, 4, 1, PARF, OUT)
79
79
  end
80
80
 
81
81
  # Declare a floating-point input+output parameter
82
82
  # @param name [Symbol] parameter name
83
83
  def iof(name)
84
- parameters.param(name, 4, PARF, IN | OUT)
84
+ parameters.param(name, 4, 1, PARF, IN | OUT)
85
85
  end
86
86
 
87
87
  # Declare a string input parameter
88
88
  # @param name [Symbol] parameter name
89
89
  # @param size [Integer] maximum string size, including the terminating 0
90
90
  def ins(name, size)
91
- parameters.param(name, size, PARS, IN)
91
+ parameters.param(name, 1, size, PARS, IN)
92
92
  end
93
93
 
94
94
  # Declare a string output parameter
95
95
  # @param name [Symbol] parameter name
96
96
  # @param size [Integer] maximum string size, including the terminating 0
97
97
  def outs(name, size)
98
- parameters.param(name, size, PARS, OUT)
98
+ parameters.param(name, 1, size, PARS, OUT)
99
99
  end
100
100
 
101
101
  # Declare a string input+output parameter
102
102
  # @param name [Symbol] parameter name
103
103
  # @param size [Integer] maximum string size, including the terminating 0
104
104
  def ios(name, size)
105
- parameters.param(name, size, PARS, IN | OUT)
105
+ parameters.param(name, 1, size, PARS, IN | OUT)
106
106
  end
107
107
  end
108
108
  end
@@ -1,8 +1,5 @@
1
1
  module Lignite
2
2
  # Allocate local or global variables
3
- # FIXME: the user can make bad alignment, resulting in VMError at runtime
4
- # bad: data8 :speed; data32 :tacho; output_read(...)
5
- # good data32 :tacho; data8 :speed; output_read(...)
6
3
  class Variables
7
4
  include Bytes
8
5
 
@@ -15,19 +12,27 @@ module Lignite
15
12
  @param_decl_bytes = ""
16
13
  end
17
14
 
18
- # declare
19
- def add(id, size, unpacker)
15
+ # Declare a variable/parameter *id*
16
+ # @param id [Symbol]
17
+ # @param size [Integer] byte size of one element of the data
18
+ # @param count [Integer] 1 for scalars, more for arrays
19
+ # @param unpacker [String] for String#unpack for direct commands
20
+ def add(id, size, count, unpacker)
20
21
  raise "Duplicate variable #{id}" if @vars.key?(id)
21
- @vars[id] = { offset: @offset, size: size }
22
- @offset += size
22
+ @offset = align(@offset, size)
23
+ @vars[id] = { offset: @offset, size: size * count }
24
+ @offset += size * count
23
25
  @unpacker += unpacker
24
26
  end
25
27
 
26
28
  # declare a subroutine parameter
27
- def param(name, size, size_code, direction)
29
+ def param(name, size, count, size_code, direction)
28
30
  raise "Duplicate parameter #{name}" if @vars.key?(name)
31
+ unless @offset == align(@offset, size)
32
+ raise "Misaligned parameter #{name} of size #{size} at #{@offset}"
33
+ end
29
34
  nonsense_unpacker = "," # FIXME: better
30
- add(name, size, nonsense_unpacker)
35
+ add(name, size, count, nonsense_unpacker)
31
36
 
32
37
  @param_count += 1
33
38
  @param_decl_bytes += u8(size_code | direction)
@@ -57,32 +62,39 @@ module Lignite
57
62
  values = buf.unpack(@unpacker)
58
63
  values.size == 1 ? values.first : values
59
64
  end
65
+
66
+ private
67
+
68
+ # Round *n* up to a next multiple of *size*
69
+ def align(n, size)
70
+ (n + size - 1).div(size) * size
71
+ end
60
72
  end
61
73
 
62
74
  # `variables` are {Variables}
63
75
  module VariableDeclarer
64
76
  def data8(id)
65
- variables.add(id, 1, "C")
77
+ variables.add(id, 1, 1, "C")
66
78
  end
67
79
 
68
80
  def data16(id)
69
- variables.add(id, 2, "S<")
81
+ variables.add(id, 2, 1, "S<")
70
82
  end
71
83
 
72
84
  def data32(id)
73
- variables.add(id, 4, "L<")
85
+ variables.add(id, 4, 1, "L<")
74
86
  end
75
87
 
76
88
  def dataf(id)
77
- variables.add(id, 4, "e")
89
+ variables.add(id, 4, 1, "e")
78
90
  end
79
91
 
80
92
  def datas(id, size)
81
- variables.add(id, size, "a#{size}")
93
+ variables.add(id, 1, size, "a#{size}")
82
94
  end
83
95
 
84
96
  def array8(id, count)
85
- variables.add(id, count * 1, "C#{count}")
97
+ variables.add(id, 1, count, "C#{count}")
86
98
  end
87
99
  end
88
100
  end
@@ -33,6 +33,7 @@ TXT
33
33
  "data/lignite-btaddr",
34
34
  "data/sysops.yml",
35
35
  "examples/bobbee.rb",
36
+ "examples/gyro-sensor.rb",
36
37
  "examples/hello.rb",
37
38
  "examples/hello.yml",
38
39
  "examples/light-sensor.rb",
@@ -47,6 +48,7 @@ TXT
47
48
  "lib/lignite/assembler.rb",
48
49
  "lib/lignite/body_compiler.rb",
49
50
  "lib/lignite/bytes.rb",
51
+ "lib/lignite/condition.rb",
50
52
  "lib/lignite/connection.rb",
51
53
  "lib/lignite/connection/bluetooth.rb",
52
54
  "lib/lignite/connection/replay.rb",
@@ -59,6 +61,7 @@ TXT
59
61
  "lib/lignite/enums.rb.erb",
60
62
  "lib/lignite/ev3_ops.rb",
61
63
  "lib/lignite/ev3_tool.rb",
64
+ "lib/lignite/jump_offset.rb",
62
65
  "lib/lignite/logger.rb",
63
66
  "lib/lignite/message.rb",
64
67
  "lib/lignite/motors.rb",
@@ -1,6 +1,6 @@
1
1
  vmthread :MAIN do
2
- ui_draw_fillwindow(0x00, 0, 0)
3
- ui_draw_text(1, 10, 50, "Hello, world!")
2
+ ui_draw_fillwindow(BG_COLOR, 0, 0)
3
+ ui_draw_text(FG_COLOR, 10, 50, "Hello, world!")
4
4
  ui_draw_update
5
5
  ui_button_wait_for_press
6
6
  end
@@ -437,7 +437,7 @@ sub :Test_JR do
437
437
 
438
438
  loop_while lambda {
439
439
  # TEST ***********************************************
440
- jr(Complex(0, 2))
440
+ jr(0)
441
441
  # ****************************************************
442
442
  add32(1, :Counter, :Counter)
443
443
  }, Lt32.new(:Counter, TIMES)
Binary file
@@ -1,3 +1,5 @@
1
1
  ---
2
- - SEND: 0100019400102e2e2f70726a732f6576657273746f726d2f6576657273746f726d2e72626600
3
- - RECV: 0100039400a3040000004c45474fa304000065000e0004000000b8000000000000001a0000001a02000000000000000000002202000000000000000000003702000000000000000000004c02000000000000000000005b02000000000000000000006a02000000000000000000008302000000000000000000009c0200000000000000000000e8020000000000000a0000004c0300000000000004000000b60300000000000004000000fa03000000000000040000006e0400000000000000000000821b08841200841300820000820000841c01820000820000842e2e2f617070732f427269636b2050726f6772616d2f4f6e427269636b496d616765313200841101840500823500821900844556335253544f524d0084003000603000617c0462991d00021d000140991d0003812100014005820b0030014a30014b30014c30016364600282380068600e8232008e820000820100487d0948014e3160483000606d488202008215006948820a00820d007d02846f6b004e5194026251960548991d0000003f01443c444d414d821600424a8214009402628472696768740030014a4082030030004a991d00021d0001443c444d644d0a821500424b821300940262846c6566740030014b4082030030004b991d000381210001443c444d684d1b823500424c823300940262842e2e2f617070732f427269636b2050726f6772616d2f4f6e427269636b536f756e6430340030014c4082030030004c0b42638220ff0a300061a30007000a300061b100068164820000830000000000a600060a300061b1000681ce820000830000000000a600060a300061a5000222a500041ea600060a300061a500021ea5000422a600060aae0001816483000000008338040000830000000000a600010aae0001819c83000000008338040000830000000000a600010a300061b00006814b820000830000000000ae0001816483000000008338040000830000000000a60007aa0001ae0001819c83000000008338040000830000000000a60001aa0001a30006000a300161318132484161825700b10006816448830000000000a60006416182430036828a024085404486444161823400194882ffff484161822900b10006816448830000000000a60006416182150036821405408540448644194882ffff48426182d2ff0a300061b10006816482c80083fa00000001a60006aa0006b1000681648238ff83fa00000001a60006aa0006b10006816482c80083fa00000001a60006aa0006b1000681648238ff83fa00000001a60006aa0006a30006008583c80000004086409402628468657900960a30006194026284736e65657a6500b10006819c820000832c01000001a60006aa0006b100068164820000832c01000001a60040a30006000a300061940262846c65667400968583c8000000408640b0000681328238ff835e01000001a60006aa00068583c800000040864094026284726967687400968583c8000000408640b00006813282c80083c201000001a60006aa0006b0000681328238ff839600000001a60006aa0006a30006000a300061a3000f00940262842e2e2f617070732f427269636b2050726f6772616d2f4f6e427269636b536f756e64313100963000630a0000000000040000006e0400
2
+ - SEND: 01000194e8032e2e2f70726a732f6576657273746f726d2f6576657273746f726d2e72626600
3
+ - RECV: 0100039400a3040000024c45474fa304000065000e0004000000b8000000000000001a0000001a02000000000000000000002202000000000000000000003702000000000000000000004c02000000000000000000005b02000000000000000000006a02000000000000000000008302000000000000000000009c0200000000000000000000e8020000000000000a0000004c0300000000000004000000b60300000000000004000000fa03000000000000040000006e0400000000000000000000821b08841200841300820000820000841c01820000820000842e2e2f617070732f427269636b2050726f6772616d2f4f6e427269636b496d616765313200841101840500823500821900844556335253544f524d0084003000603000617c0462991d00021d000140991d0003812100014005820b0030014a30014b30014c30016364600282380068600e8232008e820000820100487d0948014e3160483000606d488202008215006948820a00820d007d02846f6b004e5194026251960548991d0000003f01443c444d414d821600424a8214009402628472696768740030014a4082030030004a991d00021d0001443c444d644d0a821500424b821300940262846c6566740030014b4082030030004b991d000381210001443c444d684d1b823500424c823300940262842e2e2f617070732f427269636b2050726f6772616d2f4f6e427269636b536f756e6430340030014c4082030030004c0b42638220ff0a300061a30007000a300061b100068164820000830000000000a600060a300061b1000681ce820000830000000000a600060a300061a5000222a500041ea600060a300061a500021ea5000422a600060aae0001816483000000008338040000830000000000a600010aae0001819c83000000008338040000830000000000a600010a300061b00006814b820000830000000000ae0001816483000000008338040000830000000000a60007aa0001ae0001819c83000000008338040000830000000000a60001aa0001a30006000a300161318132484161825700b10006816448830000000000a60006416182430036828a024085404486444161823400194882ffff484161822900b10006816448830000000000a60006416182150036821405408540448644194882ffff48426182d2ff0a300061b10006816482c80083fa00000001a60006aa0006b1000681648238ff83fa00000001a60006aa0006b10006816482c80083fa00000001a60006aa0006b1000681648238ff83fa00000001a60006aa0006a30006008583c80000004086409402628468657900960a30006194026284736e65657a6500b10006819c820000832c01000001a60006aa0006b100068164820000832c01000001a600
4
+ - SEND: 0200019502e803
5
+ - RECV: 02000395080206aa0006858332000000408640a30006000a300061940262846c65667400968583c8000000408640b0000681328238ff835e01000001a60006aa00068583c800000040864094026284726967687400968583c8000000408640b00006813282c80083c201000001a60006aa0006b0000681328238ff839600000001a60006aa0006a30006000a300061a3000f00940262842e2e2f617070732f427269636b2050726f6772616d2f4f6e427269636b536f756e64313100963000630a
Binary file
@@ -52,10 +52,13 @@ describe Lignite::Ev3Tool do
52
52
 
53
53
  it "communicates the right thing" do
54
54
  expected_file_contents = File.read("#{datadir}/everstorm.rbf", mode: "rb")
55
+ e1 = expected_file_contents[0...1000]
56
+ e2 = expected_file_contents[1000..-1]
55
57
  f = double("File")
56
58
  expect(File).to receive(:open).with("everstorm.rbf", "w").and_yield(f)
57
59
  allow(File).to receive(:open).and_call_original
58
- expect(f).to receive(:write).with(expected_file_contents)
60
+ expect(f).to receive(:write).with(e1)
61
+ expect(f).to receive(:write).with(e2)
59
62
 
60
63
  expect { subject.download("../prjs/everstorm/everstorm.rbf") }.not_to raise_error
61
64
  end
@@ -93,6 +93,8 @@ def param_handler(par)
93
93
  when "PAR8", "PAR16", "PAR32", "PARF", "PARV"
94
94
  :param_simple
95
95
  when "PARNO"
96
+ :param_n_multiple
97
+ when "PARVALUES"
96
98
  :param_multiple
97
99
  else
98
100
  raise TODO, "Unhandled param type #{par_type}"
@@ -116,10 +118,16 @@ end
116
118
  def rendered_op4(oname, odesc, ovalue, cvalue, params) # rubocop:disable Metrics/MethodLength
117
119
  s = ""
118
120
 
121
+ # (..., PARVALUES, PAR8) means that there is a variable number of parameters
122
+ # of type PAR8. But since we do not check types yet, let's treat that
123
+ # like PARNO, which is a variable number of parameters of unspecified type.
124
+ params = params[0..-2] if params.fetch(-2, {})["type"] == "PARVALUES"
125
+
119
126
  param_handlers = params.map { |par| param_handler(par) }
120
127
 
121
128
  param_names = params.map do |par|
122
- (par["type"] == "PARNO" ? "*" : "") + par["name"].downcase
129
+ star = ["PARNO", "PARVALUES"].include?(par["type"]) ? "*" : ""
130
+ star + par["name"].downcase
123
131
  end
124
132
  param_decl = param_names.join ", "
125
133
  param_decl = "(#{param_decl})" unless param_decl.empty?
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.5.0
4
+ version: 0.6.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-05 00:00:00.000000000 Z
11
+ date: 2018-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libusb
@@ -154,6 +154,7 @@ files:
154
154
  - data/lignite-btaddr
155
155
  - data/sysops.yml
156
156
  - examples/bobbee.rb
157
+ - examples/gyro-sensor.rb
157
158
  - examples/hello.rb
158
159
  - examples/hello.yml
159
160
  - examples/light-sensor.rb
@@ -168,6 +169,7 @@ files:
168
169
  - lib/lignite/assembler.rb
169
170
  - lib/lignite/body_compiler.rb
170
171
  - lib/lignite/bytes.rb
172
+ - lib/lignite/condition.rb
171
173
  - lib/lignite/connection.rb
172
174
  - lib/lignite/connection/bluetooth.rb
173
175
  - lib/lignite/connection/replay.rb
@@ -180,6 +182,7 @@ files:
180
182
  - lib/lignite/enums.rb.erb
181
183
  - lib/lignite/ev3_ops.rb
182
184
  - lib/lignite/ev3_tool.rb
185
+ - lib/lignite/jump_offset.rb
183
186
  - lib/lignite/logger.rb
184
187
  - lib/lignite/message.rb
185
188
  - lib/lignite/motors.rb