local clientID
local power
local fuel
local waste
local fuelCap
local burnRate
local temp
local reactivity
local steam
local steamOut
local coolant
local coolantCap
local conRodLevel
local numConRods
local conRods = {}
local refreshRate = 3
local args = {...}
-- Checks that argument 1 always exists and that
-- both are integers
function parseArgs()
if #args < 1 or #args > 2 then
error("Usage: <program> <client ID> [refresh rate]")
end
if tonumber(#args[1]) == nil then
error("Client ID must be a number.")
end
if not args[2] == nil then
if tonumber(#args[2]) == nil then
error("Refresh rate must be a number.")
end
if not #args[2] == nil then
refreshRate = args[2]
end
end
clientID = tonumber(args[1])
end
-- Automatic detection of reactor and modem
function detect()
for per, side in pairs(rs.getSides()) do
if peripheral.isPresent(side) then
if peripheral.getType(side) == "BigReactors-Reactor" then
reactor = peripheral.wrap(side)
elseif peripheral.getType(side) == "modem" then
modem = side
end
end
end
return reactor, modem
end
function round(num, places)
local multi = 10 ^ (places or 0)
return math.floor(num * multi + 0.5) / multi
end
-- Refreshes the status of each control rod
-- in the control rod table
function updateConRodTable(rod, level)
conRods[rod] = level
end
-- Returns reactor stats that are expected to
-- remain static during operation
function getReactorBaseStatus()
numConRods = reactor.getNumberOfControlRods()
fuelCap = reactor.getFuelAmountMax()
coolantCap = reactor.getCoolantAmountMax()
end
-- Returns reactor stats that are constantly
-- changing during operation
function getReactorUpdate()
if reactor.getConnected() then
if reactor.getActive() then
power = 1
else
power = 0
end
else
error("No connection to reactor.")
end
-- For some reason the steam level and
-- coolant level functions are reversed
fuel = reactor.getFuelAmount()
waste = reactor.getWasteAmount()
burnRate = reactor.getFuelConsumedLastTick()
temp = reactor.getFuelTemperature()
steam = reactor.getCoolantAmount()
steamOut = reactor.getEnergyProducedLastTick()
coolant = reactor.getHotFluidAmount()
reactivity = reactor.getFuelReactivity()
end
function sendData()
local data = {
rPower = power,
rFuel = fuel,
rFuelCap = fuelCap,
rWaste = waste,
rBurnRate = burnRate,
rTemp = temp,
rSteam = steam,
rSteamOut = steamOut,
rCoolant = coolant,
rCoolantCap = coolantCap,
rReactivity = reactivity
}
local bundle = textutils.serialize(data)
rednet.send(clientID, bundle, "FSRC")
end
local reactor, modem = detect()
parseArgs()
rednet.open(modem)
getReactorBaseStatus()
while true do
term.clear()
term.setCursorPos(1, 1)
getReactorUpdate()
sendData()
print("Fuel Level : " .. fuel .. " mB [Burning " .. round(burnRate, 2) .. " mB/t]")
print("Waste Level : " .. waste .. " mB")
print("Max Capacity : " .. fuelCap .. " mB")
print("Temperature : " .. round(temp, 0) .. " C")
print("Reactivity : " .. round(reactivity, 0) .. "%")
print("Steam Level : " .. steam .. " mB")
print("Steam Output : " .. steamOut .. " mB/t")
print("Coolant Level : " .. coolant .. " mB")
sleep(refreshRate)
end
Comments