Skip to content

Commit

Permalink
Move IGC key to CTRL task so it can be used as well without SDLOG
Browse files Browse the repository at this point in the history
  • Loading branch information
pjalocha committed Feb 12, 2022
1 parent e85d1d1 commit f63bfd8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
20 changes: 16 additions & 4 deletions main/ctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions main/ctrl.h
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
32 changes: 17 additions & 15 deletions main/sdlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "timesync.h"
#include "fifo.h"

#include "igc-key.h" // IGC key generate/read/write/sign with
#include "ctrl.h"

// ============================================================================================

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -301,7 +303,7 @@ static void IGC_Check(void) // check if

// ============================================================================================

IGC_Key IGC_SignKey;
// IGC_Key IGC_SignKey;

#ifdef WITH_SDLOG

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit f63bfd8

Please sign in to comment.