Minor cleanup
This commit is contained in:
parent
9f2b3a8050
commit
5dd175bb00
@ -42,7 +42,6 @@ function c_waitForMessage()
|
|||||||
(message["networkid"] ~= networkid) or -- Ignore packets from other networks
|
(message["networkid"] ~= networkid) or -- Ignore packets from other networks
|
||||||
(message["targetid"] and message["targetid"] ~= os.getComputerID) -- Ignore packets for other machines
|
(message["targetid"] and message["targetid"] ~= os.getComputerID) -- Ignore packets for other machines
|
||||||
then
|
then
|
||||||
print("Discarded nonconformant message")
|
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
return message
|
return message
|
||||||
@ -60,7 +59,7 @@ function c_sendMessage(message)
|
|||||||
for k,v in pairs(message) do
|
for k,v in pairs(message) do
|
||||||
msg[k] = v
|
msg[k] = v
|
||||||
end
|
end
|
||||||
print("Transmitting message: " .. textutils.serialize(msg))
|
--print("Transmitting message: " .. textutils.serialize(msg))
|
||||||
rednet.broadcast(msg, packet_magic)
|
rednet.broadcast(msg, packet_magic)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -73,10 +72,16 @@ function m_loop()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
if msg["type"] == "pong" then
|
if msg["type"] == "pong" then
|
||||||
print("Received pong from slave: " .. msg["sourceid"])
|
local source = msg["sourceid"]
|
||||||
|
print("Received pong from slave: " .. source)
|
||||||
|
m_slaves[source] = source
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function m_ping()
|
function m_ping()
|
||||||
|
-- Clear out the list of all slaves and send out a fresh ping
|
||||||
|
-- Ping information isn't used for much, so delay in clearing cache and
|
||||||
|
-- repopulating the data isn't a big deal.
|
||||||
|
m_slaves = {}
|
||||||
c_sendMessage({type="ping"})
|
c_sendMessage({type="ping"})
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -104,8 +109,8 @@ function main ()
|
|||||||
rednet.open(modem_side)
|
rednet.open(modem_side)
|
||||||
|
|
||||||
print("Pinging for slaves...")
|
print("Pinging for slaves...")
|
||||||
c_sendMessage({type="ping"})
|
m_ping()
|
||||||
|
|
||||||
print("Entering main loop")
|
print("Entering main loop")
|
||||||
c_mainLoop(m_loop)
|
c_mainLoop(m_loop)
|
||||||
elseif (mode == "slave") then
|
elseif (mode == "slave") then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user