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.
|
The master node must have a modem attached and be within range of all slave nodes.
|
||||||
|
|
||||||
1. Deploy at least one slave node
|
1. Deploy at least one slave turtle
|
||||||
* The inventory it is to monitor must be above or in front of the unit
|
* 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
|
* 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
|
## Communication Protocol
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ print("Computer ID: " .. os.getComputerID())
|
|||||||
print("Computer " .. os.getComputerID() .. " running as " .. mode)
|
print("Computer " .. os.getComputerID() .. " running as " .. mode)
|
||||||
|
|
||||||
-- Common globals
|
-- Common globals
|
||||||
|
modem = peripheral.find("modem") or error("No modem attached", 0)
|
||||||
-- Master globals
|
-- Master globals
|
||||||
-- Slave globals
|
-- Slave globals
|
||||||
|
|
||||||
@ -33,23 +34,34 @@ end
|
|||||||
-- Master functions
|
-- Master functions
|
||||||
function m_loop()
|
function m_loop()
|
||||||
-- The main loop of the master server
|
-- 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)
|
sleep(1)
|
||||||
end
|
end
|
||||||
-- Slave functions
|
-- Slave functions
|
||||||
function s_loop()
|
function s_loop()
|
||||||
-- The main loop of any slave nodes
|
-- 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)
|
sleep(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Application entrypoint
|
-- Application entrypoint
|
||||||
function main ()
|
function main ()
|
||||||
if (mode == "master") then
|
if (mode == "master") then
|
||||||
|
modem.open(port_return)
|
||||||
c_mainLoop(m_loop)
|
c_mainLoop(m_loop)
|
||||||
elseif (mode == "slave") then
|
elseif (mode == "slave") then
|
||||||
|
modem.open(port_broadcast)
|
||||||
c_mainLoop(s_loop)
|
c_mainLoop(s_loop)
|
||||||
else
|
else
|
||||||
error("Invalid mode: " .. mode .. ", please configure this node appropriately")
|
error("Invalid mode: " .. mode .. ", please configure this node appropriately", 0)
|
||||||
end
|
end
|
||||||
|
modem.closeAll()
|
||||||
end
|
end
|
||||||
|
|
||||||
main()
|
main()
|
Loading…
x
Reference in New Issue
Block a user