|
@@ -147,10 +147,13 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
}
|
|
|
if (_request.messageId == "ConnectorUnplugged")
|
|
|
{
|
|
|
+ logger.Debug("ConnectorUnplugged");
|
|
|
JObject jo = JObject.Parse(_request.data);
|
|
|
|
|
|
var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
|
|
|
- await businessService.NotifyConnectorUnplugged(session.ChargeBoxId, jo["txId"].Value<string>(), jo["timestamp"].Value<string>());
|
|
|
+ await businessService.NotifyConnectorUnplugged(session.ChargeBoxId, jo["idTx"].Value<string>(), jo["timestamp"].Value<string>());
|
|
|
+
|
|
|
+ confirm.status = DataTransferStatus.Accepted;
|
|
|
}
|
|
|
result.Message = confirm;
|
|
|
result.Success = true;
|
|
@@ -299,8 +302,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
case Actions.MeterValues:
|
|
|
{
|
|
|
|
|
|
- MeterValuesRequest _request = request as MeterValuesRequest;
|
|
|
- decimal energy_kwh = 0;
|
|
|
+ MeterValuesRequest _request = request as MeterValuesRequest;
|
|
|
|
|
|
if (_request.meterValue.Count > 0)
|
|
|
{
|
|
@@ -310,59 +312,11 @@ 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)
|
|
|
- {
|
|
|
- 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);
|
|
|
- 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()
|
|
|
- });
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
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";
|
|
@@ -771,6 +725,32 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
if (feedto == null || string.IsNullOrEmpty(feedto.Fee)) return result;
|
|
|
string currency = feedto.Fee.Substring(feedto.Fee.Length - 3);
|
|
|
decimal chargingCost = 0;
|
|
|
+
|
|
|
+ using (var meterdb = new MeterValueDBContext())
|
|
|
+ {
|
|
|
+ string sp = "[dbo].[uspInsertMeterValueRecord] @ChargeBoxId," +
|
|
|
+ "@ConnectorId,@Value,@CreatedOn,@ContextId,@FormatId,@MeasurandId,@PhaseId,@LocationId,@UnitId,@TransactionId";
|
|
|
+
|
|
|
+ List<SqlParameter> parameter = new List<SqlParameter>
|
|
|
+ {
|
|
|
+ new SqlParameter("ChargeBoxId",session.ChargeBoxId),
|
|
|
+ new SqlParameter("ConnectorId", (byte)feedto.ConnectorId),
|
|
|
+ new SqlParameter("Value",txEnergy.PeriodEnergy.Sum(x=>x.Value)),
|
|
|
+ new SqlParameter("CreatedOn",DateTime.UtcNow),
|
|
|
+ new SqlParameter("ContextId",(int)ReadingContext.Sample_Periodic),
|
|
|
+ new SqlParameter("FormatId",(int)ValueFormat.Raw),
|
|
|
+ new SqlParameter("MeasurandId",(int)Measurand.TotalEnergy),
|
|
|
+ new SqlParameter("PhaseId", -1),
|
|
|
+ new SqlParameter("LocationId", -1),
|
|
|
+ new SqlParameter("UnitId", (int)UnitOfMeasure.kWh),
|
|
|
+ new SqlParameter("TransactionId",feedto.Id),
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ meterdb.Database.ExecuteSqlCommand(sp, parameter.ToArray());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
if (feedto.Fee.Length > 58)
|
|
|
{
|
|
|
chargingPrices = JsonConvert.DeserializeObject<List<ChargingPrice>>(feedto.Fee.Split('|')[0]);
|