From 02541184bd3fe944fad01308d7aa343105064d94 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Wed, 11 May 2022 11:31:02 -0400 Subject: [PATCH] bootloader --- .vscode/settings.json | 5 +-- coordinator/startup.lua | 4 +-- reactor-plc/startup.lua | 6 ++-- rtu/rtu.lua | 2 +- rtu/startup.lua | 22 ++++++------- rtu/threads.lua | 16 +++++----- startup.lua | 52 +++++++++++++++++++++++++++++++ supervisor/session/svsessions.lua | 6 ++-- supervisor/startup.lua | 12 +++---- supervisor/supervisor.lua | 2 +- 10 files changed, 90 insertions(+), 37 deletions(-) create mode 100644 startup.lua diff --git a/.vscode/settings.json b/.vscode/settings.json index 77e08ef..d2812b6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,6 +7,7 @@ "bit", "parallel", "colors", - "textutils" + "textutils", + "shell" ] -} \ No newline at end of file +} diff --git a/coordinator/startup.lua b/coordinator/startup.lua index 5ee3d17..ab90f72 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -6,8 +6,8 @@ local log = require("scada-common.log") local ppm = require("scada-common.ppm") local util = require("scada-common.util") -local config = require("config") -local coordinator = require("coordinator") +local config = require("coordinator.config") +local coordinator = require("coordinator.coordinator") local COORDINATOR_VERSION = "alpha-v0.1.2" diff --git a/reactor-plc/startup.lua b/reactor-plc/startup.lua index 9d79a9c..0aaaeba 100644 --- a/reactor-plc/startup.lua +++ b/reactor-plc/startup.lua @@ -7,9 +7,9 @@ local mqueue = require("scada-common.mqueue") local ppm = require("scada-common.ppm") local util = require("scada-common.util") -local config = require("config") -local plc = require("plc") -local threads = require("threads") +local config = require("reactor-plc.config") +local plc = require("reactor-plc.plc") +local threads = require("reactor-plc.threads") local R_PLC_VERSION = "alpha-v0.6.6" diff --git a/rtu/rtu.lua b/rtu/rtu.lua index ec20c93..f7b0432 100644 --- a/rtu/rtu.lua +++ b/rtu/rtu.lua @@ -4,7 +4,7 @@ local log = require("scada-common.log") local types = require("scada-common.types") local util = require("scada-common.util") -local modbus = require("modbus") +local modbus = require("rtu.modbus") local rtu = {} diff --git a/rtu/startup.lua b/rtu/startup.lua index 18119c0..ad31460 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -9,18 +9,18 @@ local rsio = require("scada-common.rsio") local types = require("scada-common.types") local util = require("scada-common.util") -local config = require("config") -local modbus = require("modbus") -local rtu = require("rtu") -local threads = require("threads") +local config = require("rtu.config") +local modbus = require("rtu.modbus") +local rtu = require("rtu.rtu") +local threads = require("rtu.threads") -local redstone_rtu = require("dev.redstone_rtu") -local boiler_rtu = require("dev.boiler_rtu") -local boilerv_rtu = require("dev.boilerv_rtu") -local energymachine_rtu = require("dev.energymachine_rtu") -local imatrix_rtu = require("dev.imatrix_rtu") -local turbine_rtu = require("dev.turbine_rtu") -local turbinev_rtu = require("dev.turbinev_rtu") +local redstone_rtu = require("rtu.dev.redstone_rtu") +local boiler_rtu = require("rtu.dev.boiler_rtu") +local boilerv_rtu = require("rtu.dev.boilerv_rtu") +local energymachine_rtu = require("rtu.dev.energymachine_rtu") +local imatrix_rtu = require("rtu.dev.imatrix_rtu") +local turbine_rtu = require("rtu.dev.turbine_rtu") +local turbinev_rtu = require("rtu.dev.turbinev_rtu") local RTU_VERSION = "alpha-v0.6.2" diff --git a/rtu/threads.lua b/rtu/threads.lua index 213781e..447178b 100644 --- a/rtu/threads.lua +++ b/rtu/threads.lua @@ -5,15 +5,15 @@ local ppm = require("scada-common.ppm") local types = require("scada-common.types") local util = require("scada-common.util") -local redstone_rtu = require("dev.redstone_rtu") -local boiler_rtu = require("dev.boiler_rtu") -local boilerv_rtu = require("dev.boilerv_rtu") -local energymachine_rtu = require("dev.energymachine_rtu") -local imatrix_rtu = require("dev.imatrix_rtu") -local turbine_rtu = require("dev.turbine_rtu") -local turbinev_rtu = require("dev.turbinev_rtu") +local redstone_rtu = require("rtu.dev.redstone_rtu") +local boiler_rtu = require("rtu.dev.boiler_rtu") +local boilerv_rtu = require("rtu.dev.boilerv_rtu") +local energymachine_rtu = require("rtu.dev.energymachine_rtu") +local imatrix_rtu = require("rtu.dev.imatrix_rtu") +local turbine_rtu = require("rtu.dev.turbine_rtu") +local turbinev_rtu = require("rtu.dev.turbinev_rtu") -local modbus = require("modbus") +local modbus = require("rtu.modbus") local threads = {} diff --git a/startup.lua b/startup.lua new file mode 100644 index 0000000..0a5cffb --- /dev/null +++ b/startup.lua @@ -0,0 +1,52 @@ +local util = require("scada-common.util") + +local BOOTLOADER_VERSION = "0.1" + +local println = util.println +local println_ts = util.println_ts + +println("SCADA BOOTLOADER V" .. BOOTLOADER_VERSION) + +local exit_code = false + +println_ts("BOOT> SCANNING FOR APPLICATIONS...") + +if fs.exists("reactor-plc/startup.lua") then + -- found reactor-plc application + println("BOOT> FOUND REACTOR PLC APPLICATION") + println("BOOT> EXEC STARTUP") + exit_code = shell.execute("reactor-plc/startup") +elseif fs.exists("rtu/startup.lua") then + -- found rtu application + println("BOOT> FOUND RTU APPLICATION") + println("BOOT> EXEC STARTUP") + exit_code = shell.execute("rtu/startup") +elseif fs.exists("supervisor/startup.lua") then + -- found supervisor application + println("BOOT> FOUND SUPERVISOR APPLICATION") + println("BOOT> EXEC STARTUP") + exit_code = shell.execute("supervisor/startup") +elseif fs.exists("coordinator/startup.lua") then + -- found coordinator application + println("BOOT> FOUND COORDINATOR APPLICATION") + println("BOOT> EXEC STARTUP") + exit_code = shell.execute("coordinator/startup") +elseif fs.exists("pocket/startup.lua") then + -- found pocket application + println("BOOT> FOUND POCKET APPLICATION") + println("BOOT> EXEC STARTUP") + exit_code = shell.execute("pocket/startup") +else + -- no known applications found + println("BOOT> NO SCADA STARTUP APPLICATION FOUND") + println("BOOT> EXIT") + return false +end + +if exit_code then + println_ts("BOOT> APPLICATION EXITED OK") +else + println_ts("BOOT> APPLICATION CRASHED") +end + +return exit_code diff --git a/supervisor/session/svsessions.lua b/supervisor/session/svsessions.lua index fa983a6..e596985 100644 --- a/supervisor/session/svsessions.lua +++ b/supervisor/session/svsessions.lua @@ -1,9 +1,9 @@ local log = require("scada-common.log") local mqueue = require("scada-common.mqueue") -local coordinator = require("session.coordinator") -local plc = require("session.plc") -local rtu = require("session.rtu") +local coordinator = require("supervisor.session.coordinator") +local plc = require("supervisor.session.plc") +local rtu = require("supervisor.session.rtu") -- Supervisor Sessions Handler diff --git a/supervisor/startup.lua b/supervisor/startup.lua index bf0eabc..be9549e 100644 --- a/supervisor/startup.lua +++ b/supervisor/startup.lua @@ -6,13 +6,13 @@ local log = require("scada-common.log") local ppm = require("scada-common.ppm") local util = require("scada-common.util") -local coordinator = require("session.coordinator") -local plc = require("session.plc") -local rtu = require("session.rtu") -local svsessions = require("session.svsessions") +local coordinator = require("supervisor.session.coordinator") +local plc = require("supervisor.session.plc") +local rtu = require("supervisor.session.rtu") +local svsessions = require("supervisor.session.svsessions") -local config = require("config") -local supervisor = require("supervisor") +local config = require("supervisor.config") +local supervisor = require("supervisor.supervisor") local SUPERVISOR_VERSION = "alpha-v0.3.4" diff --git a/supervisor/supervisor.lua b/supervisor/supervisor.lua index 3d4fa17..f9df71e 100644 --- a/supervisor/supervisor.lua +++ b/supervisor/supervisor.lua @@ -2,7 +2,7 @@ local comms = require("scada-common.comms") local log = require("scada-common.log") local util = require("scada-common.util") -local svsessions = require("session.svsessions") +local svsessions = require("supervisor.session.svsessions") local supervisor = {}