aprs_is 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2628f0430c1aaaab4c4db1dc0e6b3501a3605e76b8cc8c9ebdb2a40529b0ae12
4
+ data.tar.gz: e9d66295e712e9d32684701e69c5d53f7a5dfd9fca484674aecd68e374a710c0
5
+ SHA512:
6
+ metadata.gz: dcd936e78c5b5a03ec8b7eb09b231c4d34f38932d86bd8c613d880dfc9c4b30c9cabb3045eef27673f45ea6e50c93012673c2c8f369b592115fdeb33b06167ba
7
+ data.tar.gz: 88e0e29ea7793741a80a720939a9800f3936393121a4877702b3935dc962a94e8614bf0813a0d47f976a5972fa8e718eca6196d994c9333ab171f9865205e465
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,10 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.3
6
+ - 2.6.6
7
+ - 2.7.0
8
+ - 2.7.2
9
+ - 2.5.7
10
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in aprs_is-client.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ aprs_is (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (11.1.3)
10
+ coderay (1.1.3)
11
+ diff-lcs (1.4.4)
12
+ docile (1.3.2)
13
+ ffi (1.13.1)
14
+ formatador (0.2.5)
15
+ guard (2.16.2)
16
+ formatador (>= 0.2.4)
17
+ listen (>= 2.7, < 4.0)
18
+ lumberjack (>= 1.0.12, < 2.0)
19
+ nenv (~> 0.1)
20
+ notiffany (~> 0.0)
21
+ pry (>= 0.9.12)
22
+ shellany (~> 0.0)
23
+ thor (>= 0.18.1)
24
+ guard-compat (1.2.1)
25
+ guard-rspec (4.7.3)
26
+ guard (~> 2.1)
27
+ guard-compat (~> 1.1)
28
+ rspec (>= 2.99.0, < 4.0)
29
+ listen (3.2.1)
30
+ rb-fsevent (~> 0.10, >= 0.10.3)
31
+ rb-inotify (~> 0.9, >= 0.9.10)
32
+ lumberjack (1.2.8)
33
+ method_source (1.0.0)
34
+ nenv (0.3.0)
35
+ notiffany (0.1.3)
36
+ nenv (~> 0.1)
37
+ shellany (~> 0.0)
38
+ pry (0.13.1)
39
+ coderay (~> 1.1)
40
+ method_source (~> 1.0)
41
+ rake (12.3.2)
42
+ rb-fsevent (0.10.4)
43
+ rb-inotify (0.10.1)
44
+ ffi (~> 1.0)
45
+ rspec (3.9.0)
46
+ rspec-core (~> 3.9.0)
47
+ rspec-expectations (~> 3.9.0)
48
+ rspec-mocks (~> 3.9.0)
49
+ rspec-core (3.9.3)
50
+ rspec-support (~> 3.9.3)
51
+ rspec-expectations (3.9.4)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.9.0)
54
+ rspec-mocks (3.9.1)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.9.0)
57
+ rspec-support (3.9.4)
58
+ shellany (0.0.1)
59
+ simplecov (0.19.1)
60
+ docile (~> 1.1)
61
+ simplecov-html (~> 0.11)
62
+ simplecov-html (0.12.3)
63
+ terminal-notifier-guard (1.6.4)
64
+ thor (1.0.1)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ aprs_is!
71
+ byebug
72
+ guard
73
+ guard-rspec
74
+ rake (~> 12.0)
75
+ rspec (~> 3.2)
76
+ simplecov
77
+ terminal-notifier-guard (~> 1.6.1)
78
+
79
+ BUNDLED WITH
80
+ 2.1.4
@@ -0,0 +1,46 @@
1
+ notification :terminal_notifier, app_name: "AprsIs::Client" if `uname` =~ /Darwin/
2
+
3
+ guard :rspec, cmd: "bundle exec rspec" do
4
+ require "guard/rspec/dsl"
5
+ dsl = Guard::RSpec::Dsl.new(self)
6
+
7
+ # Feel free to open issues for suggestions and improvements
8
+
9
+ # RSpec files
10
+ rspec = dsl.rspec
11
+ watch(rspec.spec_helper) { rspec.spec_dir }
12
+ watch(rspec.spec_support) { rspec.spec_dir }
13
+ watch(rspec.spec_files)
14
+
15
+ # Ruby files
16
+ ruby = dsl.ruby
17
+ dsl.watch_spec_files_for(ruby.lib_files)
18
+
19
+ # Rails files
20
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
21
+ dsl.watch_spec_files_for(rails.app_files)
22
+ dsl.watch_spec_files_for(rails.views)
23
+
24
+ watch(rails.controllers) do |m|
25
+ [
26
+ rspec.spec.call("routing/#{m[1]}_routing"),
27
+ rspec.spec.call("controllers/#{m[1]}_controller"),
28
+ rspec.spec.call("acceptance/#{m[1]}")
29
+ ]
30
+ end
31
+
32
+ # Rails config changes
33
+ watch(rails.spec_helper) { rspec.spec_dir }
34
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
35
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
36
+
37
+ # Capybara features specs
38
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
39
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
40
+
41
+ # Turnip features and steps
42
+ watch(%r{^spec/acceptance/(.+)\.feature$})
43
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
44
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
45
+ end
46
+ end
@@ -0,0 +1,35 @@
1
+ # AprsIs::Client
2
+ [![Build Status](https://travis-ci.com/fuelxc/aprs_is.svg?branch=main)](https://travis-ci.com/fuelxc/aprs_is)
3
+
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'aprs_is'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle install
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install aprs_is
21
+
22
+ ## Usage
23
+
24
+ TODO: Write usage instructions here
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+
30
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fuelxc/aprs_is.
35
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,34 @@
1
+ require_relative 'lib/aprs_is/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "aprs_is"
5
+ spec.version = AprsIs::VERSION
6
+ spec.authors = ["Eric Harrison"]
7
+ spec.email = ["eric@rubynooby.com"]
8
+
9
+ spec.summary = %q{Gem that implements the APRS-IS specification}
10
+ spec.homepage = "https://github.com/fuelxc/aprs_is"
11
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
12
+
13
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/fuelxc/aprs_is"
17
+ spec.metadata["changelog_uri"] = "https://github.com/fuelxc/aprs_is/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "rspec", "~> 3.2"
29
+ spec.add_development_dependency "guard"
30
+ spec.add_development_dependency "guard-rspec"
31
+ spec.add_development_dependency "byebug"
32
+ spec.add_development_dependency 'terminal-notifier-guard', '~> 1.6.1'
33
+ spec.add_development_dependency 'simplecov'
34
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "aprs_is"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ require 'aprs_is/version'
2
+ require 'aprs_is/passcode'
3
+ require 'aprs_is/filter'
4
+ require 'aprs_is/client'
5
+
6
+ module AprsIs
7
+ end
@@ -0,0 +1,63 @@
1
+ require 'socket'
2
+
3
+ module AprsIs
4
+ class Client
5
+ attr_reader :hostname, :port, :version
6
+
7
+ class Error < StandardError; end
8
+
9
+ def initialize(hostname:, port:, version: "AprsIs::Client v#{VERSION}")
10
+ @hostname = hostname
11
+ @port = port
12
+ @version = version
13
+ end
14
+
15
+ def login(call_sign, filter = nil)
16
+ send_message(login_message(call_sign, filter))
17
+ return self
18
+ end
19
+
20
+ def apply_filter(filter)
21
+ send_message(filter_message(filter))
22
+ end
23
+
24
+ def read(&block)
25
+ while line = socket.gets
26
+ yield line
27
+ end
28
+ end
29
+
30
+ # :nocov:
31
+ def stream(&block)
32
+ loop do
33
+ read(&block)
34
+ end
35
+ end
36
+ # :nocov:
37
+
38
+ def send_message(message)
39
+ socket.puts message
40
+ end
41
+
42
+ private
43
+
44
+ def login_message(call_sign, filter = nil)
45
+ [
46
+ "user #{call_sign} pass #{passcode_for(call_sign)} vers #{version}",
47
+ filter&.to_s
48
+ ].compact.join(" ")
49
+ end
50
+
51
+ def filter_message(filter)
52
+ "filter #{filter}"
53
+ end
54
+
55
+ def passcode_for(call_sign)
56
+ @passcode = AprsIs::Passcode.new(call_sign)
57
+ end
58
+
59
+ def socket
60
+ @socket ||= TCPSocket.open(hostname, port)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,47 @@
1
+ require 'aprs_is/filter/constants'
2
+
3
+ module AprsIs
4
+ class Filter
5
+ class InvalidTypeError < StandardError; end;
6
+ class ValueArityError < StandardError; end;
7
+
8
+ attr_reader :filter_type, :values
9
+
10
+ def initialize(type:, values: )
11
+ @filter_type = type
12
+ @values = values || []
13
+
14
+ validate_filter_type
15
+ validate_arity
16
+ end
17
+
18
+ def to_s
19
+ values.unshift(prefix).compact.join("/")
20
+ end
21
+
22
+ private
23
+ def validate_arity
24
+ raise ValueArityError.new("Filter type '#{filter_type}' requires #{arity} values only #{values.length} given.") unless arity_matches?
25
+ end
26
+
27
+ def validate_filter_type
28
+ raise InvalidTypeError.new("'#{filter_type}' is not a valid type.") unless type_exists?
29
+ end
30
+
31
+ def arity_matches?
32
+ (arity == -1 && values.length > 0) || [arity].flatten.include?(values.length)
33
+ end
34
+
35
+ def type_exists?
36
+ Constants::FILTER_TYPE_MAP.has_key?(filter_type)
37
+ end
38
+
39
+ def arity
40
+ Constants::FILTER_TYPE_MAP[filter_type][:arity]
41
+ end
42
+
43
+ def prefix
44
+ Constants::FILTER_TYPE_MAP[filter_type][:prefix]
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,68 @@
1
+ module AprsIs
2
+ class Filter
3
+ module Constants
4
+ FILTER_TYPE_MAP = {
5
+ range: {
6
+ prefix: 'r',
7
+ arity: 3
8
+ },
9
+ prefix: {
10
+ prefix: 'p',
11
+ arity: -1
12
+ },
13
+ callsign: {
14
+ prefix: 'b',
15
+ arity: -1
16
+ },
17
+ object: {
18
+ prefix: 'o',
19
+ arity: -1
20
+ },
21
+ strict: {
22
+ prefix: 'os',
23
+ arity: -1
24
+ },
25
+ type: {
26
+ prefix: 't',
27
+ arity: [1,3]
28
+ },
29
+ symbol: {
30
+ prefix: 's',
31
+ arity: 3
32
+ },
33
+ digipeater: {
34
+ prefix: 'd',
35
+ arity: -1
36
+ },
37
+ area: {
38
+ prefix: 'a',
39
+ arity: 4
40
+ },
41
+ entry: {
42
+ prefix: 'e',
43
+ arity: -1
44
+ },
45
+ group: {
46
+ prefix: 'g',
47
+ arity: -1
48
+ },
49
+ unproto: {
50
+ prefix: 'u',
51
+ arity: -1
52
+ },
53
+ q: {
54
+ prefix: 'q',
55
+ arity: (1..2)
56
+ },
57
+ me: {
58
+ prefix: 'm',
59
+ arity: 1
60
+ },
61
+ friend: {
62
+ prefix: 'f',
63
+ arity: 2
64
+ },
65
+ }.freeze
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,33 @@
1
+ module AprsIs
2
+ class Passcode
3
+ attr_reader :call_sign
4
+
5
+ def initialize(call_sign)
6
+ @call_sign = call_sign
7
+ end
8
+
9
+ def to_s
10
+ generate.to_s
11
+ end
12
+
13
+ def generate
14
+ hash = 0x73e2
15
+ flag = true
16
+ call_sign_for_generation.split('').each do |c|
17
+ hash = if flag
18
+ (hash ^ (c.ord << 8))
19
+ else
20
+ (hash ^ c.ord)
21
+ end
22
+ flag = !flag
23
+ end
24
+ hash & 0x7fff
25
+ end
26
+
27
+ private
28
+
29
+ def call_sign_for_generation
30
+ call_sign.upcase.split('-').first
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module AprsIs
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aprs_is
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric Harrison
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: terminal-notifier-guard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.6.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.6.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - eric@rubynooby.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - Guardfile
110
+ - README.md
111
+ - Rakefile
112
+ - aprs_is.gemspec
113
+ - bin/console
114
+ - bin/setup
115
+ - lib/aprs_is.rb
116
+ - lib/aprs_is/client.rb
117
+ - lib/aprs_is/filter.rb
118
+ - lib/aprs_is/filter/constants.rb
119
+ - lib/aprs_is/passcode.rb
120
+ - lib/aprs_is/version.rb
121
+ homepage: https://github.com/fuelxc/aprs_is
122
+ licenses: []
123
+ metadata:
124
+ homepage_uri: https://github.com/fuelxc/aprs_is
125
+ source_code_uri: https://github.com/fuelxc/aprs_is
126
+ changelog_uri: https://github.com/fuelxc/aprs_is/CHANGELOG.md
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: 2.3.0
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubygems_version: 3.0.3
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Gem that implements the APRS-IS specification
146
+ test_files: []