Advertisement
Marlingaming

Test Track Manager

Sep 10th, 2021 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. --this program manages a group of test chambers
  2. TrackID = nil
  3. Track_Protocol = 0
  4. Track_State = "idle"
  5. Track_Available = false
  6. TestingDirector_Protocol = 5362
  7. local DirectorID = 0
  8.  
  9. if fs.exists("config") == false then
  10. ConfigManager("create")
  11. end
  12. ConfigManager("load")
  13. start()
  14.  
  15. function start()
  16. if Track_State ~= "idle" then
  17. TrackManager()
  18. end
  19. Standby()
  20. end
  21.  
  22. function Standby()
  23. rednet.open("top")
  24. while true do
  25. local id, message, protocol = rednet.receive()
  26. if protocol == Track_Protocol then
  27. print("Feature not finished") --add receiving function from tests to allow Track to know the chambers status
  28. elseif protocol == TestingDirector_Protocol and message == TrackID then
  29. DirectorID = id
  30. break
  31. DirectorCommands()
  32. end
  33. end
  34. end
  35.  
  36. function TrackManager()
  37. rednet.open("top")
  38. if Track_State == "starting" then
  39. ChambersExecute("start")
  40. Track_State = "Started"
  41. elseif Track_State == "LockingDown" then
  42. ChambersExecute("Lockdown")
  43. Track_State = "Lockdown"
  44. elseif Track_State == "stopping" then
  45. ChambersExecute("stop")
  46. Track_State = "idle"
  47. end
  48. end
  49.  
  50. function ChambersExecute(action)
  51. rednet.open("top")
  52. rednet.broadcast(action,Track_Protocol)
  53. end
  54.  
  55. function DirectorCommands()
  56. rednet.send(DirectorID,"ready",TestingDirector_Protocol)
  57. repeat
  58. local id, message = rednet.receive()
  59. until id == DirectorID
  60. if message == "start" then
  61. Track_State = "starting"
  62. rednet.send(DirectorID,"Starting",TestingDirector_Protocol)
  63. elseif message == "Lockdown" then
  64. Track_State = "LockingDown"
  65. rednet.send(DirectorID,"LockedDown",TestingDirector_Protocol)
  66. elseif message == "stop" then
  67. Track_State = "stopping"
  68. rednet.send(DirectorID,"stopped",TestingDirector_Protocol)
  69. elseif message == "state" then
  70. rednet.send(DirectorID,Track_State,TestingDirector_Protocol)
  71. rednet.send(DirectorID,Track_Available,TestingDirector_Protocol)
  72. end
  73. ConfigManager("save")
  74. start()
  75. end
  76.  
  77. function ConfigManager(action)
  78. if action == "load" then
  79. local file = fs.open("config","r")
  80. TrackID = file.readLine(1)
  81. Track_Protocol = file.readLine(2)
  82. Track_State = file.readLine(3)
  83. Track_Available = file.readLine(4)
  84. TestingDirector_Protocol = file.readLine(5)
  85. file.close()
  86. elseif action == "create" then
  87. local file = fs.open("config","w")
  88. file.writeLine(nil)
  89. file.writeLine(Track_Protocol)
  90. file.writeLine(Track_State)
  91. file.writeLine(Track_Available)
  92. file.writeLine(TestingDirector_Protocol)
  93. file.close()
  94. else
  95. local file = fs.open("config","w")
  96. file.clear()
  97. file.setCursorPos(1,1)
  98. file.writeLine(TrackID)
  99. file.writeLine(Track_Protocol)
  100. file.writeLine(Track_State)
  101. file.writeLine(Track_Available)
  102. file.writeLine(TestingDirector_Protocol)
  103. file.close()
  104. end
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement