diff --git a/esp_modem/CMakeLists.txt b/esp_modem/CMakeLists.txt index 9a03093b1..91148ae9c 100644 --- a/esp_modem/CMakeLists.txt +++ b/esp_modem/CMakeLists.txt @@ -9,7 +9,8 @@ set(srcs "src/esp_modem.c" "src/esp_sim7600.c" "src/esp_bg96.c" "src/esp_modem_dte.cpp" - "src/ppp_netif.cpp") + "src/ppp_netif.cpp" + "src/esp_modem_commands.cpp") set(include_dirs "include") diff --git a/esp_modem/include/cxx_include/esp_modem_commands.hpp b/esp_modem/include/cxx_include/esp_modem_commands.hpp new file mode 100644 index 000000000..90ce6ce7a --- /dev/null +++ b/esp_modem/include/cxx_include/esp_modem_commands.hpp @@ -0,0 +1,19 @@ +// +// Created by david on 3/2/21. +// + +#ifndef SIMPLE_CXX_CLIENT_ESP_MODEM_COMMANDS_HPP +#define SIMPLE_CXX_CLIENT_ESP_MODEM_COMMANDS_HPP + +#include "esp_err.h" + +namespace esp_modem { +namespace dce_commands { + +template esp_err_t sync(T t); + +} // dce_commands +} // esp_modem + + +#endif //SIMPLE_CXX_CLIENT_ESP_MODEM_COMMANDS_HPP diff --git a/esp_modem/src/esp_modem_commands.cpp b/esp_modem/src/esp_modem_commands.cpp new file mode 100644 index 000000000..4b959267e --- /dev/null +++ b/esp_modem/src/esp_modem_commands.cpp @@ -0,0 +1,36 @@ +#include "cxx_include/esp_modem_commands.hpp" +#include "cxx_include/esp_modem_dte.hpp" +#include +#include + +namespace esp_modem::dce_commands { + +template esp_err_t sync(T t) +{ + return t->send_command("AT\r", [&](uint8_t *data, size_t len) { + std::string response((char*)data, len); + if (response.find("OK") != std::string::npos) { + return ESP_OK; + } else if (response.find("ERROR") != std::string::npos) { + return ESP_FAIL; + } + return ESP_ERR_INVALID_STATE; + }, 1000); +} + +} + +namespace esp_modem { + +template +class generic_dce { +public: + explicit generic_dce(std::shared_ptr e) : dce_dte(std::move(e)) {} + + esp_err_t sync() { return dce_commands::sync(dce_dte); } + +private: + std::shared_ptr dce_dte; +}; + +} \ No newline at end of file