procon_bypass_man 0.1.22 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +1 -1
  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 +22 -0
  7. data/Gemfile.lock +5 -5
  8. data/docs/getting_started.md +9 -1
  9. data/docs/setup_raspi.md +0 -1
  10. data/lib/procon_bypass_man/buttons_setting_configuration/loader.rb +1 -1
  11. data/lib/procon_bypass_man/{commands → bypass}/bypass_command.rb +36 -24
  12. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +3 -0
  13. data/lib/procon_bypass_man/bypass.rb +40 -23
  14. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +2 -3
  15. data/lib/procon_bypass_man/commands/send_error_command.rb +2 -2
  16. data/lib/procon_bypass_man/commands.rb +0 -3
  17. data/lib/procon_bypass_man/configuration.rb +22 -3
  18. data/lib/procon_bypass_man/device_connection/command.rb +28 -0
  19. data/lib/procon_bypass_man/device_connection/executor.rb +190 -0
  20. data/lib/procon_bypass_man/device_connection/output_report_generator.rb +42 -0
  21. data/lib/procon_bypass_man/device_connection/output_report_markerable.rb +28 -0
  22. data/lib/procon_bypass_man/device_connection/output_report_sub_command_table.rb +133 -0
  23. data/lib/procon_bypass_man/device_connection/output_report_watcher.rb +41 -0
  24. data/lib/procon_bypass_man/device_connection/pre_bypass.rb +67 -0
  25. data/lib/procon_bypass_man/device_connection/procon_setting_overrider.rb +78 -0
  26. data/lib/procon_bypass_man/device_connection/spoofing_output_report_watcher.rb +39 -0
  27. data/lib/procon_bypass_man/device_connection.rb +16 -0
  28. data/lib/procon_bypass_man/device_model.rb +17 -0
  29. data/lib/procon_bypass_man/io_monitor.rb +20 -1
  30. data/lib/procon_bypass_man/procon/macro_builder.rb +5 -3
  31. data/lib/procon_bypass_man/procon/suppress_rumble.rb +13 -0
  32. data/lib/procon_bypass_man/{domains → procon/value_objects}/analog_stick_position.rb +0 -0
  33. data/lib/procon_bypass_man/{domains → procon/value_objects}/binary/base.rb +0 -0
  34. data/lib/procon_bypass_man/{domains → procon/value_objects}/binary/has_immutable_binary.rb +0 -0
  35. data/lib/procon_bypass_man/{domains → procon/value_objects}/binary/has_mutable_binary.rb +0 -0
  36. data/lib/procon_bypass_man/{domains → procon/value_objects}/binary/inbound_procon_binary.rb +5 -0
  37. data/lib/procon_bypass_man/{domains → procon/value_objects}/binary/processing_procon_binary.rb +0 -0
  38. data/lib/procon_bypass_man/procon/value_objects/binary.rb +11 -0
  39. data/lib/procon_bypass_man/{domains → procon/value_objects}/bypass_mode.rb +0 -0
  40. data/lib/procon_bypass_man/procon/value_objects/rumble_binary.rb +18 -0
  41. data/lib/procon_bypass_man/procon.rb +8 -0
  42. data/lib/procon_bypass_man/procon_display/http_request.rb +31 -0
  43. data/lib/procon_bypass_man/procon_display/http_response.rb +23 -0
  44. data/lib/procon_bypass_man/procon_display/server.rb +33 -0
  45. data/lib/procon_bypass_man/procon_display/server_app.rb +17 -0
  46. data/lib/procon_bypass_man/procon_display/status.rb +20 -0
  47. data/lib/procon_bypass_man/procon_display.rb +10 -0
  48. data/lib/procon_bypass_man/{commands → remote_pbm_action/commands}/run_remote_pbm_action_dispatch_command.rb +0 -0
  49. data/lib/procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb +7 -1
  50. data/lib/procon_bypass_man/remote_pbm_action.rb +1 -0
  51. data/lib/procon_bypass_man/runner.rb +10 -13
  52. data/lib/procon_bypass_man/support/cycle_sleep.rb +22 -0
  53. data/lib/procon_bypass_man/support/device_mouse_finder.rb +60 -0
  54. data/lib/procon_bypass_man/{device_procon_finder.rb → support/device_procon_finder.rb} +0 -0
  55. data/lib/procon_bypass_man/support/never_exit_accidentally.rb +3 -3
  56. data/lib/procon_bypass_man/support/safe_timeout.rb +7 -1
  57. data/lib/procon_bypass_man/{usb_device_controller.rb → support/usb_device_controller.rb} +9 -4
  58. data/lib/procon_bypass_man/support/yaml_loader.rb +12 -0
  59. data/lib/procon_bypass_man/version.rb +1 -1
  60. data/lib/procon_bypass_man/websocket/client.rb +1 -4
  61. data/lib/procon_bypass_man.rb +66 -51
  62. data/project_template/app.rb +23 -7
  63. data/sig/main.rbs +4 -16
  64. metadata +37 -16
  65. data/lib/procon_bypass_man/commands/connect_device_command.rb +0 -18
  66. data/lib/procon_bypass_man/device_connector.rb +0 -293
  67. data/lib/procon_bypass_man/domains.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f213faf13081ece91f62fb64af88e63672d035d29740b9c98c832f89921d8f9d
4
- data.tar.gz: 3ec15d612dfaa91b085fef0a9e8810625b79b3a2a0781c57a56a39cc0b2d6be4
3
+ metadata.gz: b867d9fe101999d57ded64ff71be83610f04fde36c1c1fffa43ca8495902fb0b
4
+ data.tar.gz: 8eb0b7506c7bdb5d4601fb0e6f33cff79cb71a4975449d0c84bcd6a2c0b6303a
5
5
  SHA512:
6
- metadata.gz: 3570d9025f546e14e13b441a60568d58ec2ae728805061f7152c34e544e142a5c75ac37e893af96cafa5c956a8063eff41ddf6585b044c87e003e1ea4ba1902d
7
- data.tar.gz: 4a1dceca2806e28ac8cb9ca859f82adc5dc09ce9071c743df0ee7d4e2a4f761386a43057660f930d4d105c3898ba48496658c6a7eb3e86fc2d60e86f0df5cd8d
6
+ metadata.gz: a37867fc758ecb8aa45698fbb79be8b48cc221cd218bf6c29646b04587ae66514846709cd1bf951a651ec1ba737cab5dbae010334cb125bc8dca1644d19aa30e
7
+ data.tar.gz: d2cf7935350a3085251deb495051586b52b422d388bfd07da7842c09fbc3f50fa0b6090a41652e662d15e367863c76e0b3a2e9e061e87a7e100f3d1e7d9be58e
data/.circleci/config.yml CHANGED
@@ -40,7 +40,7 @@ jobs:
40
40
  tag: 3.0.1
41
41
  steps:
42
42
  - checkout
43
- - run: GEM_VERSION=$(grep -o -E '[0-9.]+' lib/procon_bypass_man/version.rb) && GEM_VERSION_IN_BUNDER=$(grep procon_bypass_man project_template/app.rb | grep -o -E '[0-9.]+') && test "$GEM_VERSION" = "$GEM_VERSION_IN_BUNDER"
43
+ - run: GEM_VERSION=$(grep -o -E '[0-9.]+' lib/procon_bypass_man/version.rb) && GEM_VERSION_IN_BUNDER=$(grep procon_bypass_man project_template/app.rb | grep "gem 'procon_bypass_man'" | grep -o -E '[0-9.]+') && test "$GEM_VERSION" = "$GEM_VERSION_IN_BUNDER"
44
44
 
45
45
  syntax_check:
46
46
  parameters:
@@ -0,0 +1,12 @@
1
+ name: gitleaks
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ gitleaks:
7
+ runs-on: ubuntu-latest
8
+ timeout-minutes: 5
9
+ steps:
10
+ - uses: actions/checkout@v1
11
+ - name: gitleaks-action
12
+ uses: zricethezav/gitleaks-action@master
@@ -6,6 +6,7 @@ on:
6
6
  jobs:
7
7
  release:
8
8
  runs-on: ubuntu-latest
9
+ timeout-minutes: 5
9
10
  permissions:
10
11
  contents: write
11
12
 
@@ -12,8 +12,8 @@ on:
12
12
 
13
13
  jobs:
14
14
  test:
15
-
16
15
  runs-on: ubuntu-latest
16
+ timeout-minutes: 5
17
17
  strategy:
18
18
  matrix:
19
19
  ruby-version: ['3.0.1', '3.1.1']
data/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## [0.2.1] - 2022-05-29
2
+ - 入力表示機能を提供するSwitchProconInputViewerに対応しました
3
+ - https://github.com/splaplapla/switch-procon-input-viewer
4
+ - app.rb内のバグ修正, ログファイルとして残る世代を減らしました
5
+
6
+ ## [0.2.0] - 2022-05-20
7
+ - 3つ以上のボタンを操作するマクロに対応しました
8
+ - IOに関するログをデフォルトで無効にしました
9
+ - 有効にする場合はapp.rbに `config.io_monitor_logging = true` を記述してください
10
+ - 接続が安定化するまでの時間が短くなりました
11
+ - 接続中にプロコンのケーブルを抜くと、エラーを吐いて終了できなくなる不具合を修正しました
12
+ - プロセスをCtrl+Cで停止するときに終了するまでの時間が短くなりました
13
+ - 接続に成功するとhomeボタンのledが光るようになりました
14
+ - 無効にする場合はapp.rbに `config.enable_home_led_on_connect = false` を記述してください
15
+
16
+ ## [0.1.23] - 2022-05-04
17
+ - プロセスを停止するとプロコンがBluetooth経由でSwitchと接続するようになりました
18
+ - 起動時に表示するdevice_idを一部のみ表示するようになりました
19
+ - ライブリロードが不安定になっていたのを修正しました
20
+ - コントローラのバイブレーションを無効にしました
21
+ - プロセスを停止後、再接続しやすくなりました
22
+
1
23
  ## [0.1.22] - 2022-04-09
2
24
  * スティックを左右に入れるマクロが使えるようになりました
3
25
  * スプラトゥーン2でのタンサンボムのチャージに使えます
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- procon_bypass_man (0.1.22)
4
+ procon_bypass_man (0.2.1)
5
5
  action_cable_client
6
6
  pbmenv (>= 0.1.9)
7
7
  sorted_set
@@ -40,8 +40,8 @@ GEM
40
40
  pry (0.14.1)
41
41
  coderay (~> 1.1)
42
42
  method_source (~> 1.0)
43
- rack (2.2.3)
44
- rack-protection (2.1.0)
43
+ rack (2.2.3.1)
44
+ rack-protection (2.2.0)
45
45
  rack
46
46
  rainbow (3.0.0)
47
47
  rake (13.0.6)
@@ -79,10 +79,10 @@ GEM
79
79
  ruby-progressbar (1.11.0)
80
80
  ruby2_keywords (0.0.5)
81
81
  set (1.0.2)
82
- sinatra (2.1.0)
82
+ sinatra (2.2.0)
83
83
  mustermann (~> 1.0)
84
84
  rack (~> 2.2)
85
- rack-protection (= 2.1.0)
85
+ rack-protection (= 2.2.0)
86
86
  tilt (~> 2.0)
87
87
  sorted_set (1.0.3)
88
88
  rbtree
@@ -13,6 +13,7 @@
13
13
  * モード
14
14
  * [マクロ](#マクロ)
15
15
  * [左スティックの感度調整](#左スティックの感度調整)
16
+ * [入力表示](#入力表示)
16
17
  * 設定ファイルの書き方
17
18
  * プラグインの書き方
18
19
  * [設定ファイルの書き方がわからない、エラーが起きるとき](#設定ファイルの書き方がわからない、エラーが起きるとき)
@@ -39,6 +40,8 @@
39
40
  * [設定方法](/docs/setting/left-analogstick-cap.md)
40
41
  * WEBから設定状態の閲覧・反映
41
42
  * ボタンリマップ
43
+ * 入力表示
44
+   * https://github.com/splaplapla/switch-procon-input-viewer
42
45
 
43
46
  ## セットアップ
44
47
  ### ラズベリーパイのセットアップ
@@ -162,6 +165,10 @@ open_macro :sokuwari, steps: [:toggle_r_for_0_2sec, :toggle_thumbr_for_0_14sec,
162
165
  ## 左スティックの感度調整
163
166
  [左スティックの感度調整](/docs/setting/left-analogstick-cap.md)
164
167
 
168
+ ## 入力表示
169
+ * https://github.com/splaplapla/switch-procon-input-viewer
170
+ * 後で書きます
171
+
165
172
  ## 設定ファイルの書き方
166
173
  * 後で書きます
167
174
 
@@ -180,6 +187,7 @@ discordで質問してみてください。
180
187
  https://pbm-cloud.herokuapp.com/
181
188
  procon_bypass_man_cloudの運用をWEBで完結できるようになる無料のWEBサービスです。
182
189
 
183
- procon_bypass_man_cloudとの接続が完了後、Raspberry Piを起動時にprocon_bypass_man_cloudが自動で立ち上がるように設定すれば、Raspberry Piへのログインが不要で設定ファイルの変更やprocon_bypass_man_cloudのアップグレードができます。
190
+ procon_bypass_man_cloudとの接続が完了後、Raspberry Piを起動時にprocon_bypass_manが自動で立ち上がるように設定すれば、Raspberry Piへのログインが不要で設定ファイルの変更やprocon_bypass_man自体のアップグレードができます。
184
191
  セットアップ方法などでわからないことがあればdiscordで質問してみてください。
192
+
185
193
  セットアップ方法は https://pbm-cloud.herokuapp.com/faq に書いています。
data/docs/setup_raspi.md CHANGED
@@ -33,7 +33,6 @@ https://github.com/splaplapla/procon_bypass_man/blob/master/docs/setup_raspi_by_
33
33
  * chmod 755 ~/add_procon_gadget.sh
34
34
  * sudo reboot
35
35
  * sudo sh ~/add_procon_gadget.sh の実行に成功させる
36
- * /etc/rc.local に sh /home/pi/add_procon_gadget.sh って書く
37
36
  * cd ~ && mkdir -p src && cd ~/src && git clone https://github.com/jiikko/procon_bypass_man_sample && cd procon_bypass_man_sample
38
37
 
39
38
  おわり. 起動する時は都度 sudo ruby app.rb を実行する
@@ -32,7 +32,7 @@ module ProconBypassMan
32
32
  ProconBypassMan::ButtonsSettingConfiguration.instance.reset!
33
33
  ProconBypassMan.reset!
34
34
 
35
- yaml = YAML.load_file(setting_path)
35
+ yaml = ProconBypassMan::YamlLoader.load(path: setting_path)
36
36
  ProconBypassMan.config.raw_setting = yaml.dup
37
37
  case yaml["version"]
38
38
  when 1.0, nil
@@ -1,18 +1,23 @@
1
1
  class ProconBypassMan::BypassCommand
2
2
  include ProconBypassMan::SignalHandler
3
3
 
4
+ module WILL_TERMINATE_TOKEN
5
+ TERMINATE = :terminate
6
+ RESTART = :restart
7
+ end
8
+
4
9
  def initialize(gadget:, procon:)
5
10
  @gadget = gadget
6
11
  @procon = procon
7
12
 
8
- ProconBypassMan::IOMonitor.start!
13
+ ProconBypassMan::IOMonitor.start! if ProconBypassMan.io_monitor_logging
9
14
  ProconBypassMan::Background::JobRunner.queue.clear # forkしたときに残留物も移ってしまうため
10
15
  ProconBypassMan::Background::JobRunner.start!
11
16
  end
12
17
 
13
18
  def execute
14
19
  self_read, self_write = IO.pipe
15
- %w(TERM INT).each do |sig|
20
+ %w(TERM INT USR2).each do |sig|
16
21
  begin
17
22
  trap sig do
18
23
  self_write.puts(sig)
@@ -28,30 +33,22 @@ class ProconBypassMan::BypassCommand
28
33
  monitor2 = ProconBypassMan::IOMonitor.new(label: "procon -> switch")
29
34
  ProconBypassMan.logger.info "Thread1を起動します"
30
35
 
31
- @send_interval = 0.005
36
+ cycle_sleep = ProconBypassMan::CycleSleep.new(cycle_interval: 1, execution_cycle: ProconBypassMan.config.bypass_mode.gadget_to_procon_interval)
32
37
 
33
38
  t1 = Thread.new do
34
- timer = ProconBypassMan::SafeTimeout.new(timeout: Time.now + 10)
35
- @did_first_step = false
39
+ if ProconBypassMan.config.bypass_mode.mode == ProconBypassMan::BypassMode::TYPE_AGGRESSIVE
40
+ ProconBypassMan.logger.info "TYPE_AGGRESSIVEなのでThread1を終了します"
41
+ monitor1.shutdown
42
+ next
43
+ end
44
+
36
45
  loop do
37
- bypass = ProconBypassMan::Bypass.new(gadget: @gadget, procon: @procon, monitor: monitor1)
38
46
  break if $will_terminate_token
39
- !@did_first_step && timer.throw_if_timeout!
40
- bypass.send_gadget_to_procon!
41
- sleep(@send_interval)
42
- rescue ProconBypassMan::SafeTimeout::Timeout
43
- case ProconBypassMan.config.bypass_mode.mode
44
- when ProconBypassMan::BypassMode::TYPE_AGGRESSIVE
45
- ProconBypassMan.logger.info "10秒経過したのでThread1を終了します"
46
- monitor1.shutdown
47
- break
48
- when ProconBypassMan::BypassMode::TYPE_NORMAL
49
- ProconBypassMan.logger.info "10秒経過したのでsend_intervalを長くします"
50
- @send_interval = ProconBypassMan.config.bypass_mode.gadget_to_procon_interval
51
- else
52
- raise "unknown type"
47
+
48
+ cycle_sleep.sleep_or_execute do
49
+ bypass = ProconBypassMan::Bypass.new(gadget: @gadget, procon: @procon, monitor: monitor1)
50
+ bypass.send_gadget_to_procon!
53
51
  end
54
- @did_first_step = true
55
52
  rescue Errno::EIO, Errno::ENODEV, Errno::EPROTO, IOError, Errno::ESHUTDOWN => e
56
53
  ProconBypassMan::SendErrorCommand.execute(error: "Switchとの切断されました.終了処理を開始します. #{e.full_message}")
57
54
  Process.kill "TERM", Process.ppid
@@ -60,6 +57,7 @@ class ProconBypassMan::BypassCommand
60
57
  ProconBypassMan::SendErrorCommand.execute(error: "Switchと意図せず切断されました.終了処理を開始します. #{e.full_message}")
61
58
  Process.kill "TERM", Process.ppid
62
59
  end
60
+
63
61
  ProconBypassMan.logger.info "Thread1を終了します"
64
62
  end
65
63
 
@@ -69,14 +67,22 @@ class ProconBypassMan::BypassCommand
69
67
  t2 = Thread.new do
70
68
  bypass = ProconBypassMan::Bypass.new(gadget: @gadget, procon: @procon, monitor: monitor2)
71
69
  loop do
72
- break if $will_terminate_token
70
+ if $will_terminate_token
71
+ if $will_terminate_token == WILL_TERMINATE_TOKEN::TERMINATE
72
+ bypass.direct_connect_switch_via_bluetooth
73
+ end
74
+ break
75
+ end
76
+
73
77
  bypass.send_procon_to_gadget!
74
78
  rescue EOFError => e
75
79
  ProconBypassMan::SendErrorCommand.execute(error: "Proconが切断されました。終了処理を開始します. #{e.full_message}")
76
80
  Process.kill "TERM", Process.ppid
81
+ break
77
82
  rescue Errno::EIO, Errno::ENODEV, Errno::EPROTO, IOError, Errno::ESHUTDOWN => e
78
83
  ProconBypassMan::SendErrorCommand.execute(error: "Proconが切断されました。終了処理を開始します2. #{e.full_message}")
79
84
  Process.kill "TERM", Process.ppid
85
+ break
80
86
  end
81
87
  ProconBypassMan.logger.info "Thread2を終了します"
82
88
  end
@@ -87,12 +93,18 @@ class ProconBypassMan::BypassCommand
87
93
  signal = readable_io.first[0].gets.strip
88
94
  handle_signal(signal)
89
95
  end
96
+ rescue ProconBypassMan::Runner::InterruptForRestart
97
+ $will_terminate_token = WILL_TERMINATE_TOKEN::RESTART
98
+ [t1, t2].each(&:join)
99
+ @gadget&.close
100
+ @procon&.close
101
+ exit! 1 # child processなのでexitしていい
90
102
  rescue Interrupt
91
- $will_terminate_token = true
103
+ $will_terminate_token = WILL_TERMINATE_TOKEN::TERMINATE
92
104
  [t1, t2].each(&:join)
93
105
  @gadget&.close
94
106
  @procon&.close
95
- exit 1 # child processなのでexitしていい
107
+ exit! 1 # child processなのでexitしていい
96
108
  end
97
109
  end
98
110
  end
@@ -32,6 +32,9 @@ class ProconBypassMan::Bypass
32
32
  end
33
33
  end
34
34
 
35
+ # TODO 別のコールバッククラスから実行したい
36
+ ProconBypassMan::ProconDisplay::Status.instance.current = bypass_value.binary.to_procon_reader.to_hash.dup
37
+
35
38
  if ProconBypassMan.config.enable_reporting_pressed_buttons
36
39
  ProconBypassMan.cache.fetch key: 'pressed_buttons_reporter', expires_in: 5 do
37
40
  ProconBypassMan::ReportPressedButtonsJob.perform_async(
@@ -1,12 +1,15 @@
1
1
  require "procon_bypass_man/bypass/usb_hid_logger"
2
+ require "procon_bypass_man/bypass/bypass_command"
2
3
 
3
4
  class ProconBypassMan::Bypass
4
5
  include ProconBypassMan::Bypass::UsbHidLogger
6
+ # TODO callbackモジュールを修正して複数のメソッドをチェインできるようにする
7
+ # include ProconBypassMan::ProconDisplay::BypassCallback
5
8
 
6
- class BypassValue < Struct.new(:binary, :sent)
9
+ class BypassValue < Struct.new(:binary)
7
10
  def to_text
8
11
  return unless binary
9
- "#{binary.unpack.first} #{'x' unless sent}"
12
+ binary.unpack.first
10
13
  end
11
14
  end
12
15
 
@@ -21,23 +24,31 @@ class ProconBypassMan::Bypass
21
24
  # ゆっくりでいい
22
25
  def send_gadget_to_procon!
23
26
  monitor.record(:start_function)
24
- input = nil
25
- self.bypass_value = BypassValue.new(nil, sent = false)
27
+ self.bypass_value = BypassValue.new(nil)
26
28
 
27
29
  run_callbacks(:send_gadget_to_procon) do
30
+ break if $will_terminate_token
31
+
32
+ raw_input = nil
28
33
  begin
29
- break if $will_terminate_token
30
- # TODO blocking readにしたいが、接続時のフェーズによって長さが違うので厳しい
31
- input = self.gadget.read_nonblock(64)
32
- self.bypass_value.binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: input)
34
+ raw_input = self.gadget.read_nonblock(64)
35
+ self.bypass_value.binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: raw_input)
33
36
  rescue IO::EAGAINWaitReadable
34
37
  monitor.record(:eagain_wait_readable_on_read)
35
38
  end
36
39
 
37
- if input
40
+ if self.bypass_value.binary
38
41
  begin
39
- self.procon.write_nonblock(input)
40
- self.bypass_value.sent = true
42
+ raw_data =
43
+ case
44
+ when self.bypass_value.binary.rumble_data?
45
+ binary = ProconBypassMan::RumbleBinary.new(binary: self.bypass_value.binary.raw)
46
+ binary.noop!
47
+ binary.raw
48
+ else
49
+ self.bypass_value.binary.raw
50
+ end
51
+ self.procon.write_nonblock(raw_data)
41
52
  rescue IO::EAGAINWaitReadable
42
53
  monitor.record(:eagain_wait_readable_on_write)
43
54
  break
@@ -50,15 +61,15 @@ class ProconBypassMan::Bypass
50
61
 
51
62
  def send_procon_to_gadget!
52
63
  monitor.record(:start_function)
53
- output = nil
54
- self.bypass_value = BypassValue.new(nil, sent = false)
64
+ self.bypass_value = BypassValue.new(nil)
55
65
 
56
66
  run_callbacks(:send_procon_to_gadget) do
67
+ break if $will_terminate_token
68
+
57
69
  begin
58
- break if $will_terminate_token
59
70
  Timeout.timeout(1) do
60
- output = self.procon.read(64)
61
- self.bypass_value.binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: output)
71
+ raw_output = self.procon.read(64)
72
+ self.bypass_value.binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: raw_output)
62
73
  end
63
74
  rescue Timeout::Error
64
75
  ProconBypassMan.logger.debug { "read timeout! do sleep. by send_procon_to_gadget!" }
@@ -73,16 +84,10 @@ class ProconBypassMan::Bypass
73
84
  retry
74
85
  end
75
86
 
76
- # blocking readをしているのでnilが入ることはないが、雑なテストでnilが通るので分岐を入れる。できれば消したい
77
- break if output.nil?
78
-
79
87
  begin
80
88
  self.gadget.write_nonblock(
81
- ProconBypassMan::Processor.new(
82
- ProconBypassMan::Domains::InboundProconBinary.new(binary: output)
83
- ).process
89
+ ProconBypassMan::Processor.new(bypass_value.binary).process
84
90
  )
85
- self.bypass_value.sent = true
86
91
  rescue IO::EAGAINWaitReadable
87
92
  monitor.record(:eagain_wait_readable_on_write)
88
93
  break
@@ -90,4 +95,16 @@ class ProconBypassMan::Bypass
90
95
  end
91
96
  monitor.record(:end_function)
92
97
  end
98
+
99
+ # @return [void]
100
+ def direct_connect_switch_via_bluetooth
101
+ ProconBypassMan.logger.debug { "direct_connect_switch_via_bluetooth!" }
102
+ self.procon.write_nonblock(["010500000000000000003800"].pack("H*")) # home led off
103
+ self.procon.write_nonblock(["010600000000000000003800"].pack("H*")) # home led off
104
+ self.procon.write_nonblock(["010700000000000000003800"].pack("H*")) # home led off
105
+ self.procon.write_nonblock(["010800000000000000003800"].pack("H*")) # home led off
106
+ self.procon.write_nonblock(["8005"].pack("H*"))
107
+ self.procon.write_nonblock(["8005"].pack("H*"))
108
+ self.procon.write_nonblock(["8005"].pack("H*"))
109
+ end
93
110
  end
@@ -32,8 +32,8 @@ class ProconBypassMan::PrintBootMessageCommand
32
32
  def to_s
33
33
  booted_message = <<~EOF
34
34
  ----
35
- RUBY_VERSION: #{@table[:ruby_version]}
36
35
  ProconBypassMan::VERSION: #{@table[:pbm_version]}
36
+ RUBY_VERSION: #{@table[:ruby_version]}
37
37
  Pbmenv::VERSION: #{@table[:pbmenv_version]}
38
38
  pid: #{@table[:pid]}
39
39
  root: #{@table[:root_path]}
@@ -42,7 +42,7 @@ class ProconBypassMan::PrintBootMessageCommand
42
42
  uptime from boot: #{@table[:uptime_from_boot]} sec
43
43
  use_pbmenv: #{@table[:use_pbmenv]}
44
44
  session_id: #{ProconBypassMan.session_id}
45
- device_id: #{ProconBypassMan.device_id}
45
+ device_id: #{ProconBypassMan.device_id.gsub(/.{25}$/, "*"*25)}
46
46
  bypass_mode: #{ProconBypassMan.config.bypass_mode}
47
47
  ----
48
48
  EOF
@@ -58,7 +58,6 @@ class ProconBypassMan::PrintBootMessageCommand
58
58
  def self.execute
59
59
  message = BootMessage.new
60
60
  ProconBypassMan::ReportBootJob.perform_async(message.to_hash)
61
- ProconBypassMan::ReportLoadConfigJob.perform_async(ProconBypassMan.config.raw_setting)
62
61
  puts message.to_s
63
62
  end
64
63
  end
@@ -1,7 +1,7 @@
1
1
  class ProconBypassMan::SendErrorCommand
2
2
  # @param [String, Hash, Exception] error
3
3
  # @return [void]
4
- def self.execute(error: )
4
+ def self.execute(error: , stdout: true)
5
5
  body =
6
6
  case error
7
7
  when String, Hash
@@ -12,7 +12,7 @@ class ProconBypassMan::SendErrorCommand
12
12
 
13
13
  ProconBypassMan.logger.error body
14
14
  ProconBypassMan.error_logger.error body
15
- puts body
15
+ puts body if stdout
16
16
 
17
17
  ProconBypassMan::ReportErrorJob.perform(error)
18
18
  end
@@ -4,6 +4,3 @@ require "procon_bypass_man/commands/write_session_id_command"
4
4
  require "procon_bypass_man/commands/write_device_id_command"
5
5
  require "procon_bypass_man/commands/send_reload_config_event_command"
6
6
  require "procon_bypass_man/commands/send_error_command"
7
- require "procon_bypass_man/commands/connect_device_command"
8
- require "procon_bypass_man/commands/bypass_command"
9
- require "procon_bypass_man/commands/run_remote_pbm_action_dispatch_command"
@@ -47,10 +47,14 @@ class ProconBypassMan::Configuration
47
47
  def fallback_setting_path
48
48
  "/tmp/procon_bypass_man_fallback_setting.yaml"
49
49
  end
50
+
51
+ def io_monitor_logging
52
+ config.io_monitor_logging
53
+ end
50
54
  end
51
55
 
52
56
  attr_accessor :enable_critical_error_logging
53
- attr_writer :verbose_bypass_log, :raw_setting, :enable_reporting_pressed_buttons, :never_exit_accidentally
57
+ attr_writer :verbose_bypass_log, :raw_setting, :enable_reporting_pressed_buttons, :never_exit_accidentally, :io_monitor_logging, :enable_home_led_on_connect
54
58
 
55
59
  def root=(path)
56
60
  @root = path
@@ -100,7 +104,7 @@ class ProconBypassMan::Configuration
100
104
 
101
105
  def error_logger
102
106
  if enable_critical_error_logging
103
- @error_logger ||= Logger.new("#{ProconBypassMan.root}/error.log", 5, 1024 * 1024 * 10)
107
+ @error_logger ||= Logger.new("#{ProconBypassMan.root}/error.log", 1, 1024 * 1024 * 1)
104
108
  else
105
109
  Logger.new(File.open("/dev/null"))
106
110
  end
@@ -186,12 +190,27 @@ class ProconBypassMan::Configuration
186
190
  @raw_setting ||= {}
187
191
  end
188
192
 
193
+ # @return [Boolean] default false
189
194
  def enable_reporting_pressed_buttons
190
195
  @enable_reporting_pressed_buttons ||= false
191
196
  end
192
197
 
193
- # @return [Boolean]
198
+ # @return [Boolean] default false
194
199
  def never_exit_accidentally
195
200
  @never_exit_accidentally || false
196
201
  end
202
+
203
+ # @return [Boolean] default false
204
+ def io_monitor_logging
205
+ @io_monitor_logging ||= false
206
+ end
207
+
208
+ # @return [Boolean] default true
209
+ def enable_home_led_on_connect
210
+ if defined?(@enable_home_led_on_connect)
211
+ return @enable_home_led_on_connect
212
+ else
213
+ true
214
+ end
215
+ end
197
216
  end
@@ -0,0 +1,28 @@
1
+ class ProconBypassMan::DeviceConnection::Command
2
+ MAX_RETRY_COUNT = 3
3
+
4
+ # @return [void]
5
+ def self.execute!(retry_count: 0)
6
+ begin
7
+ gadget, procon = ProconBypassMan::DeviceConnection::Executer.execute!
8
+ rescue ProconBypassMan::DeviceConnection::TimeoutErrorInConditionalRoute
9
+ if retry_count >= MAX_RETRY_COUNT
10
+ ProconBypassMan::SendErrorCommand.execute(error: "リトライしましたが、接続できませんでした")
11
+ raise ProconBypassMan::DeviceConnection::TimeoutError
12
+ else
13
+ ProconBypassMan::SendErrorCommand.execute(error: "接続に失敗したのでリトライします")
14
+ end
15
+
16
+ retry_count = retry_count + 1
17
+ retry
18
+ rescue ProconBypassMan::DeviceConnection::NotFoundProconError => e
19
+ raise
20
+ rescue ProconBypassMan::SafeTimeout::Timeout
21
+ raise ProconBypassMan::DeviceConnection::TimeoutError
22
+ end
23
+
24
+ ProconBypassMan::DeviceConnection::PreBypass.new(gadget: gadget, procon: procon).execute!
25
+ ProconBypassMan::DeviceConnection::ProconSettingOverrider.new(procon: procon).execute!
26
+ return [gadget, procon]
27
+ end
28
+ end