Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- settings.load()
- -- #region Setup
- local me_system = peripheral.wrap(settings.get("akw.meSystem"))
- local fuel_type = settings.get("akw.fuelType")
- local recipient_id = settings.get("rednet.recipient")
- local protocol = settings.get("rednet.protocol")
- local modem_side = settings.get("rednet.modemSide")
- local update_table = {
- reactors = {},
- power_lines = {},
- fuel = 0
- }
- local reactors = {}
- for _, id in ipairs({"A", "B", "C", "D"}) do
- reactors[id] = {
- active = settings.get("akw.reactor" .. id .. ".active"),
- rods = {}
- }
- if reactors[id].active then
- update_table.reactors[id] = {
- rods = {},
- name = id
- }
- for j = 1, 4 do
- reactors[id].rods[j] = {
- deactivated = false,
- boiler = peripheral.wrap(settings.get("akw.reactor" .. id .. ".rod" .. j .. ".boiler")),
- battery = peripheral.wrap(settings.get("akw.reactor" .. id .. ".rod" .. j .. ".battery")),
- }
- update_table.reactors[id].rods[j] = {
- name = id..j,
- state = "unknown"
- }
- end
- end
- end
- local power_lines = {}
- for i = 1, 6 do
- power_lines[i] = peripheral.wrap(settings.get("akw.powerLine" .. i))
- update_table.power_lines[i] = {
- name = i,
- power = 0
- }
- end
- rednet.open(modem_side)
- -- #endregion
- -- #region Functions
- local function update_reactor_monitoring()
- for _, reactor_id in ipairs({"A", "B", "C", "D"}) do
- if reactors[reactor_id].active then
- for i = 1, 4 do
- local boiler_state = reactors[reactor_id].rods[i].boiler.getLine(1)
- local generator_state = reactors[reactor_id].rods[i].boiler.getLine(6)
- if string.find(boiler_state, "Max") then
- if string.find(generator_state, "236 RPM") then
- reactors[reactor_id].rods[i].deactivated = false
- update_table.reactors[reactor_id].rods[i].state = "active OK"
- else
- reactors[reactor_id].rods[i].deactivated = true
- update_table.reactors[reactor_id].rods[i].state = "active ERROR"
- end
- elseif string.find(boiler_state, "Idle") and reactors[reactor_id].rods[i].deactivated then
- update_table.reactors[reactor_id].rods[i].state = "deactived ERROR"
- elseif string.find(boiler_state, "Idle") then
- update_table.reactors[reactor_id].rods[i].state = "inactive OK"
- else
- update_table.reactors[reactor_id].rods[i].state = "starting"
- end
- end
- end
- end
- end
- local function update_powerline_monitoring()
- for i = 1, 6 do
- update_table.power_lines[i] = power_lines[i].getAveragePower()
- end
- end
- local function update_fuel_monitoring()
- local fuelInfo = me_system.getItem({name = fuel_type})
- if fuelInfo ~= nil then
- update_table.fuel = fuelInfo.amount
- else
- update_table.fuel = 0
- end
- end
- -- #endregion
- local function send_update()
- print("Sending update via [" .. protocol .. "] to PC" .. recipient_id)
- rednet.send(recipient_id, update_table, protocol)
- print("Update sent")
- end
- local function monitoring_reactor()
- while true do
- print("Fetching metrics...")
- update_reactor_monitoring()
- update_powerline_monitoring()
- update_fuel_monitoring()
- send_update()
- sleep(5)
- end
- end
- monitoring_reactor()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement