Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- reactor = "fissionReactorLogicAdapter_0"
- state_fissionreactor_channel = 2
- control_channel = 3
- debug = true
- states = {
- ["FissionReactor"] = {
- ["state"] = false,
- ["temperature"] = 0,
- ["damage"]= 0,
- ["coolant"]= 0,
- ["fuel"]= 0,
- ["waste"]= 0,
- },
- }
- control_reactors = {
- ["BigReactor"] = false,
- ["FissionReactor"] = false
- }
- modem_reactor = peripheral.wrap("back")
- modem_wireless = peripheral.wrap("top")
- modem_wireless.open(control_channel)
- states["FissionReactor"]["state"] = modem_reactor.callRemote(reactor, "getStatus")
- print("Reactor state: ", states["FissionReactor"]["state"])
- -- Send states to server
- -- print(("Sending to server: "), states)
- modem_wireless.transmit(state_fissionreactor_channel, 65535, states)
- local function handleMessages()
- -- Receive control commands and handle reactor
- local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
- control_reactors = message
- if debug == true then
- print("Received control message")
- print("FissionReactor: ", control_reactors["FissionReactor"])
- end
- end
- local function handleProgram()
- states["FissionReactor"]["state"] = modem_reactor.callRemote(reactor, "getStatus")
- states["FissionReactor"]["temperature"] = modem_reactor.callRemote(reactor, "getTemperature")
- states["FissionReactor"]["damage"] = modem_reactor.callRemote(reactor, "getDamagePercent")
- states["FissionReactor"]["coolant"] = modem_reactor.callRemote(reactor, "getCoolantFilledPercentage")
- states["FissionReactor"]["fuel"] = modem_reactor.callRemote(reactor, "getFuelFilledPercentage")
- states["FissionReactor"]["waste"] = modem_reactor.callRemote(reactor, "getWasteFilledPercentage")
- if debug == true then
- print("Reactor state: ", states["FissionReactor"]["state"])
- end
- -- Send states to server
- -- print(("Sending to server: "), states)
- modem_wireless.transmit(state_fissionreactor_channel, 65533, states)
- sleep(1)
- if control_reactors["FissionReactor"] == true then
- if modem_reactor.callRemote(reactor, "getStatus") == false then
- print("Turning on Reactor.")
- modem_reactor.callRemote(reactor, "activate")
- end
- elseif control_reactors["FissionReactor"] == false then
- if modem_reactor.callRemote(reactor, "getStatus") == true then
- print("Turning off Reactor.")
- modem_reactor.callRemote(reactor, "scram")
- end
- end
- end
- ---------------------------------------------------------------------------------------
- while true do
- parallel.waitForAny(handleProgram,handleMessages)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement