fixed bugs and removed goto as lua 5.1 does not have goto

This commit is contained in:
Mikayla Fischler
2022-04-05 16:09:29 -04:00
parent 5b32f83890
commit f24b214229
2 changed files with 33 additions and 30 deletions

View File

@@ -42,7 +42,7 @@ function iss_init(reactor)
self.reactor.scram() self.reactor.scram()
end end
local first_trip = ~was_tripped and self.tripped local first_trip = not was_tripped and self.tripped
return self.tripped, status, first_trip return self.tripped, status, first_trip
end end
@@ -507,7 +507,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
id = self.id, id = self.id,
type = RPLC_TYPES.STATUS, type = RPLC_TYPES.STATUS,
timestamp = os.time(), timestamp = os.time(),
control_state = ~self.scrammed, control_state = not self.scrammed,
overridden = overridden, overridden = overridden,
heating_rate = self.reactor.getHeatingRate(), heating_rate = self.reactor.getHeatingRate(),
mek_data = mek_data mek_data = mek_data

View File

@@ -7,10 +7,10 @@ os.loadAPI("scada-common/util.lua")
os.loadAPI("scada-common/ppm.lua") os.loadAPI("scada-common/ppm.lua")
os.loadAPI("scada-common/comms.lua") os.loadAPI("scada-common/comms.lua")
os.loadAPI("reactor-plc/config.lua") os.loadAPI("config.lua")
os.loadAPI("reactor-plc/plc.lua") os.loadAPI("plc.lua")
local R_PLC_VERSION = "alpha-v0.1.0" local R_PLC_VERSION = "alpha-v0.1.1"
local print_ts = util.print_ts local print_ts = util.print_ts
@@ -66,35 +66,38 @@ local LINK_TICKS = 20
local loop_tick = nil local loop_tick = nil
local ticks_to_update = LINK_TICKS -- start by linking local ticks_to_update = LINK_TICKS -- start by linking
-- initialize PLC function init()
::init:: if plc_state.init_ok then
if plc_state.init_ok then -- just booting up, no fission allowed (neutrons stay put thanks)
-- just booting up, no fission allowed (neutrons stay put thanks) reactor.scram()
reactor.scram()
-- init internal safety system -- init internal safety system
iss = plc.iss_init(reactor) iss = plc.iss_init(reactor)
log._debug("iss init") log._debug("iss init")
if networked then if networked then
-- start comms -- start comms
plc_comms = plc.comms_init(config.REACTOR_ID, modem, config.LISTEN_PORT, config.SERVER_PORT, reactor, iss) plc_comms = plc.comms_init(config.REACTOR_ID, modem, config.LISTEN_PORT, config.SERVER_PORT, reactor, iss)
log._debug("comms init") log._debug("comms init")
-- comms watchdog, 3 second timeout -- comms watchdog, 3 second timeout
conn_watchdog = watchdog.new_watchdog(3) conn_watchdog = watchdog.new_watchdog(3)
log._debug("conn watchdog started") log._debug("conn watchdog started")
else
log._debug("running without networking")
end
-- loop clock (10Hz, 2 ticks)
loop_tick = os.startTimer(0.05)
log._debug("loop clock started")
else else
log._debug("running without networking") log._warning("booted in a degraded state, awaiting peripheral connections...")
end end
-- loop clock (10Hz, 2 ticks)
loop_tick = os.startTimer(0.05)
log._debug("loop clock started")
else
log._warning("booted in a degraded state, awaiting peripheral connections...")
end end
-- initialize PLC
init()
-- event loop -- event loop
while true do while true do
local event, param1, param2, param3, param4, param5 = os.pullEventRaw() local event, param1, param2, param3, param4, param5 = os.pullEventRaw()
@@ -156,7 +159,7 @@ while true do
end end
-- determine if we are still in a degraded state -- determine if we are still in a degraded state
if not networked or get_device("modem") not nil then if not networked or get_device("modem") ~= nil then
plc_state.degraded = false plc_state.degraded = false
end end
elseif networked and device.type == "modem" then elseif networked and device.type == "modem" then
@@ -170,14 +173,14 @@ while true do
plc_state.no_modem = false plc_state.no_modem = false
-- determine if we are still in a degraded state -- determine if we are still in a degraded state
if ppm.get_device("fissionReactor") not nil then if ppm.get_device("fissionReactor") ~= nil then
plc_state.degraded = false plc_state.degraded = false
end end
end end
if not plc_state.init_ok and not plc_state.degraded then if not plc_state.init_ok and not plc_state.degraded then
plc_state.init_ok = false plc_state.init_ok = false
goto init init()
end end
end end