Merge remote-tracking branch 'origin/main' into develop_mh
# Conflicts: # app/views/modbus/index.html.erb # app/views/modbus/schedule_edit.html.erb
This commit is contained in:
commit
d33c49d1e1
|
|
@ -1,6 +1,17 @@
|
||||||
class ModbusController < ApplicationController
|
class ModbusController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@schedule = Schedule.all
|
@schedule = Schedule.all
|
||||||
|
@modbus_running = Modbus::PollingService.running?
|
||||||
|
end
|
||||||
|
|
||||||
|
def start
|
||||||
|
Modbus::PollingService.start
|
||||||
|
redirect_to modbus_index_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def stop
|
||||||
|
Modbus::PollingService.stop
|
||||||
|
redirect_to modbus_index_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def schedule_edit
|
def schedule_edit
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ module Modbus
|
||||||
class PollingService
|
class PollingService
|
||||||
class << self
|
class << self
|
||||||
def start
|
def start
|
||||||
return if @thread&.alive?
|
return if $modbus_polling_threads.any?(&:alive?)
|
||||||
|
|
||||||
@thread = Thread.new do
|
thread = Thread.new do
|
||||||
puts "[#{Time.current}] Modbus polling service 시작됨"
|
puts "[#{Time.current}] Modbus polling service 시작됨"
|
||||||
last_logged_hour = nil
|
last_logged_hour = nil
|
||||||
loop do
|
loop do
|
||||||
|
|
@ -32,14 +32,17 @@ module Modbus
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
$modbus_polling_threads << thread
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop
|
def stop
|
||||||
if @thread
|
$modbus_polling_threads.each { |t| t.kill if t.alive? }
|
||||||
@thread.exit
|
$modbus_polling_threads.clear
|
||||||
@thread = nil
|
puts "[#{Time.now}] Modbus polling service 중지됨"
|
||||||
puts "[#{Time.now}] Modbus polling service 중지됨"
|
end
|
||||||
end
|
|
||||||
|
def running?
|
||||||
|
$modbus_polling_threads.any?(&:alive?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,26 +8,11 @@
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="flex flex-col h-full divide-y divide-border-table-border">
|
<% @schedule.each do |s| %>
|
||||||
<div class="flex-1 overflow-y-auto p-4">
|
<div class="flex justify-items-center gap-x-2">
|
||||||
<table class="base-table">
|
<div><%= s.hour %>시</div>
|
||||||
<thead>
|
<div><%= s.temperature %> °C</div>
|
||||||
<tr>
|
|
||||||
<th>시간</th>
|
|
||||||
<th>온도</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<% @schedule.each do |s| %>
|
|
||||||
<tr>
|
|
||||||
<td><%= s.hour %>시</td>
|
|
||||||
<td><%= s.temperature %> °C</td>
|
|
||||||
</tr>
|
|
||||||
<% end %>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="flex p-4">
|
<% end %>
|
||||||
<%= link_to "수정", "/modbus/schedule_edit", class: "btn bg-default-slate" %>
|
|
||||||
</div>
|
<%= link_to "수정", "/modbus/schedule_edit", class: "btn btn-primary" %>
|
||||||
</div>
|
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,14 @@
|
||||||
<%= form_with url: "/modbus/schedule_edit_update", method: :post, class: 'flex flex-col h-full divide-y divide-border-table-border' do %>
|
<%= form_with url: "/modbus/schedule_edit_update", method: :post do %>
|
||||||
<div class="flex-1 overflow-y-auto p-4">
|
<% @schedule.each do |s| %>
|
||||||
<table class="base-table">
|
<div class="flex justify-items-center gap-x-2 pb-2">
|
||||||
<thead>
|
<div><%= s.hour %>시</div>
|
||||||
<tr>
|
<div>
|
||||||
<th>시간</th>
|
<%= number_field_tag "schedule[#{s.id}][temperature]", s.temperature, step: "0.1", inputmode: "decimal", class: "border px-2 py-1 rounded" %> °C
|
||||||
<th>온도</th>
|
</div>
|
||||||
</tr>
|
</div>
|
||||||
</thead>
|
<% end %>
|
||||||
<tbody>
|
|
||||||
<% @schedule.each do |s| %>
|
|
||||||
<tr>
|
|
||||||
<td><%= s.hour %>시</td>
|
|
||||||
<td><%= number_field_tag "schedule[#{s.id}][temperature]", s.temperature, step: "0.1", inputmode: "decimal", class: "border px-2 py-1 rounded" %> °C</td>
|
|
||||||
</tr>
|
|
||||||
<% end %>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex p-4">
|
<div class="pt-4">
|
||||||
<%= submit_tag "업데이트", class: "btn bg-primary" %>
|
<%= submit_tag "업데이트", class: "bg-blue-500 text-white px-4 py-2 rounded" %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
$modbus_polling_threads ||= []
|
||||||
|
|
||||||
Rails.application.config.after_initialize do
|
Rails.application.config.after_initialize do
|
||||||
Modbus::PollingService.start
|
Modbus::PollingService.start
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,8 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
resources :modbus do
|
resources :modbus do
|
||||||
collection do
|
collection do
|
||||||
get "start"
|
post "start"
|
||||||
get "stop"
|
post "stop"
|
||||||
get "status"
|
|
||||||
get "schedule_edit"
|
get "schedule_edit"
|
||||||
post "schedule_edit_update"
|
post "schedule_edit_update"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,6 @@
|
||||||
# MovieGenre.find_or_create_by!(name: genre_name)
|
# MovieGenre.find_or_create_by!(name: genre_name)
|
||||||
# end
|
# end
|
||||||
|
|
||||||
(0..23).each_with_index do |h, index|
|
(0..23).each do | h |
|
||||||
Schedule.create!(hour: h, temperature: index)
|
Schedule.create!(hour: h, temperature: 15.0)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue