added expected and fmt for cleaner code/interfaces

This commit is contained in:
2021-08-01 21:43:12 +02:00
parent 3a350f1189
commit fc2eb3718d
3 changed files with 27 additions and 8 deletions

View File

@ -30,9 +30,12 @@ set(dependencies
esp_system esp_system
# esp_http_client # esp_http_client
esp_websocket_client esp_websocket_client
tcp_transport
cpputils cpputils
espchrono espchrono
tcp_transport expected
fmt
) )
idf_component_register( idf_component_register(

View File

@ -1,19 +1,29 @@
#include "espstrutils.h" #include "espstrutils.h"
// system includes // esp-idf includes
#include <cctype> #include <esp_log.h>
// 3rdparty lib includes
#include <fmt/core.h>
// local includes
#include "futurecpp.h"
namespace espcpputils { namespace espcpputils {
namespace {
constexpr const char * const TAG = "ESPCPPUTILS";
}
std::string toString(sntp_sync_mode_t val) std::string toString(sntp_sync_mode_t val)
{ {
switch (val) switch (val)
{ {
case SNTP_SYNC_MODE_IMMED: return "SNTP_SYNC_MODE_IMMED"; case SNTP_SYNC_MODE_IMMED: return "IMMED";
case SNTP_SYNC_MODE_SMOOTH: return "SNTP_SYNC_MODE_SMOOTH"; case SNTP_SYNC_MODE_SMOOTH: return "SMOOTH";
default:
ESP_LOGW(TAG, "unknown sntp_sync_mode_t(%i)", std::to_underlying(val));
return fmt::format("Unknown sntp_sync_mode_t({})", std::to_underlying(val));
} }
return std::string{"Unknown sntp_sync_mode_t("} + std::to_string(int(val)) + ')';
} }
void urldecode(char *dst, const char *src) void urldecode(char *dst, const char *src)

View File

@ -8,6 +8,12 @@
#include <esp_websocket_client.h> #include <esp_websocket_client.h>
#include <esp_transport_ws.h> #include <esp_transport_ws.h>
// 3rdparty lib includes
#include <fmt/core.h>
// local includes
#include "futurecpp.h"
namespace espcpputils { namespace espcpputils {
class websocket_client class websocket_client
{ {
@ -56,7 +62,7 @@ public:
case WS_TRANSPORT_OPCODES_PING: return "PING"; case WS_TRANSPORT_OPCODES_PING: return "PING";
case WS_TRANSPORT_OPCODES_PONG: return "PONG"; case WS_TRANSPORT_OPCODES_PONG: return "PONG";
case WS_TRANSPORT_OPCODES_FIN: return "FIN"; case WS_TRANSPORT_OPCODES_FIN: return "FIN";
default: return "unknown opcode(" + std::to_string(op_code) + ')'; default: return fmt::format("unknown opcode({})", std::to_underlying(op_code));
} }
} }