Compare commits

...
2 changed files with 7 additions and 12 deletions

No files matched your search

+6 -8
View File
@@ -1066,20 +1066,19 @@ bool LD6002BComponent::queue_command_(uint16_t type, const uint8_t *data, uint8_
ESP_LOGW(TAG, "Command data too large: %u", len);
return false;
}
if (this->cmd_count_ >= CMD_QUEUE_SIZE) {
if (this->cmd_queue_.size() >= CMD_QUEUE_SIZE) {
ESP_LOGW(TAG, "Command queue full, dropping command 0x%04X", type);
return false;
}
PendingCommand &cmd = this->cmd_queue_[this->cmd_tail_];
PendingCommand cmd;
cmd.type = type;
cmd.len = len;
if (len > 0 && data != nullptr) {
std::memcpy(cmd.data.data(), data, len);
}
this->cmd_queue_.push(cmd);
this->cmd_tail_ = (this->cmd_tail_ + 1) % CMD_QUEUE_SIZE;
this->cmd_count_++;
this->process_command_queue_();
return true;
}
@@ -1146,12 +1145,11 @@ void LD6002BComponent::process_command_queue_() {
return;
}
if (this->cmd_count_ == 0)
if (this->cmd_queue_.empty())
return;
this->active_command_ = this->cmd_queue_[this->cmd_head_];
this->cmd_head_ = (this->cmd_head_ + 1) % CMD_QUEUE_SIZE;
this->cmd_count_--;
this->active_command_ = this->cmd_queue_.front();
this->cmd_queue_.pop();
this->send_generation_++;
this->retries_left_ = CMD_MAX_RETRIES;
+1 -4
View File
@@ -419,10 +419,7 @@ class LD6002BComponent : public Component, public uart::UARTDevice {
// A reply cannot trail the frame that earned it for longer than this; the field worst case is ~726ms.
static constexpr uint32_t STALE_ACK_MAX_AGE_MS = 1000;
std::array<PendingCommand, CMD_QUEUE_SIZE> cmd_queue_{};
uint8_t cmd_head_{0};
uint8_t cmd_tail_{0};
uint8_t cmd_count_{0};
StaticRingBuffer<PendingCommand, CMD_QUEUE_SIZE> cmd_queue_;
bool command_active_{false};
bool command_sent_{false};
PendingCommand active_command_{};