farmbot-serial 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/arduino/status.rb +4 -0
- data/spec/fakes/fake_gcode.rb +7 -0
- data/spec/lib/arduino/event_machine_spec.rb +46 -0
- data/spec/lib/arduino/incoming_handler_spec.rb +65 -0
- data/spec/lib/arduino/outgoing_handler_spec.rb +1 -1
- data/spec/lib/arduino/status_spec.rb +7 -1
- data/spec/spec_helper.rb +1 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f4002b462441175c6e02aa8f0cf3da3a1b5bb83
|
4
|
+
data.tar.gz: 2c9aca479eb11acf3285ea40c0bf4b051f260b3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f90a94e0e72c70cd0d5728e184e3f5438ea6ae7be9ac5c06bae6fe2eb65c908762c50a5c398d3b78f561362514e7004aa76837e18065907ecb323342a8e46bfc
|
7
|
+
data.tar.gz: efde1a728ade01a0be1ded75c3826e27dee3a5fe03fb6f246d316601eb695de8dfea3bc93ac52c9fdae765fd783a2d6ab9ff563b543117e9288cc11d78085ecb
|
data/lib/arduino/status.rb
CHANGED
@@ -41,4 +41,50 @@ describe FB::ArduinoEventMachine do
|
|
41
41
|
em.clear_buffer
|
42
42
|
expect(em.buffer).to eq('')
|
43
43
|
end
|
44
|
+
|
45
|
+
it 'receives data (normal end of chunk)' do
|
46
|
+
allow(em).to receive(:add_to_buffer).ordered
|
47
|
+
allow(em).to receive(:send_buffer).ordered
|
48
|
+
allow(em).to receive(:clear_buffer).ordered
|
49
|
+
allow(em.q).to receive(:clear_buffer)
|
50
|
+
em.receive_data("\r\n")
|
51
|
+
expect(em).to have_received(:add_to_buffer)
|
52
|
+
expect(em).to have_received(:send_buffer)
|
53
|
+
expect(em).to have_received(:clear_buffer)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'receives data (incomplete end of chunk)' do
|
57
|
+
allow(em).to receive(:add_to_buffer).ordered
|
58
|
+
allow(em).to receive(:send_buffer).ordered
|
59
|
+
allow(em).to receive(:clear_buffer).ordered
|
60
|
+
msg = "R00\n"
|
61
|
+
em.receive_data(msg)
|
62
|
+
expect(em).to have_received(:add_to_buffer).with(msg)
|
63
|
+
expect(em).to have_received(:send_buffer)
|
64
|
+
expect(em).to have_received(:clear_buffer)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'receives data (middle of chunk)' do
|
68
|
+
allow(em).to receive(:add_to_buffer)
|
69
|
+
allow(em).to receive(:send_buffer).ordered
|
70
|
+
allow(em).to receive(:clear_buffer).ordered
|
71
|
+
msg = "R01\n"
|
72
|
+
em.receive_data(msg)
|
73
|
+
expect(em).to have_received(:add_to_buffer).with(msg)
|
74
|
+
expect(em).to_not have_received(:send_buffer)
|
75
|
+
expect(em).to_not have_received(:clear_buffer)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'unbinds' do
|
79
|
+
allow(EM).to receive(:stop)#.ordered
|
80
|
+
em.unbind
|
81
|
+
expect(EM).to have_received(:stop)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'connects a bot' do
|
85
|
+
allow(EM).to receive(:attach)
|
86
|
+
em.class.connect(bot)
|
87
|
+
expect(EM).to have_received(:attach).with(bot.serial_port, em.class)
|
88
|
+
expect(em.class.arduino).to be(bot)
|
89
|
+
end
|
44
90
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe FB::IncomingHandler do
|
5
|
+
let(:bot) { FakeArduino.new }
|
6
|
+
let(:handler) { FB::IncomingHandler.new(bot) }
|
7
|
+
|
8
|
+
it 'handles unknowns' do
|
9
|
+
handler.execute(FakeGcode.new('hello', 'abc'))
|
10
|
+
expectation = "hello is a valid GCode, but no input handler method exists"
|
11
|
+
expect(bot.logger.message).to eq(expectation)
|
12
|
+
end
|
13
|
+
|
14
|
+
# def report_parameter_value(gcode)
|
15
|
+
# bot.status.set_pin(gcode.value_of(:P), gcode.value_of(:V))
|
16
|
+
# end
|
17
|
+
|
18
|
+
it 'reports the value of a parameter' do
|
19
|
+
handler.report_parameter_value(FB::Gcode.new { "A1 P1 V0" })
|
20
|
+
expect(bot.status.pin(1)).to eq(:off)
|
21
|
+
handler.report_parameter_value(FB::Gcode.new { "A1 P1 V1" })
|
22
|
+
expect(bot.status.pin(1)).to eq(:on)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'reports end stops' do
|
26
|
+
gcode = FB::Gcode.new { "LOL1 S99" }
|
27
|
+
handler.reporting_end_stops(gcode)
|
28
|
+
expect(bot.status[:S]).to eq(99)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'reports current position' do
|
32
|
+
gcode = FB::Gcode.new { "LOL1 X99" }
|
33
|
+
handler.report_current_position(gcode)
|
34
|
+
expect(bot.status[:X]).to eq(99)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'reports the value of a status' do
|
38
|
+
handler.report_status_value(FB::Gcode.new { "A1 P1 V0" })
|
39
|
+
expect(bot.status.pin(1)).to eq(:off)
|
40
|
+
handler.report_status_value(FB::Gcode.new { "A1 P1 V1" })
|
41
|
+
expect(bot.status.pin(1)).to eq(:on)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'responds to message received' do
|
45
|
+
handler.received(FakeGcode.new('doesnt', 'matter'))
|
46
|
+
expect(bot.status[:busy]).to eq(1)
|
47
|
+
end
|
48
|
+
it 'responds to idle message' do
|
49
|
+
handler.idle(FakeGcode.new('doesnt', 'matter'))
|
50
|
+
expect(bot.status[:busy]).to eq(0)
|
51
|
+
end
|
52
|
+
it 'responds to done message' do
|
53
|
+
handler.done(FakeGcode.new('doesnt', 'matter'))
|
54
|
+
expect(bot.status[:busy]).to eq(0)
|
55
|
+
end
|
56
|
+
it 'responds to busy message' do
|
57
|
+
handler.busy(FakeGcode.new('doesnt', 'matter'))
|
58
|
+
expect(bot.status[:busy]).to eq(1)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'has not implemented report_software_version' do
|
62
|
+
expectation = handler.report_software_version("Does not matter")
|
63
|
+
expect(expectation).to be_nil
|
64
|
+
end
|
65
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe FB::
|
3
|
+
describe FB::Status do
|
4
4
|
|
5
5
|
let(:status) { FB::Status.new }
|
6
6
|
|
@@ -51,5 +51,11 @@ describe FB::IncomingHandler do
|
|
51
51
|
expect(status.pin(2)).to eq(:unknown)
|
52
52
|
end
|
53
53
|
|
54
|
+
it 'serializes into a hash' do
|
55
|
+
reality = status.instance_variable_get("@info").to_h
|
56
|
+
perception = status.to_h
|
57
|
+
expect(perception).to eq(reality)
|
58
|
+
end
|
59
|
+
|
54
60
|
end
|
55
61
|
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.6.0
|
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-05-
|
12
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -145,9 +145,11 @@ files:
|
|
145
145
|
- lib/gcode.rb
|
146
146
|
- lib/gcode.yml
|
147
147
|
- spec/fakes/fake_arduino.rb
|
148
|
+
- spec/fakes/fake_gcode.rb
|
148
149
|
- spec/fakes/fake_logger.rb
|
149
150
|
- spec/fakes/fake_serial_port.rb
|
150
151
|
- spec/lib/arduino/event_machine_spec.rb
|
152
|
+
- spec/lib/arduino/incoming_handler_spec.rb
|
151
153
|
- spec/lib/arduino/outgoing_handler_spec.rb
|
152
154
|
- spec/lib/arduino/status_spec.rb
|
153
155
|
- spec/lib/arduino_spec.rb
|
@@ -179,9 +181,11 @@ specification_version: 4
|
|
179
181
|
summary: Serial library for Farmbot
|
180
182
|
test_files:
|
181
183
|
- spec/fakes/fake_arduino.rb
|
184
|
+
- spec/fakes/fake_gcode.rb
|
182
185
|
- spec/fakes/fake_logger.rb
|
183
186
|
- spec/fakes/fake_serial_port.rb
|
184
187
|
- spec/lib/arduino/event_machine_spec.rb
|
188
|
+
- spec/lib/arduino/incoming_handler_spec.rb
|
185
189
|
- spec/lib/arduino/outgoing_handler_spec.rb
|
186
190
|
- spec/lib/arduino/status_spec.rb
|
187
191
|
- spec/lib/arduino_spec.rb
|