mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#64 rtu code cleanup and device bugfixes
This commit is contained in:
parent
1705d8993e
commit
4ec07ca053
@ -4,11 +4,8 @@ local boiler_rtu = {}
|
||||
|
||||
-- create new boiler (mek 10.0) device
|
||||
---@param boiler table
|
||||
boiler_rtu.new = function (boiler)
|
||||
local self = {
|
||||
rtu = rtu.init_unit(),
|
||||
boiler = boiler
|
||||
}
|
||||
function boiler_rtu.new(boiler)
|
||||
local unit = rtu.init_unit()
|
||||
|
||||
-- discrete inputs --
|
||||
-- none
|
||||
@ -18,34 +15,34 @@ boiler_rtu.new = function (boiler)
|
||||
|
||||
-- input registers --
|
||||
-- build properties
|
||||
self.rtu.connect_input_reg(self.boiler.getBoilCapacity)
|
||||
self.rtu.connect_input_reg(self.boiler.getSteamCapacity)
|
||||
self.rtu.connect_input_reg(self.boiler.getWaterCapacity)
|
||||
self.rtu.connect_input_reg(self.boiler.getHeatedCoolantCapacity)
|
||||
self.rtu.connect_input_reg(self.boiler.getCooledCoolantCapacity)
|
||||
self.rtu.connect_input_reg(self.boiler.getSuperheaters)
|
||||
self.rtu.connect_input_reg(self.boiler.getMaxBoilRate)
|
||||
unit.connect_input_reg(boiler.getBoilCapacity)
|
||||
unit.connect_input_reg(boiler.getSteamCapacity)
|
||||
unit.connect_input_reg(boiler.getWaterCapacity)
|
||||
unit.connect_input_reg(boiler.getHeatedCoolantCapacity)
|
||||
unit.connect_input_reg(boiler.getCooledCoolantCapacity)
|
||||
unit.connect_input_reg(boiler.getSuperheaters)
|
||||
unit.connect_input_reg(boiler.getMaxBoilRate)
|
||||
-- current state
|
||||
self.rtu.connect_input_reg(self.boiler.getTemperature)
|
||||
self.rtu.connect_input_reg(self.boiler.getBoilRate)
|
||||
unit.connect_input_reg(boiler.getTemperature)
|
||||
unit.connect_input_reg(boiler.getBoilRate)
|
||||
-- tanks
|
||||
self.rtu.connect_input_reg(self.boiler.getSteam)
|
||||
self.rtu.connect_input_reg(self.boiler.getSteamNeeded)
|
||||
self.rtu.connect_input_reg(self.boiler.getSteamFilledPercentage)
|
||||
self.rtu.connect_input_reg(self.boiler.getWater)
|
||||
self.rtu.connect_input_reg(self.boiler.getWaterNeeded)
|
||||
self.rtu.connect_input_reg(self.boiler.getWaterFilledPercentage)
|
||||
self.rtu.connect_input_reg(self.boiler.getHeatedCoolant)
|
||||
self.rtu.connect_input_reg(self.boiler.getHeatedCoolantNeeded)
|
||||
self.rtu.connect_input_reg(self.boiler.getHeatedCoolantFilledPercentage)
|
||||
self.rtu.connect_input_reg(self.boiler.getCooledCoolant)
|
||||
self.rtu.connect_input_reg(self.boiler.getCooledCoolantNeeded)
|
||||
self.rtu.connect_input_reg(self.boiler.getCooledCoolantFilledPercentage)
|
||||
unit.connect_input_reg(boiler.getSteam)
|
||||
unit.connect_input_reg(boiler.getSteamNeeded)
|
||||
unit.connect_input_reg(boiler.getSteamFilledPercentage)
|
||||
unit.connect_input_reg(boiler.getWater)
|
||||
unit.connect_input_reg(boiler.getWaterNeeded)
|
||||
unit.connect_input_reg(boiler.getWaterFilledPercentage)
|
||||
unit.connect_input_reg(boiler.getHeatedCoolant)
|
||||
unit.connect_input_reg(boiler.getHeatedCoolantNeeded)
|
||||
unit.connect_input_reg(boiler.getHeatedCoolantFilledPercentage)
|
||||
unit.connect_input_reg(boiler.getCooledCoolant)
|
||||
unit.connect_input_reg(boiler.getCooledCoolantNeeded)
|
||||
unit.connect_input_reg(boiler.getCooledCoolantFilledPercentage)
|
||||
|
||||
-- holding registers --
|
||||
-- none
|
||||
|
||||
return self.rtu.interface()
|
||||
return unit.interface()
|
||||
end
|
||||
|
||||
return boiler_rtu
|
||||
|
@ -4,55 +4,52 @@ local boilerv_rtu = {}
|
||||
|
||||
-- create new boiler (mek 10.1+) device
|
||||
---@param boiler table
|
||||
boilerv_rtu.new = function (boiler)
|
||||
local self = {
|
||||
rtu = rtu.init_unit(),
|
||||
boiler = boiler
|
||||
}
|
||||
function boilerv_rtu.new(boiler)
|
||||
local unit = rtu.init_unit()
|
||||
|
||||
-- discrete inputs --
|
||||
self.rtu.connect_di(self.boiler.isFormed)
|
||||
unit.connect_di(boiler.isFormed)
|
||||
|
||||
-- coils --
|
||||
-- none
|
||||
|
||||
-- input registers --
|
||||
-- multiblock properties
|
||||
self.rtu.connect_input_reg(self.boiler.getLength)
|
||||
self.rtu.connect_input_reg(self.boiler.getWidth)
|
||||
self.rtu.connect_input_reg(self.boiler.getHeight)
|
||||
self.rtu.connect_input_reg(self.boiler.getMinPos)
|
||||
self.rtu.connect_input_reg(self.boiler.getMaxPos)
|
||||
unit.connect_input_reg(boiler.getLength)
|
||||
unit.connect_input_reg(boiler.getWidth)
|
||||
unit.connect_input_reg(boiler.getHeight)
|
||||
unit.connect_input_reg(boiler.getMinPos)
|
||||
unit.connect_input_reg(boiler.getMaxPos)
|
||||
-- build properties
|
||||
self.rtu.connect_input_reg(self.boiler.getBoilCapacity)
|
||||
self.rtu.connect_input_reg(self.boiler.getSteamCapacity)
|
||||
self.rtu.connect_input_reg(self.boiler.getWaterCapacity)
|
||||
self.rtu.connect_input_reg(self.boiler.getHeatedCoolantCapacity)
|
||||
self.rtu.connect_input_reg(self.boiler.getCooledCoolantCapacity)
|
||||
self.rtu.connect_input_reg(self.boiler.getSuperheaters)
|
||||
self.rtu.connect_input_reg(self.boiler.getMaxBoilRate)
|
||||
self.rtu.connect_input_reg(self.boiler.getEnvironmentalLoss)
|
||||
unit.connect_input_reg(boiler.getBoilCapacity)
|
||||
unit.connect_input_reg(boiler.getSteamCapacity)
|
||||
unit.connect_input_reg(boiler.getWaterCapacity)
|
||||
unit.connect_input_reg(boiler.getHeatedCoolantCapacity)
|
||||
unit.connect_input_reg(boiler.getCooledCoolantCapacity)
|
||||
unit.connect_input_reg(boiler.getSuperheaters)
|
||||
unit.connect_input_reg(boiler.getMaxBoilRate)
|
||||
unit.connect_input_reg(boiler.getEnvironmentalLoss)
|
||||
-- current state
|
||||
self.rtu.connect_input_reg(self.boiler.getTemperature)
|
||||
self.rtu.connect_input_reg(self.boiler.getBoilRate)
|
||||
unit.connect_input_reg(boiler.getTemperature)
|
||||
unit.connect_input_reg(boiler.getBoilRate)
|
||||
-- tanks
|
||||
self.rtu.connect_input_reg(self.boiler.getSteam)
|
||||
self.rtu.connect_input_reg(self.boiler.getSteamNeeded)
|
||||
self.rtu.connect_input_reg(self.boiler.getSteamFilledPercentage)
|
||||
self.rtu.connect_input_reg(self.boiler.getWater)
|
||||
self.rtu.connect_input_reg(self.boiler.getWaterNeeded)
|
||||
self.rtu.connect_input_reg(self.boiler.getWaterFilledPercentage)
|
||||
self.rtu.connect_input_reg(self.boiler.getHeatedCoolant)
|
||||
self.rtu.connect_input_reg(self.boiler.getHeatedCoolantNeeded)
|
||||
self.rtu.connect_input_reg(self.boiler.getHeatedCoolantFilledPercentage)
|
||||
self.rtu.connect_input_reg(self.boiler.getCooledCoolant)
|
||||
self.rtu.connect_input_reg(self.boiler.getCooledCoolantNeeded)
|
||||
self.rtu.connect_input_reg(self.boiler.getCooledCoolantFilledPercentage)
|
||||
unit.connect_input_reg(boiler.getSteam)
|
||||
unit.connect_input_reg(boiler.getSteamNeeded)
|
||||
unit.connect_input_reg(boiler.getSteamFilledPercentage)
|
||||
unit.connect_input_reg(boiler.getWater)
|
||||
unit.connect_input_reg(boiler.getWaterNeeded)
|
||||
unit.connect_input_reg(boiler.getWaterFilledPercentage)
|
||||
unit.connect_input_reg(boiler.getHeatedCoolant)
|
||||
unit.connect_input_reg(boiler.getHeatedCoolantNeeded)
|
||||
unit.connect_input_reg(boiler.getHeatedCoolantFilledPercentage)
|
||||
unit.connect_input_reg(boiler.getCooledCoolant)
|
||||
unit.connect_input_reg(boiler.getCooledCoolantNeeded)
|
||||
unit.connect_input_reg(boiler.getCooledCoolantFilledPercentage)
|
||||
|
||||
-- holding registers --
|
||||
-- none
|
||||
|
||||
return self.rtu.interface()
|
||||
return unit.interface()
|
||||
end
|
||||
|
||||
return boilerv_rtu
|
||||
|
@ -4,17 +4,8 @@ local energymachine_rtu = {}
|
||||
|
||||
-- create new energy machine device
|
||||
---@param machine table
|
||||
energymachine_rtu.new = function (machine)
|
||||
local self = {
|
||||
rtu = rtu.init_unit(),
|
||||
machine = machine
|
||||
}
|
||||
|
||||
---@class rtu_device
|
||||
local public = {}
|
||||
|
||||
-- get the RTU interface
|
||||
public.rtu_interface = function () return self.rtu end
|
||||
function energymachine_rtu.new(machine)
|
||||
local unit = rtu.init_unit()
|
||||
|
||||
-- discrete inputs --
|
||||
-- none
|
||||
@ -24,16 +15,16 @@ energymachine_rtu.new = function (machine)
|
||||
|
||||
-- input registers --
|
||||
-- build properties
|
||||
self.rtu.connect_input_reg(self.machine.getTotalMaxEnergy)
|
||||
unit.connect_input_reg(machine.getTotalMaxEnergy)
|
||||
-- containers
|
||||
self.rtu.connect_input_reg(self.machine.getTotalEnergy)
|
||||
self.rtu.connect_input_reg(self.machine.getTotalEnergyNeeded)
|
||||
self.rtu.connect_input_reg(self.machine.getTotalEnergyFilledPercentage)
|
||||
unit.connect_input_reg(machine.getTotalEnergy)
|
||||
unit.connect_input_reg(machine.getTotalEnergyNeeded)
|
||||
unit.connect_input_reg(machine.getTotalEnergyFilledPercentage)
|
||||
|
||||
-- holding registers --
|
||||
-- none
|
||||
|
||||
return public
|
||||
return unit.interface()
|
||||
end
|
||||
|
||||
return energymachine_rtu
|
||||
|
@ -4,42 +4,39 @@ local imatrix_rtu = {}
|
||||
|
||||
-- create new induction matrix (mek 10.1+) device
|
||||
---@param imatrix table
|
||||
imatrix_rtu.new = function (imatrix)
|
||||
local self = {
|
||||
rtu = rtu.init_unit(),
|
||||
imatrix = imatrix
|
||||
}
|
||||
function imatrix_rtu.new(imatrix)
|
||||
local unit = rtu.init_unit()
|
||||
|
||||
-- discrete inputs --
|
||||
self.rtu.connect_di(self.boiler.isFormed)
|
||||
unit.connect_di(imatrix.isFormed)
|
||||
|
||||
-- coils --
|
||||
-- none
|
||||
|
||||
-- input registers --
|
||||
-- multiblock properties
|
||||
self.rtu.connect_input_reg(self.boiler.getLength)
|
||||
self.rtu.connect_input_reg(self.boiler.getWidth)
|
||||
self.rtu.connect_input_reg(self.boiler.getHeight)
|
||||
self.rtu.connect_input_reg(self.boiler.getMinPos)
|
||||
self.rtu.connect_input_reg(self.boiler.getMaxPos)
|
||||
unit.connect_input_reg(imatrix.getLength)
|
||||
unit.connect_input_reg(imatrix.getWidth)
|
||||
unit.connect_input_reg(imatrix.getHeight)
|
||||
unit.connect_input_reg(imatrix.getMinPos)
|
||||
unit.connect_input_reg(imatrix.getMaxPos)
|
||||
-- build properties
|
||||
self.rtu.connect_input_reg(self.imatrix.getMaxEnergy)
|
||||
self.rtu.connect_input_reg(self.imatrix.getTransferCap)
|
||||
self.rtu.connect_input_reg(self.imatrix.getInstalledCells)
|
||||
self.rtu.connect_input_reg(self.imatrix.getInstalledProviders)
|
||||
unit.connect_input_reg(imatrix.getMaxEnergy)
|
||||
unit.connect_input_reg(imatrix.getTransferCap)
|
||||
unit.connect_input_reg(imatrix.getInstalledCells)
|
||||
unit.connect_input_reg(imatrix.getInstalledProviders)
|
||||
-- containers
|
||||
self.rtu.connect_input_reg(self.imatrix.getEnergy)
|
||||
self.rtu.connect_input_reg(self.imatrix.getEnergyNeeded)
|
||||
self.rtu.connect_input_reg(self.imatrix.getEnergyFilledPercentage)
|
||||
unit.connect_input_reg(imatrix.getEnergy)
|
||||
unit.connect_input_reg(imatrix.getEnergyNeeded)
|
||||
unit.connect_input_reg(imatrix.getEnergyFilledPercentage)
|
||||
-- I/O rates
|
||||
self.rtu.connect_input_reg(self.imatrix.getLastInput)
|
||||
self.rtu.connect_input_reg(self.imatrix.getLastOutput)
|
||||
unit.connect_input_reg(imatrix.getLastInput)
|
||||
unit.connect_input_reg(imatrix.getLastOutput)
|
||||
|
||||
-- holding registers --
|
||||
-- none
|
||||
|
||||
return self.rtu.interface()
|
||||
return unit.interface()
|
||||
end
|
||||
|
||||
return imatrix_rtu
|
||||
|
@ -1,4 +1,4 @@
|
||||
local rtu = require("rtu.rtu")
|
||||
local rtu = require("rtu.rtu")
|
||||
local rsio = require("scada-common.rsio")
|
||||
|
||||
local redstone_rtu = {}
|
||||
@ -8,13 +8,11 @@ local digital_write = rsio.digital_write
|
||||
local digital_is_active = rsio.digital_is_active
|
||||
|
||||
-- create new redstone device
|
||||
redstone_rtu.new = function ()
|
||||
local self = {
|
||||
rtu = rtu.init_unit()
|
||||
}
|
||||
function redstone_rtu.new()
|
||||
local unit = rtu.init_unit()
|
||||
|
||||
-- get RTU interface
|
||||
local interface = self.rtu.interface()
|
||||
local interface = unit.interface()
|
||||
|
||||
---@class rtu_rs_device
|
||||
--- extends rtu_device; fields added manually to please Lua diagnostics
|
||||
@ -31,7 +29,7 @@ redstone_rtu.new = function ()
|
||||
-- link digital input
|
||||
---@param side string
|
||||
---@param color integer
|
||||
public.link_di = function (side, color)
|
||||
function public.link_di(side, color)
|
||||
local f_read = nil
|
||||
|
||||
if color then
|
||||
@ -44,14 +42,14 @@ redstone_rtu.new = function ()
|
||||
end
|
||||
end
|
||||
|
||||
self.rtu.connect_di(f_read)
|
||||
unit.connect_di(f_read)
|
||||
end
|
||||
|
||||
-- link digital output
|
||||
---@param channel RS_IO
|
||||
---@param side string
|
||||
---@param color integer
|
||||
public.link_do = function (channel, side, color)
|
||||
function public.link_do(channel, side, color)
|
||||
local f_read = nil
|
||||
local f_write = nil
|
||||
|
||||
@ -81,13 +79,13 @@ redstone_rtu.new = function ()
|
||||
end
|
||||
end
|
||||
|
||||
self.rtu.connect_coil(f_read, f_write)
|
||||
unit.connect_coil(f_read, f_write)
|
||||
end
|
||||
|
||||
-- link analog input
|
||||
---@param side string
|
||||
public.link_ai = function (side)
|
||||
self.rtu.connect_input_reg(
|
||||
function public.link_ai(side)
|
||||
unit.connect_input_reg(
|
||||
function ()
|
||||
return rs.getAnalogInput(side)
|
||||
end
|
||||
@ -96,8 +94,8 @@ redstone_rtu.new = function ()
|
||||
|
||||
-- link analog output
|
||||
---@param side string
|
||||
public.link_ao = function (side)
|
||||
self.rtu.connect_holding_reg(
|
||||
function public.link_ao(side)
|
||||
unit.connect_holding_reg(
|
||||
function ()
|
||||
return rs.getAnalogOutput(side)
|
||||
end,
|
||||
|
@ -4,11 +4,8 @@ local turbine_rtu = {}
|
||||
|
||||
-- create new turbine (mek 10.0) device
|
||||
---@param turbine table
|
||||
turbine_rtu.new = function (turbine)
|
||||
local self = {
|
||||
rtu = rtu.init_unit(),
|
||||
turbine = turbine
|
||||
}
|
||||
function turbine_rtu.new(turbine)
|
||||
local unit = rtu.init_unit()
|
||||
|
||||
-- discrete inputs --
|
||||
-- none
|
||||
@ -18,29 +15,29 @@ turbine_rtu.new = function (turbine)
|
||||
|
||||
-- input registers --
|
||||
-- build properties
|
||||
self.rtu.connect_input_reg(self.turbine.getBlades)
|
||||
self.rtu.connect_input_reg(self.turbine.getCoils)
|
||||
self.rtu.connect_input_reg(self.turbine.getVents)
|
||||
self.rtu.connect_input_reg(self.turbine.getDispersers)
|
||||
self.rtu.connect_input_reg(self.turbine.getCondensers)
|
||||
self.rtu.connect_input_reg(self.turbine.getSteamCapacity)
|
||||
self.rtu.connect_input_reg(self.turbine.getMaxFlowRate)
|
||||
self.rtu.connect_input_reg(self.turbine.getMaxProduction)
|
||||
self.rtu.connect_input_reg(self.turbine.getMaxWaterOutput)
|
||||
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.getMaxFlowRate)
|
||||
unit.connect_input_reg(turbine.getMaxProduction)
|
||||
unit.connect_input_reg(turbine.getMaxWaterOutput)
|
||||
-- current state
|
||||
self.rtu.connect_input_reg(self.turbine.getFlowRate)
|
||||
self.rtu.connect_input_reg(self.turbine.getProductionRate)
|
||||
self.rtu.connect_input_reg(self.turbine.getLastSteamInputRate)
|
||||
self.rtu.connect_input_reg(self.turbine.getDumpingMode)
|
||||
unit.connect_input_reg(turbine.getFlowRate)
|
||||
unit.connect_input_reg(turbine.getProductionRate)
|
||||
unit.connect_input_reg(turbine.getLastSteamInputRate)
|
||||
unit.connect_input_reg(turbine.getDumpingMode)
|
||||
-- tanks
|
||||
self.rtu.connect_input_reg(self.turbine.getSteam)
|
||||
self.rtu.connect_input_reg(self.turbine.getSteamNeeded)
|
||||
self.rtu.connect_input_reg(self.turbine.getSteamFilledPercentage)
|
||||
unit.connect_input_reg(turbine.getSteam)
|
||||
unit.connect_input_reg(turbine.getSteamNeeded)
|
||||
unit.connect_input_reg(turbine.getSteamFilledPercentage)
|
||||
|
||||
-- holding registers --
|
||||
-- none
|
||||
|
||||
return self.rtu.interface()
|
||||
return unit.interface()
|
||||
end
|
||||
|
||||
return turbine_rtu
|
||||
|
@ -4,54 +4,51 @@ local turbinev_rtu = {}
|
||||
|
||||
-- create new turbine (mek 10.1+) device
|
||||
---@param turbine table
|
||||
turbinev_rtu.new = function (turbine)
|
||||
local self = {
|
||||
rtu = rtu.init_unit(),
|
||||
turbine = turbine
|
||||
}
|
||||
function turbinev_rtu.new(turbine)
|
||||
local unit = rtu.init_unit()
|
||||
|
||||
-- discrete inputs --
|
||||
self.rtu.connect_di(self.boiler.isFormed)
|
||||
unit.connect_di(turbine.isFormed)
|
||||
|
||||
-- coils --
|
||||
self.rtu.connect_coil(function () self.turbine.incrementDumpingMode() end, function () end)
|
||||
self.rtu.connect_coil(function () self.turbine.decrementDumpingMode() end, function () end)
|
||||
unit.connect_coil(function () turbine.incrementDumpingMode() end, function () end)
|
||||
unit.connect_coil(function () turbine.decrementDumpingMode() end, function () end)
|
||||
|
||||
-- input registers --
|
||||
-- multiblock properties
|
||||
self.rtu.connect_input_reg(self.boiler.getLength)
|
||||
self.rtu.connect_input_reg(self.boiler.getWidth)
|
||||
self.rtu.connect_input_reg(self.boiler.getHeight)
|
||||
self.rtu.connect_input_reg(self.boiler.getMinPos)
|
||||
self.rtu.connect_input_reg(self.boiler.getMaxPos)
|
||||
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)
|
||||
-- build properties
|
||||
self.rtu.connect_input_reg(self.turbine.getBlades)
|
||||
self.rtu.connect_input_reg(self.turbine.getCoils)
|
||||
self.rtu.connect_input_reg(self.turbine.getVents)
|
||||
self.rtu.connect_input_reg(self.turbine.getDispersers)
|
||||
self.rtu.connect_input_reg(self.turbine.getCondensers)
|
||||
self.rtu.connect_input_reg(self.turbine.getDumpingMode)
|
||||
self.rtu.connect_input_reg(self.turbine.getSteamCapacity)
|
||||
self.rtu.connect_input_reg(self.turbine.getMaxEnergy)
|
||||
self.rtu.connect_input_reg(self.turbine.getMaxFlowRate)
|
||||
self.rtu.connect_input_reg(self.turbine.getMaxWaterOutput)
|
||||
self.rtu.connect_input_reg(self.turbine.getMaxProduction)
|
||||
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.getDumpingMode)
|
||||
unit.connect_input_reg(turbine.getSteamCapacity)
|
||||
unit.connect_input_reg(turbine.getMaxEnergy)
|
||||
unit.connect_input_reg(turbine.getMaxFlowRate)
|
||||
unit.connect_input_reg(turbine.getMaxWaterOutput)
|
||||
unit.connect_input_reg(turbine.getMaxProduction)
|
||||
-- current state
|
||||
self.rtu.connect_input_reg(self.turbine.getFlowRate)
|
||||
self.rtu.connect_input_reg(self.turbine.getProductionRate)
|
||||
self.rtu.connect_input_reg(self.turbine.getLastSteamInputRate)
|
||||
unit.connect_input_reg(turbine.getFlowRate)
|
||||
unit.connect_input_reg(turbine.getProductionRate)
|
||||
unit.connect_input_reg(turbine.getLastSteamInputRate)
|
||||
-- tanks/containers
|
||||
self.rtu.connect_input_reg(self.turbine.getSteam)
|
||||
self.rtu.connect_input_reg(self.turbine.getSteamNeeded)
|
||||
self.rtu.connect_input_reg(self.turbine.getSteamFilledPercentage)
|
||||
self.rtu.connect_input_reg(self.turbine.getEnergy)
|
||||
self.rtu.connect_input_reg(self.turbine.getEnergyNeeded)
|
||||
self.rtu.connect_input_reg(self.turbine.getEnergyFilledPercentage)
|
||||
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)
|
||||
|
||||
-- holding registers --
|
||||
self.rtu.connect_holding_reg(self.turbine.setDumpingMode, self.turbine.getDumpingMode)
|
||||
unit.connect_holding_reg(turbine.setDumpingMode, turbine.getDumpingMode)
|
||||
|
||||
return self.rtu.interface()
|
||||
return unit.interface()
|
||||
end
|
||||
|
||||
return turbinev_rtu
|
||||
|
@ -9,7 +9,7 @@ local MODBUS_EXCODE = types.MODBUS_EXCODE
|
||||
-- new modbus comms handler object
|
||||
---@param rtu_dev rtu_device|rtu_rs_device RTU device
|
||||
---@param use_parallel_read boolean whether or not to use parallel calls when reading
|
||||
modbus.new = function (rtu_dev, use_parallel_read)
|
||||
function modbus.new(rtu_dev, use_parallel_read)
|
||||
local self = {
|
||||
rtu = rtu_dev,
|
||||
use_parallel = use_parallel_read
|
||||
@ -23,7 +23,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
||||
---@param c_addr_start integer
|
||||
---@param count integer
|
||||
---@return boolean ok, table readings
|
||||
local _1_read_coils = function (c_addr_start, count)
|
||||
local function _1_read_coils(c_addr_start, count)
|
||||
local tasks = {}
|
||||
local readings = {}
|
||||
local access_fault = false
|
||||
@ -69,7 +69,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
||||
---@param di_addr_start integer
|
||||
---@param count integer
|
||||
---@return boolean ok, table readings
|
||||
local _2_read_discrete_inputs = function (di_addr_start, count)
|
||||
local function _2_read_discrete_inputs(di_addr_start, count)
|
||||
local tasks = {}
|
||||
local readings = {}
|
||||
local access_fault = false
|
||||
@ -115,7 +115,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
||||
---@param hr_addr_start integer
|
||||
---@param count integer
|
||||
---@return boolean ok, table readings
|
||||
local _3_read_multiple_holding_registers = function (hr_addr_start, count)
|
||||
local function _3_read_multiple_holding_registers(hr_addr_start, count)
|
||||
local tasks = {}
|
||||
local readings = {}
|
||||
local access_fault = false
|
||||
@ -161,7 +161,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
||||
---@param ir_addr_start integer
|
||||
---@param count integer
|
||||
---@return boolean ok, table readings
|
||||
local _4_read_input_registers = function (ir_addr_start, count)
|
||||
local function _4_read_input_registers(ir_addr_start, count)
|
||||
local tasks = {}
|
||||
local readings = {}
|
||||
local access_fault = false
|
||||
@ -207,7 +207,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
||||
---@param c_addr integer
|
||||
---@param value any
|
||||
---@return boolean ok, MODBUS_EXCODE|nil
|
||||
local _5_write_single_coil = function (c_addr, value)
|
||||
local function _5_write_single_coil(c_addr, value)
|
||||
local response = nil
|
||||
local _, coils, _, _ = self.rtu.io_count()
|
||||
local return_ok = c_addr <= coils
|
||||
@ -229,7 +229,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
||||
---@param hr_addr integer
|
||||
---@param value any
|
||||
---@return boolean ok, MODBUS_EXCODE|nil
|
||||
local _6_write_single_holding_register = function (hr_addr, value)
|
||||
local function _6_write_single_holding_register(hr_addr, value)
|
||||
local response = nil
|
||||
local _, _, _, hold_regs = self.rtu.io_count()
|
||||
local return_ok = hr_addr <= hold_regs
|
||||
@ -251,7 +251,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
||||
---@param c_addr_start integer
|
||||
---@param values any
|
||||
---@return boolean ok, MODBUS_EXCODE|nil
|
||||
local _15_write_multiple_coils = function (c_addr_start, values)
|
||||
local function _15_write_multiple_coils(c_addr_start, values)
|
||||
local response = nil
|
||||
local _, coils, _, _ = self.rtu.io_count()
|
||||
local count = #values
|
||||
@ -278,7 +278,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
||||
---@param hr_addr_start integer
|
||||
---@param values any
|
||||
---@return boolean ok, MODBUS_EXCODE|nil
|
||||
local _16_write_multiple_holding_registers = function (hr_addr_start, values)
|
||||
local function _16_write_multiple_holding_registers(hr_addr_start, values)
|
||||
local response = nil
|
||||
local _, _, _, hold_regs = self.rtu.io_count()
|
||||
local count = #values
|
||||
@ -305,7 +305,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
||||
-- validate a request without actually executing it
|
||||
---@param packet modbus_frame
|
||||
---@return boolean return_code, modbus_packet reply
|
||||
public.check_request = function (packet)
|
||||
function public.check_request(packet)
|
||||
local return_code = true
|
||||
local response = { MODBUS_EXCODE.ACKNOWLEDGE }
|
||||
|
||||
@ -347,7 +347,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
||||
-- handle a MODBUS TCP packet and generate a reply
|
||||
---@param packet modbus_frame
|
||||
---@return boolean return_code, modbus_packet reply
|
||||
public.handle_packet = function (packet)
|
||||
function public.handle_packet(packet)
|
||||
local return_code = true
|
||||
local response = nil
|
||||
|
||||
@ -402,7 +402,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
||||
|
||||
-- return a SERVER_DEVICE_BUSY error reply
|
||||
---@return modbus_packet reply
|
||||
public.reply__srv_device_busy = function (packet)
|
||||
function public.reply__srv_device_busy(packet)
|
||||
-- reply back with error flag and exception code
|
||||
local reply = comms.modbus_packet()
|
||||
local fcode = bit.bor(packet.func_code, MODBUS_FCODE.ERROR_FLAG)
|
||||
@ -413,7 +413,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
||||
|
||||
-- return a NEG_ACKNOWLEDGE error reply
|
||||
---@return modbus_packet reply
|
||||
public.reply__neg_ack = function (packet)
|
||||
function public.reply__neg_ack(packet)
|
||||
-- reply back with error flag and exception code
|
||||
local reply = comms.modbus_packet()
|
||||
local fcode = bit.bor(packet.func_code, MODBUS_FCODE.ERROR_FLAG)
|
||||
@ -424,7 +424,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
||||
|
||||
-- return a GATEWAY_PATH_UNAVAILABLE error reply
|
||||
---@return modbus_packet reply
|
||||
public.reply__gw_unavailable = function (packet)
|
||||
function public.reply__gw_unavailable(packet)
|
||||
-- reply back with error flag and exception code
|
||||
local reply = comms.modbus_packet()
|
||||
local fcode = bit.bor(packet.func_code, MODBUS_FCODE.ERROR_FLAG)
|
||||
|
48
rtu/rtu.lua
48
rtu/rtu.lua
@ -20,7 +20,7 @@ local print_ts = util.print_ts
|
||||
local println_ts = util.println_ts
|
||||
|
||||
-- create a new RTU
|
||||
rtu.init_unit = function ()
|
||||
function rtu.init_unit()
|
||||
local self = {
|
||||
discrete_inputs = {},
|
||||
coils = {},
|
||||
@ -38,13 +38,13 @@ rtu.init_unit = function ()
|
||||
local protected = {}
|
||||
|
||||
-- refresh IO count
|
||||
local _count_io = function ()
|
||||
local function _count_io()
|
||||
self.io_count_cache = { #self.discrete_inputs, #self.coils, #self.input_regs, #self.holding_regs }
|
||||
end
|
||||
|
||||
-- return IO count
|
||||
---@return integer discrete_inputs, integer coils, integer input_regs, integer holding_regs
|
||||
public.io_count = function ()
|
||||
function public.io_count()
|
||||
return self.io_count_cache[1], self.io_count_cache[2], self.io_count_cache[3], self.io_count_cache[4]
|
||||
end
|
||||
|
||||
@ -53,7 +53,7 @@ rtu.init_unit = function ()
|
||||
-- connect discrete input
|
||||
---@param f function
|
||||
---@return integer count count of discrete inputs
|
||||
protected.connect_di = function (f)
|
||||
function protected.connect_di(f)
|
||||
insert(self.discrete_inputs, { read = f })
|
||||
_count_io()
|
||||
return #self.discrete_inputs
|
||||
@ -62,7 +62,7 @@ rtu.init_unit = function ()
|
||||
-- read discrete input
|
||||
---@param di_addr integer
|
||||
---@return any value, boolean access_fault
|
||||
public.read_di = function (di_addr)
|
||||
function public.read_di(di_addr)
|
||||
ppm.clear_fault()
|
||||
local value = self.discrete_inputs[di_addr].read()
|
||||
return value, ppm.is_faulted()
|
||||
@ -74,7 +74,7 @@ rtu.init_unit = function ()
|
||||
---@param f_read function
|
||||
---@param f_write function
|
||||
---@return integer count count of coils
|
||||
protected.connect_coil = function (f_read, f_write)
|
||||
function protected.connect_coil(f_read, f_write)
|
||||
insert(self.coils, { read = f_read, write = f_write })
|
||||
_count_io()
|
||||
return #self.coils
|
||||
@ -83,7 +83,7 @@ rtu.init_unit = function ()
|
||||
-- read coil
|
||||
---@param coil_addr integer
|
||||
---@return any value, boolean access_fault
|
||||
public.read_coil = function (coil_addr)
|
||||
function public.read_coil(coil_addr)
|
||||
ppm.clear_fault()
|
||||
local value = self.coils[coil_addr].read()
|
||||
return value, ppm.is_faulted()
|
||||
@ -93,7 +93,7 @@ rtu.init_unit = function ()
|
||||
---@param coil_addr integer
|
||||
---@param value any
|
||||
---@return boolean access_fault
|
||||
public.write_coil = function (coil_addr, value)
|
||||
function public.write_coil(coil_addr, value)
|
||||
ppm.clear_fault()
|
||||
self.coils[coil_addr].write(value)
|
||||
return ppm.is_faulted()
|
||||
@ -104,7 +104,7 @@ rtu.init_unit = function ()
|
||||
-- connect input register
|
||||
---@param f function
|
||||
---@return integer count count of input registers
|
||||
protected.connect_input_reg = function (f)
|
||||
function protected.connect_input_reg(f)
|
||||
insert(self.input_regs, { read = f })
|
||||
_count_io()
|
||||
return #self.input_regs
|
||||
@ -113,7 +113,7 @@ rtu.init_unit = function ()
|
||||
-- read input register
|
||||
---@param reg_addr integer
|
||||
---@return any value, boolean access_fault
|
||||
public.read_input_reg = function (reg_addr)
|
||||
function public.read_input_reg(reg_addr)
|
||||
ppm.clear_fault()
|
||||
local value = self.input_regs[reg_addr].read()
|
||||
return value, ppm.is_faulted()
|
||||
@ -125,7 +125,7 @@ rtu.init_unit = function ()
|
||||
---@param f_read function
|
||||
---@param f_write function
|
||||
---@return integer count count of holding registers
|
||||
protected.connect_holding_reg = function (f_read, f_write)
|
||||
function protected.connect_holding_reg(f_read, f_write)
|
||||
insert(self.holding_regs, { read = f_read, write = f_write })
|
||||
_count_io()
|
||||
return #self.holding_regs
|
||||
@ -134,7 +134,7 @@ rtu.init_unit = function ()
|
||||
-- read holding register
|
||||
---@param reg_addr integer
|
||||
---@return any value, boolean access_fault
|
||||
public.read_holding_reg = function (reg_addr)
|
||||
function public.read_holding_reg(reg_addr)
|
||||
ppm.clear_fault()
|
||||
local value = self.holding_regs[reg_addr].read()
|
||||
return value, ppm.is_faulted()
|
||||
@ -144,7 +144,7 @@ rtu.init_unit = function ()
|
||||
---@param reg_addr integer
|
||||
---@param value any
|
||||
---@return boolean access_fault
|
||||
public.write_holding_reg = function (reg_addr, value)
|
||||
function public.write_holding_reg(reg_addr, value)
|
||||
ppm.clear_fault()
|
||||
self.holding_regs[reg_addr].write(value)
|
||||
return ppm.is_faulted()
|
||||
@ -153,7 +153,7 @@ rtu.init_unit = function ()
|
||||
-- public RTU device access
|
||||
|
||||
-- get the public interface to this RTU
|
||||
protected.interface = function ()
|
||||
function protected.interface()
|
||||
return public
|
||||
end
|
||||
|
||||
@ -166,7 +166,7 @@ end
|
||||
---@param local_port integer
|
||||
---@param server_port integer
|
||||
---@param conn_watchdog watchdog
|
||||
rtu.comms = function (version, modem, local_port, server_port, conn_watchdog)
|
||||
function rtu.comms(version, modem, local_port, server_port, conn_watchdog)
|
||||
local self = {
|
||||
version = version,
|
||||
seq_num = 0,
|
||||
@ -193,7 +193,7 @@ rtu.comms = function (version, modem, local_port, server_port, conn_watchdog)
|
||||
-- send a scada management packet
|
||||
---@param msg_type SCADA_MGMT_TYPES
|
||||
---@param msg table
|
||||
local _send = function (msg_type, msg)
|
||||
local function _send(msg_type, msg)
|
||||
local s_pkt = comms.scada_packet()
|
||||
local m_pkt = comms.mgmt_packet()
|
||||
|
||||
@ -206,7 +206,7 @@ rtu.comms = function (version, modem, local_port, server_port, conn_watchdog)
|
||||
|
||||
-- keep alive ack
|
||||
---@param srv_time integer
|
||||
local _send_keep_alive_ack = function (srv_time)
|
||||
local function _send_keep_alive_ack(srv_time)
|
||||
_send(SCADA_MGMT_TYPES.KEEP_ALIVE, { srv_time, util.time() })
|
||||
end
|
||||
|
||||
@ -214,7 +214,7 @@ rtu.comms = function (version, modem, local_port, server_port, conn_watchdog)
|
||||
|
||||
-- send a MODBUS TCP packet
|
||||
---@param m_pkt modbus_packet
|
||||
public.send_modbus = function (m_pkt)
|
||||
function public.send_modbus(m_pkt)
|
||||
local s_pkt = comms.scada_packet()
|
||||
s_pkt.make(self.seq_num, PROTOCOLS.MODBUS_TCP, m_pkt.raw_sendable())
|
||||
self.modem.transmit(self.s_port, self.l_port, s_pkt.raw_sendable())
|
||||
@ -224,7 +224,7 @@ rtu.comms = function (version, modem, local_port, server_port, conn_watchdog)
|
||||
-- reconnect a newly connected modem
|
||||
---@param modem table
|
||||
---@diagnostic disable-next-line: redefined-local
|
||||
public.reconnect_modem = function (modem)
|
||||
function public.reconnect_modem(modem)
|
||||
self.modem = modem
|
||||
|
||||
-- open modem
|
||||
@ -235,14 +235,14 @@ rtu.comms = function (version, modem, local_port, server_port, conn_watchdog)
|
||||
|
||||
-- unlink from the server
|
||||
---@param rtu_state rtu_state
|
||||
public.unlink = function (rtu_state)
|
||||
function public.unlink(rtu_state)
|
||||
rtu_state.linked = false
|
||||
self.r_seq_num = nil
|
||||
end
|
||||
|
||||
-- close the connection to the server
|
||||
---@param rtu_state rtu_state
|
||||
public.close = function (rtu_state)
|
||||
function public.close(rtu_state)
|
||||
self.conn_watchdog.cancel()
|
||||
public.unlink(rtu_state)
|
||||
_send(SCADA_MGMT_TYPES.CLOSE, {})
|
||||
@ -250,7 +250,7 @@ rtu.comms = function (version, modem, local_port, server_port, conn_watchdog)
|
||||
|
||||
-- send capability advertisement
|
||||
---@param units table
|
||||
public.send_advertisement = function (units)
|
||||
function public.send_advertisement(units)
|
||||
local advertisement = { self.version }
|
||||
|
||||
for i = 1, #units do
|
||||
@ -282,7 +282,7 @@ rtu.comms = function (version, modem, local_port, server_port, conn_watchdog)
|
||||
---@param message any
|
||||
---@param distance integer
|
||||
---@return modbus_frame|mgmt_frame|nil packet
|
||||
public.parse_packet = function(side, sender, reply_to, message, distance)
|
||||
function public.parse_packet(side, sender, reply_to, message, distance)
|
||||
local pkt = nil
|
||||
local s_pkt = comms.scada_packet()
|
||||
|
||||
@ -314,7 +314,7 @@ rtu.comms = function (version, modem, local_port, server_port, conn_watchdog)
|
||||
---@param packet modbus_frame|mgmt_frame
|
||||
---@param units table
|
||||
---@param rtu_state rtu_state
|
||||
public.handle_packet = function(packet, units, rtu_state)
|
||||
function public.handle_packet(packet, units, rtu_state)
|
||||
if packet ~= nil then
|
||||
-- check sequence number
|
||||
if self.r_seq_num == nil then
|
||||
|
@ -4,27 +4,27 @@
|
||||
|
||||
require("/initenv").init_env()
|
||||
|
||||
local log = require("scada-common.log")
|
||||
local log = require("scada-common.log")
|
||||
local mqueue = require("scada-common.mqueue")
|
||||
local ppm = require("scada-common.ppm")
|
||||
local rsio = require("scada-common.rsio")
|
||||
local types = require("scada-common.types")
|
||||
local util = require("scada-common.util")
|
||||
local ppm = require("scada-common.ppm")
|
||||
local rsio = require("scada-common.rsio")
|
||||
local types = require("scada-common.types")
|
||||
local util = require("scada-common.util")
|
||||
|
||||
local config = require("rtu.config")
|
||||
local modbus = require("rtu.modbus")
|
||||
local rtu = require("rtu.rtu")
|
||||
local config = require("rtu.config")
|
||||
local modbus = require("rtu.modbus")
|
||||
local rtu = require("rtu.rtu")
|
||||
local threads = require("rtu.threads")
|
||||
|
||||
local redstone_rtu = require("rtu.dev.redstone_rtu")
|
||||
local boiler_rtu = require("rtu.dev.boiler_rtu")
|
||||
local boilerv_rtu = require("rtu.dev.boilerv_rtu")
|
||||
local redstone_rtu = require("rtu.dev.redstone_rtu")
|
||||
local boiler_rtu = require("rtu.dev.boiler_rtu")
|
||||
local boilerv_rtu = require("rtu.dev.boilerv_rtu")
|
||||
local energymachine_rtu = require("rtu.dev.energymachine_rtu")
|
||||
local imatrix_rtu = require("rtu.dev.imatrix_rtu")
|
||||
local turbine_rtu = require("rtu.dev.turbine_rtu")
|
||||
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
|
||||
local imatrix_rtu = require("rtu.dev.imatrix_rtu")
|
||||
local turbine_rtu = require("rtu.dev.turbine_rtu")
|
||||
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
|
||||
|
||||
local RTU_VERSION = "beta-v0.7.2"
|
||||
local RTU_VERSION = "beta-v0.7.3"
|
||||
|
||||
local rtu_t = types.rtu_t
|
||||
|
||||
|
@ -27,11 +27,11 @@ local COMMS_SLEEP = 100 -- (100ms, 2 ticks)
|
||||
|
||||
-- main thread
|
||||
---@param smem rtu_shared_memory
|
||||
threads.thread__main = function (smem)
|
||||
function threads.thread__main(smem)
|
||||
local public = {} ---@class thread
|
||||
|
||||
-- execute thread
|
||||
public.exec = function ()
|
||||
function public.exec()
|
||||
log.debug("main thread start")
|
||||
|
||||
-- main loop clock
|
||||
@ -155,7 +155,7 @@ threads.thread__main = function (smem)
|
||||
end
|
||||
|
||||
-- execute the thread in a protected mode, retrying it on return if not shutting down
|
||||
public.p_exec = function ()
|
||||
function public.p_exec()
|
||||
local rtu_state = smem.rtu_state
|
||||
|
||||
while not rtu_state.shutdown do
|
||||
@ -176,11 +176,11 @@ end
|
||||
|
||||
-- communications handler thread
|
||||
---@param smem rtu_shared_memory
|
||||
threads.thread__comms = function (smem)
|
||||
function threads.thread__comms(smem)
|
||||
local public = {} ---@class thread
|
||||
|
||||
-- execute thread
|
||||
public.exec = function ()
|
||||
function public.exec()
|
||||
log.debug("comms thread start")
|
||||
|
||||
-- load in from shared memory
|
||||
@ -227,7 +227,7 @@ threads.thread__comms = function (smem)
|
||||
end
|
||||
|
||||
-- execute the thread in a protected mode, retrying it on return if not shutting down
|
||||
public.p_exec = function ()
|
||||
function public.p_exec()
|
||||
local rtu_state = smem.rtu_state
|
||||
|
||||
while not rtu_state.shutdown do
|
||||
@ -249,11 +249,11 @@ end
|
||||
-- per-unit communications handler thread
|
||||
---@param smem rtu_shared_memory
|
||||
---@param unit rtu_unit_registry_entry
|
||||
threads.thread__unit_comms = function (smem, unit)
|
||||
function threads.thread__unit_comms(smem, unit)
|
||||
local public = {} ---@class thread
|
||||
|
||||
-- execute thread
|
||||
public.exec = function ()
|
||||
function public.exec()
|
||||
log.debug("rtu unit thread start -> " .. unit.name .. "(" .. unit.type .. ")")
|
||||
|
||||
-- load in from shared memory
|
||||
@ -297,7 +297,7 @@ threads.thread__unit_comms = function (smem, unit)
|
||||
end
|
||||
|
||||
-- execute the thread in a protected mode, retrying it on return if not shutting down
|
||||
public.p_exec = function ()
|
||||
function public.p_exec()
|
||||
local rtu_state = smem.rtu_state
|
||||
|
||||
while not rtu_state.shutdown do
|
||||
|
Loading…
Reference in New Issue
Block a user