More boilerplate
This commit is contained in:
parent
75b9634ea9
commit
b5ea97b5d9
@ -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
|
||||
|
||||
|
@ -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()
|
Loading…
x
Reference in New Issue
Block a user