rfbeam 0.4.10 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d9b598dd013b48a6c19e5755f4af6a687a1fd2b82ac2aaa3d38c3a8b98db2f8
4
- data.tar.gz: d1bf6b228eb6c0cff37ae44a178c7eb9b1e80e033894d2ae2456e2882d6ac180
3
+ metadata.gz: a612ea7d8038a09e50462eca0c5acaeb6358992df63d0929e26024dbff5004a9
4
+ data.tar.gz: e3bbc877194756cd958d3616623fb46bc384ae7e73430a3e096a950efe6ae3c9
5
5
  SHA512:
6
- metadata.gz: 277a4e68325e439d64db8ffc1af15b5b1aeae5be8b9f9718100d6fd9cdd7bb228274c51a856960d775f8f3ecf041616e59b039acf22b029b990d4b5488793053
7
- data.tar.gz: 54b6209b877a2304139c8ea615d9fe0437b3393ee75385c00735ffe24279d0940d29b061cf28f6fbe47cdd7c5a2b208aecffe97a49b266f2aa8fad751cf52ae2
6
+ metadata.gz: 4663603c15bb5423ee29710e0a743f9f979b7fd57185495062972189533e3c72f07712abb45ba77ea84dff55a6c2bcf72ef4142833195ca6d68f55632249c4a4
7
+ data.tar.gz: 4af5abb75a3fe9475ab0a4afd988b8fecc2323afc95d3f64f530f359b08ab0f390012a97272545d69d46da9e8051887a24a345b59434afcf90bc18b0312de2de
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.5.0] - 2023-11-4
2
+
3
+ - Refactored CLI, refined help and options
4
+
1
5
  ## [0.4.2] - 2023-4-4
2
6
 
3
7
  - Changed Data.define to Struct to support ruby 3.1.2
data/Gemfile.lock CHANGED
@@ -9,7 +9,7 @@ GIT
9
9
  PATH
10
10
  remote: .
11
11
  specs:
12
- rfbeam (0.4.10)
12
+ rfbeam (0.5.0)
13
13
  activesupport (~> 6.1.0)
14
14
  rubyserial (~> 0.6.0)
15
15
  thor (~> 1.2.1)
data/lib/rfbeam/cli.rb CHANGED
@@ -24,17 +24,17 @@ module RfBeam
24
24
  puts table.render(:ascii)
25
25
  end
26
26
 
27
- desc 'config <radar_id>', 'Shows the parameter setting for the Radar module'
27
+ desc 'config [RADAR_ID]', 'Shows the parameter setting for the Radar module'
28
28
  def config(radar_id)
29
29
  puts radar(radar_id).config
30
30
  end
31
31
 
32
- desc 'reset <radar_id>', 'Shows the parameter setting for the Radar module'
32
+ desc 'reset [RADAR_ID]', 'Shows the parameter setting for the Radar module'
33
33
  def reset(radar_id)
34
34
  @logger.success 'Radar reset to factory defaults' if radar(radar_id).reset
35
35
  end
36
36
 
37
- desc 'set_param <radar_id> <key> <value>', 'Set radar parameters, see readme for keys'
37
+ desc 'set_param [RADAR_ID] [KEY] [VALUE]', 'Set radar parameters, see readme for KEYS'
38
38
  def set_param(radar_id, param, value)
39
39
  return @logger.warn("Invalid param: '#{param}'") unless Kld7::RADAR_PARAMETERS.include?(param.to_sym)
40
40
 
@@ -43,20 +43,28 @@ module RfBeam
43
43
  @logger.success r.formatted_parameter(param.to_sym)
44
44
  end
45
45
 
46
- desc 'ddat <radar_id>', 'stream any valid detections, stop stream with q and enter'
47
- option :stream, type: :boolean, aliases: '-s', desc: 'Stream the data from the device'
46
+ desc 'ddat [RADAR_ID]', 'stream any valid detections, stop stream with q and enter'
47
+ option :stream, type: :boolean, aliases: '-s', desc: 'Stream the data from the device, press q to stop'
48
+ option :raw, type: :boolean, aliases: '-r', desc: 'Display raw data'
48
49
  def ddat(radar_id)
49
50
  cli = RfBeam::Kld7::CliOutput.new(radar_id)
50
- cli.display(:ddat, stream: options[:stream])
51
+ cli.display(:ddat, options)
51
52
  end
52
53
 
53
- desc 'pdat <radar_id>', 'Display Tracked Targets'
54
+ desc 'tdat [RADAR_ID]', 'Display tracked target data'
55
+ option :raw, type: :boolean, aliases: '-r', desc: 'Display raw data'
56
+ def tdat(radar_id)
57
+ cli = RfBeam::Kld7::CliOutput.new(radar_id)
58
+ cli.display(:tdat, options)
59
+ end
60
+
61
+ desc 'pdat [RADAR_ID]', 'Display Tracked Targets'
54
62
  def pdat(radar_id)
55
63
  cli = RfBeam::Kld7::CliOutput.new(radar_id)
56
- cli.display(:pdat, stream: options[:stream])
64
+ cli.display(:pdat, options)
57
65
  end
58
66
 
59
- desc 'rfft <radar_id>', 'Display the dopplar radar data as a plot'
67
+ desc 'rfft [RADAR_ID]', 'Display the dopplar radar data as a plot'
60
68
  option :stream, type: :boolean, aliases: '-s', desc: 'Stream the data from the device'
61
69
  option :raw, type: :boolean, aliases: '-r', desc: 'Display raw data'
62
70
  def rfft(radar_id)
@@ -68,12 +76,6 @@ module RfBeam
68
76
  end
69
77
  end
70
78
 
71
- desc 'tdat <radar_id>', 'Display tracked target data'
72
- def tdat(radar_id)
73
- cli = RfBeam::Kld7::CliOutput.new(radar_id)
74
- cli.display(:tdat, stream: options[:stream])
75
- end
76
-
77
79
  private
78
80
 
79
81
  def radar(id)
@@ -5,6 +5,10 @@ require 'tty-table'
5
5
  module RfBeam
6
6
  module Kld7
7
7
  class CliFormatter
8
+ def self.format(type, data)
9
+ new.format(type, data)
10
+ end
11
+
8
12
  def format(type, data)
9
13
  case type
10
14
  when :tdat
@@ -16,10 +20,6 @@ module RfBeam
16
20
  end
17
21
  end
18
22
 
19
- def tdat(data)
20
- { dist: data[2], speed: data[3], angle: data[4], mag: data[5] }
21
- end
22
-
23
23
  def pdat_table(data)
24
24
  table = TTY::Table.new header: ['index', 'dist (M)', 'speed (Km/h)', 'angle (°)', 'mag (db)']
25
25
  count = data[1] / 8
@@ -41,6 +41,17 @@ module RfBeam
41
41
  .join("\n")
42
42
  end
43
43
 
44
+ def tdat(data)
45
+ return 'No target detected' unless data[1].positive?
46
+
47
+ [
48
+ "Distance: #{data[2].to_f / 100.0} m",
49
+ "Speed: #{data[3].to_f / 100.0} km/h",
50
+ "Angle: #{data[4].to_f / 100.0}°",
51
+ "Mag: #{data[5].to_f / 100.0} db"
52
+ ].join("\n")
53
+ end
54
+
44
55
  def to_symbol(string)
45
56
  modified_string = string.gsub(' ', '_').downcase
46
57
  modified_string.to_sym
@@ -20,8 +20,9 @@ module RfBeam
20
20
  end
21
21
  end
22
22
 
23
- def display(type, stream: false)
24
- stream ? send("stream_#{type}") : send("display_#{type}")
23
+ def display(type, options)
24
+ display_method = options[:stream].nil? ? 'display' : 'stream'
25
+ send("#{display_method}_#{type}", options)
25
26
  end
26
27
 
27
28
  def plot(type, stream: false)
@@ -79,8 +80,12 @@ module RfBeam
79
80
  }
80
81
  end
81
82
 
82
- def display_ddat
83
- puts RfBeam::Kld7::CliFormatter.new.format(:ddat, @radar.ddat)
83
+ def display_ddat(options)
84
+ if options[:raw].nil?
85
+ puts RfBeam::Kld7::CliFormatter.format(:ddat, @radar.ddat)
86
+ else
87
+ puts @radar.ddat.inspect
88
+ end
84
89
  end
85
90
 
86
91
  def stream_ddat
@@ -98,11 +103,15 @@ module RfBeam
98
103
  end
99
104
  end
100
105
 
101
- def display_tdat
102
- puts RfBeam::Kld7::CliFormatter.new.tdat(@radar.tdat)
106
+ def display_tdat(options)
107
+ if options[:raw].nil?
108
+ puts RfBeam::Kld7::CliFormatter.format(:tdat, @radar.tdat)
109
+ else
110
+ puts @radar.tdat.inspect
111
+ end
103
112
  end
104
113
 
105
- def display_pdat
114
+ def display_pdat(options)
106
115
  table = RfBeam::Kld7::CliFormatter.new.pdat_table(@radar.pdat)
107
116
  puts "\n Detected Raw Targets"
108
117
  puts table.render(:unicode, alignment: :center)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RfBeam
4
- VERSION = '0.4.10'
4
+ VERSION = '0.5.0'
5
5
  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.10
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Carruthers