trigger.cpp

Many non-SFB devices actually 'speak SFB packets' in the sense of producing reasonably short, newline-terminated, sequences of (printable) ASCII characters. But they're not true SFB's, so we can't talk to them as if they were -- because for one thing, they don't know how to perform SFB baud rate negotiation.

A GPS unit that produces 'NMEA sentences', for example, might be such a device -- an NMEA 0183 sentence begins with a '$', contains 'normal' ASCII characters, and ends with a carriage return and a newline.

In such a case, assuming a baud rate has been agreed upon in advance, conscious packet handling on some specified face can be used to acquire packets from the device. Given such a packet, though, often what is desired is to have the system 'react' to the packet as if it had been received via full packet handling.

The SFBReactor::trigger() method, demonstrated in this sketch as 'Body.trigger()', provides a way to pass a packet back to the core software, saying in effect: "Trigger the appropriate reflex for this packet, assuming it arrived from this face."

// trigger: Read packets consciously from EAST, and react to them as normal packets

void nmeaHandler(u8 * packet) { // Handle input as desired
  logNormal("NMEA data: %#p\n" ,packet); // Here, we'll just log it NORTH
}

void setup() {
  EastFace.begin(4800,false);   // Conscious packets east; 4800 8N1 is slow but sure
  Body.reflex('$',nmeaHandler); // Regular NMEA 0183 packets start with '$'
  setLogFace(NORTH);            // Send logging NORTH. (ALL_FACES is another good choice)
}

void loop() { 
  u8 * packet = EastFace.readPacket(); // Check for input from the GPS
  if (packet)                          // Got something..
    Body.trigger(packet, EAST);        // ..so go trigger our reflexes on it
}

Generated on Fri Apr 22 06:54:11 2011 for SFB by doxygen 1.5.9