|
@@ -302,61 +302,36 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
{
|
|
|
foreach (var item in _request.meterValue)
|
|
|
{
|
|
|
- int registerCount = item.sampledValue.Where(x => x.measurand == Measurand.Energy_Active_Import_Interval).ToList().Count;
|
|
|
- if (registerCount > 0)
|
|
|
- {
|
|
|
- registerCount = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- registerCount = item.sampledValue.Where(x => x.measurand == Measurand.Energy_Active_Import_Register).ToList().Count;
|
|
|
- }
|
|
|
|
|
|
- if (registerCount > 0)
|
|
|
+ decimal meterStart = 0;
|
|
|
+ var energy_Register = item.sampledValue.Where(x => x.measurand == Measurand.Energy_Active_Import_Register).FirstOrDefault();
|
|
|
+
|
|
|
+ if (energy_Register != null)
|
|
|
{
|
|
|
- string voltage_text = item.sampledValue.Where(x => x.measurand == Measurand.Voltage).Select(x => x.value).FirstOrDefault();
|
|
|
- decimal voltage = decimal.Parse(voltage_text);
|
|
|
- string current_text = item.sampledValue.Where(x => x.measurand == Measurand.Current_Import).Select(x => x.value).FirstOrDefault();
|
|
|
- decimal current = decimal.Parse(current_text);
|
|
|
-
|
|
|
- decimal meterStart = 0;
|
|
|
- string energyRegister_text = item.sampledValue.Where(x => x.measurand == Measurand.Energy_Active_Import_Register).Select(x => x.value).FirstOrDefault();
|
|
|
- decimal energyRegister = decimal.Parse(energyRegister_text);
|
|
|
+ decimal energyRegister = decimal.Parse(energy_Register.value);
|
|
|
+ energyRegister = energy_Register.unit.Value == UnitOfMeasure.kWh ? decimal.Multiply(energyRegister, 1000) : energyRegister;
|
|
|
+
|
|
|
using (var maindb = new MainDBContext())
|
|
|
{
|
|
|
meterStart = maindb.TransactionRecord.Where(x => x.Id == _request.transactionId.Value).Select(x => x.MeterStart).FirstOrDefault();
|
|
|
}
|
|
|
-
|
|
|
- item.sampledValue.Add(new SampledValue()
|
|
|
- {
|
|
|
- context = ReadingContext.Sample_Periodic,
|
|
|
- format = ValueFormat.Raw,
|
|
|
- location = Location.Outlet,
|
|
|
- phase = Phase.L1_N,
|
|
|
- unit = UnitOfMeasure.kWh,
|
|
|
- measurand = Measurand.Energy_Active_Import_Interval,
|
|
|
- value = decimal.Divide(decimal.Subtract(energyRegister, meterStart), (decimal)1000).ToString()
|
|
|
- });
|
|
|
+
|
|
|
item.sampledValue.Add(new SampledValue()
|
|
|
{
|
|
|
context = ReadingContext.Sample_Periodic,
|
|
|
format = ValueFormat.Raw,
|
|
|
location = Location.Outlet,
|
|
|
- phase = Phase.L1_N,
|
|
|
- unit = UnitOfMeasure.kW,
|
|
|
- measurand = Measurand.Power_Active_Import,
|
|
|
- value = decimal.Divide(decimal.Multiply(voltage, current), (decimal)1000).ToString()
|
|
|
+ phase = item.sampledValue.Where(x => x.measurand == Measurand.Energy_Active_Import_Register).Select(x => x.phase).FirstOrDefault(),
|
|
|
+ unit = UnitOfMeasure.Wh,
|
|
|
+ measurand = Measurand.TotalEnergy,
|
|
|
+ value = decimal.Subtract(energyRegister, meterStart).ToString()
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
foreach (var sampleVaule in item.sampledValue)
|
|
|
{
|
|
|
-
|
|
|
- decimal value = Convert.ToDecimal(sampleVaule.value);
|
|
|
|
|
|
- if (sampleVaule.context == ReadingContext.Sample_Periodic && sampleVaule.measurand == Measurand.Energy_Active_Import_Interval)
|
|
|
- {
|
|
|
- energy_kwh = sampleVaule.unit == UnitOfMeasure.Wh ? Decimal.Divide(value, 1000) : value;
|
|
|
- }
|
|
|
+ decimal value = Convert.ToDecimal(sampleVaule.value);
|
|
|
|
|
|
string sp = "[dbo].[uspInsertMeterValueRecord] @ChargeBoxId," +
|
|
|
"@ConnectorId,@Value,@CreatedOn,@ContextId,@FormatId,@MeasurandId,@PhaseId,@LocationId,@UnitId,@TransactionId";
|
|
@@ -625,7 +600,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
|
|
|
|
|
|
await db.SaveChangesAsync();
|
|
|
-
|
|
|
+
|
|
|
|
|
|
if (session.IsBilling)
|
|
|
{
|
|
@@ -1088,7 +1063,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
currency = currency,
|
|
|
couponPoint = couponPoint,
|
|
|
accountBalance = accountBalance - tx.Cost,
|
|
|
- farewellMessage= farewellMessage
|
|
|
+ farewellMessage = farewellMessage
|
|
|
})
|
|
|
})
|
|
|
|