procon_bypass_man 0.1.14 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +1 -0
- data/.github/workflows/release.yml +33 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +28 -7
- data/README.md +26 -3
- data/Steepfile +31 -17
- data/docs/setting/left-analogstick-cap.md +60 -0
- data/docs/setup_raspi.md +2 -0
- data/docs/setup_raspi.mitamae.rb +7 -8
- data/docs/setup_raspi_by_mitamae.md +37 -1
- data/lib/ext/em_pure_ruby.rb +25 -0
- data/lib/procon_bypass_man/background.rb +0 -1
- data/lib/procon_bypass_man/buttons_setting_configuration/layer.rb +35 -13
- data/lib/procon_bypass_man/buttons_setting_configuration/loader.rb +1 -0
- data/lib/procon_bypass_man/buttons_setting_configuration/validator.rb +36 -0
- data/lib/procon_bypass_man/buttons_setting_configuration.rb +28 -13
- data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +6 -4
- data/lib/procon_bypass_man/bypass.rb +13 -6
- data/lib/procon_bypass_man/commands/print_boot_message_command.rb +50 -1
- data/lib/procon_bypass_man/commands/print_message_command.rb +8 -0
- data/lib/procon_bypass_man/commands/run_remote_pbm_action_dispatch_command.rb +3 -1
- data/lib/procon_bypass_man/commands/send_reload_config_event_command.rb +1 -2
- data/lib/procon_bypass_man/commands.rb +1 -0
- data/lib/procon_bypass_man/configuration.rb +32 -1
- data/lib/procon_bypass_man/domains/binary/base.rb +25 -0
- data/lib/procon_bypass_man/domains/binary/has_immutable_binary.rb +5 -0
- data/lib/procon_bypass_man/domains/binary/has_mutable_binary.rb +5 -0
- data/lib/procon_bypass_man/domains/binary/inbound_procon_binary.rb +9 -0
- data/lib/procon_bypass_man/domains/binary/processing_procon_binary.rb +66 -0
- data/lib/procon_bypass_man/domains.rb +11 -0
- data/lib/procon_bypass_man/plugin/splatoon2/macro/fast_return.rb +17 -0
- data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_left_key.rb +17 -0
- data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_right_key.rb +17 -0
- data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_up_key.rb +17 -0
- data/lib/procon_bypass_man/plugin/splatoon2/mode/guruguru.rb +59 -0
- data/lib/procon_bypass_man/plugin/splatoon2/version.rb +9 -0
- data/lib/procon_bypass_man/plugins.rb +11 -0
- data/lib/procon_bypass_man/processor.rb +4 -5
- data/lib/procon_bypass_man/procon/button.rb +11 -0
- data/lib/procon_bypass_man/procon/button_collection.rb +9 -11
- data/lib/procon_bypass_man/procon/layer_changer.rb +3 -2
- data/lib/procon_bypass_man/procon/macro_registry.rb +8 -5
- data/lib/procon_bypass_man/procon/mode_registry.rb +4 -4
- data/lib/procon_bypass_man/procon/press_button_aware.rb +9 -7
- data/lib/procon_bypass_man/procon/user_operation.rb +46 -63
- data/lib/procon_bypass_man/procon/{analog_stick.rb → value_objects/analog_stick.rb} +3 -4
- data/lib/procon_bypass_man/procon/value_objects/procon_reader.rb +34 -0
- data/lib/procon_bypass_man/procon.rb +18 -16
- data/lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb +4 -0
- data/lib/procon_bypass_man/remote_pbm_action/{lib → commands}/update_remote_pbm_action_status_command.rb +0 -0
- data/lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb +4 -0
- data/lib/procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb +28 -0
- data/lib/procon_bypass_man/remote_pbm_action/stop_pbm_action.rb +4 -0
- data/lib/procon_bypass_man/{value_objects → remote_pbm_action/value_objects}/remote_pbm_action_object.rb +0 -0
- data/lib/procon_bypass_man/remote_pbm_action.rb +3 -2
- data/lib/procon_bypass_man/runner.rb +4 -4
- data/lib/procon_bypass_man/scheduler.rb +0 -7
- data/lib/procon_bypass_man/support/compress_array.rb +5 -0
- data/lib/procon_bypass_man/support/http_client.rb +4 -0
- data/lib/procon_bypass_man/support/on_memory_cache.rb +3 -1
- data/lib/procon_bypass_man/support/report_http_client.rb +3 -3
- data/lib/procon_bypass_man/support/server_pool.rb +4 -0
- data/lib/procon_bypass_man/version.rb +1 -1
- data/lib/procon_bypass_man/websocket/pbm_job_client.rb +90 -0
- data/lib/procon_bypass_man.rb +50 -33
- data/procon_bypass_man.gemspec +2 -0
- data/project_template/README.md +10 -5
- data/project_template/app.rb +1 -1
- data/project_template/setting.yml +8 -8
- data/sig/main.rbs +226 -41
- data/sig/on_memory_cache.rbs +16 -0
- metadata +59 -20
- data/lib/procon_bypass_man/background/jobs/fetch_and_run_remote_pbm_action_job.rb +0 -29
- data/lib/procon_bypass_man/boot_message.rb +0 -48
- data/lib/procon_bypass_man/commands/run_local_shell_command.rb +0 -6
- data/lib/procon_bypass_man/procon_reader.rb +0 -31
- data/lib/procon_bypass_man/splatoon2/macro/fast_return.rb +0 -15
- data/lib/procon_bypass_man/splatoon2/macro/jump_to_left_key.rb +0 -15
- data/lib/procon_bypass_man/splatoon2/macro/jump_to_right_key.rb +0 -15
- data/lib/procon_bypass_man/splatoon2/macro/jump_to_up_key.rb +0 -15
- data/lib/procon_bypass_man/splatoon2/mode/guruguru.rb +0 -57
- data/lib/procon_bypass_man/splatoon2/version.rb +0 -7
- data/lib/procon_bypass_man/splatoon2.rb +0 -11
@@ -1,6 +1,7 @@
|
|
1
1
|
class ProconBypassMan::Procon::LayerChanger
|
2
|
+
# @param [ProconBypassMan::Domains::ProcessingProconBinary] binary
|
2
3
|
def initialize(binary: )
|
3
|
-
@procon_reader =
|
4
|
+
@procon_reader = binary.to_procon_reader
|
4
5
|
end
|
5
6
|
|
6
7
|
# @return [Symbol]
|
@@ -35,6 +36,6 @@ class ProconBypassMan::Procon::LayerChanger
|
|
35
36
|
|
36
37
|
# @return [Boolean]
|
37
38
|
def pressed?(button: )
|
38
|
-
@procon_reader.
|
39
|
+
@procon_reader.pressing.include?(button)
|
39
40
|
end
|
40
41
|
end
|
@@ -24,15 +24,18 @@ class ProconBypassMan::Procon::MacroRegistry
|
|
24
24
|
null: [],
|
25
25
|
}
|
26
26
|
|
27
|
-
def self.install_plugin(klass)
|
28
|
-
if plugins[klass.
|
29
|
-
raise "
|
27
|
+
def self.install_plugin(klass, steps: nil)
|
28
|
+
if plugins[klass.to_s.to_sym]
|
29
|
+
raise "#{klass} macro is already registered"
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
|
+
plugins[klass.to_s.to_sym] = ->{
|
33
|
+
ProconBypassMan::Procon::ButtonCollection.normalize(steps || klass.steps)
|
34
|
+
}
|
32
35
|
end
|
33
36
|
|
34
37
|
def self.load(name)
|
35
|
-
steps = PRESETS[name] || plugins[name] || raise("unknown macro")
|
38
|
+
steps = PRESETS[name] || plugins[name].call || raise("unknown macro")
|
36
39
|
Macro.new(name: name, steps: steps.dup)
|
37
40
|
end
|
38
41
|
|
@@ -23,14 +23,14 @@ class ProconBypassMan::Procon::ModeRegistry
|
|
23
23
|
}
|
24
24
|
|
25
25
|
def self.install_plugin(klass)
|
26
|
-
if plugins[klass.
|
27
|
-
raise "
|
26
|
+
if plugins[klass.to_s.to_sym]
|
27
|
+
raise "#{klass} mode is already registered"
|
28
28
|
end
|
29
|
-
plugins[klass.
|
29
|
+
plugins[klass.to_s.to_sym] = ->{ klass.binaries }
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.load(name)
|
33
|
-
b = PRESETS[name] || plugins[name] || raise("unknown mode")
|
33
|
+
b = PRESETS[name] || plugins[name]&.call || raise("#{name} is unknown mode")
|
34
34
|
Mode.new(name: name, binaries: b.dup)
|
35
35
|
end
|
36
36
|
|
@@ -1,13 +1,15 @@
|
|
1
|
-
class ProconBypassMan::
|
1
|
+
class ProconBypassMan::PressButtonAware
|
2
|
+
BIT_ON = '1'.freeze
|
3
|
+
|
2
4
|
def initialize(binary)
|
3
5
|
@binary = binary
|
4
6
|
end
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
] ==
|
8
|
+
# @param [Symbol]
|
9
|
+
# @return [Boolean]
|
10
|
+
def pressing_button?(button)
|
11
|
+
button_obj = ProconBypassMan::Procon::Button.new(button)
|
12
|
+
byte = @binary[button_obj.byte_position].unpack("C").first.to_s(2).reverse
|
13
|
+
byte[button_obj.bit_position] == BIT_ON
|
12
14
|
end
|
13
15
|
end
|
@@ -1,77 +1,60 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# ボタンを押しているか判断するクラス。バイナリの書き換えはしない
|
2
|
+
class ProconBypassMan::Procon::UserOperation
|
3
|
+
attr_reader :binary
|
4
4
|
|
5
|
-
|
6
|
-
define_method "pressed_#{button}?" do
|
7
|
-
pressed_button?(button)
|
8
|
-
end
|
9
|
-
end
|
5
|
+
ASCII_ENCODING = "ASCII-8BIT"
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@binary = binary
|
7
|
+
# @param [String] binary
|
8
|
+
def initialize(binary)
|
9
|
+
unless binary.encoding.name == ASCII_ENCODING
|
10
|
+
raise "おかしいです"
|
16
11
|
end
|
17
12
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def set_no_action!
|
22
|
-
binary[3] = ZERO_BIT
|
23
|
-
binary[4] = ZERO_BIT
|
24
|
-
binary[5] = ZERO_BIT
|
25
|
-
end
|
13
|
+
@binary = ProconBypassMan::Domains::ProcessingProconBinary.new(binary: binary)
|
14
|
+
end
|
26
15
|
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
def set_no_action!
|
17
|
+
binary.set_no_action!
|
18
|
+
end
|
30
19
|
|
31
|
-
|
32
|
-
|
20
|
+
def apply_left_analog_stick_cap(cap: )
|
21
|
+
binary.write_as_apply_left_analog_stick_cap(cap: cap)
|
22
|
+
end
|
33
23
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
24
|
+
# @param [Symbol] button
|
25
|
+
def unpress_button(button)
|
26
|
+
return if not pressing_button?(button)
|
27
|
+
binary.write_as_unpress_button(button)
|
28
|
+
end
|
38
29
|
|
39
|
-
|
40
|
-
|
30
|
+
# @param [Symbol] button
|
31
|
+
def press_button(button)
|
32
|
+
return if pressing_button?(button)
|
33
|
+
binary.write_as_press_button(button)
|
34
|
+
end
|
41
35
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
36
|
+
# @param [Symbol] button
|
37
|
+
def press_button_only(button)
|
38
|
+
binary.write_as_press_button_only(button)
|
39
|
+
end
|
46
40
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
binary[3] = no_action_binary[3]
|
54
|
-
binary[4] = no_action_binary[4]
|
55
|
-
binary[5] = no_action_binary[5]
|
56
|
-
end
|
57
|
-
end
|
41
|
+
# @return [void]
|
42
|
+
def merge(target_binary)
|
43
|
+
binary.write_as_merge!(
|
44
|
+
ProconBypassMan::Domains::ProcessingProconBinary.new(binary: target_binary)
|
45
|
+
)
|
46
|
+
end
|
58
47
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
binary[6] = tb[6]
|
65
|
-
binary[7] = tb[7]
|
66
|
-
binary[8] = tb[8]
|
67
|
-
binary[9] = tb[9]
|
68
|
-
binary[10] = tb[10]
|
69
|
-
binary[11] = tb[11]
|
70
|
-
self.binary
|
71
|
-
end
|
48
|
+
# @param [Symbol] button
|
49
|
+
# @return [Boolean]
|
50
|
+
def pressing_button?(button)
|
51
|
+
ProconBypassMan::PressButtonAware.new(@binary.raw).pressing_button?(button)
|
52
|
+
end
|
72
53
|
|
73
|
-
|
74
|
-
|
75
|
-
|
54
|
+
# @param [Array<Symbol>] buttons
|
55
|
+
# @return [Boolean]
|
56
|
+
def pressing_all_buttons?(buttons)
|
57
|
+
aware = ProconBypassMan::PressButtonAware.new(@binary.raw)
|
58
|
+
buttons.all? { |b| aware.pressing_button?(b) }
|
76
59
|
end
|
77
60
|
end
|
@@ -4,13 +4,12 @@ class ProconBypassMan::Procon::AnalogStick
|
|
4
4
|
|
5
5
|
def initialize(binary: )
|
6
6
|
@neutral_position = ProconBypassMan::ButtonsSettingConfiguration.instance.neutral_position
|
7
|
-
|
8
|
-
byte6 =
|
9
|
-
byte7 = binary[7].unpack("H*").first.to_i(16).to_s(2).rjust(8, "0")
|
10
|
-
byte8 = binary[8].unpack("H*").first.to_i(16).to_s(2).rjust(8, "0")
|
7
|
+
bytes = binary[ProconBypassMan::Procon::ButtonCollection::LEFT_ANALOG_STICK.fetch(:byte_position)]
|
8
|
+
byte6, byte7, byte8 = bytes.each_char.map { |x| x.unpack("C").first.to_s(2).rjust(8, "0") }
|
11
9
|
|
12
10
|
self.bin_x = "#{byte7[4..7]}#{byte6}"
|
13
11
|
self.bin_y = "#{byte8}#{byte7[0..3]}"
|
12
|
+
freeze
|
14
13
|
end
|
15
14
|
|
16
15
|
def abs_x
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class ProconReader
|
3
|
+
def initialize(binary: )
|
4
|
+
@binary = binary
|
5
|
+
@analog_stick = ProconBypassMan::Procon::AnalogStick.new(binary: binary)
|
6
|
+
freeze
|
7
|
+
end
|
8
|
+
|
9
|
+
# @return [Array<Symbol>]
|
10
|
+
def pressing
|
11
|
+
aware = ProconBypassMan::PressButtonAware.new(@binary)
|
12
|
+
pressed_table = ::ProconBypassMan::Procon::ButtonCollection::BUTTONS.reduce({}) do |acc, button|
|
13
|
+
acc[button] = aware.pressing_button?(button)
|
14
|
+
acc
|
15
|
+
end
|
16
|
+
pressed_table.select { |_key, value| value }.keys
|
17
|
+
end
|
18
|
+
|
19
|
+
def left_analog_stick
|
20
|
+
{ x: @analog_stick.relative_x, y: @analog_stick.relative_y }
|
21
|
+
end
|
22
|
+
|
23
|
+
def left_analog_stick_by_abs
|
24
|
+
{ x: @analog_stick.abs_x, y: @analog_stick.abs_y }
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_hash
|
28
|
+
{ left_analog_stick: left_analog_stick,
|
29
|
+
left_analog_stick_by_abs: left_analog_stick_by_abs,
|
30
|
+
buttons: pressing,
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -20,8 +20,11 @@ class ProconBypassMan::Procon
|
|
20
20
|
end
|
21
21
|
reset!
|
22
22
|
|
23
|
+
# @param [string] binary
|
23
24
|
def initialize(binary)
|
24
|
-
self.user_operation = ProconBypassMan::Procon::UserOperation.new(
|
25
|
+
self.user_operation = ProconBypassMan::Procon::UserOperation.new(
|
26
|
+
binary.dup
|
27
|
+
)
|
25
28
|
end
|
26
29
|
|
27
30
|
def status; @@status[:buttons]; end
|
@@ -43,7 +46,7 @@ class ProconBypassMan::Procon
|
|
43
46
|
|
44
47
|
if ongoing_macro.finished?
|
45
48
|
current_layer.macros.each do |macro_name, options|
|
46
|
-
if options[:if_pressed]
|
49
|
+
if user_operation.pressing_all_buttons?(options[:if_pressed])
|
47
50
|
@@status[:ongoing_macro] = MacroRegistry.load(macro_name)
|
48
51
|
end
|
49
52
|
end
|
@@ -60,7 +63,7 @@ class ProconBypassMan::Procon
|
|
60
63
|
next
|
61
64
|
end
|
62
65
|
|
63
|
-
if options[:if_pressed] && options[:if_pressed]
|
66
|
+
if options[:if_pressed] && user_operation.pressing_all_buttons?(options[:if_pressed])
|
64
67
|
FlipCache.fetch(key: button, expires_in: options[:flip_interval]) do
|
65
68
|
status[button] = !status[button]
|
66
69
|
end
|
@@ -75,7 +78,7 @@ class ProconBypassMan::Procon
|
|
75
78
|
@@status[:ongoing_mode] = ProconBypassMan::Procon::ModeRegistry.load(current_layer.mode)
|
76
79
|
end
|
77
80
|
if(binary = ongoing_mode.next_binary)
|
78
|
-
self.user_operation.merge(
|
81
|
+
self.user_operation.merge([binary].pack("H*"))
|
79
82
|
end
|
80
83
|
return
|
81
84
|
end
|
@@ -83,28 +86,28 @@ class ProconBypassMan::Procon
|
|
83
86
|
status
|
84
87
|
end
|
85
88
|
|
86
|
-
# @return [
|
89
|
+
# @return [ProconBypassMan::Domains::ProcessingProconBinary]
|
87
90
|
def to_binary
|
88
91
|
if ongoing_mode.name != :manual
|
89
|
-
return user_operation.binary
|
92
|
+
return user_operation.binary.raw
|
90
93
|
end
|
91
94
|
|
92
95
|
if ongoing_macro.ongoing?
|
93
|
-
step = ongoing_macro.next_step or return(user_operation.binary)
|
96
|
+
step = ongoing_macro.next_step or return(user_operation.binary.raw)
|
94
97
|
user_operation.press_button_only(step)
|
95
|
-
return user_operation.binary
|
98
|
+
return user_operation.binary.raw
|
96
99
|
end
|
97
100
|
|
98
101
|
current_layer.disables.each do |button|
|
99
102
|
user_operation.unpress_button(button)
|
100
103
|
end
|
101
104
|
|
102
|
-
current_layer.left_analog_stick_caps.each do |
|
103
|
-
if
|
104
|
-
|
105
|
+
current_layer.left_analog_stick_caps.each do |config|
|
106
|
+
if config[:if_pressed].nil? || user_operation.pressing_all_buttons?(config[:if_pressed])
|
107
|
+
config[:force_neutral]&.each do |force_neutral_button|
|
105
108
|
user_operation.unpress_button(force_neutral_button)
|
106
109
|
end
|
107
|
-
user_operation.apply_left_analog_stick_cap(cap:
|
110
|
+
user_operation.apply_left_analog_stick_cap(cap: config[:cap])
|
108
111
|
end
|
109
112
|
end
|
110
113
|
|
@@ -116,7 +119,7 @@ class ProconBypassMan::Procon
|
|
116
119
|
end
|
117
120
|
|
118
121
|
# 押している時だけ連打
|
119
|
-
if options[:if_pressed] && options[:if_pressed]
|
122
|
+
if options[:if_pressed] && user_operation.pressing_all_buttons?(options[:if_pressed])
|
120
123
|
if !status[button]
|
121
124
|
user_operation.unpress_button(button)
|
122
125
|
end
|
@@ -128,16 +131,15 @@ class ProconBypassMan::Procon
|
|
128
131
|
end
|
129
132
|
|
130
133
|
current_layer.remaps.each do |from_button, to_buttons|
|
131
|
-
if user_operation.
|
134
|
+
if user_operation.pressing_button?(from_button)
|
132
135
|
user_operation.unpress_button(from_button)
|
133
|
-
# TODO 2重でpressしないようにしたい
|
134
136
|
to_buttons[:to].each do |to_button|
|
135
137
|
user_operation.press_button(to_button)
|
136
138
|
end
|
137
139
|
end
|
138
140
|
end
|
139
141
|
|
140
|
-
user_operation.binary
|
142
|
+
user_operation.binary.raw
|
141
143
|
end
|
142
144
|
|
143
145
|
private
|
File without changes
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
module RemotePbmAction
|
3
|
+
class RestorePbmSettingAction < BaseAction
|
4
|
+
|
5
|
+
def action_content(args: )
|
6
|
+
require "pbmenv"
|
7
|
+
ProconBypassMan.logger.info "execute RestorePbmSettingAction!"
|
8
|
+
setting = args.dig("setting") or raise(ProconBypassMan::RemotePbmAction::NeedPbmVersionError, "settingが必要です, #{args.inspect}")
|
9
|
+
File.write(
|
10
|
+
ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path,
|
11
|
+
setting.to_yaml,
|
12
|
+
)
|
13
|
+
ProconBypassMan.hot_reload!
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def before_action_callback
|
19
|
+
be_in_progress
|
20
|
+
end
|
21
|
+
|
22
|
+
def after_action_callback
|
23
|
+
be_processed
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
File without changes
|
@@ -4,12 +4,13 @@ module ProconBypassMan
|
|
4
4
|
require "procon_bypass_man/remote_pbm_action/change_pbm_version_action"
|
5
5
|
require "procon_bypass_man/remote_pbm_action/reboot_os_action"
|
6
6
|
require "procon_bypass_man/remote_pbm_action/stop_pbm_action"
|
7
|
-
require "procon_bypass_man/remote_pbm_action/
|
7
|
+
require "procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb"
|
8
|
+
require "procon_bypass_man/remote_pbm_action/commands/update_remote_pbm_action_status_command"
|
8
9
|
|
9
10
|
ACTION_CHANGE_PBM_VERSION = "change_pbm_version"
|
10
11
|
ACTION_REBOOT_OS = "reboot_os"
|
11
12
|
ACTION_STOP_PBM = "stop_pbm"
|
12
|
-
ACTION_RESTORE_SETTING = "
|
13
|
+
ACTION_RESTORE_SETTING = "restore_pbm_setting"
|
13
14
|
|
14
15
|
ACTIONS = [
|
15
16
|
ACTION_CHANGE_PBM_VERSION,
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative "io_monitor"
|
2
|
-
require_relative "boot_message"
|
3
2
|
|
4
3
|
class ProconBypassMan::Runner
|
5
4
|
class InterruptForRestart < StandardError; end
|
@@ -27,10 +26,11 @@ class ProconBypassMan::Runner
|
|
27
26
|
|
28
27
|
loop do
|
29
28
|
$will_terminate_token = false
|
30
|
-
#
|
29
|
+
# NOTE メインプロセスではThreadをいくつか起動しているので念のためパフォーマンスを優先するためにforkしていく
|
31
30
|
main_loop_pid = Kernel.fork { ProconBypassMan::BypassCommand.new(gadget: @gadget, procon: @procon).execute }
|
32
31
|
|
33
32
|
begin
|
33
|
+
# TODO 小プロセスが消滅した時に、メインプロセスは生き続けてしまい、何もできなくなる問題がある
|
34
34
|
while(readable_io = IO.select([self_read]))
|
35
35
|
signal = readable_io.first[0].gets.strip
|
36
36
|
handle_signal(signal)
|
@@ -39,14 +39,14 @@ class ProconBypassMan::Runner
|
|
39
39
|
$will_terminate_token = true
|
40
40
|
Process.kill("TERM", main_loop_pid)
|
41
41
|
Process.wait
|
42
|
-
ProconBypassMan.
|
42
|
+
ProconBypassMan::PrintMessageCommand.execute(text: "Reloading config file")
|
43
43
|
begin
|
44
44
|
ProconBypassMan::ButtonsSettingConfiguration::Loader.reload_setting
|
45
45
|
ProconBypassMan::SendReloadConfigEventCommand.execute
|
46
46
|
rescue ProconBypassMan::CouldNotLoadConfigError
|
47
47
|
ProconBypassMan::SendErrorCommand.execute(error: "設定ファイルが不正です。再読み込みができませんでした")
|
48
48
|
end
|
49
|
-
ProconBypassMan.
|
49
|
+
ProconBypassMan::PrintMessageCommand.execute(text: "バイパス処理を再開します")
|
50
50
|
rescue Interrupt
|
51
51
|
$will_terminate_token = true
|
52
52
|
Process.kill("TERM", main_loop_pid)
|
@@ -68,13 +68,6 @@ module ProconBypassMan
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def self.register_schedules
|
71
|
-
register(
|
72
|
-
schedule: Schedule.new(
|
73
|
-
klass: ProconBypassMan::FetchAndRunRemotePbmActionJob,
|
74
|
-
args: [],
|
75
|
-
interval: 3,
|
76
|
-
)
|
77
|
-
)
|
78
71
|
register(
|
79
72
|
schedule: Schedule.new(
|
80
73
|
klass: ProconBypassMan::SyncDeviceStatsJob,
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
module Websocket
|
3
|
+
module PbmJobClient
|
4
|
+
CHANNEL = 'PbmJobChannel'
|
5
|
+
|
6
|
+
def self.start!
|
7
|
+
return unless ProconBypassMan.config.enable_ws?
|
8
|
+
|
9
|
+
Thread.start do
|
10
|
+
loop do
|
11
|
+
run
|
12
|
+
rescue
|
13
|
+
retry
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.run
|
19
|
+
EventMachine.run do
|
20
|
+
client = ActionCableClient.new(
|
21
|
+
ProconBypassMan.config.current_ws_server_url, {
|
22
|
+
channel: CHANNEL, device_id: ProconBypassMan.device_id,
|
23
|
+
}
|
24
|
+
)
|
25
|
+
|
26
|
+
client.connected {
|
27
|
+
ProconBypassMan.logger.info('successfully connected in ProconBypassMan::Websocket::PbmJobClient')
|
28
|
+
}
|
29
|
+
client.subscribed { |msg|
|
30
|
+
puts({ event: :subscribed, msg: msg })
|
31
|
+
ProconBypassMan::SyncDeviceStatsJob.perform(ProconBypassMan::DeviceStatus.current)
|
32
|
+
}
|
33
|
+
|
34
|
+
client.received do |data|
|
35
|
+
ProconBypassMan.logger.info(data)
|
36
|
+
|
37
|
+
dispatch(data: data, client: client)
|
38
|
+
rescue => e
|
39
|
+
ProconBypassMan::SendErrorCommand.execute(error: e)
|
40
|
+
end
|
41
|
+
|
42
|
+
client.disconnected {
|
43
|
+
puts :disconnected
|
44
|
+
client.reconnect!
|
45
|
+
sleep 2
|
46
|
+
}
|
47
|
+
client.errored { |msg| puts :errored; puts msg }
|
48
|
+
client.pinged { |msg|
|
49
|
+
ProconBypassMan.cache.fetch key: 'ws_pinged', expires_in: 10 do
|
50
|
+
ProconBypassMan.logger.info(msg)
|
51
|
+
end
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# @param [Hash] data
|
57
|
+
def self.dispatch(data: , client: )
|
58
|
+
pbm_job_hash = data.dig("message")
|
59
|
+
if pbm_job_hash['action'] == "ping"
|
60
|
+
client.perform('pong', { device_id: ProconBypassMan.device_id, message: 'hello from pbm' })
|
61
|
+
else
|
62
|
+
validate_and_run(data: data)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# @raise [ProconBypassMan::RemotePbmActionObject::ValidationError]
|
67
|
+
# @param [Hash] data
|
68
|
+
# @return [Void]
|
69
|
+
def self.validate_and_run(data: )
|
70
|
+
pbm_job_hash = data.dig("message")
|
71
|
+
begin
|
72
|
+
pbm_job_object = ProconBypassMan::RemotePbmActionObject.new(action: pbm_job_hash["action"],
|
73
|
+
status: pbm_job_hash["status"],
|
74
|
+
uuid: pbm_job_hash["uuid"],
|
75
|
+
created_at: pbm_job_hash["created_at"],
|
76
|
+
job_args: pbm_job_hash["args"])
|
77
|
+
pbm_job_object.validate!
|
78
|
+
rescue ProconBypassMan::RemotePbmActionObject::ValidationError => e
|
79
|
+
raise
|
80
|
+
end
|
81
|
+
|
82
|
+
ProconBypassMan::RunRemotePbmActionDispatchCommand.execute(
|
83
|
+
action: pbm_job_object.action,
|
84
|
+
uuid: pbm_job_object.uuid,
|
85
|
+
job_args: pbm_job_object.job_args
|
86
|
+
)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|