diff --git a/App/app/rxtx_log.c b/App/app/rxtx_log.c index 3b3e9e87..fd952035 100644 --- a/App/app/rxtx_log.c +++ b/App/app/rxtx_log.c @@ -136,6 +136,22 @@ static uint16_t gLogCursor; static uint8_t gLogFilter; static uint8_t gLogDetailMode; +bool RXTX_LOG_IsEnabled(void) +{ + return gEeprom.KEY_1_SHORT_PRESS_ACTION == ACTION_OPT_RXTX_LOG || + gEeprom.KEY_1_LONG_PRESS_ACTION == ACTION_OPT_RXTX_LOG || + gEeprom.KEY_2_SHORT_PRESS_ACTION == ACTION_OPT_RXTX_LOG || + gEeprom.KEY_2_LONG_PRESS_ACTION == ACTION_OPT_RXTX_LOG || + gEeprom.KEY_M_LONG_PRESS_ACTION == ACTION_OPT_RXTX_LOG; +} + +static void RXTX_LOG_ResetActiveSession(void) +{ + gSessionActive = false; + gSessionSMeter = RXTX_LOG_SMETER_UNKNOWN; + gSessionBattVolt = RXTX_LOG_BATT_UNKNOWN; +} + static uint8_t RXTX_LOG_Crc8(const void *data, uint16_t size) { const uint8_t *p = (const uint8_t *)data; @@ -755,6 +771,7 @@ uint32_t RXTX_LOG_K5ViewerSignature(void) { uint32_t hash = 2166136261u; + hash = RXTX_LOG_K5ViewerMix(hash, RXTX_LOG_IsEnabled()); hash = RXTX_LOG_K5ViewerMix(hash, gSessionActive); hash = RXTX_LOG_K5ViewerMix(hash, gClearActive); hash = RXTX_LOG_K5ViewerMix(hash, gLogHasTraffic); @@ -863,6 +880,13 @@ void RXTX_LOG_SendK5ViewerPacket(void (*send)(const uint8_t *data, uint16_t size RXTX_LogK5ViewerRow_t row; uint8_t header[4] = {RXTX_LOG_K5VIEWER_VERSION, 0, RXTX_LOG_K5VIEWER_ROW_COUNT, 0}; + if (!RXTX_LOG_IsEnabled()) { + header[1] = RXTX_LOG_K5VIEWER_STATUS_DISABLED; + header[2] = 0; + send(header, sizeof(header)); + return; + } + if (gSessionActive) header[1] |= RXTX_LOG_K5VIEWER_STATUS_ACTIVE; if (gLogHasTraffic) @@ -898,7 +922,7 @@ uint32_t RXTX_LOG_SendK5ViewerHistoryPage(uint32_t beforeSeq, void (*send)(const static void RXTX_LOG_CaptureSession(uint8_t flags, const VFO_Info_t *vfo) { - if (gClearActive) + if (!RXTX_LOG_IsEnabled() || vfo == NULL || gClearActive) return; const uint32_t frequency = (flags & RXTX_LOG_FLAG_TX) ? vfo->pTX->Frequency : vfo->pRX->Frequency; @@ -984,15 +1008,13 @@ void RXTX_LOG_Init(void) // Skip the marker if the log already ends with one (e.g. repeated // reboots with no RX/TX in between) to avoid stacking empty separators. - if (!found || (lastEntryFlags & RXTX_LOG_FLAG_SESSION) == 0) + if (RXTX_LOG_IsEnabled() && + (!found || (lastEntryFlags & RXTX_LOG_FLAG_SESSION) == 0)) RXTX_LOG_WriteSessionMarker(); } void RXTX_LOG_BeginRx(const VFO_Info_t *vfo, FUNCTION_Type_t function) { - if (vfo == NULL) - return; - uint8_t flags = 0; if (function == FUNCTION_MONITOR) flags |= RXTX_LOG_FLAG_MONITOR; @@ -1002,9 +1024,6 @@ void RXTX_LOG_BeginRx(const VFO_Info_t *vfo, FUNCTION_Type_t function) void RXTX_LOG_BeginTx(const VFO_Info_t *vfo) { - if (vfo == NULL) - return; - RXTX_LOG_CaptureSession(RXTX_LOG_FLAG_TX, vfo); } @@ -1013,10 +1032,8 @@ void RXTX_LOG_EndActive(void) if (!gSessionActive) return; - if (gClearActive) { - gSessionActive = false; - gSessionSMeter = RXTX_LOG_SMETER_UNKNOWN; - gSessionBattVolt = RXTX_LOG_BATT_UNKNOWN; + if (!RXTX_LOG_IsEnabled() || gClearActive) { + RXTX_LOG_ResetActiveSession(); return; } @@ -1040,9 +1057,7 @@ void RXTX_LOG_EndActive(void) gLogHasTraffic = true; RXTX_LOG_InvalidateViewCache(); - gSessionActive = false; - gSessionSMeter = RXTX_LOG_SMETER_UNKNOWN; - gSessionBattVolt = RXTX_LOG_BATT_UNKNOWN; + RXTX_LOG_ResetActiveSession(); } void RXTX_LOG_Tick500ms(void) @@ -1056,6 +1071,9 @@ void RXTX_LOG_Tick500ms(void) void RXTX_LOG_Task10ms(void) { + if (gSessionActive && !RXTX_LOG_IsEnabled()) + RXTX_LOG_ResetActiveSession(); + if (gClearActive) { RXTX_LOG_StepClear(); } else if (gViewScanActive) { diff --git a/App/app/rxtx_log.h b/App/app/rxtx_log.h index 0c849bb3..5fcc2a69 100644 --- a/App/app/rxtx_log.h +++ b/App/app/rxtx_log.h @@ -42,6 +42,8 @@ typedef struct { #define RXTX_LOG_K5VIEWER_STATUS_ACTIVE (1u << 0) #define RXTX_LOG_K5VIEWER_STATUS_HAS_TRAFFIC (1u << 1) #define RXTX_LOG_K5VIEWER_STATUS_CLEARING (1u << 2) +#define RXTX_LOG_K5VIEWER_STATUS_DISABLED (1u << 3) +#define RXTX_LOG_K5VIEWER_STATUS_PACKET_SIZE 4u typedef struct __attribute__((packed)) { uint32_t frequency; @@ -54,11 +56,11 @@ typedef struct __attribute__((packed)) { char channelName[RXTX_LOG_K5VIEWER_NAME_LENGTH]; } RXTX_LogK5ViewerRow_t; -// On-wire packet layout: 4-byte header (version, status, rowCount, -// reserved), one live row, then RXTX_LOG_K5VIEWER_ROW_COUNT row slots, -// zero-padded past the last valid row. The packet is streamed row by row -// and never built whole in RAM, so only its size is defined here. -#define RXTX_LOG_K5VIEWER_PACKET_SIZE (4u + ((RXTX_LOG_K5VIEWER_ROW_COUNT + 1u) * sizeof(RXTX_LogK5ViewerRow_t))) +// On-wire packet layout: a disabled log sends only the 4-byte status header. +// An enabled log continues with one live row and +// RXTX_LOG_K5VIEWER_ROW_COUNT row slots, zero-padded past the last valid row. +// The packet is streamed row by row and never built whole in RAM. +#define RXTX_LOG_K5VIEWER_PACKET_SIZE (RXTX_LOG_K5VIEWER_STATUS_PACKET_SIZE + ((RXTX_LOG_K5VIEWER_ROW_COUNT + 1u) * sizeof(RXTX_LogK5ViewerRow_t))) #define RXTX_LOG_K5VIEWER_HISTORY_PACKET_SIZE (RXTX_LOG_K5VIEWER_HISTORY_ROW_COUNT * sizeof(RXTX_LogK5ViewerRow_t)) uint32_t RXTX_LOG_K5ViewerSignature(void); @@ -70,6 +72,7 @@ uint32_t RXTX_LOG_SendK5ViewerHistoryPage(uint32_t beforeSeq, void (*send)(const #endif void RXTX_LOG_Init(void); +bool RXTX_LOG_IsEnabled(void); void RXTX_LOG_BeginRx(const VFO_Info_t *vfo, FUNCTION_Type_t function); void RXTX_LOG_BeginTx(const VFO_Info_t *vfo); void RXTX_LOG_EndActive(void); diff --git a/App/k5viewer.c b/App/k5viewer.c index 683b8859..5752ad34 100644 --- a/App/k5viewer.c +++ b/App/k5viewer.c @@ -123,6 +123,9 @@ static uint8_t K5VIEWER_StateFlags(void) #ifdef ENABLE_FEAT_F4HWN_RXTX_LOG_K5VIEWER static bool K5VIEWER_HasPendingRfLogUpdate(void) { + if (!RXTX_LOG_IsEnabled()) + rfLogHistoryBefore = RXTX_LOG_K5VIEWER_HISTORY_START; + if ((gSerialViewerFeatures & SERIAL_VIEWER_FEATURE_RF_LOG_RESTART) != 0) { gSerialViewerFeatures &= ~SERIAL_VIEWER_FEATURE_RF_LOG_RESTART; rfLogSent = false; @@ -157,14 +160,18 @@ static void K5VIEWER_SendRfLog(void) previousRfLogSignature = RXTX_LOG_K5ViewerSignature(); rfLogSent = true; - K5VIEWER_SendRfLogFrameHeader(K5VIEWER_TYPE_RXTX_LOG, RXTX_LOG_K5VIEWER_PACKET_SIZE); + const uint16_t size = RXTX_LOG_IsEnabled() + ? RXTX_LOG_K5VIEWER_PACKET_SIZE + : RXTX_LOG_K5VIEWER_STATUS_PACKET_SIZE; + K5VIEWER_SendRfLogFrameHeader(K5VIEWER_TYPE_RXTX_LOG, size); RXTX_LOG_SendK5ViewerPacket(K5VIEWER_Send); K5VIEWER_SendRfLogFrameEnd(); } static bool K5VIEWER_HasPendingRfLogHistory(void) { - return (gSerialViewerFeatures & SERIAL_VIEWER_FEATURE_RF_LOG_HISTORY) != 0 && + return RXTX_LOG_IsEnabled() && + (gSerialViewerFeatures & SERIAL_VIEWER_FEATURE_RF_LOG_HISTORY) != 0 && rfLogHistoryBefore != 0; }