Using the makePacketPrinter mechanism is a little bit involved, but typically boils down to the following steps:
As an illustration, this sketch 'hallucinates' that it's receiving 'd' packets at irregular intervals, when it actually is generating them itself. The keys to this sketch are the makePacketPrinter mechanism to generate an in-memory packet, and the SBFReactor::trigger() function (see trigger::cpp).
When run, this sketch generates output along the lines of:
Ln 8.404 Got 'd1' from N Ln 9.566 Got 'd2' from N Ln 9.952 Got 'd3' from N Ln 17.704 Got 'd4' from N
which shows the handleD
packet handler is being invoked, even though (or when) no actual input packets have been received.
// Demonstrate makePacketPrinter u8 myBuffer[PACKET_PRINTER_PACKET_BUFFER_SIZE]; // Let's make room for a max-size packet.. u8 * myPacket; // Location of printed packet u8 myFace; // My virtual face number void handleD(u8 * packet) { logNormal("Got '%#p' from %c\n",packet,FACE_CODE(packetSource(packet))); // Just log 'd' packets } void setup() { myPacket = makePacketPrinter(myFace,myBuffer,sizeof(myBuffer),NORTH); // Create the packet printer if (myPacket == 0) POISON(0); // Really can't happen at this point; die if it does Body.reflex('d',handleD); // Create our reflex } void loop() { static u32 loops = 0; delay(random(10000)); // Wait about five seconds. facePrintf(myFace,"d%d\n",++loops); // Make a 'd' packet in myPacket Body.trigger(myPacket,packetSource(myPacket)); // React as though it arrived from the north }