Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modem = peripheral.find("modem")
- modem.open(5296)
- db = {}
- commands = {
- alert = function(input)
- assert(type(input) == "string", "helloWorld expects a string for its input")
- print("ALERT: " .. input)
- return true
- end,
- updateStatus = function(id, dataObj)
- assert(type(id) == "number", "updateStatus expects an int for \"id\"")
- assert(type(dataObj) == "table", "updateStatus expects a table for \"dataObj\"")
- print(id)
- db[id] = dataObj
- end,
- requestTransport = function(departure, destination)
- assert(type(departure) == "number", "requestTransport expects an int for \"departure\"")
- assert(type(destination) == "number", "requestTransport expects an int for \"destination\"")
- commandRunner("prep", destination, {})
- tTime = os.startTimer(3)
- goForTransport = false
- repeat
- print("repeating")
- eventData = {os.pullEvent()}
- event = eventData[1]
- if event == "timer" and eventData[2] == tTime then
- print("Could not contact destination floor (timed out)")
- return -1
- end
- if event == "modem_message" and eventData[5].cmd == "error" then return end
- until event == "modem_message" and eventData[5].cmd == "ready"
- db[destination]["expected"] = db[departure]["cur"]
- db[departure]["expected"] = db[destination]["cur"]
- commandRunner("updateDb", -1, {db})
- end,
- getFloors = function()
- commandRunner("updateDb", -1, {db})
- end
- }
- function commandParser(cList)
- event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
- print(textutils.serialise(message))
- if commands[message.cmd] ~= nil and message.args ~= nil then
- ran, err = pcall(commands[message.cmd], table.unpack(message.args))
- if not ran then
- print(("Error in \"%s\": %s"):format(message.cmd, err))
- end
- else
- print(("No command named \"%s\" found"):format(message.cmd))
- end
- end
- function commandRunner(command, target, arguments)
- assert(type(command) == "string", "commandRunner expects a string for its input \"command\"")
- assert(type(target) == "number", "commandRunner expects a number for its input \"target\"")
- assert(type(arguments) == "table", "commandRunner expects a table for its input \"arguments\"")
- modem.transmit(5296,5296, {cmd=command, tgt=target, args=arguments})
- end
- commandRunner("init", -1, {os.computerID()})
- while true do
- commandParser(commands)
- print(textutils.serialise(db))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement