Skip to content

adding fix for newest version of esp-idf #948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions cpp_utils/CMakeLists.txt

This file was deleted.

18 changes: 7 additions & 11 deletions cpp_utils/FreeRTOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@
#include <sstream>
#include <iomanip>
#include "FreeRTOS.h"
#include <esp_log.h>
#include "sdkconfig.h"
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"

static const char* LOG_TAG = "FreeRTOS";
#endif

/**
* Sleep for the specified number of milliseconds.
Expand Down Expand Up @@ -67,22 +63,23 @@ uint32_t FreeRTOS::getTimeSinceStart() {
*/
uint32_t FreeRTOS::Semaphore::wait(std::string owner) {
ESP_LOGV(LOG_TAG, ">> wait: Semaphore waiting: %s for %s", toString().c_str(), owner.c_str());

m_owner = owner;

if (m_usePthreads) {
pthread_mutex_lock(&m_pthread_mutex);
} else {
xSemaphoreTake(m_semaphore, portMAX_DELAY);
}

m_owner = owner;

if (m_usePthreads) {
pthread_mutex_unlock(&m_pthread_mutex);
} else {
xSemaphoreGive(m_semaphore);
}

ESP_LOGV(LOG_TAG, "<< wait: Semaphore released: %s", toString().c_str());
m_owner = std::string("<N/A>");
return m_value;
} // wait

Expand All @@ -92,8 +89,7 @@ FreeRTOS::Semaphore::Semaphore(std::string name) {
if (m_usePthreads) {
pthread_mutex_init(&m_pthread_mutex, nullptr);
} else {
m_semaphore = xSemaphoreCreateBinary();
xSemaphoreGive(m_semaphore);
m_semaphore = xSemaphoreCreateMutex();
}

m_name = name;
Expand Down Expand Up @@ -229,7 +225,7 @@ void FreeRTOS::Semaphore::setName(std::string name) {
* @param [in] length The amount of storage to allocate for the ring buffer.
* @param [in] type The type of buffer. One of RINGBUF_TYPE_NOSPLIT, RINGBUF_TYPE_ALLOWSPLIT, RINGBUF_TYPE_BYTEBUF.
*/
Ringbuffer::Ringbuffer(size_t length, ringbuf_type_t type) {
Ringbuffer::Ringbuffer(size_t length, RingbufferType_t type) {
m_handle = ::xRingbufferCreate(length, type);
} // Ringbuffer

Expand Down
2 changes: 1 addition & 1 deletion cpp_utils/FreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class FreeRTOS {
*/
class Ringbuffer {
public:
Ringbuffer(size_t length, ringbuf_type_t type = RINGBUF_TYPE_NOSPLIT);
Ringbuffer(size_t length, RingbufferType_t type = RINGBUF_TYPE_NOSPLIT);
~Ringbuffer();

void* receive(size_t* size, TickType_t wait = portMAX_DELAY);
Expand Down
12 changes: 1 addition & 11 deletions cpp_utils/GeneralUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "GeneralUtils.h"
#include <esp_log.h>
#include <esp_system.h>
#include <string.h>
#include <stdio.h>
Expand All @@ -19,14 +20,7 @@
#include <esp_heap_caps.h>
#include <esp_system.h>

#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "GeneralUtils";
#endif


static const char kBase64Alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
Expand Down Expand Up @@ -371,7 +365,6 @@ std::vector<std::string> GeneralUtils::split(std::string source, char delimiter)
*/
const char* GeneralUtils::errorToString(esp_err_t errCode) {
switch (errCode) {
#if CONFIG_LOG_DEFAULT_LEVEL > 4
case ESP_OK:
return "ESP_OK";
case ESP_FAIL:
Expand Down Expand Up @@ -438,7 +431,6 @@ const char* GeneralUtils::errorToString(esp_err_t errCode) {
return "ESP_ERR_WIFI_TIMEOUT";
case ESP_ERR_WIFI_WAKE_FAIL:
return "ESP_ERR_WIFI_WAKE_FAIL";
#endif
default:
return "Unknown ESP_ERR error";
}
Expand All @@ -456,7 +448,6 @@ const char* GeneralUtils::wifiErrorToString(uint8_t errCode) {
if (errCode == UINT8_MAX) return "Not Connected (default value)";

switch ((wifi_err_reason_t) errCode) {
#if CONFIG_LOG_DEFAULT_LEVEL > 4
case WIFI_REASON_UNSPECIFIED:
return "WIFI_REASON_UNSPECIFIED";
case WIFI_REASON_AUTH_EXPIRE:
Expand Down Expand Up @@ -513,7 +504,6 @@ const char* GeneralUtils::wifiErrorToString(uint8_t errCode) {
return "WIFI_REASON_ASSOC_FAIL";
case WIFI_REASON_HANDSHAKE_TIMEOUT:
return "WIFI_REASON_HANDSHAKE_TIMEOUT";
#endif
default:
return "Unknown ESP_ERR error";
}
Expand Down
2 changes: 1 addition & 1 deletion cpp_utils/JSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#ifndef COMPONENTS_CPP_UTILS_JSON_H_
#define COMPONENTS_CPP_UTILS_JSON_H_
#include <cJSON.h>
#include "../../json/cJSON/cJSON.h"
#include <string>

// Forward declarations
Expand Down
2 changes: 1 addition & 1 deletion cpp_utils/SockServ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ SockServ::~SockServ() {
pSockServ->m_clientSet.insert(tempSock);
xQueueSendToBack(pSockServ->m_acceptQueue, &tempSock, portMAX_DELAY);
pSockServ->m_clientSemaphore.give();
} catch (std::exception e) {
} catch (std::exception & e) {
ESP_LOGD(LOG_TAG, "acceptTask ending");
pSockServ->m_clientSemaphore.give(); // Wake up any waiting clients.
FreeRTOS::deleteTask();
Expand Down
16 changes: 8 additions & 8 deletions cpp_utils/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Socket Socket::accept() {
ESP_LOGD(LOG_TAG, ">> accept: Accepting on %s; sockFd: %d, using SSL: %d", addressToString(&addr).c_str(), m_sock, getSSL());
struct sockaddr_in client_addr;
socklen_t sin_size;
int clientSockFD = ::lwip_accept_r(m_sock, (struct sockaddr*) &client_addr, &sin_size);
int clientSockFD = ::lwip_accept(m_sock, (struct sockaddr*) &client_addr, &sin_size);
//printf("------> new connection client %s:%d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
if (clientSockFD == -1) {
SocketException se(errno);
Expand Down Expand Up @@ -117,7 +117,7 @@ int Socket::bind(uint16_t port, uint32_t address) {
serverAddress.sin_family = AF_INET;
serverAddress.sin_addr.s_addr = htonl(address);
serverAddress.sin_port = htons(port);
int rc = ::lwip_bind_r(m_sock, (struct sockaddr*) &serverAddress, sizeof(serverAddress));
int rc = ::lwip_bind(m_sock, (struct sockaddr*) &serverAddress, sizeof(serverAddress));
if (rc != 0) {
ESP_LOGE(LOG_TAG, "<< bind: bind[socket=%d]: %d: %s", m_sock, errno, strerror(errno));
return rc;
Expand All @@ -144,7 +144,7 @@ int Socket::close() {
rc = 0;
if (m_sock != -1) {
ESP_LOGD(LOG_TAG, "Calling lwip_close on %d", m_sock);
rc = ::lwip_close_r(m_sock);
rc = ::lwip_close(m_sock);
if (rc != 0) {
ESP_LOGE(LOG_TAG, "Error with lwip_close: %d", rc);
}
Expand All @@ -170,7 +170,7 @@ int Socket::connect(struct in_addr address, uint16_t port) {
inet_ntop(AF_INET, &address, msg, sizeof(msg));
ESP_LOGD(LOG_TAG, "Connecting to %s:[%d]", msg, port);
createSocket();
int rc = ::lwip_connect_r(m_sock, (struct sockaddr*) &serverAddress, sizeof(struct sockaddr_in));
int rc = ::lwip_connect(m_sock, (struct sockaddr*) &serverAddress, sizeof(struct sockaddr_in));
if (rc == -1) {
ESP_LOGE(LOG_TAG, "connect_cpp: Error: %s", strerror(errno));
close();
Expand Down Expand Up @@ -268,7 +268,7 @@ int Socket::listen(uint16_t port, bool isDatagram, bool reuseAddress) {
// For a datagram socket, we don't execute a listen call. That is is only for connection oriented
// sockets.
if (!isDatagram) {
rc = ::lwip_listen_r(m_sock, 5);
rc = ::lwip_listen(m_sock, 5);
if (rc == -1) {
ESP_LOGE(LOG_TAG, "<< listen: %s", strerror(errno));
return rc;
Expand Down Expand Up @@ -356,7 +356,7 @@ size_t Socket::receive(uint8_t* data, size_t length, bool exact) {
ESP_LOGD(LOG_TAG, "rc=%d, MBEDTLS_ERR_SSL_WANT_READ=%d", rc, MBEDTLS_ERR_SSL_WANT_READ);
} while (rc == MBEDTLS_ERR_SSL_WANT_WRITE || rc == MBEDTLS_ERR_SSL_WANT_READ);
} else {
rc = ::lwip_recv_r(m_sock, data, length, 0);
rc = ::lwip_recv(m_sock, data, length, 0);
if (rc == -1) {
ESP_LOGE(LOG_TAG, "receive: %s", strerror(errno));
}
Expand All @@ -374,7 +374,7 @@ size_t Socket::receive(uint8_t* data, size_t length, bool exact) {
rc = mbedtls_ssl_read(&m_sslContext, data, amountToRead);
} while (rc == MBEDTLS_ERR_SSL_WANT_WRITE || rc == MBEDTLS_ERR_SSL_WANT_READ);
} else {
rc = ::lwip_recv_r(m_sock, data, amountToRead, 0);
rc = ::lwip_recv(m_sock, data, amountToRead, 0);
}
if (rc == -1) {
ESP_LOGE(LOG_TAG, "receive: %s", strerror(errno));
Expand Down Expand Up @@ -432,7 +432,7 @@ int Socket::send(const uint8_t* data, size_t length) const {
}
}
} else {
rc = ::lwip_send_r(m_sock, data, length, 0);
rc = ::lwip_send(m_sock, data, length, 0);
if ((rc < 0) && (errno != EAGAIN)) {
// no cure for errors other than EAGAIN - log and exit
ESP_LOGE(LOG_TAG, "send: socket=%d, %s", m_sock, strerror(errno));
Expand Down
2 changes: 1 addition & 1 deletion cpp_utils/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void WiFi::dump() {
ESP_LOGD(LOG_TAG, "WiFi Dump");
ESP_LOGD(LOG_TAG, "---------");
char ipAddrStr[30];
ip_addr_t ip = ::dns_getserver(0);
const ip_addr_t * ip = ::dns_getserver(0);
inet_ntop(AF_INET, &ip, ipAddrStr, sizeof(ipAddrStr));
ESP_LOGD(LOG_TAG, "DNS Server[0]: %s", ipAddrStr);
} // dump
Expand Down
1 change: 1 addition & 0 deletions cpp_utils/WiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <string>
#include <vector>
#include <mdns.h>

#include <esp_err.h>
#include "FreeRTOS.h"
#include "WiFiEventHandler.h"
Expand Down