Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local serialization = require("serialization")
- local internet = require("internet")
- epdl = {}
- local dialdevice = component.ep_dialling_device
- -- Change based on station
- local floppypath = "6c3"
- local lTime = 10
- function epdl.getDestinations()
- local dTable = internet.request("http://ccpost.esy.es/trains/destinations.lua")
- return serialization.unserialize(dTable())
- end
- function epdl.getStatus()
- local pState = assert(io.open("/mnt/"..floppypath.."/state.lua"))
- local poState = pState:read("*all")
- pState:close()
- return poState
- end
- function epdl.dial( dName )
- local dTable = epdl.getDestinations()
- local dCode = " "
- for k,v in pairs(dTable) do
- if v.name == dName then
- dCode = v.uuid
- end
- end
- poState = epdl.getStatus()
- if poState == "open" then
- while poState ~= "closed" do
- os.sleep(1)
- poState = epdl.getStatus()
- end
- end
- dialdevice.dial(dCode)
- local pState = assert(io.open("/mnt/"..floppypath.."/state.lua", "w"))
- pState:write("open")
- os.sleep(lTime)
- dialdevice.terminate()
- pState:write("closed")
- pState:close()
- end
- return epdl
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement