rfbeam 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.rubocop.yml +11 -0
- data/.tool-versions +1 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +63 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +16 -0
- data/lib/rfbeam/kld7/commands.rb +89 -0
- data/lib/rfbeam/kld7/detection.rb +32 -0
- data/lib/rfbeam/kld7/device_data.rb +33 -0
- data/lib/rfbeam/version.rb +5 -0
- data/lib/rfbeam.rb +28 -0
- data/node_modules/.bin/prettier +1 -0
- data/node_modules/.yarn-integrity +19 -0
- data/node_modules/@prettier/plugin-ruby/CHANGELOG.md +1351 -0
- data/node_modules/@prettier/plugin-ruby/CODE_OF_CONDUCT.md +76 -0
- data/node_modules/@prettier/plugin-ruby/CONTRIBUTING.md +185 -0
- data/node_modules/@prettier/plugin-ruby/LICENSE +21 -0
- data/node_modules/@prettier/plugin-ruby/README.md +226 -0
- data/node_modules/@prettier/plugin-ruby/docs/logo.png +0 -0
- data/node_modules/@prettier/plugin-ruby/node_modules/.bin/prettier +1 -0
- data/node_modules/@prettier/plugin-ruby/package.json +64 -0
- data/node_modules/@prettier/plugin-ruby/prettier.gemspec +36 -0
- data/node_modules/@prettier/plugin-ruby/rubocop.yml +64 -0
- data/node_modules/@prettier/plugin-ruby/src/getInfo.js +23 -0
- data/node_modules/@prettier/plugin-ruby/src/netcat.js +13 -0
- data/node_modules/@prettier/plugin-ruby/src/parseSync.js +236 -0
- data/node_modules/@prettier/plugin-ruby/src/plugin.js +172 -0
- data/node_modules/@prettier/plugin-ruby/src/server.rb +199 -0
- data/node_modules/prettier/LICENSE +5945 -0
- data/node_modules/prettier/README.md +109 -0
- data/node_modules/prettier/bin-prettier.js +62 -0
- data/node_modules/prettier/cli.js +15136 -0
- data/node_modules/prettier/doc.js +1473 -0
- data/node_modules/prettier/esm/parser-angular.mjs +2 -0
- data/node_modules/prettier/esm/parser-babel.mjs +29 -0
- data/node_modules/prettier/esm/parser-espree.mjs +26 -0
- data/node_modules/prettier/esm/parser-flow.mjs +35 -0
- data/node_modules/prettier/esm/parser-glimmer.mjs +27 -0
- data/node_modules/prettier/esm/parser-graphql.mjs +15 -0
- data/node_modules/prettier/esm/parser-html.mjs +36 -0
- data/node_modules/prettier/esm/parser-markdown.mjs +76 -0
- data/node_modules/prettier/esm/parser-meriyah.mjs +19 -0
- data/node_modules/prettier/esm/parser-postcss.mjs +76 -0
- data/node_modules/prettier/esm/parser-typescript.mjs +257 -0
- data/node_modules/prettier/esm/parser-yaml.mjs +150 -0
- data/node_modules/prettier/esm/standalone.mjs +116 -0
- data/node_modules/prettier/index.js +37885 -0
- data/node_modules/prettier/package.json +21 -0
- data/node_modules/prettier/parser-angular.js +2 -0
- data/node_modules/prettier/parser-babel.js +29 -0
- data/node_modules/prettier/parser-espree.js +26 -0
- data/node_modules/prettier/parser-flow.js +35 -0
- data/node_modules/prettier/parser-glimmer.js +27 -0
- data/node_modules/prettier/parser-graphql.js +15 -0
- data/node_modules/prettier/parser-html.js +36 -0
- data/node_modules/prettier/parser-markdown.js +76 -0
- data/node_modules/prettier/parser-meriyah.js +19 -0
- data/node_modules/prettier/parser-postcss.js +76 -0
- data/node_modules/prettier/parser-typescript.js +257 -0
- data/node_modules/prettier/parser-yaml.js +150 -0
- data/node_modules/prettier/standalone.js +116 -0
- data/node_modules/prettier/third-party.js +8978 -0
- data/package.json +6 -0
- data/sig/rfbeam.rbs +4 -0
- data/yarn.lock +15 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '0998bf706cfa767dc3a07068c8dbcf7880ef64424f3038c7eb0456d085d23025'
|
4
|
+
data.tar.gz: cbbfe4127e8baf44f60b5f85249e3556529dde8d1b9a15844811eedd6d192aea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c4ed534db0956ee23f694327f28c193614f9144d7245aa988d4b2748608dc4840f3accf499ce006fcbf97d2ac73323cbc155dcb209b8b480acd9ab11ac78efe4
|
7
|
+
data.tar.gz: b9ba0b492230144d84b8612caf1ee1345c354cd5d95bacf6e4bb9548ebe5c2839375e23b15f8f06028b037ff8fcf96222f29d0bf2b2d894617889a75319945ae
|
data/.DS_Store
ADDED
Binary file
|
data/.rubocop.yml
ADDED
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.7.6
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rfbeam (0.1.0)
|
5
|
+
activesupport (~> 6.1.0)
|
6
|
+
rubyserial (~> 0.6.0)
|
7
|
+
thor (~> 1.2.1)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (6.1.7)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (>= 1.6, < 2)
|
15
|
+
minitest (>= 5.1)
|
16
|
+
tzinfo (~> 2.0)
|
17
|
+
zeitwerk (~> 2.3)
|
18
|
+
ast (2.4.2)
|
19
|
+
concurrent-ruby (1.1.10)
|
20
|
+
ffi (1.15.5)
|
21
|
+
i18n (1.12.0)
|
22
|
+
concurrent-ruby (~> 1.0)
|
23
|
+
json (2.6.2)
|
24
|
+
minitest (5.16.3)
|
25
|
+
parallel (1.22.1)
|
26
|
+
parser (3.1.3.0)
|
27
|
+
ast (~> 2.4.1)
|
28
|
+
rainbow (3.1.1)
|
29
|
+
rake (13.0.6)
|
30
|
+
regexp_parser (2.6.1)
|
31
|
+
rexml (3.2.5)
|
32
|
+
rubocop (1.39.0)
|
33
|
+
json (~> 2.3)
|
34
|
+
parallel (~> 1.10)
|
35
|
+
parser (>= 3.1.2.1)
|
36
|
+
rainbow (>= 2.2.2, < 4.0)
|
37
|
+
regexp_parser (>= 1.8, < 3.0)
|
38
|
+
rexml (>= 3.2.5, < 4.0)
|
39
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
40
|
+
ruby-progressbar (~> 1.7)
|
41
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
42
|
+
rubocop-ast (1.23.0)
|
43
|
+
parser (>= 3.1.1.0)
|
44
|
+
ruby-progressbar (1.11.0)
|
45
|
+
rubyserial (0.6.0)
|
46
|
+
ffi (~> 1.9, >= 1.9.3)
|
47
|
+
thor (1.2.1)
|
48
|
+
tzinfo (2.0.5)
|
49
|
+
concurrent-ruby (~> 1.0)
|
50
|
+
unicode-display_width (2.3.0)
|
51
|
+
zeitwerk (2.6.6)
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
arm64-darwin-21
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
minitest (~> 5.0)
|
58
|
+
rake (~> 13.0)
|
59
|
+
rfbeam!
|
60
|
+
rubocop (~> 1.21)
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
2.3.26
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Rob Carruthers
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Rfbeam
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rfbeam`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add rfbeam
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install rfbeam
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
❯ bin/console
|
21
|
+
irb(main):001:0> RfBeam.connected
|
22
|
+
=> ["/dev/tty.usbserial-FTBX7TKD"]
|
23
|
+
irb(main):002:0> r = RfBeam::K_ld7.new("/dev/tty.usbserial-FTBX7TKD", 115200)
|
24
|
+
=> #<RfBeam::K_ld7:0x0000000146bb2ff0 @serial_port=#<Serial:0x0000000146bb2f28 @fd=9, @open=true, @config=#<RubySerial::Posix::Termios:0x0000000146bb2cf8>>>
|
25
|
+
irb(main):003:0> r.detection?
|
26
|
+
=> false
|
27
|
+
irb(main):004:0> r.detection?
|
28
|
+
=> true
|
29
|
+
irb(main):005:0> r.tdat
|
30
|
+
=> {:dist=>68, :speed=>196, :angle=>469, :mag=>6303}
|
31
|
+
```
|
32
|
+
|
33
|
+
## Development
|
34
|
+
|
35
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
36
|
+
|
37
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rfbeam.
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: %i[test rubocop]
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module RfBeam
|
2
|
+
module KLD7
|
3
|
+
require 'rubyserial'
|
4
|
+
require 'timeout'
|
5
|
+
|
6
|
+
class Error < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :serial_port
|
10
|
+
|
11
|
+
def initialize(path, baude_rate = 0)
|
12
|
+
baude_rate = check_speed(baude_rate)
|
13
|
+
data_bits = 8
|
14
|
+
parity = :even
|
15
|
+
stop_bits = 1
|
16
|
+
open_serial_port(path, baude_rate, data_bits, parity, stop_bits)
|
17
|
+
init_radar if connected?
|
18
|
+
|
19
|
+
yield self if block_given?
|
20
|
+
end
|
21
|
+
|
22
|
+
def close
|
23
|
+
return unless connected?
|
24
|
+
|
25
|
+
@serial_port.close
|
26
|
+
@serial_port = nil
|
27
|
+
@serial_port.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
def read(bytes)
|
31
|
+
return unless connected?
|
32
|
+
|
33
|
+
@serial_port.read(bytes)
|
34
|
+
end
|
35
|
+
|
36
|
+
def write(string)
|
37
|
+
return unless connected?
|
38
|
+
|
39
|
+
@serial_port.write(string)
|
40
|
+
sleep 0.1
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def open_serial_port(path, baude_rate, data_bits, parity, stop_bits)
|
46
|
+
@serial_port = Serial.new(path, baude_rate, data_bits, parity, stop_bits)
|
47
|
+
end
|
48
|
+
|
49
|
+
def connected?
|
50
|
+
raise Error, 'ConnectionError: No open Serial device connections.' if @serial_port.nil?
|
51
|
+
|
52
|
+
true
|
53
|
+
end
|
54
|
+
|
55
|
+
def flush
|
56
|
+
return unless connected?
|
57
|
+
|
58
|
+
loop until serial_port.getbyte.nil?
|
59
|
+
end
|
60
|
+
|
61
|
+
def check_speed(baude)
|
62
|
+
if BAUDE_RATES.value? baude
|
63
|
+
baude
|
64
|
+
elsif BAUDE_RATES.key? baude
|
65
|
+
BAUDE_RATES[baude]
|
66
|
+
else
|
67
|
+
115_200
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def init_radar
|
72
|
+
command = ['INIT', 4, 0]
|
73
|
+
@serial_port.write command.pack('a4LL') # 4 ASCII bytes, UINT32, UINT32
|
74
|
+
check_response
|
75
|
+
end
|
76
|
+
|
77
|
+
def check_response
|
78
|
+
sleep RESP_DELAY
|
79
|
+
resp = @serial_port.read(9).unpack('a4LC') # 4 ASCII bytes, UINT32, UINT8
|
80
|
+
raise Error, 'No valid response from Serial Port' if resp[2].nil?
|
81
|
+
|
82
|
+
response_key = resp[2]
|
83
|
+
return if response_key.zero? # Everything OK
|
84
|
+
|
85
|
+
error_string = RESP_CODES[response_key].nil? ? 'Response unknown' : RESP_CODES[response_key]
|
86
|
+
raise Error, "Initialisation Error: #{error_string}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module RfBeam
|
2
|
+
module KLD7
|
3
|
+
def detection?
|
4
|
+
data = ddat
|
5
|
+
p data
|
6
|
+
(data[2] == 1)
|
7
|
+
end
|
8
|
+
|
9
|
+
def tdat
|
10
|
+
request_frame_data(:tdat)
|
11
|
+
|
12
|
+
sleep 0.1
|
13
|
+
resp = read(16).unpack('a4LSssS')
|
14
|
+
return { dist: resp[2], speed: resp[3], angle: resp[4], mag: resp[5] } unless resp[1].zero?
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def ddat
|
20
|
+
request_frame_data(:ddat)
|
21
|
+
|
22
|
+
resp = read(14).unpack('a4LC6')
|
23
|
+
return resp
|
24
|
+
end
|
25
|
+
|
26
|
+
def request_frame_data(type)
|
27
|
+
command = ['GNFD', 4, FRAME_DATA_TYPES[type]]
|
28
|
+
write command.pack('a4LL')
|
29
|
+
check_response
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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
|
+
end
|
33
|
+
end
|
data/lib/rfbeam.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rfbeam/kld7/commands'
|
4
|
+
require 'rfbeam/kld7/detection'
|
5
|
+
require 'rfbeam/kld7/device_data'
|
6
|
+
require_relative 'rfbeam/version'
|
7
|
+
|
8
|
+
module RfBeam
|
9
|
+
class Error < StandardError
|
10
|
+
end
|
11
|
+
|
12
|
+
class K_ld7
|
13
|
+
include RfBeam::KLD7
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.connected
|
17
|
+
path_str, dir =
|
18
|
+
if RubySerial::ON_LINUX
|
19
|
+
%w[ttyUSB /dev/]
|
20
|
+
elsif RubySerial::ON_WINDOWS
|
21
|
+
['TODO: Implement find device for Windows', 'You lazy bugger']
|
22
|
+
else
|
23
|
+
%w[tty.usbserial /dev/]
|
24
|
+
end
|
25
|
+
|
26
|
+
Dir.glob("#{dir}#{path_str}*")
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
../prettier/bin-prettier.js
|
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"systemParams": "darwin-arm64-108",
|
3
|
+
"modulesFolders": [
|
4
|
+
"node_modules"
|
5
|
+
],
|
6
|
+
"flags": [],
|
7
|
+
"linkedModules": [],
|
8
|
+
"topLevelPatterns": [
|
9
|
+
"@prettier/plugin-ruby@^3.2.2",
|
10
|
+
"prettier@^2.8.0"
|
11
|
+
],
|
12
|
+
"lockfileEntries": {
|
13
|
+
"@prettier/plugin-ruby@^3.2.2": "https://registry.yarnpkg.com/@prettier/plugin-ruby/-/plugin-ruby-3.2.2.tgz#43c9d85349032f74d34c4f57e6a77487d5c5bdc1",
|
14
|
+
"prettier@>=2.3.0": "https://registry.yarnpkg.com/prettier/-/prettier-2.8.0.tgz#c7df58393c9ba77d6fba3921ae01faf994fb9dc9",
|
15
|
+
"prettier@^2.8.0": "https://registry.yarnpkg.com/prettier/-/prettier-2.8.0.tgz#c7df58393c9ba77d6fba3921ae01faf994fb9dc9"
|
16
|
+
},
|
17
|
+
"files": [],
|
18
|
+
"artifacts": {}
|
19
|
+
}
|