Parsing datapoints
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
*.out
|
||||||
|
*.swp
|
||||||
|
|
||||||
BIN
.igc.c.swp
BIN
.igc.c.swp
Binary file not shown.
37
igc.c
37
igc.c
@@ -15,20 +15,14 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "igc.h"
|
#include "igc.h"
|
||||||
|
|
||||||
void parse_igc_file(FILE* fp)
|
struct IGC_DataPoint* parse_datapoint(char* line)
|
||||||
{
|
{
|
||||||
size_t len = 0;
|
// There probably exists a better and/or prettier way
|
||||||
char* line = NULL;
|
|
||||||
|
|
||||||
while (getline(&line, &len, fp) != -1)
|
|
||||||
{
|
|
||||||
switch(line[0])
|
|
||||||
{
|
|
||||||
case DATAPOINT:
|
|
||||||
struct IGC_DataPoint* dp = (struct IGC_DataPoint*)malloc(sizeof(struct IGC_DataPoint));
|
struct IGC_DataPoint* dp = (struct IGC_DataPoint*)malloc(sizeof(struct IGC_DataPoint));
|
||||||
char hour[3], min[3], sec[3] = {0};
|
char hour[3], min[3], sec[3] = {0};
|
||||||
char lat_d[3], lat_m[3], lat_s[4] = {0};
|
char lat_d[3], lat_m[3], lat_s[4] = {0};
|
||||||
char lon_d[4], lon_m[3], lon_s[4] = {0};
|
char lon_d[4], lon_m[3], lon_s[4] = {0};
|
||||||
|
char baro_alt[6], gps_alt[6] = {0};
|
||||||
|
|
||||||
memcpy(hour, line+1, 2);
|
memcpy(hour, line+1, 2);
|
||||||
memcpy(min, line+3, 2);
|
memcpy(min, line+3, 2);
|
||||||
@@ -39,6 +33,8 @@ void parse_igc_file(FILE* fp)
|
|||||||
memcpy(lon_d, line+15, 3);
|
memcpy(lon_d, line+15, 3);
|
||||||
memcpy(lon_m, line+18, 2);
|
memcpy(lon_m, line+18, 2);
|
||||||
memcpy(lon_s, line+20, 3);
|
memcpy(lon_s, line+20, 3);
|
||||||
|
memcpy(baro_alt, line+25, 5);
|
||||||
|
memcpy(gps_alt, line+30, 5);
|
||||||
|
|
||||||
dp->hour = atoi(hour);
|
dp->hour = atoi(hour);
|
||||||
dp->minute = atoi(min);
|
dp->minute = atoi(min);
|
||||||
@@ -51,12 +47,27 @@ void parse_igc_file(FILE* fp)
|
|||||||
dp->lon.min = atoi(lon_m);
|
dp->lon.min = atoi(lon_m);
|
||||||
dp->lon.sec = atoi(lon_s);
|
dp->lon.sec = atoi(lon_s);
|
||||||
dp->lon.cardinal = line[23] == EAST ? EAST : WEST;
|
dp->lon.cardinal = line[23] == EAST ? EAST : WEST;
|
||||||
|
dp->baro_alt = atoi(baro_alt);
|
||||||
|
dp->gps_alt = atoi(gps_alt);
|
||||||
|
|
||||||
printf("%s", line);
|
printf("Data point: %d:%d:%d | %d°%d'%d\"%c %d°%d'%d\"%c | Baro: %dm GPS: %dm\n", dp->hour, dp->minute, dp->second, dp->lat.deg, dp->lat.min, dp->lat.sec, dp->lat.cardinal, dp->lon.deg, dp->lon.min, dp->lon.sec, dp->lon.cardinal, dp->baro_alt, dp->gps_alt);
|
||||||
printf("Data point: %d:%d:%d | %d°%d'%d\"%c %d°%d'%d\"%c\n", dp->hour, dp->minute, dp->second, dp->lat.deg, dp->lat.min, dp->lat.sec, dp->lat.cardinal, dp->lon.deg, dp->lon.min, dp->lon.sec, dp->lon.cardinal);
|
|
||||||
|
|
||||||
// Debug
|
return dp;
|
||||||
exit(0);
|
}
|
||||||
|
|
||||||
|
void parse_igc_file(FILE* fp)
|
||||||
|
{
|
||||||
|
size_t len = 0;
|
||||||
|
char* line = NULL;
|
||||||
|
|
||||||
|
while (getline(&line, &len, fp) != -1)
|
||||||
|
{
|
||||||
|
switch(line[0])
|
||||||
|
{
|
||||||
|
case DATAPOINT:
|
||||||
|
struct IGC_DataPoint* dp = parse_datapoint(line);
|
||||||
|
// Doubly linked list of points (so theyre joined in chronological order; opens possibilities for analysis later)
|
||||||
|
// append_datapoint(dp);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user