@enyo-energy/sunspec-sdk 0.0.31 → 0.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,10 +2,12 @@
2
2
  * SunSpec block interfaces with block numbers
3
3
  */
4
4
  export const DEFAULT_RETRY_CONFIG = {
5
- initialDelayMs: 1000,
6
- maxDelayMs: 30000,
7
- backoffFactor: 1.5,
8
- maxAttempts: 10
5
+ phases: [
6
+ { intervalMs: 10_000, durationMs: 60_000 }, // Phase 1: every 10s for 1 minute
7
+ { intervalMs: 30_000, durationMs: 120_000 }, // Phase 2: every 30s for 2 minutes
8
+ { intervalMs: 60_000, durationMs: 300_000 }, // Phase 3: every 1m for 5 minutes
9
+ { intervalMs: 300_000, durationMs: 0 }, // Phase 4: every 5m forever
10
+ ]
9
11
  };
10
12
  /**
11
13
  * Common Sunspec Model IDs
@@ -58,6 +60,87 @@ export var SunspecBatteryChargeState;
58
60
  SunspecBatteryChargeState[SunspecBatteryChargeState["HOLDING"] = 6] = "HOLDING";
59
61
  SunspecBatteryChargeState[SunspecBatteryChargeState["TESTING"] = 7] = "TESTING";
60
62
  })(SunspecBatteryChargeState || (SunspecBatteryChargeState = {}));
63
+ /**
64
+ * Battery Control Mode values for Model 802
65
+ * Offset 17: LocRemCtl - Local/Remote control mode
66
+ */
67
+ export var SunspecBatteryControlMode;
68
+ (function (SunspecBatteryControlMode) {
69
+ SunspecBatteryControlMode[SunspecBatteryControlMode["REMOTE"] = 0] = "REMOTE";
70
+ SunspecBatteryControlMode[SunspecBatteryControlMode["LOCAL"] = 1] = "LOCAL";
71
+ })(SunspecBatteryControlMode || (SunspecBatteryControlMode = {}));
72
+ /**
73
+ * Battery Type values for Model 802
74
+ * Offset 21: Typ - Battery type
75
+ */
76
+ export var SunspecBatteryType;
77
+ (function (SunspecBatteryType) {
78
+ SunspecBatteryType[SunspecBatteryType["NOT_APPLICABLE_UNKNOWN"] = 0] = "NOT_APPLICABLE_UNKNOWN";
79
+ SunspecBatteryType[SunspecBatteryType["LEAD_ACID"] = 1] = "LEAD_ACID";
80
+ SunspecBatteryType[SunspecBatteryType["NICKEL_METAL_HYDRIDE"] = 2] = "NICKEL_METAL_HYDRIDE";
81
+ SunspecBatteryType[SunspecBatteryType["NICKEL_CADMIUM"] = 3] = "NICKEL_CADMIUM";
82
+ SunspecBatteryType[SunspecBatteryType["LITHIUM_ION"] = 4] = "LITHIUM_ION";
83
+ SunspecBatteryType[SunspecBatteryType["CARBON_ZINC"] = 5] = "CARBON_ZINC";
84
+ SunspecBatteryType[SunspecBatteryType["ZINC_CHLORIDE"] = 6] = "ZINC_CHLORIDE";
85
+ SunspecBatteryType[SunspecBatteryType["ALKALINE"] = 7] = "ALKALINE";
86
+ SunspecBatteryType[SunspecBatteryType["RECHARGEABLE_ALKALINE"] = 8] = "RECHARGEABLE_ALKALINE";
87
+ SunspecBatteryType[SunspecBatteryType["SODIUM_SULFUR"] = 9] = "SODIUM_SULFUR";
88
+ SunspecBatteryType[SunspecBatteryType["FLOW"] = 10] = "FLOW";
89
+ SunspecBatteryType[SunspecBatteryType["SUPER_CAPACITOR"] = 11] = "SUPER_CAPACITOR";
90
+ SunspecBatteryType[SunspecBatteryType["OTHER"] = 99] = "OTHER";
91
+ })(SunspecBatteryType || (SunspecBatteryType = {}));
92
+ /**
93
+ * Battery Bank State values for Model 802
94
+ * Offset 22: State - Battery bank state
95
+ */
96
+ export var SunspecBatteryBankState;
97
+ (function (SunspecBatteryBankState) {
98
+ SunspecBatteryBankState[SunspecBatteryBankState["DISCONNECTED"] = 1] = "DISCONNECTED";
99
+ SunspecBatteryBankState[SunspecBatteryBankState["INITIALIZING"] = 2] = "INITIALIZING";
100
+ SunspecBatteryBankState[SunspecBatteryBankState["CONNECTED"] = 3] = "CONNECTED";
101
+ SunspecBatteryBankState[SunspecBatteryBankState["STANDBY"] = 4] = "STANDBY";
102
+ SunspecBatteryBankState[SunspecBatteryBankState["SOC_PROTECTION"] = 5] = "SOC_PROTECTION";
103
+ SunspecBatteryBankState[SunspecBatteryBankState["SUSPENDING"] = 6] = "SUSPENDING";
104
+ SunspecBatteryBankState[SunspecBatteryBankState["FAULT"] = 99] = "FAULT";
105
+ })(SunspecBatteryBankState || (SunspecBatteryBankState = {}));
106
+ /**
107
+ * Battery Event 1 bit positions for Model 802
108
+ * Offset 26-27: Evt1 - Battery event bitfield
109
+ */
110
+ export var SunspecBatteryEvent1;
111
+ (function (SunspecBatteryEvent1) {
112
+ SunspecBatteryEvent1[SunspecBatteryEvent1["COMMUNICATION_ERROR"] = 0] = "COMMUNICATION_ERROR";
113
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_TEMP_ALARM"] = 1] = "OVER_TEMP_ALARM";
114
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_TEMP_WARNING"] = 2] = "OVER_TEMP_WARNING";
115
+ SunspecBatteryEvent1[SunspecBatteryEvent1["UNDER_TEMP_ALARM"] = 3] = "UNDER_TEMP_ALARM";
116
+ SunspecBatteryEvent1[SunspecBatteryEvent1["UNDER_TEMP_WARNING"] = 4] = "UNDER_TEMP_WARNING";
117
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_CHARGE_CURRENT_ALARM"] = 5] = "OVER_CHARGE_CURRENT_ALARM";
118
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_CHARGE_CURRENT_WARNING"] = 6] = "OVER_CHARGE_CURRENT_WARNING";
119
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_DISCHARGE_CURRENT_ALARM"] = 7] = "OVER_DISCHARGE_CURRENT_ALARM";
120
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_DISCHARGE_CURRENT_WARNING"] = 8] = "OVER_DISCHARGE_CURRENT_WARNING";
121
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_VOLT_ALARM"] = 9] = "OVER_VOLT_ALARM";
122
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_VOLT_WARNING"] = 10] = "OVER_VOLT_WARNING";
123
+ SunspecBatteryEvent1[SunspecBatteryEvent1["UNDER_VOLT_ALARM"] = 11] = "UNDER_VOLT_ALARM";
124
+ SunspecBatteryEvent1[SunspecBatteryEvent1["UNDER_VOLT_WARNING"] = 12] = "UNDER_VOLT_WARNING";
125
+ SunspecBatteryEvent1[SunspecBatteryEvent1["UNDER_SOC_MIN_ALARM"] = 13] = "UNDER_SOC_MIN_ALARM";
126
+ SunspecBatteryEvent1[SunspecBatteryEvent1["UNDER_SOC_MIN_WARNING"] = 14] = "UNDER_SOC_MIN_WARNING";
127
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_SOC_MAX_ALARM"] = 15] = "OVER_SOC_MAX_ALARM";
128
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OVER_SOC_MAX_WARNING"] = 16] = "OVER_SOC_MAX_WARNING";
129
+ SunspecBatteryEvent1[SunspecBatteryEvent1["VOLTAGE_IMBALANCE_WARNING"] = 17] = "VOLTAGE_IMBALANCE_WARNING";
130
+ SunspecBatteryEvent1[SunspecBatteryEvent1["TEMPERATURE_IMBALANCE_ALARM"] = 18] = "TEMPERATURE_IMBALANCE_ALARM";
131
+ SunspecBatteryEvent1[SunspecBatteryEvent1["TEMPERATURE_IMBALANCE_WARNING"] = 19] = "TEMPERATURE_IMBALANCE_WARNING";
132
+ SunspecBatteryEvent1[SunspecBatteryEvent1["CONTACTOR_ERROR"] = 20] = "CONTACTOR_ERROR";
133
+ SunspecBatteryEvent1[SunspecBatteryEvent1["FAN_ERROR"] = 21] = "FAN_ERROR";
134
+ SunspecBatteryEvent1[SunspecBatteryEvent1["FUSE_ERROR"] = 22] = "FUSE_ERROR";
135
+ SunspecBatteryEvent1[SunspecBatteryEvent1["GROUND_FAULT"] = 23] = "GROUND_FAULT";
136
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OPEN_DOOR_ERROR"] = 24] = "OPEN_DOOR_ERROR";
137
+ SunspecBatteryEvent1[SunspecBatteryEvent1["CURRENT_IMBALANCE_WARNING"] = 25] = "CURRENT_IMBALANCE_WARNING";
138
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OTHER_ALARM"] = 26] = "OTHER_ALARM";
139
+ SunspecBatteryEvent1[SunspecBatteryEvent1["OTHER_WARNING"] = 27] = "OTHER_WARNING";
140
+ SunspecBatteryEvent1[SunspecBatteryEvent1["RESERVED_1"] = 28] = "RESERVED_1";
141
+ SunspecBatteryEvent1[SunspecBatteryEvent1["CONFIGURATION_ALARM"] = 29] = "CONFIGURATION_ALARM";
142
+ SunspecBatteryEvent1[SunspecBatteryEvent1["CONFIGURATION_WARNING"] = 30] = "CONFIGURATION_WARNING";
143
+ })(SunspecBatteryEvent1 || (SunspecBatteryEvent1 = {}));
61
144
  /**
62
145
  * Storage Control Mode bitfield values for Model 124
63
146
  *
@@ -116,3 +199,24 @@ export var SunspecStorageMode;
116
199
  SunspecStorageMode["HOLDING"] = "holding";
117
200
  SunspecStorageMode["AUTO"] = "auto"; // Both charge and discharge allowed
118
201
  })(SunspecStorageMode || (SunspecStorageMode = {}));
202
+ /**
203
+ * Battery control structure for writing to Model 124
204
+ * Used for controlling battery charge/discharge behavior
205
+ *
206
+ * IMPORTANT: To enable grid charging with specific power:
207
+ * 1. Set storCtlMod with appropriate bits to enable external control
208
+ * 2. Set chaGriSet = 1 to allow grid charging
209
+ * 3. Set wChaMax to the desired charging power in Watts
210
+ */
211
+ export var SunspecInverterCapability;
212
+ (function (SunspecInverterCapability) {
213
+ SunspecInverterCapability["FeedInLimit"] = "feed-in-limit";
214
+ })(SunspecInverterCapability || (SunspecInverterCapability = {}));
215
+ export var SunspecBatteryCapability;
216
+ (function (SunspecBatteryCapability) {
217
+ SunspecBatteryCapability["GridCharging"] = "grid-charging";
218
+ SunspecBatteryCapability["DischargeLimit"] = "discharge-limit";
219
+ })(SunspecBatteryCapability || (SunspecBatteryCapability = {}));
220
+ export var SunspecMeterCapability;
221
+ (function (SunspecMeterCapability) {
222
+ })(SunspecMeterCapability || (SunspecMeterCapability = {}));
@@ -16,9 +16,8 @@
16
16
  * - pad: 0x8000 (always returns this value)
17
17
  * - string: all registers 0x0000 (NULL)
18
18
  */
19
- import { type SunspecInverterControls, type SunspecInverterData, type SunspecInverterSettings, type SunspecMeterData, type SunspecModel, type SunspecMPPTData, type SunspecBatteryData, type SunspecBatteryControls, SunspecStorageMode, type IRetryConfig } from "./sunspec-interfaces.js";
20
- import { ConnectionRetryManager } from "./connection-retry-manager.js";
21
- import { IConnectionHealth } from "@enyo-energy/energy-app-sdk/dist/implementations/modbus/interfaces.js";
19
+ import { type SunspecInverterControls, type SunspecInverterData, type SunspecInverterSettings, type SunspecMeterData, type SunspecModel, type SunspecMPPTData, type SunspecBatteryData, type SunspecBatteryBaseData, type SunspecBatteryControls, SunspecStorageMode } from "./sunspec-interfaces.js";
20
+ import { EnergyAppModbusDataType, IConnectionHealth } from "@enyo-energy/energy-app-sdk/dist/implementations/modbus/interfaces.js";
22
21
  import { EnergyApp } from "@enyo-energy/energy-app-sdk";
23
22
  export declare class SunspecModbusClient {
24
23
  private energyApp;
@@ -29,9 +28,8 @@ export declare class SunspecModbusClient {
29
28
  private faultTolerantReader;
30
29
  private modbusDataTypeConverter;
31
30
  private connectionParams;
32
- private retryManager;
33
31
  private autoReconnectEnabled;
34
- constructor(energyApp: EnergyApp, retryConfig?: Partial<IRetryConfig>);
32
+ constructor(energyApp: EnergyApp);
35
33
  /**
36
34
  * Connect to Modbus device
37
35
  * @param host Primary host (hostname) to connect to
@@ -55,11 +53,6 @@ export declare class SunspecModbusClient {
55
53
  * Returns true if successful, false otherwise
56
54
  */
57
55
  private attemptConnection;
58
- /**
59
- * Check connection health and trigger automatic reconnection if unhealthy
60
- * Returns true if connection is healthy or was successfully restored
61
- */
62
- ensureHealthyConnection(): Promise<boolean>;
63
56
  /**
64
57
  * Enable or disable automatic reconnection
65
58
  */
@@ -68,10 +61,6 @@ export declare class SunspecModbusClient {
68
61
  * Check if auto-reconnect is enabled
69
62
  */
70
63
  isAutoReconnectEnabled(): boolean;
71
- /**
72
- * Get the retry manager for advanced configuration
73
- */
74
- getRetryManager(): ConnectionRetryManager;
75
64
  /**
76
65
  * Detect the base address and addressing mode (0-based or 1-based) for SunSpec
77
66
  */
@@ -119,13 +108,13 @@ export declare class SunspecModbusClient {
119
108
  /**
120
109
  * Helper to read register value(s) using the fault-tolerant reader with data type conversion
121
110
  */
122
- private readRegisterValue;
111
+ readRegisterValue(address: number, quantity: number | undefined, dataType: EnergyAppModbusDataType): Promise<number | string | number[]>;
123
112
  /**
124
113
  * Helper to write register value(s)
125
114
  */
126
- private writeRegisterValue;
115
+ writeRegisterValue(address: number, value: number | number[], dataType?: EnergyAppModbusDataType): Promise<boolean>;
127
116
  /**
128
- * Read inverter data from Model 103 (Three Phase)
117
+ * Read inverter data from Model 101 (Single Phase) / Model 103 (Three Phase)
129
118
  */
130
119
  readInverterData(): Promise<SunspecInverterData | null>;
131
120
  /**
@@ -140,10 +129,10 @@ export declare class SunspecModbusClient {
140
129
  * Apply scale factor to a value
141
130
  * Returns undefined if the value is unimplemented or scale factor is out of range
142
131
  */
143
- private applyScaleFactor;
132
+ applyScaleFactor(value: number, scaleFactor: number, dataType?: 'uint16' | 'int16' | 'acc32', fieldName?: string, offset?: number, modelId?: number): number | undefined;
133
+ logRegisterRead(modelId: number, offset: number, fieldName: string, rawValue: number | string | undefined, dataType?: string): void;
144
134
  /**
145
- * Read MPPT Scale Factors for a specific module
146
- * Returns the scale factors for DC Current, DC Voltage, DC Power, and DC Energy
135
+ * Read scale factors from Model 160 (MPPT)
147
136
  *
148
137
  * MPPT Model 160 Scale Factor Register Offsets (relative to module start):
149
138
  * - DCA_SF (Current Scale Factor): Offset 2
@@ -164,7 +153,7 @@ export declare class SunspecModbusClient {
164
153
  */
165
154
  readMPPTData(moduleId?: number): Promise<SunspecMPPTData | null>;
166
155
  /**
167
- * Read all available MPPT strings
156
+ * Read all MPPT strings from Model 160 (Multiple MPPT)
168
157
  */
169
158
  readAllMPPTData(): Promise<SunspecMPPTData[]>;
170
159
  /**
@@ -174,7 +163,23 @@ export declare class SunspecModbusClient {
174
163
  */
175
164
  private mapBatteryChargeState;
176
165
  /**
177
- * Read battery data from Model 124 (Basic Storage Controls)
166
+ * Map battery type to human-readable name (Model 802)
167
+ */
168
+ private mapBatteryType;
169
+ /**
170
+ * Map battery bank state to human-readable name (Model 802)
171
+ */
172
+ private mapBatteryBankState;
173
+ /**
174
+ * Read Model 802 scale factors (offsets 52-63)
175
+ */
176
+ private readBatteryBaseScaleFactors;
177
+ /**
178
+ * Read battery base data from Model 802 (Battery Base)
179
+ */
180
+ readBatteryBaseData(): Promise<SunspecBatteryBaseData | null>;
181
+ /**
182
+ * Read battery data from Model 124 (Basic Storage) with fallback to Model 802 / Model 803
178
183
  */
179
184
  readBatteryData(): Promise<SunspecBatteryData | null>;
180
185
  /**
@@ -190,11 +195,11 @@ export declare class SunspecModbusClient {
190
195
  */
191
196
  enableGridCharging(enable: boolean): Promise<boolean>;
192
197
  /**
193
- * Read current battery control settings
198
+ * Read battery control settings from Model 124 (Basic Storage Controls)
194
199
  */
195
200
  readBatteryControls(): Promise<SunspecBatteryControls | null>;
196
201
  /**
197
- * Read meter data (Model 203 for 3-phase)
202
+ * Read meter data from Model 201 (Single Phase) / Model 203 (Three Phase) / Model 204 (Split Phase)
198
203
  */
199
204
  readMeterData(): Promise<SunspecMeterData | null>;
200
205
  /**
@@ -218,11 +223,11 @@ export declare class SunspecModbusClient {
218
223
  */
219
224
  getConnectionHealth(): IConnectionHealth;
220
225
  /**
221
- * Read Block 121 - Inverter Basic Settings
226
+ * Read inverter settings from Model 121 (Inverter Settings)
222
227
  */
223
228
  readInverterSettings(): Promise<SunspecInverterSettings | null>;
224
229
  /**
225
- * Read Block 123 - Immediate Inverter Controls
230
+ * Read inverter controls from Model 123 (Immediate Inverter Controls)
226
231
  */
227
232
  readInverterControls(): Promise<SunspecInverterControls | null>;
228
233
  /**
@@ -230,7 +235,18 @@ export declare class SunspecModbusClient {
230
235
  */
231
236
  writeInverterSettings(settings: Partial<SunspecInverterSettings>): Promise<boolean>;
232
237
  /**
233
- * Write Block 123 - Immediate Inverter Controls
238
+ * Write inverter controls to Model 123 (Immediate Inverter Controls)
234
239
  */
235
240
  writeInverterControls(controls: Partial<SunspecInverterControls>): Promise<boolean>;
241
+ /**
242
+ * Set the inverter feed-in power limit using Model 123 (Immediate Inverter Controls)
243
+ *
244
+ * When limitW is a number, reads WMax from Model 121, computes percentage,
245
+ * writes WMaxLimPct and enables WMaxLim_Ena.
246
+ * When limitW is null, disables the limit by setting WMaxLim_Ena = DISABLED.
247
+ *
248
+ * @param limitW - Power limit in Watts, or null to remove the limit
249
+ * @returns true if successful, false otherwise
250
+ */
251
+ setFeedInLimit(limitW: number | null): Promise<boolean>;
236
252
  }