-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Realtime export of payload data in KML format. #2
Open
fab4space
wants to merge
1
commit into
PiInTheSky:master
Choose a base branch
from
fab4space:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* RealTime KML export of the payload data */ | ||
/* Based on https://ukhas.org.uk/using_google_earth */ | ||
|
||
#include <unistd.h> // UNIX standard function definitions | ||
#include <stdio.h> // Standard input/output definitions | ||
#include <string.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
|
||
#include "kml.h" | ||
#include "global.h" | ||
|
||
#define KML_LINE_SIZE 256 //Maximum size of a kml line | ||
|
||
/* KML file footer */ | ||
const char footer_str[] = | ||
" </coordinates>\n" \ | ||
" </LineString>\n" \ | ||
" </Placemark>\n" \ | ||
" </Document>\n" \ | ||
"</kml>\n"; | ||
|
||
/* Write the header of the KML file for the specified payload */ | ||
void writeHeader(FILE* fp, char * payload) { | ||
fprintf(fp,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); | ||
fprintf(fp," <kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\" " ); | ||
fprintf(fp," xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n"); | ||
fprintf(fp," <Document>\n <name>%s</name>\n", payload); | ||
fprintf(fp," <open>1</open>\n"); | ||
fprintf(fp," <Placemark>\n"); | ||
fprintf(fp," <name>%s-track</name>\n", payload); | ||
fprintf(fp," <LineString>\n"); | ||
fprintf(fp," <extrude>1</extrude>\n"); | ||
fprintf(fp," <tessellate>1</tessellate>\n"); | ||
fprintf(fp," <altitudeMode>absolute</altitudeMode>\n"); | ||
fprintf(fp," <coordinates>\n"); | ||
|
||
} | ||
|
||
/* Write the footer of the KML file */ | ||
void writeFooter(FILE* fp) { | ||
fprintf(fp,"%s", footer_str); | ||
} | ||
|
||
/* Write the KML for refreshing the track of the specified payload */ | ||
void writeRefreshKML(FILE* fp, char * payload) { | ||
fprintf(fp,"<kml xmlns=\"http://earth.google.com/kml/2.0\">\n"); | ||
fprintf(fp," <Document>\n"); | ||
fprintf(fp," <NetworkLink>\n"); | ||
fprintf(fp," <name>%s</name>\n", payload); | ||
fprintf(fp," <Url>\n"); | ||
fprintf(fp," <href>%s.kml</href>\n", payload); | ||
fprintf(fp," <refreshMode>onInterval</refreshMode>\n"); | ||
fprintf(fp," <refreshInterval>5</refreshInterval>\n"); | ||
fprintf(fp," </Url>\n"); | ||
fprintf(fp," </NetworkLink>\n"); | ||
fprintf(fp," </Document>\n"); | ||
fprintf(fp,"</kml>\n"); | ||
} | ||
|
||
/* Update the KML file of the payload with the specified data */ | ||
void UpdatePayloadKML(char * payload, unsigned int seconds, double latitude, double longitude, unsigned int altitude) { | ||
FILE * fp; | ||
char filename[256]; | ||
char line[KML_LINE_SIZE]; | ||
struct stat st; | ||
int res; | ||
|
||
/* Discard empty positions */ | ||
if (latitude == 0.0 && longitude == 0.0) | ||
return; | ||
/* Path to the KML file for this payload */ | ||
sprintf(filename, "%s.kml", payload); | ||
|
||
/* Check if the KML exists already */ | ||
res = stat(filename, &st); | ||
|
||
/* Prepare the KML line for the payload data */ | ||
snprintf(line, KML_LINE_SIZE, " %f,%f,%d\n", | ||
longitude, latitude, altitude); | ||
|
||
/* If the KML doesn't exists */ | ||
if (res < 0) { | ||
/* Create a KML file which will refresh the payload KML at regular interval */ | ||
char filename_refresh[256]; | ||
FILE * fp_refresh; | ||
sprintf(filename_refresh, "%s-refresh.kml", payload); | ||
fp_refresh = fopen(filename_refresh, "w"); | ||
if (fp_refresh) { | ||
writeRefreshKML(fp_refresh,payload); | ||
fclose(fp_refresh); | ||
} else { | ||
LogMessage("Can't open %s file for writing\n", filename_refresh); | ||
} | ||
/* Create the KML file for the payload */ | ||
|
||
fp = fopen(filename, "a"); | ||
if (!fp) { | ||
LogMessage("Can't open %s file for writing\n", filename); | ||
return; | ||
} else { | ||
LogMessage("Created %s file\n", filename); | ||
} | ||
/* Add the header, new data line and footer */ | ||
writeHeader(fp, payload); | ||
fwrite(line, 1, strlen(line), fp); | ||
writeFooter(fp); | ||
|
||
} else { | ||
/* KML already exists : update only the file with new data */ | ||
fp = fopen(filename, "r+"); | ||
if (!fp) { | ||
LogMessage("Can't open %s file for writing\n", filename); | ||
return; | ||
} | ||
/* Write new data just before the position of the footer in the KML */ | ||
fseek(fp, -strlen(footer_str), SEEK_END); | ||
fwrite(line, 1, strlen(line), fp); | ||
writeFooter(fp); | ||
|
||
} | ||
fclose(fp); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* RealTime KML export of the payload data */ | ||
/* Based on https://ukhas.org.uk/using_google_earth */ | ||
|
||
void UpdatePayloadKML(char * payload, unsigned int seconds, double latitude, double longitude, unsigned int altitude); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
gateway: gateway.o urlencode.o base64.o ssdv.o ssdv.h global.h | ||
cc -o gateway gateway.o urlencode.o base64.o ssdv.o -lm -lwiringPi -lwiringPiDev -lcurl -lncurses -lpthread | ||
|
||
gateway.o: gateway.c global.h | ||
gcc -c gateway.c | ||
|
||
ssdv.o: ssdv.c ssdv.h global.h | ||
gcc -c ssdv.c | ||
|
||
urlencode.o: urlencode.c | ||
gcc -c urlencode.c | ||
|
||
base64.o: base64.c | ||
gcc -c base64.c | ||
|
||
gateway: gateway.o urlencode.o base64.o ssdv.o ssdv.h kml.o global.h | ||
cc -o gateway gateway.o urlencode.o base64.o ssdv.o kml.o -lm -lwiringPi -lwiringPiDev -lcurl -lncurses -lpthread | ||
|
||
gateway.o: gateway.c global.h | ||
gcc -c gateway.c | ||
|
||
ssdv.o: ssdv.c ssdv.h global.h | ||
gcc -c ssdv.c | ||
|
||
urlencode.o: urlencode.c | ||
gcc -c urlencode.c | ||
|
||
base64.o: base64.c | ||
gcc -c base64.c | ||
|
||
kml.o: kml.c kml.h global.h | ||
gcc -c kml.c | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don`t make this a boolean. I would like to add different log levels, to record full telemetry and/or KML and/or RSSI / frequency offset etc. Perhaps change the name to "LogLevel" and use a bitmask. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This configuration entry is only for enabling KML output (like Habitat output which is a boolean too), and in this current changeset the data which is exported in the kml is not configurable (lat,lon and altitude). When new features for kml export will be implemented I suggest that we add configuration variable for these features, but since we don't know what may be supported in the future I suggest that we don't add configuration entries which are not supported. It would be nice to implement logging with the features you mentioned but this is out of scope of this kml feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that an EnableKML bolean seems consistent with the other features and perhaps LogTelemetry/LogKML/LogRSSI boleans if/when the ability to log these values is added in future?