Skip to content

Commit

Permalink
Merge pull request #542 from MikaylaFischler/devel
Browse files Browse the repository at this point in the history
2024.08.25 Release
  • Loading branch information
MikaylaFischler authored Aug 26, 2024
2 parents b034265 + 6b20445 commit 07406ca
Show file tree
Hide file tree
Showing 55 changed files with 1,909 additions and 1,228 deletions.
84 changes: 76 additions & 8 deletions ccmsi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,63 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]--

local function println(message) print(tostring(message)) end
local function print(message) term.write(tostring(message)) end

local CCMSI_VERSION = "v1.16"
local CCMSI_VERSION = "v1.17"

local install_dir = "/.install-cache"
local manifest_path = "https://mikaylafischler.github.io/cc-mek-scada/manifests/"
local repo_path = "http://raw.githubusercontent.com/MikaylaFischler/cc-mek-scada/"

---@diagnostic disable-next-line: undefined-global
local _is_pkt_env = pocket -- luacheck: ignore pocket

local function println(msg) print(tostring(msg)) end

-- stripped down & modified copy of log.dmesg
local function print(msg)
msg = tostring(msg)

local cur_x, cur_y = term.getCursorPos()
local out_w, out_h = term.getSize()

-- jump to next line if needed
if cur_x == out_w then
cur_x = 1
if cur_y == out_h then
term.scroll(1)
term.setCursorPos(1, cur_y)
else
term.setCursorPos(1, cur_y + 1)
end
end

-- wrap
local lines, remaining, s_start, s_end, ln = {}, true, 1, out_w + 1 - cur_x, 1
while remaining do
local line = string.sub(msg, s_start, s_end)

if line == "" then
remaining = false
else
lines[ln] = line
s_start = s_end + 1
s_end = s_end + out_w
ln = ln + 1
end
end

-- print
for i = 1, #lines do
cur_x, cur_y = term.getCursorPos()
if i > 1 and cur_x > 1 then
if cur_y == out_h then
term.scroll(1)
term.setCursorPos(1, cur_y)
else term.setCursorPos(1, cur_y + 1) end
end
term.write(lines[i])
end
end

local opts = { ... }
local mode, app, target
local install_manifest = manifest_path.."main/install_manifest.json"
Expand Down Expand Up @@ -219,10 +267,27 @@ end

-- get and validate command line options

println("-- CC Mekanism SCADA Installer "..CCMSI_VERSION.." --")
if _is_pkt_env then println("- SCADA Installer "..CCMSI_VERSION.." -")
else println("-- CC Mekanism SCADA Installer "..CCMSI_VERSION.." --") end

if #opts == 0 or opts[1] == "help" then
println("usage: ccmsi <mode> <app> <branch>")
if _is_pkt_env then
yellow();println("<mode>");lgray()
println(" check - check latest")
println(" install - fresh install")
println(" update - update app")
println(" uninstall - remove app")
yellow();println("<app>");lgray()
println(" reactor-plc")
println(" rtu")
println(" supervisor")
println(" coordinator")
println(" pocket")
println(" installer (update only)")
yellow();println("<branch>");lgray();
println(" main (default) | devel");white()
else
println("<mode>")
lgray()
println(" check - check latest versions available")
Expand All @@ -241,6 +306,7 @@ if #opts == 0 or opts[1] == "help" then
println(" installer - ccmsi installer (update only)")
white();println("<branch>")
lgray();println(" main (default) | devel");white()
end
return
else
mode = get_opt(opts[1], { "check", "install", "update", "uninstall" })
Expand Down Expand Up @@ -286,20 +352,22 @@ if mode == "check" then
-- list all versions
for key, value in pairs(manifest.versions) do
term.setTextColor(colors.purple)
print(string.format("%-14s", "["..key.."]"))
local tag = string.format("%-14s", "["..key.."]")
if not _is_pkt_env then print(tag) end
if key == "installer" or (local_ok and (local_manifest.versions[key] ~= nil)) then
if _is_pkt_env then println(tag) end
blue();print(local_manifest.versions[key])
if value ~= local_manifest.versions[key] then
white();print(" (")
cyan();print(value);white();println(" available)")
else green();println(" (up to date)") end
else
elseif not _is_pkt_env then
lgray();print("not installed");white();print(" (latest ")
cyan();print(value);white();println(")")
end
end

if manifest.versions.installer ~= local_manifest.versions.installer then
if manifest.versions.installer ~= local_manifest.versions.installer and not _is_pkt_env then
yellow();println("\nA different version of the installer is available, it is recommended to update (use 'ccmsi update installer').");white()
end
elseif mode == "install" or mode == "update" then
Expand Down
5 changes: 4 additions & 1 deletion coordinator/configure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,10 @@ local function config_view(display)
end

local function save_and_continue()
for k, v in pairs(tmp_cfg) do settings.set(k, v) end
for _, field in ipairs(fields) do
local k, v = field[1], tmp_cfg[field[1]]
if v == nil then settings.unset(k) else settings.set(k, v) end
end

if settings.save("/coordinator.settings") then
load_settings(settings_cfg, true)
Expand Down
2 changes: 1 addition & 1 deletion coordinator/coordinator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ function coordinator.comms(version, nic, sv_watchdog)
if self.sv_r_seq_num == nil then
self.sv_r_seq_num = packet.scada_frame.seq_num() + 1
elseif self.sv_r_seq_num ~= packet.scada_frame.seq_num() then
log.warning("sequence out-of-order: last = " .. self.sv_r_seq_num .. ", new = " .. packet.scada_frame.seq_num())
log.warning("sequence out-of-order: next = " .. self.sv_r_seq_num .. ", new = " .. packet.scada_frame.seq_num())
return false
elseif self.sv_linked and src_addr ~= self.sv_addr then
log.debug("received packet from unknown computer " .. src_addr .. " while linked; channel in use by another system?")
Expand Down
87 changes: 1 addition & 86 deletions coordinator/iocontrol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function iocontrol.init(conf, comms, temp_scale, energy_scale)
num_units = conf.num_units,
tank_mode = conf.cooling.fac_tank_mode,
tank_defs = conf.cooling.fac_tank_defs,
tank_list = conf.cooling.fac_tank_list,
all_sys_ok = false,
rtu_count = 0,

Expand Down Expand Up @@ -143,92 +144,6 @@ function iocontrol.init(conf, comms, temp_scale, energy_scale)
table.insert(io.facility.sps_ps_tbl, psil.create())
table.insert(io.facility.sps_data_tbl, {})

-- determine tank information
if io.facility.tank_mode == 0 then
io.facility.tank_defs = {}
-- on facility tank mode 0, setup tank defs to match unit tank option
for i = 1, conf.num_units do
io.facility.tank_defs[i] = util.trinary(conf.cooling.r_cool[i].TankConnection, 1, 0)
end

io.facility.tank_list = { table.unpack(io.facility.tank_defs) }
else
-- decode the layout of tanks from the connections definitions
local tank_mode = io.facility.tank_mode
local tank_defs = io.facility.tank_defs
local tank_list = { table.unpack(tank_defs) }

local function calc_fdef(start_idx, end_idx)
local first = 4
for i = start_idx, end_idx do
if io.facility.tank_defs[i] == 2 then
if i < first then first = i end
end
end
return first
end

if tank_mode == 1 then
-- (1) 1 total facility tank (A A A A)
local first_fdef = calc_fdef(1, #tank_defs)
for i = 1, #tank_defs do
if i > first_fdef and tank_defs[i] == 2 then
tank_list[i] = 0
end
end
elseif tank_mode == 2 then
-- (2) 2 total facility tanks (A A A B)
local first_fdef = calc_fdef(1, math.min(3, #tank_defs))
for i = 1, #tank_defs do
if (i ~= 4) and (i > first_fdef) and (tank_defs[i] == 2) then
tank_list[i] = 0
end
end
elseif tank_mode == 3 then
-- (3) 2 total facility tanks (A A B B)
for _, a in pairs({ 1, 3 }) do
local b = a + 1
if (tank_defs[a] == 2) and (tank_defs[b] == 2) then
tank_list[b] = 0
end
end
elseif tank_mode == 4 then
-- (4) 2 total facility tanks (A B B B)
local first_fdef = calc_fdef(2, #tank_defs)
for i = 1, #tank_defs do
if (i ~= 1) and (i > first_fdef) and (tank_defs[i] == 2) then
tank_list[i] = 0
end
end
elseif tank_mode == 5 then
-- (5) 3 total facility tanks (A A B C)
local first_fdef = calc_fdef(1, math.min(2, #tank_defs))
for i = 1, #tank_defs do
if (not (i == 3 or i == 4)) and (i > first_fdef) and (tank_defs[i] == 2) then
tank_list[i] = 0
end
end
elseif tank_mode == 6 then
-- (6) 3 total facility tanks (A B B C)
local first_fdef = calc_fdef(2, math.min(3, #tank_defs))
for i = 1, #tank_defs do
if (not (i == 1 or i == 4)) and (i > first_fdef) and (tank_defs[i] == 2) then
tank_list[i] = 0
end
end
elseif tank_mode == 7 then
-- (7) 3 total facility tanks (A B C C)
local first_fdef = calc_fdef(3, #tank_defs)
for i = 1, #tank_defs do
if (not (i == 1 or i == 2)) and (i > first_fdef) and (tank_defs[i] == 2) then
tank_list[i] = 0
end
end
end

io.facility.tank_list = tank_list
end

-- create facility tank tables
for i = 1, #io.facility.tank_list do
if io.facility.tank_list[i] == 2 then
Expand Down
6 changes: 5 additions & 1 deletion coordinator/session/pocket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function pocket.new_session(id, s_addr, i_seq_num, in_queue, out_queue, timeout)
local function _handle_packet(pkt)
-- check sequence number
if self.r_seq_num ~= pkt.scada_frame.seq_num() then
log.warning(log_header .. "sequence out-of-order: last = " .. self.r_seq_num .. ", new = " .. pkt.scada_frame.seq_num())
log.warning(log_header .. "sequence out-of-order: next = " .. self.r_seq_num .. ", new = " .. pkt.scada_frame.seq_num())
return
else
self.r_seq_num = pkt.scada_frame.seq_num() + 1
Expand Down Expand Up @@ -186,6 +186,10 @@ function pocket.new_session(id, s_addr, i_seq_num, in_queue, out_queue, timeout)
elseif pkt.type == MGMT_TYPE.CLOSE then
-- close the session
_close()
elseif pkt.type == MGMT_TYPE.ESTABLISH then
-- something is wrong, kill the session
_close()
log.warning(log_header .. "terminated session due to an unexpected ESTABLISH packet")
else
log.debug(log_header .. "handler received unsupported SCADA_MGMT packet type " .. pkt.type)
end
Expand Down
2 changes: 1 addition & 1 deletion coordinator/startup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ local renderer = require("coordinator.renderer")
local sounder = require("coordinator.sounder")
local threads = require("coordinator.threads")

local COORDINATOR_VERSION = "v1.5.2"
local COORDINATOR_VERSION = "v1.5.6"

local CHUNK_LOAD_DELAY_S = 30.0

Expand Down
4 changes: 2 additions & 2 deletions coordinator/ui/layout/front_panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ local function init(panel, num_units)
--

local about = Div{parent=main_page,width=15,height=3,x=1,y=16,fg_bg=style.fp.disabled_fg}
local fw_v = TextBox{parent=about,x=1,y=1,text="FW: v00.00.00",alignment=ALIGN.LEFT}
local comms_v = TextBox{parent=about,x=1,y=2,text="NT: v00.00.00",alignment=ALIGN.LEFT}
local fw_v = TextBox{parent=about,x=1,y=1,text="FW: v00.00.00"}
local comms_v = TextBox{parent=about,x=1,y=2,text="NT: v00.00.00"}

fw_v.register(ps, "version", function (version) fw_v.set_value(util.c("FW: ", version)) end)
comms_v.register(ps, "comms_version", function (version) comms_v.set_value(util.c("NT: v", version)) end)
Expand Down
2 changes: 1 addition & 1 deletion graphics/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local flasher = require("graphics.flasher")

local core = {}

core.version = "2.3.1"
core.version = "2.3.3"

core.flasher = flasher
core.events = events
Expand Down
4 changes: 4 additions & 0 deletions graphics/element.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-- Generic Graphics Element
--

-- local log = require("scada-common.log")
local util = require("scada-common.util")

local core = require("graphics.core")
Expand Down Expand Up @@ -503,7 +504,10 @@ function element.new(args, constraint, child_offset_x, child_offset_y)

if args.parent ~= nil then
-- remove self from parent
-- log.debug("removing " .. self.id .. " from parent")
args.parent.__remove_child(self.id)
else
-- log.debug("no parent for " .. self.id .. " on delete attempt")
end
end

Expand Down
5 changes: 5 additions & 0 deletions graphics/elements/listbox.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- Scroll-able List Box Display Graphics Element

-- local log = require("scada-common.log")
local tcd = require("scada-common.tcd")

local core = require("graphics.core")
Expand Down Expand Up @@ -152,6 +153,7 @@ local function listbox(args)
next_y = next_y + item.h + item_pad
item.e.reposition(1, item.y)
item.e.show()
-- log.debug("iterated " .. item.e.get_id())
end

content_height = next_y
Expand Down Expand Up @@ -210,6 +212,7 @@ local function listbox(args)
---@param child graphics_element child element
function e.on_added(id, child)
table.insert(list, { id = id, e = child, y = 0, h = child.get_height() })
-- log.debug("added child " .. id .. " into slot " .. #list)
update_positions()
end

Expand All @@ -219,10 +222,12 @@ local function listbox(args)
for idx, elem in ipairs(list) do
if elem.id == id then
table.remove(list, idx)
-- log.debug("removed child " .. id .. " from slot " .. idx)
update_positions()
return
end
end
-- log.debug("failed to remove child " .. id)
end

-- handle focus
Expand Down
3 changes: 3 additions & 0 deletions graphics/elements/textbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ local function textbox(args)
for i = 1, #lines do
if i > e.frame.h then break end

-- trim leading/trailing whitespace
lines[i] = util.trim(lines[i])

local len = string.len(lines[i])

-- use cursor position to align this line
Expand Down
5 changes: 4 additions & 1 deletion pocket/configure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,10 @@ local function config_view(display)
end

local function save_and_continue()
for k, v in pairs(tmp_cfg) do settings.set(k, v) end
for _, field in ipairs(fields) do
local k, v = field[1], tmp_cfg[field[1]]
if v == nil then settings.unset(k) else settings.set(k, v) end
end

if settings.save("/pocket.settings") then
load_settings(settings_cfg, true)
Expand Down
6 changes: 6 additions & 0 deletions pocket/iocontrol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ function iocontrol.report_link_state(state, sv_addr, api_addr)
end
end

-- show the reason the supervisor connection isn't linking
function iocontrol.report_svr_link_error(msg) io.ps.publish("svr_link_msg", msg) end

-- show the reason the coordinator api connection isn't linking
function iocontrol.report_crd_link_error(msg) io.ps.publish("api_link_msg", msg) end

-- determine supervisor connection quality (trip time)
---@param trip_time integer
function iocontrol.report_svr_tt(trip_time)
Expand Down
Loading

0 comments on commit 07406ca

Please sign in to comment.