Advertisement
cyber_Ahn

Ficsit-Networks-Industrie-Main-Control

Apr 13th, 2022 (edited)
2,573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.15 KB | None | 0 0
  1. ----------------------var------------------------------------------
  2. emergency_power_limit = 4500
  3. power_text_length = 43
  4. cont_text_length = 55
  5. line_per_page = 30
  6. Server = "A95659614E3764D6CA3A53948E6E9FFE"
  7. Name = "Main_PC"
  8. screen_id = "9B34CEF64FECFCB17E3A95B2CE1B6340"
  9. ----------------------get-hardware---------------------------------
  10. local NetworkCard = computer.getPCIDevices(findClass("NetworkCard"))[1]
  11.  
  12. local InternetCard = computer.getPCIDevices(findClass("FINInternetCard"))[1]
  13.  
  14. local gpu = computer.getPCIDevices(findClass("GPUT1"))[1]
  15. if not gpu then
  16.  error("No GPU T1 found!")
  17. end
  18.  
  19. local screen = computer.getPCIDevices(findClass("FINComputerScreen"))[1]
  20. if not screen then
  21.  local comp_b=""
  22.  local comp = component.findComponent(findClass("Screen"))
  23.  for i=1, #comp do
  24.   if comp[i] == screen_id then
  25.    comp_b = comp[i]
  26.   end
  27.  end
  28.  screen = component.proxy(comp_b)
  29. end
  30. gpu:bindScreen(screen)
  31. gpu:setSize(120,34)
  32. w,h = gpu:getSize()
  33. gpu:setSize(w,h)
  34. gpu:setText(0,0,"Start Terminal......")
  35. gpu:flush()
  36. event.pull(10)
  37. gpu:fill(0,0,w,h," ")
  38. gpu:flush()
  39.  
  40. local switch = component.proxy(component.findComponent("Switch"))
  41. local gen = component.proxy(component.findComponent("Generator"))
  42. local akw = component.proxy(component.findComponent("AKW"))
  43. local storage = component.proxy(component.findComponent("Storage"))
  44. local constructor = component.proxy(component.findComponent("Constructor"))
  45. local fabricator = component.proxy(component.findComponent("Fabricator"))
  46. local powerpole = component.proxy(component.findComponent("PowerPole"))
  47. local panel = component.proxy(component.findComponent("Panel"))
  48. local machine = component.proxy(component.findComponent("Machine"))
  49. local fluid = component.proxy(component.findComponent("F_Storage"))
  50. local bat = component.proxy(component.findComponent("Battery"))
  51. local pole = component.proxy(component.findComponent("Pole"))
  52. local maschine_stat = "Offline"
  53. local page = 1
  54. local max_page = 1
  55. ---------------------functions------------------------------------------
  56. function bios()
  57.  --print("Screen-ID: "..screen.id)
  58.  for i=1, #switch do
  59.   print("Switch_"..i.."-ID: "..switch[i].id)
  60.   switch[i].isSwitchOn = false
  61.  end
  62.  for i=1, #gen do
  63.   print("Bio_Generator_"..i.."-ID: "..gen[i].id)
  64.  end
  65.  for i=1, #storage do
  66.   print("Storage_"..i.."-ID: "..storage[i].id)
  67.  end
  68.  for i=1, #constructor do
  69.   print("Constructor_"..i.."-ID: "..constructor[i].id)
  70.  end
  71.  for i=1, #fabricator do
  72.   print("Fabricator_"..i.."-ID: "..fabricator[i].id)
  73.  end
  74.  for i=1, #fabricator do
  75.   print("Power_Powle_"..i.."-ID: "..powerpole[i].id)
  76.  end
  77.  for i=1, #akw do
  78.   print("AKW_"..i.."-ID: "..akw[i].id)
  79.  end
  80.  for i=1, #panel do
  81.   print("Panel_"..i.."-ID: "..panel[i].id)
  82.  end
  83.  for i=1, #machine do
  84.   print("Machine_"..i.."-ID: "..machine[i].id)
  85.  end
  86.  for i=1, #fluid do
  87.   print("Fluid_Storage_"..i.."-ID: "..fluid[i].id)
  88.  end
  89.  for i=1, #bat do
  90.   print("Battery_"..i.."-ID: "..bat[i].id)
  91.  end
  92.  for i=1, #pole do
  93.   print("Pole_"..i.."-ID: "..pole[i].id)
  94.   pole[i]:setcolor(1,0,0,5)
  95.  end
  96.  -- clean screen
  97.  gpu:setBackground(0,0,0,0)
  98.  gpu:setForeground(1,1,1,1)
  99.  gpu:fill(0,0,w,h," ")
  100.  --
  101.  gpu:setSize(w/2,h/2)
  102.  gpu:setForeground(1,1,0,1)
  103.  gpu:setText(0,0, "caworks Modular Bios V.10")
  104.  gpu:setForeground(1,1,1,1)
  105.  gpu:setText(0,1, "2011 - 2013 caworks Software Inc")
  106.  gpu:setText(0,2, "Processor caCore 2,4 GHZ x4")
  107.  gpu:setText(0,3, "Memory Testing: ok  2096084K")
  108.  gpu:setText(0,4, "----------------------------------------")
  109.  gpu:setText(0,5, "IDE Channel 0: Master  CW34342525 500GB")
  110.  gpu:setText(0,6, "IDE Channel 1: NONE")
  111.  gpu:setText(0,14, "Press F12 for Bios Setup")
  112.  gpu:flush()
  113.  event.pull(5)
  114.  gpu:fill(0,0,w,h," ")
  115.  gpu:flush()
  116.  test_network()
  117. end
  118.  
  119. function bar(r, g, b, x, y, w, h, fill)
  120.   fillLine = round((fill * h) / 100)
  121.   for i=1, h do
  122.    gpu:setText(x-1,y, "|")
  123.    gpu:setText(x+w,y, "|")
  124.    y = y - 1
  125.   end
  126.   y = y + h
  127.   gpu:setForeground(r,g,b,1)
  128.   for i=1, fillLine do
  129.    for i=1, w do
  130.     gpu:setText(x,y, "■")
  131.     x = x + 1
  132.    end
  133.    x = x - w
  134.    y = y - 1
  135.   end
  136.   gpu:setForeground(1,1,1,1)
  137. end
  138.  
  139. function test_network()
  140.  local req = InternetCard:request("https://httpbin.org/anything", "POST", "Network is ok.", "Content-Type", "text")
  141.  local text_in = req:await()
  142.  gpu:setForeground(1,1,0,1)
  143.  gpu:setSize(w,h)
  144.  gpu:setText(w/3,0, "Network test")
  145.  gpu:setForeground(1,1,1,1)
  146.  gpu:setText(w/3,1, text_in)
  147.  gpu:flush()
  148.  event.pull(3)
  149.  gpu:fill(0,0,w,h," ")
  150.  gpu:flush()
  151.  computer.beep(5)
  152.  main_prog()
  153. end
  154.  
  155. function network_send(receiver, port, data)
  156.  netcard = component.proxy(NetworkCard.id)
  157.  netcard:open(port)
  158.  netcard:send(receiver, port, data)
  159. end
  160.  
  161. function get_max_power(n)
  162.  connector = powerpole[n]:getPowerConnectors()[1]
  163.  circuit = connector:getCircuit()
  164.  return circuit.capacity
  165. end
  166.  
  167. function draw_frame(x,y,le,dire)
  168.  for i=0, le do
  169.   if dire == "right" then
  170.    gpu:setText(x+i,y, "-")
  171.   end
  172.   if dire == "down" then
  173.    gpu:setText(x,y+i, "|")
  174.   end
  175.  end
  176. end
  177.  
  178. function round(x)
  179.   return math.floor(x + 0.5)
  180. end
  181.  
  182. function main_prog()
  183.  event.pull(3)
  184.  for i=1, #akw do
  185.   akw[i].standby = false
  186.  end
  187.  for i=1, #gen do
  188.   gen[i].standby = true
  189.  end
  190.  if #panel ~= 0 then
  191.   button = panel[1]:getModule(5,5)
  192.   button_1 = panel[1]:getModule(0,0)
  193.   display = panel[1]:getModule(5,9)
  194.   display_1 = panel[1]:getModule(2,2)
  195.   display.text = "Running..."
  196.   display.size = 50
  197.   display_1.text = "    Next Page \n    "..page.."/"..max_page
  198.   display_1.size = 50
  199.  end
  200.  for i=1, #machine do
  201.   machine[i].standby = false
  202.   maschine_stat = "Online"
  203.  end
  204.  for i=1, #switch do
  205.   switch[i].isSwitchOn = false
  206.  end
  207.  for i=1, #pole do
  208.   pole[i]:setcolor(0,1,0,5)
  209.  end
  210.  while true do
  211.   network_send(Server, 5256, Name)
  212.   gpu:fill(0,0,w,h," ")
  213.   gpu:flush()
  214.   gpu:setForeground(1,1,1,1)
  215.   gpu:setSize(w,h)
  216.   gpu:setText(w/3,0, "caworks Control V1.0")
  217.   power = 0
  218.   if #powerpole > 0 then
  219.    power = get_max_power(1)
  220.   end
  221.   if(power < emergency_power_limit) then
  222.    gpu:setForeground(1,0,0,1)
  223.    for i=1, #gen do
  224.     gen[i].standby = false
  225.    end
  226.    for i=1, #machine do
  227.     machine[i].standby = true
  228.     maschine_stat = "Offline"
  229.    end
  230.    for i=1, #switch do
  231.     switch[i].isSwitchOn = false
  232.    end
  233.   end
  234.   if(power > emergency_power_limit) then
  235.    gpu:setForeground(1,1,1,1)
  236.    for i=1, #gen do
  237.     gen[i].standby = true
  238.    end
  239.    for i=1, #switch do
  240.     switch[i].isSwitchOn = true
  241.    end
  242.    for i=1, #machine do
  243.     machine[i].standby = false
  244.     maschine_stat = "Online"
  245.    end  
  246.   end
  247.   gpu:setText(1,2, "Current Max Power: "..power.." MWh")
  248.   gpu:setForeground(1,1,1,1)
  249.   for i=1, #akw do
  250.    cach = akw[i].standby
  251.    out = "Offline"
  252.    gpu:setForeground(1,0,0,1)
  253.    if cach == false then
  254.     out = "Online"
  255.     gpu:setForeground(0,1,0,1)
  256.    end
  257.    gpu:setText(10,i+3, out)
  258.    gpu:setForeground(1,1,1,1)
  259.    gpu:setText(1,i+3, "AKW "..i.." is ")
  260.   end
  261.   lines = 0
  262.   for i=1, #gen do
  263.    cach = gen[i].standby
  264.    out = "Offline"
  265.    gpu:setForeground(1,0,0,1)
  266.    if cach == false then
  267.     out = "Online"
  268.     gpu:setForeground(0,1,0,1)
  269.    end
  270.    gpu:setText((w/6)+16,i+3, out)
  271.    gpu:setForeground(1,1,1,1)
  272.    gpu:setText(w/6,i+3, "Generator "..i.." is ")
  273.    lines = i
  274.   end
  275.   draw_frame(0,1,power_text_length,"right")
  276.   draw_frame(0,2,lines+1,"down")
  277.   draw_frame(power_text_length,2,lines+1,"down")
  278.   draw_frame(0,lines+4,power_text_length,"right")
  279.   linesB = 0
  280. -------------------------------------------------------------------------------------------------------------------------------
  281.   line_start = 1
  282.   line_end = line_per_page
  283.   max_page = math.floor(#storage / line_per_page)
  284.   if max_page < (#storage / line_per_page) then
  285.    max_page = max_page + 1
  286.   end
  287.   if page > 1 then
  288.    line_start = line_per_page * (page-1)
  289.    line_end = line_per_page * page
  290.   end
  291.   display_1.text = "    Next Page \n"..page.."/"..max_page.."            "..line_start.."-"..line_end
  292.   if line_end > #storage then
  293.    line_end = #storage
  294.   end
  295.   for i=line_start, line_end do
  296.    text_line = i+1
  297.    if page > 1 then
  298.     text_line = (i-line_per_page)+1
  299.    end
  300.    inv = storage[i]:getInventories()[1]
  301.    inv:sort()
  302.    amount = inv.itemCount
  303.    itemName = "Empty"
  304.    max = 0
  305.    if amount > 1 then
  306.     max = inv:getStack(0).count * inv.size
  307.     itemName = inv:getStack(0).item.type.name
  308.    end
  309.    gpu:setText(power_text_length+1,text_line, "Container_"..i)
  310.    gpu:setText(power_text_length+14,text_line, itemName)
  311.    if (max/2) > amount then
  312.     gpu:setForeground(1,0,0,1)
  313.    end
  314.    if (max/2) < amount then
  315.     gpu:setForeground(1,1,0,1)
  316.    end
  317.    if amount == max then
  318.     gpu:setForeground(0,1,0,1)
  319.    end
  320.    if amount == 0 then
  321.     gpu:setForeground(1,0,0,1)
  322.    end
  323.    gpu:setText(power_text_length+45,text_line, amount.."/"..max)
  324.    gpu:setForeground(1,1,1,1)
  325.    gpu:setText(80,0, "Page: "..page)
  326.    linesB = i
  327.    network_send(Server, 8080, "Container_"..i.."|"..itemName.."|"..amount.."/"..max)
  328.   end
  329.   draw_frame(power_text_length+1,1,cont_text_length,"right")
  330.   draw_frame(power_text_length,2,linesB-1,"down")
  331.   draw_frame(power_text_length+cont_text_length+1,2,linesB-1,"down")
  332.   draw_frame(power_text_length,linesB+2,cont_text_length+1,"right")
  333. -----------------------------------------------------------------------------------------------------------------------------------
  334.   num_machine = #machine
  335.   gpu:setText(1,lines+5, "Machine found: "..num_machine)
  336.   gpu:setText(1,lines+6, "Machine are ")
  337.   if maschine_stat == "Offline" then
  338.    gpu:setForeground(1,0,0,1)
  339.   end
  340.   if maschine_stat == "Online" then
  341.    gpu:setForeground(0,1,0,1)
  342.   end
  343.   gpu:setText(13,lines+6, maschine_stat)
  344.   gpu:setForeground(1,1,1,1)
  345.   draw_frame(0,lines+4,2,"down")
  346.   draw_frame(power_text_length,lines+4,2,"down")
  347.   draw_frame(0,lines+7,power_text_length,"right")
  348.   linesC = 0
  349.   for i=1, #fluid do
  350.    itemName = "Empty"
  351.    isF = fluid[i].fluidContent
  352.    maxF = fluid[i].maxFluidContent
  353.    itemName = fluid[i]:getFluidType().name
  354.    gpu:setText(1,lines+7+i, "Fluid_"..i)
  355.    gpu:setText(9,lines+7+i, itemName)
  356.    if (maxF/2) > isF then
  357.     gpu:setForeground(1,0,0,1)
  358.    end
  359.    if (maxF/2) < isF then
  360.     gpu:setForeground(1,1,0,1)
  361.    end
  362.    if isF == maxF then
  363.     gpu:setForeground(0,1,0,1)
  364.    end
  365.    if isF == 0 then
  366.     gpu:setForeground(1,0,0,1)
  367.    end
  368.    if isF > maxF then
  369.     gpu:setForeground(1,1,1,1)
  370.    end
  371.    gpu:setText(33,lines+7+i, round(isF).."/"..round(maxF))
  372.    gpu:setForeground(1,1,1,1)
  373.    network_send(Server, 8080, "Fluid_"..i.."|"..itemName.."|"..round(isF).."/"..round(maxF))
  374.    if itemName == "Schwefelsäure" and isF >= maxF then
  375.     print("flush")
  376.     fluid[i]:flush()
  377.    end
  378.    if itemName == "Wasser" and isF >= maxF then
  379.     print("flush")
  380.     fluid[i]:flush()
  381.    end
  382.    if itemName == "Aluoxid-Lösung" and isF >= maxF then
  383.     print("flush")
  384.     fluid[i]:flush()
  385.    end   linesC = i
  386.   end
  387.   draw_frame(0,lines+8+linesC,power_text_length,"right")
  388.   draw_frame(0,lines+7,linesC,"down")
  389.   draw_frame(power_text_length,lines+7,linesC,"down")
  390.   if #bat > 0 then
  391.   maxCap = 0
  392.   maxStored = 0
  393.   for i=1, #bat do
  394.    store = bat[i].powerStore
  395.    cap = bat[i].powerCapacity
  396.    storeMW = (store * cap) / 100
  397.    maxCap = maxCap + cap
  398.    maxStored = maxStored + storeMW
  399.   end
  400.   maxPre = (maxStored * 100) / maxCap
  401.   bar(0, 1, 0, 115, 33, 4, 32, maxPre)
  402.   gpu:setText(115, 0, round(maxPre).."%")
  403.   gpu:setText(115, 1, round(maxCap).."MW")
  404.   end
  405.   gpu:flush()
  406.   event.listen(button, button_1)
  407.   e, s = event.pull(30)
  408.   if s == button_1 then
  409.    computer.beep(5)
  410.    page = page + 1
  411.    if page > max_page then
  412.     page = 1
  413.    end
  414.    display_1.text = "    Next Page \n"..page.."/"..max_page.."            "..line_start.."-"..line_end
  415.    display_1.size = 50
  416.   end
  417.   if s == button then
  418.    display.text = "STOP!!!"
  419.    display_1.text = ""
  420.    for i=1, #machine do
  421.     machine[i].standby = true
  422.     maschine_stat = "Offline"
  423.    end
  424.    for i=1, #switch do
  425.     switch[i].isSwitchOn = false
  426.    end
  427.    for i=1, #pole do
  428.     pole[i]:setcolor(1,0,0,5)
  429.    end  
  430.    gpu:fill(0,0,w,h," ")
  431.    gpu:flush()
  432.    break
  433.   end
  434.  end
  435. end
  436. ----------------------main-programm--------------------------------
  437. bios()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement