read telegram 0x01 offset 27 device name

This commit is contained in:
MichaelDvP
2024-10-22 08:01:04 +02:00
parent 21b2fb46de
commit 614f05a286
3 changed files with 33 additions and 1 deletions

View File

@@ -412,6 +412,7 @@ class EMSdevice {
static constexpr uint8_t EMS_DEVICE_ID_DHW8 = 0x2F; // last DHW module id? static constexpr uint8_t EMS_DEVICE_ID_DHW8 = 0x2F; // last DHW module id?
// generic type IDs // generic type IDs
static constexpr uint16_t EMS_TYPE_NAME = 0x01; // device config for ems devices, name ascii on offset 27ff for ems+
static constexpr uint16_t EMS_TYPE_VERSION = 0x02; // type ID for Version information. Generic across all EMS devices. static constexpr uint16_t EMS_TYPE_VERSION = 0x02; // type ID for Version information. Generic across all EMS devices.
static constexpr uint16_t EMS_TYPE_UBADevices = 0x07; // EMS connected devices static constexpr uint16_t EMS_TYPE_UBADevices = 0x07; // EMS connected devices
static constexpr uint16_t EMS_TYPE_DEVICEERROR = 0xBE; static constexpr uint16_t EMS_TYPE_DEVICEERROR = 0xBE;

View File

@@ -881,6 +881,9 @@ std::string EMSESP::pretty_telegram(std::shared_ptr<const Telegram> telegram) {
if (type_name.empty()) { if (type_name.empty()) {
// check for global/common types like Version & UBADevices // check for global/common types like Version & UBADevices
switch (telegram->type_id) { switch (telegram->type_id) {
case EMSdevice::EMS_TYPE_NAME:
type_name = "DeviceName";
break;
case EMSdevice::EMS_TYPE_VERSION: case EMSdevice::EMS_TYPE_VERSION:
type_name = "Version"; type_name = "Version";
break; break;
@@ -959,6 +962,27 @@ void EMSESP::process_UBADevices(std::shared_ptr<const Telegram> telegram) {
} }
} }
// read deviceName from telegram 0x01 offset 27 and set it to custom name
void EMSESP::process_deviceName(std::shared_ptr<const Telegram> telegram) {
// exit if only part of name fields
if (telegram->offset > 27 || (telegram->offset + telegram->message_length) < 29) {
return;
}
char name[16];
uint8_t len = telegram->offset + telegram->message_length - 27;
strlcpy(name, (const char *)&telegram->message_data[27 - telegram->offset], len < 16 ? len : 16);
if (strlen(name)) {
webCustomizationService.read([&](WebCustomization const & settings) {
for (EntityCustomization e : settings.entityCustomizations) {
if ((e.device_id == telegram->src) && e.custom_name.empty()) {
e.custom_name = name;
break;
}
}
});
}
}
// process the Version telegram (type 0x02), which is a common type // process the Version telegram (type 0x02), which is a common type
// e.g. 09 0B 02 00 PP V1 V2 // e.g. 09 0B 02 00 PP V1 V2
void EMSESP::process_version(std::shared_ptr<const Telegram> telegram) { void EMSESP::process_version(std::shared_ptr<const Telegram> telegram) {
@@ -1000,6 +1024,8 @@ void EMSESP::process_version(std::shared_ptr<const Telegram> telegram) {
// add it - will be overwritten if device already exists // add it - will be overwritten if device already exists
(void)add_device(device_id, product_id, version, brand); (void)add_device(device_id, product_id, version, brand);
// request the deviceName from telegram 0x01
send_read_request(EMSdevice::EMS_TYPE_NAME, device_id, 27);
} }
// find the device object that matches the deviceID and see if it has a matching telegram type handler // find the device object that matches the deviceID and see if it has a matching telegram type handler
@@ -1050,6 +1076,9 @@ bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
if (telegram->type_id == EMSdevice::EMS_TYPE_VERSION) { if (telegram->type_id == EMSdevice::EMS_TYPE_VERSION) {
process_version(telegram); process_version(telegram);
return true; return true;
} else if (telegram->type_id == EMSdevice::EMS_TYPE_NAME) {
process_deviceName(telegram);
return true;
} else if (telegram->type_id == EMSdevice::EMS_TYPE_UBADevices) { } else if (telegram->type_id == EMSdevice::EMS_TYPE_UBADevices) {
// do not flood tx-queue with version requests while waiting for km200 // do not flood tx-queue with version requests while waiting for km200
if (!wait_km_) { if (!wait_km_) {
@@ -1444,7 +1473,8 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
// not for response to raw send commands without read_id set // not for response to raw send commands without read_id set
if ((response_id_ == 0 || read_id_ > 0) && (txservice_.read_next_tx(data[3], length) == read_id_)) { if ((response_id_ == 0 || read_id_ > 0) && (txservice_.read_next_tx(data[3], length) == read_id_)) {
read_next_ = true; read_next_ = true;
txservice_.send(); txservice_.send(); // read next part withing same poll or:
// txservice_.send_poll(); // close the bus, next request in new poll
} else { } else {
read_next_ = false; read_next_ = false;
txservice_.send_poll(); // close the bus txservice_.send_poll(); // close the bus

View File

@@ -249,6 +249,7 @@ class EMSESP {
private: private:
static std::string device_tostring(const uint8_t device_id); static std::string device_tostring(const uint8_t device_id);
static void process_UBADevices(std::shared_ptr<const Telegram> telegram); static void process_UBADevices(std::shared_ptr<const Telegram> telegram);
static void process_deviceName(std::shared_ptr<const Telegram> telegram);
static void process_version(std::shared_ptr<const Telegram> telegram); static void process_version(std::shared_ptr<const Telegram> telegram);
static void publish_response(std::shared_ptr<const Telegram> telegram); static void publish_response(std::shared_ptr<const Telegram> telegram);
static void publish_all_loop(); static void publish_all_loop();