Posted 15 June 2014 - 04:45 PM
Hello,
is there any way to implement a kind of an ISR?
Basically what I tried (and what didn't work) is to use the ParallelAPI.
I have a network with three computers, each commicating with each other. There is also a turtle, which can do something (turtleState = 1) or stand by (turtleState = 0).
Since all computers need to know if they can send commands to the turtle, everytime the turtle starts to do an action, it broadcasts "1" via the protocol "tscP".
Besides this, the computers also have to receive messages from other computers, which im doing over the "sP" (standard Protocol). When they receive a message, they have to execute something, but while they are executing, they should still be able to receive the turtle status change, since this can happen at any time.
This is similar to an ISR, since the turtle status change should be an interrupt, then the variable should be set, and afterwards the program should continue what it started.
Now is there a way to do this in lua? Or do you have any similar idea how to solve this problem?
is there any way to implement a kind of an ISR?
Basically what I tried (and what didn't work) is to use the ParallelAPI.
function receiveStandard()
while (true) do
sID, msg = rednet.receive("sP")
uMsg = textutils.unserialize(msg)
print("Received Message from ", sID, ": ", uMsg["fct"])
if (uMsg["fct"] == "sortInto") then
sortOutInvalid()
sortIntoWarehouse()
end
end
end
function receiveTurtleStatusChange()
while (true) do
sID, msg = rednet.receive("tscP")
turtleState = tonumber(msg)
print("New turtle state: ", turtleState)
end
end
parallel.waitForAll(receiveStandard, receiveTurtleStatusChange)
I have a network with three computers, each commicating with each other. There is also a turtle, which can do something (turtleState = 1) or stand by (turtleState = 0).
Since all computers need to know if they can send commands to the turtle, everytime the turtle starts to do an action, it broadcasts "1" via the protocol "tscP".
Besides this, the computers also have to receive messages from other computers, which im doing over the "sP" (standard Protocol). When they receive a message, they have to execute something, but while they are executing, they should still be able to receive the turtle status change, since this can happen at any time.
This is similar to an ISR, since the turtle status change should be an interrupt, then the variable should be set, and afterwards the program should continue what it started.
Now is there a way to do this in lua? Or do you have any similar idea how to solve this problem?