Move IGC key to CTRL task so it can be used as well without SDLOG

pull/46/head
Pawel Jalocha 2022-02-12 07:08:26 +00:00
rodzic e85d1d16a0
commit f63bfd87e8
3 zmienionych plików z 36 dodań i 19 usunięć

Wyświetl plik

@ -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<uint8_t, 8> 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;

Wyświetl plik

@ -1,5 +1,8 @@
#include "fifo.h"
#include "hal.h"
#include "igc-key.h"
extern IGC_Key IGC_SignKey;
// extern FIFO<uint8_t, 8> KeyBuffer;

Wyświetl plik

@ -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<IGC_Digest_Size; Idx++) // 32 SHA256 bytes
Len+=Format_Hex(Line+Len, IGC_Digest[Idx]); // printed as hex
Line[Len++]='\n'; Line[Len]=0; // end-of-line, end-of-string
IGC_LogLine(Line, Len); // write to IGC
IGC_Close(); IGC_TimeStamp(); } // then close the IGC file
else
{ uint32_t Time=TimeSync_Time();
@ -301,7 +303,7 @@ static void IGC_Check(void) // check if
// ============================================================================================
IGC_Key IGC_SignKey;
// IGC_Key IGC_SignKey;
#ifdef WITH_SDLOG
@ -358,13 +360,13 @@ extern "C"
IGC_Serial[1] = Flight.Code36(ID%36); ID/=36;
IGC_Serial[0] = Flight.Code36(ID%36);
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);
// 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);
IGC_SHA256.Init();