@@ -30,20 +30,18 @@ void ModemClass::end(){
30
30
}
31
31
32
32
bool ModemClass::write (const string &prompt, string &data_res, char * fmt, ...){
33
+
34
+ data_res.clear ();
35
+
33
36
memset (tx_buff,0x00 ,MAX_BUFF_SIZE);
34
37
va_list va;
35
38
va_start (va, fmt);
36
39
vsprintf ((char *)tx_buff, fmt, va);
37
40
va_end (va);
38
41
#ifdef MODEM_DEBUG
39
- Serial.print (" tx_buff: " );
40
- for (int i =0 ; i<MAX_BUFF_SIZE; i++) {
41
- Serial.print (tx_buff[i], HEX);
42
- Serial.print (" " );
43
- }
44
- Serial.println ();
42
+ Serial.print (" Write Call, command sent: " );
45
43
Serial.write (tx_buff,strlen ((char *)tx_buff));
46
- Serial.println (" ciao " );
44
+ Serial.println ();
47
45
#endif
48
46
_serial->write (tx_buff,strlen ((char *)tx_buff));
49
47
return buf_read (prompt,data_res);;
@@ -52,20 +50,24 @@ bool ModemClass::write(const string &prompt, string &data_res, char * fmt, ...){
52
50
53
51
bool ModemClass::buf_read (const string &prompt, string &data_res) {
54
52
bool res = false ;
53
+ bool found = false ;
55
54
unsigned long start_time = millis ();
56
- while (millis () - start_time < _timeout){
55
+ while (millis () - start_time < _timeout && !found ){
57
56
while (_serial->available ()){
58
57
char c = _serial->read ();
59
58
data_res += c;
60
- Serial.print (c);
59
+ // Serial.print(c);
61
60
if (string::npos != data_res.rfind (PROMPT_OK)){
62
- data_res.substr (0 , data_res.length () - sizeof (PROMPT_OK));
61
+ found = true ;
62
+ data_res = data_res.substr (0 , data_res.length () - sizeof (PROMPT_OK));
63
63
if (prompt != DO_NOT_CHECK_CMD) {
64
64
if (removeAtBegin (data_res, prompt)) {
65
65
res = true ;
66
66
}
67
67
}
68
- res = true ;
68
+ else {
69
+ res = true ;
70
+ }
69
71
break ;
70
72
}
71
73
else if (string::npos != data_res.rfind (PROMPT_ERROR)) {
@@ -75,10 +77,19 @@ bool ModemClass::buf_read(const string &prompt, string &data_res) {
75
77
}
76
78
}
77
79
}
80
+ trim (data_res);
78
81
#ifdef MODEM_DEBUG
79
- Serial.print (" data_res: " );
80
- Serial.println (data_res.c_str ());
82
+ Serial.print (" Write Call, response rx |>>" );
83
+ Serial.print (data_res.c_str ());
84
+ Serial.println (" <<|" );
85
+ if (res) {
86
+ Serial.println (" Result: OK" );
87
+ }
88
+ else {
89
+ Serial.println (" Result: FAILED" );
90
+ }
81
91
#endif
92
+
82
93
return res;
83
94
}
84
95
0 commit comments