Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local serialization = require("serialization")
- local modem = component.modem
- local portNumber = 2805
- local term = require("term")
- -- Max energy in a reactor's internal cell
- local emax=10000000
- -- wrap everything in an exception handler
- local ok,msg=pcall(function ()
- local r
- local m
- local redirected=false
- local p
- function setupDevs()
- r=assert(component.br_reactor)
- if (not r.getConnected()) then
- return nil, "Computer port not connected to a valid reactor"
- end
- --if (r.getNumberOfControlRods() <1) then
- -- return nil, "Reactor seems invalid"
- --end
- r.getEnergyPercent = function ()
- return math.floor(1000 * r.getEnergyStored() / emax)/10
- end
- if r.nativeEPLT then
- r.getEnergyProducedLastTick = r.nativeEPLT
- end
- r.nativeEPLT = r.getEnergyProducedLastTick
- r.getEnergyProducedLastTick = function ()
- return math.floor(r.nativeEPLT()*1000)/1000
- end
- term.setCursorBlink(false)
- end
- function ft ()
- -- local d=os.day()
- -- local t=os.time()
- -- local h=math.floor(t)
- -- local m=math.floor((t-h)*60)
- -- return string.format("Day %d, %02d:%02d",d,h,m)
- return "timestamp..."
- end
- function log (msg)
- local stamp=ft()
- print (stamp..": "..msg)
- end
- function tableWidth(t)
- local width=0
- for _,v in pairs(t) do
- if #v>width then width=#v end
- end
- return width + 4
- end
- function ljust(s,w)
- local pad=w-#s
- return s .. string.rep(" ",pad)
- end
- function rjust(s,w)
- local pad=w-#s
- return string.rep(" ",pad) .. s
- end
- function display()
- local floatUnits = {"%","C","mB","RF/t"}
- term.clear()
- term.setCursor(1,1)
- msg = {name="Reactor A - TEST"}
- msg["metric"] = {}
- print("Reactor Status")
- print("")
- local funcs={"Connected","Active","NumberOfControlRods","EnergyStored","EnergyPercent","FuelTemperature","CasingTemperature","FuelAmount","WasteAmount","FuelAmountMax", "FuelReactivity", "FuelConsumedLastTick", "EnergyProducedLastTick"}
- local units={"","","","RF","%","C","C","mB","mB","mB","%","mB", "RF/t"}
- local values={}
- for _,v in pairs(funcs) do
- thisVal = tostring(r["get"..v]())
- values[#values+1] = thisVal
- msg["metric"][v] = thisVal
- end
- local funcW=tableWidth(funcs)
- local valW=tableWidth(values)
- for i,v in pairs(funcs) do
- print(string.format("%-12s: %s %s", v, values[i], units[i]))
- end
- modem.broadcast(2805, serialization.serialize(msg))
- end
- log("Starting")
- setupDevs()
- while true do
- local e=r.getEnergyStored()
- local p=math.floor(100*e/emax)
- local a=p<100
- local elt=r.getEnergyProducedLastTick()
- display()
- r.setAllControlRodLevels(p)
- r.setActive(a)
- os.sleep(1)
- end
- end)
- error(msg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement