procon_bypass_man 0.1.19 → 0.1.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +25 -4
- data/CHANGELOG.md +20 -1
- data/Gemfile.lock +3 -3
- data/README.md +1 -11
- data/docs/getting_started.md +62 -6
- data/docs/setting/splatoon2_recommended_setting.md +127 -0
- data/lib/procon_bypass_man/background/jobs/report_completed_upgrade_pbm_job.rb +10 -0
- data/lib/procon_bypass_man/background/jobs/report_error_reload_config_job.rb +11 -0
- data/lib/procon_bypass_man/background/jobs/report_start_reboot_job.rb +10 -0
- data/lib/procon_bypass_man/background.rb +3 -0
- data/lib/procon_bypass_man/buttons_setting_configuration/loader.rb +21 -2
- data/lib/procon_bypass_man/buttons_setting_configuration/validator.rb +10 -0
- data/lib/procon_bypass_man/buttons_setting_configuration.rb +2 -0
- data/lib/procon_bypass_man/bypass/bypass_mode.rb +29 -0
- data/lib/procon_bypass_man/bypass.rb +10 -8
- data/lib/procon_bypass_man/commands/bypass_command.rb +20 -8
- data/lib/procon_bypass_man/commands/connect_device_command.rb +4 -2
- data/lib/procon_bypass_man/commands/print_boot_message_command.rb +6 -0
- data/lib/procon_bypass_man/configuration.rb +30 -1
- data/lib/procon_bypass_man/device_connector.rb +12 -42
- data/lib/procon_bypass_man/device_procon_finder.rb +45 -0
- data/lib/procon_bypass_man/never_exit_accidentally.rb +12 -0
- data/lib/procon_bypass_man/plugin/splatoon2/macro/fast_return.rb +4 -0
- data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_left_key.rb +4 -0
- data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_right_key.rb +4 -0
- data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_up_key.rb +4 -0
- data/lib/procon_bypass_man/plugin/splatoon2/macro/sokuwari_for_splash_bomb.rb +4 -0
- data/lib/procon_bypass_man/plugin/splatoon2/mode/guruguru.rb +4 -0
- data/lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb +4 -1
- data/lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb +1 -0
- data/lib/procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb +8 -1
- data/lib/procon_bypass_man/runner.rb +7 -7
- data/lib/procon_bypass_man/scheduler.rb +1 -1
- data/lib/procon_bypass_man/support/yaml_writer.rb +8 -1
- data/lib/procon_bypass_man/usb_device_controller.rb +53 -0
- data/lib/procon_bypass_man/version.rb +1 -1
- data/lib/procon_bypass_man/websocket/pbm_job_client.rb +13 -3
- data/lib/procon_bypass_man.rb +21 -11
- data/procon_bypass_man.gemspec +1 -1
- data/project_template/app.rb +13 -1
- data/project_template/setting.yml +6 -22
- data/project_template/systemd_units/pbm.service +1 -1
- data/sig/main.rbs +5 -0
- metadata +12 -4
@@ -4,6 +4,7 @@ class ProconBypassMan::PrintBootMessageCommand
|
|
4
4
|
@table = {}
|
5
5
|
@table[:ruby_version] = RUBY_VERSION
|
6
6
|
@table[:pbm_version] = ProconBypassMan::VERSION
|
7
|
+
@table[:pbmenv_version] = Pbmenv::VERSION
|
7
8
|
@table[:pid] = $$
|
8
9
|
@table[:root_path] = ProconBypassMan.root
|
9
10
|
@table[:pid_path] = ProconBypassMan.pid_path
|
@@ -12,6 +13,9 @@ class ProconBypassMan::PrintBootMessageCommand
|
|
12
13
|
@table[:use_pbmenv] = !(!!`which pbmenv`.empty?)
|
13
14
|
@table[:session_id] = ProconBypassMan.session_id
|
14
15
|
@table[:device_id] = ProconBypassMan.device_id
|
16
|
+
@table[:bypass_mode] = ProconBypassMan.config.bypass_mode.to_s
|
17
|
+
@table[:never_exit_accidentally] = ProconBypassMan.config.never_exit_accidentally
|
18
|
+
@table[:uname] = `uname -a`.chomp
|
15
19
|
|
16
20
|
# 開発中のHEADを取りたかったけど、Gem::Specification経由から取得する必要がありそう
|
17
21
|
# build_version = `git rev-parse --short HEAD`.chomp
|
@@ -30,6 +34,7 @@ class ProconBypassMan::PrintBootMessageCommand
|
|
30
34
|
----
|
31
35
|
RUBY_VERSION: #{@table[:ruby_version]}
|
32
36
|
ProconBypassMan::VERSION: #{@table[:pbm_version]}
|
37
|
+
Pbmenv::VERSION: #{@table[:pbmenv_version]}
|
33
38
|
pid: #{@table[:pid]}
|
34
39
|
root: #{@table[:root_path]}
|
35
40
|
pid_path: #{@table[:pid_path]}
|
@@ -38,6 +43,7 @@ class ProconBypassMan::PrintBootMessageCommand
|
|
38
43
|
use_pbmenv: #{@table[:use_pbmenv]}
|
39
44
|
session_id: #{ProconBypassMan.session_id}
|
40
45
|
device_id: #{ProconBypassMan.device_id}
|
46
|
+
bypass_mode: #{ProconBypassMan.config.bypass_mode}
|
41
47
|
----
|
42
48
|
EOF
|
43
49
|
end
|
@@ -38,10 +38,19 @@ class ProconBypassMan::Configuration
|
|
38
38
|
def device_id
|
39
39
|
ENV["DEBUG_DEVICE_ID"] || ProconBypassMan::WriteDeviceIdCommand.execute
|
40
40
|
end
|
41
|
+
|
42
|
+
# @return [Boolean]
|
43
|
+
def never_exit_accidentally
|
44
|
+
config.never_exit_accidentally
|
45
|
+
end
|
46
|
+
|
47
|
+
def fallback_setting_path
|
48
|
+
"/tmp/procon_bypass_man_fallback_setting.yaml"
|
49
|
+
end
|
41
50
|
end
|
42
51
|
|
43
52
|
attr_accessor :enable_critical_error_logging
|
44
|
-
attr_writer :verbose_bypass_log, :raw_setting, :enable_reporting_pressed_buttons
|
53
|
+
attr_writer :verbose_bypass_log, :raw_setting, :enable_reporting_pressed_buttons, :never_exit_accidentally
|
45
54
|
|
46
55
|
def root=(path)
|
47
56
|
@root = path
|
@@ -56,6 +65,17 @@ class ProconBypassMan::Configuration
|
|
56
65
|
end
|
57
66
|
end
|
58
67
|
|
68
|
+
def bypass_mode=(value)
|
69
|
+
@bypass_mode = ProconBypassMan::BypassMode.new(
|
70
|
+
mode: value[:mode],
|
71
|
+
gadget_to_procon_interval: value[:gadget_to_procon_interval],
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
def bypass_mode
|
76
|
+
@bypass_mode || ProconBypassMan::BypassMode.default_value
|
77
|
+
end
|
78
|
+
|
59
79
|
def api_servers=(api_servers)
|
60
80
|
@api_servers = api_servers
|
61
81
|
return self
|
@@ -147,6 +167,10 @@ class ProconBypassMan::Configuration
|
|
147
167
|
end
|
148
168
|
end
|
149
169
|
|
170
|
+
def has_api_server?
|
171
|
+
not api_servers.length.zero?
|
172
|
+
end
|
173
|
+
|
150
174
|
def verbose_bypass_log
|
151
175
|
@verbose_bypass_log || !!ENV["VERBOSE_BYPASS_LOG"]
|
152
176
|
end
|
@@ -158,4 +182,9 @@ class ProconBypassMan::Configuration
|
|
158
182
|
def enable_reporting_pressed_buttons
|
159
183
|
@enable_reporting_pressed_buttons ||= false
|
160
184
|
end
|
185
|
+
|
186
|
+
# @return [Boolean]
|
187
|
+
def never_exit_accidentally
|
188
|
+
@never_exit_accidentally || false
|
189
|
+
end
|
161
190
|
end
|
@@ -61,9 +61,9 @@ class ProconBypassMan::DeviceConnector
|
|
61
61
|
begin
|
62
62
|
timer.throw_if_timeout!
|
63
63
|
data = from_device(item).read_nonblock(64)
|
64
|
-
debug_log_buffer << "read_from(#{item.read_from}): #{data}"
|
64
|
+
debug_log_buffer << "read_from(#{item.read_from}): #{data.unpack("H*")}"
|
65
65
|
rescue IO::EAGAINWaitReadable
|
66
|
-
debug_log_buffer << "read_from(#{item.read_from}): IO::EAGAINWaitReadable"
|
66
|
+
# debug_log_buffer << "read_from(#{item.read_from}): IO::EAGAINWaitReadable"
|
67
67
|
retry
|
68
68
|
end
|
69
69
|
|
@@ -263,49 +263,21 @@ class ProconBypassMan::DeviceConnector
|
|
263
263
|
@procon
|
264
264
|
end
|
265
265
|
|
266
|
-
def is_available_device?(path)
|
267
|
-
return false if !File.exist?(path)
|
268
|
-
|
269
|
-
system('echo > /sys/kernel/config/usb_gadget/procon/UDC')
|
270
|
-
system('ls /sys/class/udc > /sys/kernel/config/usb_gadget/procon/UDC')
|
271
|
-
sleep 0.5
|
272
|
-
|
273
|
-
file = File.open(path, "w+")
|
274
|
-
begin
|
275
|
-
file.read_nonblock(64)
|
276
|
-
rescue EOFError
|
277
|
-
file.close
|
278
|
-
return false
|
279
|
-
rescue IO::EAGAINWaitReadable
|
280
|
-
file.close
|
281
|
-
return true
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
def to_bin(string)
|
286
|
-
string.unpack "H*"
|
287
|
-
end
|
288
|
-
|
289
266
|
def init_devices
|
290
267
|
if @initialized_devices
|
291
268
|
return
|
292
269
|
end
|
270
|
+
ProconBypassMan::UsbDeviceController.init
|
293
271
|
|
294
|
-
|
295
|
-
|
296
|
-
ProconBypassMan.logger.info "proconのデバイスファイルは#{
|
297
|
-
@procon = File.open(PROCON_PATH, "w+b")
|
298
|
-
@gadget = File.open('/dev/hidg0', "w+b")
|
299
|
-
when is_available_device?(PROCON2_PATH)
|
300
|
-
ProconBypassMan.logger.info "proconのデバイスファイルは#{PROCON2_PATH}を使います"
|
301
|
-
@procon = File.open(PROCON2_PATH, "w+b")
|
302
|
-
@gadget = File.open('/dev/hidg0', "w+b")
|
272
|
+
if path = ProconBypassMan::DeviceProconFinder.find
|
273
|
+
@procon = File.open(path, "w+b")
|
274
|
+
ProconBypassMan.logger.info "proconのデバイスファイルは#{path}を使います"
|
303
275
|
else
|
304
|
-
raise
|
276
|
+
raise(ProconBypassMan::DeviceConnector::NotFoundProconError)
|
305
277
|
end
|
306
|
-
|
307
|
-
|
308
|
-
|
278
|
+
@gadget = File.open('/dev/hidg0', "w+b")
|
279
|
+
|
280
|
+
ProconBypassMan::UsbDeviceController.reset
|
309
281
|
|
310
282
|
@initialized_devices = true
|
311
283
|
|
@@ -317,10 +289,8 @@ class ProconBypassMan::DeviceConnector
|
|
317
289
|
end
|
318
290
|
rescue Errno::ENXIO => e
|
319
291
|
# /dev/hidg0 をopenできないときがある
|
320
|
-
ProconBypassMan::SendErrorCommand.execute(error: "Errno::ENXIO (No such device or address @ rb_sysopen - /dev/hidg0)が起きました。reset
|
321
|
-
|
322
|
-
system('ls /sys/class/udc > /sys/kernel/config/usb_gadget/procon/UDC')
|
323
|
-
sleep 0.5
|
292
|
+
ProconBypassMan::SendErrorCommand.execute(error: "Errno::ENXIO (No such device or address @ rb_sysopen - /dev/hidg0)が起きました。resetします.\n #{e.full_message}")
|
293
|
+
ProconBypassMan::UsbDeviceController.reset
|
324
294
|
retry
|
325
295
|
end
|
326
296
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class ProconBypassMan::DeviceProconFinder
|
2
|
+
HID_NAME = "Nintendo Co., Ltd. Pro Controller"
|
3
|
+
|
4
|
+
def self.find
|
5
|
+
new.find
|
6
|
+
end
|
7
|
+
|
8
|
+
# @return [String, NilClass]
|
9
|
+
def find
|
10
|
+
find_device_path
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
# @return [String , NilClass]
|
16
|
+
def find_device_path
|
17
|
+
if(line = device_from_shell) && (hidraw_name = line.match(/(hidraw\d+)\s+/)[1])
|
18
|
+
"/dev/#{hidraw_name}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [String , NilClass]
|
23
|
+
def device_from_shell
|
24
|
+
shell_output.split("\n").detect { |o| o.include?(HID_NAME) }
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [String]
|
28
|
+
def shell_output
|
29
|
+
`bash -c '#{get_list_shell}'`
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_list_shell
|
33
|
+
<<~SHELL
|
34
|
+
#!/bin/bash
|
35
|
+
|
36
|
+
FILES=/dev/hidraw*
|
37
|
+
for f in $FILES
|
38
|
+
do
|
39
|
+
FILE=${f##*/}
|
40
|
+
DEVICE="$(cat /sys/class/hidraw/${FILE}/device/uevent | grep HID_NAME | cut -d '=' -f2)"
|
41
|
+
printf "%s %s\n" $FILE "$DEVICE"
|
42
|
+
done
|
43
|
+
SHELL
|
44
|
+
end
|
45
|
+
end
|
@@ -3,6 +3,10 @@ module ProconBypassMan
|
|
3
3
|
module Splatoon2
|
4
4
|
module Mode
|
5
5
|
module Guruguru
|
6
|
+
def self.description
|
7
|
+
'適当に動きます'
|
8
|
+
end
|
9
|
+
|
6
10
|
def self.binaries
|
7
11
|
[ "309481408000362d684658750968f71cfe2c0e51000001480053f71ffedf0d4b000a013d00caf6ecfd4c0d480003011c00000000000000000000000000000000",
|
8
12
|
"30978140800037dd6748687509fdf6adfded0d6d0081005d00eef68dfdef0d6d00830059001bf791fd140e720090005400000000000000000000000000000000",
|
@@ -6,8 +6,11 @@ module ProconBypassMan
|
|
6
6
|
require "pbmenv"
|
7
7
|
ProconBypassMan.logger.info "execute ChangePbmVersionAction!"
|
8
8
|
pbm_version = args["pbm_version"] or raise(ProconBypassMan::RemotePbmAction::NeedPbmVersionError, "pbm_versionが必要です, #{args.inspect}")
|
9
|
-
Pbmenv.
|
9
|
+
Pbmenv.uninstall(pbm_version) # 途中でシャットダウンしてしまった、とか状態が途中の状態かもしれないので一旦消す
|
10
|
+
Pbmenv.install(pbm_version, enable_pbm_cloud: true)
|
10
11
|
Pbmenv.use(pbm_version)
|
12
|
+
ProconBypassMan.logger.info "#{pbm_version}へアップグレードしました"
|
13
|
+
ProconBypassMan::ReportCompletedUpgradePbmJob.perform
|
11
14
|
`reboot` # symlinkの参照先が変わるのでrebootする必要がある
|
12
15
|
end
|
13
16
|
|
@@ -6,7 +6,14 @@ module ProconBypassMan
|
|
6
6
|
require "pbmenv"
|
7
7
|
ProconBypassMan.logger.info "execute RestorePbmSettingAction!"
|
8
8
|
setting = args.dig("setting") or raise(ProconBypassMan::RemotePbmAction::NeedPbmVersionError, "settingが必要です, #{args.inspect}")
|
9
|
-
|
9
|
+
|
10
|
+
# 復元に失敗したら戻せるように退避する
|
11
|
+
FileUtils.copy(
|
12
|
+
ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path,
|
13
|
+
ProconBypassMan.fallback_setting_path,
|
14
|
+
)
|
15
|
+
|
16
|
+
ProconBypassMan::YamlWriter.write(
|
10
17
|
path: ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path,
|
11
18
|
content: setting,
|
12
19
|
)
|
@@ -27,7 +27,7 @@ class ProconBypassMan::Runner
|
|
27
27
|
loop do
|
28
28
|
$will_terminate_token = false
|
29
29
|
# NOTE メインプロセスではThreadをいくつか起動しているので念のためパフォーマンスを優先するためにforkしていく
|
30
|
-
|
30
|
+
child_pid = Kernel.fork { ProconBypassMan::BypassCommand.new(gadget: @gadget, procon: @procon).execute }
|
31
31
|
|
32
32
|
begin
|
33
33
|
# TODO 小プロセスが消滅した時に、メインプロセスは生き続けてしまい、何もできなくなる問題がある
|
@@ -37,25 +37,25 @@ class ProconBypassMan::Runner
|
|
37
37
|
end
|
38
38
|
rescue InterruptForRestart
|
39
39
|
$will_terminate_token = true
|
40
|
-
Process.kill("TERM",
|
40
|
+
Process.kill("TERM", child_pid)
|
41
41
|
Process.wait
|
42
42
|
ProconBypassMan::PrintMessageCommand.execute(text: "Reloading config file")
|
43
43
|
begin
|
44
44
|
ProconBypassMan::ButtonsSettingConfiguration::Loader.reload_setting
|
45
45
|
ProconBypassMan::SendReloadConfigEventCommand.execute
|
46
|
-
rescue ProconBypassMan::CouldNotLoadConfigError
|
46
|
+
rescue ProconBypassMan::CouldNotLoadConfigError => error
|
47
47
|
ProconBypassMan::SendErrorCommand.execute(error: "設定ファイルが不正です。再読み込みができませんでした")
|
48
|
+
ProconBypassMan::ReportErrorReloadConfigJob.perform_async(error.message)
|
48
49
|
end
|
49
50
|
ProconBypassMan::PrintMessageCommand.execute(text: "バイパス処理を再開します")
|
50
51
|
rescue Interrupt
|
51
52
|
$will_terminate_token = true
|
52
|
-
Process.kill("TERM",
|
53
|
+
Process.kill("TERM", child_pid)
|
53
54
|
Process.wait
|
55
|
+
ProconBypassMan::PrintMessageCommand.execute(text: "処理を終了します")
|
54
56
|
@gadget&.close
|
55
57
|
@procon&.close
|
56
|
-
|
57
|
-
FileUtils.rm_rf(ProconBypassMan.digest_path)
|
58
|
-
exit 1
|
58
|
+
break
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -3,7 +3,14 @@ class ProconBypassMan::YamlWriter
|
|
3
3
|
def self.write(path: , content: )
|
4
4
|
File.write(
|
5
5
|
path,
|
6
|
-
content.
|
6
|
+
content.transform_values { |x|
|
7
|
+
case x
|
8
|
+
when String
|
9
|
+
x.gsub("\r\n", "\n")
|
10
|
+
else
|
11
|
+
x
|
12
|
+
end
|
13
|
+
}.to_yaml
|
7
14
|
)
|
8
15
|
end
|
9
16
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class ProconBypassMan::UsbDeviceController
|
2
|
+
class << self
|
3
|
+
def reset
|
4
|
+
system('echo > /sys/kernel/config/usb_gadget/procon/UDC')
|
5
|
+
system('ls /sys/class/udc > /sys/kernel/config/usb_gadget/procon/UDC')
|
6
|
+
sleep 0.5
|
7
|
+
end
|
8
|
+
|
9
|
+
def init
|
10
|
+
return if initialized?
|
11
|
+
|
12
|
+
shell = <<~EOH
|
13
|
+
#!/bin/bash
|
14
|
+
|
15
|
+
cd /sys/kernel/config/usb_gadget/
|
16
|
+
mkdir -p procon
|
17
|
+
cd procon
|
18
|
+
echo 0x057e > idVendor
|
19
|
+
echo 0x2009 > idProduct
|
20
|
+
echo 0x0200 > bcdDevice
|
21
|
+
echo 0x0200 > bcdUSB
|
22
|
+
echo 0x00 > bDeviceClass
|
23
|
+
echo 0x00 > bDeviceSubClass
|
24
|
+
echo 0x00 > bDeviceProtocol
|
25
|
+
|
26
|
+
mkdir -p strings/0x409
|
27
|
+
echo "000000000001" > strings/0x409/serialnumber
|
28
|
+
echo "Nintendo Co., Ltd." > strings/0x409/manufacturer
|
29
|
+
echo "Pro Controller" > strings/0x409/product
|
30
|
+
|
31
|
+
mkdir -p configs/c.1/strings/0x409
|
32
|
+
echo "Nintendo Switch Pro Controller" > configs/c.1/strings/0x409/configuration
|
33
|
+
echo 500 > configs/c.1/MaxPower
|
34
|
+
echo 0xa0 > configs/c.1/bmAttributes
|
35
|
+
|
36
|
+
mkdir -p functions/hid.usb0
|
37
|
+
echo 0 > functions/hid.usb0/protocol
|
38
|
+
echo 0 > functions/hid.usb0/subclass
|
39
|
+
echo 64 > functions/hid.usb0/report_length
|
40
|
+
echo 050115000904A1018530050105091901290A150025017501950A5500650081020509190B290E150025017501950481027501950281030B01000100A1000B300001000B310001000B320001000B35000100150027FFFF0000751095048102C00B39000100150025073500463B0165147504950181020509190F2912150025017501950481027508953481030600FF852109017508953F8103858109027508953F8103850109037508953F9183851009047508953F9183858009057508953F9183858209067508953F9183C0 | xxd -r -ps > functions/hid.usb0/report_desc
|
41
|
+
|
42
|
+
ln -s functions/hid.usb0 configs/c.1/
|
43
|
+
ls /sys/class/udc > UDC
|
44
|
+
EOH
|
45
|
+
|
46
|
+
`bash -c '#{shell}'`
|
47
|
+
end
|
48
|
+
|
49
|
+
def initialized?
|
50
|
+
Dir.exist?("/sys/kernel/config/usb_gadget/procon")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -9,7 +9,8 @@ module ProconBypassMan
|
|
9
9
|
Thread.start do
|
10
10
|
loop do
|
11
11
|
run
|
12
|
-
rescue
|
12
|
+
rescue => e
|
13
|
+
ProconBypassMan.logger.error("websocket client: #{e.full_message}")
|
13
14
|
retry
|
14
15
|
end
|
15
16
|
end
|
@@ -24,14 +25,16 @@ module ProconBypassMan
|
|
24
25
|
)
|
25
26
|
|
26
27
|
client.connected {
|
27
|
-
ProconBypassMan.logger.info('successfully connected in ProconBypassMan::Websocket::PbmJobClient')
|
28
|
+
ProconBypassMan.logger.info('websocket client: successfully connected in ProconBypassMan::Websocket::PbmJobClient')
|
28
29
|
}
|
29
30
|
client.subscribed { |msg|
|
31
|
+
ProconBypassMan.logger.info('websocket client: subscribed')
|
30
32
|
puts({ event: :subscribed, msg: msg })
|
31
33
|
ProconBypassMan::SyncDeviceStatsJob.perform(ProconBypassMan::DeviceStatus.current)
|
32
34
|
}
|
33
35
|
|
34
36
|
client.received do |data|
|
37
|
+
ProconBypassMan.logger.info('websocket client: received!!')
|
35
38
|
ProconBypassMan.logger.info(data)
|
36
39
|
|
37
40
|
dispatch(data: data, client: client)
|
@@ -40,13 +43,20 @@ module ProconBypassMan
|
|
40
43
|
end
|
41
44
|
|
42
45
|
client.disconnected {
|
46
|
+
ProconBypassMan.logger.info('websocket client: disconnected!!')
|
43
47
|
puts :disconnected
|
44
48
|
client.reconnect!
|
45
49
|
sleep 2
|
46
50
|
}
|
47
|
-
client.errored { |msg|
|
51
|
+
client.errored { |msg|
|
52
|
+
ProconBypassMan.logger.error("websocket client: errored!!, #{msg}")
|
53
|
+
puts :errored
|
54
|
+
client.reconnect!
|
55
|
+
sleep 2
|
56
|
+
}
|
48
57
|
client.pinged { |msg|
|
49
58
|
ProconBypassMan.cache.fetch key: 'ws_pinged', expires_in: 10 do
|
59
|
+
ProconBypassMan.logger.info('websocket client: pinged!!')
|
50
60
|
ProconBypassMan.logger.info(msg)
|
51
61
|
end
|
52
62
|
}
|
data/lib/procon_bypass_man.rb
CHANGED
@@ -8,6 +8,8 @@ require 'em/pure_ruby'
|
|
8
8
|
require "action_cable_client"
|
9
9
|
require "ext/em_pure_ruby"
|
10
10
|
require "ext/module"
|
11
|
+
require "resolv-replace"
|
12
|
+
require "pbmenv"
|
11
13
|
|
12
14
|
require_relative "procon_bypass_man/version"
|
13
15
|
require_relative "procon_bypass_man/remote_pbm_action"
|
@@ -27,8 +29,11 @@ require_relative "procon_bypass_man/background"
|
|
27
29
|
require_relative "procon_bypass_man/commands"
|
28
30
|
require_relative "procon_bypass_man/bypass"
|
29
31
|
require_relative "procon_bypass_man/domains"
|
32
|
+
require_relative "procon_bypass_man/never_exit_accidentally"
|
30
33
|
require_relative "procon_bypass_man/device_connector"
|
34
|
+
require_relative "procon_bypass_man/device_procon_finder"
|
31
35
|
require_relative "procon_bypass_man/device_status"
|
36
|
+
require_relative "procon_bypass_man/usb_device_controller"
|
32
37
|
require_relative "procon_bypass_man/runner"
|
33
38
|
require_relative "procon_bypass_man/processor"
|
34
39
|
require_relative "procon_bypass_man/configuration"
|
@@ -48,9 +53,9 @@ Thread.abort_on_exception = true
|
|
48
53
|
|
49
54
|
module ProconBypassMan
|
50
55
|
extend ProconBypassMan::Configuration::ClassMethods
|
56
|
+
extend ProconBypassMan::NeverExitAccidentally
|
51
57
|
|
52
58
|
class CouldNotLoadConfigError < StandardError; end
|
53
|
-
class NotFoundProconError < StandardError; end
|
54
59
|
class ConnectionError < StandardError; end
|
55
60
|
class FirstConnectionError < ConnectionError; end
|
56
61
|
class EternalConnectionError < ConnectionError; end
|
@@ -62,22 +67,26 @@ module ProconBypassMan
|
|
62
67
|
ProconBypassMan::Websocket::PbmJobClient.start!
|
63
68
|
|
64
69
|
ProconBypassMan::PrintMessageCommand.execute(text: "PBMを起動しています")
|
65
|
-
ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting_path)
|
66
70
|
initialize_pbm
|
71
|
+
ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting_path)
|
67
72
|
gadget, procon = ProconBypassMan::ConnectDeviceCommand.execute!
|
68
|
-
Runner.new(gadget: gadget, procon: procon).run
|
73
|
+
Runner.new(gadget: gadget, procon: procon).run # ここでblockingする
|
74
|
+
FileUtils.rm_rf(ProconBypassMan.pid_path)
|
75
|
+
FileUtils.rm_rf(ProconBypassMan.digest_path)
|
69
76
|
rescue ProconBypassMan::CouldNotLoadConfigError
|
70
77
|
ProconBypassMan::SendErrorCommand.execute(error: "設定ファイルが不正です。設定ファイルの読み込みに失敗しました")
|
71
78
|
ProconBypassMan::DeviceStatus.change_to_setting_syntax_error_and_shutdown!
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
79
|
+
ProconBypassMan.exit_if_allow(1) do
|
80
|
+
FileUtils.rm_rf(ProconBypassMan.pid_path)
|
81
|
+
FileUtils.rm_rf(ProconBypassMan.digest_path)
|
82
|
+
end
|
83
|
+
rescue ProconBypassMan::ConnectDeviceCommand::NotFoundProconError
|
84
|
+
ProconBypassMan::SendErrorCommand.execute(error: "プロコンが見つかりませんでした。")
|
77
85
|
ProconBypassMan::DeviceStatus.change_to_procon_not_found_error!
|
78
|
-
|
79
|
-
|
80
|
-
|
86
|
+
ProconBypassMan.exit_if_allow(1) do
|
87
|
+
FileUtils.rm_rf(ProconBypassMan.pid_path)
|
88
|
+
FileUtils.rm_rf(ProconBypassMan.digest_path)
|
89
|
+
end
|
81
90
|
rescue ProconBypassMan::ConnectionError
|
82
91
|
begin
|
83
92
|
raise
|
@@ -115,6 +124,7 @@ module ProconBypassMan
|
|
115
124
|
def self.initialize_pbm
|
116
125
|
ProconBypassMan::WriteDeviceIdCommand.execute
|
117
126
|
ProconBypassMan::WriteSessionIdCommand.execute
|
127
|
+
system("renice -n -20 -p #{$$}")
|
118
128
|
File.write(pid_path, $$)
|
119
129
|
ProconBypassMan::DeviceStatus.change_to_running!
|
120
130
|
end
|
data/procon_bypass_man.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
30
|
# Uncomment to register a new dependency of your gem
|
31
|
-
spec.add_dependency "pbmenv"
|
31
|
+
spec.add_dependency "pbmenv", ">= 0.1.9" # Pbmenv.installでのenable_pbm_cloudに依存している
|
32
32
|
spec.add_dependency "action_cable_client"
|
33
33
|
spec.add_dependency "sorted_set"
|
34
34
|
|
data/project_template/app.rb
CHANGED
@@ -5,16 +5,28 @@ require 'bundler/inline'
|
|
5
5
|
gemfile do
|
6
6
|
source 'https://rubygems.org'
|
7
7
|
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
8
|
-
gem 'procon_bypass_man', '0.1.
|
8
|
+
gem 'procon_bypass_man', '0.1.20.2'
|
9
9
|
end
|
10
10
|
|
11
11
|
ProconBypassMan.configure do |config|
|
12
12
|
config.root = File.expand_path(__dir__)
|
13
13
|
config.logger = Logger.new("#{ProconBypassMan.root}/app.log", 5, 1024 * 1024 * 10)
|
14
14
|
config.logger.level = :debug
|
15
|
+
|
16
|
+
# バイパスするログを全部app.logに流すか
|
17
|
+
config.verbose_bypass_log = false
|
18
|
+
|
15
19
|
# webからProconBypassManを操作できるwebサービス
|
16
20
|
# config.api_servers = ['https://pbm-cloud.herokuapp.com']
|
21
|
+
|
22
|
+
# エラーが起きたらerror.logに書き込みます
|
17
23
|
config.enable_critical_error_logging = true
|
24
|
+
|
25
|
+
# pbm-cloudで使う場合はnever_exitにtrueをセットしてください. trueがセットされている場合、不慮の事故が発生してもプロセスが終了しなくなります
|
26
|
+
config.never_exit_accidentally = true
|
27
|
+
|
28
|
+
# 操作が高頻度で固まるときは、 gadget_to_procon_interval の数値は大きくしてください
|
29
|
+
config.bypass_mode = { mode: :normal, gadget_to_procon_interval: 5 }
|
18
30
|
end
|
19
31
|
|
20
32
|
ProconBypassMan.run(setting_path: "/usr/share/pbm/current/setting.yml")
|