#ifndef __SOLAR_CBF_STORE // include GUARD #define __SOLAR_CBF_STORE #include "esphome.h" #include #include #include "common.h" #include "cb_frame.h" using namespace esphome; namespace solar { class cbf_store : virtual public cb_frame { public: int id; // used for debugging, can be omitted int count; // how many times a duplicate of this frame was received; used to signal publish time_t first_timestamp; // used for checking whether updateinterval has expired, i.e. to force a publish time_t last_timestamp; // used for choosing which store to overwrite with new (different) frame data enum cbf_store_sortcolumns : int { sisortNULL, sisortcanid = cb_frame::sisortcanid, sisortframe = cb_frame::sisortframe, sisortrtr = cb_frame::sisortrtr, sisortmsgid = cb_frame::sisortmsgid, sisortcount, sisortfirst_timestamp, sisortlast_timestamp, sisortEND, sisortcase = SORTCASE, // where applicable, case sensitive sisortreverse = SORTREVERSE, // reverse order sisortwild = WILDNULL, // where applicable, an empty or null entry equates to wildcard sistopcomparecol = STOPCOMPARE // stop compare after this column if both items to be compared are valid and a compare was possible }; cbf_store() = delete; // default constructor not allowed cbf_store(int msg_id, uint32_t can_id, int id); cbf_store(int msg_id, uint32_t can_id, int id, time_t _first_timestamp, time_t _last_timestamp); cbf_store(int msg_id, uint32_t can_id, int id, const byte_vector& _frame, bool _rtr, time_t _first_timestamp, time_t _last_timestamp); cbf_store(const cbf_store& b, int id); cbf_store(const cbf_store&& b, int id); virtual ~cbf_store() = default; // virtual destructor for base class // using default (compiler auto generated) copy and move constructors and assignment operators std::shared_ptr clone() const; int compare(const cbf_store& b, const int *comparecolumns) const; std::string tag(const std::string& prefix = "") const override; std::string to_string() const override; bool is_publish_expired(time_t currenttime, int update_interval) const; bool is_validity_expired(time_t currenttime, int timeout_interval) const; bool update(const cbf_store& newitem, publish_spec_t publish_spec, bool& publish, const int *comparecolumns); virtual bool update(const cbf_store& newitem, bool& publish, const int *comparecolumns); // should be pure virtual function, but we need to instantiate this class private: int compare(const cbf_store &b, int cmpflag, bool *stopcomparesignal, bool validnextcol) const; virtual std::shared_ptr clone_impl() const; }; } // namespace solar #endif // __SOLAR_CBF_STORE