mirror of
https://github.com/esphome/esphome.git
synced 2025-11-19 08:15:49 +00:00
Compare commits
11 Commits
2024.12.0b
...
2024.12.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe0700166a | ||
|
|
d28cf011d1 | ||
|
|
434879ea04 | ||
|
|
0f0b829bc6 | ||
|
|
d330e73c1e | ||
|
|
561d92d402 | ||
|
|
1a69236473 | ||
|
|
c86ea99145 | ||
|
|
7661609049 | ||
|
|
c38826824f | ||
|
|
e890486043 |
@@ -27,6 +27,9 @@ namespace esp32_ble {
|
||||
|
||||
static const char *const TAG = "esp32_ble";
|
||||
|
||||
static RAMAllocator<BLEEvent> EVENT_ALLOCATOR( // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
RAMAllocator<BLEEvent>::ALLOW_FAILURE | RAMAllocator<BLEEvent>::ALLOC_INTERNAL);
|
||||
|
||||
void ESP32BLE::setup() {
|
||||
global_ble = this;
|
||||
ESP_LOGCONFIG(TAG, "Setting up BLE...");
|
||||
@@ -322,7 +325,8 @@ void ESP32BLE::loop() {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
delete ble_event; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
ble_event->~BLEEvent();
|
||||
EVENT_ALLOCATOR.deallocate(ble_event, 1);
|
||||
ble_event = this->ble_events_.pop();
|
||||
}
|
||||
if (this->advertising_ != nullptr) {
|
||||
@@ -331,9 +335,14 @@ void ESP32BLE::loop() {
|
||||
}
|
||||
|
||||
void ESP32BLE::gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) {
|
||||
BLEEvent *new_event = new BLEEvent(event, param); // NOLINT(cppcoreguidelines-owning-memory)
|
||||
BLEEvent *new_event = EVENT_ALLOCATOR.allocate(1);
|
||||
if (new_event == nullptr) {
|
||||
// Memory too fragmented to allocate new event. Can only drop it until memory comes back
|
||||
return;
|
||||
}
|
||||
new (new_event) BLEEvent(event, param);
|
||||
global_ble->ble_events_.push(new_event);
|
||||
} // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
|
||||
} // NOLINT(clang-analyzer-unix.Malloc)
|
||||
|
||||
void ESP32BLE::real_gap_event_handler_(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) {
|
||||
ESP_LOGV(TAG, "(BLE) gap_event_handler - %d", event);
|
||||
@@ -344,9 +353,14 @@ void ESP32BLE::real_gap_event_handler_(esp_gap_ble_cb_event_t event, esp_ble_gap
|
||||
|
||||
void ESP32BLE::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
|
||||
esp_ble_gatts_cb_param_t *param) {
|
||||
BLEEvent *new_event = new BLEEvent(event, gatts_if, param); // NOLINT(cppcoreguidelines-owning-memory)
|
||||
BLEEvent *new_event = EVENT_ALLOCATOR.allocate(1);
|
||||
if (new_event == nullptr) {
|
||||
// Memory too fragmented to allocate new event. Can only drop it until memory comes back
|
||||
return;
|
||||
}
|
||||
new (new_event) BLEEvent(event, gatts_if, param);
|
||||
global_ble->ble_events_.push(new_event);
|
||||
} // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
|
||||
} // NOLINT(clang-analyzer-unix.Malloc)
|
||||
|
||||
void ESP32BLE::real_gatts_event_handler_(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
|
||||
esp_ble_gatts_cb_param_t *param) {
|
||||
@@ -358,9 +372,14 @@ void ESP32BLE::real_gatts_event_handler_(esp_gatts_cb_event_t event, esp_gatt_if
|
||||
|
||||
void ESP32BLE::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
|
||||
esp_ble_gattc_cb_param_t *param) {
|
||||
BLEEvent *new_event = new BLEEvent(event, gattc_if, param); // NOLINT(cppcoreguidelines-owning-memory)
|
||||
BLEEvent *new_event = EVENT_ALLOCATOR.allocate(1);
|
||||
if (new_event == nullptr) {
|
||||
// Memory too fragmented to allocate new event. Can only drop it until memory comes back
|
||||
return;
|
||||
}
|
||||
new (new_event) BLEEvent(event, gattc_if, param);
|
||||
global_ble->ble_events_.push(new_event);
|
||||
} // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
|
||||
} // NOLINT(clang-analyzer-unix.Malloc)
|
||||
|
||||
void ESP32BLE::real_gattc_event_handler_(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
|
||||
esp_ble_gattc_cb_param_t *param) {
|
||||
|
||||
@@ -51,8 +51,11 @@ CONF_IGNORE_MISSING_GLYPHS = "ignore_missing_glyphs"
|
||||
# Cache loaded freetype fonts
|
||||
class FontCache(dict):
|
||||
def __missing__(self, key):
|
||||
res = self[key] = freetype.Face(key)
|
||||
return res
|
||||
try:
|
||||
res = self[key] = freetype.Face(key)
|
||||
return res
|
||||
except freetype.FT_Exception as e:
|
||||
raise cv.Invalid(f"Could not load Font file {key}: {e}") from e
|
||||
|
||||
|
||||
FONT_CACHE = FontCache()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Constants used by esphome."""
|
||||
|
||||
__version__ = "2024.12.0b2"
|
||||
__version__ = "2024.12.1"
|
||||
|
||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||
VALID_SUBSTITUTIONS_CHARACTERS = (
|
||||
|
||||
@@ -13,8 +13,8 @@ static const char *const TAG = "ring_buffer";
|
||||
|
||||
RingBuffer::~RingBuffer() {
|
||||
if (this->handle_ != nullptr) {
|
||||
vStreamBufferDelete(this->handle_);
|
||||
ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||
vRingbufferDelete(this->handle_);
|
||||
RAMAllocator<uint8_t> allocator(RAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||
allocator.deallocate(this->storage_, this->size_);
|
||||
}
|
||||
}
|
||||
@@ -22,26 +22,49 @@ RingBuffer::~RingBuffer() {
|
||||
std::unique_ptr<RingBuffer> RingBuffer::create(size_t len) {
|
||||
std::unique_ptr<RingBuffer> rb = make_unique<RingBuffer>();
|
||||
|
||||
rb->size_ = len + 1;
|
||||
rb->size_ = len;
|
||||
|
||||
ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||
RAMAllocator<uint8_t> allocator(RAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||
rb->storage_ = allocator.allocate(rb->size_);
|
||||
if (rb->storage_ == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
rb->handle_ = xStreamBufferCreateStatic(rb->size_, 1, rb->storage_, &rb->structure_);
|
||||
rb->handle_ = xRingbufferCreateStatic(rb->size_, RINGBUF_TYPE_BYTEBUF, rb->storage_, &rb->structure_);
|
||||
ESP_LOGD(TAG, "Created ring buffer with size %u", len);
|
||||
|
||||
return rb;
|
||||
}
|
||||
|
||||
size_t RingBuffer::read(void *data, size_t len, TickType_t ticks_to_wait) {
|
||||
if (ticks_to_wait > 0)
|
||||
xStreamBufferSetTriggerLevel(this->handle_, len);
|
||||
size_t bytes_read = 0;
|
||||
|
||||
size_t bytes_read = xStreamBufferReceive(this->handle_, data, len, ticks_to_wait);
|
||||
void *buffer_data = xRingbufferReceiveUpTo(this->handle_, &bytes_read, ticks_to_wait, len);
|
||||
|
||||
xStreamBufferSetTriggerLevel(this->handle_, 1);
|
||||
if (buffer_data == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::memcpy(data, buffer_data, bytes_read);
|
||||
|
||||
vRingbufferReturnItem(this->handle_, buffer_data);
|
||||
|
||||
if (bytes_read < len) {
|
||||
// Data may have wrapped around, so read a second time to receive the remainder
|
||||
size_t follow_up_bytes_read = 0;
|
||||
size_t bytes_remaining = len - bytes_read;
|
||||
|
||||
buffer_data = xRingbufferReceiveUpTo(this->handle_, &follow_up_bytes_read, 0, bytes_remaining);
|
||||
|
||||
if (buffer_data == nullptr) {
|
||||
return bytes_read;
|
||||
}
|
||||
|
||||
std::memcpy((void *) ((uint8_t *) (data) + bytes_read), buffer_data, follow_up_bytes_read);
|
||||
|
||||
vRingbufferReturnItem(this->handle_, buffer_data);
|
||||
bytes_read += follow_up_bytes_read;
|
||||
}
|
||||
|
||||
return bytes_read;
|
||||
}
|
||||
@@ -49,22 +72,55 @@ size_t RingBuffer::read(void *data, size_t len, TickType_t ticks_to_wait) {
|
||||
size_t RingBuffer::write(const void *data, size_t len) {
|
||||
size_t free = this->free();
|
||||
if (free < len) {
|
||||
size_t needed = len - free;
|
||||
uint8_t discard[needed];
|
||||
xStreamBufferReceive(this->handle_, discard, needed, 0);
|
||||
// Free enough space in the ring buffer to fit the new data
|
||||
this->discard_bytes_(len - free);
|
||||
}
|
||||
return xStreamBufferSend(this->handle_, data, len, 0);
|
||||
return this->write_without_replacement(data, len, 0);
|
||||
}
|
||||
|
||||
size_t RingBuffer::write_without_replacement(const void *data, size_t len, TickType_t ticks_to_wait) {
|
||||
return xStreamBufferSend(this->handle_, data, len, ticks_to_wait);
|
||||
if (!xRingbufferSend(this->handle_, data, len, ticks_to_wait)) {
|
||||
// Couldn't fit all the data, so only write what will fit
|
||||
size_t free = std::min(this->free(), len);
|
||||
if (xRingbufferSend(this->handle_, data, free, 0)) {
|
||||
return free;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t RingBuffer::available() const { return xStreamBufferBytesAvailable(this->handle_); }
|
||||
size_t RingBuffer::available() const {
|
||||
UBaseType_t ux_items_waiting = 0;
|
||||
vRingbufferGetInfo(this->handle_, nullptr, nullptr, nullptr, nullptr, &ux_items_waiting);
|
||||
return ux_items_waiting;
|
||||
}
|
||||
|
||||
size_t RingBuffer::free() const { return xStreamBufferSpacesAvailable(this->handle_); }
|
||||
size_t RingBuffer::free() const { return xRingbufferGetCurFreeSize(this->handle_); }
|
||||
|
||||
BaseType_t RingBuffer::reset() { return xStreamBufferReset(this->handle_); }
|
||||
BaseType_t RingBuffer::reset() {
|
||||
// Discards all the available data
|
||||
return this->discard_bytes_(this->available());
|
||||
}
|
||||
|
||||
bool RingBuffer::discard_bytes_(size_t discard_bytes) {
|
||||
size_t bytes_read = 0;
|
||||
|
||||
void *buffer_data = xRingbufferReceiveUpTo(this->handle_, &bytes_read, 0, discard_bytes);
|
||||
if (buffer_data != nullptr)
|
||||
vRingbufferReturnItem(this->handle_, buffer_data);
|
||||
|
||||
if (bytes_read < discard_bytes) {
|
||||
size_t wrapped_bytes_read = 0;
|
||||
buffer_data = xRingbufferReceiveUpTo(this->handle_, &wrapped_bytes_read, 0, discard_bytes - bytes_read);
|
||||
if (buffer_data != nullptr) {
|
||||
vRingbufferReturnItem(this->handle_, buffer_data);
|
||||
bytes_read += wrapped_bytes_read;
|
||||
}
|
||||
}
|
||||
|
||||
return (bytes_read == discard_bytes);
|
||||
}
|
||||
|
||||
} // namespace esphome
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#ifdef USE_ESP32
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/stream_buffer.h>
|
||||
#include <freertos/ringbuf.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
@@ -82,9 +82,14 @@ class RingBuffer {
|
||||
static std::unique_ptr<RingBuffer> create(size_t len);
|
||||
|
||||
protected:
|
||||
StreamBufferHandle_t handle_;
|
||||
StaticStreamBuffer_t structure_;
|
||||
uint8_t *storage_;
|
||||
/// @brief Discards data from the ring buffer.
|
||||
/// @param discard_bytes amount of bytes to discard
|
||||
/// @return True if all bytes were successfully discarded, false otherwise
|
||||
bool discard_bytes_(size_t discard_bytes);
|
||||
|
||||
RingbufHandle_t handle_{nullptr};
|
||||
StaticRingbuffer_t structure_;
|
||||
uint8_t *storage_{nullptr};
|
||||
size_t size_{0};
|
||||
};
|
||||
|
||||
|
||||
@@ -108,6 +108,12 @@ def is_authenticated(handler: BaseHandler) -> bool:
|
||||
return True
|
||||
|
||||
if settings.using_auth:
|
||||
if auth_header := handler.request.headers.get("Authorization"):
|
||||
assert isinstance(auth_header, str)
|
||||
if auth_header.startswith("Basic "):
|
||||
auth_decoded = base64.b64decode(auth_header[6:]).decode()
|
||||
username, password = auth_decoded.split(":", 1)
|
||||
return settings.check_password(username, password)
|
||||
return handler.get_secure_cookie(AUTH_COOKIE_NAME) == COOKIE_AUTHENTICATED_YES
|
||||
|
||||
return True
|
||||
|
||||
@@ -12,7 +12,7 @@ pyserial==3.5
|
||||
platformio==6.1.16 # When updating platformio, also update Dockerfile
|
||||
esptool==4.7.0
|
||||
click==8.1.7
|
||||
esphome-dashboard==20241120.0
|
||||
esphome-dashboard==20241217.1
|
||||
aioesphomeapi==24.6.2
|
||||
zeroconf==0.132.2
|
||||
puremagic==1.27
|
||||
|
||||
Reference in New Issue
Block a user