mirror of
https://github.com/esphome/esphome.git
synced 2025-09-15 01:32:19 +01:00
[api] Store plaintext error message in PROGMEM on ESP8266 (#10634)
This commit is contained in:
@@ -10,6 +10,10 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
|
||||||
|
#ifdef USE_ESP8266
|
||||||
|
#include <pgmspace.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace esphome::api {
|
namespace esphome::api {
|
||||||
|
|
||||||
static const char *const TAG = "api.plaintext";
|
static const char *const TAG = "api.plaintext";
|
||||||
@@ -197,11 +201,20 @@ APIError APIPlaintextFrameHelper::read_packet(ReadPacketBuffer *buffer) {
|
|||||||
// We must send at least 3 bytes to be read, so we add
|
// We must send at least 3 bytes to be read, so we add
|
||||||
// a message after the indicator byte to ensures its long
|
// a message after the indicator byte to ensures its long
|
||||||
// enough and can aid in debugging.
|
// enough and can aid in debugging.
|
||||||
const char msg[] = "\x00"
|
static constexpr uint8_t INDICATOR_MSG_SIZE = 19;
|
||||||
"Bad indicator byte";
|
#ifdef USE_ESP8266
|
||||||
|
static const char MSG_PROGMEM[] PROGMEM = "\x00"
|
||||||
|
"Bad indicator byte";
|
||||||
|
char msg[INDICATOR_MSG_SIZE];
|
||||||
|
memcpy_P(msg, MSG_PROGMEM, INDICATOR_MSG_SIZE);
|
||||||
iov[0].iov_base = (void *) msg;
|
iov[0].iov_base = (void *) msg;
|
||||||
iov[0].iov_len = 19;
|
#else
|
||||||
this->write_raw_(iov, 1, 19);
|
static const char MSG[] = "\x00"
|
||||||
|
"Bad indicator byte";
|
||||||
|
iov[0].iov_base = (void *) MSG;
|
||||||
|
#endif
|
||||||
|
iov[0].iov_len = INDICATOR_MSG_SIZE;
|
||||||
|
this->write_raw_(iov, 1, INDICATOR_MSG_SIZE);
|
||||||
}
|
}
|
||||||
return aerr;
|
return aerr;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user