Merge branch 'devel' into 232-waste-valve-and-flow-monitoring-display
This commit is contained in:
@@ -154,7 +154,8 @@ function coordinator.new_session(id, s_addr, in_queue, out_queue, timeout, facil
|
||||
local function _send_fac_status()
|
||||
local status = {
|
||||
facility.get_control_status(),
|
||||
facility.get_rtu_statuses()
|
||||
facility.get_rtu_statuses(),
|
||||
facility.get_alarm_tones()
|
||||
}
|
||||
|
||||
_send(SCADA_CRDN_TYPE.FAC_STATUS, status)
|
||||
|
||||
@@ -33,8 +33,9 @@ local PERIODICS = {
|
||||
---@param in_queue mqueue in message queue
|
||||
---@param out_queue mqueue out message queue
|
||||
---@param timeout number communications timeout
|
||||
---@param facility facility facility data table
|
||||
---@param fp_ok boolean if the front panel UI is running
|
||||
function pocket.new_session(id, s_addr, in_queue, out_queue, timeout, fp_ok)
|
||||
function pocket.new_session(id, s_addr, in_queue, out_queue, timeout, facility, fp_ok)
|
||||
-- print a log message to the terminal as long as the UI isn't running
|
||||
local function println(message) if not fp_ok then util.println_ts(message) end end
|
||||
|
||||
@@ -129,6 +130,55 @@ function pocket.new_session(id, s_addr, in_queue, out_queue, timeout, fp_ok)
|
||||
elseif pkt.type == SCADA_MGMT_TYPE.CLOSE then
|
||||
-- close the session
|
||||
_close()
|
||||
elseif pkt.type == SCADA_MGMT_TYPE.DIAG_TONE_GET then
|
||||
-- get the state of alarm tones
|
||||
_send_mgmt(SCADA_MGMT_TYPE.DIAG_TONE_GET, facility.get_alarm_tones())
|
||||
elseif pkt.type == SCADA_MGMT_TYPE.DIAG_TONE_SET then
|
||||
local valid = false
|
||||
|
||||
-- attempt to set a tone state
|
||||
if pkt.scada_frame.is_authenticated() then
|
||||
if pkt.length == 2 then
|
||||
if type(pkt.data[1]) == "number" and type(pkt.data[2]) == "boolean" then
|
||||
valid = true
|
||||
|
||||
-- try to set tone states, then send back if testing is allowed
|
||||
local allow_testing, test_tone_states = facility.diag_set_test_tone(pkt.data[1], pkt.data[2])
|
||||
_send_mgmt(SCADA_MGMT_TYPE.DIAG_TONE_SET, { allow_testing, test_tone_states })
|
||||
else
|
||||
log.debug(log_header .. "SCADA diag tone set packet data type mismatch")
|
||||
end
|
||||
else
|
||||
log.debug(log_header .. "SCADA diag tone set packet length mismatch")
|
||||
end
|
||||
else
|
||||
log.debug(log_header .. "DIAG_TONE_SET is blocked without HMAC for security")
|
||||
end
|
||||
|
||||
if not valid then _send_mgmt(SCADA_MGMT_TYPE.DIAG_TONE_SET, { false }) end
|
||||
elseif pkt.type == SCADA_MGMT_TYPE.DIAG_ALARM_SET then
|
||||
local valid = false
|
||||
|
||||
-- attempt to set an alarm state
|
||||
if pkt.scada_frame.is_authenticated() then
|
||||
if pkt.length == 2 then
|
||||
if type(pkt.data[1]) == "number" and type(pkt.data[2]) == "boolean" then
|
||||
valid = true
|
||||
|
||||
-- try to set alarm states, then send back if testing is allowed
|
||||
local allow_testing, test_alarm_states = facility.diag_set_test_alarm(pkt.data[1], pkt.data[2])
|
||||
_send_mgmt(SCADA_MGMT_TYPE.DIAG_ALARM_SET, { allow_testing, test_alarm_states })
|
||||
else
|
||||
log.debug(log_header .. "SCADA diag alarm set packet data type mismatch")
|
||||
end
|
||||
else
|
||||
log.debug(log_header .. "SCADA diag alarm set packet length mismatch")
|
||||
end
|
||||
else
|
||||
log.debug(log_header .. "DIAG_ALARM_SET is blocked without HMAC for security")
|
||||
end
|
||||
|
||||
if not valid then _send_mgmt(SCADA_MGMT_TYPE.DIAG_ALARM_SET, { false }) end
|
||||
else
|
||||
log.debug(log_header .. "handler received unsupported SCADA_MGMT packet type " .. pkt.type)
|
||||
end
|
||||
|
||||
@@ -26,7 +26,8 @@ local SCADA_MGMT_TYPE = comms.SCADA_MGMT_TYPE
|
||||
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
|
||||
|
||||
local PERIODICS = {
|
||||
KEEP_ALIVE = 2000
|
||||
KEEP_ALIVE = 2000,
|
||||
ALARM_TONES = 500
|
||||
}
|
||||
|
||||
-- create a new RTU session
|
||||
@@ -58,7 +59,8 @@ function rtu.new_session(id, s_addr, in_queue, out_queue, timeout, advertisement
|
||||
-- periodic messages
|
||||
periodics = {
|
||||
last_update = 0,
|
||||
keep_alive = 0
|
||||
keep_alive = 0,
|
||||
alarm_tones = 0
|
||||
},
|
||||
units = {}
|
||||
}
|
||||
@@ -389,6 +391,14 @@ function rtu.new_session(id, s_addr, in_queue, out_queue, timeout, advertisement
|
||||
periodics.keep_alive = 0
|
||||
end
|
||||
|
||||
-- alarm tones
|
||||
|
||||
periodics.alarm_tones = periodics.alarm_tones + elapsed
|
||||
if periodics.alarm_tones >= PERIODICS.ALARM_TONES then
|
||||
_send_mgmt(SCADA_MGMT_TYPE.RTU_TONE_ALARM, { facility.get_alarm_tones() })
|
||||
periodics.alarm_tones = 0
|
||||
end
|
||||
|
||||
self.periodics.last_update = util.time()
|
||||
|
||||
--------------------------------------------
|
||||
|
||||
@@ -104,8 +104,8 @@ local function _sv_handle_outq(session)
|
||||
|
||||
-- max 100ms spent processing queue
|
||||
if util.time() - handle_start > 100 then
|
||||
log.warning("[SVS] supervisor out queue handler exceeded 100ms queue process limit")
|
||||
log.warning(util.c("[SVS] offending session: ", session))
|
||||
log.debug("[SVS] supervisor out queue handler exceeded 100ms queue process limit")
|
||||
log.debug(util.c("[SVS] offending session: ", session))
|
||||
break
|
||||
end
|
||||
end
|
||||
@@ -430,7 +430,8 @@ function svsessions.establish_pdg_session(source_addr, version)
|
||||
|
||||
local id = self.next_ids.pdg
|
||||
|
||||
pdg_s.instance = pocket.new_session(id, source_addr, pdg_s.in_queue, pdg_s.out_queue, config.PKT_TIMEOUT, self.fp_ok)
|
||||
pdg_s.instance = pocket.new_session(id, source_addr, pdg_s.in_queue, pdg_s.out_queue, config.PKT_TIMEOUT, self.facility,
|
||||
self.fp_ok)
|
||||
table.insert(self.sessions.pdg, pdg_s)
|
||||
|
||||
local mt = {
|
||||
|
||||
Reference in New Issue
Block a user