changed to SCADA terminology, changed RCaSS to reactor PLC, maybe changed other things

This commit is contained in:
Mikayla Fischler 2022-01-13 10:06:55 -05:00
parent ab49322fec
commit 3b492ead92
15 changed files with 10 additions and 196 deletions

View File

@ -1,157 +0,0 @@
function server_comms()
local self = {
reactor_struct_cache = nil
}
local record_struct = function (id, mek_data)
end
-- send the structure data by request to pocket computers
local send_struct = function ()
end
local command_waste = function ()
end
end
function rcass_comms(id, modem, local_port, server_port, reactor)
local self = {
_id = id,
_modem = modem,
_server = server_port,
_local = local_port,
_reactor = reactor,
_status_cache = nil,
_send = function (msg)
self._modem.transmit(self._server, self._local, msg)
end
}
local _send = function (msg)
self._modem.transmit(self._server, self._local, msg)
end
-- variable reactor status information, excluding heating rate
local _reactor_status = function ()
return {
status = self._reactor.getStatus(),
burn_rate = self._reactor.getBurnRate(),
act_burn_r = self._reactor.getActualBurnRate(),
temp = self._reactor.getTemperature(),
damage = self._reactor.getDamagePercent(),
boil_eff = self._reactor.getBoilEfficiency(),
env_loss = self._reactor.getEnvironmentalLoss(),
fuel = self._reactor.getFuel(),
fuel_need = self._reactor.getFuelNeeded(),
fuel_fill = self._reactor.getFuelFilledPercentage(),
waste = self._reactor.getWaste(),
waste_need = self._reactor.getWasteNeeded(),
waste_fill = self._reactor.getWasteFilledPercentage(),
cool_type = self._reactor.getCoolant()['name'],
cool_amnt = self._reactor.getCoolant()['amount'],
cool_need = self._reactor.getCoolantNeeded(),
cool_fill = self._reactor.getCoolantFilledPercentage(),
hcool_type = self._reactor.getHeatedCoolant()['name'],
hcool_amnt = self._reactor.getHeatedCoolant()['amount'],
hcool_need = self._reactor.getHeatedCoolantNeeded(),
hcool_fill = self._reactor.getHeatedCoolantFilledPercentage()
}
end
local _status_changed = function ()
local status = self._reactor_status()
local changed = false
for key, value in pairs() do
if value ~= _status_cache[key] then
changed = true
break
end
end
return changed
end
-- attempt to establish link with
local send_link_req = function ()
local linking_data = {
id = self._id,
type = "link_req"
}
_send(linking_data)
end
-- send structure properties (these should not change)
-- server will cache these
local send_struct = function ()
local mek_data = {
heat_cap = self._reactor.getHeatCapacity(),
fuel_asm = self._reactor.getFuelAssemblies(),
fuel_sa = self._reactor.getFuelSurfaceArea(),
fuel_cap = self._reactor.getFuelCapacity(),
waste_cap = self._reactor.getWasteCapacity(),
cool_cap = self._reactor.getCoolantCapacity(),
hcool_cap = self._reactor.getHeatedCoolantCapacity(),
max_burn = self._reactor.getMaxBurnRate()
}
local struct_packet = {
id = self._id,
type = "struct_data",
mek_data = mek_data
}
_send(struct_packet)
end
-- send live status information
local send_status = function ()
local mek_data = self._reactor_status()
local sys_data = {
timestamp = os.time(),
control_state = false,
overridden = false,
faults = {},
waste_production = "antimatter" -- "plutonium", "polonium", "antimatter"
}
end
local send_keep_alive = function ()
-- heating rate is volatile, so it is skipped in status
-- send it with keep alive packets
local mek_data = {
heating_rate = self._reactor.getHeatingRate()
}
-- basic keep alive packet to server
local keep_alive_packet = {
id = self._id,
type = "keep_alive",
timestamp = os.time(),
mek_data = mek_data
}
_send(keep_alive_packet)
end
local handle_link = function (packet)
if packet.type == "link_response" then
return packet.accepted
else
return "wrong_type"
end
end
return {
send_link_req = send_link_req,
send_struct = send_struct,
send_status = send_status,
send_keep_alive = send_keep_alive,
handle_link = handle_link
}
end

View File

@ -1,29 +0,0 @@
-- timestamped print
function print_ts(message)
term.write(os.date("[%H:%M:%S] ") .. message)
end
-- ComputerCraft OS Timer based Watchdog
-- triggers a timer event if not fed within 'timeout' seconds
function new_watchdog(timeout)
local self = {
_timeout = timeout,
_wd_timer = os.startTimer(_timeout)
}
local get_timer = function ()
return self._wd_timer
end
local feed = function ()
if self._wd_timer ~= nil then
os.cancelTimer(self._wd_timer)
end
self._wd_timer = os.startTimer(self._timeout)
end
return {
get_timer = get_timer,
feed = feed
}
end

View File

View File

@ -1,6 +1,6 @@
-- unique reactor ID
REACTOR_ID = 1
-- port to send packets TO server
SERVER_PORT = 1000
SERVER_PORT = 16000
-- port to listen to incoming packets FROM server
LISTEN_PORT = 1001
LISTEN_PORT = 14001

View File

@ -1,20 +1,20 @@
--
-- RCaSS: Reactor Controller and Safety Subsystem
-- Reactor Programmable Logic Controller
--
os.loadAPI("common/util.lua")
os.loadAPI("common/comms.lua")
os.loadAPI("rcass/config.lua")
os.loadAPI("rcass/safety.lua")
os.loadAPI("scada-common/util.lua")
os.loadAPI("scada-common/comms.lua")
os.loadAPI("reactor-plc/config.lua")
os.loadAPI("reactor-plc/safety.lua")
local RCASS_VERSION = "alpha-v0.1"
local R_PLC_VERSION = "alpha-v0.1"
local print_ts = util.print_ts
local reactor = peripheral.find("fissionReactor")
local modem = peripheral.find("modem")
print(">> RCaSS " .. RCASS_VERSION .. " <<")
print(">> Reactor PLC " .. R_PLC_VERSION .. " <<")
-- we need a reactor and a modem
if reactor == nil then
@ -41,7 +41,7 @@ if not modem.isOpen(config.LISTEN_PORT) then
modem.open(config.LISTEN_PORT)
end
local comms = comms.rcass_comms(config.REACTOR_ID, modem, config.LISTEN_PORT, config.SERVER_PORT, reactor)
local comms = comms.rplc_comms(config.REACTOR_ID, modem, config.LISTEN_PORT, config.SERVER_PORT, reactor)
-- attempt server connection
local linked = false