2023-06-03 18:33:08 +00:00
--
-- RTU Connection Entry
--
local databus = require ( " supervisor.databus " )
2023-09-02 02:24:31 +00:00
local style = require ( " supervisor.panel.style " )
2023-06-03 18:33:08 +00:00
local core = require ( " graphics.core " )
local Div = require ( " graphics.elements.div " )
local TextBox = require ( " graphics.elements.textbox " )
local DataIndicator = require ( " graphics.elements.indicators.data " )
2023-10-04 03:16:46 +00:00
local ALIGN = core.ALIGN
2023-06-03 18:33:08 +00:00
local cpair = core.cpair
2023-09-02 02:24:31 +00:00
local black_lg = style.black_lg
local lg_white = style.lg_white
2023-06-03 18:33:08 +00:00
-- create an RTU list entry
---@param parent graphics_element parent
---@param id integer RTU session ID
local function init ( parent , id )
-- root div
local root = Div { parent = parent , x = 2 , y = 2 , height = 4 , width = parent.get_width ( ) - 2 , hidden = true }
2023-09-02 02:24:31 +00:00
local entry = Div { parent = root , x = 2 , y = 1 , height = 3 , fg_bg = style.bw_fg_bg }
2023-06-03 18:33:08 +00:00
local ps_prefix = " rtu_ " .. id .. " _ "
2023-09-02 02:24:31 +00:00
TextBox { parent = entry , x = 1 , y = 1 , text = " " , width = 8 , height = 1 , fg_bg = black_lg }
2023-10-04 03:16:46 +00:00
local rtu_addr = TextBox { parent = entry , x = 1 , y = 2 , text = " @ C ?? " , alignment = ALIGN.CENTER , width = 8 , height = 1 , fg_bg = black_lg , nav_active = cpair ( colors.gray , colors.black ) }
2023-09-02 02:24:31 +00:00
TextBox { parent = entry , x = 1 , y = 3 , text = " " , width = 8 , height = 1 , fg_bg = black_lg }
2023-06-07 01:56:17 +00:00
rtu_addr.register ( databus.ps , ps_prefix .. " addr " , rtu_addr.set_value )
2023-06-03 18:33:08 +00:00
TextBox { parent = entry , x = 10 , y = 2 , text = " UNITS: " , width = 7 , height = 1 }
2023-09-02 02:24:31 +00:00
local unit_count = DataIndicator { parent = entry , x = 17 , y = 2 , label = " " , unit = " " , format = " %2d " , value = 0 , width = 2 , fg_bg = style.gray_white }
2023-06-03 18:33:08 +00:00
unit_count.register ( databus.ps , ps_prefix .. " units " , unit_count.set_value )
TextBox { parent = entry , x = 21 , y = 2 , text = " FW: " , width = 3 , height = 1 }
2023-09-02 02:24:31 +00:00
local rtu_fw_v = TextBox { parent = entry , x = 25 , y = 2 , text = " ------- " , width = 9 , height = 1 , fg_bg = lg_white }
2023-06-03 18:33:08 +00:00
rtu_fw_v.register ( databus.ps , ps_prefix .. " fw " , rtu_fw_v.set_value )
TextBox { parent = entry , x = 36 , y = 2 , text = " RTT: " , width = 4 , height = 1 }
2023-09-02 02:24:31 +00:00
local rtu_rtt = DataIndicator { parent = entry , x = 40 , y = 2 , label = " " , unit = " " , format = " %5d " , value = 0 , width = 5 , fg_bg = lg_white }
TextBox { parent = entry , x = 46 , y = 2 , text = " ms " , width = 4 , height = 1 , fg_bg = lg_white }
2023-06-03 18:33:08 +00:00
rtu_rtt.register ( databus.ps , ps_prefix .. " rtt " , rtu_rtt.update )
rtu_rtt.register ( databus.ps , ps_prefix .. " rtt_color " , rtu_rtt.recolor )
return root
end
return init