-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
demo(esp_modem): console uses DCE commandable to handle URC
- Loading branch information
1 parent
a299192
commit c61fe1f
Showing
6 changed files
with
189 additions
and
7 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
components/esp_modem/examples/modem_console/main/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
components/esp_modem/examples/modem_console/main/my_module_dce.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* Modem console example: Custom DCE | ||
This example code is in the Public Domain (or CC0 licensed, at your option.) | ||
Unless required by applicable law or agreed to in writing, this | ||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
CONDITIONS OF ANY KIND, either express or implied. | ||
*/ | ||
|
||
#include <cstring> | ||
#include "cxx_include/esp_modem_api.hpp" | ||
#include "cxx_include/esp_modem_dce_module.hpp" | ||
#include "generate/esp_modem_command_declare.inc" | ||
#include "my_module_dce.hpp" | ||
|
||
using namespace esp_modem; | ||
|
||
// | ||
// Define preprocessor's forwarding to dce_commands definitions | ||
// | ||
|
||
// Helper macros to handle multiple arguments of declared API | ||
#define ARGS0 | ||
#define ARGS1 , p1 | ||
#define ARGS2 , p1 , p2 | ||
#define ARGS3 , p1 , p2 , p3 | ||
#define ARGS4 , p1 , p2 , p3, p4 | ||
#define ARGS5 , p1 , p2 , p3, p4, p5 | ||
#define ARGS6 , p1 , p2 , p3, p4, p5, p6 | ||
|
||
#define _ARGS(x) ARGS ## x | ||
#define ARGS(x) _ARGS(x) | ||
|
||
// | ||
// Repeat all declarations and forward to the AT commands defined in esp_modem::dce_commands:: namespace | ||
// | ||
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, arg_nr, ...) \ | ||
return_type Shiny::DCE::name(__VA_ARGS__) { return esp_modem::dce_commands::name(this ARGS(arg_nr) ); } | ||
|
||
DECLARE_ALL_COMMAND_APIS(return_type name(...) ) | ||
|
||
#undef ESP_MODEM_DECLARE_DCE_COMMAND | ||
|
||
std::unique_ptr<Shiny::DCE> create_shiny_dce(const esp_modem::dce_config *config, | ||
std::shared_ptr<esp_modem::DTE> dte, | ||
esp_netif_t *netif) | ||
{ | ||
return Shiny::Factory::create(config, std::move(dte), netif); | ||
} | ||
|
||
command_result Shiny::DCE::command(const std::string &cmd, got_line_cb got_line, uint32_t time_ms, const char separator) | ||
{ | ||
if (!handling_urc) { | ||
return dte->command(cmd, got_line, time_ms, separator); | ||
} | ||
handle_cmd = got_line; | ||
signal.clear(3); | ||
dte->write_cmd((uint8_t *)cmd.c_str(), cmd.length()); | ||
signal.wait_any(3, time_ms); | ||
handle_cmd = nullptr; | ||
if (signal.is_any(1)) { | ||
return esp_modem::command_result::OK; | ||
} | ||
if (signal.is_any(2)) { | ||
return esp_modem::command_result::FAIL; | ||
} | ||
return esp_modem::command_result::TIMEOUT; | ||
} | ||
|
||
command_result Shiny::DCE::handle_data(uint8_t *data, size_t len) | ||
{ | ||
if (std::memchr(data, '\n', len)) { | ||
if (handle_urc) { | ||
handle_urc(data, len); | ||
} | ||
if (handle_cmd) { | ||
auto ret = handle_cmd(data, len); | ||
if (ret == esp_modem::command_result::TIMEOUT) { | ||
return command_result::TIMEOUT; | ||
} | ||
if (ret == esp_modem::command_result::OK) { | ||
signal.set(1); | ||
} | ||
if (ret == esp_modem::command_result::FAIL) { | ||
signal.set(2); | ||
} | ||
} | ||
} | ||
return command_result::TIMEOUT; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters