116 lines
3.2 KiB
C
116 lines
3.2 KiB
C
/**
|
|
* BluettiFields - field and register-table definitions for Bluetti devices
|
|
*
|
|
* The shape mirrors the Bluetti_ESP32_Bridge `device_field_data_t` table so the
|
|
* per-model register maps port across cleanly. Each model header (Device_*.h)
|
|
* provides three tables built from these types:
|
|
* - a state table (bluetti_field_t[]) : fields to extract from poll responses
|
|
* - a poll table (bluetti_poll_t[]) : register ranges to request
|
|
* - a command table (bluetti_field_t[]) : writable controls
|
|
*
|
|
* Copyright (c) 2026 Scott Penrose
|
|
* License: MIT
|
|
*/
|
|
|
|
#ifndef BLUETTI_FIELDS_H
|
|
#define BLUETTI_FIELDS_H
|
|
|
|
#include <stdint.h>
|
|
|
|
// How a raw register value is decoded.
|
|
enum BluettiFieldType {
|
|
B_UINT, // big-endian uint16
|
|
B_BOOL, // second byte == 1
|
|
B_ENUM, // enum value (decoded as uint16)
|
|
B_STRING, // raw ASCII
|
|
B_DECIMAL, // uint16 / 10^scale
|
|
B_VERSION, // 4 bytes -> uint32 / 100
|
|
B_SN, // 8 bytes -> uint64
|
|
B_TYPE_UNDEFINED
|
|
};
|
|
|
|
// Logical field identity. Used to map a parsed value onto a BluettiData member.
|
|
enum BluettiFieldName {
|
|
BF_DEVICE_TYPE,
|
|
BF_SERIAL_NUMBER,
|
|
BF_ARM_VERSION,
|
|
BF_DSP_VERSION,
|
|
BF_DC_INPUT_POWER,
|
|
BF_AC_INPUT_POWER,
|
|
BF_AC_OUTPUT_POWER,
|
|
BF_DC_OUTPUT_POWER,
|
|
BF_POWER_GENERATION,
|
|
BF_TOTAL_BATTERY_PERCENT,
|
|
BF_AC_OUTPUT_ON,
|
|
BF_DC_OUTPUT_ON,
|
|
BF_AC_OUTPUT_MODE,
|
|
BF_INTERNAL_AC_VOLTAGE,
|
|
BF_INTERNAL_AC_FREQUENCY,
|
|
BF_INTERNAL_CURRENT_ONE,
|
|
BF_INTERNAL_POWER_ONE,
|
|
BF_INTERNAL_CURRENT_TWO,
|
|
BF_INTERNAL_POWER_TWO,
|
|
BF_INTERNAL_CURRENT_THREE,
|
|
BF_INTERNAL_POWER_THREE,
|
|
BF_AC_INPUT_VOLTAGE,
|
|
BF_AC_INPUT_FREQUENCY,
|
|
BF_INTERNAL_DC_INPUT_VOLTAGE,
|
|
BF_INTERNAL_DC_INPUT_POWER,
|
|
BF_INTERNAL_DC_INPUT_CURRENT,
|
|
BF_INTERNAL_PACK_VOLTAGE,
|
|
BF_PACK_NUM_MAX,
|
|
BF_PACK_NUM,
|
|
BF_PACK_BATTERY_PERCENT,
|
|
BF_UPS_MODE,
|
|
BF_GRID_CHARGE_ON,
|
|
BF_AUTO_SLEEP_MODE,
|
|
BF_POWER_OFF,
|
|
BF_CELL01_VOLTAGE, // 16 consecutive cell-voltage fields must stay in order
|
|
BF_CELL02_VOLTAGE,
|
|
BF_CELL03_VOLTAGE,
|
|
BF_CELL04_VOLTAGE,
|
|
BF_CELL05_VOLTAGE,
|
|
BF_CELL06_VOLTAGE,
|
|
BF_CELL07_VOLTAGE,
|
|
BF_CELL08_VOLTAGE,
|
|
BF_CELL09_VOLTAGE,
|
|
BF_CELL10_VOLTAGE,
|
|
BF_CELL11_VOLTAGE,
|
|
BF_CELL12_VOLTAGE,
|
|
BF_CELL13_VOLTAGE,
|
|
BF_CELL14_VOLTAGE,
|
|
BF_CELL15_VOLTAGE,
|
|
BF_CELL16_VOLTAGE,
|
|
BF_BATTERY_MIN_PERCENTAGE,
|
|
BF_AC_CHARGE_MAX_PERCENTAGE,
|
|
BF_AC_INPUT_POWER_MAX,
|
|
BF_AC_INPUT_CURRENT_MAX,
|
|
BF_AC_OUTPUT_POWER_MAX,
|
|
BF_AC_OUTPUT_CURRENT_MAX,
|
|
BF_UNDEFINED
|
|
};
|
|
|
|
// One field within a register page.
|
|
// page : protocol page (0x00, 0x07, 0x08, 0x0B, ...)
|
|
// offset : starting register offset within the page
|
|
// size : number of 16-bit registers
|
|
// scale : decimal scale (value / 10^scale) for B_DECIMAL
|
|
struct bluetti_field_t {
|
|
BluettiFieldName name;
|
|
uint8_t page;
|
|
uint8_t offset;
|
|
int8_t size;
|
|
int8_t scale;
|
|
int8_t fenum;
|
|
BluettiFieldType type;
|
|
};
|
|
|
|
// A register range to request in a single read poll.
|
|
struct bluetti_poll_t {
|
|
uint8_t page;
|
|
uint8_t offset;
|
|
uint8_t count; // number of 16-bit registers
|
|
};
|
|
|
|
#endif // BLUETTI_FIELDS_H
|