procon_bypass_man 0.1.13 → 0.1.16.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +33 -0
  3. data/CHANGELOG.md +13 -0
  4. data/Gemfile.lock +26 -6
  5. data/README.md +27 -3
  6. data/docs/setup_raspi.md +2 -0
  7. data/docs/setup_raspi.mitamae.rb +7 -8
  8. data/docs/setup_raspi_by_mitamae.md +37 -1
  9. data/lib/ext/em_pure_ruby.rb +25 -0
  10. data/lib/procon_bypass_man/background/jobs/base_job.rb +1 -6
  11. data/lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb +5 -0
  12. data/lib/procon_bypass_man/background/jobs/concerns/has_internal_api_setting.rb +5 -0
  13. data/lib/procon_bypass_man/background/{job_runnable.rb → jobs/concerns/job_runnable.rb} +0 -0
  14. data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +5 -3
  15. data/lib/procon_bypass_man/background/jobs/report_error_job.rb +6 -5
  16. data/lib/procon_bypass_man/background/jobs/report_event_base_job.rb +5 -0
  17. data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +5 -4
  18. data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +7 -10
  19. data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +5 -4
  20. data/lib/procon_bypass_man/background/jobs/sync_device_stats_job.rb +16 -0
  21. data/lib/procon_bypass_man/background.rb +5 -4
  22. data/lib/procon_bypass_man/buttons_setting_configuration/layer.rb +2 -6
  23. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +6 -8
  24. data/lib/procon_bypass_man/bypass.rb +13 -6
  25. data/lib/procon_bypass_man/commands/connect_device_command.rb +6 -1
  26. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +50 -1
  27. data/lib/procon_bypass_man/commands/print_message_command.rb +8 -0
  28. data/lib/procon_bypass_man/commands/run_remote_pbm_action_dispatch_command.rb +21 -0
  29. data/lib/procon_bypass_man/commands/send_error_command.rb +1 -1
  30. data/lib/procon_bypass_man/commands/send_reload_config_event_command.rb +1 -2
  31. data/lib/procon_bypass_man/commands/write_session_id_command.rb +1 -7
  32. data/lib/procon_bypass_man/commands.rb +2 -0
  33. data/lib/procon_bypass_man/configuration.rb +49 -2
  34. data/lib/procon_bypass_man/device_connector.rb +2 -1
  35. data/lib/procon_bypass_man/device_status.rb +44 -0
  36. data/lib/procon_bypass_man/domains/binary/base.rb +11 -0
  37. data/lib/procon_bypass_man/domains/binary/has_immutable_binary.rb +5 -0
  38. data/lib/procon_bypass_man/domains/binary/has_mutable_binary.rb +5 -0
  39. data/lib/procon_bypass_man/domains/binary/inbound_procon_binary.rb +23 -0
  40. data/lib/procon_bypass_man/domains/binary/processing_procon_binary.rb +80 -0
  41. data/lib/procon_bypass_man/domains.rb +11 -0
  42. data/lib/procon_bypass_man/plugin/splatoon2/macro/fast_return.rb +17 -0
  43. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_left_key.rb +17 -0
  44. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_right_key.rb +17 -0
  45. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_up_key.rb +17 -0
  46. data/lib/procon_bypass_man/plugin/splatoon2/mode/guruguru.rb +59 -0
  47. data/lib/procon_bypass_man/plugin/splatoon2/version.rb +9 -0
  48. data/lib/procon_bypass_man/plugins.rb +11 -0
  49. data/lib/procon_bypass_man/processor.rb +4 -5
  50. data/lib/procon_bypass_man/procon/button.rb +11 -0
  51. data/lib/procon_bypass_man/procon/button_collection.rb +2 -12
  52. data/lib/procon_bypass_man/procon/layer_changer.rb +3 -2
  53. data/lib/procon_bypass_man/procon/press_button_aware.rb +5 -4
  54. data/lib/procon_bypass_man/procon/user_operation.rb +46 -63
  55. data/lib/procon_bypass_man/procon/{analog_stick.rb → value_objects/analog_stick.rb} +3 -4
  56. data/lib/procon_bypass_man/procon/value_objects/procon_reader.rb +34 -0
  57. data/lib/procon_bypass_man/procon.rb +16 -14
  58. data/lib/procon_bypass_man/remote_pbm_action/base_action.rb +53 -0
  59. data/lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb +25 -0
  60. data/lib/procon_bypass_man/remote_pbm_action/commands/update_remote_pbm_action_status_command.rb +24 -0
  61. data/lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb +21 -0
  62. data/lib/procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb +28 -0
  63. data/lib/procon_bypass_man/remote_pbm_action/stop_pbm_action.rb +21 -0
  64. data/lib/procon_bypass_man/remote_pbm_action/value_objects/remote_pbm_action_object.rb +38 -0
  65. data/lib/procon_bypass_man/remote_pbm_action.rb +32 -0
  66. data/lib/procon_bypass_man/runner.rb +4 -4
  67. data/lib/procon_bypass_man/scheduler.rb +85 -0
  68. data/lib/procon_bypass_man/support/http_client.rb +102 -0
  69. data/lib/procon_bypass_man/support/report_http_client.rb +19 -0
  70. data/lib/procon_bypass_man/support/send_device_stats_http_client.rb +9 -0
  71. data/lib/procon_bypass_man/{background/has_server_pool.rb → support/server_pool.rb} +3 -15
  72. data/lib/procon_bypass_man/support/update_remote_pbm_action_status_http_client.rb +9 -0
  73. data/lib/procon_bypass_man/version.rb +1 -1
  74. data/lib/procon_bypass_man/websocket/pbm_job_client.rb +79 -0
  75. data/lib/procon_bypass_man.rb +60 -31
  76. data/procon_bypass_man.gemspec +3 -1
  77. data/project_template/README.md +10 -5
  78. data/project_template/app.rb +1 -1
  79. data/project_template/setting.yml +8 -8
  80. data/sig/main.rbs +16 -1
  81. metadata +90 -21
  82. data/lib/procon_bypass_man/background/http_client.rb +0 -67
  83. data/lib/procon_bypass_man/background/jobs/report_heartbeat_job.rb +0 -10
  84. data/lib/procon_bypass_man/boot_message.rb +0 -44
  85. data/lib/procon_bypass_man/procon_reader.rb +0 -31
  86. data/lib/procon_bypass_man/splatoon2/macro/fast_return.rb +0 -15
  87. data/lib/procon_bypass_man/splatoon2/macro/jump_to_left_key.rb +0 -15
  88. data/lib/procon_bypass_man/splatoon2/macro/jump_to_right_key.rb +0 -15
  89. data/lib/procon_bypass_man/splatoon2/macro/jump_to_up_key.rb +0 -15
  90. data/lib/procon_bypass_man/splatoon2/mode/guruguru.rb +0 -57
  91. data/lib/procon_bypass_man/splatoon2/version.rb +0 -7
  92. data/lib/procon_bypass_man/splatoon2.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62fab79bffee3adf43af06325d7ef6bce2060f844d8caaa824968ff77219e5de
4
- data.tar.gz: c15ab8b50da926169727b9af5ff097585cd35c7e24fdf2ce75d2ca7d4fe5f07e
3
+ metadata.gz: 5af6fb77bbbd2aca55c93c8af1bb9c72ede43a043f069001b30201bf8352e7de
4
+ data.tar.gz: 5607eb2f41d4a09de6e7e04cb8afcf998c09d790931ed105dbe5136c7160698a
5
5
  SHA512:
6
- metadata.gz: c94bc5e37b89c54a31fe165e53f84ac32c1b4d10fc617cc1397e0347baf1a39206fd50aff3a65626b8546545d00f33ac0e44a90da5ff25c02778d27e60aafe0f
7
- data.tar.gz: 7ad56ef9e17bb8a26d840003faf8fa7d065ba878182dcd23d66118b43053c2827221814f37bb4098174cdfbcc449486d895bf6431520f60ce295a4e7382c39e7
6
+ metadata.gz: f21c116b2d69b79a2c896cd8c1298a1e80d82c2c879e0e0db328b64f9abb19901da93edd0a88d64314413092bfafead55a9ab359f9e09a2546794812178701e1
7
+ data.tar.gz: 89d32cbe122d38ad19d55481539a05cfad959695d46c29d2dc6db8ac34eb251a2f2f49d7ab36f5d514e191751ba19f747dd13e5a21fd4cde4ae435a93ce117de
@@ -0,0 +1,33 @@
1
+ name: Publish to RubyGems
2
+
3
+ on:
4
+ [workflow_dispatch]
5
+
6
+ jobs:
7
+ release:
8
+ runs-on: ubuntu-latest
9
+ permissions:
10
+ contents: write
11
+
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ with:
15
+ token: ${{ secrets.GITHUB_TOKEN }}
16
+ - name: Set up Ruby 2.6
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.6
20
+ bundler-cache: true
21
+ - name: Publish to RubyGems
22
+ run: |
23
+ git config --local user.email "action@github.com"
24
+ git config --local user.name "GitHub Action"
25
+
26
+ mkdir -p $HOME/.gem
27
+ touch $HOME/.gem/credentials
28
+ chmod 0600 $HOME/.gem/credentials
29
+ printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_TOKEN}\n" > $HOME/.gem/credentials
30
+ bundle exec rake release
31
+ env:
32
+ RUBYGEMS_API_TOKEN: "${{secrets.RUBYGEMS_API_TOKEN}}"
33
+ GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## [0.1.16.1] - 2022-01-22
2
+ - 初期状態ではinternal api(pbm-web)の通信を無効にしました
3
+
4
+ ## [0.1.16] - 2021-12-26
5
+ - websocket経由で外部サーバからの命令を受け取れるようになりました
6
+
7
+ ## [0.1.15] - 2021-12-08
8
+ - 外部サーバから設定ファイルのリストアができるようになりました
9
+ - splatoon2 pluginのネームスペースを変更しました
10
+
11
+ ## [0.1.14] - 2021-12-02
12
+ - 外部サーバからOSの再起動やprocon_bypass_manのバージョンアップができるようになりました
13
+
1
14
  ## [0.1.13] - 2021-11-24
2
15
  - 起動を早くするために、procon_bypass_man-splatoon2を同梱しました
3
16
 
data/Gemfile.lock CHANGED
@@ -1,11 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- procon_bypass_man (0.1.13)
4
+ procon_bypass_man (0.1.16.1)
5
+ action_cable_client
6
+ pbmenv
7
+ sorted_set
5
8
 
6
9
  GEM
7
10
  remote: https://rubygems.org/
8
11
  specs:
12
+ action_cable_client (3.1.0)
13
+ websocket-eventmachine-client (>= 1.2.0)
9
14
  activesupport (6.1.4.1)
10
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
11
16
  i18n (>= 1.6, < 2)
@@ -16,6 +21,7 @@ GEM
16
21
  coderay (1.1.3)
17
22
  concurrent-ruby (1.1.9)
18
23
  diff-lcs (1.4.4)
24
+ eventmachine (1.2.7)
19
25
  ffi (1.15.4)
20
26
  i18n (1.8.11)
21
27
  concurrent-ruby (~> 1.0)
@@ -28,8 +34,9 @@ GEM
28
34
  mustermann (1.1.1)
29
35
  ruby2_keywords (~> 0.0.1)
30
36
  parallel (1.21.0)
31
- parser (3.0.2.0)
37
+ parser (3.0.3.2)
32
38
  ast (~> 2.4.1)
39
+ pbmenv (0.1.7)
33
40
  pry (0.14.1)
34
41
  coderay (~> 1.1)
35
42
  method_source (~> 1.0)
@@ -42,7 +49,8 @@ GEM
42
49
  rb-inotify (0.10.1)
43
50
  ffi (~> 1.0)
44
51
  rbs (1.7.1)
45
- regexp_parser (2.1.1)
52
+ rbtree (0.4.4)
53
+ regexp_parser (2.2.0)
46
54
  rexml (3.2.5)
47
55
  rspec (3.10.0)
48
56
  rspec-core (~> 3.10.0)
@@ -66,23 +74,27 @@ GEM
66
74
  rubocop-ast (>= 1.12.0, < 2.0)
67
75
  ruby-progressbar (~> 1.7)
68
76
  unicode-display_width (>= 1.4.0, < 3.0)
69
- rubocop-ast (1.13.0)
77
+ rubocop-ast (1.14.0)
70
78
  parser (>= 3.0.1.1)
71
79
  ruby-progressbar (1.11.0)
72
80
  ruby2_keywords (0.0.5)
81
+ set (1.0.2)
73
82
  sinatra (2.1.0)
74
83
  mustermann (~> 1.0)
75
84
  rack (~> 2.2)
76
85
  rack-protection (= 2.1.0)
77
86
  tilt (~> 2.0)
78
- steep (0.46.0)
87
+ sorted_set (1.0.3)
88
+ rbtree
89
+ set (~> 1.0)
90
+ steep (0.47.0)
79
91
  activesupport (>= 5.1)
80
92
  language_server-protocol (>= 3.15, < 4.0)
81
93
  listen (~> 3.0)
82
94
  parallel (>= 1.0.0)
83
95
  parser (>= 3.0)
84
96
  rainbow (>= 2.2.2, < 4.0)
85
- rbs (>= 1.2.0)
97
+ rbs (~> 1.7.0)
86
98
  terminal-table (>= 2, < 4)
87
99
  terminal-table (3.0.2)
88
100
  unicode-display_width (>= 1.1.1, < 3)
@@ -92,6 +104,14 @@ GEM
92
104
  concurrent-ruby (~> 1.0)
93
105
  unicode-display_width (2.1.0)
94
106
  webrick (1.7.0)
107
+ websocket (1.2.9)
108
+ websocket-eventmachine-base (1.2.0)
109
+ eventmachine (~> 1.0)
110
+ websocket (~> 1.0)
111
+ websocket-native (~> 1.0)
112
+ websocket-eventmachine-client (1.3.0)
113
+ websocket-eventmachine-base (~> 1.0)
114
+ websocket-native (1.0.0)
95
115
  zeitwerk (2.5.1)
96
116
 
97
117
  PLATFORMS
data/README.md CHANGED
@@ -28,12 +28,30 @@ 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 で sudo pbmenv install latest && cd /usr/share/pbm/current && sudo ruby app.rb
31
+ * Raspberry Pi4 でprocon_bypass_manを実行するための準備
32
+ * rubyのインストール
33
+ * sudo apt-get install rbenv
34
+ * git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
35
+ * rbenv install 3.0.1
36
+ * sudo gem install pbmenv
37
+ * sudo [pbmenv](https://github.com/splaplapla/pbmenv) install latest
38
+ * Raspberry Pi4 でprocon_bypass_manを実行する
39
+ * cd /usr/share/pbm/current
40
+ * sudo /home/pi/.rbenv/versions/3.0.1/bin/ruby app.rb
32
41
  * 動いたのを確認したらserviceとして登録にするなどしてください
42
+ * [serviceとして登録する方法](https://github.com/splaplapla/procon_bypass_man/tree/master/project_template#systemd%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6%E3%82%B5%E3%83%BC%E3%83%93%E3%82%B9%E3%81%AB%E7%99%BB%E9%8C%B2%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95)
33
43
 
34
44
  ## Plugins
35
45
  * https://github.com/splaplapla/procon_bypass_man-splatoon2
36
46
 
47
+ ## 関連ソフトウェア
48
+ * サーバソフトウェア(WIP)
49
+ * https://github.com/splaplapla/procon_bypass_man_cloud
50
+ * このサーバからOS自体の再起動、設定ファイルの変更、PBMのバージョンアップができます
51
+ * 自分でホストティングしてください
52
+ * pbmenv
53
+ * バージョンマネージャー
54
+
37
55
  ## FAQ
38
56
  * どうやって動かすの?
39
57
  * このツールはRaspberry Pi4をUSBガジェットモードで起動して有線でプロコンとSwitchに接続して使います
@@ -46,6 +64,8 @@ Switch <-- (PBM): ZR連打
46
64
  * マクロは特定のキーを順番に入れていく機能。キーの入力が終わったらマクロは終了する
47
65
  * レイヤーとは?
48
66
  * 自作キーボードみたいな感じでレイヤー毎に設定内容を記述して切り替えれる
67
+ * レイヤーを切り替える方法は?
68
+ * 設定ファイルに記述している `prefix_keys_for_changing_layer`の後ろにあるキーを同時押しながら、十字キーのどれかを押すことで任意のレイヤーに切り替わります
49
69
  * このツールでできることは?
50
70
  * キーリマップ, 連射, マクロ, 特定の同じ操作の繰り返し(mode)
51
71
  * リマップは1つのキーを別のキーに割り当てます
@@ -54,6 +74,10 @@ Switch <-- (PBM): ZR連打
54
74
  * 操作するdeviceファイルの所有者がrootだから
55
75
  * 市販されているサードパーティ製連射機との違いは?
56
76
  * サードパーティ製のコントローラーは、設定方法や形状が特殊で買い換えるたびに学習・設定コストが発生します。本ツールを使えば、設定内容はテキストで管理することができ、使い慣れたプロコンで同等のことができます。
77
+ * sshなしで運用は可能ですか?
78
+ * 後述するWEBアプリケーションを使えば、sshを使わずに運用が可能です
79
+ * https://github.com/splaplapla/procon_bypass_man_cloud
80
+ * 機能開発中ですが、使ってくれる人を探しているのでdiscordからお問合せください
57
81
 
58
82
  ## TODO
59
83
  * レコーディング機能(プロコンの入力をマクロとして登録ができる)
@@ -67,7 +91,7 @@ sudo kill -USR2 `cat ./pbm_pid`
67
91
  ```
68
92
 
69
93
  ### 起動ログをサーバに送信する
70
- * `ProconBypassMan.api_server = "http://.."` を設定すると、 `POST /api/events` に対して起動ログなどを送信するようになります
94
+ * `ProconBypassMan.api_servers = "http://.."` を設定すると、 `POST /api/events` に対して起動ログなどを送信するようになります
71
95
 
72
96
  ### 開発環境でログの送信を確認する方法
73
97
  * `bundle exec bin/dev_api_server.rb`
@@ -83,6 +107,6 @@ sudo kill -USR2 `cat ./pbm_pid`
83
107
 
84
108
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
85
109
 
86
-
87
110
  ## Links
88
111
  * https://discord.gg/bEcRNKf4ep
112
+ * 質問などご意見をdiscordでも受け付けています
data/docs/setup_raspi.md CHANGED
@@ -1,3 +1,5 @@
1
+ https://github.com/splaplapla/procon_bypass_man/blob/master/docs/setup_raspi_by_mitamae.md に半自動化した手順があります
2
+
1
3
  # Raspberry Pi4のセットアップ手順
2
4
  * SDカードにRaspberry Pi OS (32-bit)を焼く
3
5
  * SDカードをRaspberry Pi4本体に挿して起動する
@@ -1,6 +1,6 @@
1
1
  run_command "apt-get update"
2
2
 
3
- package 'ruby' do
3
+ package 'rbenv' do
4
4
  action :install
5
5
  end
6
6
 
@@ -41,16 +41,15 @@ execute "Initialize PBM" do
41
41
  SHELL
42
42
  end
43
43
 
44
- # rbenv
45
- execute "Install rbenv" do
46
- not_if "which rbenv"
47
- command "git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build"
48
- end
49
-
50
44
  # ruby
51
45
  execute "Install ruby" do
46
+ user "pi"
52
47
  not_if "rbenv versions | grep 3.0.1"
53
- command "rbenv install 3.0.1"
48
+ command <<~EOH
49
+ mkdir -p "$(rbenv root)"/plugins
50
+ git clone https://github.com/rbenv/ruby-build.git --depth 1 "$(rbenv root)"/plugins/ruby-build
51
+ rbenv install 3.0.1
52
+ EOH
54
53
  end
55
54
 
56
55
  run_command 'sudo systemctl disable triggerhappy.socket'
@@ -1,9 +1,11 @@
1
+ セットアップ手順を半自動化にしました
2
+
1
3
  # Raspberry Pi4のセットアップ手順 With mitamae
2
4
  * SDカードにRaspberry Pi OS lite (32-bit)を焼く
3
5
  * sshをできる状態で焼いておく
4
6
  * SDカードをRaspberry Pi4本体に挿して起動する
5
7
  * sshする
6
- * curl -L https://github.com/itamae-kitchen/mitamae/releases/latest/download/mitamae-armhf-linux.tar.gz | tar xvz
8
+ * wget -O - "https://github.com/itamae-kitchen/mitamae/releases/latest/download/mitamae-armhf-linux.tar.gz" | tar xvz
7
9
  * wget https://raw.githubusercontent.com/splaplapla/procon_bypass_man/master/docs/setup_raspi.mitamae.rb -O setup_raspi.mitamae.rb
8
10
  * sudo ./mitamae-armhf-linux local setup_raspi.mitamae.rb -l debug
9
11
  * sudo reboot
@@ -12,3 +14,37 @@
12
14
  * PCとRaspberry Pi4を接続し、プロコンとして認識していることを確認する
13
15
  * sudo gem i pbmenv
14
16
  * sudo pbmenv install latest
17
+
18
+ ## 上記手順の動作確認方法
19
+ * 使えそうなイメージ
20
+ * navikey/raspbian-bullseye
21
+ * balenalib/raspberry-pi
22
+
23
+ ```shell
24
+ docker run -it --rm --name my-running-app2 navikey/raspbian-bullseye bash
25
+ ```
26
+
27
+ ### 準備
28
+ * docker runするとrootなのでpiでログインする
29
+
30
+ ```shell
31
+ useradd -m --uid 1000 --groups sudo pi
32
+ echo pi:pi | chpasswd
33
+ su pi
34
+ cd ~ && sudo ls
35
+ ```
36
+
37
+ ### mitamaeスクリプトを実行する
38
+
39
+ ```
40
+ wget -O - "https://github.com/itamae-kitchen/mitamae/releases/latest/download/mitamae-armhf-linux.tar.gz" | tar xvz
41
+ wget https://raw.githubusercontent.com/splaplapla/procon_bypass_man/master/docs/setup_raspi.mitamae.rb -O setup_raspi.mitamae.rb
42
+ sudo ./mitamae-armhf-linux local setup_raspi.mitamae.rb -l debug
43
+ ```
44
+
45
+ 実行に成功したら以下を確認する
46
+
47
+ * /home/pi/.rbenv/verions に ruby3.0.1がインストールしていること
48
+ * /etc/modules に指定の文字列があること
49
+ * /boot/config.txt に指定の文字列があること
50
+ * /usr/share/pbm/shared/add_procon_gadget.sh が存在していること
@@ -0,0 +1,25 @@
1
+ # https://github.com/eventmachine/eventmachine/pull/929 is not released yet.
2
+ # i will delete this patch if released.
3
+ module EventMachine
4
+ # @private
5
+ class Reactor
6
+ def run_timers
7
+ timers_to_delete = []
8
+ @timers.each {|t|
9
+ if t.first <= @current_loop_time
10
+ #@timers.delete t
11
+ timers_to_delete << t
12
+ EventMachine::event_callback "", TimerFired, t.last
13
+ else
14
+ break
15
+ end
16
+ }
17
+ timers_to_delete.map{|c| @timers.delete c}
18
+ timers_to_delete = nil
19
+ #while @timers.length > 0 and @timers.first.first <= now
20
+ # t = @timers.shift
21
+ # EventMachine::event_callback "", TimerFired, t.last
22
+ #end
23
+ end
24
+ end
25
+ end
@@ -1,12 +1,7 @@
1
1
  class ProconBypassMan::BaseJob
2
- extend ProconBypassMan::Background::HasServerPool
3
2
  extend ProconBypassMan::Background::JobRunnable
4
3
 
5
4
  def self.servers
6
- ProconBypassMan.config.api_servers
7
- end
8
-
9
- def self.path
10
- "/api/events"
5
+ raise NotImplementedError
11
6
  end
12
7
  end
@@ -0,0 +1,5 @@
1
+ module ProconBypassMan::HasExternalApiSetting
2
+ def server_pool
3
+ ProconBypassMan.config.server_pool
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module ProconBypassMan::HasInternalApiSetting
2
+ def server_pool
3
+ ProconBypassMan.config.internal_server_pool
4
+ end
5
+ end
@@ -1,9 +1,11 @@
1
- class ProconBypassMan::ReportBootJob < ProconBypassMan::BaseJob
1
+ class ProconBypassMan::ReportBootJob < ProconBypassMan::ReportEventBaseJob
2
+ extend ProconBypassMan::HasExternalApiSetting
3
+
2
4
  # @param [String] body
3
5
  def self.perform(body)
4
- ProconBypassMan::Background::HttpClient.new(
6
+ ProconBypassMan::ReportHttpClient.new(
5
7
  path: path,
6
- pool_server: pool_server,
8
+ server_pool: server_pool,
7
9
  retry_on_connection_error: true,
8
10
  ).post(body: body, event_type: :boot)
9
11
  end
@@ -1,10 +1,11 @@
1
- class ProconBypassMan::ReportErrorJob < ProconBypassMan::BaseJob
1
+ class ProconBypassMan::ReportErrorJob < ProconBypassMan::ReportEventBaseJob
2
+ extend ProconBypassMan::HasExternalApiSetting
3
+
2
4
  # @param [String] body
3
5
  def self.perform(body)
4
- ProconBypassMan::Background::HttpClient.new(
6
+ ProconBypassMan::ReportHttpClient.new(
5
7
  path: path,
6
- pool_server: pool_server,
7
- retry_on_connection_error: false,
8
- ).post(body: body, event_type: :error,)
8
+ server_pool: server_pool,
9
+ ).post(body: body, event_type: :error)
9
10
  end
10
11
  end
@@ -0,0 +1,5 @@
1
+ class ProconBypassMan::ReportEventBaseJob < ProconBypassMan::BaseJob
2
+ def self.path
3
+ "/api/events".freeze
4
+ end
5
+ end
@@ -1,10 +1,11 @@
1
- class ProconBypassMan::ReportLoadConfigJob < ProconBypassMan::BaseJob
1
+ class ProconBypassMan::ReportLoadConfigJob < ProconBypassMan::ReportEventBaseJob
2
+ extend ProconBypassMan::HasExternalApiSetting
3
+
2
4
  # @param [String] body
3
5
  def self.perform(body)
4
- ProconBypassMan::Background::HttpClient.new(
6
+ ProconBypassMan::ReportHttpClient.new(
5
7
  path: path,
6
- pool_server: pool_server,
7
- retry_on_connection_error: false,
8
+ server_pool: server_pool,
8
9
  ).post(body: body, event_type: :load_config)
9
10
  end
10
11
  end
@@ -1,18 +1,15 @@
1
- class ProconBypassMan::ReportPressedButtonsJob
2
- extend ProconBypassMan::Background::HasServerPool
3
- extend ProconBypassMan::Background::JobRunnable
4
-
5
- PATH = "/api/pressed_buttons"
1
+ class ProconBypassMan::ReportPressedButtonsJob < ProconBypassMan::BaseJob
2
+ extend ProconBypassMan::HasInternalApiSetting
6
3
 
7
4
  # @param [String] body
8
5
  def self.perform(body)
9
- ProconBypassMan::Background::HttpClient.new(
10
- path: PATH,
11
- pool_server: pool_server,
6
+ ProconBypassMan::ReportHttpClient.new(
7
+ path: path,
8
+ server_pool: server_pool,
12
9
  ).post(body: body, event_type: :internal)
13
10
  end
14
11
 
15
- def self.servers
16
- ProconBypassMan.config.internal_api_servers
12
+ def self.path
13
+ "/api/pressed_buttons"
17
14
  end
18
15
  end
@@ -1,10 +1,11 @@
1
- class ProconBypassMan::ReportReloadConfigJob < ProconBypassMan::BaseJob
1
+ class ProconBypassMan::ReportReloadConfigJob < ProconBypassMan::ReportEventBaseJob
2
+ extend ProconBypassMan::HasExternalApiSetting
3
+
2
4
  # @param [String] body
3
5
  def self.perform(body)
4
- ProconBypassMan::Background::HttpClient.new(
6
+ ProconBypassMan::ReportHttpClient.new(
5
7
  path: path,
6
- pool_server: pool_server,
7
- retry_on_connection_error: false,
8
+ server_pool: server_pool,
8
9
  ).post(body: body, event_type: :reload_config)
9
10
  end
10
11
  end
@@ -0,0 +1,16 @@
1
+ class ProconBypassMan::SyncDeviceStatsJob < ProconBypassMan::BaseJob
2
+ extend ProconBypassMan::HasExternalApiSetting
3
+
4
+ # @param [Symbol] status
5
+ def self.perform(status)
6
+ ProconBypassMan::SendDeviceStatsHttpClient.new(
7
+ path: path,
8
+ server_pool: server_pool,
9
+ ).post(status: status, pbm_session_id: ProconBypassMan.session_id)
10
+ end
11
+
12
+ def self.path
13
+ device_id = ProconBypassMan.device_id
14
+ "/api/devices/#{ProconBypassMan.device_id}/device_statuses"
15
+ end
16
+ end
@@ -1,12 +1,13 @@
1
- require "procon_bypass_man/background/job_runnable"
1
+ require "procon_bypass_man/background/jobs/concerns/has_internal_api_setting"
2
+ require "procon_bypass_man/background/jobs/concerns/has_external_api_setting"
3
+ require "procon_bypass_man/background/jobs/concerns/job_runnable"
2
4
  require "procon_bypass_man/background/job_runner"
3
5
  require "procon_bypass_man/background/job_performer"
4
- require "procon_bypass_man/background/has_server_pool"
5
- require "procon_bypass_man/background/http_client"
6
6
  require "procon_bypass_man/background/jobs/base_job"
7
+ require "procon_bypass_man/background/jobs/report_event_base_job"
7
8
  require "procon_bypass_man/background/jobs/report_boot_job"
8
9
  require "procon_bypass_man/background/jobs/report_reload_config_job"
9
10
  require "procon_bypass_man/background/jobs/report_load_config_job"
10
11
  require "procon_bypass_man/background/jobs/report_error_job"
11
- require "procon_bypass_man/background/jobs/report_heartbeat_job"
12
12
  require "procon_bypass_man/background/jobs/report_pressed_buttons_job"
13
+ require "procon_bypass_man/background/jobs/sync_device_stats_job"
@@ -10,7 +10,6 @@ module ProconBypassMan
10
10
  self.remaps = {}
11
11
  self.left_analog_stick_caps = {}
12
12
  self.disables = []
13
- instance_eval(&block) if block_given?
14
13
  end
15
14
 
16
15
  # @param [Symbol] button
@@ -50,11 +49,8 @@ module ProconBypassMan
50
49
  end
51
50
  hash[:flip_interval] = interval
52
51
  end
53
- if self.flips[button]
54
- raise "#{button}への設定をすでに割り当て済みです"
55
- else
56
- self.flips[button] = hash
57
- end
52
+
53
+ self.flips[button] = hash
58
54
  end
59
55
 
60
56
  def macro(name, if_pressed: )
@@ -28,14 +28,12 @@ class ProconBypassMan::Bypass
28
28
  end
29
29
  end
30
30
 
31
- ProconBypassMan.cache.fetch key: 'pressed_buttons_reporter', expires_in: 5 do
32
- ProconBypassMan::ReportPressedButtonsJob.perform_async(
33
- ProconBypassMan::ProconReader.new(binary: bypass_value.binary).to_hash
34
- )
35
- end
36
-
37
- ProconBypassMan.cache.fetch key: 'heartbeat_reporter', expires_in: 60 do
38
- ProconBypassMan::ReportHeartbeatJob.perform_async(ProconBypassMan::BootMessage.new.to_hash)
31
+ if ProconBypassMan.config.enable_reporting_pressed_buttons
32
+ ProconBypassMan.cache.fetch key: 'pressed_buttons_reporter', expires_in: 5 do
33
+ ProconBypassMan::ReportPressedButtonsJob.perform_async(
34
+ bypass_value.binary.to_procon_reader.to_hash
35
+ )
36
+ end
39
37
  end
40
38
  end
41
39
  end
@@ -5,7 +5,7 @@ class ProconBypassMan::Bypass
5
5
 
6
6
  class BypassValue < Struct.new(:binary, :sent)
7
7
  def to_text
8
- "#{binary.unpack("H*").first} #{'x' unless sent}"
8
+ "#{binary.unpack.first} #{'x' unless sent}"
9
9
  end
10
10
  end
11
11
 
@@ -21,14 +21,14 @@ class ProconBypassMan::Bypass
21
21
  def send_gadget_to_procon!
22
22
  monitor.record(:start_function)
23
23
  input = nil
24
- self.bypass_value = BypassValue.new(input, sent = false)
24
+ self.bypass_value = BypassValue.new(nil, sent = false)
25
25
 
26
26
  run_callbacks(:send_gadget_to_procon) do
27
27
  begin
28
28
  break if $will_terminate_token
29
29
  # TODO blocking readにしたいが、接続時のフェーズによって長さが違うので厳しい
30
30
  input = self.gadget.read_nonblock(64)
31
- self.bypass_value.binary = input
31
+ self.bypass_value.binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: input)
32
32
  rescue IO::EAGAINWaitReadable
33
33
  monitor.record(:eagain_wait_readable_on_read)
34
34
  sleep(0.001)
@@ -50,14 +50,14 @@ class ProconBypassMan::Bypass
50
50
  def send_procon_to_gadget!
51
51
  monitor.record(:start_function)
52
52
  output = nil
53
- self.bypass_value = BypassValue.new(output, sent = false)
53
+ self.bypass_value = BypassValue.new(nil, sent = false)
54
54
 
55
55
  run_callbacks(:send_procon_to_gadget) do
56
56
  begin
57
57
  break if $will_terminate_token
58
58
  Timeout.timeout(1) do
59
59
  output = self.procon.read(64)
60
- self.bypass_value.binary = output
60
+ self.bypass_value.binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: output)
61
61
  end
62
62
  rescue Timeout::Error
63
63
  ProconBypassMan.logger.debug { "read timeout! do sleep. by send_procon_to_gadget!" }
@@ -72,8 +72,15 @@ class ProconBypassMan::Bypass
72
72
  retry
73
73
  end
74
74
 
75
+ # blocking readをしているのでnilが入ることはないが、雑なテストでnilが通るので分岐を入れる。できれば消したい
76
+ break if output.nil?
77
+
75
78
  begin
76
- self.gadget.write_nonblock(ProconBypassMan::Processor.new(output).process)
79
+ self.gadget.write_nonblock(
80
+ ProconBypassMan::Processor.new(
81
+ ProconBypassMan::Domains::InboundProconBinary.new(binary: output)
82
+ ).process
83
+ )
77
84
  self.bypass_value.sent = true
78
85
  rescue IO::EAGAINWaitReadable
79
86
  monitor.record(:eagain_wait_readable_on_write)
@@ -2,8 +2,13 @@ class ProconBypassMan::ConnectDeviceCommand
2
2
  # @return [void]
3
3
  def self.execute!
4
4
  gadget, procon = ProconBypassMan::DeviceConnector.connect
5
+ rescue ProconBypassMan::DeviceConnector::NotFoundProconError => e
6
+ ProconBypassMan.logger.error e
7
+ gadget&.close
8
+ procon&.close
9
+ raise ProconBypassMan::NotFoundProconError
5
10
  rescue ProconBypassMan::SafeTimeout::Timeout
6
- ::ProconBypassMan.logger.error "デバイスとの通信でタイムアウトが起きて接続ができませんでした。"
11
+ ProconBypassMan.logger.error "デバイスとの通信でタイムアウトが起きて接続ができませんでした。"
7
12
  gadget&.close
8
13
  procon&.close
9
14
  raise ::ProconBypassMan::EternalConnectionError