Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- verze = "22.0625.R1"
- local idPC = os.getComputerID()
- local IDserver = 142
- local w,h = term.getSize()
- local modem
- local testJednotky = false
- local casTestu = 0
- local function bgc(barvaP) term.setBackgroundColor(barvaP) end
- local function txc(barvaP) term.setTextColor(barvaP) end
- local function curs(xi,yi) term.setCursorPos(xi,yi) end
- if not fs.exists ("lastECUD.txt") then local data = fs.open("lastECUD.txt", "w") data.writeLine("0") data.close() end
- local data = fs.open("lastECUD.txt", "r") local ECUD = tonumber(data.readLine())+1 data.close()
- local historielinka = false
- local jePoplach = false
- local function prc(text, y)
- local w = term.getSize()
- local _, cy = term.getCursorPos()
- curs(math.ceil((w-#text)/2), y or cy)
- write(text)
- end
- function bar(styl, text)
- if (styl == "OK") then -- Uspech
- term.setTextColor(colors.green)
- elseif (styl == "FAIL") then -- Neuspesne
- term.setTextColor(colors.red)
- elseif (styl == "INFO") then -- Informativni
- term.setTextColor(colors.lightBlue)
- elseif (styl == "def") then -- defaultni
- term.setTextColor(colors.white)
- elseif (styl == "CONST") then -- Progress
- term.setTextColor(colors.yellow)
- else
- styl = "def"
- term.setTextColor(colors.white)
- end
- if not (styl == "def") then
- zprava = ("["..textutils.formatTime(os.time(), true).."] ["..styl.."] "..text)
- else
- zprava = text
- end
- if logs then
- logy(zprava)
- end
- print (zprava)
- end
- function boot()
- term.setBackgroundColor(colors.black) term.clear() term.setCursorPos(1,1)
- while not modem do
- bar("INFO","Finding a modem...")
- modem = peripheral.find("modem")
- sleep(1)
- end
- modem.open(idPC)
- bar("OK","Modem is connected!")
- bar("INFO","Finding a configuration file...")
- if fs.exists ("config.cfg") then
- bar("OK","Configuration file found! Reading...")
- local data = fs.open("config.cfg", "r")
- IDserver = tonumber(data.readLine())
- Linka = data.readLine()
- if (data.readLine() == "true") then testJednotky = true else testJednotky = false end
- Adresa = data.readLine()
- Udalost = data.readLine()
- Upresneni = data.readLine()
- data.close()
- bar("CONST","Server: "..IDserver)
- bar("CONST","Signal: "..Linka)
- if (testJednotky) then bar("CONST","T. Alarm: Enable") casTestu = math.random(10000, 32000) else bar("CONST","T. Alarm: Disanable") end
- bar("CONST","Address: "..Adresa)
- bar("CONST","Event: "..Udalost)
- bar("CONST","Spec.: "..Upresneni)
- else
- bar("FAIL","The configuration file is missing, the system will shut down!")
- local data = fs.open("config.cfg", "w")
- data.writeLine("Server ID")
- data.writeLine("Strana signalu")
- data.writeLine("true / false -- test jednotky")
- data.writeLine("Adresa")
- data.writeLine("Udalost")
- data.writeLine("Upresneni")
- data.close()
- error("Missing config folder!")
- end
- bar("INFO","Test the connection to the server...")
- if testPing() then
- bar("OK","The server is available!")
- else
- bar("FAIL","The server did not respond, the message may not arrive!")
- end
- bar("OK","System boot completed successfully.")
- bar("INFO","The system will start, press any key to stop the start!")
- local myTimer = os.startTimer(1)
- while true do
- local event, param1 = os.pullEvent()
- if event == "timer" and param1 == myTimer then
- --casTestu = 10
- visual()
- elseif event == "key" then
- error("Stopped by user!")
- end
- end
- end
- function testPing()
- modem.transmit(IDserver,990,idPC)
- modem.transmit(IDserver,57610,"ping")
- local myTimer = os.startTimer(2)
- while true do
- local event, side, freq, rfreq, message = os.pullEvent()
- if event == "modem_message" and rfreq == 57610 then
- return true
- elseif event == "timer" and side == myTimer then
- return false
- end
- end
- end
- function setting()
- local plocha = window.create(term.current(),1,3,w-10,h)
- plocha.setBackgroundColor(colors.white)
- plocha.setTextColor(colors.black)
- plocha.clear()
- plocha.setCursorPos(1,2)
- plocha.write("Server: ")
- plocha.setCursorPos(1,4)
- plocha.write("Signal input: ")
- plocha.setCursorPos(1,6)
- plocha.write("Training alarm: ")
- plocha.setCursorPos(1,8)
- plocha.write("Adress: ")
- plocha.setCursorPos(1,10)
- plocha.write("Event: ")
- plocha.setCursorPos(1,12)
- plocha.write("Spec.: ")
- plocha.setCursorPos(9,2)
- plocha.write("_____")
- plocha.setCursorPos(9,8)
- plocha.write("________________________________")
- plocha.setCursorPos(9,10)
- plocha.write("________________________________")
- plocha.setCursorPos(9,12)
- plocha.write("________________________________")
- plocha.setCursorPos(9,2)
- plocha.write(IDserver)
- plocha.setCursorPos(9,8)
- plocha.write(Adresa)
- plocha.setCursorPos(9,10)
- plocha.write(Udalost)
- plocha.setCursorPos(9,12)
- plocha.write(Upresneni)
- local myTimer = os.startTimer(1)
- local menuTimer = os.startTimer(3)
- menu()
- while true do
- local event, param1, x, y = os.pullEvent()
- checkLinka()
- if event == "timer" and param1 == myTimer and testJednotky then
- local HT = os.date("%H")*1
- local MT = os.date("%M")*1
- local ST = os.date("%S")*1
- if (H == HT and M == MT and S < ST) then
- poplach("TC")
- else
- myTimer = os.startTimer(1)
- end
- elseif event == "timer" and param1 == menuTimer then
- menu()
- elseif event == "mouse_click" and param1 == 1 then
- menuClick(x,y)
- elseif event == "key" and param1 == keys.q then
- os.shutdown()
- elseif event == "key" and param1 == keys.p then
- LastProtocol()
- elseif event == "key" and param1 == keys.r then
- os.reboot()
- elseif event == "key" and param1 == keys.t then
- testPing()
- end
- end
- end
- function visual()
- term.clear()
- term.setTextColor(colors.white)
- paintutils.drawLine(1,1,w,1,colors.red)
- paintutils.drawLine(1,2,w,2,colors.red)
- term.setCursorPos(1,1)
- print("FireAlarm, by Pepek@Soft")
- write("Version "..verze)
- term.setBackgroundColor(colors.white)
- local plocha = window.create(term.current(),1,3,w-10,h)
- plocha.setBackgroundColor(colors.white)
- plocha.setTextColor(colors.black)
- plocha.clear()
- plocha.setCursorPos(1,2)
- plocha.write("Adress: "..Adresa)
- local testJ = "Disabled"
- if (casTestu < 11600 and testJednotky) then
- testJ = "Enabled"
- casPoplachuH = math.floor(casTestu/60/60)
- casPoplachuM = math.floor((casTestu-casPoplachuH*3600)/60)
- casPoplachuS = casTestu-casPoplachuH*3600-casPoplachuM*60
- S = (os.date("%S")+casPoplachuS)
- M = (os.date("%M")+casPoplachuM)
- H = (os.date("%H")+casPoplachuH)
- if (S>59) then S = S - 60 M = M+1 end
- if (M>59) then M = M - 60 H = H+1 end
- if (H>24) then H = H-24 end
- plocha.setCursorPos(1,4)
- plocha.write("Training alarm time: ")
- if (H<10) then plocha.write("0"..H) else plocha.write(H) end
- plocha.write(":")
- if (M<10) then plocha.write("0"..M) else plocha.write(M) end
- plocha.write(":")
- if (S<10) then plocha.write("0"..S) else plocha.write(S) end
- else testJednotky = false
- end
- plocha.setCursorPos(1,3)
- plocha.write("Training alarm: "..testJ)
- term.setCursorPos(1,8)
- local myTimer = os.startTimer(1)
- local menuTimer = os.startTimer(3)
- menu()
- while true do
- local event, param1, x, y = os.pullEvent()
- checkLinka()
- if event == "timer" and param1 == myTimer and testJednotky then
- local HT = os.date("%H")*1
- local MT = os.date("%M")*1
- local ST = os.date("%S")*1
- if (H == HT and M == MT and S < ST) then
- poplach("TC")
- else
- myTimer = os.startTimer(1)
- end
- elseif event == "timer" and param1 == menuTimer then
- menu()
- elseif event == "mouse_click" and param1 == 1 then
- menuClick(x,y)
- elseif event == "key" and param1 == keys.enter then
- poplach()
- elseif event == "key" and param1 == keys.q then
- os.shutdown()
- elseif event == "key" and param1 == keys.p then
- LastProtocol()
- elseif event == "key" and param1 == keys.r then
- os.reboot()
- end
- end
- end
- function LastProtocol()
- local plocha = window.create(term.current(),1,3,w-10,h)
- plocha.setBackgroundColor(colors.white)
- plocha.setTextColor(colors.black)
- plocha.clear()
- local data = fs.open("lastECUD.txt", "r") ECUD = tonumber(data.readLine()) data.close()
- local data = fs.open("protocol/"..ECUD..".txt", "r")
- local i = 2
- repeat
- local dataProtocol = data.readLine()
- plocha.setCursorPos(1,i)
- plocha.write(dataProtocol)
- i = i+1
- until dataProtocol == nil
- plocha.setCursorPos(1,i-1)
- plocha.write(" ")
- data.close()
- menu()
- local myTimer = os.startTimer(1)
- local menuTimer = os.startTimer(3)
- while true do
- local event, param1, x, y = os.pullEvent()
- checkLinka()
- if event == "timer" and param1 == myTimer and testJednotky then
- local HT = os.date("%H")*1
- local MT = os.date("%M")*1
- local ST = os.date("%S")*1
- if (H == HT and M == MT and S < ST) then
- poplach("TC")
- else
- myTimer = os.startTimer(1)
- end
- elseif event == "timer" and param1 == menuTimer then
- menu()
- elseif event == "mouse_click" and param1 == 1 then
- menuClick(x,y)
- elseif event == "key" and param1 == keys.q then
- os.shutdown()
- elseif event == "key" and (param1 == keys.b or param1 == keys.enter) then
- jePoplach = false
- visual()
- elseif event == "key" and param1 == keys.r then
- os.reboot()
- end
- end
- end
- function menuClick(x,y)
- if x >= (w-9) and x<=(w) and y >= 16 and y<= 19 then
- mplocha.setBackgroundColor(colors.red)
- mplocha.setTextColor(colors.white)
- mplocha.setCursorPos(1,13)
- mplocha.write(" ")
- mplocha.setCursorPos(1,16)
- mplocha.write(" ")
- mplocha.setCursorPos(1,14)
- mplocha.write(" RUN ")
- mplocha.setCursorPos(1,15)
- mplocha.write(" ALARM! ")
- poplach()
- elseif x >= (w-9) and x<=(w) and y == 7 then
- mplocha.setBackgroundColor(colors.gray)
- mplocha.setCursorPos(1,5)
- mplocha.write(" Home ")
- sleep(0.1)
- visual()
- elseif x >= (w-9) and x<=(w) and y == 9 then
- mplocha.setBackgroundColor(colors.gray)
- mplocha.setCursorPos(1,7)
- mplocha.write(" Setting ")
- sleep(0.1)
- setting()
- elseif x >= (w-9) and x<=(w) and y == 11 then
- mplocha.setBackgroundColor(colors.gray)
- mplocha.setCursorPos(1,9)
- mplocha.write(" Protocol ")
- sleep(0.1)
- LastProtocol()
- elseif x >= (w-9) and x<=(w) and y == 13 then
- mplocha.setBackgroundColor(colors.gray)
- mplocha.setCursorPos(1,11)
- mplocha.write(" Ping ")
- sleep(0.1)
- mplocha.setCursorPos(1,11)
- if testPing() then
- mplocha.setBackgroundColor(colors.green)
- mplocha.write(" Success ")
- else
- mplocha.setBackgroundColor(colors.red)
- mplocha.write(" Fail ")
- end
- end
- end
- function menu()
- mplocha = window.create(term.current(),w-9,3,w,h)
- mplocha.setBackgroundColor(colors.white)
- mplocha.setTextColor(colors.black)
- mplocha.clear()
- mplocha.setBackgroundColor(colors.lightGray)
- mplocha.setCursorPos(1,5)
- mplocha.write(" Home ")
- mplocha.setCursorPos(1,7)
- mplocha.write(" Setting ")
- mplocha.setCursorPos(1,9)
- mplocha.write(" Protocol ")
- mplocha.setCursorPos(1,11)
- mplocha.write(" Ping ")
- mplocha.setBackgroundColor(colors.orange)
- mplocha.setTextColor(colors.white)
- mplocha.setCursorPos(1,13)
- mplocha.write(" ")
- mplocha.setCursorPos(1,16)
- mplocha.write(" ")
- mplocha.setCursorPos(1,14)
- mplocha.write(" RUN ")
- mplocha.setCursorPos(1,15)
- mplocha.write(" ALARM! ")
- if jePoplach then
- mplocha.setBackgroundColor(colors.red)
- mplocha.setTextColor(colors.white)
- mplocha.setCursorPos(1,2)
- mplocha.write(" ALARM! ")
- mplocha.setCursorPos(1,1)
- mplocha.write(" ")
- mplocha.setCursorPos(1,3)
- mplocha.write(" ")
- else
- mplocha.setBackgroundColor(colors.green)
- mplocha.setTextColor(colors.white)
- mplocha.setCursorPos(1,2)
- mplocha.write(" OK ")
- mplocha.setCursorPos(1,1)
- mplocha.write(" ")
- mplocha.setCursorPos(1,3)
- mplocha.write(" ")
- end
- end
- function checkLinka()
- local tedlinka = redstone.getInput(Linka)
- if not (historielinka == tedlinka) then
- if tedlinka then
- poplach()
- end
- end
- historielinka = tedlinka
- end
- function poplach(typ)
- jePoplach = true
- if typ == "TC" then Upresneni = (" TC - "..Upresneni) protokol () else protokol () end
- poslatStatus()
- testJednotky = false
- sleep(1)
- LastProtocol()
- end
- function poslatStatus()
- modem.transmit(IDserver,990,idPC)
- modem.transmit(IDserver,57600,Adresa)
- modem.transmit(IDserver,57601,Udalost)
- modem.transmit(IDserver,57602,Upresneni)
- end
- function protokol (tc)
- data = fs.open("lastECUD.txt", "r")
- ECUD = tonumber(data.readLine())+1
- data.close()
- data = fs.open("protocol/"..ECUD..".txt", "w")
- data.writeLine("Protokol c. "..ECUD)
- data.writeLine("Adresa zarizeni: "..idPC)
- data.writeLine("Ustredna: "..IDserver)
- data.writeLine("Adresa Udalosti: "..Adresa)
- data.writeLine("Co se stalo?: "..Udalost)
- data.writeLine("Upresneni: "..Upresneni)
- data.writeLine("Cas odeslani: "..os.date())
- data.close()
- data = fs.open("lastECUD.txt", "w")
- data.writeLine(ECUD)
- data.close()
- end
- boot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement