Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tardim = peripheral.find("digital_tardim_interface") or error("No tardim attached", 0)
- local modem = peripheral.find("modem") or error("No modem attached", 0)
- terminate = false;
- address = 0
- modem.open(address)
- password = "tardim-1"
- function listen()
- while terminate == false do
- -- os.queueEvent("run", 2, "nil")
- local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
- messageRecieved(side,channel,replyChannel,message,distance)
- -- local event, par1, par2, par3, par4, par5 = os.pullEvent()
- -- if event == "modem_message" then
- -- side = par1
- -- channel = par2
- -- replyChannel = parm3
- -- message = par4
- -- distance = par5
- -- messageRecieved(side,channel,replyChannel,message,distance)
- -- end
- -- sleep(0.1)
- end
- end
- function messageRecieved(side,channel,replyChannel,message,distance)
- print(message[1])
- print(message[2])
- if message[1] == "connect" then
- sleep(0.1)
- modem.open(replyChannel+1)
- modem.transmit(replyChannel,replyChannel+1,{"ok",replyChannel+1})
- address = replyChannel+1
- -- modem.close(address)
- end
- if message[1] == "pass" then
- if message[2] == password then
- sleep(0.1)
- modem.transmit(replyChannel,address,{"correct"})
- else
- modem.transmit(replyChannel,address,{"error"})
- end
- end
- if message[1] == "location" then
- tardim.setTravelLocation(message[2],message[3],message[4])
- sleep(0.1)
- modem.transmit(replyChannel,address,{"location_set"})
- end
- if message[1] == "demat" then
- if not tardim.isInFlight() then
- tardim.demat()
- sleep(0.1)
- modem.transmit(replyChannel,address,{"demat"})
- else
- sleep(0.1)
- modem.transmit(replyChannel,address,{"inFlight"})
- end
- end
- if message[1] == "remat" then
- if tardim.isInFlight() then
- tardim.remat()
- sleep(0.1)
- modem.transmit(replyChannel,address,{"remat"})
- else
- sleep(0.1)
- modem.transmit(replyChannel,address,{"landed"})
- end
- end
- if message[1] == "status" then
- sleep(0.1)
- modem.transmit(replyChannel,address,{"status",tardim.isInFlight(),tardim.getFuel()})
- end
- end
- parallel.waitForAll(listen)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement