sftui 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/sftui +18 -0
- data/lib/sftui.rb +6 -0
- data/lib/sftui/cli.rb +33 -0
- data/lib/sftui/command.rb +121 -0
- data/lib/sftui/commands/.gitkeep +1 -0
- data/lib/sftui/commands/stream.rb +82 -0
- data/lib/sftui/frame.rb +126 -0
- data/lib/sftui/frame_buffer.rb +23 -0
- data/lib/sftui/publish_scanner_data_worker.rb +15 -0
- data/lib/sftui/templates/.gitkeep +1 -0
- data/lib/sftui/templates/stream/.gitkeep +1 -0
- data/lib/sftui/version.rb +3 -0
- data/sftui.gemspec +40 -0
- metadata +210 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c428698816430671e802ee64efc63a99e8361e22adb823359c8c3c79a57413d6
|
4
|
+
data.tar.gz: 4d832e091feacea34897b35d3df0319d3da574dbe9f019eae731246abd3d4942
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd896e7d48883e01ed6ea7a6c03152b0837937575d62840bdb4fef8a8ff9d7693b6adaeb5c8dfa591ebb827d38b52378e3b16aa5c86ac2e3a24ff2b0468686af
|
7
|
+
data.tar.gz: bf39e833a42cf23a7416e54988a80e8d639b7756cd9f6bcda48b4074df27f02a4a8c0816b6b40ffa8b6f2c12554c16e47c09abcbddb6c49a6763dfd6cc3a4558
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at huy.duong@employmenthero.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Huy Duong
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Sftui
|
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/sftui`. 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 'sftui'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install sftui
|
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 tags, 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/pces-vn/sftui. 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/pces-vn/sftui/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
|
38
|
+
## Code of Conduct
|
39
|
+
|
40
|
+
Everyone interacting in the Sftui project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/pces-vn/sftui/blob/master/CODE_OF_CONDUCT.md).
|
41
|
+
|
42
|
+
## Copyright
|
43
|
+
|
44
|
+
Copyright (c) 2020 Huy Duong. See [MIT License](LICENSE.txt) for further details.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sftui"
|
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__)
|
data/bin/setup
ADDED
data/exe/sftui
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib_path = File.expand_path('../lib', __dir__)
|
5
|
+
$:.unshift(lib_path) if !$:.include?(lib_path)
|
6
|
+
require 'sftui/cli'
|
7
|
+
|
8
|
+
Signal.trap('INT') do
|
9
|
+
warn("\n#{caller.join("\n")}: interrupted")
|
10
|
+
exit(1)
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
Sftui::CLI.start
|
15
|
+
rescue Sftui::CLI::Error => err
|
16
|
+
puts "ERROR: #{err.message}"
|
17
|
+
exit 1
|
18
|
+
end
|
data/lib/sftui.rb
ADDED
data/lib/sftui/cli.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
module Sftui
|
6
|
+
# Handle the application command line parsing
|
7
|
+
# and the dispatch to various command objects
|
8
|
+
#
|
9
|
+
# @api public
|
10
|
+
class CLI < Thor
|
11
|
+
# Error raised by this runner
|
12
|
+
Error = Class.new(StandardError)
|
13
|
+
|
14
|
+
desc 'version', 'sftui version'
|
15
|
+
def version
|
16
|
+
require_relative 'version'
|
17
|
+
puts "v#{Sftui::VERSION}"
|
18
|
+
end
|
19
|
+
map %w(--version -v) => :version
|
20
|
+
|
21
|
+
desc 'stream UART', 'Command description...'
|
22
|
+
method_option :help, aliases: '-h', type: :boolean,
|
23
|
+
desc: 'Display usage information'
|
24
|
+
def stream(uart)
|
25
|
+
if options[:help]
|
26
|
+
invoke :help, ['stream']
|
27
|
+
else
|
28
|
+
require_relative 'commands/stream'
|
29
|
+
Sftui::Commands::Stream.new(uart, options).execute
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module Sftui
|
6
|
+
class Command
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def_delegators :command, :run
|
10
|
+
|
11
|
+
# Execute this command
|
12
|
+
#
|
13
|
+
# @api public
|
14
|
+
def execute(*)
|
15
|
+
raise(
|
16
|
+
NotImplementedError,
|
17
|
+
"#{self.class}##{__method__} must be implemented"
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
# The external commands runner
|
22
|
+
#
|
23
|
+
# @see http://www.rubydoc.info/gems/tty-command
|
24
|
+
#
|
25
|
+
# @api public
|
26
|
+
def command(**options)
|
27
|
+
require 'tty-command'
|
28
|
+
TTY::Command.new(options)
|
29
|
+
end
|
30
|
+
|
31
|
+
# The cursor movement
|
32
|
+
#
|
33
|
+
# @see http://www.rubydoc.info/gems/tty-cursor
|
34
|
+
#
|
35
|
+
# @api public
|
36
|
+
def cursor
|
37
|
+
require 'tty-cursor'
|
38
|
+
TTY::Cursor
|
39
|
+
end
|
40
|
+
|
41
|
+
# Open a file or text in the user's preferred editor
|
42
|
+
#
|
43
|
+
# @see http://www.rubydoc.info/gems/tty-editor
|
44
|
+
#
|
45
|
+
# @api public
|
46
|
+
def editor
|
47
|
+
require 'tty-editor'
|
48
|
+
TTY::Editor
|
49
|
+
end
|
50
|
+
|
51
|
+
# File manipulation utility methods
|
52
|
+
#
|
53
|
+
# @see http://www.rubydoc.info/gems/tty-file
|
54
|
+
#
|
55
|
+
# @api public
|
56
|
+
def generator
|
57
|
+
require 'tty-file'
|
58
|
+
TTY::File
|
59
|
+
end
|
60
|
+
|
61
|
+
# Terminal output paging
|
62
|
+
#
|
63
|
+
# @see http://www.rubydoc.info/gems/tty-pager
|
64
|
+
#
|
65
|
+
# @api public
|
66
|
+
def pager(**options)
|
67
|
+
require 'tty-pager'
|
68
|
+
TTY::Pager.new(options)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Terminal platform and OS properties
|
72
|
+
#
|
73
|
+
# @see http://www.rubydoc.info/gems/tty-pager
|
74
|
+
#
|
75
|
+
# @api public
|
76
|
+
def platform
|
77
|
+
require 'tty-platform'
|
78
|
+
TTY::Platform.new
|
79
|
+
end
|
80
|
+
|
81
|
+
# The interactive prompt
|
82
|
+
#
|
83
|
+
# @see http://www.rubydoc.info/gems/tty-prompt
|
84
|
+
#
|
85
|
+
# @api public
|
86
|
+
def prompt(**options)
|
87
|
+
require 'tty-prompt'
|
88
|
+
TTY::Prompt.new(options)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Get terminal screen properties
|
92
|
+
#
|
93
|
+
# @see http://www.rubydoc.info/gems/tty-screen
|
94
|
+
#
|
95
|
+
# @api public
|
96
|
+
def screen
|
97
|
+
require 'tty-screen'
|
98
|
+
TTY::Screen
|
99
|
+
end
|
100
|
+
|
101
|
+
# The unix which utility
|
102
|
+
#
|
103
|
+
# @see http://www.rubydoc.info/gems/tty-which
|
104
|
+
#
|
105
|
+
# @api public
|
106
|
+
def which(*args)
|
107
|
+
require 'tty-which'
|
108
|
+
TTY::Which.which(*args)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Check if executable exists
|
112
|
+
#
|
113
|
+
# @see http://www.rubydoc.info/gems/tty-which
|
114
|
+
#
|
115
|
+
# @api public
|
116
|
+
def exec_exist?(*args)
|
117
|
+
require 'tty-which'
|
118
|
+
TTY::Which.exist?(*args)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../command'
|
4
|
+
require_relative '../frame'
|
5
|
+
require_relative '../frame_buffer'
|
6
|
+
require_relative '../publish_scanner_data_worker'
|
7
|
+
require 'pastel'
|
8
|
+
require 'serialport'
|
9
|
+
|
10
|
+
module Sftui
|
11
|
+
module Commands
|
12
|
+
class Stream < Sftui::Command
|
13
|
+
def initialize(uart, options)
|
14
|
+
@uart = uart
|
15
|
+
@options = options
|
16
|
+
@serialport = SerialPort.new(uart)
|
17
|
+
@frame_buffer = FrameBuffer.new
|
18
|
+
@byte_buffer = []
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute
|
22
|
+
pastel = Pastel.new
|
23
|
+
puts pastel.red.bold('📡 Streaming')
|
24
|
+
|
25
|
+
trap 'INT' do
|
26
|
+
@serialport.flush
|
27
|
+
puts pastel.red.bold('Stopped!')
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
31
|
+
@serialport.flush
|
32
|
+
|
33
|
+
main
|
34
|
+
end
|
35
|
+
|
36
|
+
def main
|
37
|
+
loop do
|
38
|
+
c = @serialport.read(1).ord
|
39
|
+
|
40
|
+
@byte_buffer << c
|
41
|
+
|
42
|
+
frame = Frame.new(@byte_buffer)
|
43
|
+
|
44
|
+
next unless frame.completed?
|
45
|
+
|
46
|
+
puts frame.display
|
47
|
+
|
48
|
+
handle_frame(frame)
|
49
|
+
|
50
|
+
@byte_buffer = []
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def handle_frame(frame) # rubocop:disable Metrics/MethodLength
|
55
|
+
previous_frame = @frame_buffer.latest_frame
|
56
|
+
|
57
|
+
if frame.machine_id == previous_frame&.machine_id
|
58
|
+
@frame_buffer.pop(previous_frame)
|
59
|
+
@frame_buffer.push(previous_frame + frame)
|
60
|
+
else
|
61
|
+
@frame_buffer.push(frame)
|
62
|
+
end
|
63
|
+
|
64
|
+
latest_frame = @frame_buffer.latest_frame
|
65
|
+
|
66
|
+
return unless latest_frame.last_frame_in_transaction?
|
67
|
+
|
68
|
+
publish_scanner_data(latest_frame)
|
69
|
+
@frame_buffer.pop(latest_frame)
|
70
|
+
end
|
71
|
+
|
72
|
+
def publish_scanner_data(frame)
|
73
|
+
PublishScannerDataWorker.perform_async(
|
74
|
+
{
|
75
|
+
machine_id: frame.machine_id,
|
76
|
+
data: frame.sanitized_data
|
77
|
+
}
|
78
|
+
)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/sftui/frame.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sftui
|
4
|
+
# frozen_string_literal: true
|
5
|
+
|
6
|
+
# Len Address (4 bytes) Data
|
7
|
+
# +----+----+----+----+----+------------------------+----+----+
|
8
|
+
# | | | | | | |0xff|0xff|
|
9
|
+
# +----+----+----+----+----+------------------------+----+----+
|
10
|
+
|
11
|
+
class Frame
|
12
|
+
attr_accessor :bytes
|
13
|
+
|
14
|
+
LENGTH_LENGTH = 1
|
15
|
+
ADDRESS_LENGTH = 4
|
16
|
+
TERMINATE_LENGTH = 2
|
17
|
+
TERMINATE_CHAR = 0xff
|
18
|
+
BITWISE_MASK = 0xff
|
19
|
+
TRANSACTION_ENDING_CHAR = 0x0d
|
20
|
+
|
21
|
+
def initialize(bytes)
|
22
|
+
@bytes = bytes
|
23
|
+
end
|
24
|
+
|
25
|
+
def completed?
|
26
|
+
bytes.length == length && bytes[(-1 - TERMINATE_LENGTH + 1)..-1] == terminate_bytes
|
27
|
+
end
|
28
|
+
|
29
|
+
def machine_id
|
30
|
+
return unless completed?
|
31
|
+
|
32
|
+
to_integer(addr_bytes)
|
33
|
+
end
|
34
|
+
|
35
|
+
def +(other) # rubocop:disable Metrics/AbcSize
|
36
|
+
raise unless other.completed? && other.machine_id == machine_id
|
37
|
+
|
38
|
+
combined_data_bytes = data_bytes + other.data_bytes
|
39
|
+
combined_length = LENGTH_LENGTH + ADDRESS_LENGTH + TERMINATE_LENGTH + combined_data_bytes.length
|
40
|
+
|
41
|
+
Frame.new(
|
42
|
+
to_bytes(combined_length, LENGTH_LENGTH) +
|
43
|
+
addr_bytes +
|
44
|
+
combined_data_bytes +
|
45
|
+
terminate_bytes
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def sanitized_data
|
50
|
+
last_frame_in_transaction? ? data_bytes[0..-2].pack('c*') : data_bytes.pack('c*')
|
51
|
+
end
|
52
|
+
|
53
|
+
def data_bytes
|
54
|
+
return [] unless completed?
|
55
|
+
|
56
|
+
bytes[data_offset..(-1 - TERMINATE_LENGTH)]
|
57
|
+
end
|
58
|
+
|
59
|
+
def last_frame_in_transaction?
|
60
|
+
data_bytes[-1] == TRANSACTION_ENDING_CHAR
|
61
|
+
end
|
62
|
+
|
63
|
+
def length_bytes
|
64
|
+
bytes[0..LENGTH_LENGTH - 1]
|
65
|
+
end
|
66
|
+
|
67
|
+
def addr_bytes
|
68
|
+
bytes[addr_offset..addr_offset + ADDRESS_LENGTH - 1]
|
69
|
+
end
|
70
|
+
|
71
|
+
def terminate_bytes
|
72
|
+
Array.new(TERMINATE_LENGTH, TERMINATE_CHAR)
|
73
|
+
end
|
74
|
+
|
75
|
+
def display # rubocop:disable Metrics/AbcSize
|
76
|
+
table = TTY::Table.new(header: %w[Length Address Data Terminate])
|
77
|
+
table <<
|
78
|
+
[
|
79
|
+
length_bytes.map { |byte| to_hex(byte) }.join(' '),
|
80
|
+
addr_bytes.map { |byte| to_hex(byte) }.join(' '),
|
81
|
+
data_bytes.map { |byte| to_hex(byte) }.join(' '),
|
82
|
+
terminate_bytes.map { |byte| to_hex(byte) }.join(' ')
|
83
|
+
]
|
84
|
+
table.render(:unicode, alignments: %i[center center])
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def length
|
90
|
+
to_integer(length_bytes)
|
91
|
+
end
|
92
|
+
|
93
|
+
def addr_offset
|
94
|
+
LENGTH_LENGTH
|
95
|
+
end
|
96
|
+
|
97
|
+
def data_offset
|
98
|
+
LENGTH_LENGTH + ADDRESS_LENGTH
|
99
|
+
end
|
100
|
+
|
101
|
+
def to_integer(bytes)
|
102
|
+
sum = 0
|
103
|
+
index = 0
|
104
|
+
while index < bytes.length
|
105
|
+
sum += bytes[index] << ((bytes.length - index - 1) * 8)
|
106
|
+
index += 1
|
107
|
+
end
|
108
|
+
sum
|
109
|
+
end
|
110
|
+
|
111
|
+
def to_bytes(integer, length)
|
112
|
+
bytes = Array.new(length)
|
113
|
+
index = 0
|
114
|
+
while index < length
|
115
|
+
bytes[-1 - index] = (integer >> (index * 8)) & BITWISE_MASK
|
116
|
+
index += 1
|
117
|
+
end
|
118
|
+
|
119
|
+
bytes
|
120
|
+
end
|
121
|
+
|
122
|
+
def to_hex(byte)
|
123
|
+
"0x#{byte.to_s(16)}"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tty-table'
|
4
|
+
|
5
|
+
module Sftui
|
6
|
+
class FrameBuffer
|
7
|
+
def initialize
|
8
|
+
@buffer = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def latest_frame
|
12
|
+
@buffer[-1]
|
13
|
+
end
|
14
|
+
|
15
|
+
def push(frame)
|
16
|
+
@buffer << frame
|
17
|
+
end
|
18
|
+
|
19
|
+
def pop(frame)
|
20
|
+
@buffer -= [frame]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
require 'sidekiq'
|
5
|
+
|
6
|
+
module Sftui
|
7
|
+
class PublishScannerDataWorker
|
8
|
+
include Sidekiq::Worker
|
9
|
+
|
10
|
+
def perform(data)
|
11
|
+
response = HTTParty.post("#{ENV['SMART_FACTORY_API_HOST']}/api/v1/scanner_data", body: data)
|
12
|
+
raise StandardError.new, response.message unless response.success?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
data/sftui.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/sftui/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'sftui'
|
7
|
+
spec.license = 'MIT'
|
8
|
+
spec.version = Sftui::VERSION
|
9
|
+
spec.authors = ['Huy Duong']
|
10
|
+
spec.email = ['huy.duong@employmenthero.com']
|
11
|
+
|
12
|
+
spec.summary = 'Terminal app for smart factory.'
|
13
|
+
spec.description = 'Terminal app for smart factory.'
|
14
|
+
spec.homepage = 'https://github.com/pces-vn/smart-factory-tui'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/pces-vn/smart-factory-tui'
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.add_dependency 'httparty', '~> 0.18.1'
|
30
|
+
spec.add_dependency 'pastel', '~> 0.7.4'
|
31
|
+
spec.add_dependency 'rake', '~> 12.0'
|
32
|
+
spec.add_dependency 'rspec', '~> 3.0'
|
33
|
+
spec.add_dependency 'serialport', '~> 1.3.1'
|
34
|
+
spec.add_dependency 'sidekiq', '~> 6.0.6'
|
35
|
+
spec.add_dependency 'tty-spinner', '~> 0.9.3'
|
36
|
+
spec.add_dependency 'tty-table', '~> 0.11.0'
|
37
|
+
|
38
|
+
spec.add_development_dependency 'bundler', '~> 2.1.4'
|
39
|
+
spec.add_development_dependency 'rubocop', '~> 0.86.0'
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sftui
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Huy Duong
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.18.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.18.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pastel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.7.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.7.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: serialport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.3.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.3.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sidekiq
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 6.0.6
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 6.0.6
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: tty-spinner
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.9.3
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.9.3
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: tty-table
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.11.0
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.11.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: bundler
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.1.4
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 2.1.4
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.86.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.86.0
|
153
|
+
description: Terminal app for smart factory.
|
154
|
+
email:
|
155
|
+
- huy.duong@employmenthero.com
|
156
|
+
executables:
|
157
|
+
- sftui
|
158
|
+
extensions: []
|
159
|
+
extra_rdoc_files: []
|
160
|
+
files:
|
161
|
+
- ".gitignore"
|
162
|
+
- ".rspec"
|
163
|
+
- ".rubocop.yml"
|
164
|
+
- ".travis.yml"
|
165
|
+
- CODE_OF_CONDUCT.md
|
166
|
+
- Gemfile
|
167
|
+
- LICENSE.txt
|
168
|
+
- README.md
|
169
|
+
- Rakefile
|
170
|
+
- bin/console
|
171
|
+
- bin/setup
|
172
|
+
- exe/sftui
|
173
|
+
- lib/sftui.rb
|
174
|
+
- lib/sftui/cli.rb
|
175
|
+
- lib/sftui/command.rb
|
176
|
+
- lib/sftui/commands/.gitkeep
|
177
|
+
- lib/sftui/commands/stream.rb
|
178
|
+
- lib/sftui/frame.rb
|
179
|
+
- lib/sftui/frame_buffer.rb
|
180
|
+
- lib/sftui/publish_scanner_data_worker.rb
|
181
|
+
- lib/sftui/templates/.gitkeep
|
182
|
+
- lib/sftui/templates/stream/.gitkeep
|
183
|
+
- lib/sftui/version.rb
|
184
|
+
- sftui.gemspec
|
185
|
+
homepage: https://github.com/pces-vn/smart-factory-tui
|
186
|
+
licenses:
|
187
|
+
- MIT
|
188
|
+
metadata:
|
189
|
+
homepage_uri: https://github.com/pces-vn/smart-factory-tui
|
190
|
+
source_code_uri: https://github.com/pces-vn/smart-factory-tui
|
191
|
+
post_install_message:
|
192
|
+
rdoc_options: []
|
193
|
+
require_paths:
|
194
|
+
- lib
|
195
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
196
|
+
requirements:
|
197
|
+
- - ">="
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
version: 2.3.0
|
200
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
|
+
requirements:
|
202
|
+
- - ">="
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
version: '0'
|
205
|
+
requirements: []
|
206
|
+
rubygems_version: 3.0.3
|
207
|
+
signing_key:
|
208
|
+
specification_version: 4
|
209
|
+
summary: Terminal app for smart factory.
|
210
|
+
test_files: []
|