4#ifdef USE_CANOPEN_PDO_STORAGE
18static constexpr uint8_t STORAGE_HIGHEST_SUB = 2;
19static constexpr std::array<uint32_t, 2> STORAGE_CAPS{1, 1};
26 auto *highest =
const_cast<uint8_t *
>(&STORAGE_HIGHEST_SUB);
27 auto *caps =
const_cast<uint32_t *
>(STORAGE_CAPS.data());
40 CO_ReturnError_t err =
41 CO_storage_init(&this->
storage_, this->
co_->CANmodule, this->od_.find(0x1010), this->od_.find(0x1011),
43 if (err != CO_ERROR_NO) {
44 ESP_LOGE(TAG,
"CO_storage_init failed: %d", err);
52static constexpr uint32_t PDO_STORE_INVALID = 0;
59 static_assert(std::is_trivially_copyable_v<PdoParams>,
"PdoParams are stored as bytes");
61 static_assert(
sizeof(
PdoParams) == 44,
"PdoParams stored layout");
84 if (!this->pdo_pref_.load(
reinterpret_cast<uint8_t *
>(this->pdos_), this->pdo_count_() *
sizeof(
PdoParams))) {
85 ESP_LOGW(TAG,
"Stored PDO parameters unreadable, using the defaults");
88 ESP_LOGI(TAG,
"PDO parameters loaded from storage (0x1011 \"load\" restores the defaults)");
98 ESP_LOGI(TAG,
"PDO parameters stored");
100 ESP_LOGE(TAG,
"Storing the PDO parameters failed");
108 ESP_LOGI(TAG,
"PDO parameters: the defaults apply from the next boot");
110 ESP_LOGE(TAG,
"Restoring the default PDO parameters failed");
116 return static_cast<CANopenComponent *
>(
module->CANptr)->store_pdos_() ? ODR_OK : ODR_HW;
120 return static_cast<CANopenComponent *
>(
module->CANptr)->restore_pdo_defaults_() ? ODR_OK : ODR_HW;
bool sync()
Write this preference to flash now; ESP8266, RP2040, LibreTiny and host also write the other pending ...
size_t pdo_count_() const
ESPPreferenceObject pdo_pref_
ESPPreferenceObject pdo_valid_pref_
static ODR_t storage_store(CO_storage_entry_t *entry, CO_CANmodule_t *module)
void add_pdo_storage_od_()
bool restore_pdo_defaults_()
uint32_t pdo_fingerprint_
CO_storage_entry_t storage_entry_
static ODR_t storage_restore(CO_storage_entry_t *entry, CO_CANmodule_t *module)
void add_array(uint16_t index, OD_attr_t attr, uint8_t *count, void *data, OD_size_t elem_len, uint8_t n, OD_attr_t count_attr=ODA_SDO_R)
ESPHOME_LOG_TAG(TAG, "canopen")
constexpr uint32_t fnv1a_hash_extend(uint32_t hash, const char *str)
Extend a FNV-1a hash with additional string data.
ESPPreferences * global_preferences
constexpr uint32_t fnv1a_hash(const char *str)
Calculate a FNV-1a hash of str.
ESPPreferenceObject make_preference(size_t, uint32_t, bool)