From f63bfd87e88f7bfa323779043021a5670b6f3826 Mon Sep 17 00:00:00 2001 From: Pawel Jalocha Date: Sat, 12 Feb 2022 07:08:26 +0000 Subject: [PATCH] Move IGC key to CTRL task so it can be used as well without SDLOG --- main/ctrl.cpp | 20 ++++++++++++++++---- main/ctrl.h | 3 +++ main/sdlog.cpp | 32 +++++++++++++++++--------------- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/main/ctrl.cpp b/main/ctrl.cpp index c50237b..549d6d1 100644 --- a/main/ctrl.cpp +++ b/main/ctrl.cpp @@ -25,14 +25,18 @@ #include "disp_oled.h" #include "disp_lcd.h" +#include "igc-key.h" + // #include "ymodem.h" // #define DEBUG_PRINT -static char Line[160]; +static char Line[512]; // FIFO KeyBuffer; +IGC_Key IGC_SignKey; + // ======================================================================================================================== void PrintTasks(void (*CONS_UART_Write)(char)) @@ -167,10 +171,10 @@ static void ProcessCtrlV(void) } static void ProcessCtrlK(void) // print public key to the console -{ uint8_t Out[512]; +{ // uint8_t Out[512]; xSemaphoreTake(CONS_Mutex, portMAX_DELAY); - if(IGC_SignKey.Pub_Write(Out, 512)==0) - Format_String(CONS_UART_Write, (const char *)Out); + if(IGC_SignKey.Pub_Write((uint8_t *)Line, 512)==0) + Format_String(CONS_UART_Write, Line); xSemaphoreGive(CONS_Mutex); } static void ProcessCtrlF(void) // list log files to the console @@ -433,6 +437,14 @@ extern "C" void vTaskCTRL(void* pvParameters) { + IGC_SignKey.Init(); + IGC_SignKey.Generate(); + if(IGC_SignKey.ReadFromNVS()!=ESP_OK) IGC_SignKey.WriteToNVS(); + xSemaphoreTake(CONS_Mutex, portMAX_DELAY); + if(IGC_SignKey.Pub_Write((uint8_t *)Line, 512)==0) + Format_String(CONS_UART_Write, Line); + xSemaphoreGive(CONS_Mutex); + uint8_t Len=Format_String(Line, "$POGNS,SysStart"); Len+=NMEA_AppendCheckCRNL(Line, Len); Line[Len]=0; diff --git a/main/ctrl.h b/main/ctrl.h index 0d90462..3b07ff7 100644 --- a/main/ctrl.h +++ b/main/ctrl.h @@ -1,5 +1,8 @@ #include "fifo.h" #include "hal.h" +#include "igc-key.h" + +extern IGC_Key IGC_SignKey; // extern FIFO KeyBuffer; diff --git a/main/sdlog.cpp b/main/sdlog.cpp index a6e88d1..2364866 100644 --- a/main/sdlog.cpp +++ b/main/sdlog.cpp @@ -11,7 +11,7 @@ #include "timesync.h" #include "fifo.h" -#include "igc-key.h" // IGC key generate/read/write/sign with +#include "ctrl.h" // ============================================================================================ @@ -96,7 +96,8 @@ static uint32_t IGC_SaveTime=0; uint16_t IGC_FlightNum=0; // flight counter static SHA256 IGC_SHA256; // -static uint8_t IGC_Digest[32]; // +const int IGC_Digest_Size = 32; +static uint8_t IGC_Digest[IGC_Digest_Size]; // static void IGC_TimeStamp(void) { struct stat FileStat; @@ -272,11 +273,12 @@ static void IGC_Check(void) // check if { IGC_Log(GPS_Pos[PosIdx]); // log position if(!inFlight) // if no longer in flight { IGC_SHA256.Finish(IGC_Digest); - Line[0]='G'; // produce G-record with SH256 - for(int Idx=0; Idx<32; Idx++) // 32 SHA256 bytes - Format_Hex(Line+1+2*Idx, IGC_Digest[Idx]); // printed as hex - Line[65]='\n'; Line[66]=0; // end-of-line, end-of-string - IGC_LogLine(Line, 66); // write to IGC + int Len=0; + Line[Len++]='G'; // produce G-record with SH256 + for(int Idx=0; Idx