#pragma once

#include <Arduino.h>
#include "data_model.h"

struct MeterDriverStats {
  uint32_t frames_ok;
  uint32_t frames_parse_fail;
  uint32_t rx_overflow;
  uint32_t rx_timeout;
  uint32_t bytes_rx;
  uint32_t last_rx_ms;
  uint32_t last_good_frame_ms;
  uint32_t uart_buffer_full;
  uint32_t uart_fifo_overflow;
  uint32_t uart_frame_error;
  uint32_t uart_parity_error;
};

void meter_init();
bool meter_read(MeterData &data);
bool meter_poll_frame(const char *&frame, size_t &len);
bool meter_parse_frame(const char *frame, size_t len, MeterData &data);
void meter_get_stats(MeterDriverStats &out);
