mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
fixed acknowledge packets to use error flag, fixed 'static'-like function scope of modbus functions
This commit is contained in:
parent
3267e7ff13
commit
88c34d8bca
@ -332,10 +332,9 @@ function modbus.new(rtu_dev, use_parallel_read)
|
||||
|
||||
-- default is to echo back
|
||||
local func_code = packet.func_code
|
||||
if not return_code then
|
||||
-- echo back with error flag
|
||||
|
||||
-- echo back with error flag, on success the "error" will be acknowledgement
|
||||
func_code = bit.bor(packet.func_code, MODBUS_FCODE.ERROR_FLAG)
|
||||
end
|
||||
|
||||
-- create reply
|
||||
local reply = comms.modbus_packet()
|
||||
@ -400,40 +399,40 @@ function modbus.new(rtu_dev, use_parallel_read)
|
||||
return return_code, reply
|
||||
end
|
||||
|
||||
-- return a SERVER_DEVICE_BUSY error reply
|
||||
---@return modbus_packet reply
|
||||
function public.reply__srv_device_busy(packet)
|
||||
return public
|
||||
end
|
||||
|
||||
-- return a SERVER_DEVICE_BUSY error reply
|
||||
---@return modbus_packet reply
|
||||
function modbus.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)
|
||||
local data = { MODBUS_EXCODE.SERVER_DEVICE_BUSY }
|
||||
reply.make(packet.txn_id, packet.unit_id, fcode, data)
|
||||
return reply
|
||||
end
|
||||
end
|
||||
|
||||
-- return a NEG_ACKNOWLEDGE error reply
|
||||
---@return modbus_packet reply
|
||||
function public.reply__neg_ack(packet)
|
||||
-- return a NEG_ACKNOWLEDGE error reply
|
||||
---@return modbus_packet reply
|
||||
function modbus.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)
|
||||
local data = { MODBUS_EXCODE.NEG_ACKNOWLEDGE }
|
||||
reply.make(packet.txn_id, packet.unit_id, fcode, data)
|
||||
return reply
|
||||
end
|
||||
end
|
||||
|
||||
-- return a GATEWAY_PATH_UNAVAILABLE error reply
|
||||
---@return modbus_packet reply
|
||||
function public.reply__gw_unavailable(packet)
|
||||
-- return a GATEWAY_PATH_UNAVAILABLE error reply
|
||||
---@return modbus_packet reply
|
||||
function modbus.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)
|
||||
local data = { MODBUS_EXCODE.GATEWAY_PATH_UNAVAILABLE }
|
||||
reply.make(packet.txn_id, packet.unit_id, fcode, data)
|
||||
return reply
|
||||
end
|
||||
|
||||
return public
|
||||
end
|
||||
|
||||
return modbus
|
||||
|
@ -353,7 +353,7 @@ function rtu.comms(version, modem, local_port, server_port, conn_watchdog)
|
||||
-- check if there are more than 3 active transactions
|
||||
-- still queue the packet, but this may indicate a problem
|
||||
if unit.pkt_queue.length() > 3 then
|
||||
reply = unit.modbus_io.reply__srv_device_busy(packet)
|
||||
reply = modbus.reply__srv_device_busy(packet)
|
||||
log.debug("queueing new request with " .. unit.pkt_queue.length() ..
|
||||
" transactions already in the queue" .. unit_dbg_tag)
|
||||
end
|
||||
|
@ -25,7 +25,7 @@ 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.11"
|
||||
local RTU_VERSION = "beta-v0.7.12"
|
||||
|
||||
local rtu_t = types.rtu_t
|
||||
|
||||
|
@ -256,7 +256,7 @@ function threads.thread__unit_comms(smem, unit)
|
||||
|
||||
-- execute thread
|
||||
function public.exec()
|
||||
log.debug("rtu unit thread start -> " .. unit.name .. "(" .. unit.type .. ")")
|
||||
log.debug("rtu unit thread start -> " .. unit.type .. "(" .. unit.name .. ")")
|
||||
|
||||
-- load in from shared memory
|
||||
local rtu_state = smem.rtu_state
|
||||
@ -289,7 +289,7 @@ function threads.thread__unit_comms(smem, unit)
|
||||
|
||||
-- check for termination request
|
||||
if rtu_state.shutdown then
|
||||
log.info("rtu unit thread exiting -> " .. unit.name .. "(" .. unit.type .. ")")
|
||||
log.info("rtu unit thread exiting -> " .. unit.type .. "(" .. unit.name .. ")")
|
||||
break
|
||||
end
|
||||
|
||||
@ -309,7 +309,7 @@ function threads.thread__unit_comms(smem, unit)
|
||||
end
|
||||
|
||||
if not rtu_state.shutdown then
|
||||
log.info(util.c("rtu unit thread ", unit.name, "(", unit.type, ") restarting in 5 seconds..."))
|
||||
log.info(util.c("rtu unit thread ", unit.type, "(", unit.name, ") restarting in 5 seconds..."))
|
||||
util.psleep(5)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user