mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 08:49:52 +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) {
|
} else if ((it.telegram_->operation) == Telegram::Operation::TX_WRITE) {
|
||||||
op = read_flash_string(F("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.id_,
|
||||||
((it.retry_) ? '*' : ' '),
|
((it.retry_) ? '*' : ' '),
|
||||||
op.c_str(),
|
op.c_str(),
|
||||||
pretty_telegram(it.telegram_).c_str(),
|
pretty_telegram(it.telegram_).c_str());
|
||||||
it.telegram_->offset);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,7 +287,7 @@ std::string EMSESP::device_tostring(const uint8_t device_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// created a pretty print telegram as a text string
|
// 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) {
|
std::string EMSESP::pretty_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||||
uint8_t src = telegram->src & 0x7F;
|
uint8_t src = telegram->src & 0x7F;
|
||||||
uint8_t dest = telegram->dest & 0x7F;
|
uint8_t dest = telegram->dest & 0x7F;
|
||||||
@@ -337,14 +336,14 @@ std::string EMSESP::pretty_telegram(std::shared_ptr<const Telegram> telegram) {
|
|||||||
if (offset) {
|
if (offset) {
|
||||||
snprintf_P(&str[0],
|
snprintf_P(&str[0],
|
||||||
str.capacity() + 1,
|
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_name.c_str(),
|
||||||
src,
|
src,
|
||||||
dest_name.c_str(),
|
dest_name.c_str(),
|
||||||
dest,
|
dest,
|
||||||
type_name.c_str(),
|
type_name.c_str(),
|
||||||
telegram->type_id,
|
telegram->type_id,
|
||||||
telegram->to_string().c_str(),
|
telegram->to_string_message().c_str(),
|
||||||
offset);
|
offset);
|
||||||
} else {
|
} else {
|
||||||
snprintf_P(&str[0],
|
snprintf_P(&str[0],
|
||||||
@@ -356,7 +355,7 @@ std::string EMSESP::pretty_telegram(std::shared_ptr<const Telegram> telegram) {
|
|||||||
dest,
|
dest,
|
||||||
type_name.c_str(),
|
type_name.c_str(),
|
||||||
telegram->type_id,
|
telegram->type_id,
|
||||||
telegram->to_string().c_str());
|
telegram->to_string_message().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return 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) {
|
for (const auto & emsdevice : emsdevices) {
|
||||||
if (emsdevice) {
|
if (emsdevice) {
|
||||||
if (emsdevice->is_device_id(device_id)) {
|
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->product_id(product_id);
|
||||||
emsdevice->version(version);
|
emsdevice->version(version);
|
||||||
// only set brand if it doesn't already exist
|
// 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 {
|
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 data[EMS_MAX_TELEGRAM_LENGTH];
|
||||||
uint8_t length = 0;
|
uint8_t length = 0;
|
||||||
data[0] = this->src ^ RxService::ems_mask();
|
data[0] = this->src ^ RxService::ems_mask();
|
||||||
@@ -122,9 +118,13 @@ std::string Telegram::to_string() const {
|
|||||||
return Helpers::data_to_hex(data, length);
|
return Helpers::data_to_hex(data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns telegram's full telegram message in hex
|
// returns telegram's message body only, in hex
|
||||||
std::string Telegram::to_string(const uint8_t * telegram, uint8_t length) const {
|
std::string Telegram::to_string_message() const {
|
||||||
return Helpers::data_to_hex(telegram, length);
|
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)
|
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"),
|
LOG_DEBUG(F("Sending %s Tx [#%d], telegram: %s"),
|
||||||
(telegram->operation == Telegram::Operation::TX_WRITE) ? F("write") : F("read"),
|
(telegram->operation == Telegram::Operation::TX_WRITE) ? F("write") : F("read"),
|
||||||
tx_telegram.id_,
|
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
|
// send the telegram to the UART Tx
|
||||||
uint16_t status = EMSuart::transmit(telegram_raw, length);
|
uint16_t status = EMSuart::transmit(telegram_raw, length);
|
||||||
|
|||||||
@@ -83,8 +83,8 @@ class Telegram {
|
|||||||
TX_WRITE,
|
TX_WRITE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string to_string_message() const;
|
||||||
std::string to_string() 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
|
// reads a bit value from a given telegram position
|
||||||
void read_bitvalue(uint8_t & value, const uint8_t index, const uint8_t bit) const {
|
void read_bitvalue(uint8_t & value, const uint8_t index, const uint8_t bit) const {
|
||||||
|
|||||||
Reference in New Issue
Block a user