mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-15 19:42:09 +02:00
esp_modem: Moved to component folder
This commit is contained in:
committed by
David Cermak
parent
61f264f97a
commit
90641c89eb
13
components/esp_modem/examples/linux_modem/CMakeLists.txt
Normal file
13
components/esp_modem/examples/linux_modem/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS ../.. ../../port/linux)
|
||||
|
||||
set(COMPONENTS main)
|
||||
project(linux_modem)
|
||||
|
||||
|
||||
idf_component_get_property(esp_modem esp_modem COMPONENT_LIB)
|
||||
target_compile_definitions(${esp_modem} PRIVATE "-DCONFIG_COMPILER_CXX_EXCEPTIONS")
|
||||
target_compile_definitions(${esp_modem} PRIVATE "-DCONFIG_IDF_TARGET_LINUX")
|
19
components/esp_modem/examples/linux_modem/README.md
Normal file
19
components/esp_modem/examples/linux_modem/README.md
Normal file
@ -0,0 +1,19 @@
|
||||
# Linux modem example
|
||||
|
||||
This is an experimental port of the esp_modem to linux.
|
||||
It mocks some IDF functionality with `port/linux` layers (used for modem host test suite) and implements `esp_netif`,
|
||||
which supports `tun` interface and uses lwIP `ppp` implementation to parse or wrap IP packets to be send/receive
|
||||
over PPPoS, i.e. over the modem serial line.
|
||||
|
||||
## Configuration
|
||||
|
||||
* Set path to the lwip and lwip_contrib repositories as environmental variables:
|
||||
- `LWIP_PATH`: path to the lwip repository
|
||||
- `LWIP_CONTRIB_PATH`: path to the lwip_contrib repository
|
||||
* Create a `tun` interface using `make_tun_netif` script.
|
||||
* Set SIO dev name directly in the code: This is the serial port which is the modem connected to
|
||||
* (Set the tun device na interface name in the code: Not needed if the device was created using the script above.)
|
||||
* Build and run the example (no elevated privileges needed)
|
||||
* Experiment with the network, after getting the IP from the modem device
|
||||
- directly in the code
|
||||
- in the system (need to set `tun` interface IP, dns servers, and routing the desired traffic over the tun interface)
|
@ -0,0 +1,9 @@
|
||||
idf_component_register(SRCS "modem_main.cpp"
|
||||
REQUIRES esp_modem)
|
||||
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(${COMPONENT_LIB} PRIVATE Threads::Threads)
|
||||
|
||||
target_compile_features(${COMPONENT_LIB} PRIVATE cxx_std_17)
|
||||
target_compile_definitions(${COMPONENT_LIB} PRIVATE "-DCONFIG_IDF_TARGET_LINUX")
|
@ -0,0 +1,65 @@
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
#include <unistd.h>
|
||||
#include <esp_log.h>
|
||||
#include "cxx_include/esp_modem_terminal.hpp"
|
||||
#include "cxx_include/esp_modem_api.hpp"
|
||||
#include "cxx_include/esp_modem_dte.hpp"
|
||||
#include "esp_modem_config.h"
|
||||
#include "esp_netif.h"
|
||||
|
||||
|
||||
#define CONFIG_EXAMPLE_SIM_PIN "1234"
|
||||
|
||||
using namespace esp_modem;
|
||||
|
||||
[[maybe_unused]] static const char *TAG = "linux_modem_main";
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
// init the DTE
|
||||
esp_modem_dte_config_t dte_config = {
|
||||
.dte_buffer_size = 512,
|
||||
.task_stack_size = 1024,
|
||||
.task_priority = 10,
|
||||
.uart_config = { },
|
||||
.vfs_config = { }
|
||||
};
|
||||
dte_config.vfs_config.dev_name = "/dev/ttyUSB0";
|
||||
dte_config.vfs_config.resource = ESP_MODEM_VFS_IS_UART; // This tells the VFS to init the UART (use termux to setup baudrate, etc.)
|
||||
|
||||
esp_netif_config_t netif_config = {
|
||||
.dev_name = "/dev/net/tun",
|
||||
.if_name = "tun0"
|
||||
};
|
||||
esp_netif_t *tun_netif = esp_netif_new(&netif_config);
|
||||
auto uart_dte = create_vfs_dte(&dte_config);
|
||||
|
||||
esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("internet");
|
||||
|
||||
auto dce = create_SIM7600_dce(&dce_config, uart_dte, tun_netif);
|
||||
assert(dce != nullptr);
|
||||
|
||||
dce->set_command_mode();
|
||||
|
||||
bool pin_ok = true;
|
||||
if (dce->read_pin(pin_ok) == command_result::OK && !pin_ok) {
|
||||
throw_if_false(dce->set_pin(CONFIG_EXAMPLE_SIM_PIN) == command_result::OK, "Cannot set PIN!");
|
||||
usleep(1000000);
|
||||
}
|
||||
std::string str;
|
||||
dce->set_mode(esp_modem::modem_mode::CMUX_MODE);
|
||||
dce->get_imsi(str);
|
||||
ESP_LOGI(TAG, "Modem IMSI number: %s",str.c_str());
|
||||
dce->get_imei(str);
|
||||
ESP_LOGI(TAG, "Modem IMEI number: %s",str.c_str());
|
||||
dce->get_operator_name(str);
|
||||
ESP_LOGI(TAG, "Operator name: %s",str.c_str());
|
||||
|
||||
dce->set_mode(esp_modem::modem_mode::DATA_MODE);
|
||||
|
||||
usleep(100'000'000);
|
||||
esp_netif_destroy(tun_netif);
|
||||
}
|
3
components/esp_modem/examples/linux_modem/make_tun_netif
Executable file
3
components/esp_modem/examples/linux_modem/make_tun_netif
Executable file
@ -0,0 +1,3 @@
|
||||
sudo ip tuntap add mode tun user `whoami`
|
||||
sudo ip link set dev tun0 up
|
||||
sudo ifconfig tun0 10.184.178.109 netmask 255.255.255.255 up
|
@ -0,0 +1,5 @@
|
||||
CONFIG_IDF_TARGET="linux"
|
||||
CONFIG_COMPILER_CXX_EXCEPTIONS=y
|
||||
CONFIG_COMPILER_CXX_RTTI=y
|
||||
CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE=0
|
||||
CONFIG_COMPILER_STACK_CHECK_NONE=y
|
Reference in New Issue
Block a user