diff options
-rw-r--r-- | utilities/data2kml/data2kml.cpp | 42 | ||||
-rw-r--r-- | utilities/data2kml/logdata.h | 6 |
2 files changed, 30 insertions, 18 deletions
diff --git a/utilities/data2kml/data2kml.cpp b/utilities/data2kml/data2kml.cpp index cbcded5..86c805d 100644 --- a/utilities/data2kml/data2kml.cpp +++ b/utilities/data2kml/data2kml.cpp @@ -11,7 +11,6 @@ #include <stdlib.h> #include <time.h> #include "logdata.h" -#include "kmlhead.h" typedef struct { uint32_t timestamp; @@ -53,13 +52,27 @@ void WriteKMLData(KML_DATA* kd, uint32_t timestamp, uint16_t pid, float value[]) { kd->ts = timestamp; switch (pid) { - case PID_GPS_COORDINATES: - kd->datas.lat = value[0]; - kd->datas.lon = value[1]; + case PID_GPS_LATITUDE: + kd->datas.lat = value[0] / 100000; if (!kd->startLat) { kd->startLat = kd->datas.lat; + } + if (kd->datacount > 0) { + float diff = kd->datas.lat - kd->dataset[kd->datacount - 1].lat; + if (diff > 0.1 || diff < -0.1) + kd->datas.lat = 0; + } + break; + case PID_GPS_LONGITUDE: + kd->datas.lon = value[0] / 100000; + if (!kd->startLon) { kd->startLon = kd->datas.lon; } + if (kd->datacount > 0) { + float diff = kd->datas.lon - kd->dataset[kd->datacount - 1].lon; + if (diff > 0.1 || diff < -0.1) + kd->datas.lon = 0; + } break; case PID_GPS_ALTITUDE: kd->datas.alt = (uint16_t)value[0]; @@ -93,13 +106,12 @@ void WriteKMLData(KML_DATA* kd, uint32_t timestamp, uint16_t pid, float value[]) kd->datas.acc[1] = (int16_t)value[1]; kd->datas.acc[2] = (int16_t)value[2]; break; - case PID_GPS_TIME: { - uint32_t date = (uint32_t)value[1]; - if (date > 10000 && (kd->curDate == 0 || (date % 100) <= (kd->curDate % 100) + 1)) { - kd->curDate = date; - kd->curTime = (uint32_t)value[0]; - } - } break; + case PID_GPS_DATE: + kd->curDate = (uint32_t)value[0]; + break; + case PID_GPS_TIME: + kd->curTime = (uint32_t)value[0]; + break; } if (kd->curTime != kd->lastTime && kd->datas.lat && kd->datas.lon) { fprintf(kd->fp, "<when>"); @@ -112,7 +124,7 @@ void WriteKMLData(KML_DATA* kd, uint32_t timestamp, uint16_t pid, float value[]) } if (kd->curTime) { - fprintf(kd->fp, "T%02u:%02u:%02u.%03uZ", kd->curTime / 10000000, (kd->curTime / 100000) % 100, (kd->curTime / 1000) % 100, kd->curTime % 1000); + fprintf(kd->fp, "T%02u:%02u:%02u.%03uZ", kd->curTime / 1000000, (kd->curTime / 10000) % 100, (kd->curTime / 100) % 100, (kd->curTime % 100) * 10); } fprintf(kd->fp, "</when>"); fprintf(kd->fp, "<gx:coord>%f %f %d</gx:coord>", kd->datas.lon, kd->datas.lat, kd->datas.alt); @@ -293,11 +305,11 @@ int ConvertToKML(const char* logfile, const char* kmlfile, uint32_t startpos, ui while (fscanf(fp, "%d,%X,", &elapsed, &pid) > 0) { char c; - char data[32]; + char data[64]; int i = 0; int index = 0; float value[3] = {0}; - while ((c = fgetc(fp)) != '\n') { + while ((c = fgetc(fp)) != '\r') { if (i == sizeof(data)) continue; data[i++] = c; if (c == ' ') { @@ -340,7 +352,7 @@ int main(int argc, const char* argv[]) int endpos = 0; char outfile[256]; - printf("Data2KML (C)2013 ArduinoDev.com Written by Stanley Huang\n\n"); + printf("Data2KML (C)2013-14 Written by Stanley Huang <http://freematics.com> \n\n"); if (argc <= 1) { printf("Usage: %s [Input file] [Output file] [Start Pos] [End Pos]\n\n", argv[0]); printf("Description about the arguments:\n\n\ diff --git a/utilities/data2kml/logdata.h b/utilities/data2kml/logdata.h index 46c1d39..499ad10 100644 --- a/utilities/data2kml/logdata.h +++ b/utilities/data2kml/logdata.h @@ -57,20 +57,20 @@ enum { PID_DEVICE_TEMP, }; -#define PID_GPS_COORDINATES 0xA +#define PID_GPS_LATITUDE 0xA +#define PID_GPS_LONGITUDE 0xB #define PID_GPS_ALTITUDE 0xC #define PID_GPS_SPEED 0xD #define PID_GPS_HEADING 0xE #define PID_GPS_SAT_COUNT 0xF #define PID_GPS_TIME 0x10 +#define PID_GPS_DATE 0x11 #define PID_ACC 0x20 #define PID_GYRO 0x21 #define PID_VIDEO_FRAME 0xFF00 -#define HEADER_ID ('S' << 24 | 'U' << 16 | 'D' << 8 | 'U') - typedef struct { uint32_t time; uint16_t pid; |