View difference between Paste ID: n3yTMA9W and P2MLRWhH
SHOW: | | - or go back to the newest paste.
1
args = {...}
2
enableRaw = false -- Enables interception of Raw EAS transmissions (Beta)
3
p = "easp"
4
isDebugging = false
5
 
6
function openModems()
7
 for _, v in pairs(rs.getSides()) do
8
  if peripheral.getType(v) == "modem" then
9
   rednet.open(v)
10
   print("DEBUG: Attempted to open modem on side: "..v)
11
  end
12
 end
13
end
14
 
15
function react(msg)
16
 if term.isColour() then
17
  term.setTextColor(colors.orange)
18
 end
19
 print("["..textutils.formatTime(os.time(), false).."] "..msg)
20
 pulse(10, "back")
21
 term.setTextColor(colors.white)
22
end
23
 
24
function pulse(sec, side)
25
 local num = sec
26
 while true do
27
  local oldNum = num
28
  redstone.setOutput(side,true)
29
  sleep(0.5)
30
  redstone.setOutput(side,false)
31
  sleep(0.5)
32
  num = oldNum - 1
33
  if num == 0 then break end
34
 end
35
end
36
 
37
openModems()
38
if args[1] == "-debug" or args[2] == "-debug" then isDebugging = true end
39
if args[1] == "-raw" or args[2] == "-raw" then enableRaw = true end
40
term.clear()
41
term.setCursorPos(1, 1)
42
print("EAS Decoder v1.0")
43
print("["..textutils.formatTime(os.time(), false).."] Started EAS decoder")
44
if isDebugging then
45
 if term.isColour() then
46
  print("["..textutils.formatTime(os.time(), false).."] DEBUG: EAS decoder is working on an Advanced PC")
47
 end
48
end
49
if enableRaw then print("["..textutils.formatTime(os.time(), false).."] EAS Decoder is working in Raw mode") end
50
if enableRaw then p = "easraw" end
51
while true do
52
senderId, message, protocol = rednet.receive(p)
53
if isDebugging then print("["..textutils.formatTime(os.time(), false).."] DEBUG: Received EAS transmission from "..senderId) end
54
react(message)
55
end