sketching up the command library

This commit is contained in:
David Cermak
2021-03-02 21:01:44 +01:00
parent a9a00387cc
commit 00662fcaea
3 changed files with 57 additions and 1 deletions

View File

@ -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")

View 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

View 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;
};
}