67 lines
3.5 KiB
C++
67 lines
3.5 KiB
C++
#ifndef __SOLAR_CB_FRAME // include GUARD
|
|
#define __SOLAR_CB_FRAME
|
|
#include "esphome.h"
|
|
#include <utility>
|
|
#include "common.h"
|
|
using namespace esphome;
|
|
|
|
namespace solar
|
|
{
|
|
class cbf_store;
|
|
class cb_frame {
|
|
private:
|
|
mutable bool publish; // whether this frame should be published
|
|
public:
|
|
enum cbf_sortcolumns : int
|
|
{
|
|
sisortNULL,
|
|
sisortcanid,
|
|
sisortrtr,
|
|
sisortframe,
|
|
sisortmsgid,
|
|
sisortEND,
|
|
sisortcase = SORTCASE, // case sensitive
|
|
sisortreverse = SORTREVERSE, // reverse order
|
|
sisortwild = WILDNULL, // 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
|
|
};
|
|
int msg_id;
|
|
bool rtr;
|
|
uint32_t can_id;
|
|
byte_vector frame;
|
|
cb_frame();
|
|
cb_frame(int msg_id, uint32_t can_id);
|
|
cb_frame(int msg_id, uint32_t can_id, const byte_vector& _frame, bool _rtr);
|
|
void clear();
|
|
void swap(cb_frame &s);
|
|
virtual bool is_valid() const;
|
|
virtual int compare(const cb_frame& b, const int *comparecolumns) const;
|
|
virtual int compare(const cb_frame &b, int cmpflag, bool *stopcomparesignal, bool validnextcol) const;
|
|
int compare_frame(const byte_vector& _frame) const;
|
|
void setpublish(bool do_publish = true) const; // we promise only to modify the publish flag
|
|
bool getpublish() const;
|
|
virtual std::string tag(const std::string& prefix = "", int prefixlen = 18) const;
|
|
virtual std::string to_string() const;
|
|
virtual ~cb_frame() = default;
|
|
// using default (compiler auto generated) copy and move constructors and assignment operators
|
|
|
|
/// Helper functions to convert four scaled values into a byte stream
|
|
/// set scale to negative for signed values
|
|
static std::vector<uint8_t> get_byte_stream(double value1, int scale1);
|
|
static std::vector<uint8_t> get_byte_stream(double value1, int scale1, double value2, int scale2);
|
|
static std::vector<uint8_t> get_byte_stream(double value1, int scale1, double value2, int scale2, double value3, int scale3);
|
|
static std::vector<uint8_t> get_byte_stream(double value1, int scale1, double value2, int scale2, double value3, int scale3, double value4, int scale4);
|
|
/// Overloaded function to handle double scale for the fourth value
|
|
static std::vector<uint8_t> get_byte_stream(double value1, int scale1, double value2, int scale2, double value3, int scale3, double value4, double scale4);
|
|
|
|
/// helper function to extract a scaled double value from two bytes
|
|
static double get_double(uint8_t lsb, uint8_t msb, int inv_scale, bool is_signed = false); //inv_scale is the reciprocal of scale factor
|
|
bool send_frame(esphome::canbus::Canbus *canbus, bool extended_id = false, bool remote_transmission_request = false) const;
|
|
static bool send_frame(esphome::canbus::Canbus *canbus, uint32_t can_id, const byte_vector& frame, bool extended_id = false, bool remote_transmission_request = false); // static version to send arbitrary frame
|
|
};
|
|
|
|
extern const cb_frame emptyframe; // to return a reference to when no valid frame is found
|
|
|
|
} // namespace solar
|
|
#endif // __SOLAR_CB_FRAME
|