list track.c
#include
#include
#include
#include
#include
#include
#include
#define PIT 0xC01000
#define PCDDR 0x08
#define PCDR 0x18
#define TRUE -1
#define FALSE 0
#define SPACE 0x20
#define R0 6378.16
#define F 1.0/298.16
#define G0 75369793000000.0
#define G1 1.0027379093
#define C 299792.5
#define fnarcsin(x) (atan(x/sqrt(1.0-x*x)))
#define fndegrees(x) (x/PI*180.0)
#define fnradians(x) (x/180.0*PI)
#define fngmst(x) ((99.6367-0.2387*(x-1989)+0.9856*(int)((x-1989)/4.0))/360.0)
double SinGSLat, CosGSLat;
double SinGSLong, CosGSLong;
double GSxcoord, GSycoord, GSzcoord;
time_t tzcor;
typedef struct sat_struct {
char Name[80];
int EpochYear;
double EpochJulianDay;
double Inclination;
double RAAN;
double Eccentricity;
double ArgOfPerigee;
double MA;
double MeanMotion;
int Revolution;
int clkcor;
double freq[3];
} SAT;
SAT sat[40];
char exitstr[] = "EXIT";
char allstr[] = "ALL";
int numsat;
double PI2;
double a0;
double E1;
double cc11, cc12, cc21, cc22, cc31, cc32;
double MARadians;
int phase;
double t, oldt;
double range, oldrange;
double elevation, azimuth, longitude, latitude;
extern double atan2();
extern char kbhit();
double doppler();
int Menu()
{
char *keybuf, *t;
int option;
int i;
time_t *tim;
keybuf = (char *)malloc(80);
do {
clear();
option = -1;
/* time(tim); */
printf("*** PE1JPD - SATELLITE TRACKING PROGRAM ***\n");
printf("*** The following satellites are available : ***\n\n");
for (i=0; i=numsat) {
printf("\n");
break;
}
printf("%-20s", sat[i].Name);
i++;
if (i>=numsat) {
printf("\n");
break;
}
printf("%-20s\n", sat[i].Name);
}
printf("\nedit : Edit satellite data (not implemented yet)\n");
printf("ground : Edit ground station parameters (not implemented yet)\n");
printf("all : Show all satellites - elevation & azimuth\n");
printf("exit\n\n");
printf("Enter satellite or command : ");
scanf("%s", keybuf);
t = keybuf;
while (*t) {
*t++ = toupper(*t);
}
if (!strcmp(keybuf, exitstr))
option = 0;
else if (!strcmp(keybuf, allstr)) {
option = 44;
}
else for (i=0; i16);
}
void ShowAllSats()
{
int option;
struct tm *tmptr;
time_t tztime;
int i;
char flag;
clear();
printf("*** PE1JPD - SHOW ALL SATELLITES - ELEVATION & AZIMUTH ***\n\n\n\n");
printf(" Satellite EL AZ Satellite EL AZ\n");
printf("------------------------------ ------------------------------\n");
for (;;) {
home();
tztime = time(0) + tzcor;
tmptr = localtime(&tztime);
printf("\n\n%02d:%02d:%02d (UTC)\n\n\n\n", tmptr->tm_hour, tmptr->tm_min, tmptr->tm_sec);
for (i=0; itm_yday + 1.0 +
tmptr->tm_hour/24.0 +
tmptr->tm_min/1440.0 +
tmptr->tm_sec/86400.0;
if (sat[i].EpochYear == tmptr->tm_year-1) {
t = t + 365.0;
if (sat[i].EpochYear%4 == 0) {
t = t + 1.0;
}
}
CalcSatPosition(i);
Transform(i);
if (elevation>=0) flag = '*';
printf("%c %-14s %5.1f %5.1f", flag, sat[i].Name, azimuth, elevation);
if (i%2) {
putchar(0x0d);
}
else printf("%11c", ' ');
if (kbhit()) {
return;
}
}
sleep(1);
}
}
void TrackSat(i)
int i;
{
int option;
struct tm *tmptr;
time_t tztime;
double df, dopfreq, olddop = 0;
unsigned char *pit = 0xc01000;
char c;
clear();
*(pit+PCDDR) = 0x03;
*(pit+PCDR) = 0x00;
printf("*** PE1JPD - SATELLITE TRACKING ***\n\n\n\n");
printf("Name Azimuth Elevation Range Frequency Dopplershift\n");
printf("-------------------------------------------------------------------------------\n");
for (;;) {
home();
tztime = time(0) + tzcor;
tmptr = localtime(&tztime);
/* tm_yday 0..365, add 1 for daynumber */
t = tmptr->tm_yday + 1.0 +
tmptr->tm_hour/24.0 +
tmptr->tm_min/1440.0 +
tmptr->tm_sec/86400.0;
if (sat[i].EpochYear == tmptr->tm_year-1) {
t = t + 365.0;
if (sat[i].EpochYear%4 == 0) {
t = t + 1.0;
}
}
CalcSatPosition(i);
Transform(i);
if (oldt!=t) {
dopfreq = -sat[i].freq[0]*((range-oldrange)/(t-oldt))/(86400.0*C);
oldrange = range;
oldt = t;
}
printf("\n\n%02d:%02d:%02d (UTC)\n\n\n\n", tmptr->tm_hour, tmptr->tm_min, tmptr->tm_sec);
printf("%-20s%3.0f %3.0f %5.0f %3.4f %3.4lf \n",
sat[i].Name, azimuth, elevation,
range, sat[i].freq[0], dopfreq);
#define UP 0x02
#define DOWN 0x01
df = dopfreq - olddop;
if (df<-0.1) {
*(pit+PCDR) = DOWN;
tsleep(5);
*(pit+PCDR) = 0;
tsleep(5);
olddop = dopfreq;
}
else if (df>0.1) {
*(pit+PCDR) = UP;
tsleep(5);
*(pit+PCDR) = 0;
tsleep(5);
olddop = dopfreq;
}
if (c=kbhit()) {
return;
}
sleep(1);
}
}
CalcSatPosition(i)
int i;
{
double e2, S0, C0, S1, C1, S2, C2, K2, RA, AOP;
double OrbitPos;
int Orbit;
a0 = pow(G0/(sat[i].MeanMotion*sat[i].MeanMotion),1.0/3.0);
e2 = 1.0-sat[i].Eccentricity*sat[i].Eccentricity;
E1 = sqrt(e2);
K2 = 9.95*(pow(R0/a0, 3.5)/(e2*e2));
S1 = sin(fnradians(sat[i].Inclination));
C1 = cos(fnradians(sat[i].Inclination));
RA = sat[i].RAAN-(t-sat[i].EpochJulianDay)*K2*C1;
S0 = sin(fnradians(RA));
C0 = cos(fnradians(RA));
AOP = sat[i].ArgOfPerigee+(t-sat[i].EpochJulianDay)*K2*(2.5*(C1*C1)-0.5);
S2 = sin(fnradians(AOP));
C2 = cos(fnradians(AOP));
cc11 = (C2*C0)-(S2*S0*C1);
cc12 = -(S2*C0)-(C2*S0*C1);
cc21 = (C2*S0)+(S2*C0*C1);
cc22 = -(S2*S0)+(C2*C0*C1);
cc31 = (S2*S1);
cc32 = (C2*S1);
OrbitPos = sat[i].MA/360.0+sat[i].Revolution+sat[i].MeanMotion*(t-sat[i].EpochJulianDay);
Orbit = (int)OrbitPos;
phase = (int)((OrbitPos-Orbit)*256.0);
MARadians = (OrbitPos-Orbit)*PI2;
}
Transform(i)
int i;
{
double E, S3, C3, R3, M1, M5, X0, Y0, X1, Y1, Z1, G7, S7, C7;
double x, y, z, X5, Y5, Z5, x8, y8, z8, r;
E = MARadians+sat[i].Eccentricity*sin(MARadians)+0.5*(sat[i].Eccentricity*sat[i].Eccentricity)*sin(2.0*MARadians);
for (;;) {
S3 = sin(E);
C3 = cos(E);
R3 = 1.0-sat[i].Eccentricity*C3;
M1 = E-sat[i].Eccentricity*S3;
M5 = M1-MARadians;
if (fabs(M5)<0.000001) {
break;
}
E = E-M5/R3;
}
X0 = a0*(C3-sat[i].Eccentricity);
Y0 = a0*E1*S3;
r = a0*R3;
X1 = X0*cc11+Y0*cc12;
Y1 = X0*cc21+Y0*cc22;
Z1 = X0*cc31+Y0*cc32;
G7 = t*G1+fngmst((double)(1900+sat[i].EpochYear));
G7 = (G7-(int)G7)*PI2;
S7 = -sin(G7);
C7 = cos(G7);
x = (X1*C7)-(Y1*S7);
y = (X1*S7)+(Y1*C7);
z = Z1;
X5 = (x-GSxcoord);
Y5 = (y-GSycoord);
Z5 = (z-GSzcoord);
range = sqrt(X5*X5+Y5*Y5+Z5*Z5);
z8 = (X5*CosGSLong*CosGSLat)+(Y5*SinGSLong*CosGSLat)+(Z5*SinGSLat);
x8 = -(X5*CosGSLong*SinGSLat)-(Y5*SinGSLong*SinGSLat)+(Z5*CosGSLat);
y8 = (Y5*CosGSLong)-(X5*SinGSLong);
elevation = fndegrees(fnarcsin(z8/range));
azimuth = fndegrees(atan2(y8,x8));
longitude = 360.0-fndegrees(atan2(y,x));
latitude = fndegrees(fnarcsin(z/r));
}
SetUpConstants()
{
double L8, R9;
double gslat, gslong, gsheight;
PI2 = 2.0 * PI;
gslat = 52.0;
gslong = 355.0;
gsheight = 0.0;
/* tzcor = -3600; wintertijd */
tzcor = -7200; /* zomertijd */
SinGSLat = sin(fnradians(gslat));
CosGSLat = cos(fnradians(gslat));
SinGSLong = sin(fnradians(-gslong));
CosGSLong = cos(fnradians(-gslong));
R9 = R0*(1.0 - F/2.0 + (F/2) * cos(2.0 * fnradians(gslat))) + gsheight / 1000.0;
L8 = atan((1.0-F)*(1.0-F)*SinGSLat/CosGSLat);
GSzcoord = R9 * sin(L8);
GSxcoord = R9 * cos(L8) * CosGSLong;
GSycoord = R9 * cos(L8) * SinGSLong;
}
main()
{
int option;
int quit = FALSE;
numsat = ReadSatData();
SetUpConstants();
do {
option = Menu();
switch(option) {
case 0:
quit = TRUE;
break;
case 41:
putchar(0x0d);
printf("Edit satellite number : ");
scanf("%d", &option);
EditElements(option-1);
break;
case 42:
break;
case 44:
ShowAllSats();
break;
default:
if (option<=numsat) {
TrackSat(option-1);
}
break;
}
} while (!quit);
printf("\n\n\n");
}
(68020) Super: