SHOW:
|
|
- or go back to the newest paste.
| 1 | local component, computer = component, computer | |
| 2 | if require then component = require "component" computer = require "computer" end | |
| 3 | - | local wlan = component.proxy(component.list "modem"()) |
| 3 | + | local netcards = {}
|
| 4 | - | local computer_peripheral = component.proxy(component.list "computer"()) |
| 4 | + | for addr in component.list "modem" do table.insert(netcards, component.proxy(addr)) end |
| 5 | - | local reactor = component.proxy(component.list "nc_fusion_reactor"()) |
| 5 | + | local tunnels = {}
|
| 6 | - | local gpu = component.proxy(component.list "gpu"()) |
| 6 | + | for addr in component.list "tunnel" do table.insert(tunnels, component.proxy(addr)) end |
| 7 | - | local screen = component.list "screen"() |
| 7 | + | local computer_id = component.list "computer"() |
| 8 | - | gpu.bind(screen) |
| 8 | + | local computer_peripheral = component.proxy(computer_id) |
| 9 | - | wlan.setWakeMessage("poweron", true)
|
| 9 | + | local computer_sid = computer_id:sub(1, 8) |
| 10 | local eeprom = component.proxy(component.list "eeprom"()) | |
| 11 | - | local function display(txt) |
| 11 | + | |
| 12 | - | local w, h = gpu.getResolution() |
| 12 | + | computer_peripheral.beep(600) |
| 13 | - | gpu.set(1, 1, txt .. (" "):rep(w - #txt))
|
| 13 | + | |
| 14 | local recents = {}
| |
| 15 | ||
| 16 | - | local function sleep(timeout) |
| 16 | + | local PORT = 4096 |
| 17 | - | local deadline = computer.uptime() + (timeout or 0) |
| 17 | + | local DBG_PORT = 4097 |
| 18 | - | repeat |
| 18 | + | |
| 19 | - | computer.pullSignal(deadline - computer.uptime()) |
| 19 | + | for _, card in pairs(netcards) do |
| 20 | - | until computer.uptime() >= deadline |
| 20 | + | card.open(PORT) |
| 21 | card.open(DBG_PORT) | |
| 22 | card.setWakeMessage("poweron", true)
| |
| 23 | if card.setStrength then card.setStrength(math.huge) end | |
| 24 | - | display "Initialized" |
| 24 | + | computer_peripheral.beep(1500) |
| 25 | end | |
| 26 | - | local NC_HEAT_CONSTANT = 1218.76 |
| 26 | + | for _, tun in pairs(tunnels) do tun.setWakeMessage("poweron", true) computer_peripheral.beep(1200) end
|
| 27 | ||
| 28 | - | local last = nil |
| 28 | + | |
| 29 | ||
| 30 | while true do | |
| 31 | - | local target_temp = reactor.getFusionComboHeatVariable() * NC_HEAT_CONSTANT * 1000 |
| 31 | + | local ev, _, _, port, distance, mtxt, mid = computer.pullSignal(5) |
| 32 | - | local temp = reactor.getTemperature() |
| 32 | + | if ev == "modem_message" and type(mid) == "string" and mtxt ~= nil and (port == PORT or port == 0) and not recents[mid] then |
| 33 | - | display(("%f %f"):format(temp / target_temp, reactor.getEfficiency()))
|
| 33 | + | recents[mid] = computer.uptime() + 120 |
| 34 | - | local too_high = temp > target_temp |
| 34 | + | for _, card in pairs(netcards) do |
| 35 | - | if too_high then |
| 35 | + | pcall(card.broadcast, PORT, mtxt, mid, computer_sid) |
| 36 | - | if too_high ~= last then computer_peripheral.beep(800) end |
| 36 | + | end |
| 37 | - | reactor.deactivate() |
| 37 | + | for _, tun in pairs(tunnels) do |
| 38 | - | else |
| 38 | + | pcall(tun.send, mtxt, mid, computer_sid) |
| 39 | - | if too_high ~= last then computer_peripheral.beep(500) end |
| 39 | + | end |
| 40 | - | reactor.activate() |
| 40 | + | |
| 41 | if ev == "modem_message" and type(mtxt) == "string" and port == DBG_PORT and distance < 8 then | |
| 42 | - | last = too_high |
| 42 | + | if mtxt == "ping" then |
| 43 | - | wlan.broadcast(1111, "poweron") |
| 43 | + | computer_peripheral.beep(1000) |
| 44 | - | sleep(0.5) |
| 44 | + | card.broadcast(DBG_PORT, computer_sid) |
| 45 | elseif mtxt == "flash" and type(mid) == "string" then | |
| 46 | computer_peripheral.beep(800) | |
| 47 | eeprom.set(mid) | |
| 48 | end | |
| 49 | end | |
| 50 | local uptime = computer.uptime() | |
| 51 | for mid, deadline in pairs(recents) do | |
| 52 | if uptime > deadline then | |
| 53 | recents[mid] = nil | |
| 54 | end | |
| 55 | end | |
| 56 | end |