mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#30 PLC comms code updated for new comms design
This commit is contained in:
@ -220,10 +220,14 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
|||||||
|
|
||||||
-- PRIVATE FUNCTIONS --
|
-- PRIVATE FUNCTIONS --
|
||||||
|
|
||||||
local _send = function (msg)
|
local _send = function (msg_type, msg)
|
||||||
local packet = scada_packet()
|
local s_pkt = comms.scada_packet()
|
||||||
packet.make(self.seq_num, PROTOCOLS.RPLC, msg)
|
local r_pkt = comms.rplc_packet()
|
||||||
self.modem.transmit(self.s_port, self.l_port, packet.raw())
|
|
||||||
|
r_pkt.make(self.id, msg_type, msg)
|
||||||
|
s_pkt.make(self.seq_num, PROTOCOLS.RPLC, r_pkt.raw_sendable())
|
||||||
|
|
||||||
|
self.modem.transmit(self.s_port, self.l_port, s_pkt.raw_sendable())
|
||||||
self.seq_num = self.seq_num + 1
|
self.seq_num = self.seq_num + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -231,28 +235,28 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
|||||||
local _reactor_status = function ()
|
local _reactor_status = function ()
|
||||||
ppm.clear_fault()
|
ppm.clear_fault()
|
||||||
return {
|
return {
|
||||||
status = self.reactor.getStatus(),
|
self.reactor.getStatus(),
|
||||||
burn_rate = self.reactor.getBurnRate(),
|
self.reactor.getBurnRate(),
|
||||||
act_burn_r = self.reactor.getActualBurnRate(),
|
self.reactor.getActualBurnRate(),
|
||||||
temp = self.reactor.getTemperature(),
|
self.reactor.getTemperature(),
|
||||||
damage = self.reactor.getDamagePercent(),
|
self.reactor.getDamagePercent(),
|
||||||
boil_eff = self.reactor.getBoilEfficiency(),
|
self.reactor.getBoilEfficiency(),
|
||||||
env_loss = self.reactor.getEnvironmentalLoss(),
|
self.reactor.getEnvironmentalLoss(),
|
||||||
|
|
||||||
fuel = self.reactor.getFuel(),
|
self.reactor.getFuel(),
|
||||||
fuel_need = self.reactor.getFuelNeeded(),
|
self.reactor.getFuelNeeded(),
|
||||||
fuel_fill = self.reactor.getFuelFilledPercentage(),
|
self.reactor.getFuelFilledPercentage(),
|
||||||
waste = self.reactor.getWaste(),
|
self.reactor.getWaste(),
|
||||||
waste_need = self.reactor.getWasteNeeded(),
|
self.reactor.getWasteNeeded(),
|
||||||
waste_fill = self.reactor.getWasteFilledPercentage(),
|
self.reactor.getWasteFilledPercentage(),
|
||||||
cool_type = self.reactor.getCoolant()['name'],
|
self.reactor.getCoolant()['name'],
|
||||||
cool_amnt = self.reactor.getCoolant()['amount'],
|
self.reactor.getCoolant()['amount'],
|
||||||
cool_need = self.reactor.getCoolantNeeded(),
|
self.reactor.getCoolantNeeded(),
|
||||||
cool_fill = self.reactor.getCoolantFilledPercentage(),
|
self.reactor.getCoolantFilledPercentage(),
|
||||||
hcool_type = self.reactor.getHeatedCoolant()['name'],
|
self.reactor.getHeatedCoolant()['name'],
|
||||||
hcool_amnt = self.reactor.getHeatedCoolant()['amount'],
|
self.reactor.getHeatedCoolant()['amount'],
|
||||||
hcool_need = self.reactor.getHeatedCoolantNeeded(),
|
self.reactor.getHeatedCoolantNeeded(),
|
||||||
hcool_fill = self.reactor.getHeatedCoolantFilledPercentage()
|
self.reactor.getHeatedCoolantFilledPercentage()
|
||||||
}, ppm.faulted()
|
}, ppm.faulted()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -261,8 +265,8 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
|||||||
local changed = false
|
local changed = false
|
||||||
|
|
||||||
if not faulted then
|
if not faulted then
|
||||||
for key, value in pairs(status) do
|
for i = 1, #status do
|
||||||
if value ~= self.status_cache[key] then
|
if status[i] ~= self.status_cache[i] then
|
||||||
changed = true
|
changed = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -277,50 +281,33 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- keep alive ack
|
-- keep alive ack
|
||||||
local _send_keep_alive_ack = function ()
|
local _send_keep_alive_ack = function (srv_time)
|
||||||
local keep_alive_data = {
|
_send(RPLC_TYPES.KEEP_ALIVE, { srv_time, os.time() })
|
||||||
id = self.id,
|
|
||||||
timestamp = os.time(),
|
|
||||||
type = RPLC_TYPES.KEEP_ALIVE
|
|
||||||
}
|
|
||||||
|
|
||||||
_send(keep_alive_data)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- general ack
|
-- general ack
|
||||||
local _send_ack = function (type, succeeded)
|
local _send_ack = function (msg_type, succeeded)
|
||||||
local ack_data = {
|
_send(msg_type, { succeeded })
|
||||||
id = self.id,
|
|
||||||
type = type,
|
|
||||||
ack = succeeded
|
|
||||||
}
|
|
||||||
|
|
||||||
_send(ack_data)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- send structure properties (these should not change)
|
-- send structure properties (these should not change)
|
||||||
-- (server will cache these)
|
-- (server will cache these)
|
||||||
local _send_struct = function ()
|
local _send_struct = function ()
|
||||||
ppm.clear_fault()
|
ppm.clear_fault()
|
||||||
|
|
||||||
local mek_data = {
|
local mek_data = {
|
||||||
heat_cap = self.reactor.getHeatCapacity(),
|
self.reactor.getHeatCapacity(),
|
||||||
fuel_asm = self.reactor.getFuelAssemblies(),
|
self.reactor.getFuelAssemblies(),
|
||||||
fuel_sa = self.reactor.getFuelSurfaceArea(),
|
self.reactor.getFuelSurfaceArea(),
|
||||||
fuel_cap = self.reactor.getFuelCapacity(),
|
self.reactor.getFuelCapacity(),
|
||||||
waste_cap = self.reactor.getWasteCapacity(),
|
self.reactor.getWasteCapacity(),
|
||||||
cool_cap = self.reactor.getCoolantCapacity(),
|
self.reactor.getCoolantCapacity(),
|
||||||
hcool_cap = self.reactor.getHeatedCoolantCapacity(),
|
self.reactor.getHeatedCoolantCapacity(),
|
||||||
max_burn = self.reactor.getMaxBurnRate()
|
self.reactor.getMaxBurnRate()
|
||||||
}
|
}
|
||||||
|
|
||||||
if not faulted then
|
if not ppm.is_faulted() then
|
||||||
local struct_packet = {
|
_send(RPLC_TYPES.MEK_STRUCT, mek_data)
|
||||||
id = self.id,
|
|
||||||
type = RPLC_TYPES.MEK_STRUCT,
|
|
||||||
mek_data = mek_data
|
|
||||||
}
|
|
||||||
|
|
||||||
_send(struct_packet)
|
|
||||||
else
|
else
|
||||||
log._error("failed to send structure: PPM fault")
|
log._error("failed to send structure: PPM fault")
|
||||||
end
|
end
|
||||||
@ -381,7 +368,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
|||||||
if packet.type == RPLC_TYPES.KEEP_ALIVE then
|
if packet.type == RPLC_TYPES.KEEP_ALIVE then
|
||||||
-- keep alive request received, echo back
|
-- keep alive request received, echo back
|
||||||
local timestamp = packet.data[1]
|
local timestamp = packet.data[1]
|
||||||
local trip_time = os.time() - ts
|
local trip_time = os.time() - timestamp
|
||||||
|
|
||||||
if trip_time < 0 then
|
if trip_time < 0 then
|
||||||
log._warning("PLC KEEP_ALIVE trip time less than 0 (" .. trip_time .. ")")
|
log._warning("PLC KEEP_ALIVE trip time less than 0 (" .. trip_time .. ")")
|
||||||
@ -389,7 +376,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
|||||||
log._warning("PLC KEEP_ALIVE trip time > 1s (" .. trip_time .. ")")
|
log._warning("PLC KEEP_ALIVE trip time > 1s (" .. trip_time .. ")")
|
||||||
end
|
end
|
||||||
|
|
||||||
_send_keep_alive_ack()
|
_send_keep_alive_ack(timestamp)
|
||||||
elseif packet.type == RPLC_TYPES.LINK_REQ then
|
elseif packet.type == RPLC_TYPES.LINK_REQ then
|
||||||
-- link request confirmation
|
-- link request confirmation
|
||||||
log._debug("received unsolicited link request response")
|
log._debug("received unsolicited link request response")
|
||||||
@ -489,12 +476,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
|||||||
|
|
||||||
-- attempt to establish link with supervisor
|
-- attempt to establish link with supervisor
|
||||||
local send_link_req = function ()
|
local send_link_req = function ()
|
||||||
local linking_data = {
|
_send(RPLC_TYPES.LINK_REQ, {})
|
||||||
id = self.id,
|
|
||||||
type = RPLC_TYPES.LINK_REQ
|
|
||||||
}
|
|
||||||
|
|
||||||
_send(linking_data)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- send live status information
|
-- send live status information
|
||||||
@ -508,38 +490,28 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local sys_status = {
|
local sys_status = {
|
||||||
id = self.id,
|
os.time(),
|
||||||
type = RPLC_TYPES.STATUS,
|
(not self.scrammed),
|
||||||
timestamp = os.time(),
|
overridden,
|
||||||
control_state = not self.scrammed,
|
degraded,
|
||||||
overridden = overridden,
|
self.reactor.getHeatingRate(),
|
||||||
degraded = degraded,
|
mek_data
|
||||||
heating_rate = self.reactor.getHeatingRate(),
|
|
||||||
mek_data = mek_data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_send(sys_status)
|
_send(RPLC_TYPES.STATUS, sys_status)
|
||||||
end
|
end
|
||||||
|
|
||||||
local send_iss_status = function ()
|
local send_iss_status = function ()
|
||||||
local iss_status = {
|
_send(RPLC_TYPES.ISS_STATUS, iss.status())
|
||||||
id = self.id,
|
|
||||||
type = RPLC_TYPES.ISS_STATUS,
|
|
||||||
status = iss.status()
|
|
||||||
}
|
|
||||||
|
|
||||||
_send(iss_status)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local send_iss_alarm = function (cause)
|
local send_iss_alarm = function (cause)
|
||||||
local iss_alarm = {
|
local iss_alarm = {
|
||||||
id = self.id,
|
cause,
|
||||||
type = RPLC_TYPES.ISS_ALARM,
|
iss.status()
|
||||||
cause = cause,
|
|
||||||
status = iss.status()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_send(iss_alarm)
|
_send(RPLC_TYPES.ISS_ALARM, iss_alarm)
|
||||||
end
|
end
|
||||||
|
|
||||||
local is_scrammed = function () return self.scrammed end
|
local is_scrammed = function () return self.scrammed end
|
||||||
|
Reference in New Issue
Block a user