mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
global scope optimizations
This commit is contained in:
@ -13,6 +13,8 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
|||||||
use_parallel = use_parallel_read
|
use_parallel = use_parallel_read
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local insert = table.insert
|
||||||
|
|
||||||
local _1_read_coils = function (c_addr_start, count)
|
local _1_read_coils = function (c_addr_start, count)
|
||||||
local tasks = {}
|
local tasks = {}
|
||||||
local readings = {}
|
local readings = {}
|
||||||
@ -25,7 +27,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
|||||||
local addr = c_addr_start + i - 1
|
local addr = c_addr_start + i - 1
|
||||||
|
|
||||||
if self.use_parallel then
|
if self.use_parallel then
|
||||||
table.insert(tasks, function ()
|
insert(tasks, function ()
|
||||||
local reading, fault = self.rtu.read_coil(addr)
|
local reading, fault = self.rtu.read_coil(addr)
|
||||||
if fault then access_fault = true else readings[i] = reading end
|
if fault then access_fault = true else readings[i] = reading end
|
||||||
end)
|
end)
|
||||||
@ -68,7 +70,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
|||||||
local addr = di_addr_start + i - 1
|
local addr = di_addr_start + i - 1
|
||||||
|
|
||||||
if self.use_parallel then
|
if self.use_parallel then
|
||||||
table.insert(tasks, function ()
|
insert(tasks, function ()
|
||||||
local reading, fault = self.rtu.read_di(addr)
|
local reading, fault = self.rtu.read_di(addr)
|
||||||
if fault then access_fault = true else readings[i] = reading end
|
if fault then access_fault = true else readings[i] = reading end
|
||||||
end)
|
end)
|
||||||
@ -111,7 +113,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
|||||||
local addr = hr_addr_start + i - 1
|
local addr = hr_addr_start + i - 1
|
||||||
|
|
||||||
if self.use_parallel then
|
if self.use_parallel then
|
||||||
table.insert(tasks, function ()
|
insert(tasks, function ()
|
||||||
local reading, fault = self.rtu.read_holding_reg(addr)
|
local reading, fault = self.rtu.read_holding_reg(addr)
|
||||||
if fault then access_fault = true else readings[i] = reading end
|
if fault then access_fault = true else readings[i] = reading end
|
||||||
end)
|
end)
|
||||||
@ -154,7 +156,7 @@ modbus.new = function (rtu_dev, use_parallel_read)
|
|||||||
local addr = ir_addr_start + i - 1
|
local addr = ir_addr_start + i - 1
|
||||||
|
|
||||||
if self.use_parallel then
|
if self.use_parallel then
|
||||||
table.insert(tasks, function ()
|
insert(tasks, function ()
|
||||||
local reading, fault = self.rtu.read_input_reg(addr)
|
local reading, fault = self.rtu.read_input_reg(addr)
|
||||||
if fault then access_fault = true else readings[i] = reading end
|
if fault then access_fault = true else readings[i] = reading end
|
||||||
end)
|
end)
|
||||||
|
14
rtu/rtu.lua
14
rtu/rtu.lua
@ -18,6 +18,8 @@ rtu.init_unit = function ()
|
|||||||
io_count_cache = { 0, 0, 0, 0 }
|
io_count_cache = { 0, 0, 0, 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local insert = table.insert
|
||||||
|
|
||||||
local _count_io = function ()
|
local _count_io = function ()
|
||||||
self.io_count_cache = { #self.discrete_inputs, #self.coils, #self.input_regs, #self.holding_regs }
|
self.io_count_cache = { #self.discrete_inputs, #self.coils, #self.input_regs, #self.holding_regs }
|
||||||
end
|
end
|
||||||
@ -31,7 +33,7 @@ rtu.init_unit = function ()
|
|||||||
|
|
||||||
-- return : count of discrete inputs
|
-- return : count of discrete inputs
|
||||||
local connect_di = function (f)
|
local connect_di = function (f)
|
||||||
table.insert(self.discrete_inputs, f)
|
insert(self.discrete_inputs, f)
|
||||||
_count_io()
|
_count_io()
|
||||||
return #self.discrete_inputs
|
return #self.discrete_inputs
|
||||||
end
|
end
|
||||||
@ -47,7 +49,7 @@ rtu.init_unit = function ()
|
|||||||
|
|
||||||
-- return : count of coils
|
-- return : count of coils
|
||||||
local connect_coil = function (f_read, f_write)
|
local connect_coil = function (f_read, f_write)
|
||||||
table.insert(self.coils, { read = f_read, write = f_write })
|
insert(self.coils, { read = f_read, write = f_write })
|
||||||
_count_io()
|
_count_io()
|
||||||
return #self.coils
|
return #self.coils
|
||||||
end
|
end
|
||||||
@ -70,7 +72,7 @@ rtu.init_unit = function ()
|
|||||||
|
|
||||||
-- return : count of input registers
|
-- return : count of input registers
|
||||||
local connect_input_reg = function (f)
|
local connect_input_reg = function (f)
|
||||||
table.insert(self.input_regs, f)
|
insert(self.input_regs, f)
|
||||||
_count_io()
|
_count_io()
|
||||||
return #self.input_regs
|
return #self.input_regs
|
||||||
end
|
end
|
||||||
@ -86,7 +88,7 @@ rtu.init_unit = function ()
|
|||||||
|
|
||||||
-- return : count of holding registers
|
-- return : count of holding registers
|
||||||
local connect_holding_reg = function (f_read, f_write)
|
local connect_holding_reg = function (f_read, f_write)
|
||||||
table.insert(self.holding_regs, { read = f_read, write = f_write })
|
insert(self.holding_regs, { read = f_read, write = f_write })
|
||||||
_count_io()
|
_count_io()
|
||||||
return #self.holding_regs
|
return #self.holding_regs
|
||||||
end
|
end
|
||||||
@ -293,7 +295,7 @@ rtu.comms = function (modem, local_port, server_port)
|
|||||||
|
|
||||||
if type ~= nil then
|
if type ~= nil then
|
||||||
if type == RTU_ADVERT_TYPES.REDSTONE then
|
if type == RTU_ADVERT_TYPES.REDSTONE then
|
||||||
table.insert(advertisement, {
|
insert(advertisement, {
|
||||||
unit = i,
|
unit = i,
|
||||||
type = type,
|
type = type,
|
||||||
index = units[i].index,
|
index = units[i].index,
|
||||||
@ -301,7 +303,7 @@ rtu.comms = function (modem, local_port, server_port)
|
|||||||
rsio = units[i].device
|
rsio = units[i].device
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
table.insert(advertisement, {
|
insert(advertisement, {
|
||||||
unit = i,
|
unit = i,
|
||||||
type = type,
|
type = type,
|
||||||
index = units[i].index,
|
index = units[i].index,
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
local comms = {}
|
local comms = {}
|
||||||
|
|
||||||
|
local insert = table.insert
|
||||||
|
|
||||||
local PROTOCOLS = {
|
local PROTOCOLS = {
|
||||||
MODBUS_TCP = 0, -- our "MODBUS TCP"-esque protocol
|
MODBUS_TCP = 0, -- our "MODBUS TCP"-esque protocol
|
||||||
RPLC = 1, -- reactor PLC protocol
|
RPLC = 1, -- reactor PLC protocol
|
||||||
@ -158,7 +160,7 @@ comms.modbus_packet = function ()
|
|||||||
-- populate raw array
|
-- populate raw array
|
||||||
self.raw = { self.txn_id, self.unit_id, self.func_code }
|
self.raw = { self.txn_id, self.unit_id, self.func_code }
|
||||||
for i = 1, self.length do
|
for i = 1, self.length do
|
||||||
table.insert(self.raw, data[i])
|
insert(self.raw, data[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -248,7 +250,7 @@ comms.rplc_packet = function ()
|
|||||||
-- populate raw array
|
-- populate raw array
|
||||||
self.raw = { self.id, self.type }
|
self.raw = { self.id, self.type }
|
||||||
for i = 1, #data do
|
for i = 1, #data do
|
||||||
table.insert(self.raw, data[i])
|
insert(self.raw, data[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -331,7 +333,7 @@ comms.mgmt_packet = function ()
|
|||||||
-- populate raw array
|
-- populate raw array
|
||||||
self.raw = { self.type }
|
self.raw = { self.type }
|
||||||
for i = 1, #data do
|
for i = 1, #data do
|
||||||
table.insert(self.raw, data[i])
|
insert(self.raw, data[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -410,7 +412,7 @@ comms.coord_packet = function ()
|
|||||||
-- populate raw array
|
-- populate raw array
|
||||||
self.raw = { self.type }
|
self.raw = { self.type }
|
||||||
for i = 1, #data do
|
for i = 1, #data do
|
||||||
table.insert(self.raw, data[i])
|
insert(self.raw, data[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -489,7 +491,7 @@ comms.capi_packet = function ()
|
|||||||
-- populate raw array
|
-- populate raw array
|
||||||
self.raw = { self.type }
|
self.raw = { self.type }
|
||||||
for i = 1, #data do
|
for i = 1, #data do
|
||||||
table.insert(self.raw, data[i])
|
insert(self.raw, data[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user