procon_bypass_man 0.1.12 → 0.1.13

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/CHANGELOG.md +3 -0
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +11 -11
  5. data/README.md +10 -7
  6. data/lib/procon_bypass_man/background/http_client.rb +5 -8
  7. data/lib/procon_bypass_man/background/job_runner.rb +6 -5
  8. data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +10 -0
  9. data/lib/procon_bypass_man/background.rb +2 -0
  10. data/lib/procon_bypass_man/boot_message.rb +3 -1
  11. data/lib/procon_bypass_man/buttons_setting_configuration/layer.rb +34 -29
  12. data/lib/procon_bypass_man/buttons_setting_configuration.rb +2 -2
  13. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +7 -1
  14. data/lib/procon_bypass_man/commands/bypass_command.rb +86 -0
  15. data/lib/procon_bypass_man/commands/connect_device_command.rb +1 -1
  16. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +1 -1
  17. data/lib/procon_bypass_man/commands/send_error_command.rb +1 -0
  18. data/lib/procon_bypass_man/commands/send_reload_config_event_command.rb +1 -0
  19. data/lib/procon_bypass_man/commands/write_device_id_command.rb +1 -0
  20. data/lib/procon_bypass_man/commands.rb +1 -0
  21. data/lib/procon_bypass_man/configuration.rb +7 -4
  22. data/lib/procon_bypass_man/device_connector.rb +30 -23
  23. data/lib/procon_bypass_man/procon/analog_stick_cap.rb +1 -1
  24. data/lib/procon_bypass_man/procon/layer_changer.rb +1 -1
  25. data/lib/procon_bypass_man/runner.rb +5 -94
  26. data/lib/procon_bypass_man/splatoon2/macro/fast_return.rb +15 -0
  27. data/lib/procon_bypass_man/splatoon2/macro/jump_to_left_key.rb +15 -0
  28. data/lib/procon_bypass_man/splatoon2/macro/jump_to_right_key.rb +15 -0
  29. data/lib/procon_bypass_man/splatoon2/macro/jump_to_up_key.rb +15 -0
  30. data/lib/procon_bypass_man/splatoon2/mode/guruguru.rb +57 -0
  31. data/lib/procon_bypass_man/splatoon2/version.rb +7 -0
  32. data/lib/procon_bypass_man/splatoon2.rb +11 -0
  33. data/lib/procon_bypass_man/{callbacks.rb → support/callbacks.rb} +0 -0
  34. data/lib/procon_bypass_man/support/compress_array.rb +56 -0
  35. data/lib/procon_bypass_man/{on_memory_cache.rb → support/on_memory_cache.rb} +0 -0
  36. data/lib/procon_bypass_man/{timer.rb → support/safe_timeout.rb} +1 -1
  37. data/lib/procon_bypass_man/support/signal_handler.rb +11 -0
  38. data/lib/procon_bypass_man/{uptime.rb → support/uptime.rb} +0 -0
  39. data/lib/procon_bypass_man/version.rb +1 -1
  40. data/lib/procon_bypass_man.rb +11 -6
  41. data/procon_bypass_man.gemspec +2 -2
  42. data/project_template/README.md +18 -11
  43. data/project_template/app.rb +1 -2
  44. data/sig/{README.rb → README.md} +0 -0
  45. metadata +21 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42551d494786247ae06f81c416f522360001fb0a78ffdd67311520aafb56587a
4
- data.tar.gz: 92da20f533512ec4e1fdebe93f2c064f5ae1513fd6f26d3c4f34f2a0d488dffd
3
+ metadata.gz: 62fab79bffee3adf43af06325d7ef6bce2060f844d8caaa824968ff77219e5de
4
+ data.tar.gz: c15ab8b50da926169727b9af5ff097585cd35c7e24fdf2ce75d2ca7d4fe5f07e
5
5
  SHA512:
6
- metadata.gz: b52fde78831c29dc1b56b56217a604e421b6c0cdf5859b997732b36d94b9b7dc9d02f3906835d41df5f7168a2b694c2c457d3f96fd235903fc4827f42e74422b
7
- data.tar.gz: 50defecca29919fca30680469deddc5adc5c41d0c4f02f084c0a73f9633aa8e11101a5f07e863ea4e0b6481178d4f11e0d466a4bf2d9954f08cb5407d3cb10dd
6
+ metadata.gz: c94bc5e37b89c54a31fe165e53f84ac32c1b4d10fc617cc1397e0347baf1a39206fd50aff3a65626b8546545d00f33ac0e44a90da5ff25c02778d27e60aafe0f
7
+ data.tar.gz: 7ad56ef9e17bb8a26d840003faf8fa7d065ba878182dcd23d66118b43053c2827221814f37bb4098174cdfbcc449486d895bf6431520f60ce295a4e7382c39e7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## [0.1.13] - 2021-11-24
2
+ - 起動を早くするために、procon_bypass_man-splatoon2を同梱しました
3
+
1
4
  ## [0.1.12] - 2021-11-18
2
5
  - 起動ログなどを設定した外部サーバに送信できるようにしました
3
6
 
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in procon_bypass_man.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ gem "rake"
9
9
  gem "rspec"
10
10
  gem "pry"
11
11
  gem "timecop"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- procon_bypass_man (0.1.12)
4
+ procon_bypass_man (0.1.13)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -17,7 +17,7 @@ GEM
17
17
  concurrent-ruby (1.1.9)
18
18
  diff-lcs (1.4.4)
19
19
  ffi (1.15.4)
20
- i18n (1.8.10)
20
+ i18n (1.8.11)
21
21
  concurrent-ruby (~> 1.0)
22
22
  language_server-protocol (3.16.0.3)
23
23
  listen (3.7.0)
@@ -27,7 +27,7 @@ GEM
27
27
  minitest (5.14.4)
28
28
  mustermann (1.1.1)
29
29
  ruby2_keywords (~> 0.0.1)
30
- parallel (1.20.1)
30
+ parallel (1.21.0)
31
31
  parser (3.0.2.0)
32
32
  ast (~> 2.4.1)
33
33
  pry (0.14.1)
@@ -41,7 +41,7 @@ GEM
41
41
  rb-fsevent (0.11.0)
42
42
  rb-inotify (0.10.1)
43
43
  ffi (~> 1.0)
44
- rbs (1.6.2)
44
+ rbs (1.7.1)
45
45
  regexp_parser (2.1.1)
46
46
  rexml (3.2.5)
47
47
  rspec (3.10.0)
@@ -56,17 +56,17 @@ GEM
56
56
  rspec-mocks (3.10.2)
57
57
  diff-lcs (>= 1.2.0, < 2.0)
58
58
  rspec-support (~> 3.10.0)
59
- rspec-support (3.10.2)
60
- rubocop (1.20.0)
59
+ rspec-support (3.10.3)
60
+ rubocop (1.23.0)
61
61
  parallel (~> 1.10)
62
62
  parser (>= 3.0.0.0)
63
63
  rainbow (>= 2.2.2, < 4.0)
64
64
  regexp_parser (>= 1.8, < 3.0)
65
65
  rexml
66
- rubocop-ast (>= 1.9.1, < 2.0)
66
+ rubocop-ast (>= 1.12.0, < 2.0)
67
67
  ruby-progressbar (~> 1.7)
68
68
  unicode-display_width (>= 1.4.0, < 3.0)
69
- rubocop-ast (1.11.0)
69
+ rubocop-ast (1.13.0)
70
70
  parser (>= 3.0.1.1)
71
71
  ruby-progressbar (1.11.0)
72
72
  ruby2_keywords (0.0.5)
@@ -90,9 +90,9 @@ GEM
90
90
  timecop (0.9.4)
91
91
  tzinfo (2.0.4)
92
92
  concurrent-ruby (~> 1.0)
93
- unicode-display_width (2.0.0)
93
+ unicode-display_width (2.1.0)
94
94
  webrick (1.7.0)
95
- zeitwerk (2.4.2)
95
+ zeitwerk (2.5.1)
96
96
 
97
97
  PLATFORMS
98
98
  arm-linux
@@ -104,7 +104,7 @@ PLATFORMS
104
104
  DEPENDENCIES
105
105
  procon_bypass_man!
106
106
  pry
107
- rake (~> 13.0)
107
+ rake
108
108
  rbs
109
109
  rspec
110
110
  rubocop
data/README.md CHANGED
@@ -28,8 +28,8 @@ Switch <-- (PBM): ZR連打
28
28
  ## Usage
29
29
  * USBガジェットモードで起動するRaspberry Pi4を用意する
30
30
  * https://github.com/splaplapla/procon_bypass_man/blob/master/docs/setup_raspi.md
31
- * Raspberry Pi4で https://github.com/jiikko/procon_bypass_man_sample をclone して実行ファイルを動かす
32
- * 実行ファイルと設定ファイルについては https://github.com/splaplapla/procon_bypass_man/wiki に詳細を書いていますが、まず動かすためにはcloneしたほうが早いです
31
+ * Raspberry Pi4 sudo pbmenv install latest && cd /usr/share/pbm/current && sudo ruby app.rb
32
+ * 動いたのを確認したらserviceとして登録にするなどしてください
33
33
 
34
34
  ## Plugins
35
35
  * https://github.com/splaplapla/procon_bypass_man-splatoon2
@@ -52,6 +52,8 @@ Switch <-- (PBM): ZR連打
52
52
  * 連射中には特定のキーの入力を無視したり、複数のキーをトリガーに連射することができます
53
53
  * どうしてsudoが必要なの?
54
54
  * 操作するdeviceファイルの所有者がrootだから
55
+ * 市販されているサードパーティ製連射機との違いは?
56
+ * サードパーティ製のコントローラーは、設定方法や形状が特殊で買い換えるたびに学習・設定コストが発生します。本ツールを使えば、設定内容はテキストで管理することができ、使い慣れたプロコンで同等のことができます。
55
57
 
56
58
  ## TODO
57
59
  * レコーディング機能(プロコンの入力をマクロとして登録ができる)
@@ -59,8 +61,6 @@ Switch <-- (PBM): ZR連打
59
61
  * 設定ファイル マクロの引数に、ボタンを取れるようにする
60
62
 
61
63
  ## 開発系
62
- * pbmenvで生成するapp.rbに開発用ブランチを参照してください
63
-
64
64
  ### プロコンとの接続を維持したまま、現在の設定ファイルをPBMに反映する
65
65
  ```shell
66
66
  sudo kill -USR2 `cat ./pbm_pid`
@@ -71,9 +71,8 @@ sudo kill -USR2 `cat ./pbm_pid`
71
71
 
72
72
  ### 開発環境でログの送信を確認する方法
73
73
  * `bundle exec bin/dev_api_server.rb`
74
- * `INTERNAL_API_SERVER=http://localhost:4567 bin/console`
75
- * `API_SERVER=http://localhost:4567 bin/console`
76
- * `message = ProconBypassMan::BootMessage.new; ProconBypassMan::ReportBootJob.report(body: message.to_hash)`
74
+ * `API_SERVER=http://localhost:4567 INTERNAL_API_SERVER=http://localhost:4567 bin/console`
75
+ * `message = ProconBypassMan::BootMessage.new; ProconBypassMan::ReportBootJob.perform(body: message.to_hash)`
77
76
 
78
77
  ### リリース手順
79
78
  * project_template/web.rb, project_template/app.rb, lib/procon_bypass_man/version.rb のバージョンをあげる
@@ -83,3 +82,7 @@ sudo kill -USR2 `cat ./pbm_pid`
83
82
  ## License
84
83
 
85
84
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
85
+
86
+
87
+ ## Links
88
+ * https://discord.gg/bEcRNKf4ep
@@ -2,7 +2,7 @@ module ProconBypassMan
2
2
  module Background
3
3
  class HttpClient
4
4
  class HttpRequest
5
- def self.request!(uri: , hostname: , body: , device_id: , session_id: nil, event_type: )
5
+ def self.request!(uri: , hostname: , params: , device_id: , session_id: nil, event_type: )
6
6
  @uri = uri
7
7
  @http = Net::HTTP.new(uri.host, uri.port)
8
8
  @http.use_ssl = uri.scheme === "https"
@@ -11,7 +11,7 @@ module ProconBypassMan
11
11
  event_type: event_type,
12
12
  session_id: session_id,
13
13
  device_id: device_id,
14
- }.merge(body)
14
+ }.merge(params)
15
15
  @http.post(
16
16
  @uri.path,
17
17
  @params.to_json,
@@ -32,11 +32,8 @@ module ProconBypassMan
32
32
  ProconBypassMan.logger.info('送信先が未設定なのでスキップしました')
33
33
  return
34
34
  end
35
- if body.is_a?(Hash)
36
- body = { body: body, event_type: event_type }
37
- else
38
- body = { body: { value: body, event_type: event_type } }
39
- end
35
+
36
+ params = { body: body.to_json }
40
37
  session_id = ProconBypassMan.session_id
41
38
  device_id = ProconBypassMan.device_id
42
39
 
@@ -45,7 +42,7 @@ module ProconBypassMan
45
42
  hostname: @hostname,
46
43
  device_id: device_id,
47
44
  session_id: session_id,
48
- body: body,
45
+ params: params,
49
46
  event_type: event_type,
50
47
  )
51
48
  case response.code
@@ -8,14 +8,14 @@ module ProconBypassMan
8
8
  end
9
9
 
10
10
  # for test
11
- def self.stop!
12
- return unless defined?(@@thread)
13
- @@thread.kill
11
+ def stop!
12
+ return unless defined?(@thread)
13
+ @thread.kill
14
14
  end
15
15
 
16
16
  def start!
17
- return if defined?(@@thread)
18
- @@thread = Thread.new do
17
+ return if defined?(@thread)
18
+ @thread = Thread.new do
19
19
  while(item = self.class.queue.pop)
20
20
  begin
21
21
  JobPerformer.new(klass: item[:reporter_class], args: item[:args]).perform
@@ -25,6 +25,7 @@ module ProconBypassMan
25
25
  end
26
26
  end
27
27
  end
28
+ self
28
29
  end
29
30
 
30
31
  def self.queue
@@ -0,0 +1,10 @@
1
+ class ProconBypassMan::ReportLoadConfigJob < ProconBypassMan::BaseJob
2
+ # @param [String] body
3
+ def self.perform(body)
4
+ ProconBypassMan::Background::HttpClient.new(
5
+ path: path,
6
+ pool_server: pool_server,
7
+ retry_on_connection_error: false,
8
+ ).post(body: body, event_type: :load_config)
9
+ end
10
+ end
@@ -1,10 +1,12 @@
1
1
  require "procon_bypass_man/background/job_runnable"
2
+ require "procon_bypass_man/background/job_runner"
2
3
  require "procon_bypass_man/background/job_performer"
3
4
  require "procon_bypass_man/background/has_server_pool"
4
5
  require "procon_bypass_man/background/http_client"
5
6
  require "procon_bypass_man/background/jobs/base_job"
6
7
  require "procon_bypass_man/background/jobs/report_boot_job"
7
8
  require "procon_bypass_man/background/jobs/report_reload_config_job"
9
+ require "procon_bypass_man/background/jobs/report_load_config_job"
8
10
  require "procon_bypass_man/background/jobs/report_error_job"
9
11
  require "procon_bypass_man/background/jobs/report_heartbeat_job"
10
12
  require "procon_bypass_man/background/jobs/report_pressed_buttons_job"
@@ -8,6 +8,7 @@ class ProconBypassMan::BootMessage
8
8
  @table[:pid_path] = ProconBypassMan.pid_path
9
9
  @table[:setting_path] = ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path
10
10
  @table[:uptime_from_boot] = ProconBypassMan::Uptime.from_boot
11
+ @table[:use_pbmenv] = !(!!`which pbmenv`.empty?)
11
12
 
12
13
  # 開発中のHEADを取りたかったけど、Gem::Specification経由から取得する必要がありそう
13
14
  # build_version = `git rev-parse --short HEAD`.chomp
@@ -25,12 +26,13 @@ class ProconBypassMan::BootMessage
25
26
  booted_message = <<~EOF
26
27
  ----
27
28
  RUBY_VERSION: #{@table[:ruby_version]}
28
- ProconBypassMan: #{@table[:pbm_version]}
29
+ ProconBypassMan::VERSION: #{@table[:pbm_version]}
29
30
  pid: #{@table[:pid]}
30
31
  root: #{@table[:root_path]}
31
32
  pid_path: #{@table[:pid_path]}
32
33
  setting_path: #{@table[:setting_path]}
33
34
  uptime from boot: #{@table[:uptime_from_boot]} sec
35
+ use_pbmenv: #{@table[:use_pbmenv]}
34
36
  ----
35
37
  EOF
36
38
  end
@@ -20,21 +20,26 @@ module ProconBypassMan
20
20
  if_pressed = [button]
21
21
  when Symbol, String
22
22
  if_pressed = [if_pressed]
23
- when Array, FalseClass
24
- # sono mama
23
+ when Array
24
+ # if_pressed = if_pressed
25
+ when FalseClass, NilClass
26
+ # no-op
25
27
  else
26
28
  raise "not support class"
27
29
  end
30
+
28
31
  hash = { if_pressed: if_pressed }
29
- if force_neutral
30
- case force_neutral
31
- when TrueClass, FalseClass
32
- raise "ボタンを渡してください"
33
- when Symbol, String
34
- hash[:force_neutral] = [force_neutral]
35
- when Array
36
- hash[:force_neutral] = force_neutral
37
- end
32
+ case force_neutral
33
+ when TrueClass
34
+ raise "ボタンを渡してください"
35
+ when Symbol, String
36
+ hash[:force_neutral] = [force_neutral]
37
+ when Array
38
+ hash[:force_neutral] = force_neutral
39
+ when FalseClass, NilClass
40
+ # no-op
41
+ else
42
+ raise "not support value"
38
43
  end
39
44
 
40
45
  if flip_interval
@@ -63,7 +68,7 @@ module ProconBypassMan
63
68
 
64
69
  def remap(button, to: )
65
70
  case to
66
- when TrueClass, FalseClass
71
+ when TrueClass, FalseClass, NilClass
67
72
  raise "ボタンを渡してください"
68
73
  when Symbol, String
69
74
  self.remaps[button] = { to: [to] }
@@ -77,27 +82,27 @@ module ProconBypassMan
77
82
  hash = { cap: cap }
78
83
 
79
84
  case if_pressed
80
- when TrueClass
81
- raise "not support class"
85
+ when TrueClass, FalseClass
86
+ raise "ボタンを渡してください"
82
87
  when Symbol, String
83
88
  if_pressed = [if_pressed]
84
- when Array, FalseClass
85
- # sono mama
86
- when NilClass
87
- if_pressed = nil
89
+ when Array, NilClass
90
+ # no-op
88
91
  else
89
- raise "not support if_pressed"
92
+ raise "not support value"
90
93
  end
91
94
 
92
- if force_neutral
93
- case force_neutral
94
- when TrueClass, FalseClass
95
- raise "ボタンを渡してください"
96
- when Symbol, String
97
- hash[:force_neutral] = [force_neutral]
98
- when Array
99
- hash[:force_neutral] = force_neutral
100
- end
95
+ case force_neutral
96
+ when TrueClass
97
+ raise "ボタンを渡してください"
98
+ when Symbol, String
99
+ hash[:force_neutral] = [force_neutral]
100
+ when Array
101
+ hash[:force_neutral] = force_neutral
102
+ when FalseClass, NilClass
103
+ # no-op
104
+ else
105
+ raise "not support value"
101
106
  end
102
107
 
103
108
  left_analog_stick_caps[if_pressed] = hash
@@ -114,7 +119,7 @@ module ProconBypassMan
114
119
  when Array
115
120
  button.each { |b| disables << b }
116
121
  else
117
- raise "unknown"
122
+ raise "not support value"
118
123
  end
119
124
  end
120
125
 
@@ -77,7 +77,7 @@ module ProconBypassMan
77
77
  end
78
78
 
79
79
  def set_neutral_position(x, y)
80
- self.neutral_position = AnalogStickPosition.new(x, y)
80
+ self.neutral_position = AnalogStickPosition.new(x, y).freeze
81
81
  self
82
82
  end
83
83
 
@@ -95,7 +95,7 @@ module ProconBypassMan
95
95
  left: Layer.new,
96
96
  right: Layer.new,
97
97
  }
98
- @neutral_position = AnalogStickPosition.new(2124, 1808)
98
+ @neutral_position = AnalogStickPosition.new(2124, 1808).freeze
99
99
  end
100
100
  end
101
101
  end
@@ -10,7 +10,13 @@ class ProconBypassMan::Bypass
10
10
  set_callback :send_procon_to_gadget, :after, :log_procon_to_gadget
11
11
 
12
12
  def log_send_gadget_to_procon
13
- ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
13
+ if ProconBypassMan.config.verbose_bypass_log
14
+ ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
15
+ else
16
+ ProconBypassMan.cache.fetch key: 'bypass_log', expires_in: 1 do
17
+ ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
18
+ end
19
+ end
14
20
  end
15
21
 
16
22
  def log_procon_to_gadget
@@ -0,0 +1,86 @@
1
+ class ProconBypassMan::BypassCommand
2
+ include ProconBypassMan::SignalHandler
3
+
4
+ def initialize(gadget:, procon:)
5
+ @gadget = gadget
6
+ @procon = procon
7
+
8
+ ProconBypassMan::IOMonitor.start!
9
+ ProconBypassMan::Background::JobRunner.queue.clear # forkしたときに残留物も移ってしまうため
10
+ ProconBypassMan::Background::JobRunner.start!
11
+ end
12
+
13
+ def execute
14
+ self_read, self_write = IO.pipe
15
+ %w(TERM INT).each do |sig|
16
+ begin
17
+ trap sig do
18
+ self_write.puts(sig)
19
+ end
20
+ rescue ArgumentError
21
+ puts "プロセスでSignal #{sig} not supported"
22
+ end
23
+ end
24
+
25
+ # gadget => procon
26
+ # 遅くていい
27
+ monitor1 = ProconBypassMan::IOMonitor.new(label: "switch -> procon")
28
+ monitor2 = ProconBypassMan::IOMonitor.new(label: "procon -> switch")
29
+ ProconBypassMan.logger.info "Thread1を起動します"
30
+ t1 = Thread.new do
31
+ timer = ProconBypassMan::SafeTimeout.new(timeout: Time.now + 10)
32
+ bypass = ProconBypassMan::Bypass.new(gadget: @gadget, procon: @procon, monitor: monitor1)
33
+ loop do
34
+ break if $will_terminate_token
35
+ timer.throw_if_timeout!
36
+ bypass.send_gadget_to_procon!
37
+ sleep(0.005)
38
+ rescue ProconBypassMan::SafeTimeout::Timeout
39
+ ProconBypassMan.logger.info "10秒経過したのでThread1を終了します"
40
+ monitor1.shutdown
41
+ puts "10秒経過したのでThread1を終了します"
42
+ break
43
+ rescue Errno::EIO, Errno::ENODEV, Errno::EPROTO, IOError => e
44
+ ProconBypassMan::SendErrorCommand.execute(error: "Switchとの切断されました.終了処理を開始します. #{e.full_message}")
45
+ Process.kill "TERM", Process.ppid
46
+ rescue Errno::ETIMEDOUT => e
47
+ # TODO まれにこれが発生する. 再接続したい
48
+ ProconBypassMan::SendErrorCommand.execute(error: "Switchと意図せず切断されました.終了処理を開始します. #{e.full_message}")
49
+ Process.kill "TERM", Process.ppid
50
+ end
51
+ ProconBypassMan.logger.info "Thread1を終了します"
52
+ end
53
+
54
+ # procon => gadget
55
+ # シビア
56
+ ProconBypassMan.logger.info "Thread2を起動します"
57
+ t2 = Thread.new do
58
+ bypass = ProconBypassMan::Bypass.new(gadget: @gadget, procon: @procon, monitor: monitor2)
59
+ loop do
60
+ break if $will_terminate_token
61
+ bypass.send_procon_to_gadget!
62
+ rescue EOFError => e
63
+ ProconBypassMan::SendErrorCommand.execute(error: "Proconが切断されました。終了処理を開始します. #{e.full_message}")
64
+ Process.kill "TERM", Process.ppid
65
+ rescue Errno::EIO, Errno::ENODEV, Errno::EPROTO, IOError => e
66
+ ProconBypassMan::SendErrorCommand.execute(error: "Proconが切断されました。終了処理を開始します2. #{e.full_message}")
67
+ Process.kill "TERM", Process.ppid
68
+ end
69
+ ProconBypassMan.logger.info "Thread2を終了します"
70
+ end
71
+
72
+ ProconBypassMan.logger.info "子プロセスでgraceful shutdownの準備ができました"
73
+ begin
74
+ while(readable_io = IO.select([self_read]))
75
+ signal = readable_io.first[0].gets.strip
76
+ handle_signal(signal)
77
+ end
78
+ rescue Interrupt
79
+ $will_terminate_token = true
80
+ [t1, t2].each(&:join)
81
+ @gadget&.close
82
+ @procon&.close
83
+ exit 1
84
+ end
85
+ end
86
+ end
@@ -2,7 +2,7 @@ class ProconBypassMan::ConnectDeviceCommand
2
2
  # @return [void]
3
3
  def self.execute!
4
4
  gadget, procon = ProconBypassMan::DeviceConnector.connect
5
- rescue ProconBypassMan::Timer::Timeout
5
+ rescue ProconBypassMan::SafeTimeout::Timeout
6
6
  ::ProconBypassMan.logger.error "デバイスとの通信でタイムアウトが起きて接続ができませんでした。"
7
7
  gadget&.close
8
8
  procon&.close
@@ -3,7 +3,7 @@ class ProconBypassMan::PrintBootMessageCommand
3
3
  def self.execute
4
4
  message = ProconBypassMan::BootMessage.new
5
5
  ProconBypassMan::ReportBootJob.perform_async(message.to_hash)
6
- ProconBypassMan::ReportBootJob.perform_async(ProconBypassMan.config.raw_setting)
6
+ ProconBypassMan::ReportLoadConfigJob.perform_async(ProconBypassMan.config.raw_setting)
7
7
  puts message.to_s
8
8
  end
9
9
  end
@@ -11,6 +11,7 @@ class ProconBypassMan::SendErrorCommand
11
11
  end
12
12
 
13
13
  ProconBypassMan.logger.error body
14
+ ProconBypassMan.error_logger.error body
14
15
  puts body
15
16
 
16
17
  ProconBypassMan::ReportErrorJob.perform_async(error)
@@ -1,4 +1,5 @@
1
1
  class ProconBypassMan::SendReloadConfigEventCommand
2
+ # @return [void]
2
3
  def self.execute
3
4
  puts "設定ファイルの再読み込みができました"
4
5
  ProconBypassMan.logger.info "設定ファイルの再読み込みができました"
@@ -1,4 +1,5 @@
1
1
  class ProconBypassMan::WriteDeviceIdCommand
2
+ # @return [String]
2
3
  def self.execute
3
4
  path = "#{ProconBypassMan.root}/device_id"
4
5
  if(sid = File.read(path))
@@ -4,3 +4,4 @@ require "procon_bypass_man/commands/write_device_id_command"
4
4
  require "procon_bypass_man/commands/send_reload_config_event_command"
5
5
  require "procon_bypass_man/commands/send_error_command"
6
6
  require "procon_bypass_man/commands/connect_device_command"
7
+ require "procon_bypass_man/commands/bypass_command"
@@ -35,8 +35,8 @@ class ProconBypassMan::Configuration
35
35
  end
36
36
  end
37
37
 
38
- attr_accessor :enable_critical_error_logging, :raw_setting
39
- attr_writer :verbose_bypass_log
38
+ attr_accessor :enable_critical_error_logging
39
+ attr_writer :verbose_bypass_log, :raw_setting
40
40
 
41
41
  def root=(path)
42
42
  @root = path
@@ -75,11 +75,10 @@ class ProconBypassMan::Configuration
75
75
 
76
76
  def error_logger
77
77
  if enable_critical_error_logging
78
- @@error_logger ||= Logger.new("#{ProconBypassMan.root}/error.log", 5, 1024 * 1024 * 10)
78
+ @error_logger ||= Logger.new("#{ProconBypassMan.root}/error.log", 5, 1024 * 1024 * 10)
79
79
  else
80
80
  Logger.new(File.open("/dev/null"))
81
81
  end
82
- self
83
82
  end
84
83
 
85
84
  def digest_path
@@ -108,4 +107,8 @@ class ProconBypassMan::Configuration
108
107
  def verbose_bypass_log
109
108
  @verbose_bypass_log || !!ENV["VERBOSE_BYPASS_LOG"]
110
109
  end
110
+
111
+ def raw_setting
112
+ @raw_setting ||= {}
113
+ end
111
114
  end