Skip to content

Commit

Permalink
Merge pull request #2129 from MichaelDvP/dev
Browse files Browse the repository at this point in the history
scheduler functions #2115, uptime notset-value #2109, device custom name #2073
  • Loading branch information
proddy authored Oct 22, 2024
2 parents 68c9244 + a9d5133 commit 16be0e1
Show file tree
Hide file tree
Showing 9 changed files with 881 additions and 798 deletions.
1 change: 1 addition & 0 deletions interface/src/app/settings/ApplicationSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ const ApplicationSettings = () => {
margin="normal"
select
>
<MenuItem value="cz">Česky (CZ)</MenuItem>
<MenuItem value="de">Deutsch (DE)</MenuItem>
<MenuItem value="en">English (EN)</MenuItem>
<MenuItem value="fr">Français (FR)</MenuItem>
Expand Down
1 change: 1 addition & 0 deletions src/emsdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ class EMSdevice {
static constexpr uint8_t EMS_DEVICE_ID_DHW8 = 0x2F; // last DHW module id?

// 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_UBADevices = 0x07; // EMS connected devices
static constexpr uint16_t EMS_TYPE_DEVICEERROR = 0xBE;
Expand Down
32 changes: 31 additions & 1 deletion src/emsesp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,9 @@ std::string EMSESP::pretty_telegram(std::shared_ptr<const Telegram> telegram) {
if (type_name.empty()) {
// check for global/common types like Version & UBADevices
switch (telegram->type_id) {
case EMSdevice::EMS_TYPE_NAME:
type_name = "DeviceName";
break;
case EMSdevice::EMS_TYPE_VERSION:
type_name = "Version";
break;
Expand Down Expand Up @@ -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
// e.g. 09 0B 02 00 PP V1 V2
void EMSESP::process_version(std::shared_ptr<const Telegram> telegram) {
Expand Down Expand Up @@ -1000,6 +1024,8 @@ void EMSESP::process_version(std::shared_ptr<const Telegram> telegram) {

// add it - will be overwritten if device already exists
(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
Expand Down Expand Up @@ -1050,6 +1076,9 @@ bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
if (telegram->type_id == EMSdevice::EMS_TYPE_VERSION) {
process_version(telegram);
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) {
// do not flood tx-queue with version requests while waiting for km200
if (!wait_km_) {
Expand Down Expand Up @@ -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
if ((response_id_ == 0 || read_id_ > 0) && (txservice_.read_next_tx(data[3], length) == read_id_)) {
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 {
read_next_ = false;
txservice_.send_poll(); // close the bus
Expand Down
1 change: 1 addition & 0 deletions src/emsesp.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class EMSESP {
private:
static std::string device_tostring(const uint8_t device_id);
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 publish_response(std::shared_ptr<const Telegram> telegram);
static void publish_all_loop();
Expand Down
Loading

0 comments on commit 16be0e1

Please sign in to comment.