rfbeam 0.4.3 → 0.4.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
  SHA256:
3
- metadata.gz: 9cd82af6ee6d040de78fe19f179f643b0617c37b09a0f0f79ad952d05514b934
4
- data.tar.gz: 4efe06f17ac00595fa1407212cc77f909bf3fcdcaacf190587daa73424132f41
3
+ metadata.gz: e21d45a85534f9324053e8874f3c8f75b52a41eaaa9cf3efc37d1e8116a63b46
4
+ data.tar.gz: 0cdd3969ca1be5db0fb11a685b45afb61c7d24080ca8b4526a27fa91c2138ac4
5
5
  SHA512:
6
- metadata.gz: 07fac5306643bdac200b16c6aec4515602e6dcd42f96dc7198706d863fece4fc1b648accb1da80a48959826a50e9fcaaa6a4d7dbbc9f8775416c17faf3b49b35
7
- data.tar.gz: 64e52d170ad21a8a6fb98006310b3e874f62300162c25bd3a3de5d6f158a55652add50c1646be4c3f8d597f580ebc4c7b3f7a848212f190cf6836508e1dcf494
6
+ metadata.gz: bc9d798e398e5d134a75f1c80bb0c09fbecddb968f3438d58c8803497cb00f31e8a2994a3f5075c6ecd99e233d2045c98b6b7c0c3d6c34d574dd7efcd9834340
7
+ data.tar.gz: a8e378dc22187394d953bd134933574b524630b7edee5a1d4a2749ca280a72b7eb48a212f8a8bf02f0bb2a17cdd727dfa5714a3149dd04db36e62af34c38288f
data/.rubocop.yml CHANGED
@@ -1,10 +1,17 @@
1
+ inherit_gem:
2
+ syntax_tree: config/rubocop.yml
3
+
1
4
  AllCops:
2
5
  TargetRubyVersion: 3.1
6
+ NewCops: enable
3
7
 
4
8
  Layout/LineLength:
5
9
  Max: 120
6
10
  AutoCorrect: true
7
11
 
12
+ Style/StringLiterals:
13
+ EnforcedStyle: single_quotes
14
+
8
15
  Metrics/ModuleLength:
9
16
  Enabled: false
10
17
 
data/Gemfile CHANGED
@@ -1,26 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in rfbeam.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ gem 'minitest', '~> 5.0'
9
+ gem 'rake', '~> 13.0'
10
+ gem 'tty-logger', '~> 0.6.0'
11
+ gem 'tty-screen', '~> 0.8.1'
12
+ gem 'tty-spinner', '~> 0.9.3'
13
+ gem 'tty-table', '~> 0.12.0'
14
+ gem 'unicode_plot', '~> 0.0.5'
9
15
 
10
- gem "minitest", "~> 5.0"
11
-
12
- gem "rubocop", "~> 1.21"
13
-
14
- gem "tty-table", "~> 0.12.0"
15
-
16
- gem "tty-spinner", "~> 0.9.3"
17
-
18
- gem "unicode_plot", "~> 0.0.5"
19
-
20
- gem "tty-logger", "~> 0.6.0"
21
-
22
- gem "tty-screen", "~> 0.8.1"
23
-
24
- gem "tty-option", "~> 0.2.0"
25
-
26
- gem "tty-command", "~> 0.10.1"
16
+ gem "syntax_tree", "~> 6.1", :groups => [:development, :test]
17
+ gem "rubocop", "~> 1.39", :groups => [:development, :test]
data/Gemfile.lock CHANGED
@@ -1,10 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rfbeam (0.4.3)
4
+ rfbeam (0.4.5)
5
5
  activesupport (~> 6.1.0)
6
6
  rubyserial (~> 0.6.0)
7
7
  thor (~> 1.2.1)
8
+ tty-logger (~> 0.6.0)
9
+ tty-screen (~> 0.8.1)
10
+ tty-spinner (~> 0.9.3)
11
+ tty-table (~> 0.12.0)
12
+ unicode_plot (~> 0.0.5)
8
13
 
9
14
  GEM
10
15
  remote: https://rubygems.org/
@@ -28,6 +33,7 @@ GEM
28
33
  ast (~> 2.4.1)
29
34
  pastel (0.8.0)
30
35
  tty-color (~> 0.5)
36
+ prettier_print (1.2.1)
31
37
  rainbow (3.1.1)
32
38
  rake (13.0.6)
33
39
  regexp_parser (2.6.1)
@@ -52,14 +58,13 @@ GEM
52
58
  unicode-display_width (>= 1.5, < 3.0)
53
59
  unicode_utils (~> 1.4)
54
60
  strings-ansi (0.2.0)
61
+ syntax_tree (6.1.1)
62
+ prettier_print (>= 1.2.0)
55
63
  thor (1.2.1)
56
64
  tty-color (0.6.0)
57
- tty-command (0.10.1)
58
- pastel (~> 0.8)
59
65
  tty-cursor (0.7.1)
60
66
  tty-logger (0.6.0)
61
67
  pastel (~> 0.8)
62
- tty-option (0.2.0)
63
68
  tty-screen (0.8.1)
64
69
  tty-spinner (0.9.3)
65
70
  tty-cursor (~> 0.7)
@@ -83,10 +88,9 @@ DEPENDENCIES
83
88
  minitest (~> 5.0)
84
89
  rake (~> 13.0)
85
90
  rfbeam!
86
- rubocop (~> 1.21)
87
- tty-command (~> 0.10.1)
91
+ rubocop (~> 1.39)
92
+ syntax_tree (~> 6.1)
88
93
  tty-logger (~> 0.6.0)
89
- tty-option (~> 0.2.0)
90
94
  tty-screen (~> 0.8.1)
91
95
  tty-spinner (~> 0.9.3)
92
96
  tty-table (~> 0.12.0)
data/README.md CHANGED
@@ -27,7 +27,7 @@ The RfBeam class will return the path of any connected modules
27
27
 
28
28
  Simple pass the path and baude rate to initialise a new radar object
29
29
 
30
- RfBeam::K_ld7.new("/dev/ttyUSB0", 115200) do |radar|
30
+ RfBeam::KLD7.new("/dev/ttyUSB0", 115200) do |radar|
31
31
  puts radar.config
32
32
  end
33
33
 
@@ -285,7 +285,7 @@ radar.micro_detection_sensitivty = 4
285
285
 
286
286
  ## CLI
287
287
 
288
- ``` fish
288
+ ```fish
289
289
  ❯ bundle exec rfbeam list
290
290
 
291
291
  +--+------------+------------------+
data/Rakefile CHANGED
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
5
 
6
6
  Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/test_*.rb"]
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/test_*.rb']
10
10
  end
11
11
 
12
- require "rubocop/rake_task"
12
+ require 'rubocop/rake_task'
13
13
 
14
14
  RuboCop::RakeTask.new
15
15
 
data/exe/rfbeam CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'rfbeam'
4
5
 
data/lib/rfbeam/cli.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thor'
2
4
  require 'rfbeam'
3
5
  require 'tty-table'
@@ -8,7 +10,7 @@ require 'unicode_plot'
8
10
 
9
11
  module RfBeam
10
12
  class CLI < Thor
11
- attr_accessor :radar, :logger
13
+ attr_accessor :logger
12
14
 
13
15
  desc 'list', 'List available radar modules'
14
16
  def list
@@ -18,7 +20,7 @@ module RfBeam
18
20
 
19
21
  table = TTY::Table.new(header: %w[id Path Version])
20
22
 
21
- devices.each.with_index { |path, index| table << ["#{index}", path, radar(index).sw_version] }
23
+ devices.each.with_index { |path, index| table << [index.to_s, path, radar(index).sw_version] }
22
24
  puts table.render(:ascii)
23
25
  end
24
26
 
@@ -44,13 +46,13 @@ module RfBeam
44
46
  desc 'ddat <radar_id>', 'stream any valid detections, stop stream with q and enter'
45
47
  option :stream, type: :boolean, aliases: '-s', desc: 'Stream the data from the device'
46
48
  def ddat(radar_id)
47
- cli = RfBeam::KLD7::CliOutput.new(radar_id)
49
+ cli = RfBeam::Kld7::CliOutput.new(radar_id)
48
50
  cli.display(:ddat, stream: options[:stream])
49
51
  end
50
52
 
51
53
  desc 'pdat <radar_id>', 'Display Tracked Targets'
52
54
  def pdat(radar_id)
53
- cli = RfBeam::KLD7::CliOutput.new(radar_id)
55
+ cli = RfBeam::Kld7::CliOutput.new(radar_id)
54
56
  cli.display(:pdat, stream: options[:stream])
55
57
  end
56
58
 
@@ -58,7 +60,7 @@ module RfBeam
58
60
  option :stream, type: :boolean, aliases: '-s', desc: 'Stream the data from the device'
59
61
  option :raw, type: :boolean, aliases: '-r', desc: 'Display raw data'
60
62
  def rfft(radar_id)
61
- plotter = RfBeam::KLD7::CliOutput.new(radar_id)
63
+ plotter = RfBeam::Kld7::CliOutput.new(radar_id)
62
64
  if options[:raw]
63
65
  print radar(radar_id).rfft
64
66
  else
@@ -68,7 +70,7 @@ module RfBeam
68
70
 
69
71
  desc 'tdat <radar_id>', 'Display tracked target data'
70
72
  def tdat(radar_id)
71
- cli = RfBeam::KLD7::CliOutput.new(radar_id)
73
+ cli = RfBeam::Kld7::CliOutput.new(radar_id)
72
74
  cli.display(:tdat, stream: options[:stream])
73
75
  end
74
76
 
@@ -79,7 +81,7 @@ module RfBeam
79
81
  @logger = TTY::Logger.new
80
82
  return @logger.warning 'No Radar modules found.' unless devices.count.positive?
81
83
 
82
- RfBeam::K_ld7.new(devices[id.to_i])
84
+ RfBeam::KLD7.new(devices[id.to_i])
83
85
  end
84
86
  end
85
87
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'tty-table'
2
4
 
3
5
  module RfBeam
4
- module KLD7
6
+ module Kld7
5
7
  class CliFormatter
6
8
  def tdat(data)
7
9
  { dist: data[2], speed: data[3], angle: data[4], mag: data[5] }
@@ -11,7 +13,7 @@ module RfBeam
11
13
  table = TTY::Table.new header: ['index', 'dist (M)', 'speed (Km/h)', 'angle (°)', 'mag (db)']
12
14
  count = data[1] / 8
13
15
  data.shift(2)
14
- count.times.with_index do |index|
16
+ count.times do |index|
15
17
  values = data.shift(4).map { |value| value.to_f / 100.0 }
16
18
  table << [index, values].flatten
17
19
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'unicode_plot'
2
4
  require 'io/console'
3
5
  require 'stringio'
@@ -5,15 +7,17 @@ require 'tty-screen'
5
7
  require 'tty-logger'
6
8
 
7
9
  module RfBeam
8
- module KLD7
10
+ module Kld7
9
11
  class CliOutput
10
12
  attr_reader :radar
11
13
 
12
14
  def initialize(radar_id)
13
15
  devices = RfBeam.connected
14
- return TTY::Logger.new.warning 'No Radar modules found.' unless devices.count.positive?
15
-
16
- @radar = RfBeam::K_ld7.new(devices[radar_id.to_i])
16
+ if devices.empty?
17
+ TTY::Logger.new.warn 'No Radar modules found.'
18
+ else
19
+ @radar = RfBeam::KLD7.new(devices[radar_id.to_i])
20
+ end
17
21
  end
18
22
 
19
23
  def display(type, stream: false)
@@ -39,10 +43,10 @@ module RfBeam
39
43
  $stdout.print "\e[0J"
40
44
  $stdout.flush
41
45
 
42
- if @streaming
43
- n = lines.count
44
- $stdout.print "\e[#{n}F"
45
- end
46
+ return unless @streaming
47
+
48
+ n = lines.count
49
+ $stdout.print "\e[#{n}F"
46
50
  end
47
51
 
48
52
  def stream_plot(type)
@@ -59,7 +63,7 @@ module RfBeam
59
63
 
60
64
  def monitor_keypress
61
65
  loop do
62
- key = STDIN.getch
66
+ key = $stdin.getch
63
67
  if key.downcase == 'q'
64
68
  @streaming = false
65
69
  break
@@ -76,6 +80,7 @@ module RfBeam
76
80
  end
77
81
 
78
82
  def display_ddat(stream)
83
+ data = @radar.ddat
79
84
  if stream
80
85
  @streaming = true
81
86
  Thread.new { monitor_keypress }
@@ -83,28 +88,28 @@ module RfBeam
83
88
  logger = TTY::Logger.new
84
89
  loop do
85
90
  break unless @streaming
91
+
86
92
  spinner.spin
87
- data = @radar.ddat
88
- spinner.update title: "Searching... #{data[:detection_str]}"
89
- logger.success "#{@radar.tdat}" if data[:detection]
93
+ spinner.update title: "Detection: #{DETECTION_FLAGS[data[2]]}"
94
+ logger.success @radar.tdat.to_s unless data[2].zero?
90
95
  end
91
96
  else
92
- puts RfBeam::KLD7::CliFormatter.new.ddat(@radar.ddat)
97
+ puts RfBeam::Kld7::CliFormatter.new.ddat(data)
93
98
  end
94
99
  end
95
100
 
96
101
  def display_tdat(stream)
97
- puts RfBeam::KLD7::CliFormatter.new.tdat(@radar.tdat)
102
+ puts RfBeam::Kld7::CliFormatter.new.tdat(@radar.tdat)
98
103
  end
99
104
 
100
105
  def display_pdat(stream)
101
- table = RfBeam::KLD7::CliFormatter.new.pdat_table(@radar.pdat)
106
+ table = RfBeam::Kld7::CliFormatter.new.pdat_table(@radar.pdat)
102
107
  puts "\n Detected Raw Targets"
103
108
  puts table.render(:unicode, alignment: :center)
104
109
  end
105
110
 
106
111
  def rfft_plot
107
- width = TTY::Screen.width * 0.65
112
+ screen_width = TTY::Screen.width * 0.65
108
113
  data = rfft_plot_data(@radar.rfft)
109
114
  plot =
110
115
  UnicodePlot.lineplot(
@@ -113,7 +118,7 @@ module RfBeam
113
118
  name: 'IF1/2 Averaged',
114
119
  title: 'Raw FFT',
115
120
  height: 25,
116
- width: width,
121
+ width: screen_width,
117
122
  xlabel: 'Speed (km/h)',
118
123
  ylabel: 'Signal (db)',
119
124
  xlim: [-128, 128],
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RfBeam
2
- module KLD7
4
+ module Kld7
3
5
  # All supported Serial port baude rates
4
6
  BAUDE_RATES = { 0 => 115_200, 1 => 460_800, 2 => 921_600, 3 => 2_000_000, 4 => 3_000_000 }.freeze
5
7
 
@@ -31,158 +33,231 @@ module RfBeam
31
33
  speed: %w[Low High]
32
34
  }.freeze
33
35
 
34
- Param =
35
- Struct.new(:name, :grps_index, :description, :default, :units, :values) do
36
- def initialize(name:, grps_index:, description: nil, default: nil, units: nil, values: [])
37
- super(name, grps_index, description, default, units, values)
38
- end
36
+ class Param
37
+ attr_accessor :name, :grps_index, :description, :default, :units, :str_values
38
+
39
+ def initialize(name:, grps_index:, options: {})
40
+ @name = name
41
+ @grps_index = grps_index
42
+ @description = options.fetch(:description, nil)
43
+ @default = options.fetch(:default, nil)
44
+ @units = options.fetch(:units, nil)
45
+ @str_values = options.fetch(:str_values, [])
39
46
  end
47
+ end
40
48
 
41
49
  RADAR_PARAMETERS = {
42
- sw_version: Param.new(name: 'Software Version', grps_index: 2, default: 'K-LD7_APP-RFB-XXXX'),
50
+ sw_version: Param.new(name: 'Software Version', grps_index: 2, options: { default: 'K-LD7_APP-RFB-XXXX' }),
43
51
  base_frequency:
44
52
  Param.new(
45
53
  name: 'Base Frequency',
46
54
  grps_index: 3,
47
- description: '0 = Low, 1 = Middle, 2 = High',
48
- default: 1,
49
- values: %w[Low Middle High]
55
+ options: {
56
+ description: '0 = Low, 1 = Middle, 2 = High',
57
+ default: 1,
58
+ str_values: %w[Low Middle High]
59
+ }
50
60
  ),
51
61
  max_speed:
52
62
  Param.new(
53
63
  name: 'Maximum Speed',
54
64
  grps_index: 4,
55
- description: '0 = 12km/h, 1 = 25km/h, 2 = 50km/h, 3 = 100km/h',
56
- default: 1,
57
- units: 'km/h',
58
- values: %w[12.5 25 50 100]
65
+ options: {
66
+ description: '0 = 12km/h, 1 = 25km/h, 2 = 50km/h, 3 = 100km/h',
67
+ default: 1,
68
+ units: 'km/h',
69
+ str_values: %w[12.5 25 50 100]
70
+ }
59
71
  ),
60
72
  max_range:
61
73
  Param.new(
62
74
  name: 'Maximum Range',
63
75
  grps_index: 5,
64
- description: '0 = 5m, 1 = 10m, 2 = 30m, 3 = 100m',
65
- default: 1,
66
- values: %w[5m 10m 30m 100m]
76
+ options: {
77
+ description: '0 = 5m, 1 = 10m, 2 = 30m, 3 = 100m',
78
+ default: 1,
79
+ str_values: %w[5m 10m 30m 100m]
80
+ }
67
81
  ),
68
82
  threshold_offset:
69
- Param.new(name: 'Threshold Offset', grps_index: 6, description: '10db - 60db', default: 30, units: 'db'),
83
+ Param.new(
84
+ name: 'Threshold Offset',
85
+ grps_index: 6,
86
+ options: {
87
+ description: '10db - 60db',
88
+ default: 30,
89
+ units: 'db'
90
+ }
91
+ ),
70
92
  tracking_filter:
71
93
  Param.new(
72
94
  name: 'Tracking Filter Type',
73
95
  grps_index: 7,
74
- description: '0 = Standard, 2 = Fast Detection, 3 = Long Visibility',
75
- default: 0,
76
- values: ['standard', 'Fast Detection', 'Long Visibility']
96
+ options: {
97
+ description: '0 = Standard, 2 = Fast Detection, 3 = Long Visibility',
98
+ default: 0,
99
+ str_values: ['standard', 'Fast Detection', 'Long Visibility']
100
+ }
77
101
  ),
78
102
  vibration_suppression:
79
103
  Param.new(
80
104
  name: 'Vibration Suppression',
81
105
  grps_index: 8,
82
- description: '0-16, 0 = No Suppression, 16 = High Suppression',
83
- default: 2
106
+ options: {
107
+ description: '0-16, 0 = No Suppression, 16 = High Suppression',
108
+ default: 2
109
+ }
84
110
  ),
85
111
  min_detection_distance:
86
112
  Param.new(
87
113
  name: 'Minimum Detection Distance',
88
114
  grps_index: 9,
89
- description: '0 - 100% of range setting',
90
- default: 0,
91
- units: '%'
115
+ options: {
116
+ description: '0 - 100% of range setting',
117
+ default: 0,
118
+ units: '%'
119
+ }
92
120
  ),
93
121
  max_detection_distance:
94
122
  Param.new(
95
123
  name: 'Maximum Detection Distance',
96
124
  grps_index: 10,
97
- description: '0 - 100% of range setting',
98
- default: 50,
99
- units: '%'
125
+ options: {
126
+ description: '0 - 100% of range setting',
127
+ default: 50,
128
+ units: '%'
129
+ }
100
130
  ),
101
131
  min_detection_angle:
102
- Param.new(name: 'Minimum Detection Angle', grps_index: 11, description: '-90° - 90°', default: -90, units: '°'),
132
+ Param.new(
133
+ name: 'Minimum Detection Angle',
134
+ grps_index: 11,
135
+ options: {
136
+ description: '-90° - 90°',
137
+ default: -90,
138
+ units: '°'
139
+ }
140
+ ),
103
141
  max_detection_angle:
104
- Param.new(name: 'Maximum Detection Angle', grps_index: 12, description: '-90° - 90°', default: 90, units: '°'),
142
+ Param.new(
143
+ name: 'Maximum Detection Angle',
144
+ grps_index: 12,
145
+ options: {
146
+ description: '-90° - 90°',
147
+ default: 90,
148
+ units: '°'
149
+ }
150
+ ),
105
151
  min_detection_speed:
106
152
  Param.new(
107
153
  name: 'Minimum Detection Speed',
108
154
  grps_index: 13,
109
- description: '0 - 100% of speed setting',
110
- default: 0,
111
- units: '%'
155
+ options: {
156
+ description: '0 - 100% of speed setting',
157
+ default: 0,
158
+ units: '%'
159
+ }
112
160
  ),
113
161
  max_detection_speed:
114
162
  Param.new(
115
163
  name: 'Maximum Detection Speed',
116
164
  grps_index: 14,
117
- description: '0 - 100% of speed setting',
118
- default: 100,
119
- units: '%'
165
+ options: {
166
+ description: '0 - 100% of speed setting',
167
+ default: 100,
168
+ units: '%'
169
+ }
120
170
  ),
121
171
  detection_direction:
122
172
  Param.new(
123
173
  name: 'Detection Direction',
124
174
  grps_index: 15,
125
- description: '0 = Receding, 1 = Approaching, 2 = Both',
126
- default: 2,
127
- values: %w[Receding Approaching Both]
175
+ options: {
176
+ description: '0 = Receding, 1 = Approaching, 2 = Both',
177
+ default: 2,
178
+ str_values: %w[Receding Approaching Both]
179
+ }
128
180
  ),
129
181
  range_threshold:
130
182
  Param.new(
131
183
  name: 'Range Threshold',
132
184
  grps_index: 16,
133
- description: '0 - 100% of range setting',
134
- default: 10,
135
- units: '%'
185
+ options: {
186
+ description: '0 - 100% of range setting',
187
+ default: 10,
188
+ units: '%'
189
+ }
136
190
  ),
137
191
  angle_threshold:
138
- Param.new(name: 'Angle Threshold', grps_index: 17, description: '-90° - 90°', default: 0, units: '°'),
192
+ Param.new(
193
+ name: 'Angle Threshold',
194
+ grps_index: 17,
195
+ options: {
196
+ description: '-90° - 90°',
197
+ default: 0,
198
+ units: '°'
199
+ }
200
+ ),
139
201
  speed_threshold:
140
202
  Param.new(
141
203
  name: 'Speed Threshold',
142
204
  grps_index: 18,
143
- description: '0 - 100% of speed setting',
144
- default: 50,
145
- units: '%'
205
+ options: {
206
+ description: '0 - 100% of speed setting',
207
+ default: 50,
208
+ units: '%'
209
+ }
146
210
  ),
147
211
  digital_output1:
148
212
  Param.new(
149
213
  name: 'Digital Output 1',
150
214
  grps_index: 19,
151
- description: '0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro Detection',
152
- default: 0,
153
- values: %w[Direction Angle Range Speed Micro]
215
+ options: {
216
+ description: '0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro Detection',
217
+ default: 0,
218
+ str_values: %w[Direction Angle Range Speed Micro]
219
+ }
154
220
  ),
155
221
  digital_output2:
156
222
  Param.new(
157
223
  name: 'Digital Output 2',
158
224
  grps_index: 20,
159
- description: '0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro Detection',
160
- default: 1,
161
- values: %w[Direction Angle Range Speed Micro]
225
+ options: {
226
+ description: '0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro Detection',
227
+ default: 1,
228
+ str_values: %w[Direction Angle Range Speed Micro]
229
+ }
162
230
  ),
163
231
  digital_output3:
164
232
  Param.new(
165
233
  name: 'Digital Output 3',
166
234
  grps_index: 21,
167
- description: '0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro Detection',
168
- default: 2,
169
- values: %w[Direction Angle Range Speed Micro]
235
+ options: {
236
+ description: '0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro Detection',
237
+ default: 2,
238
+ str_values: %w[Direction Angle Range Speed Micro]
239
+ }
170
240
  ),
171
- hold_time: Param.new(name: 'Hold Time', grps_index: 22, description: '1 - 7200s', default: 1, units: 's'),
241
+ hold_time:
242
+ Param.new(name: 'Hold Time', grps_index: 22, options: { description: '1 - 7200s', default: 1, units: 's' }),
172
243
  micro_detection_retrigger:
173
244
  Param.new(
174
245
  name: 'Micro Detection Trigger',
175
246
  grps_index: 23,
176
- description: '0 = Off, 1 = Retrigger',
177
- default: 0,
178
- values: %w[Off Retrigger]
247
+ options: {
248
+ description: '0 = Off, 1 = Retrigger',
249
+ default: 0,
250
+ str_values: %w[Off Retrigger]
251
+ }
179
252
  ),
180
253
  micro_detection_sensativity:
181
254
  Param.new(
182
255
  name: 'Micro Detection Sensativity',
183
256
  grps_index: 24,
184
- description: '0 - 9, 0 = Min, 9 = Max',
185
- default: 4
257
+ options: {
258
+ description: '0 - 9, 0 = Min, 9 = Max',
259
+ default: 4
260
+ }
186
261
  )
187
262
  }.freeze
188
263
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'csv'
2
4
 
3
5
  module RfBeam
4
- module KLD7
6
+ module Kld7
5
7
  def detection?
6
8
  data = ddat
7
9
  (data[2] == 1)
@@ -33,7 +35,7 @@ module RfBeam
33
35
  return resp unless formatted
34
36
 
35
37
  target_count = resp[1].to_i / 8
36
- return [] unless target_count > 0
38
+ return [] unless target_count.positive?
37
39
 
38
40
  resp.shift 2
39
41
  resp.compact
@@ -58,6 +60,7 @@ module RfBeam
58
60
 
59
61
  resp = read(14).unpack('a4LC6')
60
62
  raise Error, "DDAT response = #{resp[0]}" unless resp[0] == 'DDAT'
63
+
61
64
  resp
62
65
  end
63
66
 
@@ -71,8 +74,8 @@ module RfBeam
71
74
 
72
75
  def config
73
76
  data = grps
74
- output = "\n"
75
- RADAR_PARAMETERS.keys.each { |key| output << formatted_parameter(key, data[RADAR_PARAMETERS[key].grps_index]) }
77
+ output = []
78
+ RADAR_PARAMETERS.each_key { |key| output << formatted_parameter(key, data[RADAR_PARAMETERS[key].grps_index]) }
76
79
  output
77
80
  end
78
81
 
@@ -82,7 +85,7 @@ module RfBeam
82
85
  data = grps
83
86
  value = data[param.grps_index]
84
87
  end
85
- param_str_value = param.values.empty? ? value.to_s : param.values[value]
88
+ param_str_value = param.str_values.empty? ? value.to_s : param.str_values[value]
86
89
  "#{param.name}: #{param_str_value}#{param.units}\n"
87
90
  end
88
91
 
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RfBeam
2
- module KLD7
4
+ module Kld7
3
5
  # -----------------
4
6
  # Software Version, 'K-LD7_APP-RFB-XXXX'
5
7
  # -----------------
@@ -382,12 +384,8 @@ module RfBeam
382
384
  def set_parameter(header, value, return_type = :uint32)
383
385
  return_type =
384
386
  case return_type
385
- when :uint32
386
- 'L'
387
387
  when :int32
388
388
  'l'
389
- when :uint32
390
- 'S'
391
389
  else
392
390
  'L'
393
391
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RfBeam
2
- module KLD7
4
+ module Kld7
3
5
  require 'rubyserial'
4
6
  require 'timeout'
5
-
7
+
6
8
  class Error < StandardError
7
9
  end
8
10
 
@@ -80,10 +82,10 @@ module RfBeam
80
82
  raise Error, 'No valid response from Serial Port' if resp[2].nil?
81
83
 
82
84
  response_key = resp[2]
83
- return response_key.zero? # Everything OK
84
-
85
85
  error_string = RESP_CODES[response_key].nil? ? 'Response unknown' : RESP_CODES[response_key]
86
- raise Error, "Radar response Error: #{error_string}"
86
+ raise Error, "Radar response Error: #{error_string}" unless response_key.zero?
87
+
88
+ response_key.zero? # Everything OK
87
89
  end
88
90
  end
89
91
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RfBeam
4
- VERSION = '0.4.3'
4
+ VERSION = '0.4.5'
5
5
  end
data/lib/rfbeam.rb CHANGED
@@ -13,8 +13,8 @@ module RfBeam
13
13
  class Error < StandardError
14
14
  end
15
15
 
16
- class K_ld7
17
- include RfBeam::KLD7
16
+ class KLD7
17
+ include RfBeam::Kld7
18
18
  end
19
19
 
20
20
  def self.connected
data/rfbeam.gemspec CHANGED
@@ -36,11 +36,15 @@ Gem::Specification.new do |spec|
36
36
  # Uncomment to register a new dependency of your gem
37
37
  # spec.add_dependency "example-gem", "~> 1.0"
38
38
  spec.add_dependency 'activesupport', '~> 6.1.0'
39
- # spec.add_dependency 'bindata', '~> 2.4.10'
40
39
  spec.add_dependency 'rubyserial', '~> 0.6.0'
41
- # spec.add_dependency 'terminal-table', '~> 3.0.2'
42
40
  spec.add_dependency 'thor', '~> 1.2.1'
41
+ spec.add_dependency 'tty-logger', '~> 0.6.0'
42
+ spec.add_dependency 'tty-screen', '~> 0.8.1'
43
+ spec.add_dependency 'tty-spinner', '~> 0.9.3'
44
+ spec.add_dependency 'tty-table', '~> 0.12.0'
45
+ spec.add_dependency 'unicode_plot', '~> 0.0.5'
43
46
 
44
47
  # For more information and examples about making a new gem, check out our
45
48
  # guide at: https://bundler.io/guides/creating_gem.html
49
+ spec.metadata['rubygems_mfa_required'] = 'true'
46
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfbeam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Carruthers
@@ -52,6 +52,76 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.2.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: tty-logger
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.6.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.6.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: tty-screen
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.8.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: tty-spinner
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.9.3
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.9.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: tty-table
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.12.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.12.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: unicode_plot
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.0.5
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.0.5
55
125
  description: Currently only tested with K-LD7 on MacOS & Raspian (bullseye)
56
126
  email:
57
127
  - robc@hey.com
@@ -165,7 +235,6 @@ files:
165
235
  - node_modules/prettier/parser-yaml.js
166
236
  - node_modules/prettier/standalone.js
167
237
  - node_modules/prettier/third-party.js
168
- - output.csv
169
238
  - package.json
170
239
  - rfbeam.gemspec
171
240
  - sig/rfbeam.rbs
@@ -177,6 +246,7 @@ metadata:
177
246
  homepage_uri: https://gitlab.com/robcarruthers/rfbeam
178
247
  source_code_uri: https://gitlab.com/robcarruthers/rfbeam
179
248
  changelog_uri: https://gitlab.com/robcarruthers/rfbeam/CHANGELOG.md
249
+ rubygems_mfa_required: 'true'
180
250
  post_install_message:
181
251
  rdoc_options: []
182
252
  require_paths:
data/output.csv DELETED
@@ -1,257 +0,0 @@
1
- 0,2105,2105
2
- 1,3070,2915
3
- 2,2915,805
4
- 3,2325,2830
5
- 4,805,3420
6
- 5,1000,1340
7
- 6,2830,1555
8
- 7,3810,2645
9
- 8,3420,1270
10
- 9,1645,1400
11
- 10,1340,1130
12
- 11,1285,1350
13
- 12,1555,1085
14
- 13,1500,910
15
- 14,2645,1400
16
- 15,2785,1435
17
- 16,1270,1150
18
- 17,500,1545
19
- 18,1400,1270
20
- 19,615,1285
21
- 20,1130,1435
22
- 21,1000,785
23
- 22,1350,710
24
- 23,1565,955
25
- 24,1085,1165
26
- 25,1420,1645
27
- 26,910,1595
28
- 27,1265,455
29
- 28,1400,805
30
- 29,1015,1050
31
- 30,1435,560
32
- 31,1060,1530
33
- 32,1150,3275
34
- 33,305,3510
35
- 34,1545,650
36
- 35,765,1415
37
- 36,1270,1760
38
- 37,785,650
39
- 38,1285,830
40
- 39,980,560
41
- 40,1435,850
42
- 41,1085,0
43
- 42,785,480
44
- 43,1340,1150
45
- 44,710,910
46
- 45,1210,1050
47
- 46,955,500
48
- 47,1000,1230
49
- 48,1165,1040
50
- 49,1060,955
51
- 50,1645,910
52
- 51,2200,150
53
- 52,1595,455
54
- 53,1085,150
55
- 54,455,830
56
- 55,1400,455
57
- 56,805,500
58
- 57,1490,850
59
- 58,1050,0
60
- 59,560,980
61
- 60,560,1040
62
- 61,800,500
63
- 62,1530,800
64
- 63,0,1410
65
- 64,3275,305
66
- 65,3990,1570
67
- 66,3510,1255
68
- 67,1105,955
69
- 68,650,150
70
- 69,700,655
71
- 70,1415,1245
72
- 71,1295,455
73
- 72,1760,710
74
- 73,1235,560
75
- 74,650,650
76
- 75,500,1000
77
- 76,830,760
78
- 77,650,760
79
- 78,560,350
80
- 79,1240,305
81
- 80,850,150
82
- 81,1400,910
83
- 82,0,650
84
- 83,805,500
85
- 84,480,1180
86
- 85,150,1435
87
- 86,1150,850
88
- 87,1360,800
89
- 88,910,1305
90
- 89,1190,910
91
- 90,1050,1260
92
- 91,1115,455
93
- 92,500,1000
94
- 93,800,615
95
- 94,1230,1265
96
- 95,980,3955
97
- 96,1040,3675
98
- 97,500,615
99
- 98,955,300
100
- 99,1285,1825
101
- 100,910,760
102
- 101,980,1315
103
- 102,150,1435
104
- 103,1200,1260
105
- 104,455,850
106
- 105,480,1260
107
- 106,150,1970
108
- 107,500,1015
109
- 108,830,350
110
- 109,700,735
111
- 110,455,1680
112
- 111,150,350
113
- 112,500,1135
114
- 113,605,865
115
- 114,850,1735
116
- 115,805,850
117
- 116,0,1165
118
- 117,710,1965
119
- 118,980,810
120
- 119,305,1005
121
- 120,1040,1200
122
- 121,150,2885
123
- 122,500,1095
124
- 123,710,1060
125
- 124,800,2455
126
- 125,1265,2145
127
- 126,1410,1665
128
- 127,1175,3230
129
- 128,305,4328
130
- 129,1255,4228
131
- 130,1570,4069
132
- 131,980,3995
133
- 132,1255,3946
134
- 133,1480,3910
135
- 134,955,3881
136
- 135,455,3857
137
- 136,150,3836
138
- 137,910,3818
139
- 138,655,3802
140
- 139,350,3788
141
- 140,1245,3774
142
- 141,1150,3762
143
- 142,455,3751
144
- 143,560,3741
145
- 144,710,3731
146
- 145,150,3722
147
- 146,560,3714
148
- 147,830,3706
149
- 148,650,3698
150
- 149,655,3691
151
- 150,1000,3684
152
- 151,350,3677
153
- 152,760,3671
154
- 153,455,3665
155
- 154,760,3659
156
- 155,560,3654
157
- 156,350,3648
158
- 157,655,3643
159
- 158,305,3638
160
- 159,150,3633
161
- 160,150,3629
162
- 161,910,3624
163
- 162,910,3620
164
- 163,1190,3616
165
- 164,650,3612
166
- 165,455,3608
167
- 166,500,3604
168
- 167,500,3600
169
- 168,1180,3596
170
- 169,1500,3592
171
- 170,1435,3589
172
- 171,1265,3586
173
- 172,850,3582
174
- 173,650,3579
175
- 174,800,3576
176
- 175,1350,3573
177
- 176,1305,3569
178
- 177,1260,3566
179
- 178,910,3563
180
- 179,805,3561
181
- 180,1260,3558
182
- 181,1175,3555
183
- 182,455,3552
184
- 183,965,3550
185
- 184,1000,3547
186
- 185,755,3544
187
- 186,615,3542
188
- 187,350,3539
189
- 188,1265,3537
190
- 189,935,3534
191
- 190,3955,3532
192
- 191,4445,3530
193
- 192,3675,3528
194
- 193,1365,3530
195
- 194,615,3532
196
- 195,605,3534
197
- 196,300,3537
198
- 197,1135,3539
199
- 198,1825,3542
200
- 199,895,3544
201
- 200,760,3547
202
- 201,500,3550
203
- 202,1315,3552
204
- 203,1330,3555
205
- 204,1435,3558
206
- 205,1385,3561
207
- 206,1260,3563
208
- 207,920,3566
209
- 208,850,3569
210
- 209,615,3573
211
- 210,1260,3576
212
- 211,1545,3579
213
- 212,1970,3582
214
- 213,1605,3586
215
- 214,1015,3589
216
- 215,955,3592
217
- 216,350,3596
218
- 217,1270,3600
219
- 218,735,3604
220
- 219,1330,3608
221
- 220,1680,3612
222
- 221,630,3616
223
- 222,350,3620
224
- 223,1200,3624
225
- 224,1135,3629
226
- 225,850,3633
227
- 226,865,3638
228
- 227,1540,3643
229
- 228,1735,3648
230
- 229,500,3654
231
- 230,850,3659
232
- 231,150,3665
233
- 232,1165,3671
234
- 233,1345,3677
235
- 234,1965,3684
236
- 235,1630,3691
237
- 236,810,3698
238
- 237,1175,3706
239
- 238,1005,3714
240
- 239,500,3722
241
- 240,1200,3731
242
- 241,2830,3741
243
- 242,2885,3751
244
- 243,1630,3762
245
- 244,1095,3774
246
- 245,980,3788
247
- 246,1060,3802
248
- 247,1190,3818
249
- 248,2455,3836
250
- 249,3045,3857
251
- 250,2145,3881
252
- 251,1500,3910
253
- 252,1665,3946
254
- 253,1975,3995
255
- 254,3230,
256
- 255,3470,
257
- 256,4328,