Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --computercraft
- --rednet console interactive debugger by drPepper
- -- "THE BEER-WARE LICENSE"
- -- drPepper@KOPROKUBACH wrote this file. As long as you retain this notice you
- -- can do whatever you want with this stuff. If we meet some day, in-game or IRL,
- -- and you think this stuff is worth it, you can give me a beer in return
- --resume table
- rt = {}
- --modem
- rt.modemSide = "bottom"
- rt.channelSend = 211
- rt.channelReceive = 210
- --pastebin entry for self-update
- rt.pastebin = "pbYLEtsC"
- --assume modem messages are serialized tables
- rt.messagesTables = true
- function ReadResume()
- if not fs.exists("resume.f") then
- print("Trying to resume without resume file, aborting...")
- return
- end
- local file = fs.open("resume.f","r")
- local sT = file.readAll()
- rt = textutils.unserialize(sT)
- file.close()
- return
- end
- function WriteResume()
- local file = fs.open("resume.f","w")
- local sT = textutils.serialize(rt)
- file.write(sT)
- file.close()
- return
- end
- function openChannel(n)
- modem.open(n)
- while modem.isOpen(n)== false do
- print("opening channel "..n.."...\n")
- sleep(1)
- modem.open(n)
- end
- end
- --operation
- --check resume file and read from it
- if fs.exists("resume.f") then
- --resuming
- ReadResume()
- else
- WriteResume()
- end
- --opening
- modem = peripheral.wrap(rt.modemSide)
- while modem==nil do
- print("wrapping...\n")
- sleep(1)
- modem = peripheral.wrap(rt.modemSide)
- end
- openChannel(rt.channelReceive)
- openChannel(111)
- term.clear()
- print("Rednet Debugger by DrPepper")
- --main loop
- while true do
- print("S - send string, L - listen, U - update, P - send packet")
- local event, keycode = os.pullEvent("key")
- if keycode == 31 then
- --send string
- print("Enter a string to send")
- local message = io.read()
- modem.transmit(rt.channelSend, rt.channelReceive, message)
- elseif keycode == 38 then
- --listen
- print("Listening on channel "..rt.channelReceive.."\nX to stop")
- local run = true
- while run do
- local event, p1, p2, p3, p4, p5 = os.pullEvent()
- if event == "key" then
- if p1 == 45 then
- --X key pressed
- run = false
- break
- else
- print("X to stop listening")
- end
- elseif event == "modem_message" then
- print(tostring(os.time()).." received on ch "..tostring(p2))
- if (rt.messagesTables == true) then
- local messageT = textutils.unserialize(p4)
- for key,value in pairs( messageT ) do
- print(tostring(key)..": "..tostring(value))
- end
- else
- print(p4)
- end
- end
- end
- elseif keycode == 22 then
- --update
- fs.delete("resume.f")
- shell.run("rm", "startup")
- shell.run("pastebin", "get "..rt.pastebin.." startup")
- os.reboot()
- elseif keycode == 25 then
- local packetT =
- {
- target = "BROADCAST",
- command = "PEXECUTE",
- pCommand = "emitBeam",
- pParams = "0, 0, 10",
- delay = 3
- }
- print("sending on channel "..rt.channelSend)
- modem.transmit(rt.channelSend, rt.channelReceive, textutils.serialize(packetT))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement