1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//! Holding-register addresses for the XY-series buck converters.
//!
//! All registers are 16-bit. Where a value is fixed-point, the *scale*
//! is the divisor to apply to the raw integer to obtain the physical
//! value (so a raw `1440` at scale `100` is `14.40`).
// This module is the canonical address surface for the whole register
// map. Some entries aren't referenced by the high-level API yet (rarely
// used registers, group offsets, individual M0 protection fields) but
// are kept so the map stays complete in one place.
/// Default Modbus slave address. Reconfigurable via [`REG_SLAVE_ADDR`];
/// the new value only takes effect after the device resets.
pub const DEFAULT_SLAVE: u8 = 0x01;
// ─── Status & runtime control (0x0000 – 0x001E) ──────────────────────────────
/// V-SET — output voltage setpoint. Scale 100 (V).
pub const REG_V_SET: u16 = 0x0000;
/// I-SET — output current limit setpoint. Scale 100 (A).
pub const REG_I_SET: u16 = 0x0001;
/// V-OUT — measured output voltage. Scale 100 (V).
pub const REG_V_OUT: u16 = 0x0002;
/// I-OUT — measured output current. Scale 100 (A).
pub const REG_I_OUT: u16 = 0x0003;
/// P-OUT — measured output power. Scale 10 (W).
pub const REG_P_OUT: u16 = 0x0004;
/// V-IN — measured input voltage. Scale 100 (V).
pub const REG_V_IN: u16 = 0x0005;
/// AH-LOW — cumulative output charge, low word. Scale 1000 (Ah).
pub const REG_AH_LOW: u16 = 0x0006;
/// AH-HIGH — cumulative output charge, high word. Untested in
/// community docs; treat the 32-bit composition as best-effort.
pub const REG_AH_HIGH: u16 = 0x0007;
/// WH-LOW — cumulative output energy, low word. Scale 1000 (Wh).
pub const REG_WH_LOW: u16 = 0x0008;
/// WH-HIGH — cumulative output energy, high word.
pub const REG_WH_HIGH: u16 = 0x0009;
/// OUT-H — output-on time, hours.
pub const REG_OUT_H: u16 = 0x000A;
/// OUT-M — output-on time, minutes.
pub const REG_OUT_M: u16 = 0x000B;
/// OUT-S — output-on time, seconds.
pub const REG_OUT_S: u16 = 0x000C;
/// T-IN — internal temperature. Scale 10 (°C/°F per [`REG_TEMP_UNIT`]).
pub const REG_T_IN: u16 = 0x000D;
/// T-EX — external probe temperature. Scale 10 (°C/°F).
pub const REG_T_EX: u16 = 0x000E;
/// LOCK — front-panel key lock (0 unlocked, 1 locked).
pub const REG_LOCK: u16 = 0x000F;
/// PROTECT — latched protection cause. Write 0 to clear.
pub const REG_PROTECT: u16 = 0x0010;
/// CVCC — regulation mode (0 CV, 1 CC).
pub const REG_CVCC: u16 = 0x0011;
/// ONOFF — output enable (0 off, 1 on).
pub const REG_OUTPUT_EN: u16 = 0x0012;
/// F-C — temperature unit (0 °C, 1 °F).
pub const REG_TEMP_UNIT: u16 = 0x0013;
/// B-LED — backlight brightness (0–5).
pub const REG_BACKLIGHT: u16 = 0x0014;
/// SLEEP — off-screen timeout in minutes.
pub const REG_SLEEP: u16 = 0x0015;
/// MODEL — product number (e.g. `0x6500` on XY7025).
pub const REG_MODEL: u16 = 0x0016;
/// VERSION — firmware version (e.g. `0x0071`).
pub const REG_VERSION: u16 = 0x0017;
/// SLAVE-ADD — Modbus slave address; takes effect after device reset.
pub const REG_SLAVE_ADDR: u16 = 0x0018;
/// BAUDRATE_L — baud-rate code (see [`crate::types::BaudRate`]).
pub const REG_BAUD_CODE: u16 = 0x0019;
/// T-IN-OFFSET — internal-temp calibration offset. Scale 10.
pub const REG_T_IN_OFFSET: u16 = 0x001A;
/// T-EX-OFFSET — external-temp calibration offset. Scale 10.
pub const REG_T_EX_OFFSET: u16 = 0x001B;
/// BUZZER — buzzer enable. Often unimplemented in firmware.
pub const REG_BUZZER: u16 = 0x001C;
/// EXTRACT-M — recall a memory group into M0 (write 0–9).
pub const REG_EXTRACT_M: u16 = 0x001D;
/// DEVICE — device status. Documented but unreliable on some firmware.
pub const REG_DEVICE: u16 = 0x001E;
// ─── WiFi pairing (0x0030 – 0x0034) — pending ────────────────────────────────
//
// Only populated when a SiniLink XY-WFPOW (ESP8285) board is attached.
// Register addresses are listed here for reference; the high-level API
// in `device.rs` does not yet expose them — see the README for the
// register layout if you want to drive these directly via
// `ModbusTransport`.
//
// 0x0030 WiFi MASTER host type (0x3B3A = WiFi)
// 0x0031 WiFi CONFIG pairing mode (0 invalid / 1 touch / 2 AP)
// 0x0032 WiFi STATUS link state (0 none / 1 router / 2 server / 3 touch / 4 AP)
// 0x0033 IPV4-H high 16 bits of IPv4 address
// 0x0034 IPV4-L low 16 bits of IPv4 address
// ─── Memory groups M0–M9 ─────────────────────────────────────────────────────
//
// 10 preset groups, 14 registers each, base 0x0050, stride 0x0010.
// M0 is the live operating set.
pub const GROUP_BASE: u16 = 0x0050;
pub const GROUP_STRIDE: u16 = 0x0010;
/// Number of registers per memory group.
pub const GROUP_LEN: u16 = 14;
/// Number of memory groups (M0 through M9).
pub const GROUP_COUNT: u8 = 10;
/// Base register address of memory group `n` (0..=9).
pub const
// In-group register offsets (add to `group_addr(n)` to get an absolute address).
pub const GROUP_OFF_V_SET: u16 = 0;
pub const GROUP_OFF_I_SET: u16 = 1;
pub const GROUP_OFF_S_LVP: u16 = 2;
pub const GROUP_OFF_S_OVP: u16 = 3;
pub const GROUP_OFF_S_OCP: u16 = 4;
pub const GROUP_OFF_S_OPP: u16 = 5;
pub const GROUP_OFF_S_OHP_H: u16 = 6;
pub const GROUP_OFF_S_OHP_M: u16 = 7;
pub const GROUP_OFF_S_OAH_L: u16 = 8;
pub const GROUP_OFF_S_OAH_H: u16 = 9;
pub const GROUP_OFF_S_OWH_L: u16 = 10;
pub const GROUP_OFF_S_OWH_H: u16 = 11;
pub const GROUP_OFF_S_OTP: u16 = 12;
pub const GROUP_OFF_S_INI: u16 = 13;
// Convenience absolute addresses for the active group (M0).
pub const REG_S_LVP: u16 = GROUP_BASE + GROUP_OFF_S_LVP;
pub const REG_S_OVP: u16 = GROUP_BASE + GROUP_OFF_S_OVP;
pub const REG_S_OCP: u16 = GROUP_BASE + GROUP_OFF_S_OCP;
pub const REG_S_OPP: u16 = GROUP_BASE + GROUP_OFF_S_OPP;
pub const REG_S_OTP: u16 = GROUP_BASE + GROUP_OFF_S_OTP;
pub const REG_S_INI: u16 = GROUP_BASE + GROUP_OFF_S_INI;
// ─── Bulk-access layout invariants ───────────────────────────────────────────
//
// Every bulk read/write in `device::*` sends a single Modbus transaction
// over a contiguous register span. These asserts pin the adjacency the
// callers rely on — a typo'd address constant turns into a build error
// instead of a silent off-by-one at runtime.
// `read_setpoints` (V-SET, I-SET).
const _: = assert!;
// `read_status` (V-SET..OUTPUT_EN, 19 regs indexed by absolute address).
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
// `read_totals` (AH_LOW..OUT_S, 7 regs).
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
// `set_protection` / `read_protection` (S-LVP, S-OVP, S-OCP).
const _: = assert!;
const _: = assert!;
// `read_temperatures` (T_IN, T_EX).
const _: = assert!;
// `read_group` / `write_group` walk all 14 in-group offsets in order.
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;
const _: = assert!;