Posted 26 April 2012 - 06:57 PM
I have two programs, one is a "monitor" program that receives status updates from the other, the "control" program.
The control program regulates a nuclear reactor from IC2. The problem is kinda minor, I just can't seem to figure out why when the monitor is updated, the "Reactor Control Connected" variable seems to flash "Not Connected" and "Connected" multiple times, problem is, the code shouldn't allow it to do that so quickly.
Oh and a pretty big problem is that I run these two programs along with a main control program and the server gives overflow warnings. :/ So someone please look these two over and point out any problems, please.
I've attached the two programs to this post as well.
I'm also fairly certain the control program is not the culprit, nor do I have any problems with it, it's fairly simple.
Reactor Control
—————————–
Reactor Control Monitor
———————
The control program regulates a nuclear reactor from IC2. The problem is kinda minor, I just can't seem to figure out why when the monitor is updated, the "Reactor Control Connected" variable seems to flash "Not Connected" and "Connected" multiple times, problem is, the code shouldn't allow it to do that so quickly.
Oh and a pretty big problem is that I run these two programs along with a main control program and the server gives overflow warnings. :/ So someone please look these two over and point out any problems, please.
I've attached the two programs to this post as well.
I'm also fairly certain the control program is not the culprit, nor do I have any problems with it, it's fairly simple.
Reactor Control
—————————–
Spoiler
-- Reactor Control v2.1b
local version = "v2.1b"
local computerId = 0
local mainControlId = 2
local monitorId = 4
local keepRunning = "False"
local screenMessage = "0"
local screenWarning = "0"
local screenStatus = "0"
local emergencyShutdown = "Off"
local modemState = "Off"
local reactorRunning = false
local reactorCooling = false
local mainControlConnected = "Not Connected"
local monitorConnected = "Not Connected"
local reactorRunningTimer = false
local reactorCoolingTimer = false
local mainControlPingBack = true
local r1 = false
local r2 = false
local r3 = false
local r4 = false
local r5 = false
local r6 = false
local r7 = false
local r8 = false
local r9 = false
local r10 = false
local r11 = false
local r12 = false
function getRedstoneStateBottom()
local state = redstone.getInput("bottom")
if state == true then
emergencyShutdown = "On"
else
emergencyShutdown = "Off"
end
return state
end
function forceReactorStart()
r1 = false
r2 = false
r3 = false
r4 = false
r5 = false
r6 = false
r7 = false
r8 = false
r9 = false
r10 = false
r11 = false
r12 = false
reactorCoolintg = false
reactorRunning = true
redstone.setOutput("right", false)
screenMessage = "Reactor Started"
screenStatus = "Running"
sreenWarning = "Reactor forced to start"
reactorRunningTimer = os.startTimer(60)
end
function startReactor()
if r1 == true or r12 == true then
screenWarning = "WARNING: Reactor appears to not have been properly cooled down."
startCooldownPhase()
update()
return true
elseif emergencyShutdown == "On" then
screenWarning = "WARNING: Tried to start while Emergency Shutdown is on."
screenStatus = "Off"
reactorRunning = false
update()
return true
end
redstone.setOutput("right", false)
screenMessage = ("Reactor started.")
reactorRunningTimer = os.startTimer(60)
reactorRunning = true
screenStatus = "Running"
update()
end
function stopReactor()
redstone.setOutput("right", true)
if reactorRunning == true then
screenMessage = ("Reactor stopped.")
reactorRunning = false
screenStatus = "Off"
update()
end
end
function ping()
if mainControlPingBack == false then
mainControlConnected = "Not Connected"
end
if monitorPingBack == false then
monitorConnected = "Not Connected"
end
if rednet.isOpen("top") == true then
modemState = "On"
rednet.send(mainControlId, "ping")
mainControlPingBack = false
rednet.send(monitorId, "ping")
monitorPingBack = false
else
modemState = "Off"
keepRunning = "False"
end
if reactorRunning == true then
screenStatus = "Running"
elseif reactorCooling == true then
screenStatus = "Cooling"
else
screenStatus = "Off"
end
update()
wScreen()
end
function getEvent()
local eName, eArg1, eArg2 = os.pullEvent()
return eName, eArg1, eArg2
end
function startCooldownPhase()
screenMessage = "Cooldown phase started."
reactorCooling = true
screenStatus = "Cooling"
c1 = false
c2 = false
c3 = false
c4 = false
reactorCoolingTimer = os.startTimer(60)
screenMessage = "Cooldown phase over in 3 minutes."
update()
end
function wScreen()
shell.run("clear")
spacerB = " "
spacerM = " "
print(spacerB, "Reactor Control")
print(" ")
print(" ")
print("Computer Id: ", computerId)
print("Version:", version)
print("Modem State:",modemState)
print("Control Connected:", mainControlConnected)
print("Monitor Connected:", monitorConnected)
print("Keep Running:", keepRunning)
print("Status:", screenStatus)
print("Emergency Shutdown:", emergencyShutdown)
print("Warning: ", screenWarning)
print("Message: ", screenMessage)
end
function update()
rednet.send(monitorId, "update")
rednet.send(monitorId, keepRunning)
rednet.send(monitorId, screenStatus)
rednet.send(monitorId, emergencyShutdown)
rednet.send(monitorId, screenWarning)
rednet.send(monitorId, screenMessage)
end
function standby()
while pRunning == true do
local eName, eArg1, eArg2 = getEvent()
if eName == "timer" then
if reactorRunning == true then
if r1 == false then
screenMessage = "Reactor cooldown phase in 11 minutes."
r1 = true
reactorRunningTimer = os.startTimer(60)
update()
elseif r2 == false then
screenMessage = "Reactor cooldown phase in 10 minutes."
r2 = true
reactorRunningTimer = os.startTimer(60)
update()
elseif r3 == false then
screenMessage = "Reactor cooldown phase in 9 minutes."
r3 = true
reactorRunningTimer = os.startTimer(60)
update()
elseif r4 == false then
screenMessage = "Reactor cooldown phase in 8minutes."
r4 = true
reactorRunningTimer = os.startTimer(60)
update()
elseif r5 == false then
screenMessage = "Reactor cooldown phase in 7 minutes."
r5 = true
reactorRunningTimer = os.startTimer(60)
update()
elseif r6 == false then
screenMessage = "Reactor coldown phase in 6 minutes."
r6 = true
reactorRunningTimer = os.startTimer(60)
update()
elseif r7 == false then
screenMessage = "Reactor coldown phase in 5 minutes."
r7 = true
reactorRunningTimer = os.startTimer(60)
update()
elseif r8 == false then
screenMessage = "Reactor coldown phase in 4 minutes."
r8 = true
reactorRunningTimer = os.startTimer(60)
update()
elseif r9 == false then
screenMessage = "Reactor coldown phase in 3 minutes."
r9 = true
reactorRunningTimer = os.startTimer(60)
update()
elseif r10 == false then
screenMessage = "Reactor cooldown phase in 2 minutes"
r10 = true
reactorRunningTimer = os.startTimer(60)
update()
elseif r11 == false then
screenMessage = "Reactor cooldown phase in 1 minute."
r11 = true
reactorRunningTimer = os.startTimer(60)
update()
elseif r12 == false then
screenMessage = "Cooldown phase started."
r12 = true
stopReactor()
startCooldownPhase()
end
elseif reactorCooling == true then
if c1 == false then
screenMessage = "Cooling phase over in 3 minutes."
c1 = true
r12 = false
r11= false
r10 = false
reactorCoolingTimer = os.startTimer(60)
update()
elseif c2 == false then
screenMessage = "Cooling phase over in 2 minutes."
c2 = true
r9 = false
r8 = false
r7 = false
reactorCoolingTimer = os.startTimer(60)
update()
elseif c3 == false then
screenMessage = "Cooling phase over in 1 minute."
c3 = true
r6 = false
r5 = false
r4 = false
reactorCoolingTimer = os.startTimer(60)
update()
elseif c4 == false then
screenMessage = "Cooling phase complete."
c4 = true
r3 = false
r2 = false
r1 = false
reactorCooling = false
screenStatus = "Off"
update()
if keepRunning == "True" and emergencyShutdown == "Off" then
startReactor()
end
end
end
elseif eName == "redstone" then
if redstone.getInput("bottom") == true then
emergencyShutdown = "On"
keepRunning = "False"
stopReactor()
startCooldownPhase()
elseif redstone.getInput("bottom") == false then
emergencyShutdown = "Off"
end
if redstone.getInput("left") == true then
ping()
end
elseif eName == "char" then
print(eArg1)
if eArg1 == "o" then
print("Enter Override Command: ")
local input = read()
if input == "q" then
pRunning = false
rednet.close("top")
print("Quitting..")
end
end
elseif eName == "rednet_message" then
if eArg1 == mainControlId then
if eArg2 == "ping" then
rednet.send(mainControlId, "pingBack")
elseif eArg2 == "pingBack" then
mainControlConnected = "Connected"
wScreen()
mainControlPingBack = true
elseif eArg2 == "Start Reactor" then
startReactor()
rednet.send(mainControlId, "Reactor Started")
elseif eArg2 == "Force Reactor Start" then
forceReactorStart()
rednet.send(mainControlId, "Reactor Forced to start.")
elseif eArg2 == "Stop Reactor" then
stopReactor()
keepRunning = "False"
startCooldownPhase()
rednet.send(mainControlId, "Reactor Stopped. Starting cooldown phase.")
elseif eArg2 == "Run Reactor" then
keepRunning = "True"
startReactor()
rednet.send(mainControlId, "Reactor main sequence started.")
elseif eArg2 == "Keep Running" then
if reactorRunning == true then
keepRunning = "True"
rednet.send(mainControlId, "Main sequence initiated.")
elseif reactorCooling == true then
keepRunning = "True"
rednet.send(mainControlId, "Main sequence will start after cooldown phase is complete.")
else
rednet.send(mainControlId, "Reactor is not active. Send command to start sequence if you wish.")
end
else
print(eArg2)
rednet.send(mainControlId, "That is not a valid command.")
end
elseif eArg1 == monitorId then
if eArg2 == "pingBack" then
monitorConnected = "Connected"
monitorPingBack = true
elseif eArg2 == "ping" then
rednet.send(monitorId, "pingBack")
end
end
end
end
end
redstone.setOutput("right", true)
getRedstoneStateBottom()
rednet.open("top")
ping()
pRunning = true
standby()
Reactor Control Monitor
———————
Spoiler
-- Reactor Control Monitor v0.8b
local computerId = 4
local monitorPingTimer
local reactorControlId = 0
local reactorMonitorVersion = "v0.6a"
local modemState = "Off"
local updating = "Not Updating"
local reactorControlConnectedToMonitor = "Not Connected"
local reactorKeepRunning = ""
local reactorEmergencyShutdown = ""
local reactorStatus = ""
local reactorWarningMessage = ""
local reactorMessage = ""
local pRunning = true
local reactorControlPingBack
function writeScreen()
shell.run("clear")
print(" Reactor Control Monitor")
print(" ")
print(" ")
print("Id: ", computerId)
print("Version: ", reactorMonitorVersion)
print("Modem State: ", modemState)
print("")
print("Control: ", reactorControlConnectedToMonitor)
print("Keep Running: ", reactorKeepRunning)
print("E. Shutdown: ", reactorEmergencyShutdown)
print("Status: ", reactorStatus)
print("Warning Msg: ", reactorWarningMessage)
print("Message: ", reactorMessage)
end
function ping()
if rednet.isOpen("right") == true then
modemState = "On"
if reactorControlPingBack == false then
reactorControlConnectedToMonitor = "Not Connected"
elseif reactorControlPingBack == true then
reactorControlConnectedToMonitor = "Connected"
end
if reactorControlId ~= false then
rednet.send(reactorControlId, "ping")
reactorControlPingBack = false
else
reactorControlConnectedToMonitor = "Id not set"
end
else
shell.run("clear")
print("Modem is off or missing..")
end
monitorPingTimer = os.startTimer(10)
end
function standby()
while pRunning == true do
local eName, eArg1, eArg2 = os.pullEvent()
if eName == "rednet_message" then
if eArg1 == reactorControlId then
if eArg2 == "pingBack" then
reactorControlPingBack = true
elseif eArg2 == "update" then
local eArg1, eArg2 = rednet.receive(2)
if eArg2 == "True" or eArg2 == "False" then
reactorKeepRunning = eArg2
end
local eArg1, eArg2 = rednet.receive(2)
if eArg2 == "Off" or eArg2 == "Running" or eArg2 == "False" then
reactorStatus = eArg2
end
local eArg1, eArg2 = rednet.receive(2)
if eArg2 == "Off" or eArg2 == "On" then
reactorEmergencyShutdown = eArg2
end
local eArg1, eArg2 = rednet.receive(2)
if eArg2 ~= "pingBack" then
reactorWarningMessage = eArg2
end
local eArg1, eArg2 = rednet.receive(2)
if eArg2 ~= "pingBack" then
reactorMessage = eArg2
end
writeScreen()
elseif eArg2 == "ping" then
rednet.send(reactorControlId, "pingBack")
end
end
elseif eName == "timer" then
ping()
writeScreen()
end
end
end
pRunning = true
rednet.open("right")
print("Reactor Control Monitor Initializing..")
monitorPingTimer = os.startTimer(3)
standby()