kopia lustrzana https://github.com/pjalocha/esp32-ogn-tracker
Merge branch 'master' of https://github.com/pjalocha/esp32-ogn-tracker
commit
5c4f22a640
|
@ -6,6 +6,8 @@
|
|||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "mbedtls/md5.h"
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
#include "esp_http_server.h"
|
||||
|
@ -695,12 +697,57 @@ 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'; }
|
||||
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<OGN_Packet> Packet;
|
||||
Len=0;
|
||||
for( ; ; )
|
||||
|
@ -713,10 +760,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; }
|
||||
|
||||
|
|
|
@ -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__
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
@ -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; }
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue