Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/sgpsdp/sgp4sdp4.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ void ClearFlag(int flag);
/* sgp_in.c */
int Checksum_Good(char *tle_set);
int Good_Elements(char *tle_set);
int Convert_Sat_Catnr(const char *catstr);
void Convert_Satellite_Data(char *tle_set, tle_t * tle);
int Get_Next_Tle_Set(char lines[3][80], tle_t * tle);
void select_ephemeris(sat_t * sat);
Expand Down
37 changes: 36 additions & 1 deletion src/sgpsdp/sgp_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,41 @@ int Good_Elements(char *tle_set)
return (1);
}

/* Decode a 5-character NORAD catalog field.
All-digit fields (leading spaces allowed) keep the historic
atoi() behavior. IDs >= 100000 use Alpha-5; I and O are
skipped as first characters so they are not confused with 1 and 0. */
int Convert_Sat_Catnr(const char *catstr)
{
char first;
int base, i;

if (catstr == NULL)
return 0;

first = catstr[0];
if (g_ascii_isdigit(first) || (first == ' '))
return atoi(catstr);

first = g_ascii_toupper(first);
if ((first >= 'A') && (first <= 'H'))
base = 10 + (first - 'A');
else if ((first >= 'J') && (first <= 'N'))
base = 18 + (first - 'J');
else if ((first >= 'P') && (first <= 'Z'))
base = 23 + (first - 'P');
else
return 0;

for (i = 1; i < 5; i++)
{
if (!g_ascii_isdigit(catstr[i]))
return 0;
}

return (base * 10000 + atoi(&catstr[1]));
}

/* Converts the strings in a raw two-line element set */
/* to their intended numerical values. No processing */
/* of these values is done, e.g. from deg to rads etc. */
Expand All @@ -157,7 +192,7 @@ void Convert_Satellite_Data(char *tle_set, tle_t * tle)
/* Satellite's catalogue number */
strncpy(buff, &tle_set[2], 5);
buff[5] = '\0';
tle->catnr = atoi(buff);
tle->catnr = Convert_Sat_Catnr(buff);

/* International Designator for satellite */
strncpy(tle->idesg, &tle_set[9], 8);
Expand Down
36 changes: 36 additions & 0 deletions src/sgpsdp/test-001.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,42 @@ int main(void)
}
}

/* Alpha-5 catalog numbers (IDs >= 100000). */
{
char a5_str[3][80];
tle_t a5_tle;

if (Convert_Sat_Catnr("25544") != 25544)
{
printf("Convert_Sat_Catnr(25544) returned %d\n",
Convert_Sat_Catnr("25544"));
return 1;
}
if (Convert_Sat_Catnr("a1286") != 101286)
{
printf("Convert_Sat_Catnr(a1286) returned %d (expected 101286)\n",
Convert_Sat_Catnr("a1286"));
return 1;
}

strcpy(a5_str[0], "OBJECT A1286");
strcpy(a5_str[1],
"1 A1286U 26249D 26310.97532605 .00001678 00000-0 14252-3 0 9998");
strcpy(a5_str[2],
"2 A1286 45.2801 232.2047 0090652 210.3603 149.2004 14.99515474 207");
if (Get_Next_Tle_Set(a5_str, &a5_tle) != 1)
{
printf("Get_Next_Tle_Set() rejected an Alpha-5 catalog TLE\n");
return 1;
}
if (a5_tle.catnr != 101286)
{
printf("Alpha-5 catalog A1286 read as %d (expected 101286)\n",
a5_tle.catnr);
return 1;
}
}

select_ephemeris(&sat);

printf("\nDEEP_SPACE_EPHEM: %d (expected 0)\n\n",
Expand Down
2 changes: 1 addition & 1 deletion src/tle-update.c
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ static gint read_fresh_tle(const gchar * dir, const gchar * fnam,
catstr[i - 2] = tle_str[1][i];
}
catstr[5] = '\0';
catnr = (guint) g_ascii_strtod(catstr, NULL);
catnr = (guint) Convert_Sat_Catnr(catstr);


if (Get_Next_Tle_Set(tle_str, &tle) != 1)
Expand Down
Loading