lib-tl1 0.1.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.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/gem-push.yml +31 -0
  3. data/.gitignore +12 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +22 -0
  6. data/.ruby-gemset +1 -0
  7. data/.ruby-version +1 -0
  8. data/CHANGELOG.md +5 -0
  9. data/CODE_OF_CONDUCT.md +84 -0
  10. data/Gemfile +12 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +43 -0
  13. data/Rakefile +12 -0
  14. data/bin/console +15 -0
  15. data/bin/setup +8 -0
  16. data/lib-tl1.gemspec +33 -0
  17. data/lib/lib/tl1.rb +8 -0
  18. data/lib/lib/tl1/message.rb +39 -0
  19. data/lib/lib/tl1/message/acknowledgment.rb +50 -0
  20. data/lib/lib/tl1/message/autonomous.rb +78 -0
  21. data/lib/lib/tl1/message/field.rb +18 -0
  22. data/lib/lib/tl1/message/field/access_identifier.rb +17 -0
  23. data/lib/lib/tl1/message/field/acknowledgment_code.rb +45 -0
  24. data/lib/lib/tl1/message/field/alarm_code.rb +42 -0
  25. data/lib/lib/tl1/message/field/base.rb +35 -0
  26. data/lib/lib/tl1/message/field/command_verb.rb +24 -0
  27. data/lib/lib/tl1/message/field/completion_code.rb +67 -0
  28. data/lib/lib/tl1/message/field/correlation_tag.rb +31 -0
  29. data/lib/lib/tl1/message/field/date.rb +25 -0
  30. data/lib/lib/tl1/message/field/general_block.rb +17 -0
  31. data/lib/lib/tl1/message/field/payload.rb +17 -0
  32. data/lib/lib/tl1/message/field/system_identifier.rb +17 -0
  33. data/lib/lib/tl1/message/field/target_identifier.rb +24 -0
  34. data/lib/lib/tl1/message/field/text_block.rb +38 -0
  35. data/lib/lib/tl1/message/field/time.rb +27 -0
  36. data/lib/lib/tl1/message/input.rb +79 -0
  37. data/lib/lib/tl1/message/output.rb +73 -0
  38. data/lib/lib/tl1/version.rb +10 -0
  39. metadata +82 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ed86149b9bbf7b03e4d43da718d078ce386f369b88227df5f347f964a7ec627d
4
+ data.tar.gz: 424eb73445bab78ebe64de2b466e77c539edd7e9c5306dc304e28a0bc6e245ea
5
+ SHA512:
6
+ metadata.gz: 5b3cf4ac73a83227e8ed4d525e1040cdea438990f7e1631e54549fdc6a0ed731ba0a8ce74ddcf3e580bd7350406656713dcab62f28b9b7c82f5a3b498463c4b7
7
+ data.tar.gz: 5ef144f03c51d4acd862943c087701799c0fb0eb6f052f5214fa12f9f4fa0bf1c16caf910c95a03af589945137319be0382291411c476fd9a07e13bd5afe38ef
@@ -0,0 +1,31 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build + Publish
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: read
13
+ packages: write
14
+
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Set up Ruby 3.0
18
+ uses: actions/setup-ruby@v1
19
+ with:
20
+ ruby-version: 3.0.x
21
+
22
+ - name: Publish to RubyGems
23
+ run: |
24
+ mkdir -p $HOME/.gem
25
+ touch $HOME/.gem/credentials
26
+ chmod 0600 $HOME/.gem/credentials
27
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
28
+ gem build *.gemspec
29
+ gem push *.gem
30
+ env:
31
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+ *.gem
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Style/Documentation:
13
+ Enabled: false
14
+
15
+ Layout/LineLength:
16
+ Max: 120
17
+
18
+ Metrics/ParameterLists:
19
+ Max: 10
20
+
21
+ Metrics/MethodLength:
22
+ Max: 15
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ lib-tl1
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-3.0.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-08-02
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at p.wojcieszonek@bosmanger.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in lib-tl1.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.10"
11
+
12
+ gem "rubocop", "~> 1.7"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Piotr Wojcieszonek
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,43 @@
1
+ # Lib::Tl1
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/lib/tl1`. 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
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'lib-tl1'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install lib-tl1
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/lib-tl1. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/lib-tl1/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Lib::Tl1 project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/lib-tl1/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "lib/tl1"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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
data/lib-tl1.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/lib/tl1/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "lib-tl1"
7
+ spec.version = Lib::Tl1::VERSION
8
+ spec.authors = ["Piotr Wojcieszonek"]
9
+ spec.email = ["piotr@wojcieszonek.pl"]
10
+
11
+ spec.summary = "Set of classes to low level handle the TL1 protocol"
12
+ spec.homepage = "https://github.com/pwojcieszonek/#{spec.name}"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.4.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
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(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ # Uncomment to register a new dependency of your gem
29
+ # spec.add_dependency "example-gem", "~> 1.0"
30
+
31
+ # For more information and examples about making a new gem, checkout our
32
+ # guide at: https://bundler.io/guides/creating_gem.html
33
+ end
data/lib/lib/tl1.rb ADDED
@@ -0,0 +1,8 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "tl1/version"
7
+ require_relative "tl1/message"
8
+
@@ -0,0 +1,39 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "message/acknowledgment"
7
+ require_relative "message/autonomous"
8
+ require_relative "message/input"
9
+ require_relative "message/output"
10
+
11
+ module Lib
12
+ module TL1
13
+ module Message
14
+ def parse(message)
15
+ case message
16
+ when /\r\n\n (.{0,20}) (\d{2,4}-\d{1,2}-\d{1,2}) (\d{1,2}:\d{1,2}:\d{1,2})\r\nM (\d{1,6}) (\w{4,6})(.*)\r\n;/mi #Output message
17
+ # $1 - SID, $2 - DATE, $3 - TIME, $4 - CTAG, $5 - COMPLETION CODE, $6 - MESSAGE TEXT BLOCK
18
+ Lib::TL1::Message::Output.new(sid: $1, date: $2, time: $3, ctag: $4, cc: $5, text_block: $6)
19
+
20
+ when /(.*):(.{0,20}):(.*):(\d{1,6}):(.*):(.*);/mi # Input message
21
+ # $1 - COMMAND VERB, $2 - TID, $3 - AID, $4 - CTAG, $5 - General Block, $6 - Message Payload
22
+ Lib::TL1::Message::Input.new(command: $1, tid: $2, aid: $3, ctag: $4, gb: $5, payload: $6)
23
+
24
+ when /(IP|PF|OK|NA|NG|RL):(\d{1,6});/mi # Acknowledgment message
25
+ # $1 - Status Code, $2 - CTAG
26
+ Lib::TL1::Message::Acknowledgment.new(ack_code: $1, ctag: $2)
27
+
28
+ when /\r\n\n (.{1,20}) (\d{2,4}-\d{1,2}-\d{1,2}) (\d{1,2}:\d{1,2}:\d{1,2})\r\n(\*C|\*\*|\*\^|A\^) (.*)(\r\n .*)\r\n;/mi # Autonomous message
29
+ # $1 - SID, $2 - DATE, $3 - TIME, $4 - Alarm Code, $5 ATAG, $6 - Verb, $7 - Message code
30
+ Lib::TL1::Message::Autonomous.new(sid: $1, date: $2, time: $3, alarm_code: $4, ctag: $5, command: $6, text_block: $7)
31
+
32
+ else
33
+ raise ArgumentError, "Can't parse Message. Unknown TL1 message type"
34
+ end
35
+ end
36
+ alias new parse
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,50 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "field"
7
+ require "comparable"
8
+ module Lib
9
+ module TL1
10
+ module Message
11
+ class Acknowledgment
12
+ include Comparable
13
+ attr_reader :ack_code, :ctag
14
+
15
+ def initialize(ack_code: nil, ctag: nil)
16
+ if block_given?
17
+ yield self
18
+ else
19
+ self.ack_code = ack_code
20
+ self.ctag = ctag
21
+ end
22
+ end
23
+
24
+ def <=>(other)
25
+ return nil unless instance_of? other.class
26
+
27
+ to_s <=> other.to_s
28
+ end
29
+
30
+ def to_s
31
+ "#{@ack_code} #{@ctag}\r\n"
32
+ end
33
+ alias to_str to_s
34
+
35
+ def ack_code=(ack_code)
36
+ @ack_code = ack_code.is_a?(Field::AcknowledgmentCode) ? ack_code : Field::AcknowledgmentCode.new(ack_code)
37
+ end
38
+ alias acknowledgment_code ack_code
39
+ alias acknowledgment_code= ack_code=
40
+
41
+ def ctag=(ctag)
42
+ @ctag = ctag.is_a?(Field::CorrelationTag) ? ctag : Field::CorrelationTag.new(ctag)
43
+ end
44
+ alias correlation_tag ctag
45
+ alias correlation_tag= ctag=
46
+
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,78 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "field"
7
+ require "comparable"
8
+
9
+ module Lib
10
+ module TL1
11
+ module Message
12
+ class Autonomous
13
+ include Comparable
14
+ attr_reader :sid, :date, :time, :alarm_code, :ctag, :command
15
+
16
+ def initialize(sid: nil, date: nil, time: nil, alarm_code: nil, ctag: nil, command: nil, text_block: nil)
17
+ if block_given?
18
+ yield self
19
+ else
20
+ self.sid = sid
21
+ self.date = date
22
+ self.time = time
23
+ self.alarm_code = alarm_code
24
+ self.ctag = ctag
25
+ self.command = command
26
+ self.text_block = text_block
27
+ end
28
+ end
29
+
30
+ def <=>(other)
31
+ return nil unless instance_of? other.class
32
+
33
+ to_s <=> other.to_s
34
+ end
35
+
36
+ def to_s
37
+ "\r\n\n #{sid} #{date} #{time}\r\n #{alarm_code} #{ctag}\r\n #{text_block}\r\n;"
38
+ end
39
+ alias to_str to_s
40
+
41
+ def sid=(sid)
42
+ @sid = sid.is_a?(Field::SystemIdentifier) ? sid : Field::SystemIdentifier.new(sid)
43
+ end
44
+ alias system_identifier sid
45
+ alias system_identifier= sid=
46
+
47
+ def date=(date)
48
+ @date = date.is_a?(Field::Date) ? date : Field::Date.new(date)
49
+ end
50
+
51
+ def time=(time)
52
+ @time = time.is_a?(Field::Time) ? time : Field::Time.new(time)
53
+ end
54
+
55
+ def alarm_code=(alarm_code)
56
+ @alarm_code = alarm_code.is_a?(Field::AlarmCode) ? alarm_code : Field::AlarmCode.new(alarm_code)
57
+ end
58
+
59
+ def ctag=(ctag)
60
+ @atag = ctag.is_a?(Field::CorrelationTag) ? ctag : Field::CorrelationTag.new(ctag)
61
+ end
62
+ alias correlation_tag ctag
63
+ alias correlation_tag= ctag=
64
+ alias atag ctag
65
+ alias atag= ctag=
66
+
67
+ def command=(command)
68
+ @verb = command.is_a?(Field::CommandVerb) ? command : Field::CommandVerb.new(command)
69
+ end
70
+
71
+ def text_block=(text_block)
72
+ @text_block = text_block.is_a?(Field::TextBlock) ? text_block : Field::TextBlock.new(text_block)
73
+ end
74
+
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,18 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "field/access_identifier"
7
+ require_relative "field/acknowledgment_code"
8
+ require_relative "field/alarm_code"
9
+ require_relative "field/command_verb"
10
+ require_relative "field/completion_code"
11
+ require_relative "field/correlation_tag"
12
+ require_relative "field/date"
13
+ require_relative "field/general_block"
14
+ require_relative "field/payload"
15
+ require_relative "field/system_identifier"
16
+ require_relative "field/target_identifier"
17
+ require_relative "field/text_block"
18
+ require_relative "field/time"
@@ -0,0 +1,17 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "base"
7
+
8
+ module Lib
9
+ module TL1
10
+ module Message
11
+ module Field
12
+ class AccessIdentifier < Base
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,45 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "base"
7
+
8
+ module Lib
9
+ module TL1
10
+ module Message
11
+ module Field
12
+ class AcknowledgmentCode < Base
13
+ ACK_CODE = {
14
+ ip: "In Progress",
15
+ fp: "Printout Follows",
16
+ ok: "All Right",
17
+ na: "No Acknowledgment",
18
+ ng: "No Good",
19
+ rl: "Repeat Later"
20
+ }.freeze
21
+
22
+ def initialize(field)
23
+ unless ACK_CODE.key? field.to_s.downcase.to_sym
24
+ raise ArgumentError, "Unknown Acknowledgment Code - #{field}"
25
+ end
26
+
27
+ super field.to_s.downcase.to_sym
28
+ end
29
+
30
+ def to_s
31
+ @field.to_s.upcase
32
+ end
33
+
34
+ def to_sym
35
+ @field
36
+ end
37
+
38
+ def description
39
+ ACK_CODE[@field]
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,42 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "base"
7
+
8
+ module Lib
9
+ module TL1
10
+ module Message
11
+ module Field
12
+ class AlarmCode < Base
13
+ ALARM_CODE = {
14
+ '*C': "Critical Alarm",
15
+ '**': "Major Alarm",
16
+ '*^': "Minor Alarm",
17
+ 'A^': "Non-Alarm Message"
18
+ }.freeze
19
+
20
+ def initialize(field)
21
+ raise ArgumentError, "Unknown Alarm Code - #{field}" unless ALARM_CODE.key? field.to_s.upcase.to_sym
22
+
23
+ super field.to_s.upcase.to_sym
24
+ end
25
+
26
+ def to_s
27
+ @field.to_s.upcase
28
+ end
29
+
30
+ def description
31
+ ALARM_CODE[@field]
32
+ end
33
+
34
+ def to_sym
35
+ @field
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,35 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require "forwardable"
7
+
8
+ module Lib
9
+ module TL1
10
+ module Message
11
+ module Field
12
+ class Base
13
+
14
+ include Comparable
15
+ extend Forwardable
16
+
17
+ def_delegators :@field, :to_s, :nil?, :empty?
18
+ attr_reader :field
19
+
20
+ def initialize(field)
21
+ @field = field
22
+ end
23
+
24
+ def <=>(other)
25
+ return nil unless instance_of? other.class
26
+
27
+ field <=> other.field
28
+ end
29
+
30
+ alias to_str to_s
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,24 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "base"
7
+
8
+ module Lib
9
+ module TL1
10
+ module Message
11
+ module Field
12
+ class CommandVerb < Base
13
+
14
+ def initialize(field)
15
+ raise ArgumentError, "Command can't be nil" if field.nil?
16
+
17
+ super field.to_s.upcase
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,67 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "base"
7
+
8
+ module Lib
9
+ module TL1
10
+ module Message
11
+ module Field
12
+ class CompletionCode < Base
13
+ COMPLETION_CODE = {
14
+ compld: "Total successful execution of the input command.",
15
+ deny: "Total denial of the input command.",
16
+ prtl: 'Partial successful execution of the input command. This response code is valid when
17
+ the ctag in the general block is FALSE represents successful queuing of the input command
18
+ submitted for delayed activation..',
19
+ delay: "Successful queuing of the input command submitted for delayed activation.",
20
+ rtry: 'Output response of a input retrieve command that retrieves extensive amount of information
21
+ from the NE and uses more time for processing'
22
+ }.freeze
23
+
24
+ def initialize(field)
25
+ unless COMPLETION_CODE.key? field.to_s.downcase.to_sym
26
+ raise ArgumentError, "Unknown Completion Code - #{field}"
27
+ end
28
+
29
+ super field.to_s.downcase.to_sym
30
+ end
31
+
32
+ def to_s
33
+ @field.to_s.upcase
34
+ end
35
+
36
+ def to_sym
37
+ @field
38
+ end
39
+
40
+ def description
41
+ COMPLETION_CODE[@field]
42
+ end
43
+
44
+ def compld?
45
+ @field == :compld
46
+ end
47
+
48
+ def deny?
49
+ @field == :deny
50
+ end
51
+
52
+ def prtl?
53
+ @field == :prtl
54
+ end
55
+
56
+ def delay?
57
+ @field == :delay
58
+ end
59
+
60
+ def rtry?
61
+ @field == :rtry
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,31 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "base"
7
+
8
+ module Lib
9
+ module TL1
10
+ module Message
11
+ module Field
12
+ class CorrelationTag < Base
13
+
14
+ def initialize(field = nil)
15
+ field = rand(0..999_999) if field.nil?
16
+ unless (field.to_i < 999_999) && (field.to_i >= 0)
17
+ raise ArgumentError, "Wrong #{self.class.name} format - #{field}"
18
+ end
19
+
20
+ super field.to_i
21
+ end
22
+
23
+ def to_i
24
+ @field.to_i
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "base"
7
+ require "date"
8
+
9
+ module Lib
10
+ module TL1
11
+ module Message
12
+ module Field
13
+ class Date < Base
14
+
15
+ def_delegators :@field, :year, :mon, :day, :month
16
+
17
+ def initialize(field = nil)
18
+ super(field.nil? ? nil : ::Date.parse(field))
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "base"
7
+
8
+ module Lib
9
+ module TL1
10
+ module Message
11
+ module Field
12
+ class GeneralBlock < Base
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "base"
7
+
8
+ module Lib
9
+ module TL1
10
+ module Message
11
+ module Field
12
+ class Payload < Base
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "base"
7
+
8
+ module Lib
9
+ module TL1
10
+ module Message
11
+ module Field
12
+ class SystemIdentifier < Base
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "base"
7
+
8
+ module Lib
9
+ module TL1
10
+ module Message
11
+ module Field
12
+ class TargetIdentifier < Base
13
+ def initialize(field)
14
+ unless field =~ (/^[a-zA-Z0-9-]{0,20}$/) || field.nil?
15
+ raise ArgumentError, "Wrong Target Identifier format - #{field}"
16
+ end
17
+
18
+ super
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,38 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "base"
7
+
8
+ module Lib
9
+ module TL1
10
+ module Message
11
+ module Field
12
+ class TextBlock < Base
13
+ def initialize(field)
14
+ @commented = false
15
+ case field
16
+ when /"\r\n (.*)"/mi
17
+ field = Regexp.last_match(1)
18
+ when %r{/\*\r\n (.*)\*/}mi
19
+ @commented = true
20
+ field = Regexp.last_match(1)
21
+ when /\r\n (.*)/mi
22
+ field = Regexp.last_match(1)
23
+ when (nil || "")
24
+ field = nil
25
+ else
26
+ raise ArgumentError, "Unknown TextBlock format #{field}"
27
+ end
28
+ super field
29
+ end
30
+
31
+ def commented?
32
+ @commented
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "base"
7
+ require "time"
8
+
9
+ module Lib
10
+ module TL1
11
+ module Message
12
+ module Field
13
+ class Time < Base
14
+ def_delegators :@field, :min, :sec, :hour, :strftime
15
+
16
+ def initialize(field)
17
+ super ::Time.parse(field)
18
+ end
19
+
20
+ def to_s
21
+ @field.strftime("%H:%M:%S")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,79 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "field"
7
+ require "comparable"
8
+
9
+ module Lib
10
+ module TL1
11
+ module Message
12
+ class Input
13
+ include Comparable
14
+ attr_reader :command, :tid, :aid, :gb, :payload, :ctag
15
+
16
+ def initialize(command: nil, tid: nil, aid: nil, ctag: nil, gb: nil, payload: nil)
17
+ if block_given?
18
+ yield self
19
+ else
20
+ self.command = command
21
+ self.tid = tid
22
+ self.aid = aid
23
+ self.ctag = ctag
24
+ self.gb = gb
25
+ self.payload = payload
26
+ end
27
+ end
28
+
29
+ def <=>(other)
30
+ return nil unless instance_of? other.class
31
+
32
+ to_s <=> other.to_s
33
+ end
34
+
35
+ def to_s
36
+ "#{command}:#{tid}:#{aid}:#{ctag}:#{gb}:#{payload};"
37
+ end
38
+ alias to_str to_s
39
+
40
+ def command=(command)
41
+ @command = command.is_a?(Field::CommandVerb) ? command : Field::CommandVerb.new(command)
42
+ end
43
+ alias command_verb command
44
+ alias command_verb= command=
45
+ alias verb command
46
+ alias verb= command=
47
+
48
+ def tid=(tid)
49
+ @tid = tid.is_a?(Field::TargetIdentifier) ? tid : Field::TargetIdentifier.new(tid)
50
+ end
51
+ alias target_identifier tid
52
+ alias target_identifier= tid=
53
+
54
+ def aid=(aid)
55
+ @aid = aid.is_a?(Field::AccessIdentifier) ? aid : Field::AccessIdentifier.new(aid)
56
+ end
57
+ alias access_identifier aid
58
+ alias access_identifier= aid=
59
+
60
+ def ctag=(ctag)
61
+ @ctag = ctag.is_a?(Field::CorrelationTag) ? ctag : Field::CorrelationTag.new(ctag)
62
+ end
63
+ alias correlation_tag ctag
64
+ alias correlation_tag= ctag=
65
+
66
+ def gb=(gb)
67
+ @gb = gb.is_a?(Field::GeneralBlock) ? gb : Field::GeneralBlock.new(gb)
68
+ end
69
+ alias general_block gb
70
+ alias general_block= gb=
71
+
72
+ def payload=(payload)
73
+ @payload = payload.is_a?(Field::Payload) ? payload : Field::Payload.new(payload)
74
+ end
75
+
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,73 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ require_relative "field"
7
+ require "comparable"
8
+
9
+ module Lib
10
+ module TL1
11
+ module Message
12
+ class Output
13
+ include Comparable
14
+ attr_reader :sid, :date, :time, :cc, :text_block, :ctag
15
+
16
+ def initialize(sid: nil, date: nil, time: nil, ctag: nil, cc: nil, text_block: nil)
17
+ if block_given?
18
+ yield self
19
+ else
20
+ self.sid = sid
21
+ self.date = date
22
+ self.time = time
23
+ self.ctag = ctag
24
+ self.cc = cc
25
+ self.text_block = text_block
26
+ end
27
+ end
28
+
29
+ def <=>(other)
30
+ return nil unless instance_of? other.class
31
+
32
+ to_s <=> other.to_s
33
+ end
34
+
35
+ def to_s
36
+ "\r\n\n #{sid} #{date} #{time}\r\nM #{ctag} #{cc}\r\n #{text_block}\r\n;"
37
+ end
38
+ alias to_str to_s
39
+
40
+ def sid=(sid)
41
+ @sid = sid.is_a?(Field::SystemIdentifier) ? sid : Field::SystemIdentifier.new(sid)
42
+ end
43
+ alias system_identifier sid
44
+ alias system_identifier= sid=
45
+
46
+ def date=(date)
47
+ @date = date.is_a?(Field::Date) ? date : Field::Date.new(date)
48
+ end
49
+
50
+ def time=(time)
51
+ @time = time.is_a?(Field::Time) ? time : Field::Time.new(time)
52
+ end
53
+
54
+ def cc=(cc)
55
+ @cc = cc.is_a?(Field::CompletionCode) ? cc : Field::CompletionCode.new(cc)
56
+ end
57
+ alias completion_code cc
58
+ alias completion_code= cc=
59
+
60
+ def text_block=(text_block)
61
+ @text_block = text_block.is_a?(Field::TextBlock) ? text_block : Field::TextBlock.new(text_block)
62
+ end
63
+
64
+ def ctag=(ctag)
65
+ @ctag = ctag.is_a?(Field::CorrelationTag) ? ctag : Field::CorrelationTag.new(ctag)
66
+ end
67
+ alias correlation_tag ctag
68
+ alias correlation_tag= ctag=
69
+
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,10 @@
1
+ # Author: Piotr Wojcieszonek
2
+ # e-mail: piotr@wojcieszonek.pl
3
+ # Copyright 03.08.2021 Piotr Wojcieszonek
4
+ # frozen_string_literal: true
5
+
6
+ module Lib
7
+ module Tl1
8
+ VERSION = "0.1.0"
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lib-tl1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Piotr Wojcieszonek
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-08-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - piotr@wojcieszonek.pl
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".github/workflows/gem-push.yml"
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".rubocop.yml"
24
+ - ".ruby-gemset"
25
+ - ".ruby-version"
26
+ - CHANGELOG.md
27
+ - CODE_OF_CONDUCT.md
28
+ - Gemfile
29
+ - LICENSE.txt
30
+ - README.md
31
+ - Rakefile
32
+ - bin/console
33
+ - bin/setup
34
+ - lib-tl1.gemspec
35
+ - lib/lib/tl1.rb
36
+ - lib/lib/tl1/message.rb
37
+ - lib/lib/tl1/message/acknowledgment.rb
38
+ - lib/lib/tl1/message/autonomous.rb
39
+ - lib/lib/tl1/message/field.rb
40
+ - lib/lib/tl1/message/field/access_identifier.rb
41
+ - lib/lib/tl1/message/field/acknowledgment_code.rb
42
+ - lib/lib/tl1/message/field/alarm_code.rb
43
+ - lib/lib/tl1/message/field/base.rb
44
+ - lib/lib/tl1/message/field/command_verb.rb
45
+ - lib/lib/tl1/message/field/completion_code.rb
46
+ - lib/lib/tl1/message/field/correlation_tag.rb
47
+ - lib/lib/tl1/message/field/date.rb
48
+ - lib/lib/tl1/message/field/general_block.rb
49
+ - lib/lib/tl1/message/field/payload.rb
50
+ - lib/lib/tl1/message/field/system_identifier.rb
51
+ - lib/lib/tl1/message/field/target_identifier.rb
52
+ - lib/lib/tl1/message/field/text_block.rb
53
+ - lib/lib/tl1/message/field/time.rb
54
+ - lib/lib/tl1/message/input.rb
55
+ - lib/lib/tl1/message/output.rb
56
+ - lib/lib/tl1/version.rb
57
+ homepage: https://github.com/pwojcieszonek/lib-tl1
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ homepage_uri: https://github.com/pwojcieszonek/lib-tl1
62
+ source_code_uri: https://github.com/pwojcieszonek/lib-tl1
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 2.4.0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.2.22
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Set of classes to low level handle the TL1 protocol
82
+ test_files: []