66 lines
3.2 KiB
C++
66 lines
3.2 KiB
C++
#ifndef __SOLAR_CBF_STORE // include GUARD
|
|
#define __SOLAR_CBF_STORE
|
|
#include "esphome.h"
|
|
#include <utility>
|
|
#include <memory>
|
|
#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_sortcolumns : int
|
|
{
|
|
sisortNULL,
|
|
sisortcanid = cb_frame::sisortcanid,
|
|
sisortrtr = cb_frame::sisortrtr,
|
|
sisortframe = cb_frame::sisortframe,
|
|
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
|
|
};
|
|
|
|
enum cbf_updateresult : int
|
|
{
|
|
stu_NONE = 0, // no update
|
|
stu_DUPLICATE = 0b01, // updated with new timestamps no publish
|
|
stu_PUBLISH = 0b10, // can publish data
|
|
stu_DUPLICATE_PUBLISH = 0b11, // updated with new timestamps; can publish data
|
|
};
|
|
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<cbf_store> clone() const;
|
|
int compare(const cbf_store& b, const int *comparecolumns) const;
|
|
virtual std::string tag(const std::string& prefix = "", int prefixlen = 18) const override;
|
|
virtual 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;
|
|
cbf_updateresult update(const cbf_store& newitem, publish_spec_t publish_spec, publish_spec_t rtr_publish_spec, const int *comparecolumns);
|
|
virtual cbf_updateresult update(const cbf_store& newitem, 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<cbf_store> clone_impl() const;
|
|
};
|
|
} // namespace solar
|
|
#endif // __SOLAR_CBF_STORE
|