Files
JP_KDDI_LFPS_48100/LFP_Manager/DataStructure/csDataStructure.cs
jkwoo 9fbe461e0e V1.0.0.8 - 2025/12/30
* RS-485 Comm Fail Timeout bug fix
2025-12-30 14:33:45 +09:00

1017 lines
28 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using static DevExpress.Utils.MVVM.Internal.ILReader;
using LFP_Manager.Function;
namespace LFP_Manager.DataStructure
{
public class CommConfig
{
public int CommType;
public string SnmpIP;
public int SnmpModelIndex;
public int ModuleQty;
public int RecvWaitTime;
public string UartPort;
public int UartBaudrate;
public int UartModelIndex;
public int UartProtocol;
public int CommFailMaxCount;
public int DbLogPeriod;
public int GyroSensitive;
public int ControlLevel;
public string MasterPw;
public string EngineerPw;
public string TechnicianPw;
public CommConfig()
{
CommType = 0;
SnmpIP = "192.168.0.200";
SnmpModelIndex = 0;
ModuleQty = 1;
UartPort = "";
UartBaudrate = 9600;
UartModelIndex = 0;
UartProtocol = 0;
RecvWaitTime = 1500; // 1500ms
CommFailMaxCount = 5; // 5 times
DbLogPeriod = 5;
GyroSensitive = 120;
ControlLevel = 0;
MasterPw = "8003";
EngineerPw = "7003";
TechnicianPw = "6003";
}
}
public class TMinMax
{
public short value;
public short num;
public TMinMax()
{
value = 0;
num = 0;
}
}
public class DeviceSystemTotalData
{
public bool CommFail;
public DeviceSystemIdent IdentData;
public DeviceValueTotalData ValueData;
public DeviceStatusTotalData StatusData;
public DeviceSystemTotalData()
{
IdentData = new DeviceSystemIdent();
ValueData = new DeviceValueTotalData();
StatusData = new DeviceStatusTotalData();
}
}
public class DeviceSystemIdent
{
public string Manufacturer;
public string DeviceModel;
//public int ModuleQuantity;
public byte[] fw_ver;
public string FwVerStr;
public int AlarmOutputMode;
public UInt32 ManufactureDate;
public string SerialNumber;
public DeviceSystemIdent()
{
Manufacturer = "";
DeviceModel = "";
//ModuleQuantity = 1;
fw_ver = new byte[4];
FwVerStr = "";
AlarmOutputMode = 0;
ManufactureDate = 0;
SerialNumber = "";
}
}
public class DateTimeStruct
{
public int year;
public int month;
public int day;
public int hour;
public int minute;
public int second;
public string DateTimeStr;
public DateTimeStruct()
{
DateTimeStr = "-";
}
}
public class DeviceSystemData
{
public bool active;
public int mNo;
public int cellQty;
public int recv_cellQty;
public int tempQty;
public int ntcQty;
public int ChargeVoltage;
public int DOD;
public int MaxChaCurrent;
public int MaxDchCurrent;
public int FloatVoltage;
public int BoostVoltage;
public int MinChargeTemp;
public int MaxChargeTemp;
public UInt32 heatbeat;
public bool CommFail;
public bool ShelfCommFail;
public DateTime LastRxTime;
public Int32 BmsDateTimeInt;
public ushort BmsDateTimeShort1;
public ushort BmsDateTimeShort2;
public DateTimeStruct BmsDateTime;
public DeviceValueData ValueData;
public DeviceAvgData AvgData;
public DeviceStatusData StatusData;
public DeviceParamData ParamData;
public DeviceCalibration CalibrationData;
public DeviceInforation Information;
public DeviceEtcStatus EtcStatus;
public DeviceMaxValue MaxValue;
public DeviceGyroValue GyroValue;
public DeviceSystemData()
{
active = false;
mNo = 0;
cellQty = csConstData.SystemInfo.MAX_MODULE_CELL_SIZE;
tempQty = csConstData.SystemInfo.MAX_MODULE_TEMP_SIZE;
ChargeVoltage = 0;
DOD = 0;
MaxChaCurrent = 0;
MaxDchCurrent = 0;
heatbeat = 0;
CommFail = false;
ShelfCommFail = false;
LastRxTime = DateTime.MinValue;
BmsDateTimeInt = 0;
BmsDateTime = new DateTimeStruct();
ValueData = new DeviceValueData();
AvgData = new DeviceAvgData();
StatusData = new DeviceStatusData();
ParamData = new DeviceParamData();
CalibrationData = new DeviceCalibration();
Information = new DeviceInforation();
EtcStatus = new DeviceEtcStatus();
MaxValue = new DeviceMaxValue();
GyroValue = new DeviceGyroValue();
}
public void Reset()
{
active = false;
mNo = 0;
cellQty = 15;
tempQty = 4;
ChargeVoltage = 0;
DOD = 0;
MaxChaCurrent = 0;
MaxDchCurrent = 0;
heatbeat = 0;
CommFail = false;
ShelfCommFail = false;
LastRxTime = DateTime.MinValue;
BmsDateTimeInt = 0;
BmsDateTimeShort1 = 0;
BmsDateTimeShort2 = 0;
ResetCopyHelpers.ResetOrRecreate(ref BmsDateTime);
ResetCopyHelpers.ResetOrRecreate(ref ValueData);
ResetCopyHelpers.ResetOrRecreate(ref AvgData);
ResetCopyHelpers.ResetOrRecreate(ref ParamData);
ResetCopyHelpers.ResetOrRecreate(ref CalibrationData);
ResetCopyHelpers.ResetOrRecreate(ref Information);
ResetCopyHelpers.ResetOrRecreate(ref EtcStatus);
ResetCopyHelpers.ResetOrRecreate(ref MaxValue);
ResetCopyHelpers.ResetOrRecreate(ref GyroValue);
}
}
public class DeviceValueTotalData
{
public short TotalVoltage;
public short TotalCurrent;
public short TotalSOC;
public short TotalSOH;
public short TotalTemp;
public DeviceValueTotalData()
{
TotalVoltage = 0;
TotalCurrent = 0;
TotalSOC = 0;
TotalSOH = 0;
TotalTemp = 0;
}
}
public class DeviceValueData
{
public byte[] fw_ver;
public short voltageOfPack;
public short current;
public short cha_current;
public short dch_current;
public short averageCurrent;
public short rSOC;
public short NumOfCells;
public short NumOfTemps;
public ushort[] CellVoltage;
public short[] CellTemperature;
public short Ext1Temperature;
public short Ext2Temperature;
public short remainingCapacity;
public short stateOfHealth;
public int cycleCount;
public int fullChargeCapacity;
public int designedCapacity;
public int TimeLeft;
public int Ah_Charged;
public int Ah_Discharged;
public int NoOfDischargeCycles;
public int NoOfChargeCycles;
public int ModuleAlarms;
public int ModuleWarnings;
public int ModuleStatus;
public int ModuleVoltage_int;
public int ModBusDocVersion;
public int ParametersChanged;
public int MaxBattChargeCurr;
public int MaxBattDischargeCurr;
public int BatteryProdDateYear;
public int BatteryProdDateMonth;
public int BatteryProdDateDay;
public int BatteryModelDescription;
public int BatteryType;
public DeviceValueData()
{
fw_ver = new byte[6];
CellVoltage = new ushort[csConstData.SystemInfo.MAX_MODULE_CELL_SIZE];
CellTemperature = new short[csConstData.SystemInfo.MAX_MODULE_TEMP_SIZE];
}
}
public class DeviceAvgData
{
public int maxCellVoltage;
public int minCellVoltage;
public int avgCellVoltage;
public int diffCellVoltage;
public int maxCellNum;
public int minCellNum;
public int maxTemp;
public int minTemp;
public int avgTemp;
public int diffTemp;
public int maxTempNum;
public int minTempNum;
public DeviceAvgData()
{
}
}
public class DeviceStatusTotalData
{
public short batteryStatus;
public short warning;
public short protection;
public short status;
}
public class DeviceStatusData
{
public short batteryStatus;
public short batteryStatus1;
public short warning;
public short protection;
public short protection1;
public short status;
public short faultAndStatus;
public short relayStatus;
public short errorCode;
public short specialAlarm; // 1: Commfail, 2. Gyro, 3, Breaker
public short faultstatus; // Only for RS-485
public short cellBallanceStatus;
public short cellBalanceValue;
public short cellBalanceFlag;
}
public class DeviceCommStatus
{
public DateTime LastRxTime;
public bool CommFail;
}
public class DeviceParamData
{
public short CellOverVoltageTrip;
public short CellOverVoltageWarning;
public short CellOverVoltageRelease;
public short CellUnderVoltageTrip;
public short CellUnderVoltageWarning;
public short CellUnderVoltageRelease;
public short SysOverVoltageTrip;
public short SysOverVoltageWarning;
public short SysOverVoltageRelease;
public short SysUnderVoltageTrip;
public short SysUnderVoltageWarning;
public short SysUnderVoltageRelease;
public short ChaHighTempTrip;
public short ChaHighTempWarning;
public short ChaHighTempRelease;
public short ChaLowTempTrip;
public short ChaLowTempWarning;
public short ChaLowTempRelease;
public short DchHighTempTrip;
public short DchHighTempWarning;
public short DchHighTempRelease;
public short DchLowTempTrip;
public short DchLowTempWarning;
public short DchLowTempRelease;
public short ChaOverCurrentTrip1;
public short ChaOverCurrentTrip2;
public short ChaOverCurrentWarning;
public short ChaOverCurrentReleaseTime;
public short ChaOverCurrentTimes;
public short ChaOverCurrentDelay1;
public short ChaOverCurrentDelay2;
public short DchOverCurrentTrip1;
public short DchOverCurrentTrip2;
public short DchOverCurrentWarning;
public short DchOverCurrentReleaseTime;
public short DchOverCurrentTimes;
public short DchOverCurrentDelay1;
public short DchOverCurrentDelay2;
public short PcbHighTempTrip;
public short PcbHighTempWarning;
public short PcbHighTempRelease;
public short EnvLowTempWarning;
public short EnvLowTempTrip;
public short EnvLowTempRelease;
public short EnvHighTempWarning;
public short EnvHighTempTrip;
public short EnvHighTempRelease;
public short ShortCircuit;
public short LowSocTrip;
public short LowSocWarning;
public short LowSocRelease;
public short CellVoltageDifferenceTrip;
public short CellVoltageDifferenceWarning;
public short CellVoltageDifferenceRelease;
public short CellVoltageDifferenceTime;
public short DefalutParamOption;
public short DefalutParamAll;
public ushort ReadParamAll;
public DeviceParamData DeepCopy()
{
DeviceParamData newCopy = new DeviceParamData
{
CellOverVoltageTrip = CellOverVoltageTrip,
CellOverVoltageWarning = CellOverVoltageWarning,
CellOverVoltageRelease = CellOverVoltageRelease,
CellUnderVoltageTrip = CellUnderVoltageTrip,
CellUnderVoltageWarning = CellUnderVoltageWarning,
CellUnderVoltageRelease = CellUnderVoltageRelease,
SysOverVoltageTrip = SysOverVoltageTrip,
SysOverVoltageWarning = SysOverVoltageWarning,
SysOverVoltageRelease = SysOverVoltageRelease,
SysUnderVoltageTrip = SysUnderVoltageTrip,
SysUnderVoltageWarning = SysUnderVoltageWarning,
SysUnderVoltageRelease = SysUnderVoltageRelease,
ChaHighTempTrip = ChaHighTempTrip,
ChaHighTempWarning = ChaHighTempWarning,
ChaHighTempRelease = ChaHighTempRelease,
ChaLowTempTrip = ChaLowTempTrip,
ChaLowTempWarning = ChaLowTempWarning,
ChaLowTempRelease = ChaLowTempRelease,
DchHighTempTrip = DchHighTempTrip,
DchHighTempWarning = DchHighTempWarning,
DchHighTempRelease = DchHighTempRelease,
DchLowTempTrip = DchLowTempTrip,
DchLowTempWarning = DchLowTempWarning,
DchLowTempRelease = DchLowTempRelease,
ChaOverCurrentTrip1 = ChaOverCurrentTrip1,
ChaOverCurrentTrip2 = ChaOverCurrentTrip2,
ChaOverCurrentWarning = ChaOverCurrentWarning,
ChaOverCurrentReleaseTime = ChaOverCurrentReleaseTime,
ChaOverCurrentTimes = ChaOverCurrentTimes,
ChaOverCurrentDelay1 = ChaOverCurrentDelay1,
ChaOverCurrentDelay2 = ChaOverCurrentDelay2,
DchOverCurrentTrip1 = DchOverCurrentTrip1,
DchOverCurrentTrip2 = DchOverCurrentTrip2,
DchOverCurrentWarning = DchOverCurrentWarning,
DchOverCurrentReleaseTime = DchOverCurrentReleaseTime,
DchOverCurrentTimes = DchOverCurrentTimes,
DchOverCurrentDelay1 = DchOverCurrentDelay1,
DchOverCurrentDelay2 = DchOverCurrentDelay2,
PcbHighTempTrip = PcbHighTempTrip,
PcbHighTempWarning = PcbHighTempWarning,
PcbHighTempRelease = PcbHighTempRelease,
EnvLowTempWarning = EnvLowTempWarning,
EnvLowTempTrip = EnvLowTempTrip,
EnvLowTempRelease = EnvLowTempRelease,
EnvHighTempWarning = EnvHighTempWarning,
EnvHighTempTrip = EnvHighTempTrip,
EnvHighTempRelease = EnvHighTempRelease,
ShortCircuit = ShortCircuit,
LowSocTrip = LowSocTrip,
LowSocWarning = LowSocWarning,
LowSocRelease = LowSocRelease,
CellVoltageDifferenceTrip = CellVoltageDifferenceTrip,
CellVoltageDifferenceWarning = CellVoltageDifferenceWarning,
CellVoltageDifferenceRelease = CellVoltageDifferenceRelease,
CellVoltageDifferenceTime = CellVoltageDifferenceTime,
DefalutParamOption = DefalutParamOption,
DefalutParamAll = DefalutParamAll,
ReadParamAll = ReadParamAll,
};
return newCopy;
}
}
public class DeviceCalibration
{
public CellVoltageCalib CellVoltge;
public SystemVoltageCalib SystemVoltage;
public ForcedBalControl ForcedBalancing;
public BatteryParameter Battery;
public CurrentCalib Current;
public SystemInfor SystemInfo;
public CapCalibration CapCalib;
public FetCalibration FetCalib;
public ChargeMode ChaMode;
public TAntiTheft AntiTheft;
public TBmsDateTime BmsDateTime;
public TBalCalib BalCalib;
public DeviceInforation InvData;
public TAntiTheftComm AntiTheftComm;
public TAntiTheftGyro AntiTheftGyro;
public DeviceCalibration()
{
CellVoltge = new CellVoltageCalib();
SystemVoltage = new SystemVoltageCalib();
ForcedBalancing = new ForcedBalControl();
Battery = new BatteryParameter();
Current = new CurrentCalib();
SystemInfo = new SystemInfor();
CapCalib = new CapCalibration();
FetCalib = new FetCalibration();
ChaMode = new ChargeMode();
AntiTheft = new TAntiTheft();
BmsDateTime = new TBmsDateTime();
BalCalib = new TBalCalib();
InvData = new DeviceInforation();
AntiTheftComm = new TAntiTheftComm();
AntiTheftGyro = new TAntiTheftGyro();
}
public DeviceCalibration DeepCopy()
{
DeviceCalibration newCopy = new DeviceCalibration
{
CellVoltge = CellVoltge,
SystemVoltage = SystemVoltage,
ForcedBalancing = ForcedBalancing,
Battery = Battery,
Current = Current,
SystemInfo = SystemInfo,
CapCalib = CapCalib.DeepCopy(),
AntiTheft = AntiTheft.DeepCopy(),
BalCalib = BalCalib.DeepCopy(),
FetCalib = FetCalib,
ChaMode = ChaMode.DeepCopy(),
};
return newCopy;
}
}
public class TAntiTheftComm
{
public int TimeOut;
public int FuncSwitch;
public int Unlock;
public TAntiTheftComm()
{
TimeOut = 0;
FuncSwitch = 0;
Unlock = 0;
}
public TAntiTheftComm DeepCopy()
{
TAntiTheftComm newCopy = new TAntiTheftComm
{
TimeOut = TimeOut,
FuncSwitch = FuncSwitch,
Unlock = Unlock
};
return newCopy;
}
}
public class TAntiTheftGyro
{
public int XAxis;
public int YAxis;
public int ZAxis;
public int GyroPolicySel;
public int GyroFuncSwitch;
public int GyroState;
public int Unlock;
public TAntiTheftGyro()
{
XAxis = 0;
YAxis = 0;
ZAxis = 0;
GyroPolicySel = 0;
GyroFuncSwitch = 0;
GyroState = 0;
Unlock = 0;
}
public TAntiTheftGyro DeepCopy()
{
TAntiTheftGyro newCopy = new TAntiTheftGyro
{
XAxis = XAxis,
YAxis = YAxis,
ZAxis = ZAxis,
GyroPolicySel = GyroPolicySel,
GyroFuncSwitch = GyroFuncSwitch,
GyroState = GyroState,
Unlock = Unlock,
};
return newCopy;
}
}
public class CellVoltageCalib
{
public short CurrentCellNo; // 0: ODD, 1: EVEN
public short OddCellVoltageCalibration_K;
public short OddCellVoltageCalibration_B;
public short EvenCellVoltageCalibration_K;
public short EvenCellVoltageCalibration_B;
}
public class SystemVoltageCalib
{
[MarshalAs(UnmanagedType.I2, SizeConst = 2)]
public short Calibration_K;
public short Calibration_B;
}
public class ForcedBalControl
{
public short Control;
public short CellNo;
public bool AutoB;
}
public class BatteryParameter
{
public short CellQty;
public short TempQty;
public UInt32 Capacity;
}
public class CurrentCalib
{
public short SelectSubItem;
public short ShuntRange;
public short CurrentZero;
public short VoltageZero;
public Int32 ChgCalibration_K;
public Int32 DchCalibration_K;
public short ChaAndDchSelect;
public short ChargeOption;
}
public class SystemInfor
{
//public short Id;
public DateTime devTime;
public ushort LastRebootCause;
}
public class CapCalibration
{
public int DesignCapacity;
public int SocValue;
public int CycleCount;
public CapCalibration()
{
DesignCapacity = 0;
SocValue = 0;
CycleCount = 0;
}
public CapCalibration DeepCopy()
{
CapCalibration newCopy = new CapCalibration
{
DesignCapacity = DesignCapacity,
SocValue = SocValue,
CycleCount = CycleCount,
};
return newCopy;
}
}
public class ChargeMode
{
public int Mode;
public int Value;
public ChargeMode()
{
Mode = 0;
Value = 0;
}
public ChargeMode DeepCopy()
{
ChargeMode newCopy = new ChargeMode
{
Mode = Mode,
Value = Value,
};
return newCopy;
}
}
public class TAntiTheft
{
public int Comm;
public int GyroScope;
public TAntiTheft()
{
Comm = 0;
GyroScope = 0;
}
public TAntiTheft DeepCopy()
{
TAntiTheft newCopy = new TAntiTheft
{
Comm = Comm,
GyroScope = GyroScope,
};
return newCopy;
}
}
public class TBmsDateTime
{
public string Str;
public int lValue;
public short[] sValue;
public TBmsDateTime()
{
Str = "";
lValue = 0;
sValue = new short[2];
}
public TBmsDateTime DeepCopy()
{
TBmsDateTime newCopy = new TBmsDateTime
{
Str = Str,
lValue = lValue,
};
for (int i = 0; i < 2; i++)
{
newCopy.sValue[i] = sValue[i];
}
return newCopy;
}
}
public class TBalCalib
{
public int Volt;
public int Diff;
public TBalCalib()
{
Volt = 0;
Diff = 0;
}
public TBalCalib DeepCopy()
{
TBalCalib newCopy = new TBalCalib
{
Volt = Volt,
Diff = Diff,
};
return newCopy;
}
}
public class FetCalibration
{
public short FetStatus;
public short DchFetOff; // 6010
public short ChaFetOff; // 6011
public short LmtChaFetOff; // 6012
public short PreChaFetOn; // 6013
public short HeaterFetOn; // 6014
public short ChaFetOn; // 6015
}
public class DeviceInforation
{
//public string ManuDate_Str;
public byte[] ManuDate_Byte;
public byte[] Model_Byte;
public byte[] FwVer_Byte;
//public string Model_Str;
//public string FwVer_Str;
public byte[] BMS_SN;
//public string BMS_SN_Str;
public byte[] Module_SN;
public string VendorName;
public string ProductCode;
public string MajorMinorRev;
public string ModelName;
public string HwSerialNumber;
public string HwProductRev;
public string ManufacturingDate;
public string SwProductRev;
public DeviceInforation()
{
ManuDate_Byte = new byte[10];
Model_Byte = new byte[24];
FwVer_Byte = new byte[6];
//Model_Str = " ";
//FwVer_Str = " ";
BMS_SN = new byte[32];
//BMS_SN_Str = " ";
Module_SN = new byte[32];
VendorName = "-";
ProductCode = "-";
MajorMinorRev = "-";
ModelName = "-";
HwSerialNumber = "-";
HwProductRev = "-";
ManufacturingDate = "-";
SwProductRev = "-";
}
}
public class DeviceEtcStatus
{
public short SwitchHW;
public short SwitchWarning;
public short SwitchProtect;
public ushort LogDurationIdle; // min
public ushort LogDurationActive; // min
public UInt32 DataAndTime;
public ushort ChgOCPModel; /* 充电限流
0不限流保护
1始终限流充电
2预充保护
4充电过流后限流
8预充+充电过流后限流 */
public short ChgLmtVoltage; // mv
public short SOC_StopFloat; // % 暂停浮充Soc
public short SOC_RecvFloat; // % 恢复浮充电压
public short DurationFloat; // sec
public short DurationIdle; // sec
public short VoltageStopFloat; // 0.1V
public short VoltageRecvFloat; // 0.1V
public short FloatMode; /* 0000: 持续浮充
0001检测电压
0002定时浮充
0003检测SOC */
public short BalanceVoltage; // mV 均衡启动电压
public short BalanceDeltaV; // mV 均衡启动压差
public short WarnLowCapacity; // 低容量告警
public short HistroyDelete; // 删除数据记录
}
public class DeviceMaxValue
{
public short MaxChgCurrent;
public short MaxChgTemperature;
public short MinChgTemperature;
public short FloatChgVolt;
public short BoostChgVolt;
public DeviceMaxValue()
{
}
}
public class DeviceGyroValue
{
public short X_axis;
public short Y_axis;
public short Z_axis;
public short Gyro_policy_sel;
public short Gyro_func_sw;
public short Gyro_state;
public DeviceGyroValue()
{
}
}
public class TUartTRxData
{
public int type;
public int length;
public byte[] data;
public TUartTRxData()
{
type = 0;
length = 0;
data = new byte[256];
}
public TUartTRxData DeepCopy()
{
TUartTRxData newCopy = new TUartTRxData
{
type = type,
length = length,
data = data
};
for (int i = 0; i < data.Length; i++)
{
newCopy.data[i] = data[i];
}
return newCopy;
}
}
public class TUartTxBuff
{
public int InPos;
public int OutPos;
public TUartTRxData[] Buf;
public TUartTxBuff()
{
InPos = 0;
OutPos = 0;
Buf = new TUartTRxData[50];
for (int i = 0; i < 50; i++)
{
Buf[i] = new TUartTRxData();
}
}
public bool CheckBuff()
{
if (InPos != OutPos) { return true; }
else { return false; }
}
public void PutBuff(TUartTRxData UartTxData)
{
if (UartTxData != null)
{
Buf[InPos++] = UartTxData.DeepCopy();
InPos %= 50;
}
}
public TUartTRxData GetBuff()
{
TUartTRxData result = null;
if (InPos != OutPos)
{
result = Buf[OutPos++].DeepCopy();
OutPos %= 50;
}
return result;
}
}
public class THistoryAlarmData
{
public int mNo;
public bool newFdata;
public bool oldFdata;
public bool newWdata;
public bool oldWdata;
public bool newEdata;
public bool oldEdata;
public THistoryAlarmData()
{
mNo = 0;
newFdata = false;
oldFdata = false;
newWdata = false;
oldWdata = false;
newEdata = false;
oldEdata = false;
}
}
}