farmbot-serial 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +3 -0
- data/lib/arduino.rb +41 -0
- data/lib/arduino_event_machine.rb +20 -0
- data/lib/default_serial_port.rb +19 -0
- data/lib/farmbot-serial.rb +4 -8
- data/lib/hardware_interface_arduino_values_received.rb +20 -24
- data/lib/outbound_message.rb +58 -0
- data/spec/fixtures/stub_serial_port.rb +19 -0
- data/spec/lib/ramps_arduino_spec.rb +89 -89
- data/spec/lib/ramps_arduino_values_received_spec.rb +5 -5
- metadata +23 -7
- data/Gemfile +0 -6
- data/farmbot-serial.gemspec +0 -27
- data/lib/hardware_interface_arduino.rb +0 -245
- data/lib/hardware_interface_write_status.rb +0 -35
- data/lib/serial_port_sim.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11e0f51d8ab86f321618b7624b564390dea98f8a
|
4
|
+
data.tar.gz: b4ee5f17fc86632387f3bbe853637eed6ee16d60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdaaf0a5772e4c18e1f8236ac9c02af0747150caf715c42e08dd8f506ec8e0795f7268d70997b599f38790ac7beefd4ba1951693433ae96b408d4080e6a50637
|
7
|
+
data.tar.gz: ad07522eb174172366067978f59979a965d208b4c3b5d4f5b82ebcf87a03a2fb89ba3a94d9f3fef382b92ff811a148d4cd0eca6f0f9fe6ed0d9820324126552d
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/lib/arduino.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
## HARDWARE INTERFACE
|
2
|
+
## ******************
|
3
|
+
|
4
|
+
# 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
|
+
module FB
|
8
|
+
class Arduino
|
9
|
+
class EmergencyStop < StandardError; end # Not yet used.
|
10
|
+
|
11
|
+
attr_reader :serial_port, :logger
|
12
|
+
|
13
|
+
# Initial and provide a serial object, as well as an IO object to send
|
14
|
+
# log messages to. Default SerialPort is DefaultSerialPort. Default logger
|
15
|
+
# is STDOUT
|
16
|
+
def initialize(serial_port = DefaultSerialPort.new, logger = STDOUT)
|
17
|
+
@serial_port, @logger = serial_port, logger
|
18
|
+
end
|
19
|
+
|
20
|
+
# Log to screen/file/IO stream
|
21
|
+
def log(message)
|
22
|
+
logger.puts(message)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Handle incoming text from arduino into pi
|
26
|
+
def read(string)
|
27
|
+
log "RECEIVED #{string}"
|
28
|
+
end
|
29
|
+
|
30
|
+
# Send outgoing test to arduino from pi
|
31
|
+
def write(string)
|
32
|
+
serial_port.puts string
|
33
|
+
log "SENT #{string}"
|
34
|
+
end
|
35
|
+
|
36
|
+
# Handle loss of serial connection
|
37
|
+
def disconnect
|
38
|
+
log "Connection to device lost"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
module FB
|
3
|
+
# Class that is fed into event machine's event loop to handle incoming serial
|
4
|
+
# messages asynchronously via EM.attach(). See: EM.attach
|
5
|
+
class ArduinoEventMachine < EventMachine::Connection
|
6
|
+
class << self
|
7
|
+
attr_accessor :arduino
|
8
|
+
end
|
9
|
+
|
10
|
+
def receive_data(data)
|
11
|
+
self.class.arduino.read(data)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Gets called when the connection breaks.
|
15
|
+
def unbind
|
16
|
+
self.class.arduino.disconnect
|
17
|
+
EM.stop
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'serialport'
|
2
|
+
|
3
|
+
# This object creates a Serial IO with sane default, since most FarmBot setups
|
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 }
|
12
|
+
|
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
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/lib/farmbot-serial.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
require 'serialport'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
require 'hardware_interface_param'
|
7
|
-
require 'hardware_interface'
|
8
|
-
require 'hardware_interface_arduino_values_received'
|
9
|
-
require 'hardware_interface_arduino_write_status'
|
2
|
+
|
3
|
+
require_relative 'default_serial_port'
|
4
|
+
require_relative 'arduino_event_machine'
|
5
|
+
require_relative 'arduino'
|
@@ -1,21 +1,15 @@
|
|
1
|
-
module
|
1
|
+
module FB
|
2
|
+
# Rename to StatusIndicator or StatusRegister
|
2
3
|
class HardwareInterfaceArduinoValuesReceived
|
3
4
|
|
4
|
-
attr_accessor :code
|
5
|
-
attr_accessor :text
|
6
|
-
attr_accessor :external_info
|
5
|
+
attr_accessor :code, :text, :external_info
|
7
6
|
|
8
|
-
# value holders with the name used in the serial
|
7
|
+
# value holders with the name used in the serial
|
9
8
|
# communucation as they are received from arduino
|
10
|
-
attr_accessor :p , :v
|
11
|
-
attr_accessor :x , :y , :z
|
12
|
-
attr_accessor :xa, :xb
|
13
|
-
attr_accessor :ya, :yb
|
14
|
-
attr_accessor :za, :zb
|
9
|
+
attr_accessor :p , :v, :x , :y , :z, :xa, :xb, :ya, :yb, :za, :zb
|
15
10
|
|
16
11
|
|
17
12
|
def initialize
|
18
|
-
|
19
13
|
@p = -1
|
20
14
|
@v = 0
|
21
15
|
@x = 0
|
@@ -30,32 +24,34 @@ module Fb
|
|
30
24
|
@text = ''
|
31
25
|
@code = 0
|
32
26
|
end
|
33
|
-
|
27
|
+
# Change name to []=?
|
34
28
|
def load_parameter(name, value)
|
35
|
-
|
29
|
+
name = name.upcase.to_sym
|
36
30
|
case name
|
37
|
-
when
|
31
|
+
when :P
|
38
32
|
@p = value
|
39
|
-
when
|
33
|
+
when :V
|
40
34
|
@v = value
|
41
|
-
when
|
35
|
+
when :XA
|
42
36
|
@xa = value
|
43
|
-
when
|
37
|
+
when :XB
|
44
38
|
@xb = value
|
45
|
-
when
|
39
|
+
when :YA
|
46
40
|
@ya = value
|
47
|
-
when
|
41
|
+
when :YB
|
48
42
|
@yb = value
|
49
|
-
when
|
43
|
+
when :ZA
|
50
44
|
@za = value
|
51
|
-
when
|
45
|
+
when :ZB
|
52
46
|
@zb = value
|
53
|
-
when
|
47
|
+
when :X
|
54
48
|
@x = value
|
55
|
-
when
|
49
|
+
when :Y
|
56
50
|
@y = value
|
57
|
-
when
|
51
|
+
when :Z
|
58
52
|
@z = value
|
53
|
+
else
|
54
|
+
raise "Unknown status symbol '#{name}'"
|
59
55
|
end
|
60
56
|
end
|
61
57
|
|
@@ -0,0 +1,58 @@
|
|
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
|
@@ -0,0 +1,19 @@
|
|
1
|
+
## SERIAL PORT SIMULATION
|
2
|
+
## **********************
|
3
|
+
|
4
|
+
# Used for unit tests
|
5
|
+
|
6
|
+
module FB
|
7
|
+
class StubSerialPort
|
8
|
+
def initialize(comm_port, parameters)
|
9
|
+
end
|
10
|
+
|
11
|
+
def write(text)
|
12
|
+
text
|
13
|
+
end
|
14
|
+
|
15
|
+
def read(characters)
|
16
|
+
characters
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
describe
|
2
|
+
describe FB::HardwareInterfaceArduino do
|
3
3
|
|
4
4
|
before do
|
5
|
-
|
5
|
+
FB::HardwareInterface.current.status = FB::Status.new
|
6
6
|
|
7
|
-
@ramps =
|
7
|
+
@ramps = FB::HardwareInterfaceArduino.new(true)
|
8
8
|
|
9
|
-
@ramps_param =
|
9
|
+
@ramps_param = FB::HardwareInterfaceParam.new
|
10
10
|
@ramps.ramps_param = @ramps_param
|
11
11
|
end
|
12
12
|
|
@@ -27,12 +27,12 @@ describe Fb::HardwareInterfaceArduino do
|
|
27
27
|
|
28
28
|
it "execute_command with causing an error" do
|
29
29
|
|
30
|
-
|
30
|
+
FB::HardwareInterface.current.status = nil
|
31
31
|
|
32
32
|
@ramps.serial_port.rts = 0
|
33
33
|
@ramps.execute_command(nil,nil,nil)
|
34
34
|
|
35
|
-
|
35
|
+
FB::HardwareInterface.current.status = FB::Status.new
|
36
36
|
|
37
37
|
expect { @ramps }.to_not raise_error
|
38
38
|
|
@@ -183,7 +183,7 @@ describe Fb::HardwareInterfaceArduino do
|
|
183
183
|
|
184
184
|
@ramps.process_code_and_params(write_status)
|
185
185
|
|
186
|
-
expect(
|
186
|
+
expect(FB::HardwareInterface.current.status.device_version).to eq(write_status.params)
|
187
187
|
|
188
188
|
end
|
189
189
|
|
@@ -214,14 +214,14 @@ describe Fb::HardwareInterfaceArduino do
|
|
214
214
|
|
215
215
|
it "emergency stop off" do
|
216
216
|
@ramps.serial_port.test_serial_write = ""
|
217
|
-
|
217
|
+
FB::HardwareInterface.current.status.emergency_stop = false
|
218
218
|
@ramps.check_emergency_stop
|
219
219
|
expect(@ramps.serial_port.test_serial_write).to eq("")
|
220
220
|
end
|
221
221
|
|
222
222
|
it "emergency stop on" do
|
223
223
|
@ramps.serial_port.test_serial_write = ""
|
224
|
-
|
224
|
+
FB::HardwareInterface.current.status.emergency_stop = true
|
225
225
|
@ramps.check_emergency_stop
|
226
226
|
expect(@ramps.serial_port.test_serial_write).to eq("E\n")
|
227
227
|
end
|
@@ -239,7 +239,7 @@ describe Fb::HardwareInterfaceArduino do
|
|
239
239
|
|
240
240
|
it "process value split two letters" do
|
241
241
|
|
242
|
-
params =
|
242
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
243
243
|
code = "R81"
|
244
244
|
text = "ZA1 ZB2 XA3 XB4 YA5 YB6"
|
245
245
|
@ramps.process_value_split(code, params, text)
|
@@ -254,7 +254,7 @@ describe Fb::HardwareInterfaceArduino do
|
|
254
254
|
|
255
255
|
it "process value split one letters" do
|
256
256
|
|
257
|
-
params =
|
257
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
258
258
|
code = "R99"
|
259
259
|
text = "P1 V2 X3 Y4 Z5"
|
260
260
|
@ramps.process_value_split(code, params, text)
|
@@ -275,7 +275,7 @@ describe Fb::HardwareInterfaceArduino do
|
|
275
275
|
code = "R21"
|
276
276
|
text = "P#{param} V#{value}"
|
277
277
|
|
278
|
-
params =
|
278
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
279
279
|
@ramps.process_value_split(code, params, text)
|
280
280
|
@ramps.process_value_R21(params,code)
|
281
281
|
|
@@ -293,7 +293,7 @@ describe Fb::HardwareInterfaceArduino do
|
|
293
293
|
code = "R23"
|
294
294
|
text = "P#{param} V#{value}"
|
295
295
|
|
296
|
-
params =
|
296
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
297
297
|
@ramps.process_value_split(code, params, text)
|
298
298
|
@ramps.process_value_R23(params,code)
|
299
299
|
|
@@ -314,7 +314,7 @@ describe Fb::HardwareInterfaceArduino do
|
|
314
314
|
|
315
315
|
@ramps.external_info = exinf
|
316
316
|
|
317
|
-
params =
|
317
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
318
318
|
@ramps.process_value_split(code, params, text)
|
319
319
|
@ramps.process_value_R41(params,code)
|
320
320
|
|
@@ -333,103 +333,103 @@ describe Fb::HardwareInterfaceArduino do
|
|
333
333
|
|
334
334
|
it "process value R81 XA" do
|
335
335
|
|
336
|
-
params =
|
336
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
337
337
|
code = "R81"
|
338
338
|
text = " XA1 XB0 YA0 YB0 ZA0 ZB0 "
|
339
339
|
@ramps.process_value_split(code, params, text)
|
340
340
|
@ramps.process_value_R81(params,code)
|
341
341
|
|
342
|
-
expect(
|
343
|
-
expect(
|
344
|
-
expect(
|
345
|
-
expect(
|
346
|
-
expect(
|
347
|
-
expect(
|
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
348
|
|
349
349
|
end
|
350
350
|
|
351
351
|
it "process value R81 XB" do
|
352
352
|
|
353
|
-
params =
|
353
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
354
354
|
code = "R81"
|
355
355
|
text = " XA0 XB1 YA0 YB0 ZA0 ZB0 "
|
356
356
|
@ramps.process_value_split(code, params, text)
|
357
357
|
@ramps.process_value_R81(params,code)
|
358
358
|
|
359
|
-
expect(
|
360
|
-
expect(
|
361
|
-
expect(
|
362
|
-
expect(
|
363
|
-
expect(
|
364
|
-
expect(
|
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
365
|
|
366
366
|
end
|
367
367
|
|
368
368
|
it "process value R81 YA" do
|
369
369
|
|
370
|
-
params =
|
370
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
371
371
|
code = "R81"
|
372
372
|
text = " XA0 XB0 YA1 YB0 ZA0 ZB0 "
|
373
373
|
@ramps.process_value_split(code, params, text)
|
374
374
|
@ramps.process_value_R81(params,code)
|
375
375
|
|
376
|
-
expect(
|
377
|
-
expect(
|
378
|
-
expect(
|
379
|
-
expect(
|
380
|
-
expect(
|
381
|
-
expect(
|
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
382
|
|
383
383
|
end
|
384
384
|
|
385
385
|
it "process value R81 YB" do
|
386
386
|
|
387
|
-
params =
|
387
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
388
388
|
code = "R81"
|
389
389
|
text = " XA0 XB0 YA0 YB1 ZA0 ZB0 "
|
390
390
|
@ramps.process_value_split(code, params, text)
|
391
391
|
@ramps.process_value_R81(params,code)
|
392
392
|
|
393
|
-
expect(
|
394
|
-
expect(
|
395
|
-
expect(
|
396
|
-
expect(
|
397
|
-
expect(
|
398
|
-
expect(
|
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
399
|
|
400
400
|
end
|
401
401
|
|
402
402
|
it "process value R81 ZA" do
|
403
403
|
|
404
|
-
params =
|
404
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
405
405
|
code = "R81"
|
406
406
|
text = " XA0 XB0 YA0 YB0 ZA1 ZB0 "
|
407
407
|
@ramps.process_value_split(code, params, text)
|
408
408
|
@ramps.process_value_R81(params,code)
|
409
409
|
|
410
|
-
expect(
|
411
|
-
expect(
|
412
|
-
expect(
|
413
|
-
expect(
|
414
|
-
expect(
|
415
|
-
expect(
|
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
416
|
|
417
417
|
end
|
418
418
|
|
419
419
|
it "process value R81 ZB" do
|
420
420
|
|
421
|
-
params =
|
421
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
422
422
|
code = "R81"
|
423
423
|
text = " XA0 XB0 YA0 YB0 ZA0 ZB1 "
|
424
424
|
@ramps.process_value_split(code, params, text)
|
425
425
|
@ramps.process_value_R81(params,code)
|
426
426
|
|
427
|
-
expect(
|
428
|
-
expect(
|
429
|
-
expect(
|
430
|
-
expect(
|
431
|
-
expect(
|
432
|
-
expect(
|
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
433
|
|
434
434
|
end
|
435
435
|
|
@@ -439,19 +439,19 @@ describe Fb::HardwareInterfaceArduino do
|
|
439
439
|
y = rand(9999999).to_i
|
440
440
|
z = rand(9999999).to_i
|
441
441
|
|
442
|
-
params =
|
442
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
443
443
|
code = "R82"
|
444
444
|
text = "X#{x} Y#{y} Z#{z}"
|
445
445
|
@ramps.process_value_split(code, params, text)
|
446
446
|
@ramps.process_value_R82(params,code)
|
447
447
|
|
448
|
-
expect(
|
449
|
-
expect(
|
450
|
-
expect(
|
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
451
|
|
452
|
-
expect(
|
453
|
-
expect(
|
454
|
-
expect(
|
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
455
|
|
456
456
|
end
|
457
457
|
|
@@ -461,7 +461,7 @@ describe Fb::HardwareInterfaceArduino do
|
|
461
461
|
|
462
462
|
@ramps.process_value_process_R83(code, text)
|
463
463
|
|
464
|
-
expect(
|
464
|
+
expect(FB::HardwareInterface.current.status.device_version).to eq(text)
|
465
465
|
end
|
466
466
|
|
467
467
|
|
@@ -502,7 +502,7 @@ describe Fb::HardwareInterfaceArduino do
|
|
502
502
|
code = "R21"
|
503
503
|
text = "P#{param} V#{value}"
|
504
504
|
|
505
|
-
params =
|
505
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
506
506
|
@ramps.process_value_split(code, params, text)
|
507
507
|
@ramps.process_value_process_param_list(params,code)
|
508
508
|
|
@@ -521,7 +521,7 @@ describe Fb::HardwareInterfaceArduino do
|
|
521
521
|
code = "R23"
|
522
522
|
text = "P#{param} V#{value}"
|
523
523
|
|
524
|
-
params =
|
524
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
525
525
|
@ramps.process_value_split(code, params, text)
|
526
526
|
@ramps.process_value_process_param_list(params,code)
|
527
527
|
|
@@ -544,7 +544,7 @@ describe Fb::HardwareInterfaceArduino do
|
|
544
544
|
|
545
545
|
@ramps.external_info = exinf
|
546
546
|
|
547
|
-
params =
|
547
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
548
548
|
@ramps.process_value_split(code, params, text)
|
549
549
|
@ramps.process_value_process_param_list(params,code)
|
550
550
|
|
@@ -568,7 +568,7 @@ describe Fb::HardwareInterfaceArduino do
|
|
568
568
|
|
569
569
|
@ramps.process_value_process_R83(code, text)
|
570
570
|
|
571
|
-
expect(
|
571
|
+
expect(FB::HardwareInterface.current.status.device_version).to eq(text)
|
572
572
|
|
573
573
|
end
|
574
574
|
|
@@ -615,34 +615,34 @@ describe Fb::HardwareInterfaceArduino do
|
|
615
615
|
|
616
616
|
it "process value 3" do
|
617
617
|
|
618
|
-
params =
|
618
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
619
619
|
code = "R81"
|
620
620
|
text = " XA0 XB0 YA0 YB0 ZA0 ZB1 "
|
621
621
|
@ramps.process_value(code,text)
|
622
622
|
|
623
|
-
expect(
|
624
|
-
expect(
|
625
|
-
expect(
|
626
|
-
expect(
|
627
|
-
expect(
|
628
|
-
expect(
|
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
629
|
|
630
630
|
end
|
631
631
|
|
632
632
|
it "process value named parameters 1" do
|
633
633
|
|
634
|
-
params =
|
634
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
635
635
|
code = "R81"
|
636
636
|
text = " XA0 XB0 YA0 YB0 ZA0 ZB1 "
|
637
637
|
@ramps.process_value_split(code, params, text)
|
638
638
|
@ramps.process_value_process_named_params(params,code)
|
639
639
|
|
640
|
-
expect(
|
641
|
-
expect(
|
642
|
-
expect(
|
643
|
-
expect(
|
644
|
-
expect(
|
645
|
-
expect(
|
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
646
|
|
647
647
|
end
|
648
648
|
|
@@ -652,19 +652,19 @@ describe Fb::HardwareInterfaceArduino do
|
|
652
652
|
y = rand(9999999).to_i
|
653
653
|
z = rand(9999999).to_i
|
654
654
|
|
655
|
-
params =
|
655
|
+
params = FB::HardwareInterfaceArduinoValuesReceived.new
|
656
656
|
code = "R82"
|
657
657
|
text = "X#{x} Y#{y} Z#{z}"
|
658
658
|
@ramps.process_value_split(code, params, text)
|
659
659
|
@ramps.process_value_process_named_params(params,code)
|
660
660
|
|
661
|
-
expect(
|
662
|
-
expect(
|
663
|
-
expect(
|
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
664
|
|
665
|
-
expect(
|
666
|
-
expect(
|
667
|
-
expect(
|
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
668
|
|
669
669
|
end
|
670
670
|
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
describe
|
2
|
+
describe FB::HardwareInterfaceArduinoValuesReceived do
|
3
3
|
|
4
4
|
before do
|
5
5
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
|
9
|
+
FB::HardwareInterface.current.status = FB::Status.new
|
10
10
|
|
11
|
-
@ramps =
|
11
|
+
@ramps = FB::HardwareInterfaceArduinoValuesReceived.new()
|
12
12
|
|
13
|
-
#@ramps =
|
13
|
+
#@ramps = FB::HardwareInterfaceArduino.new(true)
|
14
14
|
|
15
|
-
#@ramps_param =
|
15
|
+
#@ramps_param = FB::HardwareInterfaceParam.new
|
16
16
|
#@ramps.ramps_param = @ramps_param
|
17
17
|
|
18
18
|
end
|
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
|
+
version: 0.0.4
|
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-
|
12
|
+
date: 2015-03-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -81,6 +81,20 @@ dependencies:
|
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: eventmachine
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
84
98
|
- !ruby/object:Gem::Dependency
|
85
99
|
name: serialport
|
86
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,15 +117,16 @@ extensions: []
|
|
103
117
|
extra_rdoc_files: []
|
104
118
|
files:
|
105
119
|
- ".gitignore"
|
106
|
-
-
|
120
|
+
- ".rspec"
|
107
121
|
- README.md
|
108
122
|
- Rakefile
|
109
|
-
-
|
123
|
+
- lib/arduino.rb
|
124
|
+
- lib/arduino_event_machine.rb
|
125
|
+
- lib/default_serial_port.rb
|
110
126
|
- lib/farmbot-serial.rb
|
111
|
-
- lib/hardware_interface_arduino.rb
|
112
127
|
- lib/hardware_interface_arduino_values_received.rb
|
113
|
-
- lib/
|
114
|
-
-
|
128
|
+
- lib/outbound_message.rb
|
129
|
+
- spec/fixtures/stub_serial_port.rb
|
115
130
|
- spec/lib/ramps_arduino_spec.rb
|
116
131
|
- spec/lib/ramps_arduino_values_received_spec.rb
|
117
132
|
- spec/spec_helper.rb
|
@@ -141,6 +156,7 @@ signing_key:
|
|
141
156
|
specification_version: 4
|
142
157
|
summary: Serial library for Farmbot
|
143
158
|
test_files:
|
159
|
+
- spec/fixtures/stub_serial_port.rb
|
144
160
|
- spec/lib/ramps_arduino_spec.rb
|
145
161
|
- spec/lib/ramps_arduino_values_received_spec.rb
|
146
162
|
- spec/spec_helper.rb
|
data/Gemfile
DELETED
data/farmbot-serial.gemspec
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "farmbot-serial"
|
7
|
-
spec.version = '0.0.2' # TODO: Fb::VERSION
|
8
|
-
spec.authors = ["Tim Evers", "Rick Carlino"]
|
9
|
-
spec.email = ["rick.carlino@gmail.com"]
|
10
|
-
spec.description = "Serial library for Farmbot"
|
11
|
-
spec.summary = "Serial library for Farmbot"
|
12
|
-
spec.homepage = "http://github.com/farmbot/farmbot-serial"
|
13
|
-
spec.license = "MIT"
|
14
|
-
|
15
|
-
spec.files = `git ls-files`.split($/)
|
16
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
-
spec.require_paths = ["lib"]
|
19
|
-
|
20
|
-
spec.add_development_dependency "bundler"#, "~> 1.3"
|
21
|
-
spec.add_development_dependency "rake"#, "~> 10.4"
|
22
|
-
spec.add_development_dependency "rspec"#, "~> 3.2"
|
23
|
-
spec.add_development_dependency "pry"#, "~> 0.10"
|
24
|
-
spec.add_development_dependency "simplecov"#, "~> 0.9"
|
25
|
-
|
26
|
-
spec.add_runtime_dependency "serialport"#, "~> 1.3"
|
27
|
-
end
|
@@ -1,245 +0,0 @@
|
|
1
|
-
## HARDWARE INTERFACE
|
2
|
-
## ******************
|
3
|
-
|
4
|
-
# 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
|
-
module Fb
|
8
|
-
class HardwareInterfaceArduino
|
9
|
-
|
10
|
-
attr_accessor :serial_port
|
11
|
-
|
12
|
-
attr_reader :is_busy
|
13
|
-
attr_reader :is_error
|
14
|
-
attr_reader :is_done
|
15
|
-
attr_reader :return_values
|
16
|
-
|
17
|
-
# initialize the interface
|
18
|
-
#
|
19
|
-
def initialize(test_mode)
|
20
|
-
@status_debug_msg = $debug_msg
|
21
|
-
@test_mode = test_mode
|
22
|
-
|
23
|
-
# connect to arduino
|
24
|
-
connect_board()
|
25
|
-
|
26
|
-
@external_info = ""
|
27
|
-
@return_values = Queue.new
|
28
|
-
|
29
|
-
@is_busy = false
|
30
|
-
@is_error = false
|
31
|
-
@is_done = false
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
## ARDUINO HANLDING
|
36
|
-
## ****************
|
37
|
-
|
38
|
-
# connect to the serial port and start communicating with the arduino/firmata protocol
|
39
|
-
#
|
40
|
-
def connect_board
|
41
|
-
|
42
|
-
parameters =
|
43
|
-
{
|
44
|
-
"baud" => 115200,
|
45
|
-
"data_bits" => 8,
|
46
|
-
"stop_bits" => 1,
|
47
|
-
"parity" => SerialPort::NONE,
|
48
|
-
"flow_control" => SerialPort::SOFT
|
49
|
-
}
|
50
|
-
|
51
|
-
comm_port = '/dev/ttyACM0'
|
52
|
-
@serial_port = SerialPort.new(comm_port, parameters) if @test_mode == false
|
53
|
-
@serial_port = SerialPortSim.new(comm_port, parameters) if @test_mode == true
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
# write a command to the robot
|
58
|
-
#
|
59
|
-
def write_command(text, log, onscreen)
|
60
|
-
begin
|
61
|
-
|
62
|
-
write_status = create_write_status(text, log, onscreen)
|
63
|
-
write_to_serial(write_status)
|
64
|
-
|
65
|
-
@parameters = []
|
66
|
-
@is_busy = true
|
67
|
-
@is_error = false
|
68
|
-
|
69
|
-
rescue => e
|
70
|
-
handle_execution_exception(e)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# check the responses from the robot
|
75
|
-
#
|
76
|
-
def check_command_execution
|
77
|
-
begin
|
78
|
-
if Time.now - write_status.start < write_status.timeout and @is_done == 0
|
79
|
-
@is_error = true
|
80
|
-
else
|
81
|
-
check_emergency_stop
|
82
|
-
process_feedback(write_status)
|
83
|
-
end
|
84
|
-
rescue => e
|
85
|
-
handle_execution_exception(e)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
def create_write_status(text, log, onscreen)
|
91
|
-
write_status = Fb::HardwareInterfaceArduinoWriteStatus.new
|
92
|
-
write_status.text = text
|
93
|
-
write_status.log = log
|
94
|
-
|
95
|
-
write_status.onscreen = onscreen
|
96
|
-
write_status
|
97
|
-
end
|
98
|
-
|
99
|
-
def handle_execution_exception(e)
|
100
|
-
puts("ST: serial error\n#{e.message}\n#{e.backtrace.inspect}")
|
101
|
-
@serial_port.rts = 1
|
102
|
-
connect_board
|
103
|
-
@is_error = true
|
104
|
-
end
|
105
|
-
|
106
|
-
# set the serial port ready to send and write the text
|
107
|
-
#
|
108
|
-
def write_to_serial(write_status)
|
109
|
-
puts "WR: #{write_status.text}" if write_status.onscreen
|
110
|
-
@serial_port.read_timeout = 2
|
111
|
-
clean_serial_buffer() if @test_mode == false
|
112
|
-
serial_port_write( "#{write_status.text}\n" )
|
113
|
-
end
|
114
|
-
|
115
|
-
# receive all characters coming from the serial port
|
116
|
-
#
|
117
|
-
def process_feedback(write_status)
|
118
|
-
i = @serial_port.read(1)
|
119
|
-
|
120
|
-
if i != nil
|
121
|
-
i.each_char do |c|
|
122
|
-
process_characters(write_status, c)
|
123
|
-
end
|
124
|
-
else
|
125
|
-
sleep 0.001 if @test_mode == false
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
# keep incoming characters in a buffer until it is a complete string
|
130
|
-
#
|
131
|
-
def process_characters(write_status, c)
|
132
|
-
|
133
|
-
if c == "\r" or c == "\n"
|
134
|
-
if write_status.received.length >= 3
|
135
|
-
log_incoming_text(write_status)
|
136
|
-
write_status.split_received
|
137
|
-
process_code_and_params(write_status)
|
138
|
-
end
|
139
|
-
else
|
140
|
-
write_status.received = write_status.received + c
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
# handle the incoming message depending on the first code number
|
145
|
-
#
|
146
|
-
def process_code_and_params(write_status)
|
147
|
-
|
148
|
-
# process the feedback
|
149
|
-
case write_status.code
|
150
|
-
|
151
|
-
# command received by arduino
|
152
|
-
when 'R01'
|
153
|
-
write_status.timeout = 90
|
154
|
-
|
155
|
-
# command is finished
|
156
|
-
when 'R02'
|
157
|
-
write_status.done = 1
|
158
|
-
@is_done = true
|
159
|
-
# command is finished with errors
|
160
|
-
when 'R03'
|
161
|
-
write_status.done = 1
|
162
|
-
@is_done = true
|
163
|
-
# command is still ongoing
|
164
|
-
when 'R04'
|
165
|
-
write_status.start = Time.now
|
166
|
-
write_status.timeout = 90
|
167
|
-
|
168
|
-
# specific feedback that is processes separately
|
169
|
-
else
|
170
|
-
process_value(write_status.code,write_status.params)
|
171
|
-
end
|
172
|
-
|
173
|
-
write_status.received = ''
|
174
|
-
|
175
|
-
end
|
176
|
-
|
177
|
-
# empty the input buffer so no old data is processed
|
178
|
-
#
|
179
|
-
def clean_serial_buffer
|
180
|
-
while (@serial_port.read(1) != nil)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
# write something to the serial port
|
185
|
-
def serial_port_write(text)
|
186
|
-
@serial_port.write( text )
|
187
|
-
end
|
188
|
-
|
189
|
-
# if there is an emergency stop, immediately write it to the arduino
|
190
|
-
#
|
191
|
-
def emergency_stop
|
192
|
-
serial_port_write( "E\n" )
|
193
|
-
end
|
194
|
-
|
195
|
-
# write to log
|
196
|
-
#
|
197
|
-
def log_incoming_text(write_status)
|
198
|
-
puts "RD: #{write_status.received}" if write_status.onscreen
|
199
|
-
end
|
200
|
-
|
201
|
-
# process values received from arduino
|
202
|
-
#
|
203
|
-
def process_value(code,text)
|
204
|
-
|
205
|
-
# get all parameters in the current text
|
206
|
-
return_value = process_value_split(code, text)
|
207
|
-
|
208
|
-
# save the list for the client
|
209
|
-
@return_values << return_value
|
210
|
-
|
211
|
-
end
|
212
|
-
|
213
|
-
def process_value_split(code, text)
|
214
|
-
|
215
|
-
params = Fb::HardwareInterfaceArduinoValuesReceived.new
|
216
|
-
params.code = code
|
217
|
-
params.text = text
|
218
|
-
|
219
|
-
# get all separate parameters from the text
|
220
|
-
text.split(' ').each do |param|
|
221
|
-
|
222
|
-
case code
|
223
|
-
when "R81"
|
224
|
-
# this is the only code that uses two letter parameters
|
225
|
-
par_name = param[0..1].to_s
|
226
|
-
par_value = param[2..-1].to_i
|
227
|
-
else
|
228
|
-
par_name = param[0..0].to_s
|
229
|
-
par_value = param[1..-1].to_i
|
230
|
-
end
|
231
|
-
|
232
|
-
params.load_parameter(par_name, par_value)
|
233
|
-
|
234
|
-
end
|
235
|
-
|
236
|
-
return params
|
237
|
-
end
|
238
|
-
|
239
|
-
def puts(*)
|
240
|
-
# Too many messages in the test buffer right now. Will delete this later.
|
241
|
-
# just disabling it for now.
|
242
|
-
STDOUT.print('x')
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
class HardwareInterfaceArduinoWriteStatus
|
2
|
-
|
3
|
-
attr_accessor :done
|
4
|
-
attr_accessor :code
|
5
|
-
attr_accessor :received
|
6
|
-
attr_accessor :start
|
7
|
-
attr_accessor :log
|
8
|
-
attr_accessor :onscreen
|
9
|
-
attr_accessor :text
|
10
|
-
attr_accessor :params
|
11
|
-
attr_accessor :timeout
|
12
|
-
|
13
|
-
def initialize
|
14
|
-
@done = 0
|
15
|
-
@code = ''
|
16
|
-
@received = ''
|
17
|
-
@text = ''
|
18
|
-
@params = ''
|
19
|
-
@log = false
|
20
|
-
@onscreen = false
|
21
|
-
@start = Time.now
|
22
|
-
@timeout = 5
|
23
|
-
end
|
24
|
-
|
25
|
-
# def is_busy
|
26
|
-
# Time.now - @start < @timeout and @done == 0
|
27
|
-
# end
|
28
|
-
|
29
|
-
def split_received
|
30
|
-
# get the parameter and data part
|
31
|
-
@code = received[0..2].upcase
|
32
|
-
@params = received[3..-1].to_s.upcase.strip
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
data/lib/serial_port_sim.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
## SERIAL PORT SIMULATION
|
2
|
-
## **********************
|
3
|
-
|
4
|
-
# Used for unit tests
|
5
|
-
|
6
|
-
module Fb
|
7
|
-
class SerialPortSim
|
8
|
-
attr_accessor :rts, :read_timeout, :test_serial_read, :test_serial_write
|
9
|
-
|
10
|
-
def initialize(comm_port, parameters)
|
11
|
-
@test_serial_read = ""
|
12
|
-
@test_serial_write = ""
|
13
|
-
end
|
14
|
-
|
15
|
-
def write(text)
|
16
|
-
@test_serial_write = text
|
17
|
-
end
|
18
|
-
|
19
|
-
def read(characters)
|
20
|
-
i = nil
|
21
|
-
@test_serial_read = nil if @test_serial_read == ""
|
22
|
-
|
23
|
-
if @test_serial_read != nil
|
24
|
-
i = @test_serial_read[0]
|
25
|
-
@test_serial_read = @test_serial_read[1..-1]
|
26
|
-
end
|
27
|
-
i
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|