166 lines
10 KiB
C#
166 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Runtime.Serialization.Formatters.Binary;
|
|
using System.IO;
|
|
|
|
using LFP_Manager.DataStructure;
|
|
using LFP_Manager.Utils;
|
|
|
|
namespace LFP_Manager.Function
|
|
{
|
|
class csMakeDataFunction
|
|
{
|
|
private static DeviceSystemData MakeAlarmTripData(int id, short ndata, DeviceSystemData rSystemData)
|
|
{
|
|
bool[] aData = csUtils.Int16ToBitArray(ndata);
|
|
short bFault = rSystemData.StatusData.protection;
|
|
short bWarning = rSystemData.StatusData.warning;
|
|
int i = 0;
|
|
|
|
switch (id)
|
|
{
|
|
case 0: // Warning
|
|
if (aData[i++]) bWarning |= (1 << 2); // Bit 0 : Over voltage warning
|
|
else bWarning &= ~(1 << 2);
|
|
if (aData[i++]) bWarning |= (1 << 4); // Bit 1 : Cell Over voltage warning
|
|
else bWarning &= ~(1 << 4);
|
|
if (aData[i++]) bWarning |= (1 << 3); // Bit 2 : Low voltage warning
|
|
else bWarning &= ~(1 << 3);
|
|
if (aData[i++]) bWarning |= (1 << 5); // Bit 3 : Low cell voltage warning
|
|
else bWarning &= ~(1 << 5);
|
|
if (aData[i++]) bWarning |= (1 << 6); // Bit 4 : Charge over current warning
|
|
else bWarning &= ~(1 << 6);
|
|
if (aData[i++]) bWarning |= (1 << 7); // Bit 5 : Discharge over current warning
|
|
else bWarning &= ~(1 << 7);
|
|
i++; // 06 Abnormal balancing current
|
|
i++; // 07 Reserved
|
|
if ((aData[8]) || (aData[9])) bWarning |= (1 << 0); // Bit 8 : Charge over temperature warning, Bit 9 : Discharge over temperature warning
|
|
else bWarning &= ~(1 << 0);
|
|
i++; // 08
|
|
i++; // 09
|
|
if ((aData[10]) || (aData[11])) bWarning |= (1 << 1); // Bit 10 : Charge low temperature warning, Bit 11 : Discharge low temperature warning
|
|
else bWarning &= ~(1 << 1);
|
|
i++; // 10
|
|
i++; // 11
|
|
if (aData[i++]) bWarning |= (1 << 11); // 12 : Low capacity warning
|
|
else bWarning &= ~(1 << 11);
|
|
i++; // 13
|
|
if (aData[i++]) bWarning |= (1 << 9); // 14 Cell Voltage Difference Warning
|
|
else bWarning &= ~(1 << 9);
|
|
break;
|
|
case 1: // Status Code 2
|
|
if (aData[i++]) bFault |= (1 << 2); // Bit 0 : Over voltage warning
|
|
else bFault &= ~(1 << 2);
|
|
if (aData[i++]) bFault |= (1 << 4); // Bit 1 : Cell Over voltage warning
|
|
else bFault &= ~(1 << 4);
|
|
if (aData[i++]) bFault |= (1 << 3); // Bit 2 : Low voltage warning
|
|
else bFault &= ~(1 << 3);
|
|
if (aData[i++]) bFault |= (1 << 5); // Bit 3 : Low cell voltage warning
|
|
else bFault &= ~(1 << 5);
|
|
if (aData[i++]) bFault |= (1 << 6); // Bit 4 : Charge over current warning
|
|
else bFault &= ~(1 << 6);
|
|
if (aData[i++]) bFault |= (1 << 7); // Bit 5 : Discharge over current warning
|
|
else bFault &= ~(1 << 7);
|
|
i++; // 06 Abnormal balancing current
|
|
i++; // 07 Reserved
|
|
if ((aData[8]) || (aData[9])) bFault |= (1 << 0); // Bit 8 : Charge over temperature warning, Bit 9 : Discharge over temperature warning
|
|
else bFault &= ~(1 << 0);
|
|
i++; // 08
|
|
i++; // 09
|
|
if ((aData[10]) || (aData[11])) bFault |= (1 << 1); // Bit 10 : Charge low temperature warning, Bit 11 : Discharge low temperature warning
|
|
else bFault &= ~(1 << 1);
|
|
i++; // 10
|
|
i++; // 11
|
|
i++; // 12
|
|
i++; // 13
|
|
if (aData[i++]) bFault |= (1 << 9); // 14 Cell Voltage Difference Warning
|
|
else bFault &= ~(1 << 9);
|
|
break;
|
|
}
|
|
|
|
rSystemData.StatusData.protection = bFault;
|
|
rSystemData.StatusData.warning = bWarning;
|
|
|
|
return rSystemData;
|
|
}
|
|
|
|
public static void SetData(int index, double sdata, ref DeviceSystemData aSystemData)
|
|
{
|
|
switch (index)
|
|
{
|
|
case 0: aSystemData.ValueData.voltageOfPack = (short)(sdata / 100); break; // voltageOfPack
|
|
case 1: aSystemData.ValueData.current = (short)(sdata / 10); break; // current
|
|
case 2:
|
|
case 3:
|
|
case 4:
|
|
case 5:
|
|
case 6:
|
|
case 7:
|
|
case 8:
|
|
case 9:
|
|
case 10:
|
|
case 11:
|
|
case 12:
|
|
case 13:
|
|
case 14:
|
|
case 15:
|
|
case 16: aSystemData.ValueData.CellVoltage[index - 2] = (ushort)(sdata / 1); break; // CellVoltage14
|
|
case 17: aSystemData.ValueData.CellTemperature[0] = (short)(sdata / 1); break; // CellTemperature0
|
|
case 18: aSystemData.ValueData.CellTemperature[1] = (short)(sdata / 1); break; // CellTemperature1
|
|
case 19: aSystemData.ValueData.CellTemperature[2] = (short)(sdata / 1); break; // CellTemperature2
|
|
case 20: aSystemData.ValueData.CellTemperature[3] = (short)(sdata / 1); break; // CellTemperature3
|
|
case 21: aSystemData.ValueData.rSOC = (short)(sdata / 1); break; // Relatvie State Of Charge
|
|
case 22: aSystemData.ValueData.remainingCapacity = (short)(sdata / 1); break; // Remaining Capacity
|
|
case 23: aSystemData.ValueData.stateOfHealth = (short)(sdata / 1); break; // stateOfHealth
|
|
case 24: aSystemData.ValueData.cycleCount = (short)(sdata / 1); break; // cycleCount
|
|
|
|
case 25: aSystemData.AvgData.maxCellVoltage = (short)(sdata / 1); break; // maxCellVoltage
|
|
case 26: aSystemData.AvgData.minCellVoltage = (short)(sdata / 1); break; // minCellVoltage
|
|
case 27: aSystemData.AvgData.avgCellVoltage = (short)(sdata / 1); break; // avgCellVoltage
|
|
case 28: aSystemData.AvgData.diffCellVoltage = (short)(sdata / 1); break; // diffCellVoltage
|
|
case 29: aSystemData.StatusData.batteryStatus = (short)(sdata / 1); break; // batteryStatus
|
|
//case 37: aSystemData.StatusData.warning = (short)(sdata / 1); break; // warning
|
|
case 30: aSystemData = MakeAlarmTripData(0, (short)(sdata / 1), aSystemData); break; // warning
|
|
//case 38: aSystemData.StatusData.protection = (short)(sdata / 1); break; // OID-44 protection
|
|
case 31: aSystemData = MakeAlarmTripData(1, (short)(sdata / 1), aSystemData); break; // OID-44 protection
|
|
case 32: aSystemData.StatusData.status = (short)(sdata / 1); break; // status
|
|
case 33: aSystemData.StatusData.relayStatus = (short)(sdata / 1); break; // relayStatus
|
|
case 34: aSystemData.StatusData.cellBallanceStatus = (short)(sdata / 1); break; // cellBallanceStatus
|
|
case 35: aSystemData.StatusData.cellBalanceValue = (short)(sdata / 1); break; // cellBalanceValue
|
|
case 36: aSystemData.StatusData.cellBalanceFlag = (short)(sdata / 1); break; // cellBalanceFlag
|
|
case 37: aSystemData.AvgData.maxCellNum = (short)(sdata / 1); break; // maxCellNum
|
|
case 38: aSystemData.AvgData.minCellNum = (short)(sdata / 1); break; // minCellNum
|
|
//case 46: aSystemData.AvgData.maxTemp = (short)(sdata / 1); break; // maxTemp
|
|
//case 47: aSystemData.AvgData.minTemp = (short)(sdata / 1); break; // minTemp
|
|
//case 48: aSystemData.AvgData.maxTempNum = (short)(sdata / 1); break; // maxTempNum
|
|
//case 49: aSystemData.AvgData.minTempNum = (short)(sdata / 1); break; // minTempNum
|
|
}
|
|
}
|
|
|
|
public static void SetIdent(int index, object sdata, ref DeviceSystemTotalData aTotalData)
|
|
{
|
|
switch (index)
|
|
{
|
|
case 0: aTotalData.IdentData.Manufacturer = Convert.ToString(sdata); break; // Manufacturer
|
|
case 1: aTotalData.IdentData.DeviceModel = Convert.ToString(sdata); break; // Device Model
|
|
case 2: // F/W Version
|
|
if (aTotalData.IdentData.fw_ver == null)
|
|
aTotalData.IdentData.fw_ver = new byte[6];
|
|
|
|
Int32 ver = Convert.ToInt32(sdata.ToString());
|
|
aTotalData.IdentData.fw_ver[0] = (byte)(ver >> 24);
|
|
aTotalData.IdentData.fw_ver[1] = (byte)(ver >> 16);
|
|
aTotalData.IdentData.fw_ver[2] = (byte)(ver >> 8);
|
|
aTotalData.IdentData.fw_ver[3] = (byte)(ver >> 0);
|
|
break;
|
|
//case 3: aTotalData.IdentData.ModuleQuantity = Convert.ToInt32(sdata.ToString()); break; // Module Quantity
|
|
case 4: aTotalData.IdentData.AlarmOutputMode = Convert.ToInt32(sdata.ToString()); break; // Alarm Output Mode
|
|
case 5: aTotalData.IdentData.ManufactureDate = Convert.ToUInt32(sdata.ToString()); break; // Manufacture Date
|
|
case 6: aTotalData.IdentData.SerialNumber = Convert.ToString(sdata); break; // Serial Number
|
|
}
|
|
}
|
|
}
|
|
}
|