Advertisement
SirBaconBitz

Dial / Destinations API

Oct 8th, 2014
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. local component = require("component")
  2. local serialization = require("serialization")
  3. local internet = require("internet")
  4. epdl = {}
  5. local dialdevice = component.ep_dialling_device
  6.  
  7. -- Change based on station
  8. local floppypath = "6c3"
  9. local lTime = 10
  10.  
  11. function epdl.getDestinations()
  12.   local dTable = internet.request("http://ccpost.esy.es/trains/destinations.lua")
  13.   return serialization.unserialize(dTable())
  14. end
  15.  
  16. function epdl.getStatus()
  17.   local pState = assert(io.open("/mnt/"..floppypath.."/state.lua"))
  18.   local poState = pState:read("*all")
  19.   pState:close()
  20.   return poState
  21. end
  22.  
  23. function epdl.dial( dName )
  24.   local dTable = epdl.getDestinations()
  25.   local dCode = " "
  26.   for k,v in pairs(dTable) do
  27.     if v.name == dName then
  28.       dCode = v.uuid
  29.     end
  30.   end
  31.  
  32.   poState = epdl.getStatus()
  33.  
  34.   if poState == "open" then
  35.     while poState ~= "closed" do
  36.       os.sleep(1)
  37.       poState = epdl.getStatus()
  38.     end
  39.   end
  40.   dialdevice.dial(dCode)
  41.  
  42.   local pState = assert(io.open("/mnt/"..floppypath.."/state.lua", "w"))
  43.   pState:write("open")
  44.   os.sleep(lTime)
  45.   dialdevice.terminate()
  46.   pState:write("closed")
  47.   pState:close()
  48. end
  49. return epdl
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement