Skip to content

Commit

Permalink
fix(wifi_remote): Minor fixes per review
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cermak committed Apr 19, 2024
1 parent f47912e commit ec32275
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion components/esp_wifi_remote/eppp/eppp_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "esp_wifi.h"
#include "eppp_link.h"

esp_netif_t *wifi_remote_eppp_init(eppp_type_t role)
__attribute__((weak)) esp_netif_t *wifi_remote_eppp_init(eppp_type_t role)
{
uint32_t our_ip = role == EPPP_SERVER ? EPPP_DEFAULT_SERVER_IP() : EPPP_DEFAULT_CLIENT_IP();
uint32_t their_ip = role == EPPP_SERVER ? EPPP_DEFAULT_CLIENT_IP() : EPPP_DEFAULT_SERVER_IP();
Expand Down
16 changes: 12 additions & 4 deletions components/esp_wifi_remote/eppp/wifi_remote_rpc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ const char *TAG = "rpc_client";
const unsigned char ca_crt[] = "-----BEGIN CERTIFICATE-----\n" CONFIG_ESP_WIFI_REMOTE_EPPP_SERVER_CA "\n-----END CERTIFICATE-----";
const unsigned char crt[] = "-----BEGIN CERTIFICATE-----\n" CONFIG_ESP_WIFI_REMOTE_EPPP_CLIENT_CRT "\n-----END CERTIFICATE-----";
const unsigned char key[] = "-----BEGIN RSA PRIVATE KEY-----\n" CONFIG_ESP_WIFI_REMOTE_EPPP_CLIENT_KEY "\n-----END RSA PRIVATE KEY-----";
// TODO: Add option to supply keys and certs via a global symbol (file)

}

using namespace client;

struct Sync {
class Sync {
friend class RpcInstance;
public:
void lock()
{
xSemaphoreTake(mutex, portMAX_DELAY);
Expand Down Expand Up @@ -64,16 +67,21 @@ struct Sync {
vEventGroupDelete(events);
}
}


private:
SemaphoreHandle_t mutex{nullptr};
EventGroupHandle_t events{nullptr};

const int request = 1;
const int resp_header = 2;
const int resp_payload = 4;

};

class RpcInstance {
friend class Sync;
public:

template<typename T>
esp_err_t send(api_id id, T *t)
{
Expand All @@ -83,7 +91,7 @@ class RpcInstance {
return ESP_OK;
}

// specialization for (void)
// overload of the templated method (used for functions with no arguments)
esp_err_t send(api_id id)
{
ESP_RETURN_ON_ERROR(sync.notify(sync.request), TAG, "failed to notify req");
Expand Down Expand Up @@ -176,7 +184,7 @@ class RpcInstance {


namespace client {
RpcInstance instance;
constinit RpcInstance instance;
} // namespace client

RpcInstance *RpcEngine::init_client()
Expand Down
18 changes: 15 additions & 3 deletions components/esp_wifi_remote/eppp/wifi_remote_rpc_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

namespace eppp_rpc {

const int rpc_port = 3333;
static constexpr int rpc_port = 3333;

/**
* @brief Currently supported RPC commands/events
*/
enum class api_id : uint32_t {
ERROR,
UNDEF,
Expand All @@ -35,6 +38,9 @@ struct RpcHeader {
uint32_t size;
} __attribute((__packed__));

/**
* @brief Structure holding the outgoing or incoming parameter
*/
template<typename T>
struct RpcData {
RpcHeader head;
Expand All @@ -54,11 +60,17 @@ struct RpcData {
}
} __attribute((__packed__));

/**
* @brief Singleton holding the static data for either the client or server side
*/
class RpcInstance;

/**
* @brief Engine that implements a simple RPC mechanism
*/
class RpcEngine {
public:
explicit RpcEngine(role r) : tls_(nullptr), role_(r) {}
constexpr explicit RpcEngine(role r) : tls_(nullptr), role_(r) {}

esp_err_t init()
{
Expand Down Expand Up @@ -90,7 +102,7 @@ class RpcEngine {
return ESP_OK;
}

esp_err_t send(api_id id) // specialization for (void)
esp_err_t send(api_id id) // overload for (void)
{
RpcHeader head = {.id = id, .size = 0};
int len = esp_tls_conn_write(tls_, &head, sizeof(head));
Expand Down
3 changes: 2 additions & 1 deletion components/esp_wifi_remote/eppp/wifi_remote_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const char *TAG = "rpc_server";
const unsigned char ca_crt[] = "-----BEGIN CERTIFICATE-----\n" CONFIG_ESP_WIFI_REMOTE_EPPP_CLIENT_CA "\n-----END CERTIFICATE-----";
const unsigned char crt[] = "-----BEGIN CERTIFICATE-----\n" CONFIG_ESP_WIFI_REMOTE_EPPP_SERVER_CRT "\n-----END CERTIFICATE-----";
const unsigned char key[] = "-----BEGIN RSA PRIVATE KEY-----\n" CONFIG_ESP_WIFI_REMOTE_EPPP_SERVER_KEY "\n-----END RSA PRIVATE KEY-----";
// TODO: Add option to supply keys and certs via a global symbol (file)

}

Expand Down Expand Up @@ -181,7 +182,7 @@ class RpcInstance {


namespace server {
RpcInstance instance;
constinit RpcInstance instance;
}

RpcInstance *RpcEngine::init_server()
Expand Down
18 changes: 0 additions & 18 deletions components/esp_wifi_remote/examples/mqtt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
# This project serves as a demo to enable using esp-mqtt on ESP platform targets as well as on linux
cmake_minimum_required(VERSION 3.16)

if("${IDF_TARGET}" STREQUAL "linux")
# For linux-target we have two options:
# - With lwIP (must be defined on command line, e.g. idf.py -DWITH_LWIP=1)
# access networking from linux `tap` interface (TAP networking mode)
# - Without lwIP (must be defined on command line, e.g. idf.py -DWITH_LWIP=0)
# no designated interface, accesses user network via linux/socket sys calls
if(WITH_LWIP STREQUAL 1)
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_tapif_io
"../../common_components/linux_compat/esp_timer")
set(COMPONENTS main esp_netif lwip protocol_examples_tapif_io startup esp_hw_support esp_system nvs_flash mqtt esp_timer)
else()
list(APPEND EXTRA_COMPONENT_DIRS
"../../common_components/linux_compat/esp_timer"
"$ENV{IDF_PATH}/examples/protocols/linux_stubs/esp_stubs")
set(COMPONENTS main nvs_flash esp-tls esp_stubs mqtt protocol_examples_common esp_timer)
endif()
endif()

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(esp_mqtt_demo)

0 comments on commit ec32275

Please sign in to comment.