mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-30 02:37:31 +02:00
uart/dte cleanup
This commit is contained in:
@ -12,13 +12,13 @@
|
||||
|
||||
static const char *TAG = "modem_console_helper";
|
||||
|
||||
ConsoleCommand::ConsoleCommand(const char* command, const char* help, std::vector<CommandArgs>& args, std::function<bool(ConsoleCommand *)> f):
|
||||
ConsoleCommand::ConsoleCommand(const char* command, const char* help, const std::vector<CommandArgs>& args, std::function<bool(ConsoleCommand *)> f):
|
||||
func(std::move(f))
|
||||
{
|
||||
RegisterCommand(command, help, args);
|
||||
}
|
||||
|
||||
void ConsoleCommand::RegisterCommand(const char* command, const char* help, std::vector<CommandArgs>& args)
|
||||
void ConsoleCommand::RegisterCommand(const char* command, const char* help, const std::vector<CommandArgs>& args)
|
||||
{
|
||||
assert(last_command <= MAX_REPEAT_NR);
|
||||
void * common_arg = nullptr;
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
RegisterCommand(command, help, args);
|
||||
}
|
||||
|
||||
explicit ConsoleCommand(const char* command, const char* help, std::vector<CommandArgs>& args, std::function<bool(ConsoleCommand *)> f);
|
||||
explicit ConsoleCommand(const char* command, const char* help, const std::vector<CommandArgs>& args, std::function<bool(ConsoleCommand *)> f);
|
||||
int get_count(int index);
|
||||
template<typename T> int get_count_of(CommandArgs T::*member) { return get_count(index_arg(member)); }
|
||||
template<typename T> std::string get_string_of(CommandArgs T::*member) { return get_string(index_arg(member)); }
|
||||
@ -63,7 +63,7 @@ public:
|
||||
int get_int(int index);
|
||||
|
||||
private:
|
||||
void RegisterCommand(const char* command, const char* help, std::vector<CommandArgs>& args);
|
||||
void RegisterCommand(const char* command, const char* help, const std::vector<CommandArgs>& args);
|
||||
template<typename T> static constexpr size_t index_arg(CommandArgs T::*member)
|
||||
{ return ((uint8_t *)&((T*)nullptr->*member) - (uint8_t *)nullptr)/sizeof(CommandArgs); }
|
||||
std::function<bool(ConsoleCommand *)> func;
|
||||
|
@ -30,7 +30,6 @@ static esp_console_repl_t *s_repl = nullptr;
|
||||
|
||||
using namespace esp_modem;
|
||||
|
||||
|
||||
#define CHECK_ERR(cmd, success_action) do { \
|
||||
auto err = cmd; \
|
||||
if (err == command_result::OK) { \
|
||||
@ -49,9 +48,8 @@ extern "C" void app_main(void)
|
||||
|
||||
// init the DTE
|
||||
esp_modem_dte_config_t dte_config = ESP_MODEM_DTE_DEFAULT_CONFIG();
|
||||
dte_config.pattern_queue_size = 100;
|
||||
dte_config.event_task_stack_size = 4096;
|
||||
dte_config.event_task_priority = 15;
|
||||
dte_config.uart_config.event_task_stack_size = 4096;
|
||||
dte_config.uart_config.event_task_priority = 15;
|
||||
esp_netif_config_t ppp_netif_config = ESP_NETIF_DEFAULT_PPP();
|
||||
|
||||
esp_netif_t *esp_netif = esp_netif_new(&ppp_netif_config);
|
||||
@ -70,12 +68,11 @@ extern "C" void app_main(void)
|
||||
|
||||
modem_console_register_http();
|
||||
modem_console_register_ping();
|
||||
|
||||
const struct SetModeArgs {
|
||||
SetModeArgs(): mode(STR1, nullptr, nullptr, "<mode>", "PPP or CMD") {}
|
||||
CommandArgs mode;
|
||||
} set_mode_args;
|
||||
ConsoleCommand SetModeParser("set_mode", "sets modem mode", &set_mode_args, sizeof(set_mode_args), [&](ConsoleCommand *c){
|
||||
const ConsoleCommand SetModeParser("set_mode", "sets modem mode", &set_mode_args, sizeof(set_mode_args), [&](ConsoleCommand *c){
|
||||
if (c->get_count_of(&SetModeArgs::mode)) {
|
||||
auto mode = c->get_string_of(&SetModeArgs::mode);
|
||||
if (mode == "CMD") {
|
||||
@ -96,7 +93,7 @@ extern "C" void app_main(void)
|
||||
SetPinArgs(): pin(STR1, nullptr, nullptr, "<pin>", "PIN") {}
|
||||
CommandArgs pin;
|
||||
} set_pin_args;
|
||||
ConsoleCommand SetPinParser("set_pin", "sets SIM card PIN", &set_pin_args, sizeof(set_pin_args), [&](ConsoleCommand *c){
|
||||
const ConsoleCommand SetPinParser("set_pin", "sets SIM card PIN", &set_pin_args, sizeof(set_pin_args), [&](ConsoleCommand *c){
|
||||
if (c->get_count_of(&SetPinArgs::pin)) {
|
||||
auto pin = c->get_string_of(&SetPinArgs::pin);
|
||||
ESP_LOGI(TAG, "Setting pin=%s...", pin.c_str());
|
||||
@ -111,8 +108,8 @@ extern "C" void app_main(void)
|
||||
return 0;
|
||||
});
|
||||
|
||||
std::vector<CommandArgs> no_args;
|
||||
ConsoleCommand ReadPinArgs("read_pin", "checks if SIM is unlocked", no_args, [&](ConsoleCommand *c){
|
||||
const std::vector<CommandArgs> no_args;
|
||||
const ConsoleCommand ReadPinArgs("read_pin", "checks if SIM is unlocked", no_args, [&](ConsoleCommand *c){
|
||||
bool pin_ok;
|
||||
ESP_LOGI(TAG, "Checking pin...");
|
||||
auto err = dce->read_pin(pin_ok);
|
||||
@ -125,7 +122,7 @@ extern "C" void app_main(void)
|
||||
return 0;
|
||||
});
|
||||
|
||||
ConsoleCommand GetModuleName("get_module_name", "reads the module name", no_args, [&](ConsoleCommand *c){
|
||||
const ConsoleCommand GetModuleName("get_module_name", "reads the module name", no_args, [&](ConsoleCommand *c){
|
||||
std::string module_name;
|
||||
ESP_LOGI(TAG, "Reading module name...");
|
||||
CHECK_ERR(dce->get_module_name(module_name), ESP_LOGI(TAG, "OK. Module name: %s", module_name.c_str()));
|
||||
@ -167,14 +164,15 @@ extern "C" void app_main(void)
|
||||
CHECK_ERR(dce->get_signal_quality(rssi, ber), ESP_LOGI(TAG, "OK. rssi=%d, ber=%d", rssi, ber));
|
||||
});
|
||||
signal_group exit_signal;
|
||||
const ConsoleCommand ExitConsole("exit", "exit the console appliation", no_args, [&](ConsoleCommand *c){
|
||||
const ConsoleCommand ExitConsole("exit", "exit the console application", no_args, [&](ConsoleCommand *c){
|
||||
ESP_LOGI(TAG, "Exiting...");
|
||||
exit_signal.set(1);
|
||||
s_repl->del(s_repl);
|
||||
return true;
|
||||
return 0;
|
||||
});
|
||||
// start console REPL
|
||||
ESP_ERROR_CHECK(esp_console_start_repl(s_repl));
|
||||
ESP_LOGI(TAG, "Exiting...%d", esp_get_free_heap_size());
|
||||
// wait till for exit
|
||||
exit_signal.wait_any(1, UINT32_MAX);
|
||||
}
|
||||
|
@ -141,17 +141,7 @@ extern "C" void app_main(void)
|
||||
assert(esp_netif);
|
||||
|
||||
auto dce = create_SIM7600_dce(&dce_config, uart_dte, esp_netif);
|
||||
/// TEST
|
||||
{
|
||||
// std::string str;
|
||||
// dce->set_mode(esp_modem::modem_mode::CMUX_MODE);
|
||||
// while (1) {
|
||||
// dce->get_imsi(str);
|
||||
// std::cout << "Modem IMSI number:" << str << "|" << std::endl;
|
||||
// }
|
||||
}
|
||||
// return;
|
||||
//// TEST
|
||||
|
||||
dce->set_command_mode();
|
||||
|
||||
std::string str;
|
||||
|
Reference in New Issue
Block a user