 byte* buf_curr; //current position of buffer
 
 //fake data
-struct Payload {
   long latitude; //42.4439;
   long longitude;//-76.5018;
   int altitude;//9999
   byte flags;//0xF;
-} payload, *ptr_payload;
 
 enum States {
   STOPPED, PRE_LAUNCH, POST_LAUNCH, SEND_DATA, READ_DATA, READ_GPS, ERROR 


  if (millis() - timer > 400) {
    timer = millis(); // reset the timer

    if (GPS.fix) {
      payload.latitude = convertDegMinToDecDeg(GPS.latitude)*10000;
      payload.longitude = convertDegMinToDecDeg(GPS.longitude)*10000;
      payload.altitude = GPS.altitude;

      //set every byte in array to 0
      memset( buf_start, 0, MAX_BUF );

      //buf_start is pointer to first allocated space
      //buf_curr is pointer to next free space
      buf_curr = stream(MARKER_LAT, buf_start, (void*)ptr_payload->latitude, sizeof(payload.latitude));
      buf_curr = stream(MARKER_LON, buf_curr, (void*)ptr_payload->longitude, sizeof(payload.longitude));
      buf_curr = stream(MARKER_ALT, buf_curr, (void*)ptr_payload->altitude, sizeof(payload.altitude));
      buf_curr = stream(MARKER_FLAG, buf_curr, (void*)ptr_payload->flags, sizeof(payload.flags));

      //buffer size is the difference between the current and start pointers
      buf_size = buf_curr - buf_start;

      //check that buffer size did not exceed allocated size
      if( buf_size > MAX_BUF )
      {
        Serial.println("Buffer Overflow " + buf_size);
      }

      XBee.write(buf_start, buf_size);
      //arduino is little endian (LSB first)

      byte* bufferReader = buf_start;
      Serial.print("Size: ");
      Serial.println(buf_size);
      while (bufferReader != buf_curr) {
        Serial.print(*bufferReader, HEX);
        Serial.print(" ");
        bufferReader++;
      }
      Serial.println();

    }
  }
}


void setup()
{
  //Make sure XBee baud matches hardware config
  XBee.begin(115200);
  Serial.begin(115200);
  //delay(5000);

