Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1583831

Browse files
committedNov 6, 2024
feat(modem): Add pregenerated files to git
1 parent 5c19da8 commit 1583831

File tree

14 files changed

+4044
-2
lines changed

14 files changed

+4044
-2
lines changed
 

‎.github/workflows/modem__build-host-tests.yml

+16
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,19 @@ jobs:
100100
run_executable: false
101101
run_coverage: false
102102
pre_run_script: "esp-protocols/components/esp_modem/test/host_test/env.sh"
103+
104+
esp_modem_generated_commands:
105+
if: contains(github.event.pull_request.labels.*.name, 'modem') || github.event_name == 'push'
106+
name: Generated commands compatibility
107+
runs-on: ubuntu-latest
108+
steps:
109+
- name: Checkout esp-protocols
110+
uses: actions/checkout@v4
111+
shell: bash
112+
run: |
113+
apt-get update -y
114+
apt-get install -y astyle
115+
cd components/esp_modem
116+
find examples/ -type f -regex '.*/generate/.*\.\(hpp\|cpp\)' -exec ./scripts/generate.sh {} \;
117+
./scripts/generate.sh
118+
git diff --quiet
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,368 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include "cxx_include/esp_modem_dte.hpp"
10+
#include "cxx_include/esp_modem_dce_module.hpp"
11+
#include "cxx_include/esp_modem_types.hpp"
12+
13+
// --- ESP-MODEM command module starts here ---
14+
namespace esp_modem {
15+
namespace dce_commands {
16+
17+
/**
18+
* @defgroup ESP_MODEM_DCE_COMMAND ESP_MODEM DCE command library
19+
* @brief Library of the most useful DCE commands
20+
*/
21+
/** @addtogroup ESP_MODEM_DCE_COMMAND
22+
* @{
23+
*/
24+
25+
/**
26+
* @brief Generic AT command to be send with pass and fail phrases
27+
*
28+
* @param t Commandable object (anything that can accept commands)
29+
* @param command Command to be sent do the commandable object
30+
* @param pass_phrase String to be present in the reply to pass this command
31+
* @param fail_phrase String to be present in the reply to fail this command
32+
* @param timeout_ms Timeout in ms
33+
*/
34+
command_result generic_command(CommandableIf *t, const std::string &command,
35+
const std::string &pass_phrase,
36+
const std::string &fail_phrase, uint32_t timeout_ms);
37+
38+
/**
39+
* @brief Declaration of all commands is generated from esp_modem_command_declare.inc
40+
*/
41+
42+
43+
//
44+
//#define INT_IN(name) int name
45+
//#ifdef __cplusplus
46+
//#define STRING_IN(name) const std::string& name
47+
//#define STRING_OUT(name) std::string& name
48+
//#define BOOL_IN(name) const bool name
49+
//#define BOOL_OUT(name) bool& name
50+
//#define INT_OUT(name) int& name
51+
//#define INTEGER_LIST_IN(name) const int* name
52+
//#define STRUCT_OUT(struct_name, name) struct_name& name
53+
//#else
54+
//#define STRING_IN(name) const char* name
55+
//#define STRING_OUT(name) char* name
56+
//#define BOOL_IN(name) const bool name
57+
//#define BOOL_OUT(name) bool* name
58+
//#define INT_OUT(name) int* name
59+
//#define INTEGER_LIST_IN(name) const int* name
60+
//#define STRUCT_OUT(struct_name, name) esp_modem_ ## struct_name ## _t* name
61+
//#endif
62+
//
63+
//#define FORWARD_INT_IN(name) name
64+
//#define FORWARD_STRING_IN(name) name
65+
//#define FORWARD_STRING_OUT(name) name
66+
//#define FORWARD_BOOL_IN(name) name
67+
//#define FORWARD_BOOL_OUT(name) name
68+
//#define FORWARD_INT_OUT(name) name
69+
//#define FORWARD_INTEGER_LIST_IN(name) name
70+
//#define FORWARD_STRUCT_OUT(struct_name, name) name
71+
72+
// Utility to count arguments (works for up to two parameters here)
73+
74+
75+
76+
/**
77+
* @brief Sends the initial AT sequence to sync up with the device
78+
* @return OK, FAIL or TIMEOUT
79+
*/
80+
command_result sync(CommandableIf *t );
81+
82+
/**
83+
* @brief Reads the operator name
84+
* @param[out] name operator name
85+
* @param[out] act access technology
86+
* @return OK, FAIL or TIMEOUT
87+
*/
88+
command_result get_operator_name(CommandableIf *t, std::string &name, int &act );
89+
90+
/**
91+
* @brief Stores current user profile
92+
* @return OK, FAIL or TIMEOUT
93+
*/
94+
command_result store_profile(CommandableIf *t );
95+
96+
/**
97+
* @brief Sets the supplied PIN code
98+
* @param[in] pin Pin
99+
* @return OK, FAIL or TIMEOUT
100+
*/
101+
command_result set_pin(CommandableIf *t, const std::string &pin );
102+
103+
/**
104+
* @brief Execute the supplied AT command in raw mode (doesn't append '\r' to command, returns everything)
105+
* @param[in] cmd String command that's send to DTE
106+
* @param[out] out Raw output from DTE
107+
* @param[in] pass Pattern in response for the API to return OK
108+
* @param[in] fail Pattern in response for the API to return FAIL
109+
* @param[in] timeout AT command timeout in milliseconds
110+
* @return OK, FAIL or TIMEOUT
111+
*/
112+
command_result at_raw(CommandableIf *t, const std::string &cmd, std::string &out, const std::string &pass, const std::string &fail, int timeout );
113+
114+
/**
115+
* @brief Execute the supplied AT command
116+
* @param[in] cmd AT command
117+
* @param[out] out Command output string
118+
* @param[in] timeout AT command timeout in milliseconds
119+
* @return OK, FAIL or TIMEOUT
120+
*/
121+
command_result at(CommandableIf *t, const std::string &cmd, std::string &out, int timeout );
122+
123+
/**
124+
* @brief Checks if the SIM needs a PIN
125+
* @param[out] pin_ok true if the SIM card doesn't need a PIN to unlock
126+
* @return OK, FAIL or TIMEOUT
127+
*/
128+
command_result read_pin(CommandableIf *t, bool &pin_ok );
129+
130+
/**
131+
* @brief Sets echo mode
132+
* @param[in] echo_on true if echo mode on (repeats the commands)
133+
* @return OK, FAIL or TIMEOUT
134+
*/
135+
command_result set_echo(CommandableIf *t, const bool echo_on );
136+
137+
/**
138+
* @brief Sets the Txt or Pdu mode for SMS (only txt is supported)
139+
* @param[in] txt true if txt mode
140+
* @return OK, FAIL or TIMEOUT
141+
*/
142+
command_result sms_txt_mode(CommandableIf *t, const bool txt );
143+
144+
/**
145+
* @brief Sets the default (GSM) character set
146+
* @return OK, FAIL or TIMEOUT
147+
*/
148+
command_result sms_character_set(CommandableIf *t );
149+
150+
/**
151+
* @brief Sends SMS message in txt mode
152+
* @param[in] number Phone number to send the message to
153+
* @param[in] message Text message to be sent
154+
* @return OK, FAIL or TIMEOUT
155+
*/
156+
command_result send_sms(CommandableIf *t, const std::string &number, const std::string &message );
157+
158+
/**
159+
* @brief Resumes data mode (Switches back to the data mode, which was temporarily suspended)
160+
* @return OK, FAIL or TIMEOUT
161+
*/
162+
command_result resume_data_mode(CommandableIf *t );
163+
164+
/**
165+
* @brief Sets php context
166+
* @param[in] p1 PdP context struct to setup modem cellular connection
167+
* @return OK, FAIL or TIMEOUT
168+
*/
169+
command_result set_pdp_context(CommandableIf *t, PdpContext &pdp );
170+
171+
/**
172+
* @brief Switches to the command mode
173+
* @return OK, FAIL or TIMEOUT
174+
*/
175+
command_result set_command_mode(CommandableIf *t );
176+
177+
/**
178+
* @brief Switches to the CMUX mode
179+
* @return OK, FAIL or TIMEOUT
180+
*/
181+
command_result set_cmux(CommandableIf *t );
182+
183+
/**
184+
* @brief Reads the IMSI number
185+
* @param[out] imsi Module's IMSI number
186+
* @return OK, FAIL or TIMEOUT
187+
*/
188+
command_result get_imsi(CommandableIf *t, std::string &imsi );
189+
190+
/**
191+
* @brief Reads the IMEI number
192+
* @param[out] imei Module's IMEI number
193+
* @return OK, FAIL or TIMEOUT
194+
*/
195+
command_result get_imei(CommandableIf *t, std::string &imei );
196+
197+
/**
198+
* @brief Reads the module name
199+
* @param[out] name module name
200+
* @return OK, FAIL or TIMEOUT
201+
*/
202+
command_result get_module_name(CommandableIf *t, std::string &name );
203+
204+
/**
205+
* @brief Sets the modem to data mode
206+
* @return OK, FAIL or TIMEOUT
207+
*/
208+
command_result set_data_mode(CommandableIf *t );
209+
210+
/**
211+
* @brief Get Signal quality
212+
* @param[out] rssi signal strength indication
213+
* @param[out] ber channel bit error rate
214+
* @return OK, FAIL or TIMEOUT
215+
*/
216+
command_result get_signal_quality(CommandableIf *t, int &rssi, int &ber );
217+
218+
/**
219+
* @brief Sets HW control flow
220+
* @param[in] dce_flow 0=none, 2=RTS hw flow control of DCE
221+
* @param[in] dte_flow 0=none, 2=CTS hw flow control of DTE
222+
* @return OK, FAIL or TIMEOUT
223+
*/
224+
command_result set_flow_control(CommandableIf *t, int dce_flow, int dte_flow );
225+
226+
/**
227+
* @brief Hangs up current data call
228+
* @return OK, FAIL or TIMEOUT
229+
*/
230+
command_result hang_up(CommandableIf *t );
231+
232+
/**
233+
* @brief Get voltage levels of modem power up circuitry
234+
* @param[out] voltage Current status in mV
235+
* @param[out] bcs charge status (-1-Not available, 0-Not charging, 1-Charging, 2-Charging done)
236+
* @param[out] bcl 1-100% battery capacity, -1-Not available
237+
* @return OK, FAIL or TIMEOUT
238+
*/
239+
command_result get_battery_status(CommandableIf *t, int &voltage, int &bcs, int &bcl );
240+
241+
/**
242+
* @brief Power down the module
243+
* @return OK, FAIL or TIMEOUT
244+
*/
245+
command_result power_down(CommandableIf *t );
246+
247+
/**
248+
* @brief Reset the module
249+
* @return OK, FAIL or TIMEOUT
250+
*/
251+
command_result reset(CommandableIf *t );
252+
253+
/**
254+
* @brief Configures the baudrate
255+
* @param[in] baud Desired baud rate of the DTE
256+
* @return OK, FAIL or TIMEOUT
257+
*/
258+
command_result set_baud(CommandableIf *t, int baud );
259+
260+
/**
261+
* @brief Force an attempt to connect to a specific operator
262+
* @param[in] mode mode of attempt
263+
* mode=0 - automatic
264+
* mode=1 - manual
265+
* mode=2 - deregister
266+
* mode=3 - set format for read operation
267+
* mode=4 - manual with fallback to automatic
268+
* @param[in] format what format the operator is given in
269+
* format=0 - long format
270+
* format=1 - short format
271+
* format=2 - numeric
272+
* @param[in] oper the operator to connect to
273+
* @return OK, FAIL or TIMEOUT
274+
*/
275+
command_result set_operator(CommandableIf *t, int mode, int format, const std::string &oper );
276+
277+
/**
278+
* @brief Attach or detach from the GPRS service
279+
* @param[in] state 1-attach 0-detach
280+
* @return OK, FAIL or TIMEOUT
281+
*/
282+
command_result set_network_attachment_state(CommandableIf *t, int state );
283+
284+
/**
285+
* @brief Get network attachment state
286+
* @param[out] state 1-attached 0-detached
287+
* @return OK, FAIL or TIMEOUT
288+
*/
289+
command_result get_network_attachment_state(CommandableIf *t, int &state );
290+
291+
/**
292+
* @brief What mode the radio should be set to
293+
* @param[in] state state 1-full 0-minimum ...
294+
* @return OK, FAIL or TIMEOUT
295+
*/
296+
command_result set_radio_state(CommandableIf *t, int state );
297+
298+
/**
299+
* @brief Get current radio state
300+
* @param[out] state 1-full 0-minimum ...
301+
* @return OK, FAIL or TIMEOUT
302+
*/
303+
command_result get_radio_state(CommandableIf *t, int &state );
304+
305+
/**
306+
* @brief Set network mode
307+
* @param[in] mode preferred mode
308+
* @return OK, FAIL or TIMEOUT
309+
*/
310+
command_result set_network_mode(CommandableIf *t, int mode );
311+
312+
/**
313+
* @brief Preferred network mode (CAT-M and/or NB-IoT)
314+
* @param[in] mode preferred selection
315+
* @return OK, FAIL or TIMEOUT
316+
*/
317+
command_result set_preferred_mode(CommandableIf *t, int mode );
318+
319+
/**
320+
* @brief Set network bands for CAT-M or NB-IoT
321+
* @param[in] mode CAT-M or NB-IoT
322+
* @param[in] bands bitmap in hex representing bands
323+
* @param[in] size size of teh bands bitmap
324+
* @return OK, FAIL or TIMEOUT
325+
*/
326+
command_result set_network_bands(CommandableIf *t, const std::string &mode, const int *bands, int size );
327+
328+
/**
329+
* @brief Show network system mode
330+
* @param[out] mode current network mode
331+
* @return OK, FAIL or TIMEOUT
332+
*/
333+
command_result get_network_system_mode(CommandableIf *t, int &mode );
334+
335+
/**
336+
* @brief GNSS power control
337+
* @param[out] mode power mode (0 - off, 1 - on)
338+
* @return OK, FAIL or TIMEOUT
339+
*/
340+
command_result set_gnss_power_mode(CommandableIf *t, int mode );
341+
342+
/**
343+
* @brief GNSS power control
344+
* @param[out] mode power mode (0 - off, 1 - on)
345+
* @return OK, FAIL or TIMEOUT
346+
*/
347+
command_result get_gnss_power_mode(CommandableIf *t, int &mode );
348+
349+
350+
351+
/**
352+
* @brief Following commands that are different for some specific modules
353+
*/
354+
command_result get_battery_status_sim7xxx(CommandableIf *t, int &voltage, int &bcs, int &bcl);
355+
command_result set_gnss_power_mode_sim76xx(CommandableIf *t, int mode);
356+
command_result power_down_sim76xx(CommandableIf *t);
357+
command_result power_down_sim70xx(CommandableIf *t);
358+
command_result set_network_bands_sim76xx(CommandableIf *t, const std::string &mode, const int *bands, int size);
359+
command_result power_down_sim8xx(CommandableIf *t);
360+
command_result set_data_mode_alt(CommandableIf *t);
361+
command_result set_pdp_context(CommandableIf *t, PdpContext &pdp, uint32_t timeout_ms);
362+
363+
/**
364+
* @}
365+
*/
366+
367+
} // dce_commands
368+
} // esp_modem

‎components/esp_modem/command/include/cxx_include/esp_modem_dce_generic.hpp

+463
Large diffs are not rendered by default.

‎components/esp_modem/command/include/cxx_include/esp_modem_dce_module.hpp

+492
Large diffs are not rendered by default.

‎components/esp_modem/command/src/esp_modem_modules.cpp

+501
Large diffs are not rendered by default.

‎components/esp_modem/examples/modem_console/main/command/my_module_dce.cpp

+519
Large diffs are not rendered by default.

‎components/esp_modem/examples/modem_console/main/command/my_module_dce.hpp

+413
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include "cxx_include/esp_modem_dte.hpp"
10+
#include "cxx_include/esp_modem_dce_module.hpp"
11+
#include "cxx_include/esp_modem_types.hpp"
12+
13+
14+
namespace sock_commands {
15+
16+
// --- ESP-MODEM command module starts here ---
17+
18+
//
19+
//#define INT_IN(name) int name
20+
//#ifdef __cplusplus
21+
//#define STRING_IN(name) const std::string& name
22+
//#define STRING_OUT(name) std::string& name
23+
//#define BOOL_IN(name) const bool name
24+
//#define BOOL_OUT(name) bool& name
25+
//#define INT_OUT(name) int& name
26+
//#define INTEGER_LIST_IN(name) const int* name
27+
//#define STRUCT_OUT(struct_name, name) struct_name& name
28+
//#else
29+
//#define STRING_IN(name) const char* name
30+
//#define STRING_OUT(name) char* name
31+
//#define BOOL_IN(name) const bool name
32+
//#define BOOL_OUT(name) bool* name
33+
//#define INT_OUT(name) int* name
34+
//#define INTEGER_LIST_IN(name) const int* name
35+
//#define STRUCT_OUT(struct_name, name) esp_modem_ ## struct_name ## _t* name
36+
//#endif
37+
//
38+
//#define FORWARD_INT_IN(name) name
39+
//#define FORWARD_STRING_IN(name) name
40+
//#define FORWARD_STRING_OUT(name) name
41+
//#define FORWARD_BOOL_IN(name) name
42+
//#define FORWARD_BOOL_OUT(name) name
43+
//#define FORWARD_INT_OUT(name) name
44+
//#define FORWARD_INTEGER_LIST_IN(name) name
45+
//#define FORWARD_STRUCT_OUT(struct_name, name) name
46+
47+
// Utility to count arguments (works for up to two parameters here)
48+
49+
50+
51+
/**
52+
* @brief Opens network in AT command mode
53+
* @return OK, FAIL or TIMEOUT
54+
*/
55+
esp_modem::command_result net_open(esp_modem::CommandableIf *t );
56+
57+
/**
58+
* @brief Closes network in AT command mode
59+
* @return OK, FAIL or TIMEOUT
60+
*/
61+
esp_modem::command_result net_close(esp_modem::CommandableIf *t );
62+
63+
/**
64+
* @brief Opens a TCP connection
65+
* @param[in] host Host name or IP address to connect to
66+
* @param[in] port Port number
67+
* @param[in] timeout Connection timeout
68+
* @return OK, FAIL or TIMEOUT
69+
*/
70+
esp_modem::command_result tcp_open(esp_modem::CommandableIf *t, const std::string &host, int port, int timeout );
71+
72+
/**
73+
* @brief Closes opened TCP socket
74+
* @return OK, FAIL or TIMEOUT
75+
*/
76+
esp_modem::command_result tcp_close(esp_modem::CommandableIf *t );
77+
78+
/**
79+
* @brief Gets modem IP address
80+
* @param[out] addr String representation of modem's IP
81+
* @return OK, FAIL or TIMEOUT
82+
*/
83+
esp_modem::command_result get_ip(esp_modem::CommandableIf *t, std::string &addr );
84+
85+
/**
86+
* @brief Sets Rx mode
87+
* @param[in] mode 0=auto, 1=manual
88+
* @return OK, FAIL or TIMEOUT
89+
*/
90+
esp_modem::command_result set_rx_mode(esp_modem::CommandableIf *t, int mode );
91+
92+
93+
}

‎components/esp_modem/examples/modem_tcp_client/main/command/sock_dce.cpp

+403
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "esp_modem_config.h"
8+
#include "cxx_include/esp_modem_api.hpp"
9+
#include <cxx_include/esp_modem_dce_factory.hpp>
10+
#include "sock_commands.hpp"
11+
#include <sys/socket.h>
12+
13+
#pragma once
14+
15+
namespace sock_dce {
16+
17+
18+
enum class status {
19+
IDLE,
20+
CONNECTING,
21+
SENDING,
22+
RECEIVING,
23+
FAILED,
24+
PENDING
25+
};
26+
27+
class Responder {
28+
public:
29+
enum class ret {
30+
OK, FAIL, IN_PROGRESS, NEED_MORE_DATA, NEED_MORE_TIME
31+
};
32+
Responder(int &s, int &ready_fd, std::shared_ptr<esp_modem::DTE> &dte_arg):
33+
sock(s), data_ready_fd(ready_fd), dte(dte_arg) {}
34+
ret process_data(status state, uint8_t *data, size_t len);
35+
ret check_async_replies(status state, std::string_view &response);
36+
37+
void start_sending(size_t len);
38+
void start_receiving(size_t len);
39+
bool start_connecting(std::string host, int port);
40+
status pending();
41+
uint8_t *get_buf()
42+
{
43+
return &buffer[0];
44+
}
45+
size_t get_buf_len()
46+
{
47+
return buffer_size;
48+
}
49+
50+
void clear_offsets()
51+
{
52+
actual_read = 0;
53+
}
54+
55+
size_t data_available()
56+
{
57+
return actual_read;
58+
}
59+
60+
size_t has_data()
61+
{
62+
return total_len;
63+
}
64+
65+
private:
66+
static constexpr size_t buffer_size = 512;
67+
68+
bool on_read(char *data, size_t len)
69+
{
70+
#ifndef CONFIG_EXAMPLE_CUSTOM_TCP_TRANSPORT
71+
::send(sock, data, len, 0);
72+
#else
73+
::memcpy(&buffer[actual_read], data, len);
74+
actual_read += len;
75+
#endif
76+
return true;
77+
}
78+
79+
ret recv(uint8_t *data, size_t len);
80+
ret send(uint8_t *data, size_t len);
81+
ret send(std::string_view response);
82+
ret connect(std::string_view response);
83+
void send_cmd(std::string_view command)
84+
{
85+
dte->write((uint8_t *) command.begin(), command.size());
86+
}
87+
std::array<uint8_t, buffer_size> buffer;
88+
size_t data_to_recv = 0;
89+
size_t actual_read = 0;
90+
size_t total_len = 0;
91+
92+
bool read_again = false;
93+
int &sock;
94+
int &data_ready_fd;
95+
int send_stat = 0;
96+
size_t data_to_send = 0;
97+
std::shared_ptr<esp_modem::DTE> &dte;
98+
};
99+
100+
class DCE : public ::esp_modem::GenericModule {
101+
using esp_modem::GenericModule::GenericModule;
102+
public:
103+
104+
// --- ESP-MODEM command module starts here ---
105+
106+
//
107+
//#define INT_IN(name) int name
108+
//#ifdef __cplusplus
109+
//#define STRING_IN(name) const std::string& name
110+
//#define STRING_OUT(name) std::string& name
111+
//#define BOOL_IN(name) const bool name
112+
//#define BOOL_OUT(name) bool& name
113+
//#define INT_OUT(name) int& name
114+
//#define INTEGER_LIST_IN(name) const int* name
115+
//#define STRUCT_OUT(struct_name, name) struct_name& name
116+
//#else
117+
//#define STRING_IN(name) const char* name
118+
//#define STRING_OUT(name) char* name
119+
//#define BOOL_IN(name) const bool name
120+
//#define BOOL_OUT(name) bool* name
121+
//#define INT_OUT(name) int* name
122+
//#define INTEGER_LIST_IN(name) const int* name
123+
//#define STRUCT_OUT(struct_name, name) esp_modem_ ## struct_name ## _t* name
124+
//#endif
125+
//
126+
//#define FORWARD_INT_IN(name) name
127+
//#define FORWARD_STRING_IN(name) name
128+
//#define FORWARD_STRING_OUT(name) name
129+
//#define FORWARD_BOOL_IN(name) name
130+
//#define FORWARD_BOOL_OUT(name) name
131+
//#define FORWARD_INT_OUT(name) name
132+
//#define FORWARD_INTEGER_LIST_IN(name) name
133+
//#define FORWARD_STRUCT_OUT(struct_name, name) name
134+
135+
// Utility to count arguments (works for up to two parameters here)
136+
137+
138+
139+
/**
140+
* @brief Opens network in AT command mode
141+
* @return OK, FAIL or TIMEOUT
142+
*/
143+
esp_modem::command_result net_open();
144+
145+
/**
146+
* @brief Closes network in AT command mode
147+
* @return OK, FAIL or TIMEOUT
148+
*/
149+
esp_modem::command_result net_close();
150+
151+
/**
152+
* @brief Opens a TCP connection
153+
* @param[in] host Host name or IP address to connect to
154+
* @param[in] port Port number
155+
* @param[in] timeout Connection timeout
156+
* @return OK, FAIL or TIMEOUT
157+
*/
158+
esp_modem::command_result tcp_open(const std::string &host, int port, int timeout );
159+
160+
/**
161+
* @brief Closes opened TCP socket
162+
* @return OK, FAIL or TIMEOUT
163+
*/
164+
esp_modem::command_result tcp_close();
165+
166+
/**
167+
* @brief Gets modem IP address
168+
* @param[out] addr String representation of modem's IP
169+
* @return OK, FAIL or TIMEOUT
170+
*/
171+
esp_modem::command_result get_ip(std::string &addr );
172+
173+
/**
174+
* @brief Sets Rx mode
175+
* @param[in] mode 0=auto, 1=manual
176+
* @return OK, FAIL or TIMEOUT
177+
*/
178+
esp_modem::command_result set_rx_mode(int mode );
179+
180+
181+
bool init();
182+
bool connect(std::string host, int port);
183+
184+
void start_listening(int port);
185+
186+
bool perform_sock();
187+
188+
void set_idle()
189+
{
190+
signal.set(IDLE);
191+
}
192+
193+
bool wait_to_idle(uint32_t ms)
194+
{
195+
if (!signal.wait(IDLE, ms)) {
196+
ESP_LOGE("dce", "Failed to get idle");
197+
return false;
198+
}
199+
if (state != status::IDLE) {
200+
ESP_LOGE("dce", "Unexpected state %d", static_cast<int>(state));
201+
return false;
202+
}
203+
return true;
204+
}
205+
206+
int sync_recv(char *buffer, int len, int timeout_ms)
207+
{
208+
if (!wait_to_idle(timeout_ms)) {
209+
return 0;
210+
}
211+
at.clear_offsets();
212+
state = status::RECEIVING;
213+
uint64_t data;
214+
read(data_ready_fd, &data, sizeof(data));
215+
int max_len = std::min(len, (int)at.get_buf_len());
216+
at.start_receiving(max_len);
217+
if (!signal.wait(IDLE, 500 + timeout_ms)) {
218+
return 0;
219+
}
220+
int ret = at.data_available();
221+
if (ret > 0) {
222+
memcpy(buffer, at.get_buf(), ret);
223+
}
224+
set_idle();
225+
return ret;
226+
}
227+
228+
int sync_send(const char *buffer, size_t len, int timeout_ms)
229+
{
230+
int len_to_send = std::min(len, at.get_buf_len());
231+
if (!wait_to_idle(timeout_ms)) {
232+
return -1;
233+
}
234+
state = status::SENDING;
235+
memcpy(at.get_buf(), buffer, len_to_send);
236+
ESP_LOG_BUFFER_HEXDUMP("dce", at.get_buf(), len, ESP_LOG_VERBOSE);
237+
at.start_sending(len_to_send);
238+
if (!signal.wait(IDLE, timeout_ms + 1000)) {
239+
if (state == status::PENDING) {
240+
state = status::IDLE;
241+
} else {
242+
return -1;
243+
}
244+
}
245+
set_idle();
246+
return len_to_send;
247+
}
248+
249+
int wait_to_read(uint32_t ms)
250+
{
251+
if (at.has_data() > 0) {
252+
ESP_LOGD("dce", "Data buffered in modem (len=%d)", at.has_data());
253+
return 1;
254+
}
255+
struct timeval tv = {
256+
.tv_sec = static_cast<time_t>(ms / 1000),
257+
.tv_usec = 0,
258+
};
259+
fd_set fdset;
260+
FD_ZERO(&fdset);
261+
FD_SET(data_ready_fd, &fdset);
262+
int s = select(data_ready_fd + 1, &fdset, nullptr, nullptr, &tv);
263+
if (s == 0) {
264+
return 0;
265+
} else if (s < 0) {
266+
ESP_LOGE("dce", "select error %d", errno);
267+
return -1;
268+
}
269+
if (FD_ISSET(data_ready_fd, &fdset)) {
270+
ESP_LOGD("dce", "select read: modem data available");
271+
return 1;
272+
}
273+
return -1;
274+
}
275+
276+
private:
277+
esp_modem::SignalGroup signal;
278+
279+
void close_sock();
280+
bool accept_sock();
281+
bool sock_to_at();
282+
bool at_to_sock();
283+
284+
void perform_at(uint8_t *data, size_t len);
285+
286+
status state{status::IDLE};
287+
static constexpr uint8_t IDLE = 1;
288+
Responder at{sock, data_ready_fd, dte};
289+
int sock {-1};
290+
int listen_sock {-1};
291+
int data_ready_fd {-1};
292+
};
293+
294+
std::unique_ptr<DCE> create(const esp_modem::dce_config *config, std::shared_ptr<esp_modem::DTE> dte);
295+
296+
}

‎components/esp_modem/examples/simple_cmux_client/components/SIM7070_gnss/command/SIM7070_gnss.hpp

+477
Large diffs are not rendered by default.

‎components/esp_modem/examples/simple_cmux_client/components/SIM7070_gnss/generate/SIM7070_gnss.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/

‎components/esp_modem/generate/include/esp_modem_api.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/

‎components/esp_modem/scripts/generate.sh

+1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ for file in "${files[@]}"; do
5252
# Preprocess everything else to expand command prototypes or implementations
5353
sed -n '1,/ESP-MODEM command module starts here/!p' "$in_file" | \
5454
$compiler -I"$script_dir" -I"$processing_dir/generate/include" -I"$processing_dir/include" -I"$current_file_dir" - >> "$out_file"
55+
astyle --style=otbs --attach-namespaces --attach-classes --indent=spaces=4 --convert-tabs --align-pointer=name --align-reference=name --keep-one-line-statements --pad-header --pad-oper --quiet "$out_file"
5556
done

0 commit comments

Comments
 (0)
Please sign in to comment.