#include "satpos_tle.hpp"
#include "satpos_func.hpp"
#include <iostream>
#include <cstdlib>
#include <cstring>
/*###########################################################
Funktionsname: satpos::tle_data::tle_data
Übergabewerte: keine
Rückgabewerte: keine
Erstellungsdatum: 29.10.2011
Letzte Änderung: 29.10.2011
Programmierer: pointhi
Beschreibung: Diese Funktion initialisiert die TLE Variablen der Klasse satpos::tle_data
###########################################################*/
satpos::tle_data::tle_data() {
tle_satname[0] = '\0'; // Name des Sateliten
tle_nr = 0; // NORAD-Katalog-Nr. ü
tle_klass = '\0'; // Klassifizierung ü
tle_intklass[0] = '\0'; // Internationale Klassifizierung ü
tle_intklass[8] = '\0'; // Internationale Klassifizierung ü
tle_epoche = 0; // Epoche mit Jahr & Tag_Nr. , Tagesbruchteil ü
tle_widspg = 0; // Widerstandskoeffizient im SGP-Modell
tle_vwidspg = 0; // vernachlässigbarer Widerstandskoeffizient im SGP-Modell
tle_widspg4 = 0; // Widerstandskoeffizient im SGP4-Modell
tle_eph = 0; // Ephemeridentyp ü
tle_dnr = 0; // laufende Datensatz-Nummer
tle_prfs1 = 0; // Prüfsumme Modulo 10 ü
tle_prfs2 = 0; // Prüfsumme Modulo 10
tle_ink = 0; // Inklination
tle_rek = 0; // Rektaszension des aufsteigenden Knotens ?
tle_exz = 0; // numerische Exzentrizität der Umlaufbahn
tle_per = 0; // Argument des Perigäums ?
tle_mano = 0; // Mittlere Anomalie ?
tle_mbew = 0; // Mittlere Bewegung n
tle_ulnr = 0; // Umlauf Nr. seit dem Start
}
/*###########################################################
Funktionsname: satpos::tle::load
Übergabewerte: satpos::tle_data *twrite
char tle_input[]
Rückgabewerte: 0 ... Erfolg
1 ... Es wurde kein TLE-Datensatz gefunden
>1 ... Fehler
Erstellungsdatum: 29.10.2011
Letzte Änderung: 29.10.2011
Programmierer: pointhi
Beschreibung: Diese Funktion beschreibt die Klasse satpos::tle_data
aus einer Char-Array im NORAD-Format (NASA-Format)
###########################################################*/
int satpos::tle::load(satpos::tle_data *tin_write, char tin_tlin[]) {
//tin_write->tle_epoche = 06040.85138889l;
int tin_pos = -1; // Aktuelle Position in der char-Array
int tin_x = 1; // Hilfsvariable für schleifen
int tin_lengh = 0;
char tin_shelp[20];
int tin_ihelp=0;
double tin_dhelp=0;
tin_lengh = std::strcspn( tin_tlin, "\0" );
// suchen des Datensatzes
while(tin_x)
{
tin_pos = std::strcspn( tin_tlin, "1");
if(tin_pos==-1 || tin_pos > tin_lengh-138){return 1;} // Gibt einen Fehler zurück wenn kein gültiger TLE-Datensatz gefunden wurde
else if(tin_tlin[tin_pos+1]==32 && tin_tlin[tin_pos+8]==32 && tin_tlin[tin_pos+16]==32 && tin_tlin[tin_pos+69]=='\n' && tin_tlin[tin_pos+70]=='2' && tin_tlin[tin_pos+71]==32){tin_x = 0;}
}
// NORAD-Katalog-Nr.
tin_shelp = {(tin_tlin[tin_pos + 2]),(tin_tlin[tin_pos + 3]),(tin_tlin[tin_pos + 4]),(tin_tlin[tin_pos + 5]),(tin_tlin[tin_pos + 6]), '\0'};
tin_write->tle_nr = std::atoi(tin_shelp);
// Klassifizierung
tin_write->tle_klass = tin_tlin[tin_pos + 7];
// Internationale Klassifizierung
tin_write->tle_intklass[0] = tin_tlin[tin_pos + 9];
tin_write->tle_intklass[1] = tin_tlin[tin_pos + 10];
tin_write->tle_intklass[2] = tin_tlin[tin_pos + 11];
tin_write->tle_intklass[3] = tin_tlin[tin_pos + 12];
tin_write->tle_intklass[4] = tin_tlin[tin_pos + 13];
tin_write->tle_intklass[5] = tin_tlin[tin_pos + 14];
tin_write->tle_intklass[6] = tin_tlin[tin_pos + 15];
tin_write->tle_intklass[7] = tin_tlin[tin_pos + 16];
tin_write->tle_intklass[7] = '\0';
// Epoche
satpos::func::strtls(tin_tlin, tin_shelp, (tin_pos + 18), 13);
tin_write->tle_epoche = std::atof(tin_shelp);
// Widerstandskoeffizient im SGP-Modell
satpos::func::strtls(tin_tlin, tin_shelp, (tin_pos + 33), 9);
tin_write->tle_widspg = std::atof(tin_shelp);
// vernachlässigbarer Widerstandskoeffizient im SGP-Modell
satpos::func::strtls(tin_tlin, tin_shelp, (tin_pos + 44), 7);
tin_ihelp = ((char)tin_tlin[tin_pos + 51])-48;
tin_dhelp = 1;for(;tin_ihelp >0;tin_ihelp --){tin_dhelp *= 0.1;}
tin_write->tle_vwidspg = std::atof(tin_shelp) * tin_dhelp;
// Widerstandskoeffizient im SGP4-Modell
satpos::func::strtls(tin_tlin, tin_shelp, (tin_pos + 52), 6);
tin_shelp[0] = tin_shelp[1];tin_shelp[1] = '.';
tin_ihelp = ((char)tin_tlin[tin_pos + 60])-48;
tin_dhelp = 1;for(;tin_ihelp >0;tin_ihelp --){tin_dhelp *= 0.1;}
tin_write->tle_widspg4 = std::atof(tin_shelp) * tin_dhelp;
// Ephemeridentyp
tin_write->tle_eph = ((char)tin_tlin[tin_pos + 62])-48;
// Laufende Datensatznummer
satpos::func::strtls(tin_tlin, tin_shelp, (tin_pos + 64), 3);
tin_write->tle_dnr = std::atoi(tin_shelp);
// Prüfsumme1 Modulo 10
tin_write->tle_prfs1 = ((char)tin_tlin[tin_pos + 68])-48;
// Inklination
satpos::func::strtls(tin_tlin, tin_shelp, (tin_pos + 78), 7);
tin_write->tle_ink = std::atof(tin_shelp);
// Rektaszension
satpos::func::strtls(tin_tlin, tin_shelp, (tin_pos + 87), 7);
tin_write->tle_rek = std::atof(tin_shelp);
// Exzentritität
satpos::func::strtls(tin_tlin, tin_shelp, (tin_pos + 95), 7);
tin_shelp[0] = '.';
tin_write->tle_exz = std::atof(tin_shelp);
// Argument des Perigäums
satpos::func::strtls(tin_tlin, tin_shelp, (tin_pos + 104), 7);
tin_write->tle_per = std::atof(tin_shelp);
// Mittlere Anomalie
satpos::func::strtls(tin_tlin, tin_shelp, (tin_pos + 113), 7);
tin_write->tle_mano = std::atof(tin_shelp);
// Mittlere Bewegung
satpos::func::strtls(tin_tlin, tin_shelp, (tin_pos + 122), 10);
tin_write->tle_mbew = std::atof(tin_shelp);
// Mittlere Bewegung
satpos::func::strtls(tin_tlin, tin_shelp, (tin_pos + 133), 4);
tin_write->tle_ulnr = std::atof(tin_shelp);
// Prüfsumme2 Modulo 10
tin_write->tle_prfs2 = ((char)tin_tlin[tin_pos + 138])-48;
std::cout << "\ntin_pos: " << tin_pos;
std::cout << "\ntin_lengh: " << tin_lengh;tin_write->tle_prfs1 = ((char)tin_tlin[tin_pos + 68])-48; // Prüfsumme1 Modulo 10
return 0;
}
/*###########################################################
Funktionsname: satpos::tle::out
Übergabewerte: satpos::tle_data *tout
Rückgabewerte: 0 ... Erfolg
Erstellungsdatum: 29.10.2011
Letzte Änderung: 29.10.2011
Programmierer: pointhi
Beschreibung: Diese Funktion gibt die TLE-Daten der Klasse satpos::tle_data formatiert aus.
###########################################################*/
int satpos::tle::out(satpos::tle_data *tout_out) {
// Hier beginnt die Ausgabe der Werte:
std::cout << "\n-------------------------------------------------------------------\n";
std::cout << "\tTLE-Datensatz:\t" << tout_out->tle_satname << std::fixed;
std::cout << "\n-------------------------------------------------------------------\n";;
std::cout << "\nNORAD-Katalog-Nr.:\t\t\t" << tout_out->tle_nr;
std::cout << "\nKlassifizierung:\t\t\t" << tout_out->tle_klass;
std::cout << "\nInternationale Bezeichnung:\t\t" << tout_out->tle_intklass; std::cout.precision(8);
std::cout << "\nEpoche:\t\t\t\t\t" << tout_out->tle_epoche;
std::cout << "\nWiderstandskoeffizent SPG-Modell:\t" << tout_out->tle_widspg; std::cout.precision(9);
std::cout << "\nv. Widerstandskoeffizent SPG-Modell:\t" << tout_out->tle_vwidspg;
std::cout << "\nWiderstandskoeffizent SPG4-Modell:\t" << tout_out->tle_widspg4;
std::cout << "\nEphemeridentyp:\t\t\t\t" << tout_out->tle_eph;
std::cout << "\nLaufende Datensatz-Nr.:\t\t\t" << tout_out->tle_dnr; std::cout.precision(4);
std::cout << "\nInklination:\t\t\t\t" << tout_out->tle_ink;
std::cout << "\nRektaszension:\t\t\t\t" << tout_out->tle_rek; std::cout.precision(7);
std::cout << "\nExzentrizitaet:\t\t\t\t" << tout_out->tle_exz; std::cout.precision(4);
std::cout << "\nArgument des Perigaeums:\t\t" << tout_out->tle_per;
std::cout << "\nMittlere Anomalie:\t\t\t" << tout_out->tle_mano; std::cout.precision(8);
std::cout << "\nMittlere Bewegung:\t\t\t" << tout_out->tle_mbew;
std::cout << "\nUmlauf Nr. seit dem Start:\t\t" << tout_out->tle_ulnr;
std::cout << "\nPruefsumme1 Modulo 10:\t\t\t" << tout_out->tle_prfs1;
std::cout << "\nPruefsumme2 Modulo 10:\t\t\t" << tout_out->tle_prfs2;
std::cout << "\n-------------------------------------------------------------------" << std::endl;
return 0; // Melde Erfolg zurück
}