Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- YamaCorpMainController, 2022, Yamazouki
- REDNET_SIDE = "top"
- MACHINE_CONTROLLER_ID = 3
- DISPLAY_CONTROLLER_ID = 2
- REFRESH_RATE = 5
- TIMEOUT_DELAY = 5
- rednet.open(REDNET_SIDE)
- function generateErrorMessage (str)
- return {"Error :", 0xFF0000, str, 0xFF0000}
- end
- while true do
- msg = {}
- msg.protocol = "get_info"
- rednet.send(MACHINE_CONTROLLER_ID, textutils.serializeJSON(msg), "YamaCorp")
- rnID, rnMsg, rnProto = rednet.receive("YamaCorp", TIMEOUT_DELAY)
- msg = {}
- msg.protocol = "display"
- msg.body = {}
- if rnID == nil then
- print("No signals since " .. TIMEOUT_DELAY .. "s")
- table.insert(msg.body, generateErrorMessage("no signal from machine controller"))
- else
- if (rnProto == "YamaCorp") then
- write("from " .. rnID .. " : ")
- rnMsg = textutils.unserializeJSON(rnMsg)
- if (rnMsg == nil) then
- print("error serializing JSON")
- table.insert(msg.body, generateErrorMessage("JSON error"))
- else
- proto = rnMsg.protocol
- body = rnMsg.body
- print(proto)
- if (proto == 'global') then
- if (body == 'restart') then
- os.reboot()
- end
- elseif (proto == 'info') then
- msg.body = body
- end
- end
- end
- end
- rednet.send(DISPLAY_CONTROLLER_ID, textutils.serializeJSON(msg), "YamaCorp")
- sleep(REFRESH_RATE)
- end
Add Comment
Please, Sign In to add comment