A fork of the original interface for OS/2. Features a correctly-implemented recv (but retains the old behavior via recv2).
Dependents: weather_clock weather_clock
Diff: ESP8266/ESP8266.cpp
- Revision:
- 50:f484783b8a34
- Parent:
- 49:cac09a34102c
- Child:
- 51:c8c727b413d9
diff -r cac09a34102c -r f484783b8a34 ESP8266/ESP8266.cpp --- a/ESP8266/ESP8266.cpp Sun Mar 31 00:53:46 2019 +0000 +++ b/ESP8266/ESP8266.cpp Sun Mar 31 03:08:45 2019 +0000 @@ -38,19 +38,16 @@ #define INFO(x, ...) #endif -int tmp_buf_ind = 0; -char tmp_buf[8192]; -RawSerial dev1(p28,p27); ESP8266 *ESP8266::_inst; ESP8266::ESP8266(PinName tx, PinName rx, PinName reset, int baud, int timeout) : _serial(tx, rx), _reset_pin(reset) { INFO("Initializing ESP8266 object"); - _baud = baud; - _timeout = timeout; + //_baud = baud; + //_timeout = timeout; - _serial.baud(_baud); + //_serial.baud(_baud); _inst = this; } @@ -216,7 +213,7 @@ return true; } -int ESP8266::recv2(char* buffer, int len, int offset=0) { +int ESP8266::recv(char* buffer, int len, int offset=0) { // start at offset, read at most LEN bytes // first make sure we have that many bytes to read! @@ -271,84 +268,11 @@ char len_buf[16]; sprintf(len_buf, "%d", *len); - //if (!(command("cr(") && - // command(len_buf) && - // command(")"))) - // return false; - //if (!(command("\r\n") && discardEcho())) - // return false; - //if (!(command("print(cm)"))) - // return false; - char buf[4096]; - int buf_len = 4095; - int ind = 0; - while (true) { - dev1.printf("\r\nIterating\r\n"); - int res = recv2(buf + ind, buf_len, ind); - dev1.printf("Result: %d\n", res); - if (res < 0) { - break; - } else { - ind += res; - } + if (!(command("cr(") && + command(len_buf) && + command(")"))) + return false; - } - dev1.printf("\r\n** WHAT WE HAVE **\r\n"); - dev1.printf(buf); - dev1.printf("\r\n** DONE ** \r\n"); - dev1.getc(); - - int len2 = 127; - int n = 0; - char* CMD = "print(cm:sub(%d, %d))\r\n"; - char cmd[1024]; - char cmd_buf_f[8192]; - int cmd_buf_i = 0; - while (true) { - tmp_buf_ind = 0; - //command("print(#cm)\r\n"); - //sprintf(cmd, "print(#cm)\r\n"); - //command(cmd); - //command(cmd); - sprintf(cmd, CMD, n + 1, n + 1024); - command(cmd); - // cleanup the command - for (int l = 0; l <= strlen(cmd); l++) { - serialgetc(); - } - /* - // While we have numbers, get - char num_buf[16]; - int ind2 = 0; - while (char tmp = serialgetc()) { - if (tmp < '0' || tmp > '9') { - break; - } - num_buf[ind2++] = tmp; - } - num_buf[ind2] = '\0'; - dev1.printf("NUM: %s = %d\r\n", num_buf, atoi(num_buf)); - */ - for (int l = 0; l < 3; l++) { - cmd_buf_f[cmd_buf_i++] = serialgetc(); - } - cmd_buf_f[cmd_buf_i] = '\0'; - n += 1024; -// tmp_buf[tmp_buf_ind % 8192] = '\0'; - // dev1.printf("Raw output\r\n%s\r\n", tmp_buf); - //dev1.printf("Length: %d\n", len2); -// for (int k = 0; k < 4000; k++) { -// dev1.putc(buf[k]); -// } - dev1.printf("** WHAT WE HAVE SO FAR **\r\n"); - dev1.printf(cmd_buf_f); - dev1.printf("\r\n** END WHAT WE HAVE **\r\n"); - dev1.printf("Waiting...\r\n"); - dev1.getc(); - dev1.printf("Continuing...\r\n"); - } - printf("\r\n**EXECUTION**\r\n%s", buf); - while(true); if (!(command("\r\n") && discardEcho())) return false; @@ -372,6 +296,7 @@ buffer[i] = (a-'0')*100 + (b-'0')*10 + (c-'0'); } + // Flush to next prompt return flush(); } @@ -388,7 +313,7 @@ while (true) { int len = 1; - if (!recv(buffer, &len)) + if (!recv2(buffer, &len)) return -1; if (len > 0)