Minor cleanup

This commit is contained in:
Salt 2024-02-26 00:40:16 -06:00
parent 9f2b3a8050
commit 5dd175bb00
1 changed files with 10 additions and 5 deletions

View File

@ -42,7 +42,6 @@ function c_waitForMessage()
(message["networkid"] ~= networkid) or -- Ignore packets from other networks
(message["targetid"] and message["targetid"] ~= os.getComputerID) -- Ignore packets for other machines
then
print("Discarded nonconformant message")
return nil
end
return message
@ -60,7 +59,7 @@ function c_sendMessage(message)
for k,v in pairs(message) do
msg[k] = v
end
print("Transmitting message: " .. textutils.serialize(msg))
--print("Transmitting message: " .. textutils.serialize(msg))
rednet.broadcast(msg, packet_magic)
end
@ -73,10 +72,16 @@ function m_loop()
return
end
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
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"})
end
@ -104,8 +109,8 @@ function main ()
rednet.open(modem_side)
print("Pinging for slaves...")
c_sendMessage({type="ping"})
m_ping()
print("Entering main loop")
c_mainLoop(m_loop)
elseif (mode == "slave") then