 */
 void setup() {
 
-    Serial.begin(9600);      // for comm with xbee
+    Serial.begin(9600);      // for comm with xbee - TODO increase to 57600
     pinMode(LED,OUTPUT);     // indicator for rec. packet
     xbee.setSerial(Serial);
     broadcast64 = XBeeAddress64(0, 0x0000FFFF);  //broadcast address

    delay(100); // give some time to initalize
}

/** transmit power state as broadcast to all XBees
 *  "P 1" = track power (gleisbit) is on
 *  "P 0" = track power is off
*/
void send_power_state(uint8_t on) {
  for (int i=0; i <12; i++) {
    payload[i]=0;
  }
      payload[0]='P';
      payload[1]= ' ';
      if (on == 1) {
         payload[2] = '1';
      } else {
         payload[2] = '0';
      }
      payload[3]=0;  // string end  */

      xbee.send(zbTx);
}

/** receive loop for:

            char c = rx.getData(i);
            s += c;
         }
         if ((s[0] == 'R') || (s[0] == 'r')) {
            // read command, 1 int attribute
            // "R44" =read data of channel 44
            String ch = s.substring(1);
            int i_ch = ch.toInt();
            if ( ((i_ch >=1) && (i_ch <=99))
                || (i_ch == 127)) {
               uint8_t d = sx.get(i_ch);
               sendData((uint8_t)i_ch, d);
            }
         } else if ((s[0] == 'S') || (s[0] == 's')) {
            // "SET" command
            // interpret SX command from XBee
            int n= s.indexOf(' '); // command split by space
            // example:  "S44 31" = set loco #44 to speed 31,
            //                forward, Light=off, F=off
            //       (standard selectrix data format, 8 bit)
            // 127=trackpower also handled like a standard SX channel
            if (n != -1) {
               String ch = s.substring(1,n); // remove leading 's', until space
               int i_ch = ch.toInt();
               String s2 = s.substring(n+1,s.length());
               int i_value = s2.toInt();
               if ((i_value >= 0 ) && (i_value <= 255)) {  //data valid
                  uint8_t dsx = sx.get(i_ch);  // read current data on bus for this loco
                  if (dsx != (uint8_t)i_value) { // sent only if data have changed
                     do {
                        delay(10);
                     } while (sx.set(i_ch,i_value));  // send to SX bus
                  }
               }
            }

         }
         digitalWrite(LED,LOW);  // indicate stop of send to SX Bus
