forked from espressif/esp-protocols
Merge pull request #5 from david-cermak/bugfix/missign_c_api
fix(esp_modem): Add missing C API
This commit is contained in:
11
README.md
11
README.md
@ -1 +1,10 @@
|
|||||||
# Collection of protocol components for ESP-IDF
|
# Collection of protocol components for ESP-IDF
|
||||||
|
|
||||||
|
[Documentation of esp-protocol](https://espressif.github.io/esp-protocols)
|
||||||
|
|
||||||
|
## Components
|
||||||
|
|
||||||
|
### esp_modem
|
||||||
|
|
||||||
|
* Brief introduction [README](components/esp_modem/README.md)
|
||||||
|
* Full html [documentation](https://espressif.github.io/esp-protocols/esp_modem/index.html)
|
||||||
|
@ -16,4 +16,4 @@ Get started with one of the examples:
|
|||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
* Continue with esp-modem [brief overview](docs/README.md)
|
* Continue with esp-modem [brief overview](docs/README.md)
|
||||||
* View the full [html documentation ](docs/html/index.html)
|
* View the full [html documentation](https://espressif.github.io/esp-protocols/esp_modem/index.html)
|
||||||
|
@ -41,6 +41,9 @@ Modem commands
|
|||||||
|
|
||||||
These functions are the actual commands to communicate with the modem using AT command interface.
|
These functions are the actual commands to communicate with the modem using AT command interface.
|
||||||
|
|
||||||
|
Note that the functions which implement AT commands returning textual values use plain ``char *``
|
||||||
|
pointer as the return value. The API expects the output data to point to user allocated space of at least
|
||||||
|
``ESP_MODEM_C_API_STR_MAX`` (64 by default) bytes, it also truncates the output data to this size.
|
||||||
|
|
||||||
.. doxygenfile:: esp_modem_api_commands.h
|
.. doxygenfile:: esp_modem_api_commands.h
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
version: "0.1.9"
|
version: "0.1.11"
|
||||||
description: esp modem
|
description: esp modem
|
||||||
dependencies:
|
dependencies:
|
||||||
# Required IDF version
|
# Required IDF version
|
||||||
|
@ -79,6 +79,7 @@ public:
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (mode == modem_mode::COMMAND_MODE) {
|
} else if (mode == modem_mode::COMMAND_MODE) {
|
||||||
|
Task::Delay(1000); // Mandatory 1s pause
|
||||||
return set_command_mode() == command_result::OK;
|
return set_command_mode() == command_result::OK;
|
||||||
} else if (mode == modem_mode::CMUX_MODE) {
|
} else if (mode == modem_mode::CMUX_MODE) {
|
||||||
return set_cmux() == command_result::OK;
|
return set_cmux() == command_result::OK;
|
||||||
|
@ -76,6 +76,7 @@ public:
|
|||||||
|
|
||||||
static void Delete();
|
static void Delete();
|
||||||
static void Relinquish();
|
static void Relinquish();
|
||||||
|
static void Delay(uint32_t delay);
|
||||||
private:
|
private:
|
||||||
TaskT task_handle;
|
TaskT task_handle;
|
||||||
};
|
};
|
||||||
|
@ -23,6 +23,10 @@
|
|||||||
#include "exception_stub.hpp"
|
#include "exception_stub.hpp"
|
||||||
#include "cstring"
|
#include "cstring"
|
||||||
|
|
||||||
|
#ifndef ESP_MODEM_C_API_STR_MAX
|
||||||
|
#define ESP_MODEM_C_API_STR_MAX 64
|
||||||
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// C API definitions
|
// C API definitions
|
||||||
using namespace esp_modem;
|
using namespace esp_modem;
|
||||||
@ -173,7 +177,85 @@ extern "C" esp_err_t esp_modem_get_imsi(esp_modem_dce_t *dce_wrap, char *p_imsi)
|
|||||||
std::string imsi;
|
std::string imsi;
|
||||||
auto ret = command_response_to_esp_err(dce_wrap->dce->get_imsi(imsi));
|
auto ret = command_response_to_esp_err(dce_wrap->dce->get_imsi(imsi));
|
||||||
if (ret == ESP_OK && !imsi.empty()) {
|
if (ret == ESP_OK && !imsi.empty()) {
|
||||||
strcpy(p_imsi, imsi.c_str());
|
strlcpy(p_imsi, imsi.c_str(), ESP_MODEM_C_API_STR_MAX);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" esp_err_t esp_modem_set_flow_control(esp_modem_dce_t *dce_wrap, int dce_flow, int dte_flow)
|
||||||
|
{
|
||||||
|
if (dce_wrap == nullptr || dce_wrap->dce == nullptr) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
return command_response_to_esp_err(dce_wrap->dce->set_flow_control(dce_flow, dte_flow));
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" esp_err_t esp_modem_store_profile(esp_modem_dce_t *dce_wrap)
|
||||||
|
{
|
||||||
|
if (dce_wrap == nullptr || dce_wrap->dce == nullptr) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
return command_response_to_esp_err(dce_wrap->dce->store_profile());
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" esp_err_t esp_modem_get_imei(esp_modem_dce_t *dce_wrap, char *p_imei)
|
||||||
|
{
|
||||||
|
if (dce_wrap == nullptr || dce_wrap->dce == nullptr) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
std::string imei;
|
||||||
|
auto ret = command_response_to_esp_err(dce_wrap->dce->get_imei(imei));
|
||||||
|
if (ret == ESP_OK && !imei.empty()) {
|
||||||
|
strlcpy(p_imei, imei.c_str(), ESP_MODEM_C_API_STR_MAX);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" esp_err_t esp_modem_get_operator_name(esp_modem_dce_t *dce_wrap, char *p_name)
|
||||||
|
{
|
||||||
|
if (dce_wrap == nullptr || dce_wrap->dce == nullptr) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
std::string name;
|
||||||
|
auto ret = command_response_to_esp_err(dce_wrap->dce->get_operator_name(name));
|
||||||
|
if (ret == ESP_OK && !name.empty()) {
|
||||||
|
strlcpy(p_name, name.c_str(), ESP_MODEM_C_API_STR_MAX);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" esp_err_t esp_modem_get_module_name(esp_modem_dce_t *dce_wrap, char *p_name)
|
||||||
|
{
|
||||||
|
if (dce_wrap == nullptr || dce_wrap->dce == nullptr) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
std::string name;
|
||||||
|
auto ret = command_response_to_esp_err(dce_wrap->dce->get_module_name(name));
|
||||||
|
if (ret == ESP_OK && !name.empty()) {
|
||||||
|
strlcpy(p_name, name.c_str(), ESP_MODEM_C_API_STR_MAX);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" esp_err_t esp_modem_get_battery_status(esp_modem_dce_t *dce_wrap, int *p_volt, int *p_bcs, int *p_bcl)
|
||||||
|
{
|
||||||
|
if (dce_wrap == nullptr || dce_wrap->dce == nullptr || p_bcs == nullptr || p_bcl == nullptr || p_volt == nullptr) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
int bcs, bcl, volt;
|
||||||
|
auto ret = command_response_to_esp_err(dce_wrap->dce->get_battery_status(volt, bcs, bcl));
|
||||||
|
if (ret == ESP_OK) {
|
||||||
|
*p_volt = volt;
|
||||||
|
*p_bcs = bcs;
|
||||||
|
*p_bcl = bcl;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" esp_err_t esp_modem_power_down(esp_modem_dce_t *dce_wrap)
|
||||||
|
{
|
||||||
|
if (dce_wrap == nullptr || dce_wrap->dce == nullptr) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
return command_response_to_esp_err(dce_wrap->dce->power_down());
|
||||||
|
}
|
||||||
|
@ -106,4 +106,9 @@ void Task::Relinquish()
|
|||||||
vTaskDelay(1);
|
vTaskDelay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Task::Delay(uint32_t ms)
|
||||||
|
{
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(ms));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace esp_modem
|
} // namespace esp_modem
|
Reference in New Issue
Block a user