Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Modem Communication Numbering
- -- 1/2 Screen to Server 1
- -- 2/1 Server 1 to Screen
- --3/4 Screen to Power Emergency PC
- -- 4/3 Pwr Em. PC to Screen
- local modem = peripheral.wrap('back')
- local screen = peripheral.wrap('top')
- function ps(n) --similar to print
- screen.write(n)
- x,y=screen.getCursorPos()
- y=y+1
- screen.setCursorPos(1,y)
- end
- function w(n) --write same line
- x1,y1=screen.getCursorPos()
- screen.setCursorPos(1,y1)
- screen.clearLine()
- screen.write(n)
- end
- function reset() --places cursor to left again
- x1,y1=screen.getCursorPos()
- screen.setCursorPos(1,y1)
- end
- function send(chan,reply,m) --transmits a message
- modem.transmit(chan,reply,m)
- end
- function get(chan,tmout)--listener
- if tmout==nil then
- tmout=100000000000000000000000000000 --change to call event w/o timer
- end
- modem.open(chan) --opens port
- chk=modem.isOpen(chan) --checks to make sure it is open
- if chk==true then --will set listener
- --mm = os.pullEvent("modem_message")
- timeout = os.startTimer(tmout)
- while true do
- event = {os.pullEvent()}
- if event[1] == "modem_message" then
- --print'Worked'
- --print(event[1].." "..event[2].." "..event[3].." "..event[4].." "..event[5].." "..event[6])
- msg=event[5]
- returnchan=event[4]
- chan=event[3]
- success=1
- break
- elseif event[1] == "timer" and event[2] == timeout then
- success=0
- break
- end
- end
- end
- if chk==false then
- --send error# to screen
- print('Error 100: Failed to Bind Port '..chan..'.')
- end
- end
- function chksvr(sendchan,svrnum,gettmout)
- send(sendchan,2,"ping")
- get(2,gettmout)
- if success==1 then
- screen.setCursorPos(1,svrnum+2)
- w("Server "..svrnum..": Online")
- end
- if success==0 then
- screen.setCursorPos(1,svrnum+2)
- w("Server "..svrnum..": DOWN")
- end
- --sleep(5)
- end
- --main
- screen.clear()
- screen.setCursorPos(1,1)
- ps("Kizz Tower Control: ONLINE")
- ps("")
- --MAIN LOOP for REFRESH
- function main()
- key=1
- while true do
- if key==1 then
- timeout2 = os.startTimer(2)
- end
- eventData = {os.pullEvent()}
- if eventData[1] == "stop_main" then
- key=0
- return
- elseif eventData[1] == "timer" and eventData[2] == timeout2 then
- --Server Checks/Screen
- chksvr(1,1,.5)
- chksvr(3,2,.5)
- chksvr(5,3,.5)
- --Power system checks/screen
- --Screen choice chk
- end
- end
- end
- function scch()
- while true do
- print'Welcome to the Screen Server'
- print'Please select an option:'
- print'1: Server Monitor'
- print'2: Power Systems Monitor'
- print'3: System Control Touch Monitor'
- print'4: System Shutdown'
- sel=io.read()
- sel=sel+1-1
- if sel==1 then
- print'Currently active.'
- end
- if sel==2 then
- print'Coming soon.'
- end
- if sel==3 then
- print'Coming soon.'
- end
- if sel==4 then
- print'Shutting down!'
- os.queueEvent("stop_main")
- --os.pullEvent("stop_main")
- --sleep()
- screen.clear()
- screen.setCursorPos(1,1)
- ps("Warning! System Shutting Down!")
- sleep(5)
- screen.clear()
- os.shutdown()
- end
- term.clear()
- term.setCursorPos(1,1)
- end
- end
- parallel.waitForAll(scch, main)
- --end main
Advertisement
Add Comment
Please, Sign In to add comment