Posted 27 November 2015 - 01:45 PM
I'm coding in my modemShark scanner functionality, and I've been stuck in the same place for two hours now, with zero progress made.
This code resides in a function(no args, for reasons). pMax, pMin, and modemSide are supplied externally. It uses pMin and pMax to send traffic over channels that are opened elsewhere in the program. For the sake of working with a normal CraftOS repeat program, traffic is being sent over 65533, so assume pMin and pMax are both 65533.
What ends up happening is that the program sends a packet. A repeater then sends the same packet back (twice, incidentally because the rednet's repeat() program wasn't designed to handle an incoming packet on 65533, headed for 65533 and not transmit it twice). I've verified with another computer that indeed the packets are being transmitted both ways. The program then SHOULD be waiting for a response, but I have no way of telling if it's actually doing that. All of the code up until:
Note that when I say it just dies, the program itself keeps running. The coroutine itself is what ceases to progress. It doesn't throw any errors, and any statements after that line of code above simply doesn't execute. However, the loop that created and resumed the coroutines will progress, and code after the loop is fine too.
Wat do?
This code resides in a function(no args, for reasons). pMax, pMin, and modemSide are supplied externally. It uses pMin and pMax to send traffic over channels that are opened elsewhere in the program. For the sake of working with a normal CraftOS repeat program, traffic is being sent over 65533, so assume pMin and pMax are both 65533.
Spoiler
function scan()
local pings = {n=(pMax - pMin)}
local rChans = {}
local i = 0
for n=pMin,pMax do
local x, y = term.getCursorPos()
term.clearLine()
term.setCursorPos(3,y)
pings[n] = coroutine.create(function()
--(mostly) standard rednet packet creation
local nMessageID = math.random( 1, 2147483647 )
local nReplyChannel = n
local tMessage = {
nMessageID = nMessageID,
nRecipient = n,
message = "ayb",
sProtocol = "abtu"}
-- sending the packet
peripheral.call( modemSide, "transmit", tMessage.nRecipient, nReplyChannel, tMessage
print("sent message") == <<< this is a debug message that executes
local event, mSide, mRCh, mSCh, mMsg, mDst = os.pullEvent("modem_message")
print("got message") -- <<< this is a debug message that never executes
if mMsg.nMessageID == nMessageID then coroutine.yield(true)
else coroutine.yield(false)
end
end) -- end of coroutine
print("Resuming co")
local _, rsp = coroutine.resume(pings[n])
if rsp == true then rChans[i] = n end
i = i + 1
sleep(.1)
end
print("--- CHANNELS THAT RESPONDED ---")
if rChans[0] ~= nil then
for i=0,#rChans do
write(rChans[i] .. ", ")
end
else write("no responses across channel range")
end
local x, y = term.getCursorPos()
term.setCursorPos(1,y)
write("\n..>")
sleep(10)
end
local _, _, _, _, mMsg, _ = os.pullEvent("modem_message")
will execute flawlessly, and then it just dies. It definitely IS getting a response(two, infact) and they are on open modem channels, so I don't know what could be happening here.Note that when I say it just dies, the program itself keeps running. The coroutine itself is what ceases to progress. It doesn't throw any errors, and any statements after that line of code above simply doesn't execute. However, the loop that created and resumed the coroutines will progress, and code after the loop is fine too.
Wat do?
Edited on 27 November 2015 - 02:27 PM