Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- engine = peripheral.wrap("bottom") -- engine on bottom
- local modem = peripheral.wrap("right") -- modem on the right
- local tankTable = engine.getTankInfo("top")
- local fuelTankTable = tankTable[1]
- local commandchannel = 1337
- local inputchannel = 1334
- modem.open(inputchannel) -- open input channel
- local assignedTank = 999
- local bufferTankStatus = 0
- local myname = "Compression Block #1"
- local validCommands = {"start","stop","update","exit"}
- local fuelType = ""
- local fuelLevel= 0
- function requestBufferTankStatus()
- modem.transmit(assignedTank, inputchannel, "statusRequest")
- end
- function refreshLocalTankInfo()
- requestBufferTankStatus()
- tankTable = engine.getTankInfo("top")
- fuelTankTable = tankTable[1]
- fuelType = fuelTankTable["name"]
- if fuelType == nil then
- fuelType = "none"
- end
- fuelLevel = fuelTankTable["amount"]
- if fuelLevel == nil then
- fuelLevel = 0
- end
- end
- function engineStart()
- redstone.setOutput("bottom", false)
- redstone.setOutput("back", false)
- modem.transmit(commandchannel,inputchannel,"engine started")
- print("Starting engine..")
- end
- function engineStop()
- redstone.setOutput("bottom", true)
- redstone.setOutput("back", true)
- modem.transmit(commandchannel,inputchannel,"engine halted")
- print("Halting engine..")
- end
- function complistener()
- while true do
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- if message == "statusRequest" and replyChannel == commandchannel then
- refreshLocalTankInfo()
- modem.transmit(commandchannel, inputchannel, tostring(bufferTankStatus)..","..tostring(fuelTankTable["amount"])..","..tostring(engine.getEnergy())..","..tostring(engine.getEnergyPerTick()))
- elseif message == "engine halt" and replychannel == commandchannel then
- engineStop()
- elseif message == "engine start" and replyChannel == commandchannel then
- engineStart()
- elseif replyChannel == assignedTank and message == nil then
- bufferTankStatus = 0
- elseif replyChannel == assignedTank and message ~= nil then
- bufferTankStatus = message
- end
- end
- end
- function ManagerIO()
- term.clear()
- term.setCursorPos(1,1)
- printStatus()
- print("Valid inputs:")
- term.setTextColor(colors.orange)
- for k,v in pairs(validCommands) do
- write(string.upper(v).." ")
- end
- term.setTextColor(colors.white)
- print("")
- print(myname..">>")
- input = string.lower(io.read())
- if input == "start" then
- engineStart()
- sleep(1)
- elseif input == "stop" then
- engineStop()
- elseif input == "exit" then
- terminate = true
- do return end
- else
- print("Invalid input.")
- end
- end
- function printStatus()
- refreshLocalTankInfo()
- engineOnline = not redstone.getOutput("bottom")
- write("Engine is: ")
- if not engineOnline then
- term.setTextColor(colors.purple)
- print("INHIBITED")
- elseif engineOnline and tostring(engine.getEnergyPerTick()) == "80" then
- term.setTextColor(colors.green)
- print("ONLINE")
- elseif engineOnline and fuelLevel == 0 then
- term.setTextColor(colors.red)
- print("CHOKED")
- else
- term.setTextColor(colors.red)
- print("MALFUNCTIONING")
- end
- term.setTextColor(colors.white)
- print("")
- print("Fuel type: "..fuelType)
- print("Reserve fuel level: "..bufferTankStatus)
- print("Engine fuel level: "..fuelLevel)
- print("Engine energy level: "..engine.getEnergy())
- print("Engine production: "..engine.getEnergyPerTick().." RF/t")
- print("")
- end
- terminate = false
- print("Starting "..myname.." listener on "..inputchannel..".")
- while true do
- if terminate then
- term.clear()
- term.setCursorPos(1,1)
- do return end
- else
- parallel.waitForAny(complistener,ManagerIO)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement