Merge pull request #2129 from MichaelDvP/dev

scheduler functions #2115, uptime notset-value #2109, device custom name #2073
This commit is contained in:
Proddy
2024-10-22 22:08:10 +02:00
committed by GitHub
9 changed files with 871 additions and 788 deletions

View File

@@ -369,6 +369,7 @@ const ApplicationSettings = () => {
margin="normal" margin="normal"
select select
> >
<MenuItem value="cz">Česky (CZ)</MenuItem>
<MenuItem value="de">Deutsch (DE)</MenuItem> <MenuItem value="de">Deutsch (DE)</MenuItem>
<MenuItem value="en">English (EN)</MenuItem> <MenuItem value="en">English (EN)</MenuItem>
<MenuItem value="fr">Français (FR)</MenuItem> <MenuItem value="fr">Français (FR)</MenuItem>

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();

File diff suppressed because it is too large Load Diff

View File

@@ -72,6 +72,27 @@ std::deque<Token> exprToTokens(const std::string & expr) {
if (*p == '\0') { if (*p == '\0') {
--p; --p;
} }
} else if (strncmp(p, "int", 3) == 0) {
p += 2;
tokens.emplace_back(Token::Type::Unary, "i", 5);
} else if (strncmp(p, "round", 5) == 0) {
p += 4;
tokens.emplace_back(Token::Type::Unary, "r", 5);
} else if (strncmp(p, "abs", 3) == 0) {
p += 2;
tokens.emplace_back(Token::Type::Unary, "a", 5);
} else if (strncmp(p, "log", 3) == 0) {
p += 2;
tokens.emplace_back(Token::Type::Unary, "l", 5);
} else if (strncmp(p, "exp", 3) == 0) {
p += 2;
tokens.emplace_back(Token::Type::Unary, "e", 5);
} else if (strncmp(p, "sqrt", 4) == 0) {
p += 3;
tokens.emplace_back(Token::Type::Unary, "s", 5);
} else if (strncmp(p, "pow", 3) == 0) {
p += 2;
tokens.emplace_back(Token::Type::Unary, "p", 5);
} else if (*p >= 'a' && *p <= 'z') { } else if (*p >= 'a' && *p <= 'z') {
const auto * b = p; const auto * b = p;
while ((*p >= 'a' && *p <= 'z') || (*p == '_')) { while ((*p >= 'a' && *p <= 'z') || (*p == '_')) {
@@ -448,6 +469,27 @@ std::string calculate(const std::string & expr) {
} }
stack.push_back(to_logic(rhs) == 0 ? "1" : "0"); stack.push_back(to_logic(rhs) == 0 ? "1" : "0");
break; break;
case 'i':
stack.push_back(to_string(std::stoi(rhs)));
break;
case 'r':
stack.push_back(to_string(std::round(std::stod(rhs))));
break;
case 'a':
stack.push_back(to_string(std::abs(std::stod(rhs))));
break;
case 'e':
stack.push_back(to_string(std::exp(std::stod(rhs))));
break;
case 'l':
stack.push_back(to_string(std::log(std::stod(rhs))));
break;
case 's':
stack.push_back(to_string(std::sqrt(std::stod(rhs))));
break;
case 'p':
stack.push_back(to_string(std::pow(std::stod(rhs), 2)));
break;
} }
} break; } break;
case Token::Type::Compare: { case Token::Type::Compare: {

View File

@@ -68,7 +68,8 @@ const char * const languages[] = {EMSESP_LOCALE_EN,
EMSESP_LOCALE_FR, EMSESP_LOCALE_FR,
EMSESP_LOCALE_TR, EMSESP_LOCALE_TR,
EMSESP_LOCALE_IT, EMSESP_LOCALE_IT,
EMSESP_LOCALE_SK}; EMSESP_LOCALE_SK,
EMSESP_LOCALE_CZ};
#endif #endif
static constexpr uint8_t NUM_LANGUAGES = sizeof(languages) / sizeof(const char *); static constexpr uint8_t NUM_LANGUAGES = sizeof(languages) / sizeof(const char *);

View File

@@ -343,9 +343,10 @@ void TxService::send_telegram(const QueuedTxTelegram & tx_telegram) {
message_p = 6; message_p = 6;
} else { } else {
// READ // READ
telegram_raw[4] = telegram->message_data[0]; // #bytes to return, which we assume is the only byte in the message block telegram_raw[4] =
telegram_raw[5] = (telegram->type_id >> 8) - 1; // type, 1st byte, high-byte, subtract 0x100 telegram->message_data[0] > 25 ? 25 : telegram->message_data[0]; // #bytes to return, which we assume is the only byte in the message block
telegram_raw[6] = telegram->type_id & 0xFF; // type, 2nd byte, low-byte telegram_raw[5] = (telegram->type_id >> 8) - 1; // type, 1st byte, high-byte, subtract 0x100
telegram_raw[6] = telegram->type_id & 0xFF; // type, 2nd byte, low-byte
message_p = 7; message_p = 7;
copy_data = false; // there are no more data values after the type_id when reading on EMS+ copy_data = false; // there are no more data values after the type_id when reading on EMS+
} }
@@ -354,6 +355,11 @@ void TxService::send_telegram(const QueuedTxTelegram & tx_telegram) {
telegram_raw[2] = telegram->type_id; telegram_raw[2] = telegram->type_id;
telegram_raw[3] = telegram->offset; telegram_raw[3] = telegram->offset;
message_p = 4; message_p = 4;
if (telegram->operation == Telegram::Operation::TX_READ) {
telegram_raw[4] = telegram->message_data[0] > 27 ? 27 : telegram->message_data[0];
message_p = 5;
copy_data = false; // there are no more data value
}
} }
if (copy_data) { if (copy_data) {

View File

@@ -50,7 +50,7 @@ static constexpr int8_t EMS_VALUE_INT8_NOTSET = 0x7F; // for signed 8-
static constexpr uint16_t EMS_VALUE_UINT16_NOTSET = 0x7D00; // 32000: for 2-byte unsigned shorts static constexpr uint16_t EMS_VALUE_UINT16_NOTSET = 0x7D00; // 32000: for 2-byte unsigned shorts
static constexpr int16_t EMS_VALUE_INT16_NOTSET = 0x7D00; // 32000: for 2-byte signed shorts static constexpr int16_t EMS_VALUE_INT16_NOTSET = 0x7D00; // 32000: for 2-byte signed shorts
static constexpr uint32_t EMS_VALUE_UINT24_NOTSET = 0x00FFFFFF; // for 3-byte longs static constexpr uint32_t EMS_VALUE_UINT24_NOTSET = 0x00FFFFFF; // for 3-byte longs
static constexpr uint32_t EMS_VALUE_UINT32_NOTSET = 0xFFFFFFFF; // for 4-byte longs static constexpr uint32_t EMS_VALUE_UINT32_NOTSET = 0xFFFFFF00; // for 4-byte longs
static constexpr uint8_t EMS_MAX_TELEGRAM_LENGTH = 32; // max length of a complete EMS telegram static constexpr uint8_t EMS_MAX_TELEGRAM_LENGTH = 32; // max length of a complete EMS telegram
static constexpr uint8_t EMS_MAX_TELEGRAM_MESSAGE_LENGTH = 27; // max length of message block, assuming EMS1.0 static constexpr uint8_t EMS_MAX_TELEGRAM_MESSAGE_LENGTH = 27; // max length of message block, assuming EMS1.0