39 lines
1.9 KiB
C++
39 lines
1.9 KiB
C++
// NB! A lot of comments in .h and .cpp files were auto generated by CoPilot. Applicable comments have been retained, others removed.
|
|
|
|
#ifndef __SOLAR_CBF_CACHE
|
|
#define __SOLAR_CBF_CACHE
|
|
#include <utility>
|
|
#include <map>
|
|
#include "esphome.h"
|
|
#include "cbf_store_pylon.h"
|
|
#include "cbf_cache_item.h"
|
|
using namespace esphome;
|
|
|
|
namespace solar
|
|
{
|
|
class cbf_cache {
|
|
public:
|
|
typedef std::pair<uint32_t, bool> canid_rtr_t; // pair of CAN ID and RTR flag
|
|
std::map<canid_rtr_t, cbf_cache_item> cache_map; // map of rtr/CAN IDs to cache items
|
|
cbf_cache() = default;
|
|
void clear();
|
|
int size() const;
|
|
bool hasitem(canid_rtr_t key) const;
|
|
bool hasitem(uint32_t can_id, bool remote_transmission_request) const;
|
|
cbf_cache_item& getitem(uint32_t can_id, bool remote_transmission_request);
|
|
const cbf_cache_item& getitem(uint32_t can_id, bool remote_transmission_request) const;
|
|
// Add a new item to the cache or update an existing one
|
|
bool additem(const cbf_store& item);
|
|
const cb_frame& get_frame(canid_rtr_t key) const;
|
|
const cb_frame& get_frame(uint32_t can_id, bool remote_transmission_request) const;
|
|
virtual ~cbf_cache() = default; // virtual destructor for base class
|
|
bool send_frame(esphome::canbus::Canbus *canbus, uint32_t can_id, bool extended_id = false, bool remote_transmission_request = false);
|
|
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
|
|
static bool send_request(esphome::canbus::Canbus *canbus, uint32_t can_id, bool extended_id = false); // static version to send remote transmission request frame
|
|
// using default (compiler auto generated) copy and move constructors and assignment operators
|
|
|
|
};
|
|
|
|
} // namespace solar
|
|
|
|
#endif // __SOLAR_CBF_CACHE
|