@@ -69,18 +69,19 @@ bool ModemClass::passthrough(const uint8_t *data, size_t size) {
69
69
break ;
70
70
}
71
71
}
72
- }
73
- # ifdef MODEM_DEBUG_PASSTHROUGH
74
- Serial. print ( " passthrough, rx |>> " );
75
- Serial. print (data_res. c_str () );
76
- Serial. println (" <<| " );
72
+ }
73
+
74
+ if (_serial_debug && _debug_level >= 2 ) {
75
+ _serial_debug-> print (" ANSWER (passthrough): " );
76
+ _serial_debug-> println (data_res. c_str () );
77
77
if (res) {
78
- Serial. println (" Result: OK" );
78
+ _serial_debug-> println (" Result: OK" );
79
79
}
80
80
else {
81
- Serial.println (" Result: FAILED" );
82
- }
83
- #endif
81
+ _serial_debug->println (" Result: FAILED" );
82
+ }
83
+ }
84
+
84
85
return res;
85
86
}
86
87
@@ -92,11 +93,13 @@ void ModemClass::write_nowait(const string &cmd, string &str, char * fmt, ...) {
92
93
va_start (va, fmt);
93
94
vsprintf ((char *)tx_buff, fmt, va);
94
95
va_end (va);
95
- #ifdef MODEM_DEBUG
96
- Serial.print (" Write Call no wait, command sent: " );
97
- Serial.write (tx_buff,strlen ((char *)tx_buff));
98
- Serial.println ();
99
- #endif
96
+
97
+ if (_serial_debug && _debug_level >= 2 ) {
98
+ _serial_debug->print (" REQUEST (passthrough): " );
99
+ _serial_debug->write (tx_buff,strlen ((char *)tx_buff));
100
+ _serial_debug->println ();
101
+ }
102
+
100
103
_serial->write (tx_buff,strlen ((char *)tx_buff));
101
104
return ;
102
105
}
@@ -105,25 +108,22 @@ void ModemClass::write_nowait(const string &cmd, string &str, char * fmt, ...) {
105
108
/* -------------------------------------------------------------------------- */
106
109
bool ModemClass::write (const string &prompt, string &data_res, char * fmt, ...){
107
110
/* -------------------------------------------------------------------------- */
108
- data_res.clear ();
109
- memset (tx_buff,0x00 ,MAX_BUFF_SIZE);
110
- va_list va;
111
- va_start (va, fmt);
112
- vsprintf ((char *)tx_buff, fmt, va);
113
- va_end (va);
114
- #ifdef MODEM_DEBUG
115
- Serial.println ();
116
- Serial.println (" ###>" );
117
- Serial.print (" READ BY SIZE: " );
118
- Serial.println ((int )read_by_size);
119
- Serial.print (" Write Call, command sent: " );
120
- Serial.write (tx_buff,strlen ((char *)tx_buff));
121
- Serial.println ();
111
+ data_res.clear ();
112
+ memset (tx_buff,0x00 ,MAX_BUFF_SIZE);
113
+ va_list va;
114
+ va_start (va, fmt);
115
+ vsprintf ((char *)tx_buff, fmt, va);
116
+ va_end (va);
117
+
118
+ if (_serial_debug) {
119
+ _serial_debug->println ();
120
+ _serial_debug->print (" REQUEST: " );
121
+ _serial_debug->write (tx_buff,strlen ((char *)tx_buff));
122
+ _serial_debug->println ();
123
+ }
122
124
123
- Serial.println (" <###" );
124
- #endif
125
- _serial->write (tx_buff,strlen ((char *)tx_buff));
126
- return buf_read (prompt,data_res);;
125
+ _serial->write (tx_buff,strlen ((char *)tx_buff));
126
+ return buf_read (prompt,data_res);;
127
127
}
128
128
129
129
@@ -200,16 +200,20 @@ bool ModemClass::buf_read(const string &prompt, string &data_res) {
200
200
bool res = false ;
201
201
bool found = false ;
202
202
203
+ if (_serial_debug && _debug_level >= 1 ) {
204
+ _serial_debug->print (" RAW: " );
205
+ }
206
+
203
207
unsigned long start_time = millis ();
204
208
while ((millis () - start_time < _timeout) && !found){
205
209
while ( _serial->available () ){
206
210
char c = _serial->read ();
207
211
data_res += c;
208
- # ifdef SELECTABLE_MODEM_DEBUG
209
- if (enable_dbg ) {
210
- Serial. print (c);
212
+
213
+ if (_serial_debug && _debug_level >= 1 ) {
214
+ _serial_debug-> print (c);
211
215
}
212
- # endif
216
+
213
217
214
218
if (read_by_size) {
215
219
if (read_by_size_finished (data_res)) {
@@ -264,18 +268,24 @@ bool ModemClass::buf_read(const string &prompt, string &data_res) {
264
268
}
265
269
trim_results = true ;
266
270
read_by_size = false ;
267
- #ifdef MODEM_DEBUG
268
- Serial.print (" Write Call, response rx |>>" );
269
- Serial.print (data_res.c_str ());
270
- Serial.println (" <<|" );
271
+
272
+ if (_serial_debug && _debug_level >= 1 ) {
273
+ _serial_debug->print (" <-RAW END" );
274
+ _serial_debug->println ();
275
+ }
276
+
277
+ if (_serial_debug) {
278
+ _serial_debug->print (" ANSWER: " );
279
+ _serial_debug->println (data_res.c_str ());
271
280
if (res) {
272
- Serial. println (" Result: OK" );
281
+ _serial_debug-> println (" Result: OK" );
273
282
}
274
283
else {
275
- Serial.println (" Result: FAILED" );
276
- }
277
- #endif
278
-
284
+ _serial_debug->println (" Result: FAILED" );
285
+ }
286
+ }
287
+
288
+
279
289
return res;
280
290
}
281
291
0 commit comments