17
17
18
18
/* *
19
19
* @brief A class that provides methods to interact with a modem.
20
- *
20
+ *
21
21
* This class is responsible for providing an interface to communicate with
22
- * a modem through serial communication. It includes methods for initialization,
22
+ * a modem through serial communication. It includes methods for initialization,
23
23
* sending and receiving data, and handling modem configurations.
24
24
*/
25
25
class ModemClass {
26
26
27
27
public:
28
- /* *
29
- * @brief Constructor for the ModemClass, which initializes the modem with the specified transmit (TX) and receive (RX) pins.
30
- *
31
- * @param Initializes an instance of the ModemClass class with
32
- * specific transmit `tx` and receive `rx` pins for communication.
33
- */
34
- ModemClass (int tx, int rx);
35
-
36
- /* *
37
- * @brief Constructor for the ModemClass, which initializes the modem with the specified UART interface.
38
- *
39
- * @param `_serial` is a pointer to the UART object that will be used for communication with the modem.
40
- */
41
- ModemClass (UART * _serial);
42
-
43
- /* *
44
- * @brief Destructor for ModemClass.
45
- */
46
- ~ModemClass ();
47
-
48
-
49
- /* *
50
- * @brief Initializes the modem communication with a specified baud rate.
51
- *
52
- * @param[in] `badurate` sets the baud rate for the serial connection.
53
- */
54
- void begin (int badurate = 115200 , int retry = 3 );
55
-
56
- /* *
57
- * @brief Ends the modem communication.
58
- */
59
- void end ();
60
-
61
-
62
- /* *
63
- * @brief Sends a formatted command string to a device and stores the response.
64
- *
65
- * This function formats a command string using the provided format and arguments,
66
- * sends it to a device, and waits for a response, which is stored in the `str` string.
67
- *
68
- * @param `cmd` A string representing the command to be sent to the device.
69
- * @param `str` A reference to a string that will hold the device's response.
70
- * @param `fmt` A format string for constructing the command.
71
- *
72
- * @return `true` if the command was successfully sent and a response was received,
73
- * `false` otherwise.
74
- */
75
- bool write (const std::string &cmd, std::string &str, const char * fmt, ...);
76
-
77
- /* *
78
- * @brief Used to send a command to the modem without waiting for a response.
79
- *
80
- * @param It takes a command string `cmd`, a string `str` where the response will be stored,
81
- * and a format string `fmt` along with additional arguments.
82
- */
83
- void write_nowait (const std::string &cmd, std::string &str, const char * fmt, ...);
84
-
85
- /* *
86
- * @brief Sends binary data directly to the modem without any processing or interpretation.
87
- *
88
- * @param It takes a pointer to the binary `data` and the `size` of the data as arguments.
89
- * Used for sending raw binary commands or data to the modem for operations that
90
- * require direct communication without any additional formatting or parsing.
91
- */
92
- bool passthrough (const uint8_t *data, size_t size);
93
-
94
- /* *
95
- * @brief Disables automatic trimming of results for one operation.
96
- *
97
- * This function disables the automatic trimming of results for one operation.
98
- * After it is called, the results will not be trimmed automatically until
99
- * the function is called again.
100
- */
101
- void avoid_trim_results () {
102
- /* one shot - it works only 1 time the it is necessary to call again this
28
+ /* *
29
+ * @brief Constructor for the ModemClass, which initializes the modem with the specified transmit (TX) and receive (RX) pins.
30
+ *
31
+ * @param Initializes an instance of the ModemClass class with
32
+ * specific transmit `tx` and receive `rx` pins for communication.
33
+ */
34
+ ModemClass (int tx, int rx);
35
+
36
+ /* *
37
+ * @brief Constructor for the ModemClass, which initializes the modem with the specified UART interface.
38
+ *
39
+ * @param `_serial` is a pointer to the UART object that will be used for communication with the modem.
40
+ */
41
+ ModemClass (UART * _serial);
42
+
43
+ /* *
44
+ * @brief Destructor for ModemClass.
45
+ */
46
+ ~ModemClass ();
47
+
48
+
49
+ /* *
50
+ * @brief Initializes the modem communication with a specified baud rate.
51
+ *
52
+ * @param[in] `badurate` sets the baud rate for the serial connection.
53
+ */
54
+ void begin (int badurate = 115200 , int retry = 3 );
55
+
56
+ /* *
57
+ * @brief Ends the modem communication.
58
+ */
59
+ void end ();
60
+
61
+
62
+ /* *
63
+ * @brief Sends a formatted command string to a device and stores the response.
64
+ *
65
+ * This function formats a command string using the provided format and arguments,
66
+ * sends it to a device, and waits for a response, which is stored in the `str` string.
67
+ *
68
+ * @param `cmd` A string representing the command to be sent to the device.
69
+ * @param `str` A reference to a string that will hold the device's response.
70
+ * @param `fmt` A format string for constructing the command.
71
+ *
72
+ * @return `true` if the command was successfully sent and a response was received,
73
+ * `false` otherwise.
74
+ */
75
+ bool write (const std::string &cmd, std::string &str, const char * fmt, ...);
76
+
77
+ /* *
78
+ * @brief Used to send a command to the modem without waiting for a response.
79
+ *
80
+ * @param It takes a command string `cmd`, a string `str` where the response will be stored,
81
+ * and a format string `fmt` along with additional arguments.
82
+ */
83
+ void write_nowait (const std::string &cmd, std::string &str, const char * fmt, ...);
84
+
85
+ /* *
86
+ * @brief Sends binary data directly to the modem without any processing or interpretation.
87
+ *
88
+ * @param It takes a pointer to the binary `data` and the `size` of the data as arguments.
89
+ * Used for sending raw binary commands or data to the modem for operations that
90
+ * require direct communication without any additional formatting or parsing.
91
+ */
92
+ bool passthrough (const uint8_t *data, size_t size);
93
+
94
+ /* *
95
+ * @brief Disables automatic trimming of results for one operation.
96
+ *
97
+ * This function disables the automatic trimming of results for one operation.
98
+ * After it is called, the results will not be trimmed automatically until
99
+ * the function is called again.
100
+ */
101
+ void avoid_trim_results () {
102
+ /* one shot - it works only 1 time the it is necessary to call again this
103
103
funtion */
104
104
trim_results = false ;
105
105
}
@@ -109,9 +109,9 @@ class ModemClass {
109
109
* to be read is considered for processing.
110
110
*/
111
111
void read_using_size () {
112
- // read_by_size = true; // deprecated
112
+ // read_by_size = true; // deprecated
113
113
}
114
-
114
+
115
115
bool beginned;
116
116
117
117
/* Calling this function with no argument will enable debug message to be printed
@@ -143,11 +143,32 @@ class ModemClass {
143
143
144
144
/* *
145
145
* @brief Sets the timeout value for communication operations.
146
- *
146
+ *
147
147
* @param Can be called with a specified timeout value in milliseconds.
148
148
*/
149
149
void timeout (size_t timeout_ms) {_timeout = timeout_ms;}
150
150
151
+ /* *
152
+ * @brief Gets the timeout value for communication operations.
153
+ *
154
+ * @return Can be called to get the specified timeout value in milliseconds.
155
+ */
156
+ unsigned long getTimeout () { return _timeout; }
157
+
158
+ /* *
159
+ * @brief Sets the timeout value for reading communication operations.
160
+ *
161
+ * @param Can be called with a specified read timeout value in milliseconds.
162
+ */
163
+ void readTimeout (size_t timeout_ms) {_readTimeout = timeout_ms;}
164
+
165
+ /* *
166
+ * @brief Gets the timeout value for reading communication operations.
167
+ *
168
+ * @return Can be called to get the specified read timeout value in milliseconds.
169
+ */
170
+ unsigned long getReadTimeout () { return _readTimeout; }
171
+
151
172
private:
152
173
enum ParseResult {
153
174
Ok,
@@ -160,6 +181,7 @@ class ModemClass {
160
181
bool delete_serial;
161
182
UART * _serial;
162
183
unsigned long _timeout;
184
+ unsigned long _readTimeout = MODEM_TIMEOUT;
163
185
uint8_t tx_buff[MAX_BUFF_SIZE];
164
186
bool trim_results;
165
187
Stream * _serial_debug;
0 commit comments