|
|
using BatCharging.Model;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace BatCharging.Service
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 解析充电记录上传
|
|
|
/// </summary>
|
|
|
public class MsgRecChaDecoder
|
|
|
{
|
|
|
public RecordCharg mRecordCharg(byte[] data)
|
|
|
{
|
|
|
RecordCharg mRecordCharg = null;
|
|
|
if (data != null && data.Length > 0)
|
|
|
{
|
|
|
mRecordCharg = new RecordCharg();
|
|
|
byte startSecond = data[24];
|
|
|
byte startMinute = data[25];
|
|
|
byte startHour = data[26];
|
|
|
byte startDay = data[27];
|
|
|
byte startMonth = data[28];
|
|
|
byte startYear = data[29];
|
|
|
byte endSecond = data[30];
|
|
|
byte endMinute = data[31];
|
|
|
byte endHour = data[32];
|
|
|
byte endDay = data[33];
|
|
|
byte endMonth = data[34];
|
|
|
byte endYear = data[35];
|
|
|
|
|
|
//string strStartYear = startYear.ToString().Length == 2 ? "20" + startYear.ToString() : "2" + startYear.ToString();
|
|
|
//string strEndYear = endYear.ToString().Length == 2 ? "20" + endYear.ToString() : "2" + endYear.ToString();
|
|
|
string strStartYear = (startYear + 1900).ToString();
|
|
|
string strEndYear = (endYear + 1900).ToString();
|
|
|
mRecordCharg.startTime = (
|
|
|
strStartYear + "-" +
|
|
|
startMonth.ToString().PadLeft(2, '0') + "-" +
|
|
|
startDay.ToString().PadLeft(2, '0') + " " +
|
|
|
startHour.ToString().PadLeft(2, '0') + ":" +
|
|
|
startMinute.ToString().PadLeft(2, '0') + ":" +
|
|
|
startSecond.ToString().PadLeft(2, '0'));
|
|
|
mRecordCharg.endTime = (
|
|
|
strEndYear + "-" +
|
|
|
endMonth.ToString().PadLeft(2, '0') + "-" +
|
|
|
endDay.ToString().PadLeft(2, '0') + " " +
|
|
|
endHour.ToString().PadLeft(2, '0') + ":" +
|
|
|
endMinute.ToString().PadLeft(2, '0') + ":" +
|
|
|
endSecond.ToString().PadLeft(2, '0'));
|
|
|
mRecordCharg.BeforeChargMeterData1 = ByteUtils.ToUInt32(data, 36) * (float)0.01;
|
|
|
mRecordCharg.AfterChargMeterData1 = ByteUtils.ToUInt32(data, 40) * (float)0.01;
|
|
|
mRecordCharg.BeforeChargMeterData2 = ByteUtils.ToUInt32(data, 44) * (float)0.01;
|
|
|
mRecordCharg.AfterChargMeterData2 = ByteUtils.ToUInt32(data, 48) * (float)0.01;
|
|
|
mRecordCharg.ChargeCapacity = Convert.ToSingle(ByteUtils.ToUInt32(data, 52)) * (float)0.01;
|
|
|
mRecordCharg.BeforeChargSOC = data[56];
|
|
|
mRecordCharg.AfterChargSOC = data[57];
|
|
|
mRecordCharg.NumberChargPeriods = data[58];
|
|
|
|
|
|
UInt32[] powersPeriods = new UInt32[4] { 0, 0, 0, 0 }; //元素索引顺序代表值;1:尖;2:峰;3:平;4:谷
|
|
|
mRecordCharg.StartTimePeriod1 = data[59].ToString() + ":" + data[60].ToString();
|
|
|
mRecordCharg.TimePeriodPower1 = ByteUtils.ToUInt32(data, 61) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier1 = data[65];
|
|
|
if (data[65] >= 1 && data[65] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[65] - 1] += ByteUtils.ToUInt32(data, 61);
|
|
|
}
|
|
|
|
|
|
mRecordCharg.StartTimePeriod2 = data[66].ToString() + ":" + data[67].ToString();
|
|
|
mRecordCharg.TimePeriodPower2 = ByteUtils.ToUInt32(data, 68) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier2 = data[72];
|
|
|
if (data[72] >= 1 && data[72] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[72] - 1] += ByteUtils.ToUInt32(data, 68);
|
|
|
}
|
|
|
|
|
|
mRecordCharg.StartTimePeriod3 = data[73].ToString() + ":" + data[74].ToString();
|
|
|
mRecordCharg.TimePeriodPower3 = ByteUtils.ToUInt32(data, 75) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier3 = data[79];
|
|
|
if (data[79] >= 1 && data[79] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[79] - 1] += ByteUtils.ToUInt32(data, 75);
|
|
|
}
|
|
|
|
|
|
mRecordCharg.StartTimePeriod4 = data[80].ToString() + ":" + data[81].ToString();
|
|
|
mRecordCharg.TimePeriodPower4 = ByteUtils.ToUInt32(data, 82) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier4 = data[86];
|
|
|
if (data[86] >= 1 && data[86] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[86] - 1] += ByteUtils.ToUInt32(data, 82);
|
|
|
}
|
|
|
|
|
|
mRecordCharg.StartTimePeriod5 = data[87].ToString() + ":" + data[88].ToString();
|
|
|
mRecordCharg.TimePeriodPower5 = ByteUtils.ToUInt32(data, 89) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier5 = data[93];
|
|
|
if (data[93] >= 1 && data[93] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[93] - 1] += ByteUtils.ToUInt32(data, 89);
|
|
|
}
|
|
|
|
|
|
mRecordCharg.StartTimePeriod6 = data[94].ToString() + ":" + data[95].ToString();
|
|
|
mRecordCharg.TimePeriodPower6 = ByteUtils.ToUInt32(data, 96) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier6 = data[100];
|
|
|
if (data[100] >= 1 && data[100] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[100] - 1] += ByteUtils.ToUInt32(data, 96);
|
|
|
}
|
|
|
|
|
|
mRecordCharg.StartTimePeriod7 = data[101].ToString() + ":" + data[102].ToString();
|
|
|
mRecordCharg.TimePeriodPower7 = ByteUtils.ToUInt32(data, 103) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier7 = data[107];
|
|
|
if (data[107] >= 1 && data[107] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[107] - 1] += ByteUtils.ToUInt32(data, 103);
|
|
|
}
|
|
|
|
|
|
mRecordCharg.StartTimePeriod8 = data[108].ToString() + ":" + data[109].ToString();
|
|
|
mRecordCharg.TimePeriodPower8 = ByteUtils.ToUInt32(data, 110) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier8 = data[114];
|
|
|
if (data[114] >= 1 && data[114] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[114] - 1] += ByteUtils.ToUInt32(data, 110);
|
|
|
}
|
|
|
|
|
|
mRecordCharg.StartTimePeriod9 = data[115].ToString() + ":" + data[116].ToString();
|
|
|
mRecordCharg.TimePeriodPower9 = ByteUtils.ToUInt32(data, 117) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier9 = data[121];
|
|
|
if (data[121] >= 1 && data[121] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[121] - 1] += ByteUtils.ToUInt32(data, 117);
|
|
|
}
|
|
|
|
|
|
mRecordCharg.StartTimePeriod10 = data[122].ToString() + ":" + data[123].ToString();
|
|
|
mRecordCharg.TimePeriodPower10 = ByteUtils.ToUInt32(data, 124) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier10 = data[128];
|
|
|
if (data[128] >= 1 && data[128] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[128] - 1] += ByteUtils.ToUInt32(data, 124);
|
|
|
}
|
|
|
|
|
|
|
|
|
mRecordCharg.StartTimePeriod11 = data[129].ToString() + ":" + data[130].ToString();
|
|
|
mRecordCharg.TimePeriodPower11 = ByteUtils.ToUInt32(data, 131) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier11 = data[135];
|
|
|
if (data[135] >= 1 && data[135] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[135] - 1] += ByteUtils.ToUInt32(data, 131);
|
|
|
}
|
|
|
|
|
|
|
|
|
mRecordCharg.StartTimePeriod12 = data[136].ToString() + ":" + data[137].ToString();
|
|
|
mRecordCharg.TimePeriodPower12 = ByteUtils.ToUInt32(data, 138) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier12 = data[142];
|
|
|
if (data[142] >= 1 && data[142] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[142] - 1] += ByteUtils.ToUInt32(data, 138);
|
|
|
}
|
|
|
|
|
|
|
|
|
mRecordCharg.StartTimePeriod13 = data[143].ToString() + ":" + data[144].ToString();
|
|
|
mRecordCharg.TimePeriodPower13 = ByteUtils.ToUInt32(data, 145) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier13 = data[149];
|
|
|
if (data[149] >= 1 && data[149] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[149] - 1] += ByteUtils.ToUInt32(data, 145);
|
|
|
}
|
|
|
|
|
|
|
|
|
mRecordCharg.StartTimePeriod14 = data[150].ToString() + ":" + data[151].ToString();
|
|
|
mRecordCharg.TimePeriodPower14 = ByteUtils.ToUInt32(data, 152) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier14 = data[156];
|
|
|
if (data[156] >= 1 && data[156] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[156] - 1] += ByteUtils.ToUInt32(data, 152);
|
|
|
}
|
|
|
|
|
|
mRecordCharg.StartTimePeriod15 = data[157].ToString() + ":" + data[158].ToString();
|
|
|
mRecordCharg.TimePeriodPower15 = ByteUtils.ToUInt32(data, 159) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier15 = data[163];
|
|
|
if (data[163] >= 1 && data[163] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[163] - 1] += ByteUtils.ToUInt32(data, 159);
|
|
|
}
|
|
|
|
|
|
|
|
|
mRecordCharg.StartTimePeriod16 = data[164].ToString() + ":" + data[165].ToString();
|
|
|
mRecordCharg.TimePeriodPower16 = ByteUtils.ToUInt32(data, 166) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier16 = data[170];
|
|
|
if (data[170] >= 1 && data[170] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[170] - 1] += ByteUtils.ToUInt32(data, 166);
|
|
|
}
|
|
|
|
|
|
|
|
|
mRecordCharg.StartTimePeriod17 = data[171].ToString() + ":" + data[172].ToString();
|
|
|
mRecordCharg.TimePeriodPower17 = ByteUtils.ToUInt32(data, 173) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier17 = data[177];
|
|
|
if (data[177] >= 1 && data[177] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[177] - 1] += ByteUtils.ToUInt32(data, 173);
|
|
|
}
|
|
|
|
|
|
|
|
|
mRecordCharg.StartTimePeriod18 = data[178].ToString() + ":" + data[179].ToString();
|
|
|
mRecordCharg.TimePeriodPower18 = ByteUtils.ToUInt32(data, 180) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier18 = data[184];
|
|
|
if (data[184] >= 1 && data[184] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[184] - 1] += ByteUtils.ToUInt32(data, 180);
|
|
|
}
|
|
|
|
|
|
|
|
|
mRecordCharg.StartTimePeriod19 = data[185].ToString() + ":" + data[186].ToString();
|
|
|
mRecordCharg.TimePeriodPower19 = ByteUtils.ToUInt32(data, 187) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier19 = data[191];
|
|
|
if (data[191] >= 1 && data[191] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[191] - 1] += ByteUtils.ToUInt32(data, 187);
|
|
|
}
|
|
|
|
|
|
mRecordCharg.StartTimePeriod20 = data[192].ToString() + ":" + data[193].ToString();
|
|
|
mRecordCharg.TimePeriodPower20 = ByteUtils.ToUInt32(data, 194) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier20 = data[198];
|
|
|
if (data[198] >= 1 && data[198] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[198] - 1] += ByteUtils.ToUInt32(data, 194);
|
|
|
}
|
|
|
|
|
|
|
|
|
mRecordCharg.StartTimePeriod21 = data[199].ToString() + ":" + data[200].ToString();
|
|
|
mRecordCharg.TimePeriodPower21 = ByteUtils.ToUInt32(data, 201) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier21 = data[205];
|
|
|
if (data[205] >= 1 && data[205] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[192058] - 1] += ByteUtils.ToUInt32(data, 201);
|
|
|
}
|
|
|
|
|
|
mRecordCharg.StartTimePeriod22 = data[206].ToString() + ":" + data[207].ToString();
|
|
|
mRecordCharg.TimePeriodPower22 = ByteUtils.ToUInt32(data, 208) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier22 = data[212];
|
|
|
if (data[212] >= 1 && data[212] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[212] - 1] += ByteUtils.ToUInt32(data, 208);
|
|
|
}
|
|
|
|
|
|
mRecordCharg.StartTimePeriod23 = data[213].ToString() + ":" + data[214].ToString();
|
|
|
mRecordCharg.TimePeriodPower23 = ByteUtils.ToUInt32(data, 215) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier23 = data[219];
|
|
|
if (data[219] >= 1 && data[219] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[219] - 1] += ByteUtils.ToUInt32(data, 215);
|
|
|
}
|
|
|
|
|
|
mRecordCharg.StartTimePeriod24 = data[220].ToString() + ":" + data[221].ToString();
|
|
|
mRecordCharg.TimePeriodPower24 = ByteUtils.ToUInt32(data, 222) * (float)0.01;
|
|
|
mRecordCharg.PeriodIdentifier24 = data[226];
|
|
|
if (data[226] >= 1 && data[226] <= 4)
|
|
|
{
|
|
|
powersPeriods[data[226] - 1] += ByteUtils.ToUInt32(data, 222);
|
|
|
}
|
|
|
|
|
|
mRecordCharg.SharpPeriodPower = Convert.ToSingle(powersPeriods[0] * 0.01);
|
|
|
mRecordCharg.PeakPeriodPower = Convert.ToSingle(powersPeriods[1] * 0.01);
|
|
|
mRecordCharg.FlatPeriodPower = Convert.ToSingle(powersPeriods[2] * 0.01);
|
|
|
mRecordCharg.ValleyPeriodPower = Convert.ToSingle(powersPeriods[3] * 0.01);
|
|
|
|
|
|
mRecordCharg.BeforeAcTableValue = Convert.ToSingle(ByteUtils.ToUInt32(data, 227)) * (float)0.01;
|
|
|
mRecordCharg.AfterAcTableValue = Convert.ToSingle(ByteUtils.ToUInt32(data, 231)) * (float)0.01;
|
|
|
mRecordCharg.StartMode = data[235];
|
|
|
}
|
|
|
return mRecordCharg;
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|