farmbot-serial 0.0.4 → 0.0.5

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: 11e0f51d8ab86f321618b7624b564390dea98f8a
4
- data.tar.gz: b4ee5f17fc86632387f3bbe853637eed6ee16d60
3
+ metadata.gz: 76fb34947d7e8701118ad070a874e9ccf7318b84
4
+ data.tar.gz: 97a79c5b63f4fe02d4532f5efd24193fd9b2902f
5
5
  SHA512:
6
- metadata.gz: cdaaf0a5772e4c18e1f8236ac9c02af0747150caf715c42e08dd8f506ec8e0795f7268d70997b599f38790ac7beefd4ba1951693433ae96b408d4080e6a50637
7
- data.tar.gz: ad07522eb174172366067978f59979a965d208b4c3b5d4f5b82ebcf87a03a2fb89ba3a94d9f3fef382b92ff811a148d4cd0eca6f0f9fe6ed0d9820324126552d
6
+ metadata.gz: 47c21fdafd0323365b48d24037af53414a7ec65953a66195be9e9a7e2c73c4d366a112ade1d0e86a5c2c0663bb00b81d6c54e8d5d6bb573944e2a4e79cb958c0
7
+ data.tar.gz: c48d82dd75b5be870756af8d2b8c4906416305fe9f27a50aa15c79948a99e34fe191de80504f308198bb4fb21c26a5e1c52b4cf974e2d43ecf9b79321002f3fc
data/README.md CHANGED
@@ -1 +1,20 @@
1
- Under construction.
1
+ # Farmbot-Serial
2
+
3
+ A ruby gem for controlling Farmbot via serial line with EventMachine.
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ bot = FB::Arduino.new # Defaults to '/dev/ttyACM0'
9
+
10
+ EM.run do
11
+ # Register bot with event loop.
12
+ FB::ArduinoEventMachine.connect(bot)
13
+ # Make the bot flinch every 5 seconds...
14
+ FB::ArduinoEventMachine.poll(5) { bot.commands.move_relative(1, 1, 1) }
15
+ # Immediate handling of incoming messages.
16
+ bot.onmessage { |data| puts "Serial message in: #{data}" }
17
+ # Stop event loop if connection closes or serial cable is disconnected
18
+ bot.onclose { EM.stop }
19
+ end
20
+ ```
data/lib/arduino.rb CHANGED
@@ -1,20 +1,16 @@
1
- ## HARDWARE INTERFACE
2
- ## ******************
3
-
4
1
  # Communicate with the arduino using a serial interface
5
- # All information is exchanged using a variation of g-code
6
- # Parameters are stored in the database
7
2
  module FB
8
3
  class Arduino
9
4
  class EmergencyStop < StandardError; end # Not yet used.
10
5
 
11
- attr_reader :serial_port, :logger
6
+ attr_reader :serial_port, :logger, :commands, :queue
12
7
 
13
8
  # Initial and provide a serial object, as well as an IO object to send
14
9
  # log messages to. Default SerialPort is DefaultSerialPort. Default logger
15
10
  # is STDOUT
16
11
  def initialize(serial_port = DefaultSerialPort.new, logger = STDOUT)
17
- @serial_port, @logger = serial_port, logger
12
+ @serial_port, @logger, @queue = serial_port, logger, EM::Queue.new
13
+ @commands = FB::ArduinoCommandSet.new(self)
18
14
  end
19
15
 
20
16
  # Log to screen/file/IO stream
@@ -23,8 +19,16 @@ module FB
23
19
  end
24
20
 
25
21
  # Handle incoming text from arduino into pi
26
- def read(string)
27
- log "RECEIVED #{string}"
22
+ def onmessage(&blk)
23
+ raise 'read() requires a block' unless block_given?
24
+ @queue.pop do |string|
25
+ log "RECEIVED #{string}"
26
+ blk.call(string)
27
+ end
28
+ end
29
+
30
+ def onclose(&blk)
31
+ @onclose = blk
28
32
  end
29
33
 
30
34
  # Send outgoing test to arduino from pi
@@ -36,6 +40,10 @@ module FB
36
40
  # Handle loss of serial connection
37
41
  def disconnect
38
42
  log "Connection to device lost"
43
+ @onclose.call if @onclose
44
+ end
45
+
46
+ def reconnect
39
47
  end
40
48
  end
41
49
  end
@@ -7,8 +7,14 @@ module FB
7
7
  attr_accessor :arduino
8
8
  end
9
9
 
10
+ def self.poll(interval, &blk)
11
+ raise 'You must pass a block' unless block_given?
12
+ EventMachine::PeriodicTimer.new(interval.to_f, &blk)
13
+ end
14
+
15
+ # Gets called when data arrives.
10
16
  def receive_data(data)
11
- self.class.arduino.read(data)
17
+ self.class.arduino.queue.push(data)
12
18
  end
13
19
 
14
20
  # Gets called when the connection breaks.
@@ -16,5 +22,10 @@ module FB
16
22
  self.class.arduino.disconnect
17
23
  EM.stop
18
24
  end
25
+
26
+ def self.connect(arduino)
27
+ @arduino = arduino
28
+ EM.attach arduino.serial_port, self
29
+ end
19
30
  end
20
31
  end
@@ -2,18 +2,19 @@ require 'serialport'
2
2
 
3
3
  # This object creates a Serial IO with sane default, since most FarmBot setups
4
4
  # follow the same serial configuration setup.
5
- class DefaultSerialPort < SerialPort
6
- COM_PORT = '/dev/ttyACM0'
7
- OPTIONS = { "baud" => 115200,
8
- "data_bits" => 8,
9
- "stop_bits" => 1,
10
- "parity" => SerialPort::NONE,
11
- "flow_control" => SerialPort::SOFT }
5
+ module FB
6
+ class DefaultSerialPort < SerialPort
7
+ COM_PORT = '/dev/ttyACM0'
8
+ OPTIONS = { "baud" => 115200,
9
+ "data_bits" => 8,
10
+ "stop_bits" => 1,
11
+ "parity" => SerialPort::NONE,
12
+ "flow_control" => SerialPort::SOFT }
12
13
 
13
- # Why `def self::new()`? it was defined that way in the parent class,
14
- # therefore, I can't call super in #initialize().
15
- def self::new(com = COM_PORT, conf = OPTIONS)
16
- super
14
+ # Why `def self::new()`? it was defined that way in the parent class,
15
+ # therefore, I can't call super in #initialize().
16
+ def self::new(com = COM_PORT, conf = OPTIONS)
17
+ super
18
+ end
17
19
  end
18
20
  end
19
-
@@ -1,5 +1,5 @@
1
1
  require 'serialport'
2
-
3
2
  require_relative 'default_serial_port'
3
+ require_relative 'arduino_command_set'
4
4
  require_relative 'arduino_event_machine'
5
5
  require_relative 'arduino'
@@ -1,10 +1,8 @@
1
1
  ## SERIAL PORT SIMULATION
2
2
  ## **********************
3
-
4
- # Used for unit tests
5
-
6
3
  module FB
7
- class StubSerialPort
4
+ # Used for unit tests
5
+ class StubSerialPort # TODO: Inherit from StringIO?
8
6
  def initialize(comm_port, parameters)
9
7
  end
10
8
 
@@ -2,19 +2,7 @@ require 'spec_helper'
2
2
  describe FB::HardwareInterfaceArduinoValuesReceived do
3
3
 
4
4
  before do
5
-
6
-
7
-
8
-
9
- FB::HardwareInterface.current.status = FB::Status.new
10
-
11
- @ramps = FB::HardwareInterfaceArduinoValuesReceived.new()
12
-
13
- #@ramps = FB::HardwareInterfaceArduino.new(true)
14
-
15
- #@ramps_param = FB::HardwareInterfaceParam.new
16
- #@ramps.ramps_param = @ramps_param
17
-
5
+ @ramps = FB::HardwareInterfaceArduinoValuesReceived.new
18
6
  end
19
7
 
20
8
  it "load parameters" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: farmbot-serial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Evers
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-24 00:00:00.000000000 Z
12
+ date: 2015-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -124,10 +124,7 @@ files:
124
124
  - lib/arduino_event_machine.rb
125
125
  - lib/default_serial_port.rb
126
126
  - lib/farmbot-serial.rb
127
- - lib/hardware_interface_arduino_values_received.rb
128
- - lib/outbound_message.rb
129
127
  - spec/fixtures/stub_serial_port.rb
130
- - spec/lib/ramps_arduino_spec.rb
131
128
  - spec/lib/ramps_arduino_values_received_spec.rb
132
129
  - spec/spec_helper.rb
133
130
  - testcommands.csv
@@ -157,6 +154,5 @@ specification_version: 4
157
154
  summary: Serial library for Farmbot
158
155
  test_files:
159
156
  - spec/fixtures/stub_serial_port.rb
160
- - spec/lib/ramps_arduino_spec.rb
161
157
  - spec/lib/ramps_arduino_values_received_spec.rb
162
158
  - spec/spec_helper.rb
@@ -1,59 +0,0 @@
1
- module FB
2
- # Rename to StatusIndicator or StatusRegister
3
- class HardwareInterfaceArduinoValuesReceived
4
-
5
- attr_accessor :code, :text, :external_info
6
-
7
- # value holders with the name used in the serial
8
- # communucation as they are received from arduino
9
- attr_accessor :p , :v, :x , :y , :z, :xa, :xb, :ya, :yb, :za, :zb
10
-
11
-
12
- def initialize
13
- @p = -1
14
- @v = 0
15
- @x = 0
16
- @y = 0
17
- @z = 0
18
- @xa = 0
19
- @xb = 0
20
- @ya = 0
21
- @yb = 0
22
- @za = 0
23
- @zb = 0
24
- @text = ''
25
- @code = 0
26
- end
27
- # Change name to []=?
28
- def load_parameter(name, value)
29
- name = name.upcase.to_sym
30
- case name
31
- when :P
32
- @p = value
33
- when :V
34
- @v = value
35
- when :XA
36
- @xa = value
37
- when :XB
38
- @xb = value
39
- when :YA
40
- @ya = value
41
- when :YB
42
- @yb = value
43
- when :ZA
44
- @za = value
45
- when :ZB
46
- @zb = value
47
- when :X
48
- @x = value
49
- when :Y
50
- @y = value
51
- when :Z
52
- @z = value
53
- else
54
- raise "Unknown status symbol '#{name}'"
55
- end
56
- end
57
-
58
- end
59
- end
@@ -1,58 +0,0 @@
1
- # An outbound (Pi -> Arduino) status message.
2
- # Originally HardwareInterfaceArduinoWriteStatus
3
- class OutboundMessage
4
-
5
- attr_accessor :done, :code, :received, :start, :log, :onscreen, :text,
6
- :params, :timeout
7
-
8
- def initialize(text)
9
- @text = text
10
- @done = 0
11
- @code = ''
12
- @received = ''
13
- @text = ''
14
- @params = ''
15
- @log = false
16
- @onscreen = false
17
- @start = Time.now
18
- @timeout = 5
19
- end
20
-
21
- def parse_response!
22
- # get the parameter and data part
23
- @code = received[0..2].upcase
24
- @params = received[3..-1].to_s.upcase.strip
25
- end
26
-
27
- # handle the incoming message depending on the first code number
28
- #
29
- def process_code_and_params
30
-
31
- # process the feedback
32
- case self.code
33
-
34
- # command received by arduino
35
- when 'R01'
36
- self.timeout = 90
37
- # command is finished
38
- when 'R02'
39
- self.done = 1
40
- @is_done = true
41
- # command is finished with errors
42
- when 'R03'
43
- self.done = 1
44
- @is_done = true
45
- # command is still ongoing
46
- when 'R04'
47
- self.start = Time.now
48
- self.timeout = 90
49
- # specific feedback that is processes separately
50
- else
51
- process_value(self.code,self.params)
52
- end
53
-
54
- self.received = ''
55
-
56
- end
57
-
58
- end
@@ -1,672 +0,0 @@
1
- require 'spec_helper'
2
- describe FB::HardwareInterfaceArduino do
3
-
4
- before do
5
- FB::HardwareInterface.current.status = FB::Status.new
6
-
7
- @ramps = FB::HardwareInterfaceArduino.new(true)
8
-
9
- @ramps_param = FB::HardwareInterfaceParam.new
10
- @ramps.ramps_param = @ramps_param
11
- end
12
-
13
- it "read status" do
14
- @ramps.connect_board
15
- expect(1).to eq(1)
16
- end
17
-
18
- it "execute_command" do
19
- command = "TEST"
20
-
21
- @ramps.serial_port.test_serial_read = "R01\nR02\n"
22
- @ramps.execute_command(command, false, false)
23
-
24
- expect(@ramps.serial_port.test_serial_write).to eq("#{command}\n")
25
-
26
- end
27
-
28
- it "execute_command with causing an error" do
29
-
30
- FB::HardwareInterface.current.status = nil
31
-
32
- @ramps.serial_port.rts = 0
33
- @ramps.execute_command(nil,nil,nil)
34
-
35
- FB::HardwareInterface.current.status = FB::Status.new
36
-
37
- expect { @ramps }.to_not raise_error
38
-
39
- end
40
-
41
- it "create write status" do
42
-
43
- text = rand(9999999).to_s
44
- log = rand(9999999).to_s
45
- onscreen = true
46
-
47
- write_status = @ramps.create_write_status(text, log, onscreen)
48
-
49
- expect(write_status.text ).to eq(text )
50
- expect(write_status.log ).to eq(log )
51
- expect(write_status.onscreen ).to eq(onscreen )
52
- end
53
-
54
- it "handle execution exception" do
55
- e = Exception.new
56
- @ramps.handle_execution_exception(e)
57
- expect(1).to eq(1)
58
- end
59
-
60
- it "log result of execution" do
61
-
62
- text = rand(9999999).to_s
63
- log = rand(9999999).to_s
64
- onscreen = true
65
-
66
- write_status = @ramps.create_write_status(text, log, onscreen)
67
-
68
- @ramps.log_result_of_execution(write_status)
69
-
70
- expect(1).to eq(1)
71
- end
72
-
73
- it "process feedback" do
74
-
75
- text = rand(9999999).to_s
76
- log = rand(9999999).to_s
77
- onscreen = false
78
-
79
- @ramps.serial_port.test_serial_read = "R02\n"
80
-
81
- write_status = @ramps.create_write_status(text, log, onscreen)
82
-
83
- @ramps.process_feedback(write_status)
84
- @ramps.process_feedback(write_status)
85
- @ramps.process_feedback(write_status)
86
- @ramps.process_feedback(write_status)
87
- @ramps.process_feedback(write_status)
88
-
89
- expect(write_status.done).to eq(1)
90
-
91
- end
92
-
93
- it "and and process characters" do
94
-
95
- text = rand(9999999).to_s
96
- log = rand(9999999).to_s
97
- onscreen = false
98
-
99
- write_status = @ramps.create_write_status(text, log, onscreen)
100
-
101
- @ramps.add_and_process_characters(write_status, 'R')
102
- @ramps.add_and_process_characters(write_status, '0')
103
- @ramps.add_and_process_characters(write_status, '2')
104
- @ramps.add_and_process_characters(write_status, "\n")
105
-
106
- expect(write_status.done).to eq(1)
107
-
108
- end
109
-
110
- it "process codes and parameters R01" do
111
-
112
- text = rand(9999999).to_s
113
- log = rand(9999999).to_s
114
- onscreen = false
115
-
116
- write_status = @ramps.create_write_status(text, log, onscreen)
117
- write_status.code = "R01"
118
- timeout = write_status.timeout
119
-
120
- @ramps.process_code_and_params(write_status)
121
-
122
- expect(write_status.timeout).to be > timeout
123
-
124
- end
125
-
126
- it "process codes and parameters R02" do
127
-
128
- text = rand(9999999).to_s
129
- log = rand(9999999).to_s
130
- onscreen = false
131
-
132
- write_status = @ramps.create_write_status(text, log, onscreen)
133
- write_status.code = "R02"
134
-
135
- @ramps.process_code_and_params(write_status)
136
-
137
- expect(write_status.done).to eq(1)
138
-
139
- end
140
-
141
- it "process codes and parameters R03" do
142
-
143
- text = rand(9999999).to_s
144
- log = rand(9999999).to_s
145
- onscreen = false
146
-
147
- write_status = @ramps.create_write_status(text, log, onscreen)
148
- write_status.code = "R03"
149
-
150
- @ramps.process_code_and_params(write_status)
151
-
152
- expect(write_status.done).to eq(1)
153
- end
154
-
155
- it "process codes and parameters R04" do
156
-
157
- text = rand(9999999).to_s
158
- log = rand(9999999).to_s
159
- onscreen = false
160
-
161
- write_status = @ramps.create_write_status(text, log, onscreen)
162
- write_status.code = "R04"
163
- timeout = write_status.timeout
164
- time = Time.now
165
-
166
- @ramps.process_code_and_params(write_status)
167
-
168
- expect(write_status.timeout).to be > timeout
169
- expect(write_status.start).to be > time
170
-
171
- end
172
-
173
- it "process codes and parameters other" do
174
-
175
- text = rand(9999999).to_s
176
- log = rand(9999999).to_s
177
- onscreen = false
178
- par = rand(9999999).to_s
179
-
180
- write_status = @ramps.create_write_status(text, log, onscreen)
181
- write_status.code = "R83"
182
- write_status.params = par
183
-
184
- @ramps.process_code_and_params(write_status)
185
-
186
- expect(FB::HardwareInterface.current.status.device_version).to eq(write_status.params)
187
-
188
- end
189
-
190
-
191
- it "prepare serial port" do
192
- text = rand(9999999).to_s
193
- log = rand(9999999).to_s
194
- onscreen = false
195
-
196
- write_status = @ramps.create_write_status(text, log, onscreen)
197
-
198
- @ramps.prepare_serial_port(write_status)
199
- expect(1).to eq(1)
200
- end
201
-
202
- it "clean serial buffer" do
203
- @ramps.serial_port.test_serial_read = rand(9999999).to_s
204
- @ramps.clean_serial_buffer
205
- expect(@ramps.serial_port.test_serial_read).to eq(nil)
206
-
207
- end
208
-
209
- it "serial port write" do
210
- text = rand(9999999).to_s
211
- @ramps.serial_port_write(text)
212
- expect(@ramps.serial_port.test_serial_write).to eq(text)
213
- end
214
-
215
- it "emergency stop off" do
216
- @ramps.serial_port.test_serial_write = ""
217
- FB::HardwareInterface.current.status.emergency_stop = false
218
- @ramps.check_emergency_stop
219
- expect(@ramps.serial_port.test_serial_write).to eq("")
220
- end
221
-
222
- it "emergency stop on" do
223
- @ramps.serial_port.test_serial_write = ""
224
- FB::HardwareInterface.current.status.emergency_stop = true
225
- @ramps.check_emergency_stop
226
- expect(@ramps.serial_port.test_serial_write).to eq("E\n")
227
- end
228
-
229
- it "log incoming text" do
230
- text = rand(9999999).to_s
231
- log = rand(9999999).to_s
232
- onscreen = false
233
-
234
- write_status = @ramps.create_write_status(text, log, onscreen)
235
-
236
- @ramps.log_incoming_text(write_status)
237
- expect(1).to eq(1)
238
- end
239
-
240
- it "process value split two letters" do
241
-
242
- params = FB::HardwareInterfaceArduinoValuesReceived.new
243
- code = "R81"
244
- text = "ZA1 ZB2 XA3 XB4 YA5 YB6"
245
- @ramps.process_value_split(code, params, text)
246
-
247
- expect(params.za).to eq(1)
248
- expect(params.zb).to eq(2)
249
- expect(params.xa).to eq(3)
250
- expect(params.xb).to eq(4)
251
- expect(params.ya).to eq(5)
252
- expect(params.yb).to eq(6)
253
- end
254
-
255
- it "process value split one letters" do
256
-
257
- params = FB::HardwareInterfaceArduinoValuesReceived.new
258
- code = "R99"
259
- text = "P1 V2 X3 Y4 Z5"
260
- @ramps.process_value_split(code, params, text)
261
-
262
- expect(params.p).to eq(1)
263
- expect(params.v).to eq(2)
264
- expect(params.x).to eq(3)
265
- expect(params.y).to eq(4)
266
- expect(params.z).to eq(5)
267
-
268
- end
269
-
270
- it "process value R21" do
271
-
272
- param = 1
273
- value = rand(999).to_i
274
-
275
- code = "R21"
276
- text = "P#{param} V#{value}"
277
-
278
- params = FB::HardwareInterfaceArduinoValuesReceived.new
279
- @ramps.process_value_split(code, params, text)
280
- @ramps.process_value_R21(params,code)
281
-
282
- par_obj = @ramps_param.get_param_by_id(param)
283
-
284
- expect(par_obj['value_ar']).to eq(value)
285
-
286
- end
287
-
288
- it "process value R23" do
289
-
290
- param = 1
291
- value = rand(999).to_i
292
-
293
- code = "R23"
294
- text = "P#{param} V#{value}"
295
-
296
- params = FB::HardwareInterfaceArduinoValuesReceived.new
297
- @ramps.process_value_split(code, params, text)
298
- @ramps.process_value_R23(params,code)
299
-
300
- par_obj = @ramps_param.get_param_by_id(param)
301
-
302
- expect(par_obj['value_db']).to eq(value)
303
-
304
- end
305
-
306
- it "process value R41" do
307
-
308
- pinnr = rand(9999999).to_i
309
- value = rand(9999999).to_i
310
- exinf = rand(9999999).to_i
311
-
312
- code = "R41"
313
- text = "P#{pinnr} V#{value}"
314
-
315
- @ramps.external_info = exinf
316
-
317
- params = FB::HardwareInterfaceArduinoValuesReceived.new
318
- @ramps.process_value_split(code, params, text)
319
- @ramps.process_value_R41(params,code)
320
-
321
- pin_value = 0
322
-
323
-
324
- list.each do |meas|
325
- if meas['ext_info'].to_s == exinf.to_s
326
- pin_value = meas['value']
327
- end
328
- end
329
-
330
- expect(pin_value.to_i).to eq(value.to_i)
331
-
332
- end
333
-
334
- it "process value R81 XA" do
335
-
336
- params = FB::HardwareInterfaceArduinoValuesReceived.new
337
- code = "R81"
338
- text = " XA1 XB0 YA0 YB0 ZA0 ZB0 "
339
- @ramps.process_value_split(code, params, text)
340
- @ramps.process_value_R81(params,code)
341
-
342
- expect(FB::HardwareInterface.current.status.info_end_stop_x_a).to eq(true)
343
- expect(FB::HardwareInterface.current.status.info_end_stop_x_b).to eq(false)
344
- expect(FB::HardwareInterface.current.status.info_end_stop_y_a).to eq(false)
345
- expect(FB::HardwareInterface.current.status.info_end_stop_y_b).to eq(false)
346
- expect(FB::HardwareInterface.current.status.info_end_stop_z_a).to eq(false)
347
- expect(FB::HardwareInterface.current.status.info_end_stop_z_b).to eq(false)
348
-
349
- end
350
-
351
- it "process value R81 XB" do
352
-
353
- params = FB::HardwareInterfaceArduinoValuesReceived.new
354
- code = "R81"
355
- text = " XA0 XB1 YA0 YB0 ZA0 ZB0 "
356
- @ramps.process_value_split(code, params, text)
357
- @ramps.process_value_R81(params,code)
358
-
359
- expect(FB::HardwareInterface.current.status.info_end_stop_x_a).to eq(false)
360
- expect(FB::HardwareInterface.current.status.info_end_stop_x_b).to eq(true)
361
- expect(FB::HardwareInterface.current.status.info_end_stop_y_a).to eq(false)
362
- expect(FB::HardwareInterface.current.status.info_end_stop_y_b).to eq(false)
363
- expect(FB::HardwareInterface.current.status.info_end_stop_z_a).to eq(false)
364
- expect(FB::HardwareInterface.current.status.info_end_stop_z_b).to eq(false)
365
-
366
- end
367
-
368
- it "process value R81 YA" do
369
-
370
- params = FB::HardwareInterfaceArduinoValuesReceived.new
371
- code = "R81"
372
- text = " XA0 XB0 YA1 YB0 ZA0 ZB0 "
373
- @ramps.process_value_split(code, params, text)
374
- @ramps.process_value_R81(params,code)
375
-
376
- expect(FB::HardwareInterface.current.status.info_end_stop_x_a).to eq(false)
377
- expect(FB::HardwareInterface.current.status.info_end_stop_x_b).to eq(false)
378
- expect(FB::HardwareInterface.current.status.info_end_stop_y_a).to eq(true)
379
- expect(FB::HardwareInterface.current.status.info_end_stop_y_b).to eq(false)
380
- expect(FB::HardwareInterface.current.status.info_end_stop_z_a).to eq(false)
381
- expect(FB::HardwareInterface.current.status.info_end_stop_z_b).to eq(false)
382
-
383
- end
384
-
385
- it "process value R81 YB" do
386
-
387
- params = FB::HardwareInterfaceArduinoValuesReceived.new
388
- code = "R81"
389
- text = " XA0 XB0 YA0 YB1 ZA0 ZB0 "
390
- @ramps.process_value_split(code, params, text)
391
- @ramps.process_value_R81(params,code)
392
-
393
- expect(FB::HardwareInterface.current.status.info_end_stop_x_a).to eq(false)
394
- expect(FB::HardwareInterface.current.status.info_end_stop_x_b).to eq(false)
395
- expect(FB::HardwareInterface.current.status.info_end_stop_y_a).to eq(false)
396
- expect(FB::HardwareInterface.current.status.info_end_stop_y_b).to eq(true)
397
- expect(FB::HardwareInterface.current.status.info_end_stop_z_a).to eq(false)
398
- expect(FB::HardwareInterface.current.status.info_end_stop_z_b).to eq(false)
399
-
400
- end
401
-
402
- it "process value R81 ZA" do
403
-
404
- params = FB::HardwareInterfaceArduinoValuesReceived.new
405
- code = "R81"
406
- text = " XA0 XB0 YA0 YB0 ZA1 ZB0 "
407
- @ramps.process_value_split(code, params, text)
408
- @ramps.process_value_R81(params,code)
409
-
410
- expect(FB::HardwareInterface.current.status.info_end_stop_x_a).to eq(false)
411
- expect(FB::HardwareInterface.current.status.info_end_stop_x_b).to eq(false)
412
- expect(FB::HardwareInterface.current.status.info_end_stop_y_a).to eq(false)
413
- expect(FB::HardwareInterface.current.status.info_end_stop_y_b).to eq(false)
414
- expect(FB::HardwareInterface.current.status.info_end_stop_z_a).to eq(true)
415
- expect(FB::HardwareInterface.current.status.info_end_stop_z_b).to eq(false)
416
-
417
- end
418
-
419
- it "process value R81 ZB" do
420
-
421
- params = FB::HardwareInterfaceArduinoValuesReceived.new
422
- code = "R81"
423
- text = " XA0 XB0 YA0 YB0 ZA0 ZB1 "
424
- @ramps.process_value_split(code, params, text)
425
- @ramps.process_value_R81(params,code)
426
-
427
- expect(FB::HardwareInterface.current.status.info_end_stop_x_a).to eq(false)
428
- expect(FB::HardwareInterface.current.status.info_end_stop_x_b).to eq(false)
429
- expect(FB::HardwareInterface.current.status.info_end_stop_y_a).to eq(false)
430
- expect(FB::HardwareInterface.current.status.info_end_stop_y_b).to eq(false)
431
- expect(FB::HardwareInterface.current.status.info_end_stop_z_a).to eq(false)
432
- expect(FB::HardwareInterface.current.status.info_end_stop_z_b).to eq(true)
433
-
434
- end
435
-
436
- it "process value R82" do
437
-
438
- x = rand(9999999).to_i
439
- y = rand(9999999).to_i
440
- z = rand(9999999).to_i
441
-
442
- params = FB::HardwareInterfaceArduinoValuesReceived.new
443
- code = "R82"
444
- text = "X#{x} Y#{y} Z#{z}"
445
- @ramps.process_value_split(code, params, text)
446
- @ramps.process_value_R82(params,code)
447
-
448
- expect(FB::HardwareInterface.current.status.info_current_x_steps).to eq(x)
449
- expect(FB::HardwareInterface.current.status.info_current_y_steps).to eq(y)
450
- expect(FB::HardwareInterface.current.status.info_current_z_steps).to eq(z)
451
-
452
- expect(FB::HardwareInterface.current.status.info_current_x ).to eq(x / @ramps_param.axis_x_steps_per_unit)
453
- expect(FB::HardwareInterface.current.status.info_current_y ).to eq(y / @ramps_param.axis_y_steps_per_unit)
454
- expect(FB::HardwareInterface.current.status.info_current_z ).to eq(z / @ramps_param.axis_z_steps_per_unit)
455
-
456
- end
457
-
458
- it "process value R83" do
459
- code = "R83"
460
- text = rand(9999999).to_s
461
-
462
- @ramps.process_value_process_R83(code, text)
463
-
464
- expect(FB::HardwareInterface.current.status.device_version).to eq(text)
465
- end
466
-
467
-
468
- it "process value R99" do
469
-
470
- code = "R99"
471
- text = rand(9999999).to_s
472
-
473
- @ramps.process_value_process_R99(code, text)
474
- end
475
-
476
- it "save pin value" do
477
-
478
- pinnr = rand(9999999).to_i
479
- value = rand(9999999).to_i
480
- exinf = rand(9999999).to_i
481
-
482
- @ramps.external_info = exinf
483
- pin_value = 0
484
-
485
-
486
- list.each do |meas|
487
- if meas['ext_info'].to_s == exinf.to_s
488
- pin_value = meas['value']
489
- end
490
- end
491
-
492
- expect(pin_value.to_i).to eq(value.to_i)
493
- end
494
-
495
- it "process value process param list 1" do
496
-
497
- # "process value R21"
498
-
499
- param = 1
500
- value = rand(999).to_i
501
-
502
- code = "R21"
503
- text = "P#{param} V#{value}"
504
-
505
- params = FB::HardwareInterfaceArduinoValuesReceived.new
506
- @ramps.process_value_split(code, params, text)
507
- @ramps.process_value_process_param_list(params,code)
508
-
509
- par_obj = @ramps_param.get_param_by_id(param)
510
-
511
- expect(par_obj['value_ar']).to eq(value)
512
- end
513
-
514
- it "process value process param list 2" do
515
-
516
- # "process value R23"
517
-
518
- param = 1
519
- value = rand(999).to_i
520
-
521
- code = "R23"
522
- text = "P#{param} V#{value}"
523
-
524
- params = FB::HardwareInterfaceArduinoValuesReceived.new
525
- @ramps.process_value_split(code, params, text)
526
- @ramps.process_value_process_param_list(params,code)
527
-
528
- par_obj = @ramps_param.get_param_by_id(param)
529
-
530
- expect(par_obj['value_db']).to eq(value)
531
-
532
- end
533
-
534
- it "process value process param list 3" do
535
-
536
- # "process value R41"
537
-
538
- pinnr = rand(9999999).to_i
539
- value = rand(9999999).to_i
540
- exinf = rand(9999999).to_i
541
-
542
- code = "R41"
543
- text = "P#{pinnr} V#{value}"
544
-
545
- @ramps.external_info = exinf
546
-
547
- params = FB::HardwareInterfaceArduinoValuesReceived.new
548
- @ramps.process_value_split(code, params, text)
549
- @ramps.process_value_process_param_list(params,code)
550
-
551
- pin_value = 0
552
-
553
-
554
- list.each do |meas|
555
- if meas['ext_info'].to_s == exinf.to_s
556
- pin_value = meas['value']
557
- end
558
- end
559
-
560
- end
561
-
562
- it "process value process text 1" do
563
-
564
- # process_value_process_R83
565
-
566
- code = "R83"
567
- text = rand(9999999).to_s
568
-
569
- @ramps.process_value_process_R83(code, text)
570
-
571
- expect(FB::HardwareInterface.current.status.device_version).to eq(text)
572
-
573
- end
574
-
575
- it "process value process text 2" do
576
-
577
- # process_value_process_R99
578
-
579
- code = "R99"
580
- text = rand(9999999).to_s
581
-
582
- @ramps.process_value_process_R99(code, text)
583
-
584
- end
585
-
586
- it "process value 1" do
587
-
588
- # "process value R21"
589
-
590
- param = 1
591
- value = rand(999).to_i
592
-
593
- code = "R21"
594
- text = "P#{param} V#{value}"
595
-
596
- @ramps.process_value(code,text)
597
-
598
- par_obj = @ramps_param.get_param_by_id(param)
599
-
600
- expect(par_obj['value_ar']).to eq(value)
601
-
602
- end
603
-
604
- it "process value 2" do
605
-
606
-
607
- # process_value_process_R99
608
-
609
- code = "R99"
610
- text = rand(9999999).to_s
611
-
612
- @ramps.process_value(code,text)
613
-
614
- end
615
-
616
- it "process value 3" do
617
-
618
- params = FB::HardwareInterfaceArduinoValuesReceived.new
619
- code = "R81"
620
- text = " XA0 XB0 YA0 YB0 ZA0 ZB1 "
621
- @ramps.process_value(code,text)
622
-
623
- expect(FB::HardwareInterface.current.status.info_end_stop_x_a).to eq(false)
624
- expect(FB::HardwareInterface.current.status.info_end_stop_x_b).to eq(false)
625
- expect(FB::HardwareInterface.current.status.info_end_stop_y_a).to eq(false)
626
- expect(FB::HardwareInterface.current.status.info_end_stop_y_b).to eq(false)
627
- expect(FB::HardwareInterface.current.status.info_end_stop_z_a).to eq(false)
628
- expect(FB::HardwareInterface.current.status.info_end_stop_z_b).to eq(true)
629
-
630
- end
631
-
632
- it "process value named parameters 1" do
633
-
634
- params = FB::HardwareInterfaceArduinoValuesReceived.new
635
- code = "R81"
636
- text = " XA0 XB0 YA0 YB0 ZA0 ZB1 "
637
- @ramps.process_value_split(code, params, text)
638
- @ramps.process_value_process_named_params(params,code)
639
-
640
- expect(FB::HardwareInterface.current.status.info_end_stop_x_a).to eq(false)
641
- expect(FB::HardwareInterface.current.status.info_end_stop_x_b).to eq(false)
642
- expect(FB::HardwareInterface.current.status.info_end_stop_y_a).to eq(false)
643
- expect(FB::HardwareInterface.current.status.info_end_stop_y_b).to eq(false)
644
- expect(FB::HardwareInterface.current.status.info_end_stop_z_a).to eq(false)
645
- expect(FB::HardwareInterface.current.status.info_end_stop_z_b).to eq(true)
646
-
647
- end
648
-
649
- it "process value named parameters 2" do
650
-
651
- x = rand(9999999).to_i
652
- y = rand(9999999).to_i
653
- z = rand(9999999).to_i
654
-
655
- params = FB::HardwareInterfaceArduinoValuesReceived.new
656
- code = "R82"
657
- text = "X#{x} Y#{y} Z#{z}"
658
- @ramps.process_value_split(code, params, text)
659
- @ramps.process_value_process_named_params(params,code)
660
-
661
- expect(FB::HardwareInterface.current.status.info_current_x_steps).to eq(x)
662
- expect(FB::HardwareInterface.current.status.info_current_y_steps).to eq(y)
663
- expect(FB::HardwareInterface.current.status.info_current_z_steps).to eq(z)
664
-
665
- expect(FB::HardwareInterface.current.status.info_current_x ).to eq(x / @ramps_param.axis_x_steps_per_unit)
666
- expect(FB::HardwareInterface.current.status.info_current_y ).to eq(y / @ramps_param.axis_y_steps_per_unit)
667
- expect(FB::HardwareInterface.current.status.info_current_z ).to eq(z / @ramps_param.axis_z_steps_per_unit)
668
-
669
- end
670
-
671
- end
672
-