From 5782113fad7cbd4573e2217d63d542509025a20a Mon Sep 17 00:00:00 2001 From: Pawel Jalocha Date: Sun, 7 Mar 2021 15:47:28 +0000 Subject: [PATCH 1/2] Add header to the HTTP IGC files and the G-record (MD5) --- main/http.cpp | 37 +++++++++++++++++++++++++++++++++---- main/ogn1.h | 4 +--- main/sdlog.cpp | 2 +- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/main/http.cpp b/main/http.cpp index 54948ae..34f6f02 100644 --- a/main/http.cpp +++ b/main/http.cpp @@ -6,6 +6,8 @@ #include #include +#include "mbedtls/md5.h" + #include "hal.h" #include "esp_http_server.h" @@ -695,12 +697,26 @@ static int LogFileName(char *Name, time_t Time, const char *Ext=0) // send give log file in the IGC format static esp_err_t SendLog_IGC(httpd_req_t *Req, const char *FileName, uint32_t FileTime) { char ContDisp[64]; + mbedtls_md5_context MD5; + mbedtls_md5_starts_ret(&MD5); char Line[1000]; int Len=0; Len=Format_String(ContDisp, "attachement; filename=\""); Len+=LogFileName(ContDisp+Len, FileTime, ".IGC"); ContDisp[Len++]='\"'; ContDisp[Len]=0; httpd_resp_set_hdr(Req, "Content-Disposition", ContDisp); httpd_resp_set_type(Req, "text/plain"); FILE *File = fopen(FileName, "rb"); if(File==0) { httpd_resp_send_chunk(Req, 0, 0); return ESP_OK; } - // here we should write the IGC header + Len=Format_String(Line, "AGNE001Tracker\nHFFXA020\n"); // IGC file header + Len+=Format_String(Line+Len, "HFDTEDate:"); + GPS_Time Time; Time.setUnixTime(FileTime); + Len+=Format_UnsDec(Line+Len, (uint16_t)Time.Day , 2); + Len+=Format_UnsDec(Line+Len, (uint16_t)Time.Month, 2); + Len+=Format_UnsDec(Line+Len, (uint16_t)Time.Year , 2); + Line[Len++]='\n'; + if(Parameters.Pilot[0]) + { Len+=Format_String(Line+Len, "HFPLTPilotincharge:"); + Len+=Format_String(Line+Len, Parameters.Pilot); + Line[Len++]='\n'; } + httpd_resp_send_chunk(Req, Line, Len); + mbedtls_md5_update_ret(&MD5, (uint8_t *)Line, Len); OGN_LogPacket Packet; Len=0; for( ; ; ) @@ -713,10 +729,23 @@ static esp_err_t SendLog_IGC(httpd_req_t *Req, const char *FileName, uint32_t Fi bool Own = Packet.Packet.Header.Address==Parameters.Address && Packet.Packet.Header.AddrType==Parameters.AddrType; // if(Own && !Packet.Packet.Header.NonPos && !Packet.Packet.Header.Encrypted) Len+=APRS2IGC(Line+Len, APRS, GPS_GeoidSepar); // IGC B-record - if(Len>=800) { httpd_resp_send_chunk(Req, Line, Len); Len=0; } // when more than 800 bytes then write this part to the socket - vTaskDelay(1); } + if(Len>=800) // when more than 800 bytes then write this part to the socket + { httpd_resp_send_chunk(Req, Line, Len); + mbedtls_md5_update_ret(&MD5, (uint8_t *)Line, Len); + Len=0; vTaskDelay(1); } + } fclose(File); - if(Len) { httpd_resp_send_chunk(Req, Line, Len); Len=0; } + if(Len) + { httpd_resp_send_chunk(Req, Line, Len); + mbedtls_md5_update_ret(&MD5, (uint8_t *)Line, Len); + Len=0; } + uint8_t Digest[16]; + mbedtls_md5_finish_ret(&MD5, Digest); + Len=0; Line[Len++]='G'; // G-record, not signed yet, just MD5 + for(int Idx=0; Idx<16; Idx++) + Len+=Format_Hex(Line+Len, Digest[Idx]); + Line[Len++]='\n'; Line[Len]=0; + httpd_resp_send_chunk(Req, Line, Len); httpd_resp_send_chunk(Req, 0, 0); return ESP_OK; } diff --git a/main/ogn1.h b/main/ogn1.h index 28b38db..557d927 100644 --- a/main/ogn1.h +++ b/main/ogn1.h @@ -616,9 +616,7 @@ class OGN1_Packet // Packet structure for the OGN tracker Msg[Len++] = ' '; Msg[Len++] = 'g'; Msg[Len++] = 'p'; Msg[Len++] = 's'; Len+=Format_UnsDec(Msg+Len, HorPrec); Msg[Len++] = 'x'; Len+=Format_UnsDec(Msg+Len, VerPrec); - Msg[Len++]='\n'; - Msg[Len]=0; - return Len; } + Msg[Len++]='\n'; Msg[Len]=0; return Len; } #endif // __AVR__ diff --git a/main/sdlog.cpp b/main/sdlog.cpp index db5696d..0a0aa14 100644 --- a/main/sdlog.cpp +++ b/main/sdlog.cpp @@ -111,7 +111,7 @@ static void IGC_TimeStamp(void) { struct stat FileStat; struct utimbuf FileTime; if(stat(IGC_FileName, &FileStat)>=0) // get file attributes (maybe not needed really ? - { FileTime.actime = IGC_SaveTime; // set access and modification tim$ + { FileTime.actime = IGC_SaveTime; // set access and modification time FileTime.modtime = IGC_SaveTime; utime(IGC_FileName, &FileTime); } // write to the FAT } From 24c03733909f0bc3127aa87f374318b42ed31774 Mon Sep 17 00:00:00 2001 From: Pawel Jalocha Date: Sun, 7 Mar 2021 16:28:19 +0000 Subject: [PATCH 2/2] More header lines for HTTP IGC and some bugs fixed --- main/http.cpp | 31 +++++++++++++++++++++++++++++++ main/sdlog.cpp | 9 ++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/main/http.cpp b/main/http.cpp index 34f6f02..0c7308d 100644 --- a/main/http.cpp +++ b/main/http.cpp @@ -715,6 +715,37 @@ static esp_err_t SendLog_IGC(httpd_req_t *Req, const char *FileName, uint32_t Fi { Len+=Format_String(Line+Len, "HFPLTPilotincharge:"); Len+=Format_String(Line+Len, Parameters.Pilot); Line[Len++]='\n'; } + if(Parameters.Reg[0]) + { Len+=Format_String(Line+Len, "HFGIDGliderID:"); + Len+=Format_String(Line+Len, Parameters.Reg); + Line[Len++]='\n'; } +#ifdef WITH_FollowMe + Len+=Format_String(Line+Len, "HFRHWHardwareVersion:FollowMe\n"); +#else + Len+=Format_String(Line+Len, "HFRHWHardwareVersion:ESP32+LoRa\n"); // hardware version +#endif + Len+=Format_String(Line+Len, "HFRFWFirmwareVersion:ESP32-OGN-TRACKER " __DATE__ " " __TIME__ "\n"); +#ifdef WITH_BMP180 + Len+=Format_String(Line+Len, "HFPRSPressAltSensor:BMP180\n"); // pressure sensor +#endif +#ifdef WITH_BMP280 + Len+=Format_String(Line+Len, "HFPRSPressAltSensor:BMP280\n"); // pressure sensor +#endif +#ifdef WITH_BME280 + Len+=Format_String(Line+Len, "HFPRSPressAltSensor:BME280/BMP280\n"); // pressure sensor +#endif + Len+=Format_String(Line+Len, "LOGN"); + Len+=Format_HHMMSS(Line+Len, FileTime); + Len+=Format_String(Line+Len, "ID "); + Len+=Format_Hex(Line+Len, Parameters.AcftID); + Line[Len++]='\n'; + uint64_t MAC = getUniqueID(); + Len+=Format_String(Line+Len, "LOGN"); + Len+=Format_HHMMSS(Line+Len, FileTime); + Len+=Format_String(Line+Len, "MAC "); + Len+=Format_Hex(Line+Len, (uint16_t)(MAC>>32)); // ESP32 48-bit ID + Len+=Format_Hex(Line+Len, (uint32_t) MAC ); + Line[Len++]='\n'; httpd_resp_send_chunk(Req, Line, Len); mbedtls_md5_update_ret(&MD5, (uint8_t *)Line, Len); OGN_LogPacket Packet; diff --git a/main/sdlog.cpp b/main/sdlog.cpp index 0a0aa14..2288ec0 100644 --- a/main/sdlog.cpp +++ b/main/sdlog.cpp @@ -204,9 +204,9 @@ static int IGC_Header(const GPS_Position &Pos) // write the IGC_HeadParm("HFCIDCompetitionID:", Parameters.ID); // competition ID { #ifdef WITH_FollowMe - int Len=Format_String(Line, "HFRHWHardwareVersion:FollowMe"); + int Len=Format_String(Line, "HFRHWHardwareVersion:FollowMe\n"); #else - int Len=Format_String(Line, "HFRHWHardwareVersion:ESP32-SX1276"); // hardware version + int Len=Format_String(Line, "HFRHWHardwareVersion:ESP32+LoRa\n"); // hardware version #endif Line[Len++]='\n'; Line[Len]=0; IGC_LogLine(Line, Len); } @@ -221,11 +221,14 @@ static int IGC_Header(const GPS_Position &Pos) // write the IGC_LogLine("HFGPSReceiver:MTK\n"); // GPS sensor #endif #endif +#ifdef WITH_BMP180 + IGC_LogLine("HFPRSPressAltSensor:BMP180\n"); // pressure sensor +#endif #ifdef WITH_BMP280 IGC_LogLine("HFPRSPressAltSensor:BMP280\n"); // pressure sensor #endif #ifdef WITH_BME280 - IGC_LogLine("HFPRSPressAltSensor:BME280\n"); // pressure sensor + IGC_LogLine("HFPRSPressAltSensor:BME280/BMP280\n"); // pressure sensor #endif return 0; }