Skip to content

Commit 2bc141c

Browse files
Unifying codestyle
1 parent 644aba4 commit 2bc141c

File tree

3 files changed

+109
-129
lines changed

3 files changed

+109
-129
lines changed

Diff for: libraries/WiFiS3/src/Modem.cpp

+41-60
Original file line numberDiff line numberDiff line change
@@ -9,110 +9,91 @@ using namespace std;
99
/* -------------------------------------------------------------------------- */
1010
ModemClass::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
/* -------------------------------------------------------------------------- */
1616
ModemClass::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
/* -------------------------------------------------------------------------- */
2121
ModemClass::~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
/* -------------------------------------------------------------------------- */
3030
void 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
/* -------------------------------------------------------------------------- */
4242
void ModemClass::end(){
43-
/* -------------------------------------------------------------------------- */
44-
_serial->end();
43+
/* -------------------------------------------------------------------------- */
44+
_serial->end();
4545
}
4646

4747
/* -------------------------------------------------------------------------- */
4848
bool 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
/* -------------------------------------------------------------------------- */
8970
void 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
/* -------------------------------------------------------------------------- */
10889
bool 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
/* -------------------------------------------------------------------------- */
136117
bool 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
/* -------------------------------------------------------------------------- */
196177
bool ModemClass::buf_read(const string &prompt, string &data_res) {
197-
/* -------------------------------------------------------------------------- */
178+
/* -------------------------------------------------------------------------- */
198179
bool res = false;
199180
bool found = false;
200181

@@ -270,6 +251,7 @@ bool ModemClass::buf_read(const string &prompt, string &data_res) {
270251
}
271252
}
272253
}
254+
273255
if(trim_results) {
274256
trim(data_res);
275257
}
@@ -281,23 +263,22 @@ bool ModemClass::buf_read(const string &prompt, string &data_res) {
281263
_serial_debug->println();
282264
}
283265

284-
if(_serial_debug) {
266+
if(_serial_debug) {
285267
_serial_debug->print(" ANSWER: ");
286268
_serial_debug->println(data_res.c_str());
287269
if(res) {
288270
_serial_debug->println(" Result: OK");
289271
}
290272
else {
291273
_serial_debug->println(" Result: FAILED");
292-
}
293-
}
294-
274+
}
275+
}
295276

296277
return res;
297278
}
298279

299280
#ifdef ARDUINO_UNOWIFIR4
300-
ModemClass modem = ModemClass(&Serial2);
281+
ModemClass modem = ModemClass(&Serial2);
301282
#else
302-
ModemClass modem = ModemClass(D24,D25);
283+
ModemClass modem = ModemClass(D24,D25);
303284
#endif

Diff for: libraries/WiFiS3/src/Modem.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ class ModemClass {
3636

3737
void read_using_size() {
3838
read_by_size = true;
39-
}
39+
}
4040
bool beginned;
4141

4242
/* calling this function with no argument will enable debug message to be printed
4343
on Serial
44-
use first parameter UART *u to redirect debug output to a different serial
44+
use first parameter UART *u to redirect debug output to a different serial
4545
4646
level from 0 defaul to 2 (maximum) */
4747

4848
void debug(Stream &u, uint8_t level = 0) {
4949
_serial_debug = &u;
50-
50+
5151
if(level > 2) {
5252
level = 2;
5353
}

0 commit comments

Comments
 (0)