2022-05-12 19:36:27 +00:00
|
|
|
local rtu = require("rtu.rtu")
|
2022-05-04 15:23:45 +00:00
|
|
|
|
2022-05-04 17:37:01 +00:00
|
|
|
local turbinev_rtu = {}
|
|
|
|
|
2023-07-11 21:27:03 +00:00
|
|
|
-- create new turbine device
|
2023-02-22 04:50:43 +00:00
|
|
|
---@nodiscard
|
2022-05-12 19:36:27 +00:00
|
|
|
---@param turbine table
|
2023-04-06 16:52:25 +00:00
|
|
|
---@return rtu_device interface, boolean faulted
|
2022-05-31 18:54:55 +00:00
|
|
|
function turbinev_rtu.new(turbine)
|
|
|
|
local unit = rtu.init_unit()
|
2022-05-04 15:23:45 +00:00
|
|
|
|
2023-04-06 16:52:25 +00:00
|
|
|
-- disable auto fault clearing
|
2023-06-22 19:46:17 +00:00
|
|
|
turbine.__p_clear_fault()
|
2023-04-06 16:52:25 +00:00
|
|
|
turbine.__p_disable_afc()
|
|
|
|
|
2022-05-04 15:23:45 +00:00
|
|
|
-- discrete inputs --
|
2022-05-31 18:54:55 +00:00
|
|
|
unit.connect_di(turbine.isFormed)
|
2022-05-04 15:23:45 +00:00
|
|
|
|
|
|
|
-- coils --
|
2022-05-31 18:54:55 +00:00
|
|
|
unit.connect_coil(function () turbine.incrementDumpingMode() end, function () end)
|
|
|
|
unit.connect_coil(function () turbine.decrementDumpingMode() end, function () end)
|
2022-05-04 15:23:45 +00:00
|
|
|
|
|
|
|
-- input registers --
|
|
|
|
-- multiblock properties
|
2022-05-31 18:54:55 +00:00
|
|
|
unit.connect_input_reg(turbine.getLength)
|
|
|
|
unit.connect_input_reg(turbine.getWidth)
|
|
|
|
unit.connect_input_reg(turbine.getHeight)
|
|
|
|
unit.connect_input_reg(turbine.getMinPos)
|
|
|
|
unit.connect_input_reg(turbine.getMaxPos)
|
2022-05-04 15:23:45 +00:00
|
|
|
-- build properties
|
2022-05-31 18:54:55 +00:00
|
|
|
unit.connect_input_reg(turbine.getBlades)
|
|
|
|
unit.connect_input_reg(turbine.getCoils)
|
|
|
|
unit.connect_input_reg(turbine.getVents)
|
|
|
|
unit.connect_input_reg(turbine.getDispersers)
|
|
|
|
unit.connect_input_reg(turbine.getCondensers)
|
|
|
|
unit.connect_input_reg(turbine.getSteamCapacity)
|
|
|
|
unit.connect_input_reg(turbine.getMaxEnergy)
|
|
|
|
unit.connect_input_reg(turbine.getMaxFlowRate)
|
|
|
|
unit.connect_input_reg(turbine.getMaxProduction)
|
2022-06-05 13:30:56 +00:00
|
|
|
unit.connect_input_reg(turbine.getMaxWaterOutput)
|
2022-05-04 15:23:45 +00:00
|
|
|
-- current state
|
2022-05-31 18:54:55 +00:00
|
|
|
unit.connect_input_reg(turbine.getFlowRate)
|
|
|
|
unit.connect_input_reg(turbine.getProductionRate)
|
|
|
|
unit.connect_input_reg(turbine.getLastSteamInputRate)
|
2022-06-05 13:30:56 +00:00
|
|
|
unit.connect_input_reg(turbine.getDumpingMode)
|
2022-05-04 15:23:45 +00:00
|
|
|
-- tanks/containers
|
2022-05-31 18:54:55 +00:00
|
|
|
unit.connect_input_reg(turbine.getSteam)
|
|
|
|
unit.connect_input_reg(turbine.getSteamNeeded)
|
|
|
|
unit.connect_input_reg(turbine.getSteamFilledPercentage)
|
|
|
|
unit.connect_input_reg(turbine.getEnergy)
|
|
|
|
unit.connect_input_reg(turbine.getEnergyNeeded)
|
|
|
|
unit.connect_input_reg(turbine.getEnergyFilledPercentage)
|
2022-05-04 15:23:45 +00:00
|
|
|
|
|
|
|
-- holding registers --
|
2023-02-25 19:11:40 +00:00
|
|
|
unit.connect_holding_reg(turbine.getDumpingMode, turbine.setDumpingMode)
|
2022-05-04 15:23:45 +00:00
|
|
|
|
2023-04-06 16:52:25 +00:00
|
|
|
-- check if any calls faulted
|
|
|
|
local faulted = turbine.__p_is_faulted()
|
|
|
|
turbine.__p_clear_fault()
|
|
|
|
turbine.__p_enable_afc()
|
|
|
|
|
|
|
|
return unit.interface(), faulted
|
2022-05-04 15:23:45 +00:00
|
|
|
end
|
2022-05-04 17:37:01 +00:00
|
|
|
|
|
|
|
return turbinev_rtu
|