mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-16 12:02:11 +02:00
PPP renamed to Netif, common AT command to console
This commit is contained in:
@ -428,7 +428,7 @@ extern "C" void app_main(void)
|
||||
const struct GenericCommandArgs {
|
||||
GenericCommandArgs():
|
||||
cmd(STR1, nullptr, nullptr, "<command>", "AT command to send to the modem"),
|
||||
timeout(INT1, "t", "timeout", "<timeout>", "command timeout"),
|
||||
timeout(INT0, "t", "timeout", "<timeout>", "command timeout"),
|
||||
pattern(STR0, "p", "pattern", "<pattern>", "command response to wait for"),
|
||||
no_cr(LIT0, "n", "no-cr", "not add trailing CR to the command") {}
|
||||
CommandArgs cmd;
|
||||
@ -436,14 +436,26 @@ extern "C" void app_main(void)
|
||||
CommandArgs pattern;
|
||||
CommandArgs no_cr;
|
||||
} send_cmd_args;
|
||||
|
||||
ConsoleCommand SendCommand("cmd", "sends generic AT command, no_args", &send_cmd_args, sizeof(send_cmd_args), [&](ConsoleCommand *c){
|
||||
const ConsoleCommand SendCommand("cmd", "sends generic AT command, no_args", &send_cmd_args, sizeof(send_cmd_args), [&](ConsoleCommand *c) {
|
||||
auto cmd = c->get_string_of(&GenericCommandArgs::cmd);
|
||||
auto timeout = c->get_int_of(&GenericCommandArgs::timeout);
|
||||
auto timeout = c->get_count_of(&GenericCommandArgs::timeout) ? c->get_int_of(&GenericCommandArgs::timeout)
|
||||
: 1000;
|
||||
auto pattern = c->get_string_of(&GenericCommandArgs::pattern);
|
||||
if (c->get_count_of(&GenericCommandArgs::no_cr) == 0) {
|
||||
cmd += '\r';
|
||||
}
|
||||
ESP_LOGI(TAG, "Sending command %s with timeout %d", cmd.c_str(), timeout);
|
||||
CHECK_ERR(dce->command(cmd, nullptr, timeout),
|
||||
ESP_LOGI(TAG, "OK"));
|
||||
CHECK_ERR(dce->command(cmd, [&](uint8_t *data, size_t len) {
|
||||
std::string response((char *) data, len);
|
||||
ESP_LOGI(TAG, "%s", response.c_str());
|
||||
if (pattern.empty() || response.find(pattern) != std::string::npos)
|
||||
return command_result::OK;
|
||||
if (response.find(pattern) != std::string::npos)
|
||||
return command_result::OK;
|
||||
return command_result::TIMEOUT;
|
||||
}, timeout),);
|
||||
});
|
||||
|
||||
// start console REPL
|
||||
ESP_ERROR_CHECK(esp_console_start_repl(s_repl));
|
||||
ESP_LOGE(TAG, "Exit console!!!");
|
||||
|
@ -11,7 +11,7 @@ class Modes {
|
||||
public:
|
||||
Modes(): mode(modem_mode::COMMAND_MODE) {}
|
||||
~Modes() = default;
|
||||
bool set(DTE *dte, ModuleIf *module, PPP &netif, modem_mode m);
|
||||
bool set(DTE *dte, ModuleIf *module, Netif &netif, modem_mode m);
|
||||
modem_mode get();
|
||||
|
||||
private:
|
||||
@ -48,7 +48,7 @@ protected:
|
||||
|
||||
std::shared_ptr<DTE> dte;
|
||||
std::shared_ptr<SpecificModule> module;
|
||||
PPP netif;
|
||||
Netif netif;
|
||||
esp_modem::DCE::Modes mode;
|
||||
};
|
||||
|
||||
|
@ -9,18 +9,18 @@
|
||||
#include "cxx_include/esp_modem_primitives.hpp"
|
||||
|
||||
class DTE;
|
||||
class PPP;
|
||||
class Netif;
|
||||
|
||||
//struct ppp_netif_driver;
|
||||
struct ppp_netif_driver {
|
||||
esp_netif_driver_base_t base;
|
||||
PPP *ppp;
|
||||
Netif *ppp;
|
||||
};
|
||||
|
||||
|
||||
class PPP {
|
||||
class Netif {
|
||||
public:
|
||||
explicit PPP(std::shared_ptr<DTE> e, esp_netif_t *netif);
|
||||
explicit Netif(std::shared_ptr<DTE> e, esp_netif_t *netif);
|
||||
|
||||
void start();
|
||||
// void notify_ppp_exit() { signal.set(PPP_EXIT); }
|
||||
|
@ -9,7 +9,7 @@
|
||||
namespace esp_modem::DCE {
|
||||
|
||||
|
||||
bool Modes::set(DTE *dte, ModuleIf *device, PPP &netif, modem_mode m)
|
||||
bool Modes::set(DTE *dte, ModuleIf *device, Netif &netif, modem_mode m)
|
||||
{
|
||||
switch (m) {
|
||||
case modem_mode::UNDEF:
|
||||
|
@ -12,10 +12,10 @@
|
||||
#include <iostream>
|
||||
|
||||
|
||||
void PPP::on_ppp_changed(void *arg, esp_event_base_t event_base,
|
||||
void Netif::on_ppp_changed(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
{
|
||||
PPP *ppp = (PPP*)arg;
|
||||
Netif *ppp = (Netif*)arg;
|
||||
// DTE *e = (DTE*)arg;
|
||||
std::cout << "on_ppp_changed " << std::endl;
|
||||
ESP_LOGW("TAG", "PPP state changed event %d", event_id);
|
||||
@ -29,9 +29,9 @@ void PPP::on_ppp_changed(void *arg, esp_event_base_t event_base,
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t PPP::esp_modem_dte_transmit(void *h, void *buffer, size_t len)
|
||||
esp_err_t Netif::esp_modem_dte_transmit(void *h, void *buffer, size_t len)
|
||||
{
|
||||
PPP *ppp = (PPP*)h;
|
||||
Netif *ppp = (Netif*)h;
|
||||
if (ppp->signal.is_any(PPP_STARTED)) {
|
||||
std::cout << "sending data " << len << std::endl;
|
||||
if (ppp->ppp_dte->write((uint8_t*)buffer, len) > 0) {
|
||||
@ -41,11 +41,11 @@ esp_err_t PPP::esp_modem_dte_transmit(void *h, void *buffer, size_t len)
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t PPP::esp_modem_post_attach(esp_netif_t * esp_netif, void * args)
|
||||
esp_err_t Netif::esp_modem_post_attach(esp_netif_t * esp_netif, void * args)
|
||||
{
|
||||
auto d = (ppp_netif_driver*)args;
|
||||
esp_netif_driver_ifconfig_t driver_ifconfig = { };
|
||||
driver_ifconfig.transmit = PPP::esp_modem_dte_transmit;
|
||||
driver_ifconfig.transmit = Netif::esp_modem_dte_transmit;
|
||||
driver_ifconfig.handle = (void*)d->ppp;
|
||||
std::cout << "esp_modem_post_attach " << std::endl;
|
||||
d->base.netif = esp_netif;
|
||||
@ -63,7 +63,7 @@ esp_err_t PPP::esp_modem_post_attach(esp_netif_t * esp_netif, void * args)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void PPP::receive(uint8_t *data, size_t len)
|
||||
void Netif::receive(uint8_t *data, size_t len)
|
||||
{
|
||||
if (signal.is_any(PPP_STARTED)) {
|
||||
std::cout << "received data " << len << std::endl;
|
||||
@ -71,7 +71,7 @@ void PPP::receive(uint8_t *data, size_t len)
|
||||
}
|
||||
}
|
||||
|
||||
PPP::PPP(std::shared_ptr<DTE> e, esp_netif_t *ppp_netif):
|
||||
Netif::Netif(std::shared_ptr<DTE> e, esp_netif_t *ppp_netif):
|
||||
ppp_dte(std::move(e)), netif(ppp_netif)
|
||||
{
|
||||
driver.base.netif = ppp_netif;
|
||||
@ -83,7 +83,7 @@ PPP::PPP(std::shared_ptr<DTE> e, esp_netif_t *ppp_netif):
|
||||
throw_if_esp_fail(esp_netif_attach(ppp_netif, &driver));
|
||||
}
|
||||
|
||||
void PPP::start()
|
||||
void Netif::start()
|
||||
{
|
||||
ppp_dte->set_data_cb([this](size_t len) -> bool {
|
||||
uint8_t *data;
|
||||
@ -95,7 +95,7 @@ void PPP::start()
|
||||
signal.set(PPP_STARTED);
|
||||
}
|
||||
|
||||
void PPP::stop()
|
||||
void Netif::stop()
|
||||
{
|
||||
std::cout << "esp_netif_action_stop " << std::endl;
|
||||
esp_netif_action_stop(driver.base.netif, nullptr, 0, nullptr);
|
||||
|
Reference in New Issue
Block a user