@@ -9,110 +9,91 @@ using namespace std;
9
9
/* -------------------------------------------------------------------------- */
10
10
ModemClass::ModemClass (int tx, int rx) : beginned(false ), delete_serial(false ), _timeout(MODEM_TIMEOUT), trim_results(true ), read_by_size(false ) {
11
11
/* -------------------------------------------------------------------------- */
12
- _serial = new UART (tx,rx);
12
+ _serial = new UART (tx,rx);
13
13
}
14
14
15
15
/* -------------------------------------------------------------------------- */
16
16
ModemClass::ModemClass (UART * serial) : beginned(false ) , delete_serial(true ) , _serial(serial), _timeout(MODEM_TIMEOUT), trim_results(true ), read_by_size(false ) {
17
- /* -------------------------------------------------------------------------- */
17
+ /* -------------------------------------------------------------------------- */
18
18
}
19
19
20
20
/* -------------------------------------------------------------------------- */
21
21
ModemClass::~ModemClass () {
22
- /* -------------------------------------------------------------------------- */
23
- if (_serial != nullptr && !delete_serial){
22
+ /* -------------------------------------------------------------------------- */
23
+ if (_serial != nullptr && !delete_serial){
24
24
delete _serial;
25
25
_serial = nullptr ;
26
- }
26
+ }
27
27
}
28
28
29
29
/* -------------------------------------------------------------------------- */
30
30
void ModemClass::begin (int badurate){
31
- /* -------------------------------------------------------------------------- */
32
- if (_serial != nullptr && !beginned) {
31
+ /* -------------------------------------------------------------------------- */
32
+ if (_serial != nullptr && !beginned) {
33
33
_serial->begin (badurate);
34
34
beginned = true ;
35
35
string res = " " ;
36
36
_serial->flush ();
37
37
modem.write (string (PROMPT (_SOFTRESETWIFI)),res, " %s" , CMD (_SOFTRESETWIFI));
38
- }
38
+ }
39
39
}
40
40
41
41
/* -------------------------------------------------------------------------- */
42
42
void ModemClass::end (){
43
- /* -------------------------------------------------------------------------- */
44
- _serial->end ();
43
+ /* -------------------------------------------------------------------------- */
44
+ _serial->end ();
45
45
}
46
46
47
47
/* -------------------------------------------------------------------------- */
48
48
bool ModemClass::passthrough (const uint8_t *data, size_t size) {
49
- /* -------------------------------------------------------------------------- */
49
+ /* -------------------------------------------------------------------------- */
50
50
_serial->write (data,size);
51
- bool res = false ;
52
- bool found = false ;
53
- string data_res = " " ;
54
-
55
- unsigned long start_time = millis ();
56
- while (millis () - start_time < _timeout && !found){
57
- while (_serial->available ()){
58
- char c = _serial->read ();
59
- data_res += c;
60
-
61
- if (string::npos != data_res.rfind (RESULT_OK)){
62
- found = true ;
63
- res = true ;
64
- break ;
65
- }
66
- else if (string::npos != data_res.rfind (RESULT_ERROR)) {
67
- found = true ;
68
- res = false ;
69
- break ;
70
- }
71
- }
72
- }
73
-
74
- if (_serial_debug && _debug_level >= 2 ) {
75
- _serial_debug->print (" ANSWER (passthrough): " );
76
- _serial_debug->println (data_res.c_str ());
77
- if (res) {
78
- _serial_debug->println (" Result: OK" );
79
- }
80
- else {
81
- _serial_debug->println (" Result: FAILED" );
82
- }
83
- }
84
-
51
+
52
+ std::string tmp, data_res; // FIXME
53
+ bool res = buf_read (tmp, data_res);
54
+
55
+ // if(_serial_debug && _debug_level >= 2) {
56
+ // _serial_debug->print(" ANSWER (passthrough): ");
57
+ // _serial_debug->println(data_res.c_str());
58
+ // if(res) {
59
+ // _serial_debug->println(" Result: OK");
60
+ // }
61
+ // else {
62
+ // _serial_debug->println(" Result: FAILED");
63
+ // }
64
+ // }
65
+
85
66
return res;
86
67
}
87
68
88
69
/* -------------------------------------------------------------------------- */
89
70
void ModemClass::write_nowait (const string &cmd, string &str, const char * fmt, ...) {
90
- /* -------------------------------------------------------------------------- */
71
+ /* -------------------------------------------------------------------------- */
91
72
va_list va;
92
73
va_start (va, fmt);
93
74
vsnprintf ((char *)tx_buff, MAX_BUFF_SIZE, fmt, va);
94
75
va_end (va);
95
-
96
- if (_serial_debug && _debug_level >= 2 ) {
76
+
77
+ if (_serial_debug && _debug_level >= 2 ) {
97
78
_serial_debug->print (" REQUEST (passthrough): " );
98
79
_serial_debug->write (tx_buff,strlen ((char *)tx_buff));
99
80
_serial_debug->println ();
100
81
}
101
-
82
+
102
83
_serial->write (tx_buff,strlen ((char *)tx_buff));
103
84
return ;
104
85
}
105
86
106
87
107
88
/* -------------------------------------------------------------------------- */
108
89
bool ModemClass::write (const string &prompt, string &data_res, const char * fmt, ...){
109
- /* -------------------------------------------------------------------------- */
90
+ /* -------------------------------------------------------------------------- */
110
91
data_res.clear ();
111
92
va_list va;
112
93
va_start (va, fmt);
113
94
vsnprintf ((char *)tx_buff, MAX_BUFF_SIZE, fmt, va);
114
95
va_end (va);
115
-
96
+
116
97
if (_serial_debug) {
117
98
_serial_debug->println ();
118
99
_serial_debug->print (" REQUEST: " );
@@ -121,7 +102,7 @@ bool ModemClass::write(const string &prompt, string &data_res, const char * fmt,
121
102
}
122
103
123
104
_serial->write (tx_buff,strlen ((char *)tx_buff));
124
- return buf_read (prompt,data_res);;
105
+ return buf_read (prompt, data_res);;
125
106
}
126
107
127
108
@@ -134,7 +115,7 @@ typedef enum {
134
115
135
116
/* -------------------------------------------------------------------------- */
136
117
bool ModemClass::read_by_size_finished (string &rx) {
137
- /* -------------------------------------------------------------------------- */
118
+ /* -------------------------------------------------------------------------- */
138
119
bool rv = false ;
139
120
static bool first_call = true ;
140
121
static ReadBySizeSt_t st = IDLE;
@@ -194,7 +175,7 @@ bool ModemClass::read_by_size_finished(string &rx) {
194
175
195
176
/* -------------------------------------------------------------------------- */
196
177
bool ModemClass::buf_read (const string &prompt, string &data_res) {
197
- /* -------------------------------------------------------------------------- */
178
+ /* -------------------------------------------------------------------------- */
198
179
bool res = false ;
199
180
bool found = false ;
200
181
@@ -270,6 +251,7 @@ bool ModemClass::buf_read(const string &prompt, string &data_res) {
270
251
}
271
252
}
272
253
}
254
+
273
255
if (trim_results) {
274
256
trim (data_res);
275
257
}
@@ -281,23 +263,22 @@ bool ModemClass::buf_read(const string &prompt, string &data_res) {
281
263
_serial_debug->println ();
282
264
}
283
265
284
- if (_serial_debug) {
266
+ if (_serial_debug) {
285
267
_serial_debug->print (" ANSWER: " );
286
268
_serial_debug->println (data_res.c_str ());
287
269
if (res) {
288
270
_serial_debug->println (" Result: OK" );
289
271
}
290
272
else {
291
273
_serial_debug->println (" Result: FAILED" );
292
- }
293
- }
294
-
274
+ }
275
+ }
295
276
296
277
return res;
297
278
}
298
279
299
280
#ifdef ARDUINO_UNOWIFIR4
300
- ModemClass modem = ModemClass(&Serial2);
281
+ ModemClass modem = ModemClass(&Serial2);
301
282
#else
302
- ModemClass modem = ModemClass(D24,D25);
283
+ ModemClass modem = ModemClass(D24,D25);
303
284
#endif
0 commit comments