📟 pmme-device: backporting - Match uart_data reading from Rust
This commit is contained in:
parent
a638e0293c
commit
614aef96c5
@ -78,7 +78,7 @@ void send_pms7003_command(uint8_t cmd, uint8_t datah, uint8_t datal) {
|
||||
|
||||
void read_pm_data(uint8_t *buf) {
|
||||
uint16_t checksum = 0;
|
||||
for (int i = 0; i <= 29; i++) {
|
||||
for (int i = 0; i <= 28; i++) {
|
||||
checksum += buf[i];
|
||||
}
|
||||
uint16_t c = (((uint16_t)buf[30]) << 8) | ((uint16_t)buf[31]);
|
||||
@ -130,13 +130,12 @@ void pm_sensor_task(void *pvParameters) {
|
||||
int len = uart_read_bytes(UART_NUM, uart_data, BUF_SIZE, 100 / portTICK_PERIOD_MS);
|
||||
// ESP_LOGI(TAG, "Received %d bytes from sensor", len);
|
||||
if (len > 0) {
|
||||
if (len == 32 && (uart_data[0] != 0x42 || uart_data[1] != 0x4D)) {
|
||||
if (uart_data[0] != 0x42 || uart_data[1] != 0x4D) {
|
||||
ESP_LOGW(TAG, "Frame Start does not match 0x42, 0x4D, instead got %x %x", uart_data[0], uart_data[1]);
|
||||
} else {
|
||||
} else if (len == 32) {
|
||||
read_pm_data(uart_data);
|
||||
// for(int i = 0; i < len && i < BUF_SIZE; i++) {
|
||||
// ESP_LOGI(TAG, "0x%02X", uart_data[i]);
|
||||
// }
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Unexpected frame length: %d", len);
|
||||
}
|
||||
}
|
||||
uart_flush(UART_NUM);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user