From b5ea97b5d9fecad28f62a419b945e5e088e2f0cb Mon Sep 17 00:00:00 2001 From: Jacob Babor Date: Sun, 25 Feb 2024 23:01:37 -0600 Subject: [PATCH] More boilerplate --- storage-net/README.md | 6 ++++-- storage-net/common.lua | 14 +++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/storage-net/README.md b/storage-net/README.md index fcfb073..b061001 100644 --- a/storage-net/README.md +++ b/storage-net/README.md @@ -10,9 +10,11 @@ Slave nodes must have a modem attached and be within range of the GPS and master The master node must have a modem attached and be within range of all slave nodes. -1. Deploy at least one slave node - * The inventory it is to monitor must be above or in front of the unit +1. Deploy at least one slave turtle + * The inventory it is to monitor must be above the unit * The unit should be able to drop below itself to push items to the master node + * Any subsequent slaves should be placed in front of the unit +2. Set up a return system that pushes into the first slave node (can be a hopper or similar) ## Communication Protocol diff --git a/storage-net/common.lua b/storage-net/common.lua index 1aeb55d..66a3682 100644 --- a/storage-net/common.lua +++ b/storage-net/common.lua @@ -19,6 +19,7 @@ print("Computer ID: " .. os.getComputerID()) print("Computer " .. os.getComputerID() .. " running as " .. mode) -- Common globals +modem = peripheral.find("modem") or error("No modem attached", 0) -- Master globals -- Slave globals @@ -33,23 +34,34 @@ end -- Master functions function m_loop() -- The main loop of the master server + -- Listen for packets on the return net. This has a timeout for events and stuff + local timeout = os.startTimer(1) + local event, side, channel, replyChannel, message, distance = os.pullEvent() + if (event == "modem_message") then + print("Message received: " .. message) + end sleep(1) end -- Slave functions function s_loop() -- The main loop of any slave nodes + -- Listen for packets from the master + local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message") sleep(1) end -- Application entrypoint function main () if (mode == "master") then + modem.open(port_return) c_mainLoop(m_loop) elseif (mode == "slave") then + modem.open(port_broadcast) c_mainLoop(s_loop) else - error("Invalid mode: " .. mode .. ", please configure this node appropriately") + error("Invalid mode: " .. mode .. ", please configure this node appropriately", 0) end + modem.closeAll() end main() \ No newline at end of file