diff --git a/MicroPython_BUILD/components/micropython/esp32/machine_uart.c b/MicroPython_BUILD/components/micropython/esp32/machine_uart.c index 614fa72..533b132 100644 --- a/MicroPython_BUILD/components/micropython/esp32/machine_uart.c +++ b/MicroPython_BUILD/components/micropython/esp32/machine_uart.c @@ -103,7 +103,7 @@ static int uart_buf_get(uart_ringbuf_t *r, uint8_t *dest, uint16_t len) { if (r->iget == r->iput) break; } // move the buffer and adjust the pointers - memmove(r->buf, r->buf+res, res); + memmove(r->buf, r->buf+res, r->iput - res); r->iget -= res; r->iput -= res; @@ -120,15 +120,16 @@ static int uart_buf_put(uart_ringbuf_t *r, uint8_t *source, uint16_t len) { return res; } -//--------------------------------------------------------------------------------------- -int pattern_match(uint8_t *text, int text_length, uint8_t *pattern, int pattern_length) { +//--------------------------------------------------------------------------------------------- +static int match_pattern(uint8_t *text, int text_length, uint8_t *pattern, int pattern_length) +{ int c, d, e, position = -1; if (pattern_length > text_length) return -1; for (c = 0; c <= (text_length - pattern_length); c++) { position = e = c; - + // check pattern for (d = 0; d < pattern_length; d++) { if (pattern[d] == text[e]) e++; else break; @@ -197,7 +198,7 @@ static void uart_event_task(void *pvParameters) } else if (self->pattern_cb) { // ** callback on pattern received - res = pattern_match(uart_buf[self->uart_num]->buf, uart_buf[self->uart_num]->iput, self->pattern, self->pattern_len); + res = match_pattern(uart_buf[self->uart_num]->buf, uart_buf[self->uart_num]->iput, self->pattern, self->pattern_len); if (res >= 0) { // found, pull data, including pattern from buffer uart_buf_get(uart_buf[self->uart_num], dtmp, res+self->pattern_len); @@ -594,9 +595,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_flush_obj, machine_uart_flush); STATIC mp_obj_t machine_uart_readln(size_t n_args, const mp_obj_t *args) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(args[0]); - vstr_t vstr; - int res = -1; + uint8_t *rdstr = NULL; + int rdlen = -1; int lnendlen = strlen((char *)self->lineend); + if (lnendlen == 0) return mp_const_none; + int timeout = self->timeout; if (n_args == 2) timeout = mp_obj_get_int(args[1]); @@ -607,14 +610,18 @@ STATIC mp_obj_t machine_uart_readln(size_t n_args, const mp_obj_t *args) { if (uart_mutex) xSemaphoreGive(uart_mutex); return mp_const_none; } - res = pattern_match(uart_buf[self->uart_num]->buf, uart_buf[self->uart_num]->iput, self->lineend, lnendlen); - if (res >= 0) { + rdlen = match_pattern(uart_buf[self->uart_num]->buf, uart_buf[self->uart_num]->iput, self->lineend, lnendlen); + if (rdlen >= 0) { // found, pull data, including pattern from buffer - vstr_init_len(&vstr, res+lnendlen); - uart_buf_get(uart_buf[self->uart_num], (uint8_t *)vstr.buf, res+lnendlen); + rdlen += lnendlen; + rdstr = calloc(rdlen+1, 1); + if (rdstr) { + uart_buf_get(uart_buf[self->uart_num], rdstr, rdlen); + rdstr[rdlen] = 0; + } } if (uart_mutex) xSemaphoreGive(uart_mutex); - if (res < 0) return mp_const_none; + if (rdlen < 0) return mp_const_none; } else { // wait until line end received or timeout @@ -635,11 +642,15 @@ STATIC mp_obj_t machine_uart_readln(size_t n_args, const mp_obj_t *args) { mp_hal_reset_wdt(); continue; } - res = pattern_match(uart_buf[self->uart_num]->buf, uart_buf[self->uart_num]->iput, self->lineend, lnendlen); - if (res >= 0) { + rdlen = match_pattern(uart_buf[self->uart_num]->buf, uart_buf[self->uart_num]->iput, self->lineend, lnendlen); + if (rdlen >= 0) { + rdlen += lnendlen; // found, pull data, including pattern from buffer - vstr_init_len(&vstr, res+lnendlen); - uart_buf_get(uart_buf[self->uart_num], (uint8_t *)vstr.buf, res+lnendlen); + rdstr = calloc(rdlen+1, 1); + if (rdstr) { + uart_buf_get(uart_buf[self->uart_num], rdstr, rdlen); + rdstr[rdlen] = 0; + } if (uart_mutex) xSemaphoreGive(uart_mutex); break; } @@ -649,10 +660,12 @@ STATIC mp_obj_t machine_uart_readln(size_t n_args, const mp_obj_t *args) { mp_hal_reset_wdt(); } MP_THREAD_GIL_ENTER(); - if (res < 0) return mp_const_none; + if (rdlen < 0) return mp_const_none; } - - return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); + if (rdstr == NULL) return mp_const_none; + mp_obj_t res_str = mp_obj_new_str((const char *)rdstr, rdlen, false); + free(rdstr); + return res_str; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_uart_readln_obj, 1, 2, machine_uart_readln); @@ -753,6 +766,9 @@ STATIC const mp_rom_map_elem_t machine_uart_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_uart_locals_dict, machine_uart_locals_dict_table); + +// === Stream UART functions === + //------------------------------------------------------------------------------------------------ STATIC mp_uint_t machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/MicroPython_BUILD/components/micropython/esp32/mpversion.h b/MicroPython_BUILD/components/micropython/esp32/mpversion.h index bae95cf..2b5f3bd 100644 --- a/MicroPython_BUILD/components/micropython/esp32/mpversion.h +++ b/MicroPython_BUILD/components/micropython/esp32/mpversion.h @@ -24,10 +24,10 @@ * THE SOFTWARE. */ -#define MICROPY_GIT_TAG "ESP32_LoBo_v3.1.24" +#define MICROPY_GIT_TAG "ESP32_LoBo_v3.1.25" #define MICROPY_GIT_HASH "g77eae33a" -#define MICROPY_BUILD_DATE "2017-03-16" +#define MICROPY_BUILD_DATE "2017-03-17" #define MICROPY_VERSION_MAJOR (3) #define MICROPY_VERSION_MINOR (1) -#define MICROPY_VERSION_MICRO (24) -#define MICROPY_VERSION_STRING "3.1.24" +#define MICROPY_VERSION_MICRO (25) +#define MICROPY_VERSION_STRING "3.1.25" diff --git a/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32.zip b/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32.zip index 06eac6a..a178f08 100644 Binary files a/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32.zip and b/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32.zip differ diff --git a/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_all.zip b/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_all.zip index 0416ac9..e409b43 100644 Binary files a/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_all.zip and b/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_all.zip differ diff --git a/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_ota.zip b/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_ota.zip index ce14385..9862bda 100644 Binary files a/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_ota.zip and b/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_ota.zip differ diff --git a/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_psram.zip b/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_psram.zip index 7a05231..b1cba8d 100644 Binary files a/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_psram.zip and b/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_psram.zip differ diff --git a/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_psram_all.zip b/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_psram_all.zip index 757beb0..56b5514 100644 Binary files a/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_psram_all.zip and b/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_psram_all.zip differ diff --git a/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_psram_ota.zip b/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_psram_ota.zip index 3283ed0..153b899 100644 Binary files a/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_psram_ota.zip and b/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_psram_ota.zip differ diff --git a/MicroPython_BUILD/firmware/esp32/MicroPython.bin b/MicroPython_BUILD/firmware/esp32/MicroPython.bin index 03b4c72..7d5a476 100644 Binary files a/MicroPython_BUILD/firmware/esp32/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32/bootloader/bootloader.bin index a7ed807..a3bf18e 100644 Binary files a/MicroPython_BUILD/firmware/esp32/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32/bootloader/bootloader.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_all/MicroPython.bin b/MicroPython_BUILD/firmware/esp32_all/MicroPython.bin index 90d334a..615adfc 100644 Binary files a/MicroPython_BUILD/firmware/esp32_all/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32_all/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_all/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32_all/bootloader/bootloader.bin index 848326c..624cd1d 100644 Binary files a/MicroPython_BUILD/firmware/esp32_all/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32_all/bootloader/bootloader.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_ota/MicroPython.bin b/MicroPython_BUILD/firmware/esp32_ota/MicroPython.bin index 8d0ac30..ac071d6 100644 Binary files a/MicroPython_BUILD/firmware/esp32_ota/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32_ota/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_ota/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32_ota/bootloader/bootloader.bin index 4ba8fda..fb1f756 100644 Binary files a/MicroPython_BUILD/firmware/esp32_ota/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32_ota/bootloader/bootloader.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin b/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin index 8846df3..408a9d1 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32_psram/bootloader/bootloader.bin index 53fb598..aad760f 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32_psram/bootloader/bootloader.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram_all/MicroPython.bin b/MicroPython_BUILD/firmware/esp32_psram_all/MicroPython.bin index b068b3c..a6408df 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram_all/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32_psram_all/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram_all/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32_psram_all/bootloader/bootloader.bin index 244dddc..f13e602 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram_all/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32_psram_all/bootloader/bootloader.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram_ota/MicroPython.bin b/MicroPython_BUILD/firmware/esp32_psram_ota/MicroPython.bin index c72fad4..5f756ae 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram_ota/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32_psram_ota/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram_ota/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32_psram_ota/bootloader/bootloader.bin index 96bcf28..af46a32 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram_ota/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32_psram_ota/bootloader/bootloader.bin differ