rfbeam 0.3.2 → 0.3.4

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: daed0b3716d78b7783768008f4fb69a0b1dd790fe23aaaceb4682b8c68982341
4
- data.tar.gz: 74b70ca29f4065966a59ab2801e0d1eaefbf7fab45f67a8b70062fd8cf944cff
3
+ metadata.gz: 698385739f70574b698a117af8c749a21ebd75d9c3b0abaa39447ebd869324ef
4
+ data.tar.gz: 11f47d264d76f5a5b968c8f7cb49152602359383e8a0cf20a16564a2b2e808f3
5
5
  SHA512:
6
- metadata.gz: f4c29ec4115d65fb0fd8dd565c070d3124cf8ef32e863fd236346faac28265960c7e872ba166463180c84f20cc7db04b184551cfbda804bbcf98cb7d7de5e81f
7
- data.tar.gz: 9e5763c1acbd1c4f4f45bdd481d4efc4fa66cff721f8ebfda263d89548110fe538bdbd8b4b36ad65f08f523fb3256a8052c275c039ba4e01b3394baaadfc689b
6
+ metadata.gz: 58b01ae8497458e6e4f238afcc64a38cd925312e7893b4e65a854407f34694493b002e5721a9980129d586370cc51abfca5e5cd238a51cf33dfb890f40992479
7
+ data.tar.gz: 48934f301cb4eb9ac2cdb695d08dfd544cc9e6ea16f130ab6b30b182c35ee1630d5ad2574c4bab081656f51ce4208857c92a2dfd6d2925639c303a3c66c0d1ae
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 2.7.6
1
+ ruby 3.2.1
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
- ## [0.3.1] - 2023-3-28
1
+ ## [0.3.4] - 2023-3-28
2
+
3
+ - Added a formatted option to pdat
4
+
5
+ ## [0.3.2] - 2023-3-28
2
6
 
3
7
  - Added setters for Parameter settings
4
8
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rfbeam (0.3.1)
4
+ rfbeam (0.3.4)
5
5
  activesupport (~> 6.1.0)
6
6
  rubyserial (~> 0.6.0)
7
7
  thor (~> 1.2.1)
@@ -1,40 +1,40 @@
1
1
  module RfBeam
2
2
  module KLD7
3
-
4
- def detection?
5
- data = ddat
6
- (data[2] == 1)
7
- end
8
-
9
- def config
10
- puts formatted_grps(grps)
11
- end
12
3
 
13
- # Get the radar parameter structure
14
- def grps
15
- command = ['GRPS', 0]
16
- write command.pack('a4L')
17
- check_response
18
- read(50).unpack('a4LA19C8c2C4cCCCCSCC')
4
+ # Base Frequency, 0 = low, 1 = middle (default), 2 = high
5
+ def base_frequency
6
+ data = grps
7
+ data[3]
19
8
  end
9
+ alias rbfr base_frequency
10
+
20
11
 
21
- # Base Frequency, 0 = low, 1 = middle (default), 2 = high
22
12
  def set_base_frequency(frequency = 1)
23
- set_parameter(:rbfr, frequency, :uint8)
13
+ value = case frequency
14
+ when 0, :low, 'low'
15
+ 0
16
+ when 1, :middle, 'middle'
17
+ 1
18
+ when 2, :high, 'high'
19
+ 2
20
+ else
21
+ raise ArgumentError, "Invalid arg: '#{frequency}'"
22
+ end
23
+ set_parameter(:rbfr, value, :uint8)
24
24
  end
25
- alias_method :rbfr, :set_base_frequency
25
+ alias set_rbfr set_base_frequency
26
26
 
27
27
  # Maximum Speed, 0 = 12.5km/h, 1 = 25km/h (default), 2 = 50km/h, 3 = 100km/h
28
28
  def set_max_speed(speed = 1)
29
29
  set_parameter :rspi, speed, :uint8
30
30
  end
31
- alias_method :rspi, :set_max_speed
31
+ alias rspi set_max_speed
32
32
 
33
33
  # Maximum Range, 0 = 5m, 1 = 10m (default), 2 = 30m, 3 = 100m
34
34
  def set_max_range(range = 1)
35
35
  set_parameter :rrai, range, :uint8
36
36
  end
37
- alias_method :rrai, :set_max_range
37
+ alias rrai set_max_range
38
38
 
39
39
  # Threshold Offset, 10 - 60db, (default = 30)
40
40
  def set_threshold_offset(offset = 30)
@@ -43,61 +43,61 @@ module RfBeam
43
43
 
44
44
  set_parameter :thof, offset, :uint8
45
45
  end
46
- alias_method :thof, :set_threshold_offset
46
+ alias thof set_threshold_offset
47
47
 
48
48
  # Tracking filter type, 0 = Standard (Default), 1 = Fast Tracking, 2 = Long visibility
49
49
  def set_tracking_filter(type = 0)
50
50
  set_parameter :trft, type, :uint8
51
51
  end
52
- alias_method :trtf, :set_tracking_filter
52
+ alias trtf set_tracking_filter
53
53
 
54
54
  # Vibration suppression, 0 - 16, 0 = No Suppression, 16 = High Suppression, default = 2
55
55
  def set_vibration_suppression(value = 2)
56
56
  set_parameter :visu, value, :uint8
57
57
  end
58
- alias_method :visu, :set_vibration_suppression
58
+ alias visu set_vibration_suppression
59
59
 
60
60
  # Minimum Detection distance, 0 - 100% of Range setting, default = 0
61
61
  def set_min_detection_distance(value = 0)
62
62
  set_parameter :mira, value, :uint8
63
63
  end
64
- alias_method :mira, :set_min_detection_distance
64
+ alias mira set_min_detection_distance
65
65
 
66
66
  # Maximum Detection distance, 0 - 100% of Range setting, default = 50
67
67
  def set_max_detection_distance(value = 50)
68
68
  set_parameter :mara, value, :uint8
69
69
  end
70
- alias_method :mara, :set_max_detection_distance
70
+ alias mara set_max_detection_distance
71
71
 
72
72
  # Minimum Detection Angle, -90° - 90°, default = -90
73
73
  def set_min_detection_angle(angle = -90)
74
74
  set_parameter :mian, angle, :int8
75
75
  end
76
- alias_method :mian, :set_min_detection_distance
76
+ alias mian set_min_detection_distance
77
77
 
78
78
  # Maximum Detection Angle, -90° - 90°, default = 90
79
- def set_min_detection_angle(angle = 90)
79
+ def set_max_detection_angle(angle = 90)
80
80
  set_parameter :maan, angle, :int8
81
81
  end
82
- alias_method :maan, :set_min_detection_angle
82
+ alias maan set_max_detection_angle
83
83
 
84
84
  # Minimum Detection Speed, 0 - 100% of Speed setting, default = 0
85
85
  def set_min_detection_speed(speed = 0)
86
86
  set_parameter :misp, speed, :uint8
87
87
  end
88
- alias_method :misp, :set_min_detection_speed
88
+ alias misp set_min_detection_speed
89
89
 
90
90
  # Maximum Detection Speed, 0 - 100% of Speed setting, default = 100
91
91
  def set_max_detection_speed(speed = 100)
92
92
  set_parameter :masp, speed, :uint8
93
93
  end
94
- alias_method :masp, :set_max_detection_speed
94
+ alias masp set_max_detection_speed
95
95
 
96
96
  # Detection Direction, 0 = Receding, 1 = Approaching, 2 = Both (default)
97
97
  def set_detection_direction(direction = 2)
98
98
  set_parameter :dedi, direction, :uint8
99
99
  end
100
- alias_method :dedi, :set_detection_direction
100
+ alias dedi set_detection_direction
101
101
 
102
102
  # Range Threshold, 0 - 100% of Range setting, default = 10
103
103
  def set_range_threshold(value = 10)
@@ -106,7 +106,7 @@ module RfBeam
106
106
 
107
107
  set_parameter :rath, value, :uint8
108
108
  end
109
- alias_method :rath, :set_range_threshold
109
+ alias rath set_range_threshold
110
110
 
111
111
  # Angle Threshold, -90° to 90°, default = 0
112
112
  def set_range_threshold(value = 0)
@@ -115,7 +115,7 @@ module RfBeam
115
115
 
116
116
  set_parameter :anth, value, :int8
117
117
  end
118
- alias_method :anth, :set_range_threshold
118
+ alias anth set_range_threshold
119
119
 
120
120
  # Speed Threshold, 0 - 100% of speed setting, default = 50
121
121
  def set_angle_threshold(value = 50)
@@ -124,7 +124,7 @@ module RfBeam
124
124
 
125
125
  set_parameter :spth, value, :uint8
126
126
  end
127
- alias_method :spth, :set_angle_threshold
127
+ alias spth set_angle_threshold
128
128
 
129
129
  # Digital output 1, 0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro Detection, default = 0
130
130
  def set_dio_1(value = 0)
@@ -133,7 +133,7 @@ module RfBeam
133
133
 
134
134
  set_parameter :dig1, value, :uint8
135
135
  end
136
- alias_method :dig1, :set_dio_1
136
+ alias dig1 set_dio_1
137
137
 
138
138
  # Digital output 2, 0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro Detection, default = 1
139
139
  def set_dio_2(value = 1)
@@ -142,7 +142,7 @@ module RfBeam
142
142
 
143
143
  set_parameter :dig2, value, :uint8
144
144
  end
145
- alias_method :dig2, :set_dio_2
145
+ alias dig2 set_dio_2
146
146
 
147
147
  # Digital output 3, 0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro Detection, default = 2
148
148
  def set_dio_3(value = 2)
@@ -151,7 +151,7 @@ module RfBeam
151
151
 
152
152
  set_parameter :dig3, value, :uint8
153
153
  end
154
- alias_method :dig3, :set_dio_3
154
+ alias dig3 set_dio_3
155
155
 
156
156
  # Hold Time, 1 - 7200s, default = 1
157
157
  def set_hold_time(time = 1)
@@ -160,15 +160,15 @@ module RfBeam
160
160
 
161
161
  set_parameter :hold, time, :uint16
162
162
  end
163
- alias_method :hold, :set_hold_time
163
+ alias hold set_hold_time
164
164
 
165
165
  # Micro Detection retrigger, 0 = Off (default), 1 = Retrigger
166
166
  def set_micro_detection_retrigger(value = 0)
167
- return false unless (value == 0 || value == 1)
167
+ return false unless [0, 1].include?(value)
168
168
 
169
169
  set_parameter :mide, value, :uint8
170
170
  end
171
- alias_method :mide, :set_micro_detection_retrigger
171
+ alias mide set_micro_detection_retrigger
172
172
 
173
173
  # Micro Detection sensitivity, 0 - 9, 0 = Min, 9 = Max, default = 4
174
174
  def set_micro_detection_sensitivty(value = 4)
@@ -177,7 +177,7 @@ module RfBeam
177
177
 
178
178
  set_parameter :mids, value, :uint8
179
179
  end
180
- alias_method :mids, :set_micro_detection_sensitivty
180
+ alias mids set_micro_detection_sensitivty
181
181
 
182
182
  private
183
183
 
@@ -187,7 +187,7 @@ module RfBeam
187
187
  when :uint8
188
188
  'L'
189
189
  when :int8
190
- 'c'
190
+ 'l'
191
191
  when :uint16
192
192
  'S'
193
193
  else
@@ -197,34 +197,5 @@ module RfBeam
197
197
  write command.pack("a4L#{return_type}")
198
198
  check_response
199
199
  end
200
-
201
- def formatted_grps(data)
202
- output = "\n"
203
- output << "Software Version: #{data[2]}\n"
204
- output << "Base Frequency: #{PARAMETER_STRUCTURE[:base_frequency][data[3]]}\n"
205
- output << "Max Speed: #{PARAMETER_STRUCTURE[:max_speed][data[4]]}\n"
206
- output << "Max Range: #{PARAMETER_STRUCTURE[:max_range][data[5]]}\n"
207
- output << "Threshold offset: #{data[6]}db\n"
208
- output << "Tracking Filter Type: #{PARAMETER_STRUCTURE[:tracking_filter_type][data[7]]}\n"
209
- output << "Vibration Suppression: #{data[8]} , (#{PARAMETER_STRUCTURE[:vibration_suppression]})\n"
210
- output << "Minimum Detection Distance: #{data[9]} , (#{PARAMETER_STRUCTURE[:min_detection_distance]})\n"
211
- output << "Maximum Detection Distance: #{data[10]} , (#{PARAMETER_STRUCTURE[:max_detection_distance]})\n"
212
- output << "Minimum Detection Angle: #{data[11]}° , (#{PARAMETER_STRUCTURE[:min_detection_angle]})\n"
213
- output << "Maximum Detection Angle: #{data[12]}° , (#{PARAMETER_STRUCTURE[:max_detection_angle]})\n"
214
- output << "Minimum Detection Speed: #{data[13]} , (#{PARAMETER_STRUCTURE[:min_detection_speed]})\n"
215
- output << "Maximum Detection Speed: #{data[14]} , (#{PARAMETER_STRUCTURE[:max_detection_speed]})\n"
216
- output << "Detection Direction: #{PARAMETER_STRUCTURE[:detection_direction][data[15]]}\n"
217
- output << "Range Threshold: #{data[16]}%, (#{PARAMETER_STRUCTURE[:range_threshold]})\n"
218
- output << "Angle Threshold: #{data[17]}°, (#{PARAMETER_STRUCTURE[:angle_threshold]})\n"
219
- output << "Speed Threshold: #{data[18]}%, (#{PARAMETER_STRUCTURE[:speed_threshold]})\n"
220
- output << "Digital output 1: #{PARAMETER_STRUCTURE[:digital_output_1][data[19]]}\n"
221
- output << "Digital output 2: #{PARAMETER_STRUCTURE[:digital_output_2][data[20]]}\n"
222
- output << "Digital output 3: #{PARAMETER_STRUCTURE[:digital_output_3][data[21]]}\n"
223
- output << "Hold time: #{data[22]}sec\n"
224
- output << "Micro Detection Retrigger: #{PARAMETER_STRUCTURE[:micro_detection_trigger][data[23]]}\n"
225
- output << "Micro Detection Sensitivity: #{data[24]} (#{PARAMETER_STRUCTURE[:micro_detection_sensitivity]})"
226
-
227
- output
228
- end
229
200
  end
230
201
  end
@@ -0,0 +1,100 @@
1
+ module RfBeam
2
+ module KLD7
3
+ def detection?
4
+ data = ddat
5
+ (data[2] == 1)
6
+ end
7
+
8
+ def pdat(formatted: false)
9
+ request_frame_data(:pdat)
10
+ resp = read(102).unpack('a4LSssSSssSSssSSssSSssSSssSSssSSssSSssSSssS')
11
+ return resp unless formatted
12
+
13
+ target_count = resp[1].to_i / 8
14
+ return [] unless target_count > 0
15
+
16
+ resp.shift 2
17
+ resp.compact
18
+ detected_raw_targets = []
19
+ target_count.times { detected_raw_targets << format_raw_target_data(resp.shift(4)) }
20
+ detected_raw_targets
21
+ end
22
+
23
+ def tdat
24
+ request_frame_data(:tdat)
25
+
26
+ sleep 0.1
27
+ resp = read(16).unpack('a4LSssS')
28
+ return { dist: resp[2], speed: resp[3], angle: resp[4], mag: resp[5] } unless resp[1].zero?
29
+ end
30
+
31
+ def ddat
32
+ request_frame_data(:ddat)
33
+
34
+ read(14).unpack('a4LC6')
35
+ end
36
+
37
+ def config
38
+ puts formatted_grps(grps)
39
+ end
40
+
41
+ def formatted_parameter(param)
42
+ return unless PARAMETERS.include? param
43
+
44
+ param_data = PARAMETERS[param]
45
+ grps_data = grps
46
+ index = grps_data[param_data[:grps_index]]
47
+ param_data[:values][index]
48
+ end
49
+
50
+ # Get the radar parameter structure
51
+ def grps
52
+ command = ['GRPS', 0]
53
+ write command.pack('a4L')
54
+ check_response
55
+ read(50).unpack('a4LA19C8c2C4cCCCCSCC')
56
+ end
57
+
58
+
59
+ private
60
+
61
+ def format_raw_target_data(array)
62
+ { dist: array.shift, speed: array.shift, angle: array.shift, mag: array.shift }
63
+ end
64
+
65
+ def request_frame_data(type)
66
+ command = ['GNFD', 4, FRAME_DATA_TYPES[type]]
67
+ write command.pack('a4LL')
68
+ check_response
69
+ end
70
+
71
+ def formatted_grps(data)
72
+ output = "\n"
73
+ output << "Software Version: #{data[2]}\n"
74
+ output << "Base Frequency: #{PARAMETER_STRUCTURE[:base_frequency][data[3]]}\n"
75
+ output << "Max Speed: #{PARAMETER_STRUCTURE[:max_speed][data[4]]}\n"
76
+ output << "Max Range: #{PARAMETER_STRUCTURE[:max_range][data[5]]}\n"
77
+ output << "Threshold offset: #{data[6]}db\n"
78
+ output << "Tracking Filter Type: #{PARAMETER_STRUCTURE[:tracking_filter_type][data[7]]}\n"
79
+ output << "Vibration Suppression: #{data[8]} , (#{PARAMETER_STRUCTURE[:vibration_suppression]})\n"
80
+ output << "Minimum Detection Distance: #{data[9]} , (#{PARAMETER_STRUCTURE[:min_detection_distance]})\n"
81
+ output << "Maximum Detection Distance: #{data[10]} , (#{PARAMETER_STRUCTURE[:max_detection_distance]})\n"
82
+ output << "Minimum Detection Angle: #{data[11]}° , (#{PARAMETER_STRUCTURE[:min_detection_angle]})\n"
83
+ output << "Maximum Detection Angle: #{data[12]}° , (#{PARAMETER_STRUCTURE[:max_detection_angle]})\n"
84
+ output << "Minimum Detection Speed: #{data[13]} , (#{PARAMETER_STRUCTURE[:min_detection_speed]})\n"
85
+ output << "Maximum Detection Speed: #{data[14]} , (#{PARAMETER_STRUCTURE[:max_detection_speed]})\n"
86
+ output << "Detection Direction: #{PARAMETER_STRUCTURE[:detection_direction][data[15]]}\n"
87
+ output << "Range Threshold: #{data[16]}%, (#{PARAMETER_STRUCTURE[:range_threshold]})\n"
88
+ output << "Angle Threshold: #{data[17]}°, (#{PARAMETER_STRUCTURE[:angle_threshold]})\n"
89
+ output << "Speed Threshold: #{data[18]}%, (#{PARAMETER_STRUCTURE[:speed_threshold]})\n"
90
+ output << "Digital output 1: #{PARAMETER_STRUCTURE[:digital_output_1][data[19]]}\n"
91
+ output << "Digital output 2: #{PARAMETER_STRUCTURE[:digital_output_2][data[20]]}\n"
92
+ output << "Digital output 3: #{PARAMETER_STRUCTURE[:digital_output_3][data[21]]}\n"
93
+ output << "Hold time: #{data[22]}sec\n"
94
+ output << "Micro Detection Retrigger: #{PARAMETER_STRUCTURE[:micro_detection_trigger][data[23]]}\n"
95
+ output << "Micro Detection Sensitivity: #{data[24]} (#{PARAMETER_STRUCTURE[:micro_detection_sensitivity]})"
96
+
97
+ output
98
+ end
99
+ end
100
+ end
@@ -3,6 +3,8 @@ module RfBeam
3
3
  require 'rubyserial'
4
4
  require 'timeout'
5
5
 
6
+
7
+
6
8
  class Error < StandardError
7
9
  end
8
10
 
@@ -0,0 +1,85 @@
1
+ module RfBeam
2
+ module KLD7
3
+ # All supported Serial port baude rates
4
+ BAUDE_RATES = { 0 => 115_200, 1 => 460_800, 2 => 921_600, 3 => 2_000_000, 4 => 3_000_000 }.freeze
5
+
6
+ # 'INIT' command response codes
7
+ RESP_CODES = {
8
+ 0 => 'OK',
9
+ 1 => 'Unknown command',
10
+ 2 => 'Invalid parameter value',
11
+ 3 => 'Invalid RPST version',
12
+ 4 => 'Uart error (parity, framing, noise)',
13
+ 5 => 'Sensor busy',
14
+ 6 => 'Timeout error',
15
+ }.freeze
16
+
17
+ # The response delay was determined empirically and may need adjusting with baude rate
18
+ RESP_DELAY = 0.1
19
+
20
+ # 'GNFD' command types
21
+ FRAME_DATA_TYPES = { disabled: 0x00, radc: 0x01, rfft: 0x02, pdat: 0x04, tdat: 0x08, ddat: 0x10, done: 0x20 }.freeze
22
+
23
+ # The angle, direction, range and speed flags are only valid if the detection flag is 1.
24
+ DETECTION_FLAGS = {
25
+ detection: ['No Detection', 'Detection'],
26
+ micro_detection: ['No Detection', 'Detection'],
27
+ angle: %w[Left Right],
28
+ direction: %w[Receding Approaching],
29
+ range: %w[Far Near],
30
+ speed: %w[Low High],
31
+ }.freeze
32
+
33
+ # GRPS - Parameter structure, used to map return values to readable strings
34
+ PARAMETER_STRUCTURE = {
35
+ base_frequency: ['Low', 'Middle', 'High'],
36
+ max_speed: ['12.5km/h', '25km/h', '50km/h', '100km/h'],
37
+ max_range: %w[5m 10m 30m 100m],
38
+ threshold_offset: '10db - 60db',
39
+ tracking_filter_type: ['standard', 'Fast Detection', 'Long Visibility'],
40
+ vibration_suppression: '0-16, 0 = No Suppression, 16 = High Suppression',
41
+ min_detection_distance: '0 - 100% of range setting',
42
+ max_detection_distance: '0 - 100% of range setting',
43
+ min_detection_angle: '-90° - 90°',
44
+ max_detection_angle: '-90° - 90°',
45
+ min_detection_speed: '0 - 100% of speed setting',
46
+ max_detection_speed: '0 - 100% of speed setting',
47
+ detection_direction: %w[receding approaching both],
48
+ range_threshold: '0 - 100% of range setting',
49
+ angle_threshold: '-90° - 90°',
50
+ speed_threshold: '0 - 100% of speed setting',
51
+ digital_output_1: %w[Direction Angle Range Speed Micro],
52
+ digital_output_2: %w[Direction Angle Range Speed Micro],
53
+ digital_output_3: %w[Direction Angle Range Speed Micro],
54
+ hold_time: '1 - 7200s',
55
+ micro_detection_trigger: %w[Off Retrigger],
56
+ micro_detection_sensitivity: '0 - 9, 0 = Min, 9 = Max'
57
+ }.freeze
58
+
59
+ # PARAMETERS = {
60
+ # sw_version: { grps_index: 2, default: 'K-LD7_APP-RFB-XXXX' },
61
+ # base_frequency: { grps_index: 3, description: '0 = Low, 1 = Middle, 2 = High', default: '1 - Middle', values: ['Low', 'Middle', 'High'] },
62
+ # max_speed: { grps_index: 4, description: '0 = 12km/h, 1 = 25km/h, 2 = 50km/h, 3 = 100km/h, default: 1', values: ['12.5km/h', '25km/h', '50km/h', '100km/h'] },
63
+ # max_range: { grps_index: 5, description: '0 = 5m, 1 = 10m, 2 = 30m, 3 = 100m, default: 1', values: %w[5m 10m 30m 100m] },
64
+ # threshold_offset: { grps_index: 6, description: '10db - 60db, default: 30', values: '10db - 60db' },
65
+ # tracking_filter_type: { grps_index: 7, description: '0 = Standard, 2 = Fast Detection, 3 = Long Visibility, default: 0', values: ['standard', 'Fast Detection', 'Long Visibility'] },
66
+ # vibration_suppression: { grps_index: 8, description: '0-16, 0 = No Suppression, 16 = High Suppression, default: 2' },
67
+ # min_detection_distance: { grps_index: 3, description: '0 - 100% of range setting, default: 0' },
68
+ # max_detection_distance: { grps_index: 10, description: '0 - 100% of range setting, default: 50' },
69
+ # min_detection_angle: { grps_index: 11, description: '-90° - 90°, default: -90' },
70
+ # max_detection_angle: { grps_index: 12, description: '-90° - 90°, default: 90' },
71
+ # min_detection_speed: { grps_index: 13, description: '0 - 100% of speed setting, default: 0' },
72
+ # max_detection_speed: { grps_index: 14, description: '0 - 100% of speed setting, default: 100' },
73
+ # detection_direction: { grps_index: 15, description: '0 = Receding, 1 = Approaching, 2 = Both, default: 2', values: %w[receding approaching both] },
74
+ # range_threshold: { grps_index: 16, description: '0 - 100% of range setting, default: 10', values: '0 - 100% of range setting' },
75
+ # angle_threshold: { grps_index: 17, description: '-90° - 90°, default: 0' },
76
+ # speed_threshold: { grps_index: 18, description: '0 - 100% of speed setting, default: 50' },
77
+ # digital_output_1: { grps_index: 19, description: '0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro Detection, default: 0', values: %w[Direction Angle Range Speed Micro] },
78
+ # digital_output_2: { grps_index: 20, description: '0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro Detection, default: 1', values: %w[Direction Angle Range Speed Micro] },
79
+ # digital_output_3: { grps_index: 21, description: '0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro Detection, default: 2', values: %w[Direction Angle Range Speed Micro] },
80
+ # hold_time: { grps_index: 22, description: '1 - 7200s, default: 1', values: '1 - 7200s' },
81
+ # micro_detection_trigger: { grps_index: 23, description: '0 = Off, 1 = Retrigger, default: 0' },
82
+ # micro_detection_sensitivity: { grps_index: 24, description: '0 - 9, 0 = Min, 9 = Max, default: 4' }'
83
+ # }
84
+ end
85
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RfBeam
4
- VERSION = '0.3.2'
4
+ VERSION = '0.3.4'
5
5
  end
data/lib/rfbeam.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rfbeam/kld7/commands'
4
- require 'rfbeam/kld7/detection'
5
- require 'rfbeam/kld7/parameters'
6
- require 'rfbeam/kld7/device_data'
3
+ require 'rfbeam/kld7/app_commands'
4
+ require 'rfbeam/kld7/app_messages'
5
+ require 'rfbeam/kld7/connection'
6
+ require 'rfbeam/kld7/constants'
7
7
  require_relative 'rfbeam/version'
8
8
 
9
9
  module RfBeam
@@ -14,16 +14,16 @@ module RfBeam
14
14
  include RfBeam::KLD7
15
15
  end
16
16
 
17
- def self.connected
18
- path_str, dir =
19
- if RubySerial::ON_LINUX
20
- %w[ttyUSB /dev/]
21
- elsif RubySerial::ON_WINDOWS
22
- ['TODO: Implement find device for Windows', 'You lazy bugger']
23
- else
24
- %w[tty.usbserial /dev/]
25
- end
26
-
27
- Dir.glob("#{dir}#{path_str}*")
17
+ def self.connected
18
+ path_str, dir =
19
+ if RubySerial::ON_LINUX
20
+ %w[ttyUSB /dev/]
21
+ elsif RubySerial::ON_WINDOWS
22
+ ['TODO: Implement find device for Windows', 'You lazy bugger']
23
+ else
24
+ %w[tty.usbserial /dev/]
25
+ end
26
+
27
+ Dir.glob("#{dir}#{path_str}*")
28
28
  end
29
29
  end
data/rfbeam.gemspec ADDED
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/rfbeam/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rfbeam'
7
+ spec.version = RfBeam::VERSION
8
+ spec.authors = ['Rob Carruthers']
9
+ spec.email = ['robc@hey.com']
10
+
11
+ spec.summary = 'Ruby API and CLI for RFBeam doplar radar modules'
12
+ spec.description = 'Currently only tested with K-LD7 on MacOS & Raspian (bullseye)'
13
+ spec.homepage = 'https://gitlab.com/robcarruthers/rfbeam'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.2.1'
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://gitlab.com/robcarruthers/rfbeam'
21
+ spec.metadata['changelog_uri'] = 'https://gitlab.com/robcarruthers/rfbeam/CHANGELOG.md'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files =
26
+ Dir.chdir(__dir__) do
27
+ `git ls-files -z`.split("\x0")
28
+ .reject do |f|
29
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
30
+ end
31
+ end
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ['lib']
35
+
36
+ # Uncomment to register a new dependency of your gem
37
+ # spec.add_dependency "example-gem", "~> 1.0"
38
+ spec.add_dependency 'activesupport', '~> 6.1.0'
39
+ # spec.add_dependency 'bindata', '~> 2.4.10'
40
+ spec.add_dependency 'rubyserial', '~> 0.6.0'
41
+ # spec.add_dependency 'terminal-table', '~> 3.0.2'
42
+ spec.add_dependency 'thor', '~> 1.2.1'
43
+
44
+ # For more information and examples about making a new gem, check out our
45
+ # guide at: https://bundler.io/guides/creating_gem.html
46
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfbeam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Carruthers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-29 00:00:00.000000000 Z
11
+ date: 2023-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.2.1
55
- description: Currently only works K-LD7 on Raspberry Pi (MacOS & Ubuntu 22.04 LTS)
55
+ description: Currently only tested with K-LD7 on MacOS & Raspian (bullseye)
56
56
  email:
57
57
  - robc@hey.com
58
58
  executables: []
@@ -69,10 +69,10 @@ files:
69
69
  - README.md
70
70
  - Rakefile
71
71
  - lib/rfbeam.rb
72
- - lib/rfbeam/kld7/commands.rb
73
- - lib/rfbeam/kld7/detection.rb
74
- - lib/rfbeam/kld7/device_data.rb
75
- - lib/rfbeam/kld7/parameters.rb
72
+ - lib/rfbeam/kld7/app_commands.rb
73
+ - lib/rfbeam/kld7/app_messages.rb
74
+ - lib/rfbeam/kld7/connection.rb
75
+ - lib/rfbeam/kld7/constants.rb
76
76
  - lib/rfbeam/version.rb
77
77
  - node_modules/.bin/prettier
78
78
  - node_modules/.yarn-integrity
@@ -160,6 +160,7 @@ files:
160
160
  - node_modules/prettier/standalone.js
161
161
  - node_modules/prettier/third-party.js
162
162
  - package.json
163
+ - rfbeam.gemspec
163
164
  - sig/rfbeam.rbs
164
165
  - yarn.lock
165
166
  homepage: https://gitlab.com/robcarruthers/rfbeam
@@ -177,15 +178,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
178
  requirements:
178
179
  - - ">="
179
180
  - !ruby/object:Gem::Version
180
- version: 2.7.6
181
+ version: 3.2.1
181
182
  required_rubygems_version: !ruby/object:Gem::Requirement
182
183
  requirements:
183
184
  - - ">="
184
185
  - !ruby/object:Gem::Version
185
186
  version: '0'
186
187
  requirements: []
187
- rubygems_version: 3.1.6
188
+ rubygems_version: 3.4.9
188
189
  signing_key:
189
190
  specification_version: 4
190
- summary: Ruby Serial interface and CLI for RFBeam doplar radar modules
191
+ summary: Ruby API and CLI for RFBeam doplar radar modules
191
192
  test_files: []
@@ -1,31 +0,0 @@
1
- module RfBeam
2
- module KLD7
3
- def detection?
4
- data = ddat
5
- (data[2] == 1)
6
- end
7
-
8
- def tdat
9
- request_frame_data(:tdat)
10
-
11
- sleep 0.1
12
- resp = read(16).unpack('a4LSssS')
13
- return { dist: resp[2], speed: resp[3], angle: resp[4], mag: resp[5] } unless resp[1].zero?
14
- end
15
-
16
- def ddat
17
- request_frame_data(:ddat)
18
-
19
- resp = read(14).unpack('a4LC6')
20
- return resp
21
- end
22
-
23
- private
24
-
25
- def request_frame_data(type)
26
- command = ['GNFD', 4, FRAME_DATA_TYPES[type]]
27
- write command.pack('a4LL')
28
- check_response
29
- end
30
- end
31
- end
@@ -1,59 +0,0 @@
1
- module RfBeam
2
- module KLD7
3
- # All supported Serial port baude rates
4
- BAUDE_RATES = { 0 => 115_200, 1 => 460_800, 2 => 921_600, 3 => 2_000_000, 4 => 3_000_000 }.freeze
5
-
6
- # 'INIT' command response codes
7
- RESP_CODES = {
8
- 0 => 'OK',
9
- 1 => 'Unknown command',
10
- 2 => 'Invalid parameter value',
11
- 3 => 'Invalid RPST version',
12
- 4 => 'Uart error (parity, framing, noise)',
13
- 5 => 'Sensor busy',
14
- 6 => 'Timeout error',
15
- }.freeze
16
-
17
- # The response delay was determined empirically and may need adjusting with baude rate
18
- RESP_DELAY = 0.1
19
-
20
- # 'GNFD' command types
21
- FRAME_DATA_TYPES = { disabled: 0x00, radc: 0x01, rfft: 0x02, pdat: 0x04, tdat: 0x08, ddat: 0x10, done: 0x20 }.freeze
22
-
23
- # The angle, direction, range and speed flags are only valid if the detection flag is 1.
24
- DETECTION_FLAGS = {
25
- detection: ['No Detection', 'Detection'],
26
- micro_detection: ['No Detection', 'Detection'],
27
- angle: %w[Left Right],
28
- direction: %w[Receding Approaching],
29
- range: %w[Far Near],
30
- speed: %w[Low High],
31
- }
32
-
33
- # GRPS - Parameter structture, used to map return values to readable strings
34
- PARAMETER_STRUCTURE = {
35
- base_frequency: ['Low', 'Middle', 'High'],
36
- max_speed: ['12.5km/h', '25km/h', '50km/h', '100km/h'],
37
- max_range: %w[5m 10m 30m 100m],
38
- threshold_offset: '10db - 60db',
39
- tracking_filter_type: ['standard', 'Fast Detection', 'Long Visibility'],
40
- vibration_suppression: '0-16, 0 = No Suppression, 16 = High Suppression',
41
- min_detection_distance: '0 - 100% of range setting',
42
- max_detection_distance: '0 - 100% of range setting',
43
- min_detection_angle: '-90° - 90°',
44
- max_detection_angle: '-90° - 90°',
45
- min_detection_speed: '0 - 100% of speed setting',
46
- max_detection_speed: '0 - 100% of speed setting',
47
- detection_direction: %w[receding approaching both],
48
- range_threshold: '0 - 100% of range setting',
49
- angle_threshold: '-90° - 90°',
50
- speed_threshold: '0 - 100% of speed setting',
51
- digital_output_1: %w[Direction Angle Range Speed Micro],
52
- digital_output_2: %w[Direction Angle Range Speed Micro],
53
- digital_output_3: %w[Direction Angle Range Speed Micro],
54
- hold_time: '1 - 7200s',
55
- micro_detection_trigger: %w[Off Retrigger],
56
- micro_detection_sensitivity: '0 - 9, 0 = Min, 9 = Max'
57
- }
58
- end
59
- end