added more scripts

This commit is contained in:
navid.sassan 2021-01-09 03:30:47 +01:00
parent c4c7e9046c
commit 3eedbc3b62
3 changed files with 139 additions and 0 deletions

84
react.lua Normal file
View File

@ -0,0 +1,84 @@
--regulate in between these in normal operation
NORMAL_THRESHOLD_U = 8000000
NORMAL_THRESHOLD_L = 7000000
--control rod pos for normal operation
NORMAL_ROD_POS = 81
--proportionally increase production when energy
--storage drops below this level
--(by removing control rods)
HIGH_THRESHOLD = 6000000
local active = false
local ctrl_rods = NORMAL_ROD_POS
local reactor = peripheral.wrap("back")
local mon = peripheral.wrap("right")
print("Monitoring reactor...")
while (true)
do
--setup monitor
mon.clear()
--get reactor energy
local energy = reactor.getEnergyStored()
--display
mon.setCursorPos(1, 1) --why is there no print() ???
mon.write(energy)
mon.write("RF")
if (energy > NORMAL_THRESHOLD_U)
then
active = false
else
if (energy < NORMAL_THRESHOLD_L)
then
active = true
if (energy < HIGH_THRESHOLD)
then
--proportional control
ctrl_rods = NORMAL_ROD_POS * (energy / HIGH_THRESHOLD)
end
end
end
--actually set state
mon.setCursorPos(1, 2)
if (active)
then
reactor.setActive(true)
mon.write("On")
else
reactor.setActive(false)
mon.write("Off")
end
mon.setCursorPos(1, 4)
reactor.setAllControlRodLevels(ctrl_rods)
mon.write(ctrl_rods)
mon.write("%")
--display power produced
mon.setCursorPos(1, 3)
mon.write(math.floor(reactor.getEnergyProducedLastTick()))
mon.write("RF/t")
--also check if fuel has run out
--(if the fuel inside the reactor isn't
--getting refilled anymore)
local deltaFuel = reactor.getFuelAmountMax() - reactor.getFuelAmount()
if (deltaFuel > 1000) --more than 1 bucket
then
mon.setCursorPos(1, 5)
mon.write("REFUEL!")
end
sleep(1)
end

22
recv_file.lua Normal file
View File

@ -0,0 +1,22 @@
local sides = peripheral.getNames()
for i = 1, #sides do
if peripheral.getType(sides[i]) == "modem" then
modemSide = sides[i]
break
end
end
rednet.open(modemSide)
id, msg, dist = rednet.receive()
print("Received data:")
term.write("Filename: ")
name = tostring(read())
print(msg)
content = textutils.unserialize(msg)
local file = fs.open(name, "w")
file.write(content)
file.close()
rednet.close(modemSide)

33
send_file.lua Normal file
View File

@ -0,0 +1,33 @@
local sides = peripheral.getNames()
for i = 1, #sides do
if peripheral.getType(sides[i]) == "modem" then
modemSide = sides[i]
break
end
end
rednet.open(modemSide)
term.write("Path: ")
path = tostring(read())
local file = fs.open(path, "r")
content = file.readAll()
data = textutils.serialize(content)
term.write("Receiver id: ")
id = tonumber(read())
print("Initialize receiver please!")
print("Press 's' to send")
local event, c = os.pullEvent("char")
if c == "s" then
print("Sending...")
print(id)
rednet.send(id, data)
else
print("Aborted.")
end
rednet.close(modemSide)