Advertisement
melzneni

isrLib

Apr 22nd, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. ETYPE_RNET=0
  2.  
  3. if not fs.exists("disk/cid") then
  4. error("please start the isr-unit first")
  5. end
  6.  
  7. local f=fs.open("disk/cid","r")
  8. local cId=tonumber(f.readAll())
  9. f.close()
  10.  
  11. fs.delete("disk/isrLock")
  12.  
  13. function getCId()
  14. return cId
  15. end
  16.  
  17. function getEvents()
  18. if fs.exists("disk/isr") then
  19. fs.open("disk/isrLock", "w").close()
  20. while fs.exists("disk/isrLock2") do
  21. sleep(0.01)
  22. end
  23. local data = {}
  24. local handle = fs.open("disk/isr", "r")
  25. for line in handle.readLine do
  26. if line ~= "" then
  27. if string.sub(line, 1, 5) == "rnet:" then
  28. line = string.sub(line, 6)
  29. local ind = string.find(line, ",")
  30. table.insert(data,{type=ETYPE_RNET,id=tonumber(string.sub(line,1,ind-1)),msg=string.sub(line,ind+1)})
  31. else print("unknown event: " .. line)
  32. end
  33. end
  34. end
  35. handle.close()
  36. fs.open("disk/isr","w").close()
  37. fs.delete("disk/isrLock")
  38. return data
  39. end
  40. return {}
  41. end
  42.  
  43. getEvents()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement