From ad836f8fda9a26c0df608b98e97ed0a2999d6715 Mon Sep 17 00:00:00 2001 From: John L Chen Date: Sat, 17 Aug 2024 20:18:22 +0800 Subject: [PATCH] Refactor IrLogic to see if we can get rid of memory issue --- fw/Core/Hitcon/Logic/IrLogic.cc | 6 ++++-- fw/Core/Hitcon/Logic/IrLogic.h | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fw/Core/Hitcon/Logic/IrLogic.cc b/fw/Core/Hitcon/Logic/IrLogic.cc index a259efd..6cb4a47 100644 --- a/fw/Core/Hitcon/Logic/IrLogic.cc +++ b/fw/Core/Hitcon/Logic/IrLogic.cc @@ -109,9 +109,11 @@ void IrLogic::OnBufferReceived(uint8_t *buffer) { for (size_t i = 0; i < IR_SERVICE_RX_BUFFER_PER_RUN && buffer_received_ctr < IR_SERVICE_RX_ON_BUFFER_SIZE; i++, buffer_received_ctr++) { + my_assert(buffer_received_ctr < IR_SERVICE_RX_ON_BUFFER_SIZE); + uint8_t current_byte = buffer[buffer_received_ctr]; for (uint8_t j = 0; j < 8; j++) { - my_assert(buffer_received_ctr < IR_SERVICE_RX_ON_BUFFER_SIZE); - uint8_t is_on = (buffer[buffer_received_ctr] & (1 << j)) ? 1 : 0; + uint8_t is_on = current_byte & 0x01; + current_byte = current_byte >> 1; switch (packet_state) { case STATE_START: packet_buf <<= 1; diff --git a/fw/Core/Hitcon/Logic/IrLogic.h b/fw/Core/Hitcon/Logic/IrLogic.h index 8910214..dcb2f95 100644 --- a/fw/Core/Hitcon/Logic/IrLogic.h +++ b/fw/Core/Hitcon/Logic/IrLogic.h @@ -60,8 +60,8 @@ class IrLogic { IrPacket rx_packet_ctrler; IrPacket tx_packet; - // To split OnBufferReceived into pieces - size_t buffer_received_ctr; + // This variable is a mystery. + size_t dummy1 = 0xBAADF00D; // Total periods collected for load factor computation. size_t lf_total_period; @@ -72,6 +72,9 @@ class IrLogic { // Load factor after low pass filter. // In Q15.16 fixed point. uint32_t lowpass_loadfactor; + + // To split OnBufferReceived into pieces + size_t buffer_received_ctr; }; extern IrLogic irLogic;