mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-16 12:02:11 +02:00
sketching up the command library
This commit is contained in:
@ -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")
|
||||
|
||||
|
19
esp_modem/include/cxx_include/esp_modem_commands.hpp
Normal file
19
esp_modem/include/cxx_include/esp_modem_commands.hpp
Normal file
@ -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 <typename T> esp_err_t sync(T t);
|
||||
|
||||
} // dce_commands
|
||||
} // esp_modem
|
||||
|
||||
|
||||
#endif //SIMPLE_CXX_CLIENT_ESP_MODEM_COMMANDS_HPP
|
36
esp_modem/src/esp_modem_commands.cpp
Normal file
36
esp_modem/src/esp_modem_commands.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "cxx_include/esp_modem_commands.hpp"
|
||||
#include "cxx_include/esp_modem_dte.hpp"
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace esp_modem::dce_commands {
|
||||
|
||||
template <typename T> 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 T>
|
||||
class generic_dce {
|
||||
public:
|
||||
explicit generic_dce(std::shared_ptr<dte> e) : dce_dte(std::move(e)) {}
|
||||
|
||||
esp_err_t sync() { return dce_commands::sync(dce_dte); }
|
||||
|
||||
private:
|
||||
std::shared_ptr<T> dce_dte;
|
||||
};
|
||||
|
||||
}
|
Reference in New Issue
Block a user