Skip to content

Commit 395387c

Browse files
authored
Merge pull request #1 from COM8/master
Fixed ESP-IDF 4.0 compile errors
2 parents abd792c + abc5cd8 commit 395387c

9 files changed

+29
-24
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ Due to [this issue](https://github.com/nkolban/esp32-snippets/issues/797), remov
1616
### 2) Add new static method to kill BLE server properly
1717

1818
Add removeServer() method to BLEDevice class, so that the programmer could deinitialise the BLE server(kill the BLE server).
19+
20+
### 3) Creates a bunch of fixes for GCC warnings and errors
21+
22+
View commits for more information.

cpp_utils/BLECharacteristic.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -661,14 +661,14 @@ void BLECharacteristic::setValue(std::string value) {
661661
setValue((uint8_t*)(value.data()), value.length());
662662
} // setValue
663663

664-
void BLECharacteristic::setValue(uint16_t& data16) {
664+
void BLECharacteristic::setValue(uint16_t data16) {
665665
uint8_t temp[2];
666666
temp[0] = data16;
667667
temp[1] = data16 >> 8;
668668
setValue(temp, 2);
669669
} // setValue
670670

671-
void BLECharacteristic::setValue(uint32_t& data32) {
671+
void BLECharacteristic::setValue(uint32_t data32) {
672672
uint8_t temp[4];
673673
temp[0] = data32;
674674
temp[1] = data32 >> 8;
@@ -677,7 +677,7 @@ void BLECharacteristic::setValue(uint32_t& data32) {
677677
setValue(temp, 4);
678678
} // setValue
679679

680-
void BLECharacteristic::setValue(int& data32) {
680+
void BLECharacteristic::setValue(int data32) {
681681
uint8_t temp[4];
682682
temp[0] = data32;
683683
temp[1] = data32 >> 8;
@@ -686,13 +686,13 @@ void BLECharacteristic::setValue(int& data32) {
686686
setValue(temp, 4);
687687
} // setValue
688688

689-
void BLECharacteristic::setValue(float& data32) {
689+
void BLECharacteristic::setValue(float data32) {
690690
uint8_t temp[4];
691691
*((float*)temp) = data32;
692692
setValue(temp, 4);
693693
} // setValue
694694

695-
void BLECharacteristic::setValue(double& data64) {
695+
void BLECharacteristic::setValue(double data64) {
696696
uint8_t temp[8];
697697
*((double*)temp) = data64;
698698
setValue(temp, 8);

cpp_utils/BLECharacteristic.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ class BLECharacteristic {
7272
void setReadProperty(bool value);
7373
void setValue(uint8_t* data, size_t size);
7474
void setValue(std::string value);
75-
void setValue(uint16_t& data16);
76-
void setValue(uint32_t& data32);
77-
void setValue(int& data32);
78-
void setValue(float& data32);
79-
void setValue(double& data64);
75+
void setValue(uint16_t data16);
76+
void setValue(uint32_t data32);
77+
void setValue(int data32);
78+
void setValue(float data32);
79+
void setValue(double data64);
8080
void setWriteProperty(bool value);
8181
void setWriteNoResponseProperty(bool value);
8282
std::string toString();

cpp_utils/BLEDevice.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
485485
*/
486486
void BLEDevice::whiteListAdd(BLEAddress address) {
487487
ESP_LOGD(LOG_TAG, ">> whiteListAdd: %s", address.toString().c_str());
488-
esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative()); // True to add an entry.
488+
esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative(), BLE_WL_ADDR_TYPE_RANDOM); // True to add an entry.
489489
if (errRc != ESP_OK) {
490490
ESP_LOGE(LOG_TAG, "esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
491491
}
@@ -499,7 +499,7 @@ void BLEDevice::whiteListAdd(BLEAddress address) {
499499
*/
500500
void BLEDevice::whiteListRemove(BLEAddress address) {
501501
ESP_LOGD(LOG_TAG, ">> whiteListRemove: %s", address.toString().c_str());
502-
esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative()); // False to remove an entry.
502+
esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative(), BLE_WL_ADDR_TYPE_RANDOM); // False to remove an entry.
503503
if (errRc != ESP_OK) {
504504
ESP_LOGE(LOG_TAG, "esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
505505
}

cpp_utils/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set(COMPONENT_REQUIRES
55
"json"
66
"mdns"
77
"nvs_flash"
8+
"bt"
89
)
910
set(COMPONENT_PRIV_REQUIRES )
1011

cpp_utils/HttpRequest.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include "GeneralUtils.h"
4040

4141
#include <esp_log.h>
42-
#include <hwcrypto/sha.h>
42+
#include <esp32/sha.h>
4343

4444
#define STATE_NAME 0
4545
#define STATE_VALUE 1

cpp_utils/SockServ.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ SockServ::~SockServ() {
7070
pSockServ->m_clientSet.insert(tempSock);
7171
xQueueSendToBack(pSockServ->m_acceptQueue, &tempSock, portMAX_DELAY);
7272
pSockServ->m_clientSemaphore.give();
73-
} catch (std::exception e) {
73+
} catch (std::exception& e) {
7474
ESP_LOGD(LOG_TAG, "acceptTask ending");
7575
pSockServ->m_clientSemaphore.give(); // Wake up any waiting clients.
7676
FreeRTOS::deleteTask();

cpp_utils/Socket.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Socket Socket::accept() {
6060
ESP_LOGD(LOG_TAG, ">> accept: Accepting on %s; sockFd: %d, using SSL: %d", addressToString(&addr).c_str(), m_sock, getSSL());
6161
struct sockaddr_in client_addr;
6262
socklen_t sin_size;
63-
int clientSockFD = ::lwip_accept_r(m_sock, (struct sockaddr*) &client_addr, &sin_size);
63+
int clientSockFD = ::lwip_accept(m_sock, (struct sockaddr*) &client_addr, &sin_size);
6464
//printf("------> new connection client %s:%d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
6565
if (clientSockFD == -1) {
6666
SocketException se(errno);
@@ -117,7 +117,7 @@ int Socket::bind(uint16_t port, uint32_t address) {
117117
serverAddress.sin_family = AF_INET;
118118
serverAddress.sin_addr.s_addr = htonl(address);
119119
serverAddress.sin_port = htons(port);
120-
int rc = ::lwip_bind_r(m_sock, (struct sockaddr*) &serverAddress, sizeof(serverAddress));
120+
int rc = ::lwip_bind(m_sock, (struct sockaddr*) &serverAddress, sizeof(serverAddress));
121121
if (rc != 0) {
122122
ESP_LOGE(LOG_TAG, "<< bind: bind[socket=%d]: %d: %s", m_sock, errno, strerror(errno));
123123
return rc;
@@ -144,7 +144,7 @@ int Socket::close() {
144144
rc = 0;
145145
if (m_sock != -1) {
146146
ESP_LOGD(LOG_TAG, "Calling lwip_close on %d", m_sock);
147-
rc = ::lwip_close_r(m_sock);
147+
rc = ::lwip_close(m_sock);
148148
if (rc != 0) {
149149
ESP_LOGE(LOG_TAG, "Error with lwip_close: %d", rc);
150150
}
@@ -170,7 +170,7 @@ int Socket::connect(struct in_addr address, uint16_t port) {
170170
inet_ntop(AF_INET, &address, msg, sizeof(msg));
171171
ESP_LOGD(LOG_TAG, "Connecting to %s:[%d]", msg, port);
172172
createSocket();
173-
int rc = ::lwip_connect_r(m_sock, (struct sockaddr*) &serverAddress, sizeof(struct sockaddr_in));
173+
int rc = ::lwip_connect(m_sock, (struct sockaddr*) &serverAddress, sizeof(struct sockaddr_in));
174174
if (rc == -1) {
175175
ESP_LOGE(LOG_TAG, "connect_cpp: Error: %s", strerror(errno));
176176
close();
@@ -268,7 +268,7 @@ int Socket::listen(uint16_t port, bool isDatagram, bool reuseAddress) {
268268
// For a datagram socket, we don't execute a listen call. That is is only for connection oriented
269269
// sockets.
270270
if (!isDatagram) {
271-
rc = ::lwip_listen_r(m_sock, 5);
271+
rc = ::lwip_listen(m_sock, 5);
272272
if (rc == -1) {
273273
ESP_LOGE(LOG_TAG, "<< listen: %s", strerror(errno));
274274
return rc;
@@ -356,7 +356,7 @@ size_t Socket::receive(uint8_t* data, size_t length, bool exact) {
356356
ESP_LOGD(LOG_TAG, "rc=%d, MBEDTLS_ERR_SSL_WANT_READ=%d", rc, MBEDTLS_ERR_SSL_WANT_READ);
357357
} while (rc == MBEDTLS_ERR_SSL_WANT_WRITE || rc == MBEDTLS_ERR_SSL_WANT_READ);
358358
} else {
359-
rc = ::lwip_recv_r(m_sock, data, length, 0);
359+
rc = ::lwip_recv(m_sock, data, length, 0);
360360
if (rc == -1) {
361361
ESP_LOGE(LOG_TAG, "receive: %s", strerror(errno));
362362
}
@@ -374,7 +374,7 @@ size_t Socket::receive(uint8_t* data, size_t length, bool exact) {
374374
rc = mbedtls_ssl_read(&m_sslContext, data, amountToRead);
375375
} while (rc == MBEDTLS_ERR_SSL_WANT_WRITE || rc == MBEDTLS_ERR_SSL_WANT_READ);
376376
} else {
377-
rc = ::lwip_recv_r(m_sock, data, amountToRead, 0);
377+
rc = ::lwip_recv(m_sock, data, amountToRead, 0);
378378
}
379379
if (rc == -1) {
380380
ESP_LOGE(LOG_TAG, "receive: %s", strerror(errno));
@@ -432,7 +432,7 @@ int Socket::send(const uint8_t* data, size_t length) const {
432432
}
433433
}
434434
} else {
435-
rc = ::lwip_send_r(m_sock, data, length, 0);
435+
rc = ::lwip_send(m_sock, data, length, 0);
436436
if ((rc < 0) && (errno != EAGAIN)) {
437437
// no cure for errors other than EAGAIN - log and exit
438438
ESP_LOGE(LOG_TAG, "send: socket=%d, %s", m_sock, strerror(errno));

cpp_utils/WiFi.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ void WiFi::dump() {
218218
ESP_LOGD(LOG_TAG, "WiFi Dump");
219219
ESP_LOGD(LOG_TAG, "---------");
220220
char ipAddrStr[30];
221-
ip_addr_t ip = ::dns_getserver(0);
222-
inet_ntop(AF_INET, &ip, ipAddrStr, sizeof(ipAddrStr));
221+
const ip_addr_t* ip = ::dns_getserver(0);
222+
inet_ntop(AF_INET, ip, ipAddrStr, sizeof(ipAddrStr));
223223
ESP_LOGD(LOG_TAG, "DNS Server[0]: %s", ipAddrStr);
224224
} // dump
225225

0 commit comments

Comments
 (0)