Solar/cbf_cache.h
2025-09-03 22:38:18 +02:00

36 lines
1.6 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:
std::map<uint32_t, cbf_cache_item> cache_map; // map of CAN IDs to cache items
cbf_cache() = default;
void clear();
int size() const;
bool hasitem(uint32_t can_id) const;
cbf_cache_item& getitem(uint32_t can_id);
const cbf_cache_item& getitem(uint32_t can_id) const;
// Add a new item to the cache or update an existing one
bool additem(const cbf_store& item);
const cb_frame& get_frame(uint32_t can_id) 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