char inBuffer[100];
uint32_t now = 0;
uint32_t last = 0;
struct __attribute__((__packed__)) {
// Telegram Header:
uint8_t ui8Start; // 0x00
uint16_t ui16Dummy;
uint8_t ui8Header1; // 0x18
uint8_t ui8Header2; // 0x00
uint8_t ui8Header3; // 0x04
uint8_t ui8Header4; // 0x01
// GPS Data:
uint16_t ui16DummyH;
uint16_t ui16Speed; //10+11
uint16_t ui16DistanceToHome; //12+13
uint16_t ui16Altitude; //14+15
uint16_t ui16LatitudeHigh; //16+17
uint16_t ui16LatitudeLow; //18+19
uint16_t ui16LongitudeHigh;//20+21
uint16_t ui16LongitudeLow;//22+23
uint16_t ui16Direction; //24+25
uint8_t ui8NS; //
uint8_t ui8EW; //
uint16_t ui16Alt1s;
uint8_t ui8Alt3s;
uint8_t ui8Dbm;
uint8_t ui8Sat;
uint8_t ui8FixChar;
uint16_t ui16HomeDirection;
uint8_t ui8AngleX;
uint8_t ui8AngleY;
uint8_t ui8AngleZ;
uint16_t ui16GyroX;
uint16_t ui16GyroY;
uint16_t ui16GyroZ;
uint8_t ui8Vibration;
uint8_t ui8FreeChar1;
uint8_t ui8FreeChar2;
uint8_t ui8FreeChar3;
uint8_t ui8VerNo;
uint16_t ui16DummyD;
} GPSData;
struct __attribute__((__packed__)) {
// Telegram Header:
uint8_t ui8Start; // 0x00
uint16_t ui16Dummy;
uint8_t ui8Header1; // 0x0b
uint8_t ui8Header2; // 0x00
uint8_t ui8Header3; // 0x04
uint8_t ui8Header4; // 0x01
// Receiver Data:
uint16_t ui16DummyH;
uint16_t ui16Temp;
uint16_t ui16LossPack;
uint8_t ui8Strength;
uint8_t ui8Volt;
uint8_t ui8Dbm;
uint8_t ui8Quality;
uint8_t ui8LowVolt;
uint16_t ui16DummyD;
} ReceiverData;
struct __attribute__((__packed__)) {
// Telegram Header:
uint8_t ui8Start;
uint16_t ui16Dummy;
uint8_t ui8Header1;
uint8_t ui8Header2;
uint8_t ui8Header3;
uint8_t ui8Header4;
// Electric Data:
uint16_t ui16Cell_Volt1;
uint16_t ui16Cell_Volt2;
uint16_t ui16Cell_Volt3;
uint16_t ui16Cell_Volt4;
uint16_t ui16Cell_Volt5;
uint16_t ui16Cell_Volt6;
uint16_t ui16Cell_Volt7;
uint16_t ui16Cell_Volt8;
uint16_t ui16Cell_Volt9;
uint16_t ui16Cell_Volt10;
uint16_t ui16Cell_Volt11;
uint16_t ui16Cell_Volt12;
uint16_t ui16Cell_Volt13;
uint16_t ui16Cell_Volt14;
uint16_t ui16Batt_Volt1;
uint16_t ui16Batt_Volt2;
uint16_t ui16Temp1;
uint16_t ui16Temp2;
uint16_t ui16Alt;
uint16_t ui16Power_Current;
uint16_t ui16Power_Volt;
uint16_t ui16Power_Capacity;
uint16_t ui16Alt_1sec;
uint8_t ui8Alt_3sec;
uint8_t ui8Fixed_value; //0xe0
uint16_t ui16RPM;
uint8_t ui8Time_minutes;
uint8_t ui8Time_seconds;
uint8_t ui8Speed;
uint8_t ui8version_number;
uint16_t ui16CRC;
} ElectricData;
const int gpsAnswerLen = 51;
const int eamAnswerLen = 66;
const int rxAnswerLen = 20;
//const int varioAnswerLen = 51;
//const int escAnswerLen = 35;
//const int gamAnswerLen = 60;
const byte gpsRequest[9] = { 0x00, 0x03, 0xfc, 0x00, 0x00, 0x04, 0x38, 0x9f, 0x7b }; //GPS
const byte eamRequest[9] = { 0x00, 0x03, 0xfc, 0x00, 0x00, 0x04, 0x36, 0x51, 0x9a }; //ElectricAir
const byte rxRequest[9] = { 0x00, 0x03, 0xfc, 0x00, 0x00, 0x04, 0x34, 0x13, 0xba }; //Receiver
//const byte varioRequest[9] = { 0x00, 0x03, 0xfc, 0x00, 0x00, 0x04, 0x37, 0x70, 0x8a }; //Vario
//const byte escRequest[9] = { 0x00, 0x03, 0xfc, 0x00, 0x00, 0x04, 0x39, 0xbe, 0x6b }; //ESC
//const byte gamRequest[9] = { 0x00, 0x03, 0xfc, 0x00, 0x00, 0x04, 0x35, 0x32, 0xaa }; //GeneralAir
//Serial0: (RX) and 1 (TX); Serial1: 19 (RX) and 18 (TX); Serial2: 17 (RX) and 16 (TX); Serial3: 15 (RX) and 14 (TX)
#define HOTTSERIAL Serial1 //Serial1: 19 (RX) and 18 (TX)
#define DEBUG
void setup()
{
Serial.begin(19200); //Serial zum PC
memset(inBuffer,0,51);
initHoTT();
}
void loop()
{
now = millis();
if ((now - last) >= 1000)
{
askHoTTgps();
readHoTTgps();
last = now;
}
}
uint32_t HottGetGpsDegree( uint16_t high, uint16_t low )
{
uint32_t ui32Result;
ui32Result = ((uint32_t)(high % 100)) * 10000000;
ui32Result += (uint32_t)low * 1000;
ui32Result /= 60;
ui32Result += (uint32_t)(high/100) * 10000000;
return ui32Result;
}
void initHoTT()
{
HOTTSERIAL.begin(115200);
}
bool HottClean( void )
{
while( HOTTSERIAL.available() > 0 ) HOTTSERIAL.read();
}
// REQUESTS
void askHoTTgps()
{
HottClean();
HOTTSERIAL.write(gpsRequest, 9);
}
void askHoTTelectric()
{
HottClean();
HOTTSERIAL.write(eamRequest, 9);
}
void askHoTTreceiver()
{
HottClean();
HOTTSERIAL.write(rxRequest, 9);
}
//ANSWER
void readHoTTgps()
{
memset(inBuffer,9,sizeof(inBuffer)); //inBuffer leeren
HOTTSERIAL.setTimeout(250);
HOTTSERIAL.readBytes( inBuffer, gpsAnswerLen); //Daten in inBuffer lesen
memcpy(&GPSData,&inBuffer, gpsAnswerLen); //Daten in GPSData struct kopieren
#ifdef DEBUG
Serial.println("GPS MODUL ANTWORT");
Serial.write(inBuffer, gpsAnswerLen); //Debugausgabe vom inBuffer
#endif
}
void readHoTTeam()
{
memset(inBuffer,9,sizeof(inBuffer)); //inBuffer leeren
HOTTSERIAL.setTimeout(250);
HOTTSERIAL.readBytes( inBuffer, eamAnswerLen); //Daten in inBuffer lesen
memcpy(&GPSData,&inBuffer, eamAnswerLen); //Daten in GPSData struct kopieren
#ifdef DEBUG
Serial.println("EAM MODUL ANTWORT");
Serial.write(inBuffer, eamAnswerLen); //Debugausgabe vom inBuffer
#endif
}
void readHoTTrx()
{
memset(inBuffer,9,sizeof(inBuffer)); //inBuffer leeren
HOTTSERIAL.setTimeout(250);
HOTTSERIAL.readBytes( inBuffer, rxAnswerLen); //Daten in inBuffer lesen
memcpy(&GPSData,&inBuffer, rxAnswerLen); //Daten in GPSData struct kopieren
#ifdef DEBUG
Serial.println("RX ANTWORT");
Serial.write(inBuffer, rxAnswerLen); //Debugausgabe vom inBuffer
#endif
}