mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
fix telegram to_string
This commit is contained in:
@@ -215,12 +215,11 @@ void EMSESP::show_ems(uuid::console::Shell & shell) {
|
||||
} else if ((it.telegram_->operation) == Telegram::Operation::TX_WRITE) {
|
||||
op = read_flash_string(F("WRITE"));
|
||||
}
|
||||
shell.printfln(F(" [%02d%c] %s %s (offset %d)"),
|
||||
shell.printfln(F(" [%02d%c] %s %s"),
|
||||
it.id_,
|
||||
((it.retry_) ? '*' : ' '),
|
||||
op.c_str(),
|
||||
pretty_telegram(it.telegram_).c_str(),
|
||||
it.telegram_->offset);
|
||||
pretty_telegram(it.telegram_).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +287,7 @@ std::string EMSESP::device_tostring(const uint8_t device_id) {
|
||||
}
|
||||
|
||||
// created a pretty print telegram as a text string
|
||||
// e.g. Boiler(0x08) -> Me(0x0B), Version(0x02), data: 7B 06 01 00 00 00 00 00 00 04 (#data=10)
|
||||
// e.g. Boiler(0x08) -> Me(0x0B), Version(0x02), data: 7B 06 01 00 00 00 00 00 00 04 (offset 1)
|
||||
std::string EMSESP::pretty_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||
uint8_t src = telegram->src & 0x7F;
|
||||
uint8_t dest = telegram->dest & 0x7F;
|
||||
@@ -337,14 +336,14 @@ std::string EMSESP::pretty_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||
if (offset) {
|
||||
snprintf_P(&str[0],
|
||||
str.capacity() + 1,
|
||||
PSTR("%s(0x%02X) -> %s(0x%02X), %s(0x%02X), data: %s @offset %d"),
|
||||
PSTR("%s(0x%02X) -> %s(0x%02X), %s(0x%02X), data: %s (offset %d)"),
|
||||
src_name.c_str(),
|
||||
src,
|
||||
dest_name.c_str(),
|
||||
dest,
|
||||
type_name.c_str(),
|
||||
telegram->type_id,
|
||||
telegram->to_string().c_str(),
|
||||
telegram->to_string_message().c_str(),
|
||||
offset);
|
||||
} else {
|
||||
snprintf_P(&str[0],
|
||||
@@ -356,7 +355,7 @@ std::string EMSESP::pretty_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||
dest,
|
||||
type_name.c_str(),
|
||||
telegram->type_id,
|
||||
telegram->to_string().c_str());
|
||||
telegram->to_string_message().c_str());
|
||||
}
|
||||
|
||||
return str;
|
||||
@@ -566,7 +565,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, std::
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
if (emsdevice) {
|
||||
if (emsdevice->is_device_id(device_id)) {
|
||||
LOG_DEBUG(F("Updating details to already existing device ID 0x%02X"), device_id);
|
||||
LOG_DEBUG(F("Updating details on already existing device ID 0x%02X"), device_id);
|
||||
emsdevice->product_id(product_id);
|
||||
emsdevice->version(version);
|
||||
// only set brand if it doesn't already exist
|
||||
|
||||
@@ -78,12 +78,8 @@ Telegram::Telegram(const uint8_t operation,
|
||||
}
|
||||
}
|
||||
|
||||
// returns telegram's message data bytes in hex
|
||||
// returns telegram as data bytes in hex (excluding CRC)
|
||||
std::string Telegram::to_string() const {
|
||||
if (this->message_length == 0) {
|
||||
return read_flash_string(F("<empty>"));
|
||||
}
|
||||
|
||||
uint8_t data[EMS_MAX_TELEGRAM_LENGTH];
|
||||
uint8_t length = 0;
|
||||
data[0] = this->src ^ RxService::ems_mask();
|
||||
@@ -122,9 +118,13 @@ std::string Telegram::to_string() const {
|
||||
return Helpers::data_to_hex(data, length);
|
||||
}
|
||||
|
||||
// returns telegram's full telegram message in hex
|
||||
std::string Telegram::to_string(const uint8_t * telegram, uint8_t length) const {
|
||||
return Helpers::data_to_hex(telegram, length);
|
||||
// returns telegram's message body only, in hex
|
||||
std::string Telegram::to_string_message() const {
|
||||
if (this->message_length == 0) {
|
||||
return read_flash_string(F("<empty>"));
|
||||
}
|
||||
|
||||
return Helpers::data_to_hex(this->message_data, this->message_length);
|
||||
}
|
||||
|
||||
RxService::QueuedRxTelegram::QueuedRxTelegram(uint16_t id, std::shared_ptr<Telegram> && telegram)
|
||||
@@ -380,7 +380,7 @@ void TxService::send_telegram(const QueuedTxTelegram & tx_telegram) {
|
||||
LOG_DEBUG(F("Sending %s Tx [#%d], telegram: %s"),
|
||||
(telegram->operation == Telegram::Operation::TX_WRITE) ? F("write") : F("read"),
|
||||
tx_telegram.id_,
|
||||
telegram->to_string(telegram_raw, length).c_str());
|
||||
Helpers::data_to_hex(telegram_raw, length).c_str());
|
||||
|
||||
// send the telegram to the UART Tx
|
||||
uint16_t status = EMSuart::transmit(telegram_raw, length);
|
||||
|
||||
@@ -83,8 +83,8 @@ class Telegram {
|
||||
TX_WRITE,
|
||||
};
|
||||
|
||||
std::string to_string_message() const;
|
||||
std::string to_string() const;
|
||||
std::string to_string(const uint8_t * telegram, uint8_t length) const;
|
||||
|
||||
// reads a bit value from a given telegram position
|
||||
void read_bitvalue(uint8_t & value, const uint8_t index, const uint8_t bit) const {
|
||||
|
||||
Reference in New Issue
Block a user