initialize
This commit is contained in:
commit
5b23ea99fd
43 changed files with 2336 additions and 0 deletions
3
apricot/README.md
Normal file
3
apricot/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
If this ever gets worked on again, this was intended to log **all** messages on **all** possible channels, reverse tria- wait no there's a different word for this. Basically global spy monitoring station
|
||||
|
||||
If you're wondering why it's named apricot, I literally had no idea and randomly thought about throwing apricots at people in Hitman 3. **Yes.**
|
58
apricot/node/logger.lua
Normal file
58
apricot/node/logger.lua
Normal file
|
@ -0,0 +1,58 @@
|
|||
local logger = {}
|
||||
logger.init = function(monitor_wrap, scale)
|
||||
local self = {}
|
||||
|
||||
local monitor = monitor_wrap or peripheral.find("monitor")
|
||||
if not monitor then
|
||||
monitor = term
|
||||
else monitor.setTextScale(scale or 0.5)
|
||||
end
|
||||
local log_colours = {
|
||||
['log'] = colours.white,
|
||||
['info'] = colours.lightBlue,
|
||||
['warn'] = colours.yellow,
|
||||
['err'] = colours.red,
|
||||
['success'] = colours.lime
|
||||
}
|
||||
|
||||
local function move_line()
|
||||
monitor.setCursorPos(1, select(2, monitor.getCursorPos()) + 1)
|
||||
if select(2, monitor.getCursorPos()) >= select(2, monitor.getSize()) then
|
||||
monitor.scroll(1)
|
||||
monitor.setCursorPos(1, select(2, monitor.getCursorPos()) - 1)
|
||||
end
|
||||
end
|
||||
|
||||
local function write_msg(message, msg_colour)
|
||||
local time_str = os.date('%Y-%b-%d %H:%M:%S')
|
||||
local msg_formatted = "[" .. time_str .. "] " .. message
|
||||
|
||||
monitor.setTextColour(msg_colour)
|
||||
monitor.write(msg_formatted)
|
||||
move_line()
|
||||
end
|
||||
|
||||
function self.log(msg)
|
||||
write_msg(msg, log_colours['log'])
|
||||
end
|
||||
|
||||
function self.info(msg)
|
||||
write_msg('INFO: ' .. msg, log_colours['info'])
|
||||
end
|
||||
|
||||
function self.warning(msg)
|
||||
write_msg('WARNING: ' .. msg, log_colours['warn'])
|
||||
end
|
||||
|
||||
function self.error(msg)
|
||||
write_msg('ERROR: ' .. msg, log_colours['err'])
|
||||
end
|
||||
|
||||
function self.success(msg)
|
||||
write_msg('SUCCESS: ' .. msg, log_colours['success'])
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
return logger
|
19
apricot/node/modems.lua
Normal file
19
apricot/node/modems.lua
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
local modems = {peripheral.find("modem")}
|
||||
local logger = require('logger').init()
|
||||
|
||||
logger.info("Powering up!")
|
||||
for modem_i, modem in pairs(modems) do
|
||||
modem.closeAll()
|
||||
modem.open(1)
|
||||
-- for i = (128 * (modem_i - 1)),((128 * modem_i) - 1) do
|
||||
-- modem.open(i)
|
||||
-- end
|
||||
logger.success("Modem " .. modem_i .. " opened ports " .. (128 * (modem_i - 1)) .. " - " .. ((128 * modem_i) - 1))
|
||||
end
|
||||
|
||||
local event, side, channel, replyChannel, message, distance
|
||||
while true do
|
||||
event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
|
||||
logger.info(channel .. " " .. replyChannel .. " " .. tostring(message) .. " " .. distance )
|
||||
end
|
12
apricot/scripts/receiver.lua
Normal file
12
apricot/scripts/receiver.lua
Normal file
|
@ -0,0 +1,12 @@
|
|||
local modem = peripheral.find("modem") or error("No modem attached", 0)
|
||||
local logger = require('logger').init()
|
||||
|
||||
for i = 1,125 do
|
||||
modem.open(i)
|
||||
end
|
||||
|
||||
local event, side, channel, replyChannel, message, distance
|
||||
while true do
|
||||
event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
|
||||
logger.info(channel .. " " .. replyChannel .. " " .. tostring(message) .. " " .. distance )
|
||||
end
|
6
apricot/scripts/sender.lua
Normal file
6
apricot/scripts/sender.lua
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
local modem = peripheral.find("modem") or error("No modem attached", 0)
|
||||
|
||||
modem.transmit(15, 43, "Hello, world!")
|
||||
modem.transmit(25, 2, {message=1})
|
||||
modem.transmit(1, 1, "What if I put you in an infinite loop?")
|
Loading…
Add table
Add a link
Reference in a new issue