Advertisement
BigSHinyToys

CC network test reciver

Apr 28th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 KB | None | 0 0
  1. --[[
  2.         test reciver
  3. ]]--
  4.  
  5. local function findDevice(sType)
  6.     for _,sSide in pairs(rs.getSides()) do
  7.         if peripheral.isPresent(sSide) and peripheral.getType(sSide) == sType then
  8.             return sSide,peripheral.wrap(sSide)
  9.         end
  10.     end
  11. end
  12.  
  13. local function dec2hex(nInput)
  14.     return string.format("%X",tonumber(nInput))
  15. end
  16.  
  17. local function hex2dec(sInput)
  18.     return tonumber(sInput,10)
  19. end
  20.  
  21. local function draw(sInput)
  22.     for a = 0,15 do
  23.         term.setCursorPos(1,a + 1)
  24.         term.setBackgroundColor(colors.black)
  25.         term.write(dec2hex(a).." ")
  26.         for b = 0,15 do
  27.             -- local char = string.sub(sInput,(a*16) + b + 1,(a*16) + b + 1)
  28.             local dec = string.byte(sInput,(a*16) + b + 1)
  29.             term.setBackgroundColor(colors.blue)
  30.            
  31.             term.write(string.char(dec))
  32.            
  33.             term.setBackgroundColor(colors.black)
  34.             if dec ~= ((a*16) + b ) then
  35.                 term.setBackgroundColor(colors.red)
  36.             end
  37.             local sPart = dec2hex(dec)
  38.             if #sPart == 1 then
  39.                 term.write(" ")
  40.             end
  41.            
  42.             term.write(sPart)
  43.            
  44.             --[[
  45.             term.write(tostring((a*16) + b + 1).." ")
  46.            
  47.             local char = string.char((a*16) + b)
  48.             term.setBackgroundColor(colors.white)
  49.             term.setTextColor(colors.lime)
  50.             term.write(char)
  51.             term.setBackgroundColor(colors.black)
  52.             term.setTextColor(colors.gray)
  53.             term.write(dec2hex(a)..dec2hex(b))
  54.             table.insert(sOut,char)
  55.             ]]--
  56.         end
  57.     end
  58. end
  59.  
  60. local sSide,modem = findDevice("modem")
  61.  
  62. modem.open(255)
  63.  
  64. while true do
  65.     local event = {os.pullEvent()}
  66.     if event[1] == "modem_message" then
  67.         draw(event[5])
  68.         --[[local file = fs.open("data","w")
  69.         file.write(event[5])
  70.         file.close()]]--
  71.     end
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement