모드버스 cli 코드 통합
This commit is contained in:
@@ -22,22 +22,31 @@ module Modbus
|
||||
private
|
||||
def apply_schedule(schedule)
|
||||
if schedule.is_active
|
||||
run_script("on_off.rb", "#{schedule.controller.station_id}", "0", "[Schedule] #{schedule.controller.name} ON")
|
||||
run_script(
|
||||
"power",
|
||||
"#{schedule.controller.station_id}",
|
||||
"0",
|
||||
"[Schedule] #{schedule.controller.name} ON"
|
||||
)
|
||||
sleep 2
|
||||
run_script(
|
||||
"serial.rb",
|
||||
"temp",
|
||||
"#{schedule.controller.station_id}",
|
||||
(schedule.temperature * 10).to_i.to_s,
|
||||
"[Schedule] #{schedule.controller.name} #{format('%02d:%02d', schedule.hour, schedule.minute)} → #{schedule.temperature}°C"
|
||||
)
|
||||
else
|
||||
run_script("on_off.rb", "#{schedule.controller.station_id}", "1", "[Schedule] #{schedule.controller.name} OFF")
|
||||
run_script(
|
||||
"power",
|
||||
"#{schedule.controller.station_id}",
|
||||
"1",
|
||||
"[Schedule] #{schedule.controller.name} OFF"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def run_script(file, controller_id, value, success_msg)
|
||||
path = Rails.root.join(file)
|
||||
if system("ruby", path.to_s, controller_id, value)
|
||||
def run_script(mode, controller_id, value, success_msg)
|
||||
if system("ruby", "modbus.rb", mode, controller_id, value)
|
||||
puts success_msg
|
||||
Rails.logger.info success_msg
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user