-
Notifications
You must be signed in to change notification settings - Fork 0
/
derEmulator.lua
116 lines (94 loc) · 2.88 KB
/
derEmulator.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
--derEmulator (Draconic Evolution Reactor Emulator) V1.1.0
--Official Stamper (c) Aug 2018
--Changelog V1.1.0 added OC Code
-- Listen for modem request from control
local modemSide = 'top' -- Only required for CC
local modemTx = 299
local modemRx = 299
-- Emulation values
local fuelInject = 10368
local fuelConversion = 0 --0.5427
--Peripherals and components (do not initialise to values)
--local monitor
local modem
--local emulatedReactor
local serialization
--check os version
local OSVer = ""
local OC = false
local CC = false
if _OSVERSION then
OSVer = _OSVERSION
OC = true
elseif os.version() then
OSVer = os.version()
CC = true
end
if CC then
--Open the modem on the channel specified
modem = peripheral.wrap(modemSide)
os.loadAPI("emulatedReactor")
--local reactor = peripheral.wrap(reactorSide)
elseif OC then
local component = require("component")
local computer = require("computer")
local event = require("event")
local term = require("term")
serialization = require("serialization")
modem = component.modem
local gpu = component.gpu
emulatedReactor = require("mooviesReactor")
os.pullEvent = event.pull
modem.transmit = modem.broadcast
else
-- no valid OS
end
--Initialise emulatedReactor
emulatedReactor.fluxGates.input.setFlowOverride(0)
emulatedReactor.fluxGates.output.setFlowOverride(0)
emulatedReactor.fluxGates.input.setOverrideEnabled(true)
emulatedReactor.fluxGates.output.setOverrideEnabled(true)
emulatedReactor.setFuel(fuelInject, fuelConversion)
modem.open(modemRx)
print("Listening.....")
local request = {
getReactorInfo = function(id)
local info = emulatedReactor.getReactorInfo()
if OC then info = serialization.serialize(info) end
modem.transmit(modemTx, id, info)
end,
chargeReactor = function() emulatedReactor.chargeReactor() end,
activateReactor = function() emulatedReactor.activateReactor() end,
stopReactor = function() emulatedReactor.stopReactor() end,
setFailSafe = function() emulatedReactor.setFailSafe() end,
reset = function() emulatedReactor.reset() end
}
function main()
while true do
local event, modemSide, senderChannel, id, message, senderDistance, more = os.pullEvent("modem_message")
if OC then
senderChannel = id
id = senderDistance
message = serialization.unserialize(more)
end
if (senderChannel == modemRx) then -- is this message for me?
emulatedReactor.fluxGates.input.setFlowOverride(message.inRF)
emulatedReactor.fluxGates.output.setFlowOverride(message.outRF)
emulatedReactor.update()
request[message.req](id)
else
--Message not for me
end
end
end
main()
--local errNo, errMsg = pcall(main)
-- print(tostring(errNo).." : "..errMsg)
-- if errMsg == "Terminated" then
-- return
-- else
-- local f = fs.open("log","a")
-- f.writeLine(textutils.formatTime(os.time("utc"),true).."(UTC) #"..os.getComputerID()..": "..errMsg)
-- f.close()
-- os.reboot()
-- end