brn.cpp

The reflex 'baud rate negotiation' protocol always starts out at 9600 8N1, and involves ongoing exchanges of type 'S' (originally referring to 'Speed') packets, the first of which is always 'S!'. An 'SC' ('Speed Complete') packet ends the initial protocol.

If a sketch wants to do conscious packet handling on a face, and is happy to run the face at 9600 8N1, it is possible to 'short circuit' the BRN, saying in effect "Let's just keep talking 9600 8N1." This sketch demonstrates a way to do that.

// brn: Short-circuits baud rate negotiation on West, and logs all
// other packets north (including those that would normally be handled
// by reflexes, e.g., 'P'rogramming packets).

// (If two IXM's running this sketch are connected together
// west-to-west, watch out!  You might think it's harmless -- since on
// the west this sketch 'never speaks unless spoken to' -- but if an S
// packet does manage to get sent between them (e.g., by deliberate
// 'R'outing), that will provoke a response of TWO S packets, which
// will provoke FOUR S packets, which will...)

void setup() {
  WestFace.begin(9600,false);   // Open west in conscious packet mode, 9600 8N1
}                               // (NORTH unmentioned, defaults to reflex packet mode)

void loop() { 
  u8 * packet = WestFace.readPacket(); // Check for packet from south

  if (!packet)                  // Nothing to deal with
    return;

  if (packet[0]=='S')           // Did we get a type 'S' packet?
    facePrintf(WEST,"S!\nSC\n"); // Yes, respond with S! and SC (two packets!)
  else                          // Otherwise log it to NORTH
    facePrintf(NORTH,"Ld '%#p'\n",packet); // Wrap it in a Log packet and send it NORTH
}

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