ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
device_info.cpp
Go to the documentation of this file.
1// Identity (0x1018), device information (0x1000, 0x1008-0x100A) and the default SDO server (0x1200).
2#include "canopen.h"
3
4#ifdef USE_CANOPEN_NODE
5
7#include "esphome/core/log.h"
9
10namespace esphome::canopen {
11
12ESPHOME_LOG_TAG(TAG, "canopen");
13
14// for setup() and dump_config(): setup() stops before it on a failed CAN bus, dump_config() runs anyway
16 if (this->device_name_ == nullptr)
17 this->device_name_ = App.get_name().c_str();
18 if (this->software_version_ == nullptr)
19 this->software_version_ = ESPHOME_VERSION;
20}
21
23 auto &od = this->od_;
24 od.add_var(0x1000, ODA_SDO_R, &this->dev_type_, sizeof(this->dev_type_));
26 od.add_string(0x1008, this->device_name_);
27 if (this->hardware_version_ != nullptr)
28 od.add_string(0x1009, this->hardware_version_);
29 od.add_string(0x100A, this->software_version_);
30 od.add_record(0x1018, {{0, ODA_SDO_R, &this->identity_highest_sub_, 1},
31 {1, ODA_SDO_R, &this->identity_[0], 4},
32 {2, ODA_SDO_R, &this->identity_[1], 4},
33 {3, ODA_SDO_R, &this->identity_[2], 4},
34 {4, ODA_SDO_R, &this->identity_[3], 4}});
35 od.add_record(0x1200, {{0, ODA_SDO_R, &this->sdo_srv_highest_sub_, 1},
36 {1, ODA_SDO_R, &this->sdo_srv_cob_rx_, 4},
37 {2, ODA_SDO_R, &this->sdo_srv_cob_tx_, 4}});
38}
39
41 // the default SDO server (CiA 301: mandatory)
42 cfg.CNT_SDO_SRV = 1;
43 cfg.ENTRY_H1200 = this->od_.find(0x1200);
44}
45
48 ESP_LOGCONFIG(
49 TAG, " Identity: vendor 0x%08" PRIx32 ", product 0x%08" PRIx32 ", revision 0x%08" PRIx32 ", serial 0x%08" PRIx32,
50 this->identity_[0], this->identity_[1], this->identity_[2], this->identity_[3]);
51 ESP_LOGCONFIG(TAG, " Device name: %s, software version: %s", this->device_name_, this->software_version_);
52 if (this->hardware_version_ != nullptr) {
53 ESP_LOGCONFIG(TAG, " Hardware version: %s", this->hardware_version_);
54 }
55}
56
57} // namespace esphome::canopen
58
59#endif // USE_CANOPEN_NODE
const StringRef & get_name() const
Get the name of this Application set by pre_setup().
constexpr const char * c_str() const
Definition string_ref.h:78
std::array< uint32_t, 4 > identity_
Definition canopen.h:347
void config_device_info_(CO_config_t &cfg)
void add_var(uint16_t index, OD_attr_t attr, void *data, OD_size_t len)
Definition od.cpp:30
OD_entry_t * find(uint16_t index)
Definition od.h:73
ESPHOME_LOG_TAG(TAG, "canopen")
Application App
Global storage of Application pointer - only one Application can exist.