-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modem): Add iperf test of PPP netif
- Loading branch information
1 parent
909e8d9
commit f806d88
Showing
9 changed files
with
586 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# The following five lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/system/console/advanced/components | ||
$ENV{IDF_PATH}/examples/common_components/iperf | ||
"../..") | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(pppd_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
idf_component_register(SRCS "NetworkDCE.cpp" | ||
"cmd_pppclient.c" | ||
"pppd_iperf_main.c") |
96 changes: 96 additions & 0 deletions
96
components/esp_modem/test/target_iperf/main/NetworkDCE.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Unlicense OR CC0-1.0 | ||
*/ | ||
#include "cxx_include/esp_modem_dte.hpp" | ||
#include "esp_modem_config.h" | ||
#include "cxx_include/esp_modem_api.hpp" | ||
#include "cxx_include/esp_modem_dce_factory.hpp" | ||
#include <memory> | ||
#include <utility> | ||
|
||
using namespace esp_modem; | ||
using namespace esp_modem::dce_factory; | ||
|
||
class NetModule; | ||
typedef DCE_T<NetModule> NetDCE; | ||
|
||
/** | ||
* @brief Custom factory which can build and create a DCE using a custom module | ||
*/ | ||
class NetDCE_Factory: public Factory { | ||
public: | ||
template <typename T, typename ...Args> | ||
static DCE_T<T> *create(const config *cfg, Args &&... args) | ||
{ | ||
return build_generic_DCE<T>(cfg, std::forward<Args>(args)...); | ||
} | ||
}; | ||
|
||
/** | ||
* @brief This is a null-module, doesn't define any AT commands, just passes everything to pppd | ||
*/ | ||
class NetModule: public ModuleIf { | ||
public: | ||
explicit NetModule(std::shared_ptr<DTE> dte, const esp_modem_dce_config *cfg): | ||
dte(std::move(dte)) {} | ||
|
||
bool setup_data_mode() override | ||
{ | ||
return true; | ||
} | ||
|
||
bool set_mode(modem_mode mode) override | ||
{ | ||
return true; | ||
} | ||
|
||
static esp_err_t init(esp_netif_t *netif) | ||
{ | ||
// configure | ||
esp_modem_dte_config_t dte_config = ESP_MODEM_DTE_DEFAULT_CONFIG(); | ||
dte_config.uart_config.baud_rate = 921600; // check also 460800 | ||
esp_modem_dce_config dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG(""); | ||
|
||
// create DTE and minimal network DCE | ||
auto uart_dte = create_uart_dte(&dte_config); | ||
dce = NetDCE_Factory::create<NetModule>(&dce_config, uart_dte, netif); | ||
return dce == nullptr ? ESP_FAIL : ESP_OK; | ||
} | ||
|
||
static void deinit() | ||
{ | ||
delete dce; | ||
} | ||
static void start() | ||
{ | ||
dce->set_data(); | ||
} | ||
static void stop() | ||
{ | ||
dce->exit_data(); | ||
} | ||
|
||
private: | ||
static NetDCE *dce; | ||
std::shared_ptr<DTE> dte; | ||
}; | ||
|
||
NetDCE *NetModule::dce = nullptr; | ||
|
||
extern "C" esp_err_t modem_init_network(esp_netif_t *netif) | ||
{ | ||
return NetModule::init(netif); | ||
} | ||
|
||
extern "C" esp_err_t modem_start_network() | ||
{ | ||
NetModule::start(); | ||
return ESP_OK; | ||
} | ||
|
||
extern "C" void modem_stop_network() | ||
{ | ||
NetModule::stop(); | ||
} |
Oops, something went wrong.