@enyo-energy/sunspec-sdk 0.0.31 → 0.0.32

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.
@@ -16,7 +16,7 @@
16
16
  * - pad: 0x8000 (always returns this value)
17
17
  * - string: all registers 0x0000 (NULL)
18
18
  */
19
- import { SunspecModelId, SunspecBatteryChargeState, SunspecStorageControlMode, SunspecChargeSource, SunspecStorageMode } from "./sunspec-interfaces.js";
19
+ import { SunspecModelId, SunspecBatteryChargeState, SunspecStorageControlMode, SunspecChargeSource, SunspecStorageMode, SunspecBatteryType, SunspecBatteryBankState } from "./sunspec-interfaces.js";
20
20
  import { ConnectionRetryManager } from "./connection-retry-manager.js";
21
21
  import { EnergyAppModbusConnectionHealth } from "@enyo-energy/energy-app-sdk/dist/implementations/modbus/EnergyAppModbusConnectionHealth.js";
22
22
  import { EnergyAppModbusFaultTolerantReader } from "@enyo-energy/energy-app-sdk/dist/implementations/modbus/EnergyAppModbusFaultTolerantReader.js";
@@ -292,7 +292,7 @@ export class SunspecModbusClient {
292
292
  }
293
293
  }
294
294
  const addressesChecked = customBaseAddress !== undefined
295
- ? `${customBaseAddress}, ${customBaseAddress + 1}, 40000, or 40001`
295
+ ? `${customBaseAddress}, ${customBaseAddress + 1}`
296
296
  : '40000 or 40001';
297
297
  throw new Error(`Device is not SunSpec compliant - "SunS" identifier not found at addresses ${addressesChecked}`);
298
298
  }
@@ -522,64 +522,44 @@ export class SunspecModbusClient {
522
522
  const voltageANRaw = await this.readRegisterValue(baseAddr + 10, 1, 'uint16');
523
523
  const voltageBNRaw = await this.readRegisterValue(baseAddr + 11, 1, 'uint16');
524
524
  const voltageCNRaw = await this.readRegisterValue(baseAddr + 12, 1, 'uint16');
525
+ // Read raw values for fields that need IIFEs removed
526
+ const acCurrentRaw = await this.readRegisterValue(baseAddr + 2, 1, 'uint16');
527
+ const acPowerRaw = await this.readRegisterValue(baseAddr + 14, 1, 'int16');
528
+ const dcCurrentRaw = await this.readRegisterValue(baseAddr + 27, 1, 'uint16');
529
+ const dcVoltageRaw = await this.readRegisterValue(baseAddr + 28, 1, 'uint16');
530
+ const dcPowerRaw = await this.readRegisterValue(baseAddr + 30, 1, 'int16');
525
531
  const data = {
526
532
  blockNumber: 103,
527
533
  blockAddress: model.address,
528
534
  blockLength: model.length,
529
535
  // AC Current values - Offsets 2-5
530
- acCurrent: this.applyScaleFactor(await (async () => {
531
- const addr = baseAddr + 2;
532
- const raw = await this.readRegisterValue(addr, 1, 'uint16');
533
- console.log(`AC Current: address=${addr}, raw=0x${raw.toString(16).toUpperCase()} (${raw})`);
534
- return raw;
535
- })(), scaleFactors.A_SF, 'uint16', 'AC Current'),
536
- phaseACurrent: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 3, 1, 'uint16'), scaleFactors.A_SF, 'uint16', 'Phase A Current'),
537
- phaseBCurrent: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 4, 1, 'uint16'), scaleFactors.A_SF, 'uint16', 'Phase B Current'),
538
- phaseCCurrent: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 5, 1, 'uint16'), scaleFactors.A_SF, 'uint16', 'Phase C Current'),
536
+ acCurrent: this.applyScaleFactor(acCurrentRaw, scaleFactors.A_SF, 'uint16', 'AC Current', 2, 103),
537
+ phaseACurrent: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 3, 1, 'uint16'), scaleFactors.A_SF, 'uint16', 'Phase A Current', 3, 103),
538
+ phaseBCurrent: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 4, 1, 'uint16'), scaleFactors.A_SF, 'uint16', 'Phase B Current', 4, 103),
539
+ phaseCCurrent: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 5, 1, 'uint16'), scaleFactors.A_SF, 'uint16', 'Phase C Current', 5, 103),
539
540
  // Voltage values - Offsets 7-12
540
- voltageAB: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 7, 1, 'uint16'), scaleFactors.V_SF, 'uint16', 'Voltage AB'),
541
- voltageBC: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 8, 1, 'uint16'), scaleFactors.V_SF, 'uint16', 'Voltage BC'),
542
- voltageCA: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 9, 1, 'uint16'), scaleFactors.V_SF, 'uint16', 'Voltage CA'),
543
- // Apply scale factor with unimplemented value checking
544
- voltageAN: this.applyScaleFactor(voltageANRaw, scaleFactors.V_SF, 'uint16', 'Voltage AN'),
545
- voltageBN: this.applyScaleFactor(voltageBNRaw, scaleFactors.V_SF, 'uint16', 'Voltage BN'),
546
- voltageCN: this.applyScaleFactor(voltageCNRaw, scaleFactors.V_SF, 'uint16', 'Voltage CN'),
541
+ voltageAB: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 7, 1, 'uint16'), scaleFactors.V_SF, 'uint16', 'Voltage AB', 7, 103),
542
+ voltageBC: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 8, 1, 'uint16'), scaleFactors.V_SF, 'uint16', 'Voltage BC', 8, 103),
543
+ voltageCA: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 9, 1, 'uint16'), scaleFactors.V_SF, 'uint16', 'Voltage CA', 9, 103),
544
+ voltageAN: this.applyScaleFactor(voltageANRaw, scaleFactors.V_SF, 'uint16', 'Voltage AN', 10, 103),
545
+ voltageBN: this.applyScaleFactor(voltageBNRaw, scaleFactors.V_SF, 'uint16', 'Voltage BN', 11, 103),
546
+ voltageCN: this.applyScaleFactor(voltageCNRaw, scaleFactors.V_SF, 'uint16', 'Voltage CN', 12, 103),
547
547
  // Power values - Offsets 14, 18, 20, 22
548
- acPower: this.applyScaleFactor(await (async () => {
549
- const addr = baseAddr + 14;
550
- const raw = await this.readRegisterValue(addr, 1, 'int16');
551
- console.log(`AC Power (W): address=${addr}, raw=0x${raw.toString(16).toUpperCase()} (${raw}), SF=${scaleFactors.W_SF}`);
552
- return raw;
553
- })(), scaleFactors.W_SF, 'int16', 'AC Power'),
554
- apparentPower: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 18, 1, 'uint16'), scaleFactors.VA_SF, 'uint16', 'Apparent Power'),
555
- reactivePower: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 20, 1, 'int16'), scaleFactors.VAr_SF, 'int16', 'Reactive Power'),
556
- powerFactor: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 22, 1, 'int16'), scaleFactors.PF_SF, 'int16', 'Power Factor'),
548
+ acPower: this.applyScaleFactor(acPowerRaw, scaleFactors.W_SF, 'int16', 'AC Power', 14, 103),
549
+ apparentPower: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 18, 1, 'uint16'), scaleFactors.VA_SF, 'uint16', 'Apparent Power', 18, 103),
550
+ reactivePower: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 20, 1, 'int16'), scaleFactors.VAr_SF, 'int16', 'Reactive Power', 20, 103),
551
+ powerFactor: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 22, 1, 'int16'), scaleFactors.PF_SF, 'int16', 'Power Factor', 22, 103),
557
552
  // Frequency - Offset 16
558
- frequency: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 16, 1, 'uint16'), scaleFactors.Hz_SF, 'uint16', 'Frequency'),
553
+ frequency: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 16, 1, 'uint16'), scaleFactors.Hz_SF, 'uint16', 'Frequency', 16, 103),
559
554
  // DC values - Offsets 27, 28, 30
560
- dcCurrent: this.applyScaleFactor(await (async () => {
561
- const addr = baseAddr + 27;
562
- const raw = await this.readRegisterValue(addr, 1, 'uint16');
563
- console.log(`DC Current: address=${addr}, raw=0x${raw.toString(16).toUpperCase()} (${raw})`);
564
- return raw;
565
- })(), scaleFactors.DCA_SF, 'uint16', 'DC Current'),
566
- dcVoltage: this.applyScaleFactor(await (async () => {
567
- const addr = baseAddr + 28;
568
- const raw = await this.readRegisterValue(addr, 1, 'uint16');
569
- console.log(`DC Voltage: address=${addr}, raw=0x${raw.toString(16).toUpperCase()} (${raw})`);
570
- return raw;
571
- })(), scaleFactors.DCV_SF, 'uint16', 'DC Voltage'),
572
- dcPower: this.applyScaleFactor(await (async () => {
573
- const addr = baseAddr + 30;
574
- const raw = await this.readRegisterValue(addr, 1, 'int16');
575
- console.log(`DC Power: address=${addr}, raw=0x${raw.toString(16).toUpperCase()} (${raw}), SF=${scaleFactors.DCW_SF}`);
576
- return raw;
577
- })(), scaleFactors.DCW_SF, 'int16', 'DC Power'),
555
+ dcCurrent: this.applyScaleFactor(dcCurrentRaw, scaleFactors.DCA_SF, 'uint16', 'DC Current', 27, 103),
556
+ dcVoltage: this.applyScaleFactor(dcVoltageRaw, scaleFactors.DCV_SF, 'uint16', 'DC Voltage', 28, 103),
557
+ dcPower: this.applyScaleFactor(dcPowerRaw, scaleFactors.DCW_SF, 'int16', 'DC Power', 30, 103),
578
558
  // Temperature values - Offsets 32, 34, 35, 36
579
- cabinetTemperature: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 32, 1, 'int16'), scaleFactors.Tmp_SF, 'int16', 'Cabinet Temperature'),
580
- heatSinkTemperature: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 34, 1, 'int16'), scaleFactors.Tmp_SF, 'int16', 'Heat Sink Temperature'),
581
- transformerTemperature: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 35, 1, 'int16'), scaleFactors.Tmp_SF, 'int16', 'Transformer Temperature'),
582
- otherTemperature: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 36, 1, 'int16'), scaleFactors.Tmp_SF, 'int16', 'Other Temperature'),
559
+ cabinetTemperature: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 32, 1, 'int16'), scaleFactors.Tmp_SF, 'int16', 'Cabinet Temperature', 32, 103),
560
+ heatSinkTemperature: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 34, 1, 'int16'), scaleFactors.Tmp_SF, 'int16', 'Heat Sink Temperature', 34, 103),
561
+ transformerTemperature: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 35, 1, 'int16'), scaleFactors.Tmp_SF, 'int16', 'Transformer Temperature', 35, 103),
562
+ otherTemperature: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 36, 1, 'int16'), scaleFactors.Tmp_SF, 'int16', 'Other Temperature', 36, 103),
583
563
  // Status values - Offsets 38, 39
584
564
  operatingState: await this.readRegisterValue(baseAddr + 38, 1, 'uint16'),
585
565
  vendorState: await this.readRegisterValue(baseAddr + 39, 1, 'uint16'),
@@ -591,11 +571,20 @@ export class SunspecModbusClient {
591
571
  vendorEvents3: await this.readRegisterValue(baseAddr + 48, 2, 'uint32'),
592
572
  vendorEvents4: await this.readRegisterValue(baseAddr + 50, 2, 'uint32')
593
573
  };
574
+ // Log non-scaled fields
575
+ this.logRegisterRead(103, 38, 'Operating State', data.operatingState, 'enum16');
576
+ this.logRegisterRead(103, 39, 'Vendor State', data.vendorState, 'uint16');
577
+ this.logRegisterRead(103, 40, 'Events', data.events, 'bitfield32');
578
+ this.logRegisterRead(103, 42, 'Events2', data.events2, 'bitfield32');
579
+ this.logRegisterRead(103, 44, 'Vendor Events 1', data.vendorEvents1, 'bitfield32');
580
+ this.logRegisterRead(103, 46, 'Vendor Events 2', data.vendorEvents2, 'bitfield32');
581
+ this.logRegisterRead(103, 48, 'Vendor Events 3', data.vendorEvents3, 'bitfield32');
582
+ this.logRegisterRead(103, 50, 'Vendor Events 4', data.vendorEvents4, 'bitfield32');
594
583
  // Read AC Energy (32-bit accumulator) - Offset 24-25
595
- const acEnergyAddr = baseAddr + 24;
596
- const acEnergy = await this.readRegisterValue(acEnergyAddr, 2, 'uint32');
584
+ const acEnergy = await this.readRegisterValue(baseAddr + 24, 2, 'uint32');
585
+ this.logRegisterRead(103, 24, 'AC Energy', acEnergy, 'acc32');
597
586
  data.acEnergy = !this.isUnimplementedValue(acEnergy, 'acc32')
598
- ? acEnergy * Math.pow(10, scaleFactors.WH_SF) // Regular number with scale factor
587
+ ? acEnergy * Math.pow(10, scaleFactors.WH_SF)
599
588
  : undefined;
600
589
  return data;
601
590
  }
@@ -623,41 +612,32 @@ export class SunspecModbusClient {
623
612
  DCV_SF: await this.readRegisterValue(baseAddr + 19, 1, 'int16'),
624
613
  DCW_SF: await this.readRegisterValue(baseAddr + 21, 1, 'int16')
625
614
  };
626
- console.log('Single-Phase Inverter Scale Factors:', JSON.stringify(scaleFactors, null, 2));
627
- // Read raw values with logging
628
- const acCurrentAddr = baseAddr + 2;
629
- const acCurrentRaw = await this.readRegisterValue(acCurrentAddr, 1, 'uint16');
630
- console.log(`AC Current: address=${acCurrentAddr}, raw=0x${acCurrentRaw.toString(16).toUpperCase()} (${acCurrentRaw})`);
631
- const voltageAddr = baseAddr + 7;
632
- const voltageRaw = await this.readRegisterValue(voltageAddr, 1, 'uint16');
633
- console.log(`AC Voltage: address=${voltageAddr}, raw=0x${voltageRaw.toString(16).toUpperCase()} (${voltageRaw})`);
634
- const acPowerAddr = baseAddr + 9;
635
- const acPowerRaw = await this.readRegisterValue(acPowerAddr, 1, 'int16');
636
- console.log(`AC Power: address=${acPowerAddr}, raw=0x${acPowerRaw.toString(16).toUpperCase()} (${acPowerRaw}), SF=${scaleFactors.W_SF}`);
637
- const freqAddr = baseAddr + 11;
638
- const freqRaw = await this.readRegisterValue(freqAddr, 1, 'uint16');
639
- console.log(`Frequency: address=${freqAddr}, raw=0x${freqRaw.toString(16).toUpperCase()} (${freqRaw})`);
640
- const dcCurrentAddr = baseAddr + 14;
641
- const dcCurrentRaw = await this.readRegisterValue(dcCurrentAddr, 1, 'uint16');
642
- console.log(`DC Current: address=${dcCurrentAddr}, raw=0x${dcCurrentRaw.toString(16).toUpperCase()} (${dcCurrentRaw})`);
643
- const dcVoltageAddr = baseAddr + 15;
644
- const dcVoltageRaw = await this.readRegisterValue(dcVoltageAddr, 1, 'uint16');
645
- console.log(`DC Voltage: address=${dcVoltageAddr}, raw=0x${dcVoltageRaw.toString(16).toUpperCase()} (${dcVoltageRaw})`);
646
- const dcPowerAddr = baseAddr + 20;
647
- const dcPowerRaw = await this.readRegisterValue(dcPowerAddr, 1, 'int16');
648
- console.log(`DC Power: address=${dcPowerAddr}, raw=0x${dcPowerRaw.toString(16).toUpperCase()} (${dcPowerRaw}), SF=${scaleFactors.DCW_SF}`);
649
- const stateAddr = baseAddr + 24;
650
- const stateRaw = await this.readRegisterValue(stateAddr, 1, 'uint16');
651
- console.log(`Operating State: address=${stateAddr}, raw=0x${stateRaw.toString(16).toUpperCase()} (${stateRaw})`);
615
+ this.logRegisterRead(101, 6, 'A_SF', scaleFactors.A_SF, 'int16');
616
+ this.logRegisterRead(101, 13, 'V_SF', scaleFactors.V_SF, 'int16');
617
+ this.logRegisterRead(101, 10, 'W_SF', scaleFactors.W_SF, 'int16');
618
+ this.logRegisterRead(101, 12, 'Hz_SF', scaleFactors.Hz_SF, 'int16');
619
+ this.logRegisterRead(101, 18, 'DCA_SF', scaleFactors.DCA_SF, 'int16');
620
+ this.logRegisterRead(101, 19, 'DCV_SF', scaleFactors.DCV_SF, 'int16');
621
+ this.logRegisterRead(101, 21, 'DCW_SF', scaleFactors.DCW_SF, 'int16');
622
+ // Read raw values
623
+ const acCurrentRaw = await this.readRegisterValue(baseAddr + 2, 1, 'uint16');
624
+ const voltageRaw = await this.readRegisterValue(baseAddr + 7, 1, 'uint16');
625
+ const acPowerRaw = await this.readRegisterValue(baseAddr + 9, 1, 'int16');
626
+ const freqRaw = await this.readRegisterValue(baseAddr + 11, 1, 'uint16');
627
+ const dcCurrentRaw = await this.readRegisterValue(baseAddr + 14, 1, 'uint16');
628
+ const dcVoltageRaw = await this.readRegisterValue(baseAddr + 15, 1, 'uint16');
629
+ const dcPowerRaw = await this.readRegisterValue(baseAddr + 20, 1, 'int16');
630
+ const stateRaw = await this.readRegisterValue(baseAddr + 24, 1, 'uint16');
631
+ this.logRegisterRead(101, 24, 'Operating State', stateRaw, 'enum16');
652
632
  return {
653
633
  blockNumber: 101,
654
- voltageAN: this.applyScaleFactor(voltageRaw, scaleFactors.V_SF, 'uint16', 'Single Phase Voltage'),
655
- acCurrent: this.applyScaleFactor(acCurrentRaw, scaleFactors.A_SF, 'uint16', 'Single Phase AC Current'),
656
- acPower: this.applyScaleFactor(acPowerRaw, scaleFactors.W_SF, 'int16', 'Single Phase AC Power'),
657
- frequency: this.applyScaleFactor(freqRaw, scaleFactors.Hz_SF, 'uint16', 'Single Phase Frequency'),
658
- dcCurrent: this.applyScaleFactor(dcCurrentRaw, scaleFactors.DCA_SF, 'uint16', 'Single Phase DC Current'),
659
- dcVoltage: this.applyScaleFactor(dcVoltageRaw, scaleFactors.DCV_SF, 'uint16', 'Single Phase DC Voltage'),
660
- dcPower: this.applyScaleFactor(dcPowerRaw, scaleFactors.DCW_SF, 'int16', 'Single Phase DC Power'),
634
+ voltageAN: this.applyScaleFactor(voltageRaw, scaleFactors.V_SF, 'uint16', 'Voltage AN', 7, 101),
635
+ acCurrent: this.applyScaleFactor(acCurrentRaw, scaleFactors.A_SF, 'uint16', 'AC Current', 2, 101),
636
+ acPower: this.applyScaleFactor(acPowerRaw, scaleFactors.W_SF, 'int16', 'AC Power', 9, 101),
637
+ frequency: this.applyScaleFactor(freqRaw, scaleFactors.Hz_SF, 'uint16', 'Frequency', 11, 101),
638
+ dcCurrent: this.applyScaleFactor(dcCurrentRaw, scaleFactors.DCA_SF, 'uint16', 'DC Current', 14, 101),
639
+ dcVoltage: this.applyScaleFactor(dcVoltageRaw, scaleFactors.DCV_SF, 'uint16', 'DC Voltage', 15, 101),
640
+ dcPower: this.applyScaleFactor(dcPowerRaw, scaleFactors.DCW_SF, 'int16', 'DC Power', 20, 101),
661
641
  operatingState: stateRaw
662
642
  };
663
643
  }
@@ -684,24 +664,55 @@ export class SunspecModbusClient {
684
664
  DCW_SF: await this.readRegisterValue(baseAddr + 31, 1, 'int16'), // Offset 31
685
665
  Tmp_SF: await this.readRegisterValue(baseAddr + 36, 1, 'int16') // Offset 36
686
666
  };
687
- console.log('Inverter Scale Factors:', JSON.stringify(scaleFactors, null, 2));
667
+ this.logRegisterRead(103, 6, 'A_SF', scaleFactors.A_SF, 'int16');
668
+ this.logRegisterRead(103, 13, 'V_SF', scaleFactors.V_SF, 'int16');
669
+ this.logRegisterRead(103, 15, 'W_SF', scaleFactors.W_SF, 'int16');
670
+ this.logRegisterRead(103, 17, 'Hz_SF', scaleFactors.Hz_SF, 'int16');
671
+ this.logRegisterRead(103, 19, 'VA_SF', scaleFactors.VA_SF, 'int16');
672
+ this.logRegisterRead(103, 21, 'VAr_SF', scaleFactors.VAr_SF, 'int16');
673
+ this.logRegisterRead(103, 23, 'PF_SF', scaleFactors.PF_SF, 'int16');
674
+ this.logRegisterRead(103, 26, 'WH_SF', scaleFactors.WH_SF, 'int16');
675
+ this.logRegisterRead(103, 28, 'DCA_SF', scaleFactors.DCA_SF, 'int16');
676
+ this.logRegisterRead(103, 29, 'DCV_SF', scaleFactors.DCV_SF, 'int16');
677
+ this.logRegisterRead(103, 31, 'DCW_SF', scaleFactors.DCW_SF, 'int16');
678
+ this.logRegisterRead(103, 36, 'Tmp_SF', scaleFactors.Tmp_SF, 'int16');
688
679
  return scaleFactors;
689
680
  }
690
681
  /**
691
682
  * Apply scale factor to a value
692
683
  * Returns undefined if the value is unimplemented or scale factor is out of range
693
684
  */
694
- applyScaleFactor(value, scaleFactor, dataType = 'uint16', fieldName) {
685
+ applyScaleFactor(value, scaleFactor, dataType = 'uint16', fieldName, offset, modelId) {
695
686
  // Check for unimplemented values
696
687
  if (this.isUnimplementedValue(value, dataType)) {
697
688
  return undefined;
698
689
  }
699
690
  const scaledValue = value * Math.pow(10, scaleFactor);
700
- // Log the raw and scaled values in decimal format
701
- const fieldPrefix = fieldName ? `${fieldName}: ` : '';
702
- console.log(`Scale Factor Applied - ${fieldPrefix}raw=${value} (decimal), SF=${scaleFactor}, scaled=${scaledValue}`);
691
+ // Log the raw and scaled values
692
+ if (offset !== undefined && modelId !== undefined && fieldName) {
693
+ const hex = value >= 0 ? value.toString(16).toUpperCase() : (value >>> 0).toString(16).toUpperCase();
694
+ console.log(`[Model ${modelId}] offset ${offset}: ${fieldName} raw=${value} (0x${hex}), SF=${scaleFactor}, scaled=${scaledValue}`);
695
+ }
696
+ else {
697
+ const fieldPrefix = fieldName ? `${fieldName}: ` : '';
698
+ console.log(`Scale Factor Applied - ${fieldPrefix}raw=${value} (decimal), SF=${scaleFactor}, scaled=${scaledValue}`);
699
+ }
703
700
  return scaledValue;
704
701
  }
702
+ logRegisterRead(modelId, offset, fieldName, rawValue, dataType) {
703
+ const typeInfo = dataType ? ` (${dataType})` : '';
704
+ if (rawValue === undefined) {
705
+ console.log(`[Model ${modelId}] offset ${offset}: ${fieldName} = -${typeInfo}`);
706
+ return;
707
+ }
708
+ if (typeof rawValue === 'number') {
709
+ const hex = rawValue >= 0 ? rawValue.toString(16).toUpperCase() : (rawValue >>> 0).toString(16).toUpperCase();
710
+ console.log(`[Model ${modelId}] offset ${offset}: ${fieldName} = ${rawValue} (0x${hex})${typeInfo}`);
711
+ }
712
+ else {
713
+ console.log(`[Model ${modelId}] offset ${offset}: ${fieldName} = "${rawValue}"${typeInfo}`);
714
+ }
715
+ }
705
716
  /**
706
717
  * Read MPPT Scale Factors for a specific module
707
718
  * Returns the scale factors for DC Current, DC Voltage, DC Power, and DC Energy
@@ -735,10 +746,10 @@ export class SunspecModbusClient {
735
746
  DCW_SF, // Power Scale Factor
736
747
  DCWH_SF, // Energy Scale Factor
737
748
  };
738
- console.log(` DCA_SF (Current): ${DCA_SF} at register ${moduleAddr + 2}`);
739
- console.log(` DCV_SF (Voltage): ${DCV_SF} at register ${moduleAddr + 3}`);
740
- console.log(` DCW_SF (Power): ${DCW_SF} at register ${moduleAddr + 4}`);
741
- console.log(` DCWH_SF (Energy): ${DCWH_SF} at register ${moduleAddr + 5}`);
749
+ this.logRegisterRead(160, 2, 'DCA_SF', DCA_SF, 'int16');
750
+ this.logRegisterRead(160, 3, 'DCV_SF', DCV_SF, 'int16');
751
+ this.logRegisterRead(160, 4, 'DCW_SF', DCW_SF, 'int16');
752
+ this.logRegisterRead(160, 5, 'DCWH_SF', DCWH_SF, 'int16');
742
753
  return scaleFactors;
743
754
  }
744
755
  catch (error) {
@@ -768,7 +779,6 @@ export class SunspecModbusClient {
768
779
  console.error(`Failed to read scale factors for MPPT module ${moduleId}`);
769
780
  return null;
770
781
  }
771
- console.log(`MPPT Module ${moduleId} Scale Factors:`, JSON.stringify(scaleFactors, null, 2));
772
782
  const id = await this.readRegisterValue(moduleAddr, 1, 'uint16');
773
783
  const idString = await this.readRegisterValue(moduleAddr + 1, 8, 'string');
774
784
  const dcCurrentRaw = await this.readRegisterValue(moduleAddr + 9, 1, 'uint16');
@@ -777,6 +787,8 @@ export class SunspecModbusClient {
777
787
  const dcEnergyRaw = await this.readRegisterValue(moduleAddr + 12, 2, 'uint32');
778
788
  const temperatureRaw = await this.readRegisterValue(moduleAddr + 16, 1, 'int16');
779
789
  const dcst = await this.readRegisterValue(moduleAddr + 17, 1, 'uint16');
790
+ this.logRegisterRead(160, 0, `MPPT ${moduleId} ID`, id, 'uint16');
791
+ this.logRegisterRead(160, 1, `MPPT ${moduleId} String ID`, idString, 'string');
780
792
  // Map the DC module state to human-readable name
781
793
  // Check if this module is actually implemented/connected
782
794
  // If all key values are unimplemented, this module doesn't exist
@@ -790,24 +802,28 @@ export class SunspecModbusClient {
790
802
  // Note: There appears to be a temperature scale factor in the original model,
791
803
  // but it's not in the current register map. We'll apply a default scale factor.
792
804
  const temperatureScaleFactor = -1; // Common default for temperature readings
805
+ this.logRegisterRead(160, 12, `MPPT ${moduleId} DC Energy`, dcEnergyRaw, 'acc32');
806
+ const timestampRaw = await this.readRegisterValue(moduleAddr + 14, 2, 'uint32');
807
+ this.logRegisterRead(160, 14, `MPPT ${moduleId} Timestamp`, timestampRaw, 'uint32');
808
+ this.logRegisterRead(160, 17, `MPPT ${moduleId} Operating State`, dcst, 'enum16');
793
809
  const data = {
794
810
  blockNumber: 160,
795
811
  blockAddress: model.address,
796
812
  blockLength: model.length,
797
813
  id: id,
798
814
  stringId: idString,
799
- dcCurrent: this.applyScaleFactor(dcCurrentRaw, scaleFactors.DCA_SF, 'uint16', `MPPT ${moduleId} DC Current`),
815
+ dcCurrent: this.applyScaleFactor(dcCurrentRaw, scaleFactors.DCA_SF, 'uint16', `MPPT ${moduleId} DC Current`, 9, 160),
800
816
  dcCurrentSF: scaleFactors.DCA_SF,
801
- dcVoltage: this.applyScaleFactor(dcVoltageRaw, scaleFactors.DCV_SF, 'uint16', `MPPT ${moduleId} DC Voltage`),
817
+ dcVoltage: this.applyScaleFactor(dcVoltageRaw, scaleFactors.DCV_SF, 'uint16', `MPPT ${moduleId} DC Voltage`, 10, 160),
802
818
  dcVoltageSF: scaleFactors.DCV_SF,
803
- dcPower: this.applyScaleFactor(dcPowerRaw, scaleFactors.DCW_SF, 'uint16', `MPPT ${moduleId} DC Power`),
819
+ dcPower: this.applyScaleFactor(dcPowerRaw, scaleFactors.DCW_SF, 'uint16', `MPPT ${moduleId} DC Power`, 11, 160),
804
820
  dcPowerSF: scaleFactors.DCW_SF,
805
821
  dcEnergy: !this.isUnimplementedValue(dcEnergyRaw, 'acc32')
806
- ? dcEnergyRaw * Math.pow(10, scaleFactors.DCWH_SF) // Regular number with scale factor
822
+ ? dcEnergyRaw * Math.pow(10, scaleFactors.DCWH_SF)
807
823
  : undefined,
808
824
  dcEnergySF: scaleFactors.DCWH_SF,
809
- timestamp: await this.readRegisterValue(moduleAddr + 14, 2, 'uint32'),
810
- temperature: this.applyScaleFactor(temperatureRaw, temperatureScaleFactor, 'int16', `MPPT ${moduleId} Temperature`),
825
+ timestamp: timestampRaw,
826
+ temperature: this.applyScaleFactor(temperatureRaw, temperatureScaleFactor, 'int16', `MPPT ${moduleId} Temperature`, 16, 160),
811
827
  temperatureSF: temperatureScaleFactor,
812
828
  operatingState: dcst,
813
829
  };
@@ -900,6 +916,238 @@ export class SunspecModbusClient {
900
916
  return `UNKNOWN(${state})`;
901
917
  }
902
918
  }
919
+ /**
920
+ * Map battery type to human-readable name (Model 802)
921
+ */
922
+ mapBatteryType(typ) {
923
+ switch (typ) {
924
+ case SunspecBatteryType.NOT_APPLICABLE_UNKNOWN:
925
+ return "NOT_APPLICABLE_UNKNOWN";
926
+ case SunspecBatteryType.LEAD_ACID:
927
+ return "LEAD_ACID";
928
+ case SunspecBatteryType.NICKEL_METAL_HYDRIDE:
929
+ return "NICKEL_METAL_HYDRIDE";
930
+ case SunspecBatteryType.NICKEL_CADMIUM:
931
+ return "NICKEL_CADMIUM";
932
+ case SunspecBatteryType.LITHIUM_ION:
933
+ return "LITHIUM_ION";
934
+ case SunspecBatteryType.CARBON_ZINC:
935
+ return "CARBON_ZINC";
936
+ case SunspecBatteryType.ZINC_CHLORIDE:
937
+ return "ZINC_CHLORIDE";
938
+ case SunspecBatteryType.ALKALINE:
939
+ return "ALKALINE";
940
+ case SunspecBatteryType.RECHARGEABLE_ALKALINE:
941
+ return "RECHARGEABLE_ALKALINE";
942
+ case SunspecBatteryType.SODIUM_SULFUR:
943
+ return "SODIUM_SULFUR";
944
+ case SunspecBatteryType.FLOW:
945
+ return "FLOW";
946
+ case SunspecBatteryType.SUPER_CAPACITOR:
947
+ return "SUPER_CAPACITOR";
948
+ case SunspecBatteryType.OTHER:
949
+ return "OTHER";
950
+ default:
951
+ if (this.isUnimplementedValue(typ, 'enum16')) {
952
+ return "NOT_IMPLEMENTED";
953
+ }
954
+ return `UNKNOWN(${typ})`;
955
+ }
956
+ }
957
+ /**
958
+ * Map battery bank state to human-readable name (Model 802)
959
+ */
960
+ mapBatteryBankState(state) {
961
+ switch (state) {
962
+ case SunspecBatteryBankState.DISCONNECTED:
963
+ return "DISCONNECTED";
964
+ case SunspecBatteryBankState.INITIALIZING:
965
+ return "INITIALIZING";
966
+ case SunspecBatteryBankState.CONNECTED:
967
+ return "CONNECTED";
968
+ case SunspecBatteryBankState.STANDBY:
969
+ return "STANDBY";
970
+ case SunspecBatteryBankState.SOC_PROTECTION:
971
+ return "SOC_PROTECTION";
972
+ case SunspecBatteryBankState.SUSPENDING:
973
+ return "SUSPENDING";
974
+ case SunspecBatteryBankState.FAULT:
975
+ return "FAULT";
976
+ default:
977
+ if (this.isUnimplementedValue(state, 'enum16')) {
978
+ return "NOT_IMPLEMENTED";
979
+ }
980
+ return `UNKNOWN(${state})`;
981
+ }
982
+ }
983
+ /**
984
+ * Read Model 802 scale factors (offsets 52-63)
985
+ */
986
+ async readBatteryBaseScaleFactors(baseAddr) {
987
+ const scaleFactors = {
988
+ AHRtg_SF: await this.readRegisterValue(baseAddr + 52, 1, 'int16'),
989
+ WHRtg_SF: await this.readRegisterValue(baseAddr + 53, 1, 'int16'),
990
+ WChaDisChaMax_SF: await this.readRegisterValue(baseAddr + 54, 1, 'int16'),
991
+ DisChaRte_SF: await this.readRegisterValue(baseAddr + 55, 1, 'int16'),
992
+ SoC_SF: await this.readRegisterValue(baseAddr + 56, 1, 'int16'),
993
+ DoD_SF: await this.readRegisterValue(baseAddr + 57, 1, 'int16'),
994
+ SoH_SF: await this.readRegisterValue(baseAddr + 58, 1, 'int16'),
995
+ V_SF: await this.readRegisterValue(baseAddr + 59, 1, 'int16'),
996
+ CellV_SF: await this.readRegisterValue(baseAddr + 60, 1, 'int16'),
997
+ A_SF: await this.readRegisterValue(baseAddr + 61, 1, 'int16'),
998
+ AMax_SF: await this.readRegisterValue(baseAddr + 62, 1, 'int16'),
999
+ W_SF: await this.readRegisterValue(baseAddr + 63, 1, 'int16'),
1000
+ };
1001
+ this.logRegisterRead(802, 52, 'AHRtg_SF', scaleFactors.AHRtg_SF, 'int16');
1002
+ this.logRegisterRead(802, 53, 'WHRtg_SF', scaleFactors.WHRtg_SF, 'int16');
1003
+ this.logRegisterRead(802, 54, 'WChaDisChaMax_SF', scaleFactors.WChaDisChaMax_SF, 'int16');
1004
+ this.logRegisterRead(802, 55, 'DisChaRte_SF', scaleFactors.DisChaRte_SF, 'int16');
1005
+ this.logRegisterRead(802, 56, 'SoC_SF', scaleFactors.SoC_SF, 'int16');
1006
+ this.logRegisterRead(802, 57, 'DoD_SF', scaleFactors.DoD_SF, 'int16');
1007
+ this.logRegisterRead(802, 58, 'SoH_SF', scaleFactors.SoH_SF, 'int16');
1008
+ this.logRegisterRead(802, 59, 'V_SF', scaleFactors.V_SF, 'int16');
1009
+ this.logRegisterRead(802, 60, 'CellV_SF', scaleFactors.CellV_SF, 'int16');
1010
+ this.logRegisterRead(802, 61, 'A_SF', scaleFactors.A_SF, 'int16');
1011
+ this.logRegisterRead(802, 62, 'AMax_SF', scaleFactors.AMax_SF, 'int16');
1012
+ this.logRegisterRead(802, 63, 'W_SF', scaleFactors.W_SF, 'int16');
1013
+ return scaleFactors;
1014
+ }
1015
+ /**
1016
+ * Read battery base data from Model 802 (Battery Base)
1017
+ */
1018
+ async readBatteryBaseData() {
1019
+ const model = this.findModel(SunspecModelId.BatteryBase);
1020
+ if (!model) {
1021
+ console.log('Battery Base model 802 not found');
1022
+ return null;
1023
+ }
1024
+ const baseAddr = model.address;
1025
+ console.log(`Reading Battery Base Data from Model 802 at base address: ${baseAddr}`);
1026
+ try {
1027
+ // Read scale factors first (offsets 52-63)
1028
+ const sf = await this.readBatteryBaseScaleFactors(baseAddr);
1029
+ // Read raw values
1030
+ const ahRtgRaw = await this.readRegisterValue(baseAddr + 2, 1, 'uint16');
1031
+ const whRtgRaw = await this.readRegisterValue(baseAddr + 3, 1, 'uint16');
1032
+ const wChaRteMaxRaw = await this.readRegisterValue(baseAddr + 4, 1, 'uint16');
1033
+ const wDisChaRteMaxRaw = await this.readRegisterValue(baseAddr + 5, 1, 'uint16');
1034
+ const disChaRteRaw = await this.readRegisterValue(baseAddr + 6, 1, 'uint16');
1035
+ const soCMaxRaw = await this.readRegisterValue(baseAddr + 7, 1, 'uint16');
1036
+ const soCMinRaw = await this.readRegisterValue(baseAddr + 8, 1, 'uint16');
1037
+ const soCRsvMaxRaw = await this.readRegisterValue(baseAddr + 9, 1, 'uint16');
1038
+ const soCRsvMinRaw = await this.readRegisterValue(baseAddr + 10, 1, 'uint16');
1039
+ const soCRaw = await this.readRegisterValue(baseAddr + 11, 1, 'uint16');
1040
+ const doDRaw = await this.readRegisterValue(baseAddr + 12, 1, 'uint16');
1041
+ const soHRaw = await this.readRegisterValue(baseAddr + 13, 1, 'uint16');
1042
+ const nCycRaw = await this.readRegisterValue(baseAddr + 14, 2, 'uint32');
1043
+ const chaStRaw = await this.readRegisterValue(baseAddr + 16, 1, 'uint16');
1044
+ const locRemCtlRaw = await this.readRegisterValue(baseAddr + 17, 1, 'uint16');
1045
+ const typRaw = await this.readRegisterValue(baseAddr + 21, 1, 'uint16');
1046
+ const stateRaw = await this.readRegisterValue(baseAddr + 22, 1, 'uint16');
1047
+ const evt1Raw = await this.readRegisterValue(baseAddr + 26, 2, 'uint32');
1048
+ const evt2Raw = await this.readRegisterValue(baseAddr + 28, 2, 'uint32');
1049
+ const evtVnd1Raw = await this.readRegisterValue(baseAddr + 30, 2, 'uint32');
1050
+ const evtVnd2Raw = await this.readRegisterValue(baseAddr + 32, 2, 'uint32');
1051
+ const vRaw = await this.readRegisterValue(baseAddr + 34, 1, 'uint16');
1052
+ const vMaxRaw = await this.readRegisterValue(baseAddr + 35, 1, 'uint16');
1053
+ const vMinRaw = await this.readRegisterValue(baseAddr + 36, 1, 'uint16');
1054
+ const cellVMaxRaw = await this.readRegisterValue(baseAddr + 37, 1, 'uint16');
1055
+ const cellVMaxStrRaw = await this.readRegisterValue(baseAddr + 38, 1, 'uint16');
1056
+ const cellVMaxModRaw = await this.readRegisterValue(baseAddr + 39, 1, 'uint16');
1057
+ const cellVMinRaw = await this.readRegisterValue(baseAddr + 40, 1, 'uint16');
1058
+ const cellVMinStrRaw = await this.readRegisterValue(baseAddr + 41, 1, 'uint16');
1059
+ const cellVMinModRaw = await this.readRegisterValue(baseAddr + 42, 1, 'uint16');
1060
+ const cellVAvgRaw = await this.readRegisterValue(baseAddr + 43, 1, 'uint16');
1061
+ const aRaw = await this.readRegisterValue(baseAddr + 44, 1, 'int16');
1062
+ const aChaMaxRaw = await this.readRegisterValue(baseAddr + 45, 1, 'uint16');
1063
+ const aDisChaMaxRaw = await this.readRegisterValue(baseAddr + 46, 1, 'uint16');
1064
+ const wRaw = await this.readRegisterValue(baseAddr + 47, 1, 'int16');
1065
+ const reqInvStateRaw = await this.readRegisterValue(baseAddr + 48, 1, 'uint16');
1066
+ const reqWRaw = await this.readRegisterValue(baseAddr + 49, 1, 'int16');
1067
+ const setOpRaw = await this.readRegisterValue(baseAddr + 50, 1, 'uint16');
1068
+ const setInvStateRaw = await this.readRegisterValue(baseAddr + 51, 1, 'uint16');
1069
+ // Map enum fields
1070
+ const chaStName = this.mapBatteryChargeState(chaStRaw);
1071
+ const typName = this.mapBatteryType(typRaw);
1072
+ const stateName = this.mapBatteryBankState(stateRaw);
1073
+ // Log non-scaled fields
1074
+ this.logRegisterRead(802, 14, 'nCyc', nCycRaw, 'uint32');
1075
+ this.logRegisterRead(802, 16, 'chaSt', chaStRaw, 'enum16');
1076
+ this.logRegisterRead(802, 17, 'locRemCtl', locRemCtlRaw, 'enum16');
1077
+ this.logRegisterRead(802, 21, 'typ', typRaw, 'enum16');
1078
+ this.logRegisterRead(802, 22, 'state', stateRaw, 'enum16');
1079
+ this.logRegisterRead(802, 26, 'evt1', evt1Raw, 'bitfield32');
1080
+ this.logRegisterRead(802, 28, 'evt2', evt2Raw, 'bitfield32');
1081
+ this.logRegisterRead(802, 30, 'evtVnd1', evtVnd1Raw, 'bitfield32');
1082
+ this.logRegisterRead(802, 32, 'evtVnd2', evtVnd2Raw, 'bitfield32');
1083
+ this.logRegisterRead(802, 38, 'cellVMaxStr', cellVMaxStrRaw, 'uint16');
1084
+ this.logRegisterRead(802, 39, 'cellVMaxMod', cellVMaxModRaw, 'uint16');
1085
+ this.logRegisterRead(802, 41, 'cellVMinStr', cellVMinStrRaw, 'uint16');
1086
+ this.logRegisterRead(802, 42, 'cellVMinMod', cellVMinModRaw, 'uint16');
1087
+ this.logRegisterRead(802, 48, 'reqInvState', reqInvStateRaw, 'enum16');
1088
+ this.logRegisterRead(802, 50, 'setOp', setOpRaw, 'enum16');
1089
+ this.logRegisterRead(802, 51, 'setInvState', setInvStateRaw, 'enum16');
1090
+ const data = {
1091
+ blockNumber: 802,
1092
+ blockAddress: model.address,
1093
+ blockLength: model.length,
1094
+ // Nameplate
1095
+ ahRtg: this.applyScaleFactor(ahRtgRaw, sf.AHRtg_SF, 'uint16', 'AH Rating', 2, 802),
1096
+ whRtg: this.applyScaleFactor(whRtgRaw, sf.WHRtg_SF, 'uint16', 'WH Rating', 3, 802),
1097
+ wChaRteMax: this.applyScaleFactor(wChaRteMaxRaw, sf.WChaDisChaMax_SF, 'uint16', 'Max Charge Rate', 4, 802),
1098
+ wDisChaRteMax: this.applyScaleFactor(wDisChaRteMaxRaw, sf.WChaDisChaMax_SF, 'uint16', 'Max Discharge Rate', 5, 802),
1099
+ // SoC/Health
1100
+ disChaRte: this.applyScaleFactor(disChaRteRaw, sf.DisChaRte_SF, 'uint16', 'Self Discharge Rate', 6, 802),
1101
+ soCMax: this.applyScaleFactor(soCMaxRaw, sf.SoC_SF, 'uint16', 'SoC Max', 7, 802),
1102
+ soCMin: this.applyScaleFactor(soCMinRaw, sf.SoC_SF, 'uint16', 'SoC Min', 8, 802),
1103
+ soCRsvMax: this.applyScaleFactor(soCRsvMaxRaw, sf.SoC_SF, 'uint16', 'SoC Reserve Max', 9, 802),
1104
+ soCRsvMin: this.applyScaleFactor(soCRsvMinRaw, sf.SoC_SF, 'uint16', 'SoC Reserve Min', 10, 802),
1105
+ soC: this.applyScaleFactor(soCRaw, sf.SoC_SF, 'uint16', 'State of Charge', 11, 802),
1106
+ doD: this.applyScaleFactor(doDRaw, sf.DoD_SF, 'uint16', 'Depth of Discharge', 12, 802),
1107
+ soH: this.applyScaleFactor(soHRaw, sf.SoH_SF, 'uint16', 'State of Health', 13, 802),
1108
+ // Status
1109
+ nCyc: !this.isUnimplementedValue(nCycRaw, 'uint32') ? nCycRaw : undefined,
1110
+ chaSt: !this.isUnimplementedValue(chaStRaw, 'enum16') ? chaStRaw : undefined,
1111
+ chaStName,
1112
+ locRemCtl: !this.isUnimplementedValue(locRemCtlRaw, 'enum16') ? locRemCtlRaw : undefined,
1113
+ typ: !this.isUnimplementedValue(typRaw, 'enum16') ? typRaw : undefined,
1114
+ typName,
1115
+ state: !this.isUnimplementedValue(stateRaw, 'enum16') ? stateRaw : undefined,
1116
+ stateName,
1117
+ // Events
1118
+ evt1: !this.isUnimplementedValue(evt1Raw, 'bitfield32') ? evt1Raw : undefined,
1119
+ evt2: !this.isUnimplementedValue(evt2Raw, 'bitfield32') ? evt2Raw : undefined,
1120
+ evtVnd1: !this.isUnimplementedValue(evtVnd1Raw, 'bitfield32') ? evtVnd1Raw : undefined,
1121
+ evtVnd2: !this.isUnimplementedValue(evtVnd2Raw, 'bitfield32') ? evtVnd2Raw : undefined,
1122
+ // Voltage
1123
+ v: this.applyScaleFactor(vRaw, sf.V_SF, 'uint16', 'Battery Voltage', 34, 802),
1124
+ vMax: this.applyScaleFactor(vMaxRaw, sf.V_SF, 'uint16', 'Max Battery Voltage', 35, 802),
1125
+ vMin: this.applyScaleFactor(vMinRaw, sf.V_SF, 'uint16', 'Min Battery Voltage', 36, 802),
1126
+ cellVMax: this.applyScaleFactor(cellVMaxRaw, sf.CellV_SF, 'uint16', 'Max Cell Voltage', 37, 802),
1127
+ cellVMaxStr: !this.isUnimplementedValue(cellVMaxStrRaw, 'uint16') ? cellVMaxStrRaw : undefined,
1128
+ cellVMaxMod: !this.isUnimplementedValue(cellVMaxModRaw, 'uint16') ? cellVMaxModRaw : undefined,
1129
+ cellVMin: this.applyScaleFactor(cellVMinRaw, sf.CellV_SF, 'uint16', 'Min Cell Voltage', 40, 802),
1130
+ cellVMinStr: !this.isUnimplementedValue(cellVMinStrRaw, 'uint16') ? cellVMinStrRaw : undefined,
1131
+ cellVMinMod: !this.isUnimplementedValue(cellVMinModRaw, 'uint16') ? cellVMinModRaw : undefined,
1132
+ cellVAvg: this.applyScaleFactor(cellVAvgRaw, sf.CellV_SF, 'uint16', 'Avg Cell Voltage', 43, 802),
1133
+ // Current
1134
+ a: this.applyScaleFactor(aRaw, sf.A_SF, 'int16', 'Battery Current', 44, 802),
1135
+ aChaMax: this.applyScaleFactor(aChaMaxRaw, sf.AMax_SF, 'uint16', 'Max Charge Current', 45, 802),
1136
+ aDisChaMax: this.applyScaleFactor(aDisChaMaxRaw, sf.AMax_SF, 'uint16', 'Max Discharge Current', 46, 802),
1137
+ // Power
1138
+ w: this.applyScaleFactor(wRaw, sf.W_SF, 'int16', 'Battery Power', 47, 802),
1139
+ reqInvState: !this.isUnimplementedValue(reqInvStateRaw, 'enum16') ? reqInvStateRaw : undefined,
1140
+ reqW: this.applyScaleFactor(reqWRaw, sf.W_SF, 'int16', 'Requested Power', 49, 802),
1141
+ setOp: !this.isUnimplementedValue(setOpRaw, 'enum16') ? setOpRaw : undefined,
1142
+ setInvState: !this.isUnimplementedValue(setInvStateRaw, 'enum16') ? setInvStateRaw : undefined,
1143
+ };
1144
+ return data;
1145
+ }
1146
+ catch (error) {
1147
+ console.error(`Error reading battery base data: ${error}`);
1148
+ return null;
1149
+ }
1150
+ }
903
1151
  /**
904
1152
  * Read battery data from Model 124 (Basic Storage Controls)
905
1153
  */
@@ -934,7 +1182,14 @@ export class SunspecModbusClient {
934
1182
  InBatV_SF: await this.readRegisterValue(baseAddr + 24, 1, 'int16'),
935
1183
  InOutWRte_SF: await this.readRegisterValue(baseAddr + 25, 1, 'int16')
936
1184
  };
937
- console.log('Battery Scale Factors:', JSON.stringify(scaleFactors, null, 2));
1185
+ this.logRegisterRead(124, 18, 'WChaMax_SF', scaleFactors.WChaMax_SF, 'int16');
1186
+ this.logRegisterRead(124, 19, 'WChaDisChaGra_SF', scaleFactors.WChaDisChaGra_SF, 'int16');
1187
+ this.logRegisterRead(124, 20, 'VAChaMax_SF', scaleFactors.VAChaMax_SF, 'int16');
1188
+ this.logRegisterRead(124, 21, 'MinRsvPct_SF', scaleFactors.MinRsvPct_SF, 'int16');
1189
+ this.logRegisterRead(124, 22, 'ChaState_SF', scaleFactors.ChaState_SF, 'int16');
1190
+ this.logRegisterRead(124, 23, 'StorAval_SF', scaleFactors.StorAval_SF, 'int16');
1191
+ this.logRegisterRead(124, 24, 'InBatV_SF', scaleFactors.InBatV_SF, 'int16');
1192
+ this.logRegisterRead(124, 25, 'InOutWRte_SF', scaleFactors.InOutWRte_SF, 'int16');
938
1193
  // Read raw values
939
1194
  const wChaMaxRaw = await this.readRegisterValue(baseAddr + 2, 1, 'uint16');
940
1195
  const wChaGraRaw = await this.readRegisterValue(baseAddr + 3, 1, 'uint16');
@@ -952,43 +1207,42 @@ export class SunspecModbusClient {
952
1207
  const inOutWRteRvrtTmsRaw = await this.readRegisterValue(baseAddr + 15, 1, 'uint16');
953
1208
  const inOutWRteRmpTmsRaw = await this.readRegisterValue(baseAddr + 16, 1, 'uint16');
954
1209
  const chaGriSetRaw = await this.readRegisterValue(baseAddr + 17, 1, 'uint16');
955
- // Map charge state to human-readable name
1210
+ // Map charge state and log non-scaled fields
956
1211
  const chaStName = this.mapBatteryChargeState(chaStRaw);
957
- console.log(`Battery Charge State: ${chaStRaw} (${chaStName})`);
958
- // Log storage control mode
959
- if (!this.isUnimplementedValue(storCtlModRaw, 'bitfield16')) {
960
- const chargeEnabled = (storCtlModRaw & SunspecStorageControlMode.CHARGE) !== 0;
961
- const dischargeEnabled = (storCtlModRaw & SunspecStorageControlMode.DISCHARGE) !== 0;
962
- console.log(`Storage Control Mode: 0x${storCtlModRaw.toString(16)} (Charge: ${chargeEnabled}, Discharge: ${dischargeEnabled})`);
963
- }
1212
+ this.logRegisterRead(124, 5, 'storCtlMod', storCtlModRaw, 'bitfield16');
1213
+ this.logRegisterRead(124, 11, 'chaSt', chaStRaw, 'enum16');
1214
+ this.logRegisterRead(124, 14, 'inOutWRteWinTms', inOutWRteWinTmsRaw, 'uint16');
1215
+ this.logRegisterRead(124, 15, 'inOutWRteRvrtTms', inOutWRteRvrtTmsRaw, 'uint16');
1216
+ this.logRegisterRead(124, 16, 'inOutWRteRmpTms', inOutWRteRmpTmsRaw, 'uint16');
1217
+ this.logRegisterRead(124, 17, 'chaGriSet', chaGriSetRaw, 'enum16');
964
1218
  // Calculate actual values with scale factors
965
1219
  const data = {
966
1220
  blockNumber: 124,
967
1221
  blockAddress: model.address,
968
1222
  blockLength: model.length,
969
1223
  // Control settings
970
- wChaMax: this.applyScaleFactor(wChaMaxRaw, scaleFactors.WChaMax_SF, 'uint16', 'Max Charge Power'),
1224
+ wChaMax: this.applyScaleFactor(wChaMaxRaw, scaleFactors.WChaMax_SF, 'uint16', 'Max Charge Power', 2, 124),
971
1225
  wChaMaxSF: scaleFactors.WChaMax_SF,
972
- wChaGra: this.applyScaleFactor(wChaGraRaw, scaleFactors.WChaDisChaGra_SF, 'uint16', 'Charge Rate Gradient'),
973
- wDisChaGra: this.applyScaleFactor(wDisChaGraRaw, scaleFactors.WChaDisChaGra_SF, 'uint16', 'Discharge Rate Gradient'),
1226
+ wChaGra: this.applyScaleFactor(wChaGraRaw, scaleFactors.WChaDisChaGra_SF, 'uint16', 'Charge Rate Gradient', 3, 124),
1227
+ wDisChaGra: this.applyScaleFactor(wDisChaGraRaw, scaleFactors.WChaDisChaGra_SF, 'uint16', 'Discharge Rate Gradient', 4, 124),
974
1228
  wChaDisChaGraSF: scaleFactors.WChaDisChaGra_SF,
975
1229
  storCtlMod: !this.isUnimplementedValue(storCtlModRaw, 'bitfield16') ? storCtlModRaw : undefined,
976
- vaChaMax: this.applyScaleFactor(vaChaMaxRaw, scaleFactors.VAChaMax_SF, 'uint16', 'Max Charging VA'),
1230
+ vaChaMax: this.applyScaleFactor(vaChaMaxRaw, scaleFactors.VAChaMax_SF, 'uint16', 'Max Charging VA', 6, 124),
977
1231
  vaChaMaxSF: scaleFactors.VAChaMax_SF,
978
- minRsvPct: this.applyScaleFactor(minRsvPctRaw, scaleFactors.MinRsvPct_SF, 'uint16', 'Min Reserve Percent'),
1232
+ minRsvPct: this.applyScaleFactor(minRsvPctRaw, scaleFactors.MinRsvPct_SF, 'uint16', 'Min Reserve Percent', 7, 124),
979
1233
  minRsvPctSF: scaleFactors.MinRsvPct_SF,
980
1234
  // Status values
981
- chaState: this.applyScaleFactor(chaStateRaw, scaleFactors.ChaState_SF, 'uint16', 'State of Charge'),
1235
+ chaState: this.applyScaleFactor(chaStateRaw, scaleFactors.ChaState_SF, 'uint16', 'State of Charge', 8, 124),
982
1236
  chaStateSF: scaleFactors.ChaState_SF,
983
- storAval: this.applyScaleFactor(storAvalRaw, scaleFactors.StorAval_SF, 'uint16', 'Available Storage'),
1237
+ storAval: this.applyScaleFactor(storAvalRaw, scaleFactors.StorAval_SF, 'uint16', 'Available Storage', 9, 124),
984
1238
  storAvalSF: scaleFactors.StorAval_SF,
985
- inBatV: this.applyScaleFactor(inBatVRaw, scaleFactors.InBatV_SF, 'uint16', 'Battery Voltage'),
1239
+ inBatV: this.applyScaleFactor(inBatVRaw, scaleFactors.InBatV_SF, 'uint16', 'Battery Voltage', 10, 124),
986
1240
  inBatVSF: scaleFactors.InBatV_SF,
987
1241
  chaSt: !this.isUnimplementedValue(chaStRaw, 'enum16') ? chaStRaw : undefined,
988
1242
  chaStName: chaStName,
989
1243
  // Rate control
990
- outWRte: this.applyScaleFactor(outWRteRaw, scaleFactors.InOutWRte_SF, 'int16', 'Discharge Rate'),
991
- inWRte: this.applyScaleFactor(inWRteRaw, scaleFactors.InOutWRte_SF, 'int16', 'Charge Rate'),
1244
+ outWRte: this.applyScaleFactor(outWRteRaw, scaleFactors.InOutWRte_SF, 'int16', 'Discharge Rate', 12, 124),
1245
+ inWRte: this.applyScaleFactor(inWRteRaw, scaleFactors.InOutWRte_SF, 'int16', 'Charge Rate', 13, 124),
992
1246
  inOutWRteSF: scaleFactors.InOutWRte_SF,
993
1247
  // Timing parameters
994
1248
  inOutWRteWinTms: !this.isUnimplementedValue(inOutWRteWinTmsRaw, 'uint16') ? inOutWRteWinTmsRaw : undefined,
@@ -1013,8 +1267,43 @@ export class SunspecModbusClient {
1013
1267
  }
1014
1268
  return data;
1015
1269
  }
1270
+ else if (model.id === 802) {
1271
+ // Model 802: Battery Base
1272
+ console.log('Using Model 802 (Battery Base)');
1273
+ const baseData = await this.readBatteryBaseData();
1274
+ if (!baseData) {
1275
+ return null;
1276
+ }
1277
+ // Derive charge/discharge power from w field
1278
+ let chargePower;
1279
+ let dischargePower;
1280
+ if (baseData.w !== undefined) {
1281
+ if (baseData.w >= 0) {
1282
+ chargePower = baseData.w;
1283
+ dischargePower = 0;
1284
+ }
1285
+ else {
1286
+ chargePower = 0;
1287
+ dischargePower = Math.abs(baseData.w);
1288
+ }
1289
+ }
1290
+ return {
1291
+ blockNumber: 802,
1292
+ blockAddress: model.address,
1293
+ blockLength: model.length,
1294
+ soc: baseData.soC,
1295
+ soh: baseData.soH,
1296
+ voltage: baseData.v,
1297
+ current: baseData.a,
1298
+ chaSt: baseData.chaSt,
1299
+ chaStName: baseData.chaStName,
1300
+ status: baseData.state,
1301
+ chargePower,
1302
+ dischargePower,
1303
+ };
1304
+ }
1016
1305
  else {
1017
- // Handle other battery models (802, 803) if needed
1306
+ // Handle other battery models (803) if needed
1018
1307
  console.log(`Battery Model ${model.id} reading not yet implemented`);
1019
1308
  return {
1020
1309
  blockNumber: model.id,
@@ -1145,6 +1434,9 @@ export class SunspecModbusClient {
1145
1434
  MinRsvPct_SF: await this.readRegisterValue(baseAddr + 21, 1, 'int16'),
1146
1435
  InOutWRte_SF: await this.readRegisterValue(baseAddr + 25, 1, 'int16')
1147
1436
  };
1437
+ this.logRegisterRead(124, 18, 'WChaMax_SF', scaleFactors.WChaMax_SF, 'int16');
1438
+ this.logRegisterRead(124, 21, 'MinRsvPct_SF', scaleFactors.MinRsvPct_SF, 'int16');
1439
+ this.logRegisterRead(124, 25, 'InOutWRte_SF', scaleFactors.InOutWRte_SF, 'int16');
1148
1440
  // Read raw values
1149
1441
  const wChaMaxRaw = await this.readRegisterValue(baseAddr + 2, 1, 'uint16');
1150
1442
  const storCtlModRaw = await this.readRegisterValue(baseAddr + 5, 1, 'uint16');
@@ -1152,14 +1444,16 @@ export class SunspecModbusClient {
1152
1444
  const outWRteRaw = await this.readRegisterValue(baseAddr + 12, 1, 'int16');
1153
1445
  const inWRteRaw = await this.readRegisterValue(baseAddr + 13, 1, 'int16');
1154
1446
  const chaGriSetRaw = await this.readRegisterValue(baseAddr + 17, 1, 'uint16');
1447
+ this.logRegisterRead(124, 5, 'storCtlMod', storCtlModRaw, 'bitfield16');
1448
+ this.logRegisterRead(124, 17, 'chaGriSet', chaGriSetRaw, 'enum16');
1155
1449
  // Apply scale factors and return control settings
1156
1450
  return {
1157
1451
  storCtlMod: !this.isUnimplementedValue(storCtlModRaw, 'bitfield16') ? storCtlModRaw : undefined,
1158
1452
  chaGriSet: !this.isUnimplementedValue(chaGriSetRaw, 'enum16') ? chaGriSetRaw : undefined,
1159
- wChaMax: this.applyScaleFactor(wChaMaxRaw, scaleFactors.WChaMax_SF, 'uint16'),
1160
- inWRte: this.applyScaleFactor(inWRteRaw, scaleFactors.InOutWRte_SF, 'int16'),
1161
- outWRte: this.applyScaleFactor(outWRteRaw, scaleFactors.InOutWRte_SF, 'int16'),
1162
- minRsvPct: this.applyScaleFactor(minRsvPctRaw, scaleFactors.MinRsvPct_SF, 'uint16')
1453
+ wChaMax: this.applyScaleFactor(wChaMaxRaw, scaleFactors.WChaMax_SF, 'uint16', 'Max Charge Power', 2, 124),
1454
+ inWRte: this.applyScaleFactor(inWRteRaw, scaleFactors.InOutWRte_SF, 'int16', 'Charge Rate', 13, 124),
1455
+ outWRte: this.applyScaleFactor(outWRteRaw, scaleFactors.InOutWRte_SF, 'int16', 'Discharge Rate', 12, 124),
1456
+ minRsvPct: this.applyScaleFactor(minRsvPctRaw, scaleFactors.MinRsvPct_SF, 'uint16', 'Min Reserve Percent', 7, 124)
1163
1457
  };
1164
1458
  }
1165
1459
  catch (error) {
@@ -1230,25 +1524,21 @@ export class SunspecModbusClient {
1230
1524
  const powerSF = await this.readRegisterValue(baseAddr + powerSFOffset, 1, 'int16');
1231
1525
  const freqSF = await this.readRegisterValue(baseAddr + freqSFOffset, 1, 'int16');
1232
1526
  const energySF = await this.readRegisterValue(baseAddr + energySFOffset, 1, 'int16');
1233
- console.log(`Meter Scale Factors: Power_SF=${powerSF}, Freq_SF=${freqSF}, Energy_SF=${energySF}`);
1527
+ this.logRegisterRead(model.id, powerSFOffset, 'W_SF', powerSF, 'int16');
1528
+ this.logRegisterRead(model.id, freqSFOffset, 'Hz_SF', freqSF, 'int16');
1529
+ this.logRegisterRead(model.id, energySFOffset, 'TotWh_SF', energySF, 'int16');
1234
1530
  // Read raw values
1235
- const powerAddr = baseAddr + powerOffset;
1236
- const powerRaw = await this.readRegisterValue(powerAddr, 1, 'int16');
1237
- console.log(`Meter Total Power: address=${powerAddr}, raw=0x${powerRaw.toString(16).toUpperCase()} (${powerRaw}), SF=${powerSF}`);
1238
- const freqAddr = baseAddr + freqOffset;
1239
- const freqRaw = await this.readRegisterValue(freqAddr, 1, 'uint16');
1240
- console.log(`Meter Frequency: address=${freqAddr}, raw=0x${freqRaw.toString(16).toUpperCase()} (${freqRaw}), SF=${freqSF}`);
1241
- const exportAddr = baseAddr + exportOffset;
1242
- const exportRaw = await this.readRegisterValue(exportAddr, 2, 'uint32');
1243
- console.log(`Meter Export Energy: address=${exportAddr}, raw=0x${exportRaw.toString(16).toUpperCase()} (${exportRaw}), SF=${energySF}`);
1244
- const importAddr = baseAddr + importOffset;
1245
- const importRaw = await this.readRegisterValue(importAddr, 2, 'uint32');
1246
- console.log(`Meter Import Energy: address=${importAddr}, raw=0x${importRaw.toString(16).toUpperCase()} (${importRaw}), SF=${energySF}`);
1531
+ const powerRaw = await this.readRegisterValue(baseAddr + powerOffset, 1, 'int16');
1532
+ const freqRaw = await this.readRegisterValue(baseAddr + freqOffset, 1, 'uint16');
1533
+ const exportRaw = await this.readRegisterValue(baseAddr + exportOffset, 2, 'uint32');
1534
+ const importRaw = await this.readRegisterValue(baseAddr + importOffset, 2, 'uint32');
1535
+ this.logRegisterRead(model.id, exportOffset, 'TotWhExp', exportRaw, 'acc32');
1536
+ this.logRegisterRead(model.id, importOffset, 'TotWhImp', importRaw, 'acc32');
1247
1537
  // Calculate final values with scale factors
1248
- const totalPower = this.applyScaleFactor(powerRaw, powerSF, 'int16', 'Meter Total Power');
1249
- const frequency = this.applyScaleFactor(freqRaw, freqSF, 'uint16', 'Meter Frequency');
1250
- const exportedEnergy = this.applyScaleFactor(exportRaw, energySF, "acc32");
1251
- const importedEnergy = this.applyScaleFactor(importRaw, energySF, "acc32");
1538
+ const totalPower = this.applyScaleFactor(powerRaw, powerSF, 'int16', 'Total Power', powerOffset, model.id);
1539
+ const frequency = this.applyScaleFactor(freqRaw, freqSF, 'uint16', 'Frequency', freqOffset, model.id);
1540
+ const exportedEnergy = this.applyScaleFactor(exportRaw, energySF, "acc32", 'Exported Energy', exportOffset, model.id);
1541
+ const importedEnergy = this.applyScaleFactor(importRaw, energySF, "acc32", 'Imported Energy', importOffset, model.id);
1252
1542
  return {
1253
1543
  blockNumber: model.id,
1254
1544
  totalPower,
@@ -1282,30 +1572,26 @@ export class SunspecModbusClient {
1282
1572
  const versionAddr = baseAddr + 40; // Offset 40-47 (8 registers) from data start
1283
1573
  const serialAddr = baseAddr + 48; // Offset 48-63 (16 registers) from data start
1284
1574
  const deviceAddrAddr = baseAddr + 64; // Offset 64 from data start
1285
- console.log(`Reading manufacturer from address ${manufacturerAddr} (16 registers)`);
1286
1575
  const manufacturer = await this.readRegisterValue(manufacturerAddr, 16, 'string');
1287
- console.log(`Manufacturer raw value: "${manufacturer}"`);
1288
- console.log(`Reading model from address ${modelAddr} (16 registers)`);
1576
+ this.logRegisterRead(1, 0, 'Manufacturer', manufacturer, 'string');
1289
1577
  const modelName = await this.readRegisterValue(modelAddr, 16, 'string');
1290
- console.log(`Model raw value: "${modelName}"`);
1291
- console.log(`Reading options from address ${optionsAddr} (8 registers)`);
1578
+ this.logRegisterRead(1, 16, 'Model', modelName, 'string');
1292
1579
  const options = await this.readRegisterValue(optionsAddr, 8, 'string');
1293
- console.log(`Reading version from address ${versionAddr} (8 registers)`);
1580
+ this.logRegisterRead(1, 32, 'Options', options, 'string');
1294
1581
  const version = await this.readRegisterValue(versionAddr, 8, 'string');
1295
- console.log(`Reading serial from address ${serialAddr} (16 registers)`);
1582
+ this.logRegisterRead(1, 40, 'Version', version, 'string');
1296
1583
  const serialNumber = await this.readRegisterValue(serialAddr, 16, 'string');
1297
- console.log(`Reading device address from address ${deviceAddrAddr}`);
1584
+ this.logRegisterRead(1, 48, 'Serial Number', serialNumber, 'string');
1298
1585
  const deviceAddress = await this.readRegisterValue(deviceAddrAddr, 1, 'uint16');
1299
- const result = {
1300
- manufacturer: manufacturer,
1586
+ this.logRegisterRead(1, 64, 'Device Address', deviceAddress, 'uint16');
1587
+ return {
1588
+ manufacturer,
1301
1589
  model: modelName,
1302
- options: options,
1303
- version: version,
1304
- serialNumber: serialNumber,
1305
- deviceAddress: deviceAddress
1590
+ options,
1591
+ version,
1592
+ serialNumber,
1593
+ deviceAddress
1306
1594
  };
1307
- console.log('Common Block Data:', JSON.stringify(result, null, 2));
1308
- return result;
1309
1595
  }
1310
1596
  catch (error) {
1311
1597
  console.error(`Error reading common block: ${error}`);
@@ -1361,47 +1647,64 @@ export class SunspecModbusClient {
1361
1647
  MaxRmpRte_SF: await this.readRegisterValue(baseAddr + 30, 1, 'int16'),
1362
1648
  ECPNomHz_SF: await this.readRegisterValue(baseAddr + 31, 1, 'int16')
1363
1649
  };
1650
+ this.logRegisterRead(121, 22, 'WMax_SF', scaleFactors.WMax_SF, 'int16');
1651
+ this.logRegisterRead(121, 23, 'VRef_SF', scaleFactors.VRef_SF, 'int16');
1652
+ this.logRegisterRead(121, 24, 'VRefOfs_SF', scaleFactors.VRefOfs_SF, 'int16');
1653
+ this.logRegisterRead(121, 25, 'VMinMax_SF', scaleFactors.VMinMax_SF, 'int16');
1654
+ this.logRegisterRead(121, 26, 'VAMax_SF', scaleFactors.VAMax_SF, 'int16');
1655
+ this.logRegisterRead(121, 27, 'VArMax_SF', scaleFactors.VArMax_SF, 'int16');
1656
+ this.logRegisterRead(121, 28, 'WGra_SF', scaleFactors.WGra_SF, 'int16');
1657
+ this.logRegisterRead(121, 29, 'PFMin_SF', scaleFactors.PFMin_SF, 'int16');
1658
+ this.logRegisterRead(121, 30, 'MaxRmpRte_SF', scaleFactors.MaxRmpRte_SF, 'int16');
1659
+ this.logRegisterRead(121, 31, 'ECPNomHz_SF', scaleFactors.ECPNomHz_SF, 'int16');
1660
+ // Read non-scaled fields first for logging
1661
+ const vArActRaw = await this.readRegisterValue(baseAddr + 17, 1, 'uint16');
1662
+ const clcTotVARaw = await this.readRegisterValue(baseAddr + 18, 1, 'uint16');
1663
+ const connPhRaw = await this.readRegisterValue(baseAddr + 21, 1, 'uint16');
1664
+ this.logRegisterRead(121, 17, 'VArAct', vArActRaw, 'enum16');
1665
+ this.logRegisterRead(121, 18, 'ClcTotVA', clcTotVARaw, 'enum16');
1666
+ this.logRegisterRead(121, 21, 'ConnPh', connPhRaw, 'enum16');
1364
1667
  return {
1365
1668
  blockNumber: 121,
1366
1669
  blockAddress: model.address,
1367
1670
  blockLength: model.length,
1368
1671
  // Power settings - Offset 2
1369
- WMax: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 2, 1, 'uint16'), scaleFactors.WMax_SF, 'uint16', 'Max Power'),
1672
+ WMax: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 2, 1, 'uint16'), scaleFactors.WMax_SF, 'uint16', 'Max Power', 2, 121),
1370
1673
  WMax_SF: scaleFactors.WMax_SF,
1371
1674
  // Voltage settings - Offsets 3-6
1372
- VRef: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 3, 1, 'uint16'), scaleFactors.VRef_SF, 'uint16', 'Voltage Reference'),
1675
+ VRef: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 3, 1, 'uint16'), scaleFactors.VRef_SF, 'uint16', 'Voltage Reference', 3, 121),
1373
1676
  VRef_SF: scaleFactors.VRef_SF,
1374
- VRefOfs: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 4, 1, 'int16'), scaleFactors.VRefOfs_SF, 'int16', 'Voltage Reference Offset'),
1677
+ VRefOfs: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 4, 1, 'int16'), scaleFactors.VRefOfs_SF, 'int16', 'Voltage Reference Offset', 4, 121),
1375
1678
  VRefOfs_SF: scaleFactors.VRefOfs_SF,
1376
- VMax: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 5, 1, 'uint16'), scaleFactors.VMinMax_SF, 'uint16', 'Max Voltage'),
1377
- VMin: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 6, 1, 'uint16'), scaleFactors.VMinMax_SF, 'uint16', 'Min Voltage'),
1679
+ VMax: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 5, 1, 'uint16'), scaleFactors.VMinMax_SF, 'uint16', 'Max Voltage', 5, 121),
1680
+ VMin: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 6, 1, 'uint16'), scaleFactors.VMinMax_SF, 'uint16', 'Min Voltage', 6, 121),
1378
1681
  VMinMax_SF: scaleFactors.VMinMax_SF,
1379
1682
  // Apparent power settings - Offset 7
1380
- VAMax: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 7, 1, 'uint16'), scaleFactors.VAMax_SF, 'uint16', 'Max Apparent Power'),
1683
+ VAMax: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 7, 1, 'uint16'), scaleFactors.VAMax_SF, 'uint16', 'Max Apparent Power', 7, 121),
1381
1684
  VAMax_SF: scaleFactors.VAMax_SF,
1382
1685
  // Reactive power settings - Offsets 8-11
1383
- VArMaxQ1: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 8, 1, 'int16'), scaleFactors.VArMax_SF, 'int16', 'Max Reactive Power Q1'),
1384
- VArMaxQ2: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 9, 1, 'int16'), scaleFactors.VArMax_SF, 'int16', 'Max Reactive Power Q2'),
1385
- VArMaxQ3: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 10, 1, 'int16'), scaleFactors.VArMax_SF, 'int16', 'Max Reactive Power Q3'),
1386
- VArMaxQ4: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 11, 1, 'int16'), scaleFactors.VArMax_SF, 'int16', 'Max Reactive Power Q4'),
1686
+ VArMaxQ1: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 8, 1, 'int16'), scaleFactors.VArMax_SF, 'int16', 'Max Reactive Power Q1', 8, 121),
1687
+ VArMaxQ2: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 9, 1, 'int16'), scaleFactors.VArMax_SF, 'int16', 'Max Reactive Power Q2', 9, 121),
1688
+ VArMaxQ3: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 10, 1, 'int16'), scaleFactors.VArMax_SF, 'int16', 'Max Reactive Power Q3', 10, 121),
1689
+ VArMaxQ4: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 11, 1, 'int16'), scaleFactors.VArMax_SF, 'int16', 'Max Reactive Power Q4', 11, 121),
1387
1690
  VArMax_SF: scaleFactors.VArMax_SF,
1388
1691
  // Ramp rate settings - Offset 12
1389
- WGra: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 12, 1, 'uint16'), scaleFactors.WGra_SF, 'uint16', 'Power Ramp Rate'),
1692
+ WGra: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 12, 1, 'uint16'), scaleFactors.WGra_SF, 'uint16', 'Power Ramp Rate', 12, 121),
1390
1693
  WGra_SF: scaleFactors.WGra_SF,
1391
1694
  // Power factor settings - Offsets 13-16
1392
- PFMinQ1: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 13, 1, 'int16'), scaleFactors.PFMin_SF, 'int16', 'Min Power Factor Q1'),
1393
- PFMinQ2: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 14, 1, 'int16'), scaleFactors.PFMin_SF, 'int16', 'Min Power Factor Q2'),
1394
- PFMinQ3: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 15, 1, 'int16'), scaleFactors.PFMin_SF, 'int16', 'Min Power Factor Q3'),
1395
- PFMinQ4: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 16, 1, 'int16'), scaleFactors.PFMin_SF, 'int16', 'Min Power Factor Q4'),
1695
+ PFMinQ1: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 13, 1, 'int16'), scaleFactors.PFMin_SF, 'int16', 'Min Power Factor Q1', 13, 121),
1696
+ PFMinQ2: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 14, 1, 'int16'), scaleFactors.PFMin_SF, 'int16', 'Min Power Factor Q2', 14, 121),
1697
+ PFMinQ3: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 15, 1, 'int16'), scaleFactors.PFMin_SF, 'int16', 'Min Power Factor Q3', 15, 121),
1698
+ PFMinQ4: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 16, 1, 'int16'), scaleFactors.PFMin_SF, 'int16', 'Min Power Factor Q4', 16, 121),
1396
1699
  PFMin_SF: scaleFactors.PFMin_SF,
1397
1700
  // Other settings - Offsets 17-21
1398
- VArAct: await this.readRegisterValue(baseAddr + 17, 1, 'uint16'),
1399
- ClcTotVA: await this.readRegisterValue(baseAddr + 18, 1, 'uint16'),
1400
- MaxRmpRte: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 19, 1, 'uint16'), scaleFactors.MaxRmpRte_SF, 'uint16', 'Max Ramp Rate'),
1701
+ VArAct: vArActRaw,
1702
+ ClcTotVA: clcTotVARaw,
1703
+ MaxRmpRte: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 19, 1, 'uint16'), scaleFactors.MaxRmpRte_SF, 'uint16', 'Max Ramp Rate', 19, 121),
1401
1704
  MaxRmpRte_SF: scaleFactors.MaxRmpRte_SF,
1402
- ECPNomHz: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 20, 1, 'uint16'), scaleFactors.ECPNomHz_SF, 'uint16', 'Nominal Frequency'),
1705
+ ECPNomHz: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 20, 1, 'uint16'), scaleFactors.ECPNomHz_SF, 'uint16', 'Nominal Frequency', 20, 121),
1403
1706
  ECPNomHz_SF: scaleFactors.ECPNomHz_SF,
1404
- ConnPh: await this.readRegisterValue(baseAddr + 21, 1, 'uint16')
1707
+ ConnPh: connPhRaw
1405
1708
  };
1406
1709
  }
1407
1710
  catch (error) {
@@ -1426,38 +1729,74 @@ export class SunspecModbusClient {
1426
1729
  OutPFSet_SF: await this.readRegisterValue(baseAddr + 22, 1, 'int16'),
1427
1730
  VArPct_SF: await this.readRegisterValue(baseAddr + 23, 1, 'int16')
1428
1731
  };
1732
+ this.logRegisterRead(123, 21, 'WMaxLimPct_SF', scaleFactors.WMaxLimPct_SF, 'int16');
1733
+ this.logRegisterRead(123, 22, 'OutPFSet_SF', scaleFactors.OutPFSet_SF, 'int16');
1734
+ this.logRegisterRead(123, 23, 'VArPct_SF', scaleFactors.VArPct_SF, 'int16');
1735
+ // Read non-scaled fields
1736
+ const connWinTmsRaw = await this.readRegisterValue(baseAddr, 1, 'uint16');
1737
+ const connRvrtTmsRaw = await this.readRegisterValue(baseAddr + 1, 1, 'uint16');
1738
+ const connRaw = await this.readRegisterValue(baseAddr + 2, 1, 'uint16');
1739
+ const wMaxLimPctWinTmsRaw = await this.readRegisterValue(baseAddr + 4, 1, 'uint16');
1740
+ const wMaxLimPctRvrtTmsRaw = await this.readRegisterValue(baseAddr + 5, 1, 'uint16');
1741
+ const wMaxLimPctRmpTmsRaw = await this.readRegisterValue(baseAddr + 6, 1, 'uint16');
1742
+ const wMaxLimEnaRaw = await this.readRegisterValue(baseAddr + 7, 1, 'uint16');
1743
+ const outPFSetWinTmsRaw = await this.readRegisterValue(baseAddr + 9, 1, 'uint16');
1744
+ const outPFSetRvrtTmsRaw = await this.readRegisterValue(baseAddr + 10, 1, 'uint16');
1745
+ const outPFSetRmpTmsRaw = await this.readRegisterValue(baseAddr + 11, 1, 'uint16');
1746
+ const outPFSetEnaRaw = await this.readRegisterValue(baseAddr + 12, 1, 'uint16');
1747
+ const vArPctWinTmsRaw = await this.readRegisterValue(baseAddr + 16, 1, 'uint16');
1748
+ const vArPctRvrtTmsRaw = await this.readRegisterValue(baseAddr + 17, 1, 'uint16');
1749
+ const vArPctRmpTmsRaw = await this.readRegisterValue(baseAddr + 18, 1, 'uint16');
1750
+ const vArPctModRaw = await this.readRegisterValue(baseAddr + 19, 1, 'uint16');
1751
+ const vArPctEnaRaw = await this.readRegisterValue(baseAddr + 20, 1, 'uint16');
1752
+ this.logRegisterRead(123, 0, 'Conn_WinTms', connWinTmsRaw, 'uint16');
1753
+ this.logRegisterRead(123, 1, 'Conn_RvrtTms', connRvrtTmsRaw, 'uint16');
1754
+ this.logRegisterRead(123, 2, 'Conn', connRaw, 'enum16');
1755
+ this.logRegisterRead(123, 4, 'WMaxLimPct_WinTms', wMaxLimPctWinTmsRaw, 'uint16');
1756
+ this.logRegisterRead(123, 5, 'WMaxLimPct_RvrtTms', wMaxLimPctRvrtTmsRaw, 'uint16');
1757
+ this.logRegisterRead(123, 6, 'WMaxLimPct_RmpTms', wMaxLimPctRmpTmsRaw, 'uint16');
1758
+ this.logRegisterRead(123, 7, 'WMaxLim_Ena', wMaxLimEnaRaw, 'enum16');
1759
+ this.logRegisterRead(123, 9, 'OutPFSet_WinTms', outPFSetWinTmsRaw, 'uint16');
1760
+ this.logRegisterRead(123, 10, 'OutPFSet_RvrtTms', outPFSetRvrtTmsRaw, 'uint16');
1761
+ this.logRegisterRead(123, 11, 'OutPFSet_RmpTms', outPFSetRmpTmsRaw, 'uint16');
1762
+ this.logRegisterRead(123, 12, 'OutPFSet_Ena', outPFSetEnaRaw, 'enum16');
1763
+ this.logRegisterRead(123, 16, 'VArPct_WinTms', vArPctWinTmsRaw, 'uint16');
1764
+ this.logRegisterRead(123, 17, 'VArPct_RvrtTms', vArPctRvrtTmsRaw, 'uint16');
1765
+ this.logRegisterRead(123, 18, 'VArPct_RmpTms', vArPctRmpTmsRaw, 'uint16');
1766
+ this.logRegisterRead(123, 19, 'VArPct_Mod', vArPctModRaw, 'enum16');
1767
+ this.logRegisterRead(123, 20, 'VArPct_Ena', vArPctEnaRaw, 'enum16');
1429
1768
  const controls = {
1430
1769
  blockNumber: 123,
1431
1770
  blockAddress: model.address,
1432
1771
  blockLength: model.length,
1433
1772
  // Connection control - Offsets 0-2
1434
- Conn_WinTms: await this.readRegisterValue(baseAddr, 1, 'uint16'),
1435
- Conn_RvrtTms: await this.readRegisterValue(baseAddr + 1, 1, 'uint16'),
1436
- Conn: await this.readRegisterValue(baseAddr + 2, 1, 'uint16'),
1773
+ Conn_WinTms: connWinTmsRaw,
1774
+ Conn_RvrtTms: connRvrtTmsRaw,
1775
+ Conn: connRaw,
1437
1776
  // Power limit control - Offsets 3-7
1438
- WMaxLimPct: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 3, 1, 'uint16'), scaleFactors.WMaxLimPct_SF, 'uint16', 'Power Limit Percentage'),
1777
+ WMaxLimPct: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 3, 1, 'uint16'), scaleFactors.WMaxLimPct_SF, 'uint16', 'Power Limit Percentage', 3, 123),
1439
1778
  WMaxLimPct_SF: scaleFactors.WMaxLimPct_SF,
1440
- WMaxLimPct_WinTms: await this.readRegisterValue(baseAddr + 4, 1, 'uint16'),
1441
- WMaxLimPct_RvrtTms: await this.readRegisterValue(baseAddr + 5, 1, 'uint16'),
1442
- WMaxLimPct_RmpTms: await this.readRegisterValue(baseAddr + 6, 1, 'uint16'),
1443
- WMaxLim_Ena: await this.readRegisterValue(baseAddr + 7, 1, 'uint16'),
1779
+ WMaxLimPct_WinTms: wMaxLimPctWinTmsRaw,
1780
+ WMaxLimPct_RvrtTms: wMaxLimPctRvrtTmsRaw,
1781
+ WMaxLimPct_RmpTms: wMaxLimPctRmpTmsRaw,
1782
+ WMaxLim_Ena: wMaxLimEnaRaw,
1444
1783
  // Power factor control - Offsets 8-12
1445
- OutPFSet: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 8, 1, 'int16'), scaleFactors.OutPFSet_SF, 'int16', 'Output Power Factor Set'),
1784
+ OutPFSet: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 8, 1, 'int16'), scaleFactors.OutPFSet_SF, 'int16', 'Output Power Factor Set', 8, 123),
1446
1785
  OutPFSet_SF: scaleFactors.OutPFSet_SF,
1447
- OutPFSet_WinTms: await this.readRegisterValue(baseAddr + 9, 1, 'uint16'),
1448
- OutPFSet_RvrtTms: await this.readRegisterValue(baseAddr + 10, 1, 'uint16'),
1449
- OutPFSet_RmpTms: await this.readRegisterValue(baseAddr + 11, 1, 'uint16'),
1450
- OutPFSet_Ena: await this.readRegisterValue(baseAddr + 12, 1, 'uint16'),
1786
+ OutPFSet_WinTms: outPFSetWinTmsRaw,
1787
+ OutPFSet_RvrtTms: outPFSetRvrtTmsRaw,
1788
+ OutPFSet_RmpTms: outPFSetRmpTmsRaw,
1789
+ OutPFSet_Ena: outPFSetEnaRaw,
1451
1790
  // Reactive power control - Offsets 13-20
1452
- VArWMaxPct: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 13, 1, 'int16'), scaleFactors.VArPct_SF, 'int16', 'Reactive Power at Max Power %'),
1453
- VArMaxPct: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 14, 1, 'int16'), scaleFactors.VArPct_SF, 'int16', 'Max Reactive Power %'),
1454
- VArAvalPct: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 15, 1, 'int16'), scaleFactors.VArPct_SF, 'int16', 'Available Reactive Power %'),
1791
+ VArWMaxPct: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 13, 1, 'int16'), scaleFactors.VArPct_SF, 'int16', 'Reactive Power at Max Power %', 13, 123),
1792
+ VArMaxPct: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 14, 1, 'int16'), scaleFactors.VArPct_SF, 'int16', 'Max Reactive Power %', 14, 123),
1793
+ VArAvalPct: this.applyScaleFactor(await this.readRegisterValue(baseAddr + 15, 1, 'int16'), scaleFactors.VArPct_SF, 'int16', 'Available Reactive Power %', 15, 123),
1455
1794
  VArPct_SF: scaleFactors.VArPct_SF,
1456
- VArPct_WinTms: await this.readRegisterValue(baseAddr + 16, 1, 'uint16'),
1457
- VArPct_RvrtTms: await this.readRegisterValue(baseAddr + 17, 1, 'uint16'),
1458
- VArPct_RmpTms: await this.readRegisterValue(baseAddr + 18, 1, 'uint16'),
1459
- VArPct_Mod: await this.readRegisterValue(baseAddr + 19, 1, 'uint16'),
1460
- VArPct_Ena: await this.readRegisterValue(baseAddr + 20, 1, 'uint16')
1795
+ VArPct_WinTms: vArPctWinTmsRaw,
1796
+ VArPct_RvrtTms: vArPctRvrtTmsRaw,
1797
+ VArPct_RmpTms: vArPctRmpTmsRaw,
1798
+ VArPct_Mod: vArPctModRaw,
1799
+ VArPct_Ena: vArPctEnaRaw
1461
1800
  };
1462
1801
  return controls;
1463
1802
  }