Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ModemPos = "top"
- MyID = os.getComputerID()
- modem = peripheral.wrap(ModemPos)
- modem.open(MyID)
- 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 == "PRO") 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 loop()
- local function defaultHod()
- idComp = nil
- hodnota = nil
- bar("INFO", "Pripraveno pro novy zapis")
- end
- local _, side, freq, rfreq, message = os.pullEvent('modem_message')
- if (rfreq == 990) then
- bar("INFO", "Zadost o zpracovani udaju.")
- idComp = message
- bar("PRO", "Adresa zarizeni: "..idComp)
- if not fs.exists("/database/"..idComp) then
- bar("INFO", "Provedena nova Registrace zarizeni "..idComp)
- fs.makeDir("/database/"..idComp)
- end
- end
- if (idComp) then
- if (rfreq == 57610) then
- bar("OK", "Funkcni pojeni s Elektromerem ID: "..idComp)
- modem.transmit(idComp,57610,true)
- if not fs.exists("/database/"..idComp.."/info.txt") then
- bar("INFO", "Zapsani fyzicke adresy elektromeru.")
- local data = fs.open("/database/"..idComp.."/info.txt", "w")
- data.writeLine(message)
- data.close()
- end
- end
- if (rfreq == 8080) then
- idComp = message --login to domain
- bar("INFO", "Prijem informaci ze zarizeni "..idComp)
- end
- if (rfreq == 8081) then
- hodnota = message
- bar("PRO", "Prichozi hodnota: "..hodnota)
- if tonumber(idComp) >= 0 then
- if fs.exists("/database/"..idComp.."/nevyuctovano.txt") then
- bar("INFO", "Nalezen zaznam s puvodni hodnotou.")
- local data = fs.open("/database/"..idComp.."/nevyuctovano.txt", "r")
- local puv_hodnota = tonumber(data.readLine())
- data.close()
- hodnota = hodnota + puv_hodnota
- end
- local zapis = fs.open("/database/"..idComp.."/nevyuctovano.txt", "w")
- zapis.writeLine(hodnota)
- bar("PRO", "Nova hodnota: "..hodnota)
- bar("OK", "Prepsano")
- zapis.close()
- defaultHod()
- end
- end
- if (rfreq == 8082) then
- bar("INFO", "Doruceni vyzadane hodnoty.")
- hodnota = message
- if tonumber(idComp) >= 0 then
- local zapis = fs.open("/database/"..idComp.."/info_stav.txt", "w")
- zapis.writeLine(hodnota)
- bar("OK", "Zapsana aktualni hodnota.")
- zapis.close()
- end
- end
- if (rfreq == 8083) then
- bar("INFO", "Doruceni vyzadane hodnoty.")
- hodnota = message
- if tonumber(idComp) >= 0 then
- local zapis = fs.open("/database/"..idComp.."/info_Celk_stav.txt", "w")
- zapis.writeLine(hodnota)
- bar("OK", "Zapsana celkova hodnota.")
- zapis.close()
- defaultHod()
- end
- end
- end
- loop()
- end
- bar("INFO", "Pripraveno k pouziti")
- loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement