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,8 +66,7 @@ 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()
@@ -94,6 +93,10 @@ if plc_state.init_ok then
else else
log._warning("booted in a degraded state, awaiting peripheral connections...") log._warning("booted in a degraded state, awaiting peripheral connections...")
end end
end
-- initialize PLC
init()
-- event loop -- event loop
while true do while true do
@@ -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