mirror of
https://github.com/esphome/esphome.git
synced 2026-08-22 22:26:21 +00:00
[ufm01] Prefix PassiveReadResult enumerators to avoid Realtek SDK macro collision (#18240)
This commit is contained in:
@@ -329,21 +329,21 @@ PassiveReadResult UFM01Component::continue_passive_read_() {
|
|||||||
|
|
||||||
if (this->passive_index_ < PASSIVE_FRAME_SIZE) {
|
if (this->passive_index_ < PASSIVE_FRAME_SIZE) {
|
||||||
if (millis() - this->passive_start_ms_ < PASSIVE_READ_TIMEOUT_MS)
|
if (millis() - this->passive_start_ms_ < PASSIVE_READ_TIMEOUT_MS)
|
||||||
return PassiveReadResult::PENDING;
|
return PassiveReadResult::PASSIVE_READ_RESULT_PENDING;
|
||||||
ESP_LOGD(TAG, "passive read timeout (%zu/%zu bytes)", this->passive_index_, PASSIVE_FRAME_SIZE);
|
ESP_LOGD(TAG, "passive read timeout (%zu/%zu bytes)", this->passive_index_, PASSIVE_FRAME_SIZE);
|
||||||
return PassiveReadResult::FAILURE;
|
return PassiveReadResult::PASSIVE_READ_RESULT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!validate_passive_frame(this->passive_frame_)) {
|
if (!validate_passive_frame(this->passive_frame_)) {
|
||||||
log_hex(this->passive_frame_, PASSIVE_FRAME_SIZE);
|
log_hex(this->passive_frame_, PASSIVE_FRAME_SIZE);
|
||||||
ESP_LOGW(TAG, "invalid passive frame");
|
ESP_LOGW(TAG, "invalid passive frame");
|
||||||
return PassiveReadResult::FAILURE;
|
return PassiveReadResult::PASSIVE_READ_RESULT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t active_frame[FRAME_SIZE];
|
uint8_t active_frame[FRAME_SIZE];
|
||||||
passive_no_id_to_active_frame(this->passive_frame_, active_frame);
|
passive_no_id_to_active_frame(this->passive_frame_, active_frame);
|
||||||
this->on_active_frame_(active_frame);
|
this->on_active_frame_(active_frame);
|
||||||
return PassiveReadResult::SUCCESS;
|
return PassiveReadResult::PASSIVE_READ_RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UFM01Component::loop_startup_() {
|
void UFM01Component::loop_startup_() {
|
||||||
@@ -410,15 +410,15 @@ void UFM01Component::loop_startup_() {
|
|||||||
|
|
||||||
case StartupPhase::PASSIVE_WAIT_REPLY:
|
case StartupPhase::PASSIVE_WAIT_REPLY:
|
||||||
switch (this->continue_passive_read_()) {
|
switch (this->continue_passive_read_()) {
|
||||||
case PassiveReadResult::PENDING:
|
case PassiveReadResult::PASSIVE_READ_RESULT_PENDING:
|
||||||
return;
|
return;
|
||||||
case PassiveReadResult::SUCCESS:
|
case PassiveReadResult::PASSIVE_READ_RESULT_SUCCESS:
|
||||||
ESP_LOGI(TAG, "UFM-01 using passive polling");
|
ESP_LOGI(TAG, "UFM-01 using passive polling");
|
||||||
this->operating_mode_ = OperatingMode::PASSIVE_POLL;
|
this->operating_mode_ = OperatingMode::PASSIVE_POLL;
|
||||||
this->passive_read_pending_ = false;
|
this->passive_read_pending_ = false;
|
||||||
this->last_poll_ms_ = millis();
|
this->last_poll_ms_ = millis();
|
||||||
return;
|
return;
|
||||||
case PassiveReadResult::FAILURE:
|
case PassiveReadResult::PASSIVE_READ_RESULT_FAILURE:
|
||||||
ESP_LOGW(TAG, "Startup failed, retrying in %" PRIu32 " ms", STARTUP_RETRY_MS);
|
ESP_LOGW(TAG, "Startup failed, retrying in %" PRIu32 " ms", STARTUP_RETRY_MS);
|
||||||
this->startup_wait_ms_ = STARTUP_RETRY_MS;
|
this->startup_wait_ms_ = STARTUP_RETRY_MS;
|
||||||
this->set_startup_phase_(StartupPhase::WAIT);
|
this->set_startup_phase_(StartupPhase::WAIT);
|
||||||
@@ -441,10 +441,10 @@ void UFM01Component::loop_active_stream_() {
|
|||||||
void UFM01Component::loop_passive_poll_() {
|
void UFM01Component::loop_passive_poll_() {
|
||||||
if (this->passive_read_pending_) {
|
if (this->passive_read_pending_) {
|
||||||
const PassiveReadResult result = this->continue_passive_read_();
|
const PassiveReadResult result = this->continue_passive_read_();
|
||||||
if (result == PassiveReadResult::PENDING)
|
if (result == PassiveReadResult::PASSIVE_READ_RESULT_PENDING)
|
||||||
return;
|
return;
|
||||||
this->passive_read_pending_ = false;
|
this->passive_read_pending_ = false;
|
||||||
if (result == PassiveReadResult::FAILURE)
|
if (result == PassiveReadResult::PASSIVE_READ_RESULT_FAILURE)
|
||||||
this->status_set_warning("UFM-01 passive poll failed");
|
this->status_set_warning("UFM-01 passive poll failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ enum class StartupPhase : uint8_t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum class PassiveReadResult : uint8_t {
|
enum class PassiveReadResult : uint8_t {
|
||||||
PENDING = 0,
|
PASSIVE_READ_RESULT_PENDING = 0,
|
||||||
SUCCESS = 1,
|
PASSIVE_READ_RESULT_SUCCESS = 1,
|
||||||
FAILURE = 2,
|
PASSIVE_READ_RESULT_FAILURE = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
class UFM01Component : public uart::UARTDevice, public Component {
|
class UFM01Component : public uart::UARTDevice, public Component {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ TEST_F(UFM01Test, ValidPassiveFrameReadSuccess) {
|
|||||||
this->mock_uart_.enqueue(std::vector<uint8_t>(frame.begin(), frame.end()));
|
this->mock_uart_.enqueue(std::vector<uint8_t>(frame.begin(), frame.end()));
|
||||||
this->ufm01_.prepare_passive_read();
|
this->ufm01_.prepare_passive_read();
|
||||||
|
|
||||||
EXPECT_EQ(this->ufm01_.continue_passive_read(), PassiveReadResult::SUCCESS);
|
EXPECT_EQ(this->ufm01_.continue_passive_read(), PassiveReadResult::PASSIVE_READ_RESULT_SUCCESS);
|
||||||
EXPECT_EQ(this->ufm01_.passive_index(), PASSIVE_FRAME_SIZE);
|
EXPECT_EQ(this->ufm01_.passive_index(), PASSIVE_FRAME_SIZE);
|
||||||
EXPECT_NE(this->ufm01_.last_valid_frame_ms(), 0u);
|
EXPECT_NE(this->ufm01_.last_valid_frame_ms(), 0u);
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ TEST_F(UFM01Test, InvalidPassiveChecksumFails) {
|
|||||||
this->mock_uart_.enqueue(std::vector<uint8_t>(frame.begin(), frame.end()));
|
this->mock_uart_.enqueue(std::vector<uint8_t>(frame.begin(), frame.end()));
|
||||||
this->ufm01_.prepare_passive_read();
|
this->ufm01_.prepare_passive_read();
|
||||||
|
|
||||||
EXPECT_EQ(this->ufm01_.continue_passive_read(), PassiveReadResult::FAILURE);
|
EXPECT_EQ(this->ufm01_.continue_passive_read(), PassiveReadResult::PASSIVE_READ_RESULT_FAILURE);
|
||||||
EXPECT_EQ(this->ufm01_.last_valid_frame_ms(), 0u);
|
EXPECT_EQ(this->ufm01_.last_valid_frame_ms(), 0u);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ TEST_F(UFM01Test, PassiveReadResyncsAfterGarbagePrefix) {
|
|||||||
this->mock_uart_.enqueue(std::vector<uint8_t>(frame.begin(), frame.end()));
|
this->mock_uart_.enqueue(std::vector<uint8_t>(frame.begin(), frame.end()));
|
||||||
this->ufm01_.prepare_passive_read();
|
this->ufm01_.prepare_passive_read();
|
||||||
|
|
||||||
EXPECT_EQ(this->ufm01_.continue_passive_read(), PassiveReadResult::SUCCESS);
|
EXPECT_EQ(this->ufm01_.continue_passive_read(), PassiveReadResult::PASSIVE_READ_RESULT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UFM01Test, PassiveReadResyncsOnSecondStartByte) {
|
TEST_F(UFM01Test, PassiveReadResyncsOnSecondStartByte) {
|
||||||
@@ -65,7 +65,7 @@ TEST_F(UFM01Test, PassiveReadResyncsOnSecondStartByte) {
|
|||||||
this->mock_uart_.enqueue(std::vector<uint8_t>(frame.begin(), frame.end()));
|
this->mock_uart_.enqueue(std::vector<uint8_t>(frame.begin(), frame.end()));
|
||||||
this->ufm01_.prepare_passive_read();
|
this->ufm01_.prepare_passive_read();
|
||||||
|
|
||||||
EXPECT_EQ(this->ufm01_.continue_passive_read(), PassiveReadResult::SUCCESS);
|
EXPECT_EQ(this->ufm01_.continue_passive_read(), PassiveReadResult::PASSIVE_READ_RESULT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UFM01Test, PassiveReadPendingWhenPartial) {
|
TEST_F(UFM01Test, PassiveReadPendingWhenPartial) {
|
||||||
@@ -73,11 +73,11 @@ TEST_F(UFM01Test, PassiveReadPendingWhenPartial) {
|
|||||||
this->mock_uart_.enqueue(std::vector<uint8_t>(frame.begin(), frame.begin() + 10));
|
this->mock_uart_.enqueue(std::vector<uint8_t>(frame.begin(), frame.begin() + 10));
|
||||||
this->ufm01_.prepare_passive_read();
|
this->ufm01_.prepare_passive_read();
|
||||||
|
|
||||||
EXPECT_EQ(this->ufm01_.continue_passive_read(), PassiveReadResult::PENDING);
|
EXPECT_EQ(this->ufm01_.continue_passive_read(), PassiveReadResult::PASSIVE_READ_RESULT_PENDING);
|
||||||
EXPECT_LT(this->ufm01_.passive_index(), PASSIVE_FRAME_SIZE);
|
EXPECT_LT(this->ufm01_.passive_index(), PASSIVE_FRAME_SIZE);
|
||||||
|
|
||||||
this->mock_uart_.enqueue(std::vector<uint8_t>(frame.begin() + 10, frame.end()));
|
this->mock_uart_.enqueue(std::vector<uint8_t>(frame.begin() + 10, frame.end()));
|
||||||
EXPECT_EQ(this->ufm01_.continue_passive_read(), PassiveReadResult::SUCCESS);
|
EXPECT_EQ(this->ufm01_.continue_passive_read(), PassiveReadResult::PASSIVE_READ_RESULT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace esphome::ufm01::testing
|
} // namespace esphome::ufm01::testing
|
||||||
|
|||||||
Reference in New Issue
Block a user