components/mhz19b/MHZ19B.cpp
/**
 * Run read task for this instance.
 */
Run read task for this instance.
Run read task for this instance .
void MHZ19B::read()
{
    ESP_LOGI(TAG, "read, this:%p", this);
    while (true) {
        ESP_LOGI(TAG, "read, uart_read_bytes");
        const int rx_bytes = uart_read_bytes(uart_port, rx_buffer, FRAME_LENGTH,  portMAX_DELAY);
        if (rx_bytes == -1) {
            ESP_LOGE(TAG, "read, error");
        } else if (rx_bytes == 0) {
            ESP_LOGI(TAG, "read, timeout");
        } else if (rx_bytes == FRAME_LENGTH) {
            decode_frame(rx_buffer);
        } else {
            ESP_LOGI(TAG, "read, %02x %02x %02x %02x %02x %02x %02x %02x %02x invalid frame length: %d", rx_buffer[0], rx_buffer[1],
                    rx_buffer[2], rx_buffer[3], rx_buffer[4], rx_buffer[5], rx_buffer[6], rx_buffer[7], rx_buffer[8], rx_bytes);
            esp_err_t status = uart_flush(uart_port);
            if (status != ESP_OK) {
                ESP_LOGE(TAG, "read, uart_flush (%s)", esp_err_to_name(status));
            }
        }
    };
}
void MHZ19B :: read ( ) { ESP_LOGI ( TAG , " " , this ) ; while ( true ) { ESP_LOGI ( TAG , " " ) ; const int rx_bytes = uart_read_bytes ( uart_port , rx_buffer , FRAME_LENGTH , portMAX_DELAY ) ; if ( rx_bytes == -1 ) { ESP_LOGE ( TAG , " " ) ; } else if ( rx_bytes == 0 ) { ESP_LOGI ( TAG , " " ) ; } else if ( rx_bytes == FRAME_LENGTH ) { decode_frame ( rx_buffer ) ; } else { ESP_LOGI ( TAG , " " , rx_buffer [ 0 ] , rx_buffer [ 1 ] , rx_buffer [ 2 ] , rx_buffer [ 3 ] , rx_buffer [ 4 ] , rx_buffer [ 5 ] , rx_buffer [ 6 ] , rx_buffer [ 7 ] , rx_buffer [ 8 ] , rx_bytes ) ; esp_err_t status = uart_flush ( uart_port ) ; if ( status != ESP_OK ) { ESP_LOGE ( TAG , " " , esp_err_to_name ( status ) ) ; } } } ; }
Run read task for this instance.
Run read task for this instance .
// remove left over of malformed frame