Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --this program manages a group of test chambers
- TrackID = nil
- Track_Protocol = 0
- Track_State = "idle"
- Track_Available = false
- TestingDirector_Protocol = 5362
- local DirectorID = 0
- if fs.exists("config") == false then
- ConfigManager("create")
- end
- ConfigManager("load")
- start()
- function start()
- if Track_State ~= "idle" then
- TrackManager()
- end
- Standby()
- end
- function Standby()
- rednet.open("top")
- while true do
- local id, message, protocol = rednet.receive()
- if protocol == Track_Protocol then
- print("Feature not finished") --add receiving function from tests to allow Track to know the chambers status
- elseif protocol == TestingDirector_Protocol and message == TrackID then
- DirectorID = id
- break
- DirectorCommands()
- end
- end
- end
- function TrackManager()
- rednet.open("top")
- if Track_State == "starting" then
- ChambersExecute("start")
- Track_State = "Started"
- elseif Track_State == "LockingDown" then
- ChambersExecute("Lockdown")
- Track_State = "Lockdown"
- elseif Track_State == "stopping" then
- ChambersExecute("stop")
- Track_State = "idle"
- end
- end
- function ChambersExecute(action)
- rednet.open("top")
- rednet.broadcast(action,Track_Protocol)
- end
- function DirectorCommands()
- rednet.send(DirectorID,"ready",TestingDirector_Protocol)
- repeat
- local id, message = rednet.receive()
- until id == DirectorID
- if message == "start" then
- Track_State = "starting"
- rednet.send(DirectorID,"Starting",TestingDirector_Protocol)
- elseif message == "Lockdown" then
- Track_State = "LockingDown"
- rednet.send(DirectorID,"LockedDown",TestingDirector_Protocol)
- elseif message == "stop" then
- Track_State = "stopping"
- rednet.send(DirectorID,"stopped",TestingDirector_Protocol)
- elseif message == "state" then
- rednet.send(DirectorID,Track_State,TestingDirector_Protocol)
- rednet.send(DirectorID,Track_Available,TestingDirector_Protocol)
- end
- ConfigManager("save")
- start()
- end
- function ConfigManager(action)
- if action == "load" then
- local file = fs.open("config","r")
- TrackID = file.readLine(1)
- Track_Protocol = file.readLine(2)
- Track_State = file.readLine(3)
- Track_Available = file.readLine(4)
- TestingDirector_Protocol = file.readLine(5)
- file.close()
- elseif action == "create" then
- local file = fs.open("config","w")
- file.writeLine(nil)
- file.writeLine(Track_Protocol)
- file.writeLine(Track_State)
- file.writeLine(Track_Available)
- file.writeLine(TestingDirector_Protocol)
- file.close()
- else
- local file = fs.open("config","w")
- file.clear()
- file.setCursorPos(1,1)
- file.writeLine(TrackID)
- file.writeLine(Track_Protocol)
- file.writeLine(Track_State)
- file.writeLine(Track_Available)
- file.writeLine(TestingDirector_Protocol)
- file.close()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement