mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
fixed RTU comms bad function calls, fixed loop clock, changed terminate logic/prints
This commit is contained in:
parent
2278469a8b
commit
91079eeb78
@ -180,7 +180,7 @@ function rtu_comms(modem, local_port, server_port)
|
|||||||
if packet.unit_id <= #units then
|
if packet.unit_id <= #units then
|
||||||
local unit = units[packet.unit_id]
|
local unit = units[packet.unit_id]
|
||||||
local return_code, response = unit.modbus_io.handle_packet(packet)
|
local return_code, response = unit.modbus_io.handle_packet(packet)
|
||||||
_send(response, PROTOCOLS.MODBUS_TCP)
|
_send(PROTOCOLS.MODBUS_TCP, response)
|
||||||
|
|
||||||
if not return_code then
|
if not return_code then
|
||||||
log._warning("MODBUS operation failed")
|
log._warning("MODBUS operation failed")
|
||||||
@ -249,7 +249,7 @@ function rtu_comms(modem, local_port, server_port)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
_send(advertisement, PROTOCOLS.SCADA_MGMT)
|
_send(PROTOCOLS.SCADA_MGMT, advertisement)
|
||||||
end
|
end
|
||||||
|
|
||||||
local send_heartbeat = function ()
|
local send_heartbeat = function ()
|
||||||
@ -257,7 +257,7 @@ function rtu_comms(modem, local_port, server_port)
|
|||||||
type = SCADA_MGMT_TYPES.RTU_HEARTBEAT
|
type = SCADA_MGMT_TYPES.RTU_HEARTBEAT
|
||||||
}
|
}
|
||||||
|
|
||||||
_send(heartbeat, PROTOCOLS.SCADA_MGMT)
|
_send(PROTOCOLS.SCADA_MGMT, heartbeat)
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -17,7 +17,7 @@ os.loadAPI("dev/boiler_rtu.lua")
|
|||||||
os.loadAPI("dev/imatrix_rtu.lua")
|
os.loadAPI("dev/imatrix_rtu.lua")
|
||||||
os.loadAPI("dev/turbine_rtu.lua")
|
os.loadAPI("dev/turbine_rtu.lua")
|
||||||
|
|
||||||
local RTU_VERSION = "alpha-v0.1.3"
|
local RTU_VERSION = "alpha-v0.1.4"
|
||||||
|
|
||||||
local print = util.print
|
local print = util.print
|
||||||
local println = util.println
|
local println = util.println
|
||||||
@ -173,7 +173,7 @@ end
|
|||||||
----------------------------------------
|
----------------------------------------
|
||||||
|
|
||||||
-- advertisement/heartbeat clock (every 2 seconds)
|
-- advertisement/heartbeat clock (every 2 seconds)
|
||||||
local loop_tick = os.startTimer(2)
|
local loop_clock = os.startTimer(2)
|
||||||
|
|
||||||
-- event loop
|
-- event loop
|
||||||
while true do
|
while true do
|
||||||
@ -217,7 +217,7 @@ while true do
|
|||||||
println_ts("reconnected the " .. unit.type .. " on interface " .. unit.name)
|
println_ts("reconnected the " .. unit.type .. " on interface " .. unit.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif event == "timer" and param1 == loop_tick then
|
elseif event == "timer" and param1 == loop_clock then
|
||||||
-- period tick, if we are linked send heartbeat, if not send advertisement
|
-- period tick, if we are linked send heartbeat, if not send advertisement
|
||||||
if linked then
|
if linked then
|
||||||
rtu_comms.send_heartbeat()
|
rtu_comms.send_heartbeat()
|
||||||
@ -225,6 +225,9 @@ while true do
|
|||||||
-- advertise units
|
-- advertise units
|
||||||
rtu_comms.send_advertisement(units)
|
rtu_comms.send_advertisement(units)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- start next clock timer
|
||||||
|
loop_clock = os.startTimer(2)
|
||||||
elseif event == "modem_message" then
|
elseif event == "modem_message" then
|
||||||
-- got a packet
|
-- got a packet
|
||||||
local link_ref = { linked = linked }
|
local link_ref = { linked = linked }
|
||||||
@ -235,7 +238,10 @@ while true do
|
|||||||
-- if linked, stop sending advertisements
|
-- if linked, stop sending advertisements
|
||||||
linked = link_ref.linked
|
linked = link_ref.linked
|
||||||
elseif event == "terminate" then
|
elseif event == "terminate" then
|
||||||
println_ts("exiting...")
|
log._warning("terminate requested, exiting...")
|
||||||
return
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
println_ts("exited")
|
||||||
|
log._info("exited")
|
||||||
|
Loading…
Reference in New Issue
Block a user