Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- remote_console.lua (CC:Tweaked)
- -- Advanced wireless computer. Mirrors turtle logs and sends basic controls.
- -- Keys: [P]=pause [R]=resume [S]=stop [Q]=quit viewer
- local PROTO = "tmine.v1"
- local function openAnyModem()
- for _,side in ipairs(rs.getSides()) do
- if peripheral.getType(side) == "modem" then
- local m = peripheral.wrap(side)
- if m and m.isWireless and m.isWireless() then
- rednet.open(side)
- return true
- end
- end
- end
- return false
- end
- assert(openAnyModem(), "No wireless modem found/opened")
- local filterID = nil
- term.clear(); term.setCursorPos(1,1)
- print("Turtle Log Console")
- print("Optional: enter a Turtle computer ID to filter, or press Enter:")
- local line = read()
- if line and line:match("%d+") then filterID = tonumber(line) end
- term.clear(); term.setCursorPos(1,1)
- print("Listening for logs... [P]=pause [R]=resume [S]=stop [Q]=quit")
- local function sendCmd(cmd)
- rednet.broadcast({cmd=cmd}, PROTO)
- end
- local function keyTask()
- while true do
- local e, key = os.pullEvent("key")
- if key == keys.p then sendCmd("pause")
- elseif key == keys.r then sendCmd("resume")
- elseif key == keys.s then sendCmd("stop")
- elseif key == keys.q then break
- end
- end
- end
- local function logTask()
- while true do
- local _, sender, payload, proto = os.pullEvent("rednet_message")
- if proto == PROTO and type(payload)=="table" and payload.msg then
- if not filterID or filterID == payload.id then
- local ts = os.date("!%H:%M:%S", math.floor((payload.t or 0)/1000))
- print(("[%s] #%s: %s"):format(ts, tostring(payload.id or "?"), payload.msg))
- end
- end
- end
- end
- parallel.waitForAny(keyTask, logTask)
- print("Console closed.")
Advertisement
Add Comment
Please, Sign In to add comment