diff --git a/rtu/dev/redstone.lua b/rtu/dev/redstone.lua new file mode 100644 index 0000000..0ec1283 --- /dev/null +++ b/rtu/dev/redstone.lua @@ -0,0 +1,88 @@ +-- #REQUIRES rtu.lua +-- note: this RTU makes extensive use of the programming concept of closures + +function redstone_rtu() + local self = { + rtu = rtu_init() + } + + local rtu_interface = function () + return self.rtu + end + + local link_di = function (side, color) + local f_read = nil + + if color then + f_read = function () + return rs.testBundledInput(side, color) + end + else + f_read = function () + return rs.getInput(side) + end + end + + self.rtu.connect_di(f_read) + end + + local link_do = function (side, color) + local f_read = nil + local f_write = nil + + if color then + f_read = function () + return colors.test(rs.getBundledOutput(side), color) + end + + f_write = function (value) + local output = rs.getBundledOutput(side) + + if value then + colors.combine(output, value) + else + colors.subtract(output, value) + end + + rs.setBundledOutput(side, output) + end + else + f_read = function () + return rs.getOutput(side) + end + + f_write = function (value) + rs.setOutput(side, color) + end + end + + self.rtu.connect_coil(f_read, f_write) + end + + local link_ai = function (side) + self.rtu.connect_input_reg( + function () + return rs.getAnalogInput(side) + end + ) + end + + local link_ao = function (side) + self.rtu.connect_holding_reg( + function () + return rs.getAnalogOutput(side) + end, + function (value) + rs.setAnalogOutput(side, value) + end + ) + end + + return { + rtu_interface = rtu_interface, + link_di = link_di, + link_do = link_do, + link_ai = link_ai, + link_ao = link_ao + } +end diff --git a/scada-common/rsio.lua b/scada-common/rsio.lua new file mode 100644 index 0000000..ebc91f4 --- /dev/null +++ b/scada-common/rsio.lua @@ -0,0 +1,37 @@ +RS_IO = { + -- digital inputs -- + + -- facility + F_SCRAM, -- active high, facility-wide scram + F_AE2_LIVE, -- active high, indicates whether AE2 network is online (hint: use redstone P2P) + + -- reactor + R_SCRAM, -- active high, reactor scram + R_ENABLE, -- active high, reactor enable + + -- digital outputs -- + + -- waste + WASTE_PO, -- active low, polonium routing + WASTE_PU, -- active low, plutonium routing + WASTE_AM, -- active low, antimatter routing + + -- reactor + R_SCRAMMED, -- if the reactor is scrammed + R_AUTO_SCRAM, -- if the reactor was automatically scrammed + R_ACTIVE, -- if the reactor is active + R_AUTO_CTRL, -- if the reactor burn rate is automatic + R_DMG_CRIT, -- if the reactor damage is critical + R_HIGH_TEMP, -- if the reactor is at a high temperature + R_NO_COOLANT, -- if the reactor has no coolant + R_EXCESS_HC, -- if the reactor has excess heated coolant + R_EXCESS_WS, -- if the reactor has excess waste + R_INSUFF_FUEL, -- if the reactor has insufficent fuel + R_PLC_TIMEOUT, -- if the reactor PLC has not been heard from + + -- analog outputs -- + + A_R_BURN_RATE, -- reactor burn rate percentage + A_B_BOIL_RATE, -- boiler boil rate percentage + A_T_FLOW_RATE -- turbine flow rate percentage +}