farmbot-serial 0.0.1 → 0.0.2

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.
@@ -1,52 +0,0 @@
1
- module Fb
2
- class Status
3
- attr_accessor :command_refresh, :device_version, :emergency_stop,
4
- :info_command_last, :info_command_next, :info_current_x,
5
- :info_current_x_steps, :info_current_y, :info_current_y_steps,
6
- :info_current_z, :info_current_z_steps, :info_end_stop_x_a,
7
- :info_end_stop_x_b, :info_end_stop_y_a, :info_end_stop_y_b,
8
- :info_end_stop_z_a, :info_end_stop_z_b, :info_movement,
9
- :info_nr_of_commands, :info_status, :info_target_x, :info_target_y,
10
- :info_target_z, :info_pin_8, :info_pin_9, :info_pin_10, :info_pin_13
11
-
12
- def initialize
13
-
14
- @emergency_stop = false;
15
-
16
- @info_command_next = nil
17
- @info_command_last = nil
18
- @info_nr_of_commands = 0
19
- @info_status = 'initializing'
20
- @info_movement = 'idle'
21
-
22
- @info_current_x_steps = 0
23
- @info_current_y_steps = 0
24
- @info_current_z_steps = 0
25
-
26
- @info_current_x = 0
27
- @info_current_y = 0
28
- @info_current_z = 0
29
-
30
- @info_target_x = 0
31
- @info_target_y = 0
32
- @info_target_z = 0
33
-
34
- @info_end_stop_x_a = 0
35
- @info_end_stop_x_b = 0
36
- @info_end_stop_y_a = 0
37
- @info_end_stop_y_b = 0
38
- @info_end_stop_z_a = 0
39
- @info_end_stop_z_b = 0
40
-
41
- @info_pin_8 = 0
42
- @info_pin_9 = 0
43
- @info_pin_10 = 0
44
- @info_pin_13 = 0
45
-
46
- @command_refresh = 0
47
- @device_version = 'UNKNOWN'
48
-
49
- end
50
-
51
- end
52
- end
@@ -1,27 +0,0 @@
1
- describe Fb::HardwareInterfaceArduinoWriteStatus do
2
-
3
- before do
4
- Fb::HardwareInterface.current.status = Fb::Status.new
5
- @ramps = Fb::HardwareInterfaceArduinoWriteStatus.new()
6
- end
7
-
8
- it "is busy 1" do
9
- @ramps.done = 0
10
- busy = @ramps.is_busy
11
- expect(busy).to eq(true)
12
- end
13
-
14
- it "is busy 2" do
15
- @ramps.done = 1
16
- busy = @ramps.is_busy
17
- expect(busy).to eq(false)
18
- end
19
-
20
- it "split parameter" do
21
- @ramps.received = "R00 XXX"
22
- @ramps.split_received()
23
-
24
- expect(@ramps.code).to eq("R00")
25
- expect(@ramps.params).to eq("XXX")
26
- end
27
- end
@@ -1,555 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Fb::HardwareInterfaceArduino do
4
-
5
- before do
6
-
7
-
8
-
9
-
10
- Fb::HardwareInterface.current.status = Fb::Status.new
11
-
12
- @ramps = Fb::HardwareInterfaceArduino.new(true)
13
-
14
- @ramps_param = Fb::HardwareInterfaceParam.new
15
- @ramps_param.ramps_arduino = @ramps
16
-
17
- @ramps.ramps_param = @ramps_param
18
-
19
- end
20
-
21
- # def load_param_values_non_arduino
22
-
23
- it "load param values non arduino" do
24
-
25
- x_per_unit = rand(9999999).to_i
26
- y_per_unit = rand(9999999).to_i
27
- z_per_unit = rand(9999999).to_i
28
-
29
-
30
-
31
-
32
-
33
-
34
- @ramps_param.load_param_values_non_arduino()
35
-
36
- expect(@ramps_param.axis_x_steps_per_unit).to eq(x_per_unit)
37
- expect(@ramps_param.axis_y_steps_per_unit).to eq(y_per_unit)
38
- expect(@ramps_param.axis_z_steps_per_unit).to eq(z_per_unit)
39
-
40
- end
41
-
42
-
43
-
44
- it "load config from database" do
45
-
46
- x_per_unit = rand(9999999).to_i
47
- name = 'MOVEMENT_STEPS_PER_UNIT_X'
48
-
49
-
50
-
51
-
52
- x_per_unit_retrieved = 0
53
-
54
- @ramps_param.params.each do |p|
55
- if p['name'] == name
56
- x_per_unit_retrieved = p['value_db']
57
- end
58
- end
59
-
60
- expect(x_per_unit_retrieved).to eq(x_per_unit)
61
-
62
- end
63
-
64
- # def load_param_names
65
-
66
- it "load param names" do
67
- @ramps_param.params = []
68
- @ramps_param.load_param_names()
69
-
70
- expect(@ramps_param.params.count).to eq($arduino_default_params.count)
71
- end
72
-
73
- # def param_name_add(name, id, default)
74
-
75
- it "param name add" do
76
-
77
- name = rand(9999999).to_s
78
- id = rand(9999999).to_i
79
- default = rand(9999999).to_i
80
-
81
- @ramps_param.param_name_add(name, id, default)
82
-
83
- param = nil
84
- @ramps_param.params.each do |p|
85
- if p['name'] == name
86
- param = p
87
- end
88
- end
89
-
90
- expect(param['name']).to eq(name)
91
- expect(param['id']).to eq(id)
92
- expect(param['default']).to eq(default)
93
-
94
- # repeat again so the part where the param already exists is ran too
95
- @ramps_param.param_name_add(name, id, default)
96
-
97
- end
98
-
99
- # def get_param_by_name(name)
100
-
101
- it "get param by name" do
102
- name = rand(9999999).to_s
103
- id = rand(9999999).to_i
104
- default = rand(9999999).to_i
105
-
106
- @ramps_param.param_name_add(name, id, default)
107
- param = @ramps_param.get_param_by_name(name)
108
-
109
- expect(param['name']).to eq(name)
110
- expect(param['id']).to eq(id)
111
- expect(param['default']).to eq(default)
112
- end
113
-
114
- # def get_param_by_id(id)
115
-
116
- it "get param by id" do
117
- name = rand(9999999).to_s
118
- id = rand(9999999).to_i
119
- default = rand(9999999).to_i
120
-
121
- @ramps_param.param_name_add(name, id, default)
122
- param = @ramps_param.get_param_by_id(id)
123
-
124
- expect(param['name']).to eq(name)
125
- expect(param['id']).to eq(id)
126
- expect(param['default']).to eq(default)
127
- end
128
-
129
- # def get_param(name_or_id, by_name_or_id)
130
-
131
- it "get param (by id)" do
132
- name = rand(9999999).to_s
133
- id = rand(9999999).to_i
134
- default = rand(9999999).to_i
135
-
136
- @ramps_param.param_name_add(name, id, default)
137
- param = @ramps_param.get_param(id, :by_id)
138
-
139
- expect(param['name']).to eq(name)
140
- expect(param['id']).to eq(id)
141
- expect(param['default']).to eq(default)
142
- end
143
-
144
- it "get param (by name)" do
145
-
146
- name = rand(9999999).to_s
147
- id = rand(9999999).to_i
148
- default = rand(9999999).to_i
149
-
150
- @ramps_param.param_name_add(name, id, default)
151
- param = @ramps_param.get_param(name, :by_name)
152
-
153
- expect(param['name']).to eq(name)
154
- expect(param['id']).to eq(id)
155
- expect(param['default']).to eq(default)
156
- end
157
-
158
- # def save_param_value(name_or_id, by_name_or_id, from_device_or_db, value)
159
-
160
- it "save param value (by id, by device)" do
161
- name = rand(9999999).to_s
162
- id = rand(9999999).to_i
163
- default = rand(9999999).to_i
164
- value = rand(9999999).to_i
165
-
166
- @ramps_param.param_name_add(name, id, default)
167
- @ramps_param.save_param_value(id, :by_id, :from_device, value)
168
- param = @ramps_param.get_param(id, :by_id)
169
-
170
- expect(param['name']).to eq(name)
171
- expect(param['id']).to eq(id)
172
- expect(param['default']).to eq(default)
173
- expect(param['value_ar']).to eq(value)
174
-
175
- end
176
-
177
- it "save param value (by name, by device)" do
178
- name = rand(9999999).to_s
179
- id = rand(9999999).to_i
180
- default = rand(9999999).to_i
181
- value = rand(9999999).to_i
182
-
183
- @ramps_param.param_name_add(name, id, default)
184
- @ramps_param.save_param_value(name, :by_name, :from_device, value)
185
- param = @ramps_param.get_param(name, :by_name)
186
-
187
- expect(param['name']).to eq(name)
188
- expect(param['id']).to eq(id)
189
- expect(param['default']).to eq(default)
190
- expect(param['value_ar']).to eq(value)
191
-
192
- end
193
-
194
- it "save param value (by id, by database)" do
195
- name = rand(9999999).to_s
196
- id = rand(9999999).to_i
197
- default = rand(9999999).to_i
198
- value = rand(9999999).to_i
199
-
200
- @ramps_param.param_name_add(name, id, default)
201
- @ramps_param.save_param_value(id, :by_id, :from_db, value)
202
- param = @ramps_param.get_param(id, :by_id)
203
-
204
- expect(param['name']).to eq(name)
205
- expect(param['id']).to eq(id)
206
- expect(param['default']).to eq(default)
207
- expect(param['value_db']).to eq(value)
208
-
209
- end
210
-
211
- it "save param value (by name, by database)" do
212
- name = rand(9999999).to_s
213
- id = rand(9999999).to_i
214
- default = rand(9999999).to_i
215
- value = rand(9999999).to_i
216
-
217
- @ramps_param.param_name_add(name, id, default)
218
- @ramps_param.save_param_value(name, :by_name, :from_db, value)
219
- param = @ramps_param.get_param(name, :by_name)
220
-
221
- expect(param['name']).to eq(name)
222
- expect(param['id']).to eq(id)
223
- expect(param['default']).to eq(default)
224
- expect(param['value_db']).to eq(value)
225
-
226
- end
227
-
228
- # def read_parameter_from_device(id)
229
-
230
- it "read parameter from device" do
231
-
232
- id = 1
233
- value = rand(9999999).to_i
234
-
235
- @ramps.clean_serial_buffer()
236
- @ramps.serial_port.test_serial_write = ""
237
- @ramps.serial_port.test_serial_read = "R01\nR21 P#{id} V#{value}\nR02\n"
238
- @ramps_param.read_parameter_from_device(id)
239
- param = @ramps_param.get_param(id, :by_id)
240
-
241
- expect(param['id']).to eq(id)
242
- expect(param['value_ar']).to eq(value)
243
- end
244
-
245
- # def write_parameter_to_device(id, value)
246
-
247
- it "write parameter to device" do
248
-
249
- id = 1
250
- default = rand(9999999).to_i
251
- value = rand(9999999).to_i
252
-
253
- @ramps_param.save_param_value(id, :by_id, :from_db, value)
254
-
255
- @ramps.clean_serial_buffer()
256
- @ramps.serial_port.test_serial_write = ""
257
- @ramps.serial_port.test_serial_read = "R01\nR02\n"
258
-
259
- @ramps_param.write_parameter_to_device(id, value)
260
-
261
- expect(@ramps.serial_port.test_serial_write).to eq("F22 P#{id} V#{value}\n")
262
-
263
- end
264
-
265
- # def update_param_version_ar
266
-
267
- it "update parameter version from arduino" do
268
-
269
- id = 0
270
- value = rand(9999999).to_i
271
-
272
- @ramps.clean_serial_buffer()
273
- @ramps.serial_port.test_serial_write = ""
274
- @ramps.serial_port.test_serial_read = "R01\nR21 P#{id} V#{value}\nR02\n"
275
-
276
- @ramps_param.update_param_version_ar()
277
-
278
- expect(@ramps_param.param_version_ar).to eq(value)
279
- end
280
-
281
- # def parameters_different
282
-
283
- it "parameters different false" do
284
-
285
- @ramps.serial_port.test_serial_write = ""
286
- @ramps.serial_port.test_serial_read = ""
287
-
288
- @ramps_param.params.each do |p|
289
- p['value_ar'] = p['value_db']
290
- @ramps.serial_port.test_serial_read = @ramps.serial_port.test_serial_read + "R02\n"
291
- end
292
-
293
- different = @ramps_param.parameters_different()
294
-
295
- expect(different).to eq(false)
296
- end
297
-
298
- it "parameters different true" do
299
-
300
- id = 11
301
- value = rand(9999999).to_i
302
-
303
- @ramps.serial_port.test_serial_write = ""
304
- @ramps.serial_port.test_serial_read = ""
305
-
306
- @ramps_param.params.each do |p|
307
- p['value_ar'] = p['value_db']
308
- @ramps.serial_port.test_serial_read = @ramps.serial_port.test_serial_read + "R02\n"
309
- end
310
-
311
- @ramps_param.save_param_value(id, :by_id, :from_db, value)
312
-
313
- different = @ramps_param.parameters_different()
314
-
315
- expect(different).to eq(true)
316
- end
317
-
318
- # def check_and_write_parameter(param)
319
-
320
- it "check and write one parameter, test with similar" do
321
-
322
- name = 'TESTING'
323
- id = 1
324
- value = rand(9999999).to_i
325
- value2 = rand(9999999).to_i
326
-
327
-
328
-
329
- param = @ramps_param.get_param(id, :by_id)
330
-
331
- @ramps.serial_port.test_serial_write = ""
332
- @ramps.serial_port.test_serial_read = "R01\nR21 P#{id} V#{value}\nR02\nR02\n"
333
-
334
- differences_found = @ramps_param.check_and_write_parameter(param)
335
-
336
- expect(differences_found).to eq(false)
337
- end
338
-
339
- it "check and write one parameter, test with different" do
340
-
341
- name = 'TESTING'
342
- id = 1
343
- value = rand(9999999).to_i
344
- value2 = rand(9999999).to_i
345
-
346
-
347
-
348
- param = @ramps_param.get_param(id, :by_id)
349
- @ramps.serial_port.test_serial_write = ""
350
- @ramps.serial_port.test_serial_read = "R01\nR21 P#{id} V#{value2}\nR02\nR02\n"
351
-
352
- differences_found = @ramps_param.check_and_write_parameter(param)
353
-
354
- expect(differences_found).to eq(true)
355
- expect(@ramps.serial_port.test_serial_write).to eq("F22 P#{id} V#{value}\n")
356
- end
357
-
358
-
359
- # def compare_and_write_parameters
360
-
361
- it "compare and write paramters, different" do
362
-
363
- name = 'TESTING'
364
- id = 1
365
-
366
- value0 = rand(9999999).to_i
367
- value1 = rand(9999999).to_i
368
- value2 = rand(9999999).to_i
369
- value3 = rand(9999999).to_i
370
- value4 = rand(9999999).to_i
371
-
372
- @ramps.serial_port.test_serial_write = ""
373
- @ramps.serial_port.test_serial_read = ""
374
-
375
-
376
-
377
- @ramps_param.param_version_db = value3
378
- @ramps_param.param_version_ar = value4
379
-
380
- @ramps_param.params.each do |p|
381
- p['value_ar'] = p['value_db']
382
- end
383
-
384
- @ramps_param.params.each do |p|
385
- if p['id'] == id
386
- p['value_ar'] = value1
387
- p['value_db'] = value2
388
- end
389
- end
390
-
391
- #@ramps_param.save_param_value(id, :by_id, :from_db, value)
392
- @ramps.serial_port.test_serial_write = ""
393
- @ramps.serial_port.test_serial_read = ""
394
-
395
- feedback = ""
396
- @ramps_param.params.each do |p|
397
- if p['id'] != 0
398
- feedback = feedback + "R01\nR02\n"
399
- end
400
- end
401
- feedback = feedback + "R01\nR02\n"
402
- @ramps.serial_port.test_serial_read = feedback
403
-
404
- @ramps_param.compare_and_write_parameters()
405
-
406
- expect(@ramps.serial_port.test_serial_write).to eq("F22 P#{id} V#{value0}\n")
407
- expect(@ramps_param.params_in_sync).to eq(false)
408
- end
409
-
410
- it "compare and write paramters, no difference" do
411
-
412
- name = 'TESTING'
413
- id = 1
414
-
415
- value = rand(9999999).to_i
416
-
417
- @ramps.serial_port.test_serial_write = ""
418
- @ramps.serial_port.test_serial_read = ""
419
-
420
- @ramps_param.param_version_db = value
421
- @ramps_param.param_version_ar = value
422
-
423
- feedback = ""
424
- @ramps_param.params.each do |p|
425
- if p['id'] != 0
426
- feedback = feedback + "R01\nR02\n"
427
- end
428
- end
429
- @ramps.serial_port.test_serial_read = feedback
430
-
431
- @ramps_param.compare_and_write_parameters()
432
-
433
- expect(@ramps.serial_port.test_serial_write).to eq("")
434
- expect(@ramps_param.params_in_sync).to eq(true)
435
- end
436
-
437
- it "compare and write paramters, different version, all parameters identical" do
438
-
439
- name = 'TESTING'
440
- id = 1
441
-
442
- value = rand(9999999).to_i
443
-
444
- @ramps.serial_port.test_serial_write = ""
445
- @ramps.serial_port.test_serial_read = ""
446
-
447
- @ramps_param.params.each do |p|
448
- p['value_ar'] = p['value_db']
449
- end
450
-
451
- @ramps_param.param_version_db = value
452
- @ramps_param.param_version_ar = value - 1
453
-
454
-
455
-
456
- feedback = ""
457
- @ramps_param.params.each do |p|
458
- if p['id'] != 0
459
- feedback = feedback + "R01\nR02\n"
460
- end
461
- end
462
- feedback = feedback + "R01\nR02\n"
463
- @ramps.serial_port.test_serial_read = feedback
464
- @ramps.serial_port.test_serial_write = ""
465
-
466
- @ramps_param.compare_and_write_parameters()
467
-
468
- expect(@ramps.serial_port.test_serial_write).to eq("F22 P0 V#{value}\n")
469
- expect(@ramps_param.params_in_sync).to eq(true)
470
- end
471
-
472
-
473
- # def check_parameters
474
-
475
- it "check parameter, no difference" do
476
-
477
- name = 'TESTING'
478
- id = 1
479
-
480
- db_version = rand(9999999).to_i
481
-
482
-
483
-
484
- feedback = ""
485
- feedback = feedback + "R01\nR21 P0 V#{db_version}\nR02\n"
486
- @ramps_param.params.each do |p|
487
- if p['id'] != 0
488
- feedback = feedback + "R01\nR02\n"
489
- end
490
- end
491
- #feedback = feedback + "R01\nR02\n"
492
-
493
- @ramps.serial_port.test_serial_read = feedback
494
- @ramps.serial_port.test_serial_write = ""
495
-
496
- #@ramps.serial_port.test_serial_read =
497
-
498
- @ramps_param.check_parameters()
499
-
500
- expect(@ramps_param.params_in_sync).to eq(true)
501
-
502
- end
503
-
504
- it "check parameter, different" do
505
-
506
- name = 'TESTING'
507
- id = 1
508
-
509
- db_version = rand(9999999).to_i
510
- ar_version = rand(9999999).to_i
511
-
512
- value0 = rand(9999999).to_i
513
- value1 = rand(9999999).to_i
514
- value2 = rand(9999999).to_i
515
-
516
- @ramps.serial_port.test_serial_write = ""
517
- @ramps.serial_port.test_serial_read = ""
518
-
519
-
520
-
521
-
522
-
523
- feedback = ""
524
- feedback = feedback + "R01\nR21 P0 V#{ar_version}\nR02\n"
525
- @ramps_param.params.each do |p|
526
- if p['id'] != 0
527
- feedback = feedback + "R01\nR02\n"
528
- end
529
- end
530
- feedback = feedback + "R01\nR02\n"
531
- @ramps.serial_port.test_serial_write = ""
532
- @ramps.serial_port.test_serial_read = feedback
533
-
534
- # make sure all parameters in device and database are equal
535
- @ramps_param.params.each do |p|
536
- p['value_ar'] = p['value_db']
537
- end
538
-
539
- # then only change one parameter
540
- @ramps_param.params.each do |p|
541
- if p['id'] == id
542
- p['value_ar'] = value1
543
- p['value_db'] = value2
544
- end
545
- end
546
-
547
- @ramps_param.check_parameters()
548
-
549
- expect(@ramps_param.params_in_sync).to eq(false)
550
- expect(@ramps.serial_port.test_serial_write).to eq("F22 P#{id} V#{value0}\n")
551
-
552
- end
553
-
554
- end
555
-