8000 Fixes for #328 · James-sjec/esp32-snippets@20214be · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 20214be

Browse files
committed
Fixes for nkolban#328
1 parent 0a4e277 commit 20214be

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

cpp_utils/BLECharacteristic.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,16 @@ void BLECharacteristic::handleGATTServerEvent(
327327
case ESP_GATTS_READ_EVT: {
328328
if (param->read.handle == m_handle) {
329329

330-
if (m_pCallbacks != nullptr) {
331-
m_pCallbacks->onRead(this); // Invoke the read callback.
332-
}
330+
333331

334332
// Here's an interesting thing. The read request has the option of saying whether we need a response
335333
// or not. What would it "mean" to receive a read request and NOT send a response back? That feels like
336334
// a very strange read.
337335
//
338336
// We have to handle the case where the data we wish to send back to the client is greater than the maximum
339-
// packet size of 22 bytes. In this case, we become responsible for chunking the data into uints of 22 bytes.
340-
// The apparent algorithm is as follows.
337+
// packet size of 22 bytes. In this case, we become responsible for chunking the data into units of 22 bytes.
338+
// The apparent algorithm is as follows:
339+
//
341340
// If the is_long flag is set then this is a follow on from an original read and we will already have sent at least 22 bytes.
342341
// If the is_long flag is not set then we need to check how much data we are going to send. If we are sending LESS than
343342
// 22 bytes, then we "just" send it and thats the end of the story.
@@ -359,8 +358,10 @@ void BLECharacteristic::handleGATTServerEvent(
359358
if (param->read.need_rsp) {
360359
ESP_LOGD(LOG_TAG, "Sending a response (esp_ble_gatts_send_response)");
361360
esp_gatt_rsp_t rsp;
362-
std::string value = m_value.getValue();
361+
363362
if (param->read.is_long) {
363+
std::string value = m_value.getValue();
364+
364365
if (value.length() - m_value.getReadOffset() < maxOffset) {
365366
// This is the last in the chain
366367
rsp.attr_value.len = value.length() - m_value.getReadOffset();
@@ -374,7 +375,14 @@ void BLECharacteristic::handleGATTServerEvent(
374375
memcpy(rsp.attr_value.value, value.data() + rsp.attr_value.offset, rsp.attr_value.len);
375376
m_value.setReadOffset(rsp.attr_value.offset + maxOffset);
376377
}
377-
} else {
378+
} else { // read.is_long == false
379+
380+
if (m_pCallbacks != nullptr) { // If is.long is false then this is the first (or only) request to read data, so invoke the callback
381+
m_pCallbacks->onRead(this); // Invoke the read callback.
382+
}
383+
384+
std::string value = m_value.getValue();
385+
378386
if (value.length()+1 > maxOffset) {
379387
// Too big for a single shot entry.
380388
m_value.setReadOffset(maxOffset);
@@ -408,6 +416,7 @@ void BLECharacteristic::handleGATTServerEvent(
408416
break;
409417
} // ESP_GATTS_READ_EVT
410418

419+
411420
// ESP_GATTS_CONF_EVT
412421
//
413422
// conf:

cpp_utils/HttpServer.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
/*
22
* HttpServer.cpp
3+
* Design:
4+
* This class represents an HTTP server. We create an instance of the class and then it is configured.
5+
* When the user has completed the configuration, they execute the start() method which starts it running.
6+
* A subsequent call to stop() will stop it. When start() is called, a new task is created which listens
7+
* for incoming messages.
38
*
49
* Created on: Aug 30, 2017
510
* Author: kolban
@@ -157,7 +162,7 @@ class HttpServerTask: public Task {
157162
while(1) { // Loop forever.
158163

159164
ESP_LOGD("HttpServerTask", "Waiting for new peer client");
160-
//Memory::checkIntegrity();
165+
161166
try {
162167
clientSocket = m_pHttpServer->m_socket.accept(); // Block waiting for a new external client connection.
163168
clientSocket.setTimeout(m_pHttpServer->getClientTimeout());
@@ -167,8 +172,7 @@ class HttpServerTask: public Task {
167172
return;
168173
}
169174

170-
ESP_LOGD("HttpServerTask", "HttpServer listening on port %d received a new client connection; sockFd=%d", m_pHttpServer->getPort(), clientSocket.getFD());
171-
175+
ESP_LOGD("HttpServerTask", "HttpServer listening on port %d has received a new client connection; sockFd=%d", m_pHttpServer->getPort(), clientSocket.getFD());
172176

173177
HttpRequest request(clientSocket); // Build the HTTP Request from the socket.
174178
if (request.isWebsocket()) { // If this is a WebSocket

0 commit comments

Comments
 (0)
0