procon_bypass_man 0.1.23 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +13 -0
  3. data/.github/workflows/gitleacks.yml +12 -0
  4. data/.github/workflows/release.yml +1 -0
  5. data/.github/workflows/ruby.yml +1 -1
  6. data/CHANGELOG.md +20 -0
  7. data/Gemfile +6 -3
  8. data/Gemfile.lock +3 -3
  9. data/README.md +2 -2
  10. data/bin/generate_default_app +10 -0
  11. data/docs/getting_started.md +52 -7
  12. data/docs/setup_raspi.md +0 -1
  13. data/lib/procon_bypass_man/background/jobs/base_job.rb +1 -1
  14. data/lib/procon_bypass_man/background/jobs/concerns/{job_runnable.rb → job_performable.rb} +1 -1
  15. data/lib/procon_bypass_man/background.rb +1 -1
  16. data/lib/procon_bypass_man/buttons_setting_configuration/loader.rb +1 -1
  17. data/lib/procon_bypass_man/{commands → bypass}/bypass_command.rb +11 -19
  18. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +0 -1
  19. data/lib/procon_bypass_man/bypass.rb +9 -14
  20. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +1 -2
  21. data/lib/procon_bypass_man/commands/send_error_command.rb +2 -2
  22. data/lib/procon_bypass_man/commands.rb +0 -3
  23. data/lib/procon_bypass_man/configuration.rb +22 -3
  24. data/lib/procon_bypass_man/device_connection/command.rb +28 -0
  25. data/lib/procon_bypass_man/{device_connector.rb → device_connection/executor.rb} +51 -38
  26. data/lib/procon_bypass_man/device_connection/output_report_generator.rb +42 -0
  27. data/lib/procon_bypass_man/device_connection/output_report_markerable.rb +28 -0
  28. data/lib/procon_bypass_man/device_connection/output_report_sub_command_table.rb +133 -0
  29. data/lib/procon_bypass_man/device_connection/output_report_watcher.rb +41 -0
  30. data/lib/procon_bypass_man/device_connection/pre_bypass.rb +67 -0
  31. data/lib/procon_bypass_man/device_connection/procon_setting_overrider.rb +78 -0
  32. data/lib/procon_bypass_man/device_connection/spoofing_output_report_watcher.rb +39 -0
  33. data/lib/procon_bypass_man/device_connection.rb +16 -0
  34. data/lib/procon_bypass_man/device_model.rb +17 -0
  35. data/lib/procon_bypass_man/io_monitor.rb +20 -1
  36. data/lib/procon_bypass_man/procon/macro_builder.rb +5 -3
  37. data/lib/procon_bypass_man/procon_display/bypass_hook.rb +11 -0
  38. data/lib/procon_bypass_man/procon_display/http_request.rb +31 -0
  39. data/lib/procon_bypass_man/procon_display/http_response.rb +23 -0
  40. data/lib/procon_bypass_man/procon_display/server.rb +33 -0
  41. data/lib/procon_bypass_man/procon_display/server_app.rb +17 -0
  42. data/lib/procon_bypass_man/procon_display/status.rb +20 -0
  43. data/lib/procon_bypass_man/procon_display.rb +11 -0
  44. data/lib/procon_bypass_man/{commands → remote_pbm_action/commands}/run_remote_pbm_action_dispatch_command.rb +0 -0
  45. data/lib/procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb +7 -1
  46. data/lib/procon_bypass_man/remote_pbm_action.rb +1 -0
  47. data/lib/procon_bypass_man/runner.rb +4 -7
  48. data/lib/procon_bypass_man/support/callbacks.rb +68 -34
  49. data/lib/procon_bypass_man/support/never_exit_accidentally.rb +3 -3
  50. data/lib/procon_bypass_man/support/usb_device_controller.rb +2 -2
  51. data/lib/procon_bypass_man/support/yaml_loader.rb +12 -0
  52. data/lib/procon_bypass_man/version.rb +1 -1
  53. data/lib/procon_bypass_man/websocket/client.rb +1 -4
  54. data/lib/procon_bypass_man.rb +66 -41
  55. data/procon_bypass_man.gemspec +1 -1
  56. data/project_template/README.md +0 -5
  57. data/project_template/app.rb +24 -6
  58. data/project_template/app.rb.erb +64 -0
  59. data/project_template/lib/app_generator.rb +31 -0
  60. data/project_template/web.rb +1 -1
  61. data/sig/main.rbs +3 -3
  62. data/tmp/.keep +0 -0
  63. metadata +30 -8
  64. data/lib/procon_bypass_man/commands/connect_device_command.rb +0 -18
@@ -2,24 +2,36 @@
2
2
 
3
3
  require 'bundler/inline'
4
4
 
5
+ retry_count_on_git_command_error = 0
5
6
  begin
7
+ if retry_count_on_git_command_error > 10
8
+ STDOUT.puts "Stopped the procon_bypass_man program because could not download any source codes."
9
+ exit 1
10
+ end
11
+
6
12
  gemfile do
7
13
  source 'https://rubygems.org'
8
14
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
9
- gem 'procon_bypass_man', '0.1.23'
15
+ gem 'procon_bypass_man', '0.2.2'
10
16
  end
11
17
  rescue Bundler::Source::Git::GitCommandError => e
18
+ retry_count_on_git_command_error = retry_count_on_git_command_error + 1
19
+ sleep(5) # サービスの起動順によっては、まだoffline状態なので待機する
20
+
12
21
  # install中に強制終了するとgitの管理ファイルが不正状態になり、次のエラーが起きるので発生したらcache directoryを削除する
13
22
  #"Git error: command `git fetch --force --quiet --tags https://github.com/splaplapla/procon_bypass_man refs/heads/\\*:refs/heads/\\*` in directory /home/pi/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/cache/bundler/git/procon_bypass_man-ae4c9016d76b667658c8ba66f3bbd2eebf2656af has failed.\n\nIf this error persists you could try removing the cache directory '/home/pi/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/cache/bundler/git/procon_bypass_man-ae4c9016d76b667658c8ba66f3bbd2eebf2656af'"
14
- if /try removing the cache directory '([^']+)'/ =~ e.message
23
+ if /try removing the cache directory '([^']+)'/ =~ e.message && $1&.start_with?('/home/pi/.rbenv')
24
+ require 'fileutils'
15
25
  FileUtils.rm_rf($1)
16
- retry
26
+ STDOUT.puts "Deleted #{$1}"
17
27
  end
28
+
29
+ retry
18
30
  end
19
31
 
20
32
  ProconBypassMan.configure do |config|
21
33
  config.root = File.expand_path(__dir__)
22
- config.logger = Logger.new("#{ProconBypassMan.root}/app.log", 5, 1024 * 1024 * 10)
34
+ config.logger = Logger.new("#{ProconBypassMan.root}/app.log", 1, 1024 * 1024 * 1)
23
35
  config.logger.level = :debug
24
36
 
25
37
  # バイパスするログを全部app.logに流すか
@@ -34,8 +46,14 @@ ProconBypassMan.configure do |config|
34
46
  # pbm-cloudで使う場合はnever_exitにtrueをセットしてください. trueがセットされている場合、不慮の事故が発生してもプロセスが終了しなくなります
35
47
  config.never_exit_accidentally = true
36
48
 
37
- # 操作が高頻度で固まるときは、 gadget_to_procon_interval の数値は大きくしてください
38
- config.bypass_mode = { mode: :normal, gadget_to_procon_interval: 5 }
49
+ # 毎秒行ったIOをログに出力するか
50
+ config.io_monitor_logging = false
51
+
52
+ # 接続に成功したらコントローラーのHOME LEDを光らせるか
53
+ config.enable_home_led_on_connect = true
54
+
55
+ # 操作が高頻度で固まるときは、 gadget_to_procon_interval の数値を大きくしてください
56
+ config.bypass_mode = { mode: :normal, gadget_to_procon_interval: 10 }
39
57
  end
40
58
 
41
59
  ProconBypassMan.run(setting_path: "/usr/share/pbm/current/setting.yml")
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/inline'
4
+
5
+ retry_count_on_git_command_error = 0
6
+ begin
7
+ if retry_count_on_git_command_error > 10
8
+ STDOUT.puts "Stopped the procon_bypass_man program because could not download any source codes."
9
+ exit 1
10
+ end
11
+
12
+ gemfile do
13
+ source 'https://rubygems.org'
14
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
15
+ gem 'procon_bypass_man', '0.2.2'
16
+ end
17
+ rescue Bundler::Source::Git::GitCommandError => e
18
+ retry_count_on_git_command_error = retry_count_on_git_command_error + 1
19
+ sleep(5) # サービスの起動順によっては、まだoffline状態なので待機する
20
+
21
+ # install中に強制終了するとgitの管理ファイルが不正状態になり、次のエラーが起きるので発生したらcache directoryを削除する
22
+ #"Git error: command `git fetch --force --quiet --tags https://github.com/splaplapla/procon_bypass_man refs/heads/\\*:refs/heads/\\*` in directory /home/pi/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/cache/bundler/git/procon_bypass_man-ae4c9016d76b667658c8ba66f3bbd2eebf2656af has failed.\n\nIf this error persists you could try removing the cache directory '/home/pi/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/cache/bundler/git/procon_bypass_man-ae4c9016d76b667658c8ba66f3bbd2eebf2656af'"
23
+ if /try removing the cache directory '([^']+)'/ =~ e.message && $1&.start_with?('/home/pi/.rbenv')
24
+ require 'fileutils'
25
+ FileUtils.rm_rf($1)
26
+ STDOUT.puts "Deleted #{$1}"
27
+ end
28
+
29
+ retry
30
+ end
31
+
32
+ ProconBypassMan.configure do |config|
33
+ config.root = File.expand_path(__dir__)
34
+ config.logger = Logger.new("#{ProconBypassMan.root}/app.log", 1, 1024 * 1024 * 1)
35
+ config.logger.level = :debug
36
+
37
+ # バイパスするログを全部app.logに流すか
38
+ config.verbose_bypass_log = false
39
+
40
+ # webからProconBypassManを操作できるwebサービス
41
+ <%- api_server_config = "config.api_servers = ['https://pbm-cloud.herokuapp.com']" -%>
42
+ <%- if enable_integration_with_pbm_cloud -%>
43
+ <%= api_server_config %>
44
+ <%- else -%>
45
+ <%= "# #{api_server_config}" %>
46
+ <%- end -%>
47
+
48
+ # エラーが起きたらerror.logに書き込みます
49
+ config.enable_critical_error_logging = true
50
+
51
+ # pbm-cloudで使う場合はnever_exitにtrueをセットしてください. trueがセットされている場合、不慮の事故が発生してもプロセスが終了しなくなります
52
+ config.never_exit_accidentally = true
53
+
54
+ # 毎秒行ったIOをログに出力するか
55
+ config.io_monitor_logging = false
56
+
57
+ # 接続に成功したらコントローラーのHOME LEDを光らせるか
58
+ config.enable_home_led_on_connect = true
59
+
60
+ # 操作が高頻度で固まるときは、 gadget_to_procon_interval の数値を大きくしてください
61
+ config.bypass_mode = { mode: :normal, gadget_to_procon_interval: 10 }
62
+ end
63
+
64
+ ProconBypassMan.run(setting_path: "/usr/share/pbm/current/setting.yml")
@@ -0,0 +1,31 @@
1
+ require "erb"
2
+
3
+ # NOTE pbmenvで参照しているクラス
4
+ # 後方互換を維持するために、パラメータの削除・必須をしてはいけない
5
+ class AppGenerator
6
+ attr_reader :prefix_path
7
+
8
+ # @param [String] prefix_path
9
+ # @param [Boolean] enable_integration_with_pbm_cloud
10
+ def initialize(prefix_path: , enable_integration_with_pbm_cloud: )
11
+ @prefix_path = prefix_path
12
+ @enable_integration_with_pbm_cloud = enable_integration_with_pbm_cloud
13
+ end
14
+
15
+ def generate
16
+ erb = File.read(template_path)
17
+ enable_integration_with_pbm_cloud = @enable_integration_with_pbm_cloud
18
+ app_rb = ERB.new(erb, nil, '-').result(binding)
19
+ File.write(output_path, app_rb)
20
+ end
21
+
22
+ private
23
+
24
+ def template_path
25
+ File.join(prefix_path, "app.rb.erb")
26
+ end
27
+
28
+ def output_path
29
+ File.join(prefix_path, "app.rb")
30
+ end
31
+ end
@@ -10,7 +10,7 @@ end
10
10
 
11
11
  ProconBypassMan::Web.configure do |config|
12
12
  config.root = File.expand_path(__dir__)
13
- config.logger = Logger.new("#{ProconBypassMan::Web.root}/web.log", 1, 1024 * 1024 * 10)
13
+ config.logger = Logger.new("#{ProconBypassMan::Web.root}/web.log", 1, 1024 * 1024 * 1)
14
14
  end
15
15
 
16
16
  ProconBypassMan::Web::Server.start
data/sig/main.rbs CHANGED
@@ -11,9 +11,6 @@ module ProconBypassMan
11
11
  class CouldNotLoadConfigError < StandardError
12
12
  end
13
13
 
14
- class EternalConnectionError < StandardError
15
- end
16
-
17
14
  def self.configure: (?setting_path: untyped? setting_path) { () -> untyped } -> untyped
18
15
 
19
16
  def self.run: (?setting_path: untyped? setting_path) { () -> untyped } -> untyped
@@ -189,6 +186,7 @@ class ProconBypassMan::Configuration
189
186
  attr_reader api_server: untyped
190
187
  attr_reader api_servers: untyped
191
188
  attr_writer never_exit_accidentally: bool
189
+ attr_writer io_monitor_logging: bool
192
190
 
193
191
  attr_accessor enable_critical_error_logging: bool
194
192
 
@@ -228,6 +226,8 @@ class ProconBypassMan::Configuration
228
226
  def verbose_bypass_log: () -> bool
229
227
 
230
228
  def never_exit_accidentally: () -> bool
229
+
230
+ def io_monitor_logging: () -> bool
231
231
  end
232
232
 
233
233
 
data/tmp/.keep ADDED
File without changes
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.1.23
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - jiikko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-04 00:00:00.000000000 Z
11
+ date: 2022-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pbmenv
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".circleci/config.yml"
63
+ - ".github/workflows/gitleacks.yml"
63
64
  - ".github/workflows/release.yml"
64
65
  - ".github/workflows/ruby.yml"
65
66
  - ".gitignore"
@@ -75,6 +76,7 @@ files:
75
76
  - Steepfile
76
77
  - bin/console
77
78
  - bin/dev_api_server.rb
79
+ - bin/generate_default_app
78
80
  - bin/setup
79
81
  - docs/getting_started.md
80
82
  - docs/how_to_connect_procon.md
@@ -96,7 +98,7 @@ files:
96
98
  - lib/procon_bypass_man/background/jobs/base_job.rb
97
99
  - lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb
98
100
  - lib/procon_bypass_man/background/jobs/concerns/has_internal_api_setting.rb
99
- - lib/procon_bypass_man/background/jobs/concerns/job_runnable.rb
101
+ - lib/procon_bypass_man/background/jobs/concerns/job_performable.rb
100
102
  - lib/procon_bypass_man/background/jobs/post_completed_remote_macro_job.rb
101
103
  - lib/procon_bypass_man/background/jobs/report_boot_job.rb
102
104
  - lib/procon_bypass_man/background/jobs/report_completed_upgrade_pbm_job.rb
@@ -122,19 +124,27 @@ files:
122
124
  - lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/open_macro_steps.rb
123
125
  - lib/procon_bypass_man/buttons_setting_configuration/validator.rb
124
126
  - lib/procon_bypass_man/bypass.rb
127
+ - lib/procon_bypass_man/bypass/bypass_command.rb
125
128
  - lib/procon_bypass_man/bypass/usb_hid_logger.rb
126
129
  - lib/procon_bypass_man/commands.rb
127
- - lib/procon_bypass_man/commands/bypass_command.rb
128
- - lib/procon_bypass_man/commands/connect_device_command.rb
129
130
  - lib/procon_bypass_man/commands/print_boot_message_command.rb
130
131
  - lib/procon_bypass_man/commands/print_message_command.rb
131
- - lib/procon_bypass_man/commands/run_remote_pbm_action_dispatch_command.rb
132
132
  - lib/procon_bypass_man/commands/send_error_command.rb
133
133
  - lib/procon_bypass_man/commands/send_reload_config_event_command.rb
134
134
  - lib/procon_bypass_man/commands/write_device_id_command.rb
135
135
  - lib/procon_bypass_man/commands/write_session_id_command.rb
136
136
  - lib/procon_bypass_man/configuration.rb
137
- - lib/procon_bypass_man/device_connector.rb
137
+ - lib/procon_bypass_man/device_connection.rb
138
+ - lib/procon_bypass_man/device_connection/command.rb
139
+ - lib/procon_bypass_man/device_connection/executor.rb
140
+ - lib/procon_bypass_man/device_connection/output_report_generator.rb
141
+ - lib/procon_bypass_man/device_connection/output_report_markerable.rb
142
+ - lib/procon_bypass_man/device_connection/output_report_sub_command_table.rb
143
+ - lib/procon_bypass_man/device_connection/output_report_watcher.rb
144
+ - lib/procon_bypass_man/device_connection/pre_bypass.rb
145
+ - lib/procon_bypass_man/device_connection/procon_setting_overrider.rb
146
+ - lib/procon_bypass_man/device_connection/spoofing_output_report_watcher.rb
147
+ - lib/procon_bypass_man/device_model.rb
138
148
  - lib/procon_bypass_man/device_status.rb
139
149
  - lib/procon_bypass_man/io_monitor.rb
140
150
  - lib/procon_bypass_man/plugin/splatoon2/macro/charge_tansan_bomb.rb
@@ -175,6 +185,13 @@ files:
175
185
  - lib/procon_bypass_man/procon/value_objects/bypass_mode.rb
176
186
  - lib/procon_bypass_man/procon/value_objects/procon_reader.rb
177
187
  - lib/procon_bypass_man/procon/value_objects/rumble_binary.rb
188
+ - lib/procon_bypass_man/procon_display.rb
189
+ - lib/procon_bypass_man/procon_display/bypass_hook.rb
190
+ - lib/procon_bypass_man/procon_display/http_request.rb
191
+ - lib/procon_bypass_man/procon_display/http_response.rb
192
+ - lib/procon_bypass_man/procon_display/server.rb
193
+ - lib/procon_bypass_man/procon_display/server_app.rb
194
+ - lib/procon_bypass_man/procon_display/status.rb
178
195
  - lib/procon_bypass_man/remote_macro.rb
179
196
  - lib/procon_bypass_man/remote_macro/queue_over_process.rb
180
197
  - lib/procon_bypass_man/remote_macro/remote_macro_object.rb
@@ -185,6 +202,7 @@ files:
185
202
  - lib/procon_bypass_man/remote_pbm_action.rb
186
203
  - lib/procon_bypass_man/remote_pbm_action/base_action.rb
187
204
  - lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb
205
+ - lib/procon_bypass_man/remote_pbm_action/commands/run_remote_pbm_action_dispatch_command.rb
188
206
  - lib/procon_bypass_man/remote_pbm_action/commands/update_remote_pbm_action_status_command.rb
189
207
  - lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb
190
208
  - lib/procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb
@@ -210,6 +228,7 @@ files:
210
228
  - lib/procon_bypass_man/support/update_remote_pbm_action_status_http_client.rb
211
229
  - lib/procon_bypass_man/support/uptime.rb
212
230
  - lib/procon_bypass_man/support/usb_device_controller.rb
231
+ - lib/procon_bypass_man/support/yaml_loader.rb
213
232
  - lib/procon_bypass_man/support/yaml_writer.rb
214
233
  - lib/procon_bypass_man/version.rb
215
234
  - lib/procon_bypass_man/websocket/client.rb
@@ -218,6 +237,8 @@ files:
218
237
  - procon_bypass_man.gemspec
219
238
  - project_template/README.md
220
239
  - project_template/app.rb
240
+ - project_template/app.rb.erb
241
+ - project_template/lib/app_generator.rb
221
242
  - project_template/setting.yml
222
243
  - project_template/systemd_units/pbm.service
223
244
  - project_template/systemd_units/pbm_web.service
@@ -225,6 +246,7 @@ files:
225
246
  - sig/README.md
226
247
  - sig/main.rbs
227
248
  - sig/on_memory_cache.rbs
249
+ - tmp/.keep
228
250
  homepage: https://github.com/splaplapla/procon_bypass_man
229
251
  licenses:
230
252
  - MIT
@@ -240,7 +262,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
240
262
  requirements:
241
263
  - - ">="
242
264
  - !ruby/object:Gem::Version
243
- version: 3.0.0
265
+ version: 2.5.0
244
266
  required_rubygems_version: !ruby/object:Gem::Requirement
245
267
  requirements:
246
268
  - - ">="
@@ -1,18 +0,0 @@
1
- class ProconBypassMan::ConnectDeviceCommand
2
- class NotFoundProconError < StandardError; end
3
-
4
- # @return [void]
5
- def self.execute!
6
- gadget, procon = ProconBypassMan::DeviceConnector.connect
7
- rescue ProconBypassMan::DeviceConnector::NotFoundProconError => e
8
- ProconBypassMan.logger.error e
9
- gadget&.close
10
- procon&.close
11
- raise ProconBypassMan::ConnectDeviceCommand::NotFoundProconError
12
- rescue ProconBypassMan::SafeTimeout::Timeout
13
- ProconBypassMan.logger.error "デバイスとの通信でタイムアウトが起きて接続ができませんでした。"
14
- gadget&.close
15
- procon&.close
16
- raise ProconBypassMan::EternalConnectionError
17
- end
18
- end