| 
									
										
										
										
											2021-05-15 22:09:08 +02:00
										 |  |  | #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"
 | 
					
						
							| 
									
										
										
										
											2021-05-23 20:43:50 +02:00
										 |  |  | #include "vfs_resource/vfs_create.hpp"
 | 
					
						
							| 
									
										
										
										
											2021-05-15 22:09:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-19 07:28:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define CONFIG_EXAMPLE_SIM_PIN "1234"
 | 
					
						
							| 
									
										
										
										
											2021-05-23 20:43:50 +02:00
										 |  |  | #define CONFIG_USE_VFS_UART     1
 | 
					
						
							| 
									
										
										
										
											2021-05-19 07:28:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-15 22:09:08 +02:00
										 |  |  | using namespace esp_modem; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-26 16:41:19 +08:00
										 |  |  | [[maybe_unused]] constexpr auto TAG = "linux_modem_main"; | 
					
						
							| 
									
										
										
										
											2021-05-15 22:09:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-19 07:28:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-15 22:09:08 +02:00
										 |  |  | int main() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // init the DTE
 | 
					
						
							|  |  |  |     esp_modem_dte_config_t dte_config = { | 
					
						
							| 
									
										
										
										
											2021-06-01 10:21:51 +02:00
										 |  |  |         .dte_buffer_size = 512, | 
					
						
							|  |  |  |         .task_stack_size = 1024, | 
					
						
							|  |  |  |         .task_priority = 10, | 
					
						
							|  |  |  |         .vfs_config = {} | 
					
						
							| 
									
										
										
										
											2021-05-23 20:43:50 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  | #if CONFIG_USE_VFS_UART == 1
 | 
					
						
							|  |  |  |     struct esp_modem_vfs_uart_creator uart_config = { | 
					
						
							| 
									
										
										
										
											2021-06-01 10:21:51 +02:00
										 |  |  |         .dev_name = "/dev/ttyUSB0", | 
					
						
							|  |  |  |         .uart = {} | 
					
						
							| 
									
										
										
										
											2021-05-23 20:43:50 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  |     assert(vfs_create_uart(&uart_config, &dte_config.vfs_config) == true); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |     /**
 | 
					
						
							|  |  |  |      * @note: It is possible to setup a serial to socket bridge, running a this on a remote host which connects `/dev/ttyS0` to the modem | 
					
						
							|  |  |  |      * socat TCP-L:2222 GOPEN:/dev/ttyS0,ispeed=115200,ospeed=1152000,b115200,raw,echo=0 | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     struct esp_modem_vfs_socket_creator socket_config = { | 
					
						
							| 
									
										
										
										
											2021-06-01 10:21:51 +02:00
										 |  |  |         .host_name = "raspberrypi.local", | 
					
						
							|  |  |  |         .port = 2222 | 
					
						
							| 
									
										
										
										
											2021-05-15 22:09:08 +02:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2021-05-23 20:43:50 +02:00
										 |  |  |     assert(vfs_create_socket(&socket_config, &dte_config.vfs_config) == true); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |     auto dte = create_vfs_dte(&dte_config); | 
					
						
							| 
									
										
										
										
											2021-05-15 22:09:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     esp_netif_config_t netif_config = { | 
					
						
							| 
									
										
										
										
											2021-06-01 10:21:51 +02:00
										 |  |  |         .dev_name = "/dev/net/tun", | 
					
						
							|  |  |  |         .if_name = "tun0" | 
					
						
							| 
									
										
										
										
											2021-05-15 22:09:08 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  |     esp_netif_t *tun_netif = esp_netif_new(&netif_config); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("internet"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-23 20:43:50 +02:00
										 |  |  |     auto dce = create_SIM7600_dce(&dce_config, dte, tun_netif); | 
					
						
							| 
									
										
										
										
											2021-05-15 22:09:08 +02:00
										 |  |  |     assert(dce != nullptr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dce->set_command_mode(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool pin_ok = true; | 
					
						
							|  |  |  |     if (dce->read_pin(pin_ok) == command_result::OK && !pin_ok) { | 
					
						
							| 
									
										
										
										
											2022-07-13 08:45:43 +02:00
										 |  |  |         ESP_MODEM_THROW_IF_FALSE(dce->set_pin(CONFIG_EXAMPLE_SIM_PIN) == command_result::OK, "Cannot set PIN!"); | 
					
						
							| 
									
										
										
										
											2021-05-15 22:09:08 +02:00
										 |  |  |         usleep(1000000); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     std::string str; | 
					
						
							| 
									
										
										
										
											2021-05-23 20:43:50 +02:00
										 |  |  | //    dce->set_mode(esp_modem::modem_mode::CMUX_MODE);
 | 
					
						
							| 
									
										
										
										
											2021-05-15 22:09:08 +02:00
										 |  |  |     dce->get_imsi(str); | 
					
						
							| 
									
										
										
										
											2021-06-01 10:21:51 +02:00
										 |  |  |     ESP_LOGI(TAG, "Modem IMSI number: %s", str.c_str()); | 
					
						
							| 
									
										
										
										
											2021-05-15 22:09:08 +02:00
										 |  |  |     dce->get_imei(str); | 
					
						
							| 
									
										
										
										
											2021-06-01 10:21:51 +02:00
										 |  |  |     ESP_LOGI(TAG, "Modem IMEI number: %s", str.c_str()); | 
					
						
							|  |  |  |     while (command_result::OK != dce->get_operator_name(str)) { | 
					
						
							|  |  |  |         printf(".\n"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ESP_LOGI(TAG, "Operator name: %s", str.c_str()); | 
					
						
							| 
									
										
										
										
											2021-05-15 22:09:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     dce->set_mode(esp_modem::modem_mode::DATA_MODE); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-23 20:43:50 +02:00
										 |  |  |     usleep(15'000'000); | 
					
						
							| 
									
										
										
										
											2021-05-15 22:09:08 +02:00
										 |  |  |     esp_netif_destroy(tun_netif); | 
					
						
							|  |  |  | } |