procon_bypass_man 0.3.6 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +4 -0
  3. data/.github/workflows/gitleacks.yml +1 -1
  4. data/.github/workflows/release.yml +1 -1
  5. data/.github/workflows/ruby.yml +2 -2
  6. data/CHANGELOG.md +10 -0
  7. data/Gemfile +1 -0
  8. data/Gemfile.lock +4 -2
  9. data/README.md +2 -2
  10. data/bin/validate_external_input +19 -0
  11. data/docs/getting_started.md +28 -0
  12. data/docs/setting/integration_external_input_serial_port.md +56 -0
  13. data/docs/setting/integration_external_input_serial_port_format.md +36 -0
  14. data/lib/procon_bypass_man/background/jobs/report_procon_performance_measurements_job.rb +1 -0
  15. data/lib/procon_bypass_man/bypass/procon_to_switch.rb +16 -1
  16. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +4 -1
  17. data/lib/procon_bypass_man/configuration.rb +31 -14
  18. data/lib/procon_bypass_man/external_input/boot_message.rb +21 -0
  19. data/lib/procon_bypass_man/external_input/channels/base.rb +22 -0
  20. data/lib/procon_bypass_man/external_input/channels/serial_port_channel.rb +56 -0
  21. data/lib/procon_bypass_man/external_input/channels/tcpip_channel.rb +131 -0
  22. data/lib/procon_bypass_man/external_input/channels.rb +12 -0
  23. data/lib/procon_bypass_man/external_input/external_data.rb +79 -0
  24. data/lib/procon_bypass_man/external_input.rb +31 -0
  25. data/lib/procon_bypass_man/processor.rb +3 -2
  26. data/lib/procon_bypass_man/procon/button_collection.rb +5 -0
  27. data/lib/procon_bypass_man/procon/performance_measurement/measurements_summarizer.rb +4 -0
  28. data/lib/procon_bypass_man/procon/performance_measurement.rb +7 -1
  29. data/lib/procon_bypass_man/procon.rb +17 -2
  30. data/lib/procon_bypass_man/procon_display/status.rb +0 -2
  31. data/lib/procon_bypass_man/support/forever.rb +51 -0
  32. data/lib/procon_bypass_man/support/proccess_cheacker.rb +14 -0
  33. data/lib/procon_bypass_man/support/retryable.rb +5 -2
  34. data/lib/procon_bypass_man/support/simple_tcp_server.rb +63 -0
  35. data/lib/procon_bypass_man/support/watchdog.rb +23 -0
  36. data/lib/procon_bypass_man/support/web_connectivity_checker.rb +41 -0
  37. data/lib/procon_bypass_man/version.rb +1 -1
  38. data/lib/procon_bypass_man/websocket/client.rb +11 -9
  39. data/lib/procon_bypass_man.rb +16 -3
  40. data/project_template/app.rb +11 -1
  41. data/project_template/app.rb.erb +11 -1
  42. data/sig/main.rbs +2 -2
  43. metadata +17 -4
  44. data/lib/procon_bypass_man/websocket/forever.rb +0 -47
  45. data/lib/procon_bypass_man/websocket/watchdog.rb +0 -19
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'singleton'
3
4
  require "logger"
4
5
  require 'yaml'
5
6
  require "json"
@@ -40,6 +41,11 @@ require_relative "procon_bypass_man/support/cycle_sleep"
40
41
  require_relative "procon_bypass_man/support/can_over_process"
41
42
  require_relative "procon_bypass_man/support/retryable"
42
43
  require_relative "procon_bypass_man/support/renice_command"
44
+ require_relative "procon_bypass_man/support/web_connectivity_checker"
45
+ require_relative "procon_bypass_man/support/watchdog"
46
+ require_relative "procon_bypass_man/support/forever"
47
+ require_relative "procon_bypass_man/support/simple_tcp_server"
48
+ require_relative "procon_bypass_man/support/proccess_cheacker"
43
49
  require_relative "procon_bypass_man/procon_display"
44
50
  require_relative "procon_bypass_man/background"
45
51
  require_relative "procon_bypass_man/commands"
@@ -59,9 +65,7 @@ require_relative "procon_bypass_man/scheduler"
59
65
  require_relative "procon_bypass_man/plugins"
60
66
  require_relative "procon_bypass_man/worker"
61
67
  require_relative "procon_bypass_man/websocket/client"
62
- require_relative "procon_bypass_man/websocket/watchdog"
63
- require_relative "procon_bypass_man/websocket/forever"
64
-
68
+ require_relative "procon_bypass_man/external_input"
65
69
  require_relative "procon_bypass_man/remote_action"
66
70
 
67
71
  STDOUT.sync = true
@@ -130,6 +134,8 @@ module ProconBypassMan
130
134
  # 実行ファイル(app.rb)から呼び出している
131
135
  # @return [void]
132
136
  def self.configure(&block)
137
+ require_relative "procon_bypass_man/external_input"
138
+
133
139
  @@configuration = ProconBypassMan::Configuration.new
134
140
  @@configuration.instance_eval(&block)
135
141
  nil
@@ -155,6 +161,12 @@ module ProconBypassMan
155
161
 
156
162
  # @return [void]
157
163
  def self.initialize_pbm
164
+ if ProconBypassMan.pid && ProconBypassMan::ProcessChecker.running?(ProconBypassMan.pid)
165
+ ProconBypassMan::SendErrorCommand.execute(error: "別のプロセスでPBMがすでに起動中なので処理を停止します。")
166
+ raise 'テスト実行中でここに入ると調査が面倒なのでエラーにします' if ENV['PBM_ENV'] == 'test'
167
+ exit 1
168
+ end
169
+
158
170
  ProconBypassMan::ReniceCommand.change_priority(to: :low, pid: $$)
159
171
  ProconBypassMan::Background::JobQueue.start!
160
172
  ProconBypassMan::Websocket::Client.start!
@@ -205,6 +217,7 @@ module ProconBypassMan
205
217
  ProconBypassMan::RemoteAction::QueueOverProcess.shutdown
206
218
  ProconBypassMan::Procon::PerformanceMeasurement::QueueOverProcess.shutdown
207
219
  self.worker&.shutdown
220
+ ProconBypassMan::ExternalInput.shutdown
208
221
  end
209
222
 
210
223
  # @return [void]
@@ -12,7 +12,11 @@ begin
12
12
  gemfile do
13
13
  source 'https://rubygems.org'
14
14
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
15
- gem 'procon_bypass_man', '0.3.6'
15
+ gem 'procon_bypass_man', '0.3.8'
16
+ # uncomment if you want to use master branch
17
+ # gem 'procon_bypass_man', github: 'splaplapla/procon_bypass_man', branch: 'master'
18
+ # uncomment if you want to use serial communication feature
19
+ # gem "serialport"
16
20
  end
17
21
  rescue Bundler::Source::Git::GitCommandError => e
18
22
  retry_count_on_git_command_error = retry_count_on_git_command_error + 1
@@ -49,6 +53,12 @@ ProconBypassMan.configure do |config|
49
53
 
50
54
  # 接続に成功したらコントローラーのHOME LEDを光らせるか
51
55
  config.enable_home_led_on_connect = true
56
+
57
+ # シリアル通信やTCP/IP経由で入力するときに設定してください
58
+ # config.external_input_channels = [
59
+ # ProconBypassMan::ExternalInput::Channels::SerialPortChannel.new(device_path: '/dev/serial0', baud_rate: 9600),
60
+ # ProconBypassMan::ExternalInput::Channels::TCPIPChannel.new(port: 9000),
61
+ # ]
52
62
  end
53
63
 
54
64
  ProconBypassMan.run(setting_path: "/usr/share/pbm/current/setting.yml")
@@ -12,7 +12,11 @@ begin
12
12
  gemfile do
13
13
  source 'https://rubygems.org'
14
14
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
15
- gem 'procon_bypass_man', '0.3.6'
15
+ gem 'procon_bypass_man', '0.3.8'
16
+ # uncomment if you want to use master branch
17
+ # gem 'procon_bypass_man', github: 'splaplapla/procon_bypass_man', branch: 'master'
18
+ # uncomment if you want to use serial communication feature
19
+ # gem "serialport"
16
20
  end
17
21
  rescue Bundler::Source::Git::GitCommandError => e
18
22
  retry_count_on_git_command_error = retry_count_on_git_command_error + 1
@@ -54,6 +58,12 @@ ProconBypassMan.configure do |config|
54
58
 
55
59
  # 接続に成功したらコントローラーのHOME LEDを光らせるか
56
60
  config.enable_home_led_on_connect = true
61
+
62
+ # シリアル通信やTCP/IP経由で入力するときに設定してください
63
+ # config.external_input_channels = [
64
+ # ProconBypassMan::ExternalInput::Channels::SerialPortChannel.new(device_path: '/dev/serial0', baud_rate: 9600),
65
+ # ProconBypassMan::ExternalInput::Channels::TCPIPChannel.new(port: 9000),
66
+ # ]
57
67
  end
58
68
 
59
69
  ProconBypassMan.run(setting_path: "/usr/share/pbm/current/setting.yml")
data/sig/main.rbs CHANGED
@@ -210,7 +210,7 @@ class ProconBypassMan::Configuration
210
210
 
211
211
  def current_ws_server: () -> (String | nil)
212
212
 
213
- def current_ws_server_url: () -> ::String
213
+ def current_ws_server_url: () -> (String | nil)
214
214
 
215
215
  def enable_ws?: () -> bool
216
216
 
@@ -577,7 +577,7 @@ module ProconBypassMan
577
577
  @retry_on_connection_error: false
578
578
 
579
579
  def initialize: (path: String, server: untyped, ?retry_on_connection_error: false) -> void
580
- def get: -> nil
580
+ def get: -> Hash[untyped, untyped]?
581
581
  def post: (request_body: untyped) -> nil
582
582
  def put: (request_body: untyped) -> nil
583
583
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: procon_bypass_man
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - jiikko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-12 00:00:00.000000000 Z
11
+ date: 2023-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pbmenv
@@ -95,9 +95,12 @@ files:
95
95
  - bin/generate_default_app
96
96
  - bin/generate_output_report
97
97
  - bin/setup
98
+ - bin/validate_external_input
98
99
  - docs/getting_started.md
99
100
  - docs/how_to_connect_procon.md
100
101
  - docs/run_pbm_on_my_branch.md
102
+ - docs/setting/integration_external_input_serial_port.md
103
+ - docs/setting/integration_external_input_serial_port_format.md
101
104
  - docs/setting/left-analogstick-cap.md
102
105
  - docs/setting/splatoon2_macro_dasei_cancel.md
103
106
  - docs/setting/splatoon2_macro_forward_ikarole.md
@@ -176,6 +179,13 @@ files:
176
179
  - lib/procon_bypass_man/device_model.rb
177
180
  - lib/procon_bypass_man/device_status.rb
178
181
  - lib/procon_bypass_man/ephemeral_configuration.rb
182
+ - lib/procon_bypass_man/external_input.rb
183
+ - lib/procon_bypass_man/external_input/boot_message.rb
184
+ - lib/procon_bypass_man/external_input/channels.rb
185
+ - lib/procon_bypass_man/external_input/channels/base.rb
186
+ - lib/procon_bypass_man/external_input/channels/serial_port_channel.rb
187
+ - lib/procon_bypass_man/external_input/channels/tcpip_channel.rb
188
+ - lib/procon_bypass_man/external_input/external_data.rb
179
189
  - lib/procon_bypass_man/plugin/splatoon2/macro/charge_tansan_bomb.rb
180
190
  - lib/procon_bypass_man/plugin/splatoon2/macro/dasei_cancel.rb
181
191
  - lib/procon_bypass_man/plugin/splatoon2/macro/fast_return.rb
@@ -267,10 +277,12 @@ files:
267
277
  - lib/procon_bypass_man/support/cycle_sleep.rb
268
278
  - lib/procon_bypass_man/support/device_mouse_finder.rb
269
279
  - lib/procon_bypass_man/support/device_procon_finder.rb
280
+ - lib/procon_bypass_man/support/forever.rb
270
281
  - lib/procon_bypass_man/support/http_client.rb
271
282
  - lib/procon_bypass_man/support/load_agv.rb
272
283
  - lib/procon_bypass_man/support/never_exit_accidentally.rb
273
284
  - lib/procon_bypass_man/support/on_memory_cache.rb
285
+ - lib/procon_bypass_man/support/proccess_cheacker.rb
274
286
  - lib/procon_bypass_man/support/procon_performance_http_client.rb
275
287
  - lib/procon_bypass_man/support/remote_macro_http_client.rb
276
288
  - lib/procon_bypass_man/support/renice_command.rb
@@ -278,15 +290,16 @@ files:
278
290
  - lib/procon_bypass_man/support/retryable.rb
279
291
  - lib/procon_bypass_man/support/safe_timeout.rb
280
292
  - lib/procon_bypass_man/support/send_device_stats_http_client.rb
293
+ - lib/procon_bypass_man/support/simple_tcp_server.rb
281
294
  - lib/procon_bypass_man/support/update_remote_pbm_job_status_http_client.rb
282
295
  - lib/procon_bypass_man/support/uptime.rb
283
296
  - lib/procon_bypass_man/support/usb_device_controller.rb
297
+ - lib/procon_bypass_man/support/watchdog.rb
298
+ - lib/procon_bypass_man/support/web_connectivity_checker.rb
284
299
  - lib/procon_bypass_man/support/yaml_loader.rb
285
300
  - lib/procon_bypass_man/support/yaml_writer.rb
286
301
  - lib/procon_bypass_man/version.rb
287
302
  - lib/procon_bypass_man/websocket/client.rb
288
- - lib/procon_bypass_man/websocket/forever.rb
289
- - lib/procon_bypass_man/websocket/watchdog.rb
290
303
  - lib/procon_bypass_man/worker.rb
291
304
  - procon_bypass_man.gemspec
292
305
  - project_template/README.md
@@ -1,47 +0,0 @@
1
- module ProconBypassMan
2
- module Websocket
3
- class Forever
4
- # 動作確認方法
5
- # - 10秒ごとにrefreshするのでタイムアウトは起きない
6
- # - ProconBypassMan::Websocket::Forever.run { loop { puts(:hi); sleep(10); ProconBypassMan::Websocket::Watchdog.active! } }
7
- # - タイムアウトが起きること
8
- # - ProconBypassMan::Websocket::Forever.run { puts(:hi); sleep(3000); }
9
- # - ブロックを1回評価するとThreadが死ぬので100秒後にタイムアウトが起きること
10
- # - ProconBypassMan::Websocket::Forever.run { puts(:hi); sleep(10); ProconBypassMan::Websocket::Watchdog.active! }
11
- def self.run(&block)
12
- loop do
13
- new.run(&block)
14
- end
15
- end
16
-
17
- def run(&block)
18
- raise("need a block") unless block_given?
19
-
20
- ws_thread = work_one(callable: block)
21
- wait_and_kill_if_outdated(ws_thread)
22
- end
23
-
24
- # @return [Thread]
25
- def work_one(callable: )
26
- Thread.start do
27
- callable.call
28
- rescue => e
29
- ProconBypassMan.logger.error("websocket client with forever: #{e.full_message}")
30
- end
31
- end
32
-
33
- def wait_and_kill_if_outdated(thread)
34
- loop do
35
- if Watchdog.outdated?
36
- Watchdog.active!
37
- ProconBypassMan.logger.error("watchdog timeout!!")
38
- thread.kill
39
- return
40
- end
41
-
42
- sleep(10)
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,19 +0,0 @@
1
- module ProconBypassMan
2
- module Websocket
3
- class Watchdog
4
- def self.outdated?
5
- @@time < Time.now
6
- end
7
-
8
- def self.time
9
- @@time
10
- end
11
-
12
- def self.active!
13
- @@time = Time.now + 100
14
- end
15
-
16
- active!
17
- end
18
- end
19
- end