@@ -9,110 +9,91 @@ using namespace std;
99/* -------------------------------------------------------------------------- */
1010ModemClass::ModemClass (int tx, int rx) : beginned(false ), delete_serial(false ), _timeout(MODEM_TIMEOUT), trim_results(true ), read_by_size(false ) {
1111/* -------------------------------------------------------------------------- */
12- _serial = new UART (tx,rx);
12+ _serial = new UART (tx,rx);
1313}
1414
1515/* -------------------------------------------------------------------------- */
1616ModemClass::ModemClass (UART * serial) : beginned(false ) , delete_serial(true ) , _serial(serial), _timeout(MODEM_TIMEOUT), trim_results(true ), read_by_size(false ) {
17- /* -------------------------------------------------------------------------- */
17+ /* -------------------------------------------------------------------------- */
1818}
1919
2020/* -------------------------------------------------------------------------- */
2121ModemClass::~ModemClass () {
22- /* -------------------------------------------------------------------------- */
23- if (_serial != nullptr && !delete_serial){
22+ /* -------------------------------------------------------------------------- */
23+ if (_serial != nullptr && !delete_serial){
2424 delete _serial;
2525 _serial = nullptr ;
26- }
26+ }
2727}
2828
2929/* -------------------------------------------------------------------------- */
3030void ModemClass::begin (int badurate){
31- /* -------------------------------------------------------------------------- */
32- if (_serial != nullptr && !beginned) {
31+ /* -------------------------------------------------------------------------- */
32+ if (_serial != nullptr && !beginned) {
3333 _serial->begin (badurate);
3434 beginned = true ;
3535 string res = " " ;
3636 _serial->flush ();
3737 modem.write (string (PROMPT (_SOFTRESETWIFI)),res, " %s" , CMD (_SOFTRESETWIFI));
38- }
38+ }
3939}
4040
4141/* -------------------------------------------------------------------------- */
4242void ModemClass::end (){
43- /* -------------------------------------------------------------------------- */
44- _serial->end ();
43+ /* -------------------------------------------------------------------------- */
44+ _serial->end ();
4545}
4646
4747/* -------------------------------------------------------------------------- */
4848bool ModemClass::passthrough (const uint8_t *data, size_t size) {
49- /* -------------------------------------------------------------------------- */
49+ /* -------------------------------------------------------------------------- */
5050 _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+
8566 return res;
8667}
8768
8869/* -------------------------------------------------------------------------- */
8970void ModemClass::write_nowait (const string &cmd, string &str, const char * fmt, ...) {
90- /* -------------------------------------------------------------------------- */
71+ /* -------------------------------------------------------------------------- */
9172 va_list va;
9273 va_start (va, fmt);
9374 vsnprintf ((char *)tx_buff, MAX_BUFF_SIZE, fmt, va);
9475 va_end (va);
95-
96- if (_serial_debug && _debug_level >= 2 ) {
76+
77+ if (_serial_debug && _debug_level >= 2 ) {
9778 _serial_debug->print (" REQUEST (passthrough): " );
9879 _serial_debug->write (tx_buff,strlen ((char *)tx_buff));
9980 _serial_debug->println ();
10081 }
101-
82+
10283 _serial->write (tx_buff,strlen ((char *)tx_buff));
10384 return ;
10485}
10586
10687
10788/* -------------------------------------------------------------------------- */
10889bool ModemClass::write (const string &prompt, string &data_res, const char * fmt, ...){
109- /* -------------------------------------------------------------------------- */
90+ /* -------------------------------------------------------------------------- */
11091 data_res.clear ();
11192 va_list va;
11293 va_start (va, fmt);
11394 vsnprintf ((char *)tx_buff, MAX_BUFF_SIZE, fmt, va);
11495 va_end (va);
115-
96+
11697 if (_serial_debug) {
11798 _serial_debug->println ();
11899 _serial_debug->print (" REQUEST: " );
@@ -121,7 +102,7 @@ bool ModemClass::write(const string &prompt, string &data_res, const char * fmt,
121102 }
122103
123104 _serial->write (tx_buff,strlen ((char *)tx_buff));
124- return buf_read (prompt,data_res);;
105+ return buf_read (prompt, data_res);;
125106}
126107
127108
@@ -134,7 +115,7 @@ typedef enum {
134115
135116/* -------------------------------------------------------------------------- */
136117bool ModemClass::read_by_size_finished (string &rx) {
137- /* -------------------------------------------------------------------------- */
118+ /* -------------------------------------------------------------------------- */
138119 bool rv = false ;
139120 static bool first_call = true ;
140121 static ReadBySizeSt_t st = IDLE;
@@ -194,7 +175,7 @@ bool ModemClass::read_by_size_finished(string &rx) {
194175
195176/* -------------------------------------------------------------------------- */
196177bool ModemClass::buf_read (const string &prompt, string &data_res) {
197- /* -------------------------------------------------------------------------- */
178+ /* -------------------------------------------------------------------------- */
198179 bool res = false ;
199180 bool found = false ;
200181
@@ -262,6 +243,7 @@ bool ModemClass::buf_read(const string &prompt, string &data_res) {
262243 }
263244 }
264245 }
246+
265247 if (trim_results) {
266248 trim (data_res);
267249 }
@@ -273,23 +255,22 @@ bool ModemClass::buf_read(const string &prompt, string &data_res) {
273255 _serial_debug->println ();
274256 }
275257
276- if (_serial_debug) {
258+ if (_serial_debug) {
277259 _serial_debug->print (" ANSWER: " );
278260 _serial_debug->println (data_res.c_str ());
279261 if (res) {
280262 _serial_debug->println (" Result: OK" );
281263 }
282264 else {
283265 _serial_debug->println (" Result: FAILED" );
284- }
285- }
286-
266+ }
267+ }
287268
288269 return res;
289270}
290271
291272#ifdef ARDUINO_UNOWIFIR4
292- ModemClass modem = ModemClass(&Serial2);
273+ ModemClass modem = ModemClass(&Serial2);
293274#else
294- ModemClass modem = ModemClass(D24,D25);
275+ ModemClass modem = ModemClass(D24,D25);
295276#endif
0 commit comments