 #include <OneWire.h> 
 #include <Wire.h>
 #include <SoftwareSerial.h>
+#include <string.h>
+#include <util/crc16.h>
 
 
 // *********************************************************************

float CurrentTimeStamp;


void setup(void) {
  Serial.begin(9600);
  

}


void TransmitDataToGround(float TimeStamp, float Altitude, float Latitude, float Longitude) {
  dtostrf(TimeStamp, 20, 3, TimeStampBuffer);
  dtostrf(Altitude, 20, 3, AltitudeBuffer);
  dtostrf(Latitude, 20, 5, LatitudeBuffer);
  dtostrf(Longitude, 20, 5, LongitudeBuffer);

  int TransmitIndex = 0;
  TransmitIndex = TransferBuffer(CALL_SIGN, sizeof(CALL_SIGN), TransmitBuffer, TransmitIndex, true);
  TransmitIndex = TransferBuffer(TimeStampBuffer, sizeof(TimeStampBuffer), TransmitBuffer, TransmitIndex, true);
  TransmitIndex = TransferBuffer(AltitudeBuffer, sizeof(AltitudeBuffer), TransmitBuffer, TransmitIndex, true);
  TransmitIndex = TransferBuffer(LatitudeBuffer, sizeof(LatitudeBuffer), TransmitBuffer, TransmitIndex, true);
  TransmitIndex = TransferBuffer(LongitudeBuffer, sizeof(LongitudeBuffer), TransmitBuffer, TransmitIndex, true);


  unsigned int CHECKSUM = gps_CRC16_checksum(TransmitBuffer);  // Calculates the checksum for this datastring
  sprintf(TransmitBufferChecksum, "*%04X\n", CHECKSUM);
  TransmitIndex = TransferBuffer(TransmitBufferChecksum, sizeof(TransmitBufferChecksum), TransmitBuffer, TransmitIndex, false);
 
  // TODO: Write data to radio
  //Serial.println(TransmitBuffer);
  rtty_txstring (TransmitBuffer);
}




// *********************************************************************
// General subroutines


// This copies the SourceBuffer into DestBuffer starting at DestIndex, 
// but trims out any leading spaces in SourceBuffer
int TransferBuffer(char* SourceBuffer, int SourceBufferSize, char* DestBuffer, int DestIndex, boolean ShouldAddComma) {
  int BufferIndex = 0;
  
  // Skip all characters from 0-32, but don't count carriage returns, chr(13)
  while (BufferIndex < SourceBufferSize-1 
          && SourceBuffer[BufferIndex] <= 32 && SourceBuffer[BufferIndex] != 13) { BufferIndex++; }
  while (BufferIndex < SourceBufferSize-1) {     
    DestBuffer[DestIndex] = SourceBuffer[BufferIndex];
    DestIndex++;
    BufferIndex++;
  }  
  
  if(ShouldAddComma) {
    TransmitBuffer[DestIndex] = ',';
    DestIndex++;
  }

  return DestIndex;
}



// *********************************************************************
// Temperature sensor subroutines
float GetTemp(){
