Skip to content

Commit

Permalink
Refactored Non-NASA protocol implementation and improved memory manag…
Browse files Browse the repository at this point in the history
…ement
  • Loading branch information
omerfaruk-aran committed Oct 30, 2024
1 parent 376c277 commit 53b662e
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 116 deletions.
18 changes: 15 additions & 3 deletions components/samsung_ac/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ namespace esphome
return DataResult::Clear;
}

if (data.size() < 12)
{
ESP_LOGE(TAG, "Data size is too small: expected at least 12 bytes, got %d", data.size());
return DataResult::Clear;
}

// Check if its a decodeable NonNASA packat
DecodeResult result = DecodeResult::Ok;
NonNasaDataPacket nonpacket_;
static NonNasaProtocol non_nasa_protocol;

if (protocol_processing == ProtocolProcessing::Auto || protocol_processing == ProtocolProcessing::NonNASA)
{
result = try_decode_non_nasa_packet(data);
result = non_nasa_protocol.try_decode_non_nasa_packet(data);
if (result == DecodeResult::Ok)
{
if (debug_log_raw_bytes)
Expand All @@ -43,8 +51,7 @@ namespace esphome
{
protocol_processing = ProtocolProcessing::NonNASA;
}

process_non_nasa_packet(target);
non_nasa_protocol.process_non_nasa_packet(target, nonpacket_);
return DataResult::Clear;
}
}
Expand Down Expand Up @@ -72,6 +79,7 @@ namespace esphome

if (result == DecodeResult::SizeDidNotMatch || result == DecodeResult::UnexpectedSize)
{
ESP_LOGE(TAG, "Data size did not match expected: %s", bytes_to_hex(data).c_str());
return DataResult::Fill;
}

Expand All @@ -92,6 +100,10 @@ namespace esphome
{
// is logged within decoder
}
else if (result == DecodeResult::UnknownCommand)
{
ESP_LOGW(TAG, "Unknown command received in packet: %s", bytes_to_hex(data).c_str());
}
return DataResult::Clear;
}

Expand Down
3 changes: 2 additions & 1 deletion components/samsung_ac/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ namespace esphome
InvalidEndByte = 2,
SizeDidNotMatch = 3,
UnexpectedSize = 4,
CrcError = 5
CrcError = 5,
UnknownCommand = 6
};

enum class Mode
Expand Down
Loading

0 comments on commit 53b662e

Please sign in to comment.