#65 safe concat where appropriate

This commit is contained in:
Mikayla Fischler
2022-06-05 11:16:25 -04:00
parent 5068e47590
commit f0c97e8b70
12 changed files with 40 additions and 39 deletions

View File

@ -738,7 +738,7 @@ function plc.comms(id, version, modem, local_port, server_port, reactor, rps, co
log.warning("PLC KEEP_ALIVE trip time > 500ms (" .. trip_time .. "ms)") log.warning("PLC KEEP_ALIVE trip time > 500ms (" .. trip_time .. "ms)")
end end
-- log.debug("RPLC RTT = ".. trip_time .. "ms") -- log.debug("RPLC RTT = " .. trip_time .. "ms")
_send_keep_alive_ack(timestamp) _send_keep_alive_ack(timestamp)
else else

View File

@ -383,7 +383,7 @@ function rtu.comms(version, modem, local_port, server_port, conn_watchdog)
log.warning("RTU KEEP_ALIVE trip time > 500ms (" .. trip_time .. "ms)") log.warning("RTU KEEP_ALIVE trip time > 500ms (" .. trip_time .. "ms)")
end end
-- log.debug("RTU RTT = ".. trip_time .. "ms") -- log.debug("RTU RTT = " .. trip_time .. "ms")
_send_keep_alive_ack(timestamp) _send_keep_alive_ack(timestamp)
else else

View File

@ -102,7 +102,7 @@ for entry_idx = 1, #rtu_redstone do
local capabilities = {} local capabilities = {}
log.debug("init> starting redstone RTU I/O linking for reactor " .. io_reactor .. "...") log.debug(util.c("init> starting redstone RTU I/O linking for reactor ", io_reactor, "..."))
local continue = true local continue = true
@ -110,7 +110,7 @@ for entry_idx = 1, #rtu_redstone do
local unit = units[i] ---@type rtu_unit_registry_entry local unit = units[i] ---@type rtu_unit_registry_entry
if unit.reactor == io_reactor and unit.type == rtu_t.redstone then if unit.reactor == io_reactor and unit.type == rtu_t.redstone then
-- duplicate entry -- duplicate entry
log.warning("init> skipping definition block #" .. entry_idx .. " for reactor " .. io_reactor .. " with already defined redstone I/O") log.warning(util.c("init> skipping definition block #", entry_idx, " for reactor ", io_reactor, " with already defined redstone I/O"))
continue = false continue = false
break break
end end
@ -131,8 +131,8 @@ for entry_idx = 1, #rtu_redstone do
end end
if not valid then if not valid then
local message = "init> invalid redstone definition at index " .. i .. " in definition block #" .. entry_idx .. local message = util.c("init> invalid redstone definition at index ", i, " in definition block #", entry_idx,
" (for reactor " .. io_reactor .. ")" " (for reactor ", io_reactor, ")")
println_ts(message) println_ts(message)
log.warning(message) log.warning(message)
else else
@ -141,7 +141,7 @@ for entry_idx = 1, #rtu_redstone do
if mode == rsio.IO_MODE.DIGITAL_IN then if mode == rsio.IO_MODE.DIGITAL_IN then
-- can't have duplicate inputs -- can't have duplicate inputs
if util.table_contains(capabilities, conf.channel) then if util.table_contains(capabilities, conf.channel) then
log.warning("init> skipping duplicate input for channel " .. rsio.to_string(conf.channel) .. " on side " .. conf.side) log.warning(util.c("init> skipping duplicate input for channel ", rsio.to_string(conf.channel), " on side ", conf.side))
else else
rs_rtu.link_di(conf.side, conf.bundled_color) rs_rtu.link_di(conf.side, conf.bundled_color)
end end
@ -150,7 +150,7 @@ for entry_idx = 1, #rtu_redstone do
elseif mode == rsio.IO_MODE.ANALOG_IN then elseif mode == rsio.IO_MODE.ANALOG_IN then
-- can't have duplicate inputs -- can't have duplicate inputs
if util.table_contains(capabilities, conf.channel) then if util.table_contains(capabilities, conf.channel) then
log.warning("init> skipping duplicate input for channel " .. rsio.to_string(conf.channel) .. " on side " .. conf.side) log.warning(util.c("init> skipping duplicate input for channel ", rsio.to_string(conf.channel), " on side ", conf.side))
else else
rs_rtu.link_ai(conf.side) rs_rtu.link_ai(conf.side)
end end
@ -164,8 +164,8 @@ for entry_idx = 1, #rtu_redstone do
table.insert(capabilities, conf.channel) table.insert(capabilities, conf.channel)
log.debug("init> linked redstone " .. #capabilities .. ": " .. rsio.to_string(conf.channel) .. " (" .. conf.side .. log.debug(util.c("init> linked redstone ", #capabilities, ": ", rsio.to_string(conf.channel), " (", conf.side, ") for reactor ",
") for reactor " .. io_reactor) io_reactor))
end end
end end
@ -184,7 +184,7 @@ for entry_idx = 1, #rtu_redstone do
table.insert(units, unit) table.insert(units, unit)
log.debug("init> initialized RTU unit #" .. #units .. ": redstone_io (redstone) [1] for reactor " .. io_reactor) log.debug(util.c("init> initialized RTU unit #", #units, ": redstone_io (redstone) [1] for reactor ", io_reactor))
end end
end end
@ -193,7 +193,7 @@ for i = 1, #rtu_devices do
local device = ppm.get_periph(rtu_devices[i].name) local device = ppm.get_periph(rtu_devices[i].name)
if device == nil then if device == nil then
local message = "init> '" .. rtu_devices[i].name .. "' not found" local message = util.c("init> '", rtu_devices[i].name, "' not found")
println_ts(message) println_ts(message)
log.warning(message) log.warning(message)
else else
@ -231,7 +231,7 @@ for i = 1, #rtu_devices do
rtu_type = rtu_t.env_detector rtu_type = rtu_t.env_detector
rtu_iface = envd_rtu.new(device) rtu_iface = envd_rtu.new(device)
else else
local message = "init> device '" .. rtu_devices[i].name .. "' is not a known type (" .. type .. ")" local message = util.c("init> device '", rtu_devices[i].name, "' is not a known type (", type, ")")
println_ts(message) println_ts(message)
log.warning(message) log.warning(message)
end end
@ -254,8 +254,8 @@ for i = 1, #rtu_devices do
table.insert(units, rtu_unit) table.insert(units, rtu_unit)
log.debug("init> initialized RTU unit #" .. #units .. ": " .. rtu_devices[i].name .. " (" .. rtu_type .. ") [" .. log.debug(util.c("init> initialized RTU unit #", #units, ": ", rtu_devices[i].name, " (", rtu_type, ") [",
rtu_devices[i].index .. "] for reactor " .. rtu_devices[i].for_reactor) rtu_devices[i].index, "] for reactor ", rtu_devices[i].for_reactor))
end end
end end
end end

View File

@ -307,7 +307,7 @@ function threads.thread__unit_comms(smem, unit)
end end
if not rtu_state.shutdown then if not rtu_state.shutdown then
log.info("rtu unit thread " .. unit.name .. "(" .. unit.type .. ") restarting in 5 seconds...") log.info(util.c("rtu unit thread ", unit.name, "(", unit.type, ") restarting in 5 seconds..."))
util.psleep(5) util.psleep(5)
end end
end end

View File

@ -107,7 +107,7 @@ function crypto.encrypt(plaintext)
local ciphertext = c_eng.cipher.asHex() ---@type hex local ciphertext = c_eng.cipher.asHex() ---@type hex
log.debug("crypto.encrypt: aes128-ctr-mode took " .. (util.time() - start) .. "ms") log.debug("crypto.encrypt: aes128-ctr-mode took " .. (util.time() - start) .. "ms")
log.debug("ciphertext: " .. ciphertext) log.debug("ciphertext: " .. util.strval(ciphertext))
return iv, ciphertext return iv, ciphertext
end end
@ -129,7 +129,7 @@ function crypto.decrypt(iv, ciphertext)
local plaintext = stream.toString(stream.fromHex(plaintext_hex)) local plaintext = stream.toString(stream.fromHex(plaintext_hex))
log.debug("crypto.decrypt: aes128-ctr-mode took " .. (util.time() - start) .. "ms") log.debug("crypto.decrypt: aes128-ctr-mode took " .. (util.time() - start) .. "ms")
log.debug("plaintext: " .. plaintext) log.debug("plaintext: " .. util.strval(plaintext))
return plaintext return plaintext
end end
@ -146,7 +146,7 @@ function crypto.hmac(message_hex)
local hash = c_eng.hmac.asHex() ---@type hex local hash = c_eng.hmac.asHex() ---@type hex
log.debug("crypto.hmac: hmac-sha1 took " .. (util.time() - start) .. "ms") log.debug("crypto.hmac: hmac-sha1 took " .. (util.time() - start) .. "ms")
log.debug("hmac: " .. hash) log.debug("hmac: " .. util.strval(hash))
return hash return hash
end end

View File

@ -177,7 +177,7 @@ function log.dmesg(msg, tag, tag_color)
out.write(lines[i]) out.write(lines[i])
end end
_log("[" .. t_stamp .. "] " .. tag .. " " .. msg) _log(util.c("[", t_stamp, "] ", tag, " ", msg))
end end
-- log debug messages -- log debug messages

View File

@ -3,6 +3,7 @@
-- --
local log = require("scada-common.log") local log = require("scada-common.log")
local util = require("scada-common.util")
---@class ppm ---@class ppm
local ppm = {} local ppm = {}
@ -76,7 +77,7 @@ local function peri_init(iface)
count_str = " [" .. self.fault_counts[key] .. " total faults]" count_str = " [" .. self.fault_counts[key] .. " total faults]"
end end
log.error("PPM: protected " .. key .. "() -> " .. result .. count_str) log.error(util.c("PPM: protected ", key, "() -> ", result, count_str))
end end
self.fault_counts[key] = self.fault_counts[key] + 1 self.fault_counts[key] = self.fault_counts[key] + 1
@ -176,7 +177,7 @@ function ppm.mount_all()
for i = 1, #ifaces do for i = 1, #ifaces do
_ppm_sys.mounts[ifaces[i]] = peri_init(ifaces[i]) _ppm_sys.mounts[ifaces[i]] = peri_init(ifaces[i])
log.info("PPM: found a " .. _ppm_sys.mounts[ifaces[i]].type .. " (" .. ifaces[i] .. ")") log.info(util.c("PPM: found a ", _ppm_sys.mounts[ifaces[i]].type, " (", ifaces[i], ")"))
end end
if #ifaces == 0 then if #ifaces == 0 then
@ -199,7 +200,7 @@ function ppm.mount(iface)
pm_type = _ppm_sys.mounts[iface].type pm_type = _ppm_sys.mounts[iface].type
pm_dev = _ppm_sys.mounts[iface].dev pm_dev = _ppm_sys.mounts[iface].dev
log.info("PPM: mount(" .. iface .. ") -> found a " .. pm_type) log.info(util.c("PPM: mount(", iface, ") -> found a ", pm_type))
break break
end end
end end
@ -221,9 +222,9 @@ function ppm.handle_unmount(iface)
pm_type = lost_dev.type pm_type = lost_dev.type
pm_dev = lost_dev.dev pm_dev = lost_dev.dev
log.warning("PPM: lost device " .. pm_type .. " mounted to " .. iface) log.warning(util.c("PPM: lost device ", pm_type, " mounted to ", iface))
else else
log.error("PPM: lost device unknown to the PPM mounted to " .. iface) log.error(util.c("PPM: lost device unknown to the PPM mounted to ", iface))
end end
return pm_type, pm_dev return pm_type, pm_dev

View File

@ -391,8 +391,8 @@ function plc.new_session(id, for_reactor, in_queue, out_queue)
log.warning(log_header .. "PLC KEEP_ALIVE round trip time > 500ms (" .. self.last_rtt .. "ms)") log.warning(log_header .. "PLC KEEP_ALIVE round trip time > 500ms (" .. self.last_rtt .. "ms)")
end end
-- log.debug(log_header .. "PLC RTT = ".. self.last_rtt .. "ms") -- log.debug(log_header .. "PLC RTT = " .. self.last_rtt .. "ms")
-- log.debug(log_header .. "PLC TT = ".. (srv_now - plc_send) .. "ms") -- log.debug(log_header .. "PLC TT = " .. (srv_now - plc_send) .. "ms")
else else
log.debug(log_header .. "SCADA keep alive packet length mismatch") log.debug(log_header .. "SCADA keep alive packet length mismatch")
end end

View File

@ -235,8 +235,8 @@ function rtu.new_session(id, in_queue, out_queue, advertisement)
log.warning(log_header .. "RTU KEEP_ALIVE round trip time > 500ms (" .. self.last_rtt .. "ms)") log.warning(log_header .. "RTU KEEP_ALIVE round trip time > 500ms (" .. self.last_rtt .. "ms)")
end end
-- log.debug(log_header .. "RTU RTT = ".. self.last_rtt .. "ms") -- log.debug(log_header .. "RTU RTT = " .. self.last_rtt .. "ms")
-- log.debug(log_header .. "RTU TT = ".. (srv_now - rtu_send) .. "ms") -- log.debug(log_header .. "RTU TT = " .. (srv_now - rtu_send) .. "ms")
else else
log.debug(log_header .. "SCADA keep alive packet length mismatch") log.debug(log_header .. "SCADA keep alive packet length mismatch")
end end

View File

@ -104,7 +104,7 @@ function redstone.new(session_id, unit_id, advert, out_queue)
table.insert(self.io_list.analog_out, channel) table.insert(self.io_list.analog_out, channel)
else else
-- should be unreachable code, we already validated channels -- should be unreachable code, we already validated channels
log.error(log_tag .. "failed to identify advertisement channel IO mode (" .. channel .. ")", true) log.error(util.c(log_tag, "failed to identify advertisement channel IO mode (", channel, ")"), true)
return nil return nil
end end
@ -212,8 +212,8 @@ function redstone.new(session_id, unit_id, advert, out_queue)
break break
end end
end end
elseif mode ~= nil then else
log.debug(log_tag .. "attemted write to non D/O or A/O mode " .. mode) log.debug(util.c(log_tag, "attemted write to non D/O or A/O mode ", mode))
end end
end end
end end

View File

@ -237,7 +237,7 @@ function turbinev.new(session_id, unit_id, advert, out_queue)
elseif cmd == TBV_RTU_S_CMDS.DEC_DUMP_MODE then elseif cmd == TBV_RTU_S_CMDS.DEC_DUMP_MODE then
_dec_dump_mode() _dec_dump_mode()
else else
log.debug(log_tag .. "unrecognized in_q command " .. util.strval(cmd)) log.debug(util.c(log_tag, "unrecognized in_q command ", cmd))
end end
elseif msg.qtype == mqueue.TYPE.DATA then elseif msg.qtype == mqueue.TYPE.DATA then
-- instruction with body -- instruction with body
@ -245,7 +245,7 @@ function turbinev.new(session_id, unit_id, advert, out_queue)
if cmd.key == TBV_RTU_S_DATA.SET_DUMP_MODE then if cmd.key == TBV_RTU_S_DATA.SET_DUMP_MODE then
_set_dump_mode(cmd.val) _set_dump_mode(cmd.val)
else else
log.debug(log_tag .. "unrecognized in_q data " .. util.strval(cmd.key)) log.debug(util.c(log_tag, "unrecognized in_q data ", cmd.key))
end end
end end
end end

View File

@ -187,11 +187,11 @@ function supervisor.comms(version, num_reactors, modem, dev_listen, coord_listen
local plc_id = svsessions.establish_plc_session(l_port, r_port, packet.data[1], packet.data[2]) local plc_id = svsessions.establish_plc_session(l_port, r_port, packet.data[1], packet.data[2])
if plc_id == false then if plc_id == false then
-- reactor already has a PLC assigned -- reactor already has a PLC assigned
log.debug("PLC_LNK: assignment collision with reactor " .. packet.data[1]) log.debug(util.c("PLC_LNK: assignment collision with reactor ", packet.data[1]))
_send_plc_linking(next_seq_id, r_port, { RPLC_LINKING.COLLISION }) _send_plc_linking(next_seq_id, r_port, { RPLC_LINKING.COLLISION })
else else
-- got an ID; assigned to a reactor successfully -- got an ID; assigned to a reactor successfully
println("connected to reactor " .. packet.data[1] .. " PLC (" .. packet.data[2] .. ") [:" .. r_port .. "]") println(util.c("connected to reactor ", packet.data[1], " PLC (", packet.data[2], ") [:", r_port, "]"))
log.debug("PLC_LNK: allowed for device at " .. r_port) log.debug("PLC_LNK: allowed for device at " .. r_port)
_send_plc_linking(next_seq_id, r_port, { RPLC_LINKING.ALLOW }) _send_plc_linking(next_seq_id, r_port, { RPLC_LINKING.ALLOW })
end end
@ -215,7 +215,7 @@ function supervisor.comms(version, num_reactors, modem, dev_listen, coord_listen
elseif packet.type == SCADA_MGMT_TYPES.RTU_ADVERT then elseif packet.type == SCADA_MGMT_TYPES.RTU_ADVERT then
if packet.length >= 1 then if packet.length >= 1 then
-- this is an RTU advertisement for a new session -- this is an RTU advertisement for a new session
println("connected to RTU (" .. packet.data[1] .. ") [:" .. r_port .. "]") println(util.c("connected to RTU (", packet.data[1], ") [:", r_port, "]"))
svsessions.establish_rtu_session(l_port, r_port, packet.data) svsessions.establish_rtu_session(l_port, r_port, packet.data)
@ -244,7 +244,7 @@ function supervisor.comms(version, num_reactors, modem, dev_listen, coord_listen
log.debug("illegal packet type " .. protocol .. " on coordinator listening channel") log.debug("illegal packet type " .. protocol .. " on coordinator listening channel")
end end
else else
log.error("received packet on unused channel " .. l_port, true) log.warning("received packet on unused channel " .. l_port)
end end
end end
end end