mirror of
https://github.com/esphome/esphome.git
synced 2026-01-17 23:44:52 -07:00
Compare commits
10 Commits
tormatic
...
cse7766_st
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f41ebf831d | ||
|
|
91e5191c67 | ||
|
|
325a812202 | ||
|
|
d49c06df35 | ||
|
|
0b676c0daa | ||
|
|
d4bbad9ea2 | ||
|
|
4befd86a96 | ||
|
|
e13743a9c3 | ||
|
|
d3d96afbba | ||
|
|
6e77182523 |
@@ -207,20 +207,24 @@ void CSE7766Component::parse_data_() {
|
||||
|
||||
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE
|
||||
{
|
||||
std::string buf = "Parsed:";
|
||||
// Buffer: 7 + 15 + 33 + 15 + 25 = 95 chars max + null, rounded to 128 for safety margin.
|
||||
// Float sizes with %.4f can be up to 11 chars for large values (e.g., 999999.9999).
|
||||
char buf[128];
|
||||
size_t pos = buf_append_printf(buf, sizeof(buf), 0, "Parsed:");
|
||||
if (have_voltage) {
|
||||
buf += str_sprintf(" V=%fV", voltage);
|
||||
pos = buf_append_printf(buf, sizeof(buf), pos, " V=%.4fV", voltage);
|
||||
}
|
||||
if (have_current) {
|
||||
buf += str_sprintf(" I=%fmA (~%fmA)", current * 1000.0f, calculated_current * 1000.0f);
|
||||
pos = buf_append_printf(buf, sizeof(buf), pos, " I=%.4fmA (~%.4fmA)", current * 1000.0f,
|
||||
calculated_current * 1000.0f);
|
||||
}
|
||||
if (have_power) {
|
||||
buf += str_sprintf(" P=%fW", power);
|
||||
pos = buf_append_printf(buf, sizeof(buf), pos, " P=%.4fW", power);
|
||||
}
|
||||
if (energy != 0.0f) {
|
||||
buf += str_sprintf(" E=%fkWh (%u)", energy, cf_pulses);
|
||||
buf_append_printf(buf, sizeof(buf), pos, " E=%.4fkWh (%u)", energy, cf_pulses);
|
||||
}
|
||||
ESP_LOGVV(TAG, "%s", buf.c_str());
|
||||
ESP_LOGVV(TAG, "%s", buf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -55,7 +55,6 @@ enum MessageType : uint16_t {
|
||||
COMMAND = 0x0106,
|
||||
};
|
||||
|
||||
// Max string length: 7 ("Unknown"/"Command"). Update print() buffer sizes if adding longer strings.
|
||||
inline const char *message_type_to_str(MessageType t) {
|
||||
switch (t) {
|
||||
case STATUS:
|
||||
@@ -84,11 +83,7 @@ struct MessageHeader {
|
||||
}
|
||||
|
||||
std::string print() {
|
||||
// 64 bytes: "MessageHeader: seq " + uint16 + ", len " + uint32 + ", type " + type + safety margin
|
||||
char buf[64];
|
||||
buf_append_printf(buf, sizeof(buf), 0, "MessageHeader: seq %d, len %d, type %s", this->seq, this->len,
|
||||
message_type_to_str(this->type));
|
||||
return buf;
|
||||
return str_sprintf("MessageHeader: seq %d, len %d, type %s", this->seq, this->len, message_type_to_str(this->type));
|
||||
}
|
||||
|
||||
void byteswap() {
|
||||
@@ -136,7 +131,6 @@ inline CoverOperation gate_status_to_cover_operation(GateStatus s) {
|
||||
return COVER_OPERATION_IDLE;
|
||||
}
|
||||
|
||||
// Max string length: 11 ("Ventilating"). Update print() buffer sizes if adding longer strings.
|
||||
inline const char *gate_status_to_str(GateStatus s) {
|
||||
switch (s) {
|
||||
case PAUSED:
|
||||
@@ -176,12 +170,7 @@ struct StatusReply {
|
||||
GateStatus state;
|
||||
uint8_t trailer = 0x0;
|
||||
|
||||
std::string print() {
|
||||
// 48 bytes: "StatusReply: state " (19) + state (11) + safety margin
|
||||
char buf[48];
|
||||
buf_append_printf(buf, sizeof(buf), 0, "StatusReply: state %s", gate_status_to_str(this->state));
|
||||
return buf;
|
||||
}
|
||||
std::string print() { return str_sprintf("StatusReply: state %s", gate_status_to_str(this->state)); }
|
||||
|
||||
void byteswap(){};
|
||||
} __attribute__((packed));
|
||||
@@ -213,12 +202,7 @@ struct CommandRequestReply {
|
||||
CommandRequestReply() = default;
|
||||
CommandRequestReply(GateStatus state) { this->state = state; }
|
||||
|
||||
std::string print() {
|
||||
// 56 bytes: "CommandRequestReply: state " (27) + state (11) + safety margin
|
||||
char buf[56];
|
||||
buf_append_printf(buf, sizeof(buf), 0, "CommandRequestReply: state %s", gate_status_to_str(this->state));
|
||||
return buf;
|
||||
}
|
||||
std::string print() { return str_sprintf("CommandRequestReply: state %s", gate_status_to_str(this->state)); }
|
||||
|
||||
void byteswap() { this->type = convert_big_endian(this->type); }
|
||||
} __attribute__((packed));
|
||||
|
||||
Reference in New Issue
Block a user