remove EbusReceiver

This commit is contained in:
Guido Schreuder 2024-02-25 14:39:33 +01:00
parent 8cd7a78786
commit c0be8efe05
2 changed files with 10 additions and 19 deletions

View file

@ -45,8 +45,6 @@ void EbusComponent::set_command_queue_size(uint8_t command_queue_size) {
this->command_queue_size_ = command_queue_size;
}
void EbusComponent::add_receiver(EbusReceiver *receiver) { this->receivers_.push_back(receiver); }
void EbusComponent::setup_queues_() {
this->history_queue_ = xQueueCreate(this->history_queue_size_, sizeof(Telegram));
this->command_queue_ = xQueueCreate(this->command_queue_size_, sizeof(Telegram));
@ -72,8 +70,8 @@ void EbusComponent::setup_ebus_() {
this->ebus_->add_send_response_handler([&](Telegram &telegram) {
std::vector<uint8_t> reply = {};
for (auto const &receiver : this->receivers_) {
reply = receiver->reply(telegram);
for (auto const &item : this->items_) {
reply = item->reply(telegram);
if (reply.size() != 0) {
break;
}
@ -157,8 +155,8 @@ void EbusComponent::handle_message_(Telegram &telegram) {
return;
}
for (auto const &receiver : this->receivers_) {
receiver->process_received(telegram);
for (auto const &item : this->items_) {
item->process_received(telegram);
}
}

View file

@ -20,16 +20,7 @@ static const char *const TAG = "ebus";
class EbusComponent;
class EbusReceiver {
public:
virtual void process_received(Telegram) = 0;
std::vector<uint8_t> reply(Telegram telegram) {
std::vector<uint8_t> reply = {0xe3, 'E', 'S', 'P', 'H', 'M', 0x12, 0x34, 0x56, 0x78};
return reply;
};
};
class EbusItem : public EbusReceiver, public Component {
class EbusItem : public Component {
public:
void dump_config() override;
@ -40,6 +31,11 @@ class EbusItem : public EbusReceiver, public Component {
void set_payload(const std::vector<uint8_t> &payload) { this->payload_ = payload; }
void set_response_read_position(uint8_t response_position) { this->response_position_ = response_position; }
virtual void process_received(Telegram) { }
virtual std::vector<uint8_t> reply(Telegram telegram) {
std::vector<uint8_t> reply = {0xe3, 'E', 'S', 'P', 'H', 'M', 0x12, 0x34, 0x56, 0x78};
return reply;
};
virtual optional<SendCommand> prepare_command();
// TODO: refactor these
@ -72,10 +68,8 @@ class EbusComponent : public PollingComponent {
void set_history_queue_size(uint8_t /*history_queue_size*/);
void set_command_queue_size(uint8_t /*command_queue_size*/);
void add_receiver(EbusReceiver * /*receiver*/);
void add_item(EbusItem *item) {
this->items_.push_back(item);
this->add_receiver(item);
};
void update() override;
@ -96,7 +90,6 @@ class EbusComponent : public PollingComponent {
#endif
std::list<EbusItem *> items_;
std::list<EbusReceiver *> receivers_;
std::unique_ptr<Ebus> ebus_;