|
@@ -16,6 +16,7 @@ using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
using System.Diagnostics;
|
|
|
+using EVCB_OCPP.Domain.Models.Database;
|
|
|
|
|
|
namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
{
|
|
@@ -26,15 +27,15 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
[Route("api/v1/cpo")]
|
|
|
public class CPOController : ControllerBase
|
|
|
{
|
|
|
- private readonly IServiceProvider serviceProvider;
|
|
|
- private readonly ILogger<CPOController> logger;
|
|
|
-
|
|
|
public CPOController(IServiceProvider serviceProvider, IConfiguration configuration, ILogger<CPOController> logger)
|
|
|
{
|
|
|
this.serviceProvider = serviceProvider;
|
|
|
this.logger = logger;
|
|
|
}
|
|
|
|
|
|
+ private readonly IServiceProvider serviceProvider;
|
|
|
+ private readonly ILogger<CPOController> logger;
|
|
|
+
|
|
|
[Route("station")]
|
|
|
[HttpGet]
|
|
|
public async Task<IActionResult> Station()
|
|
@@ -42,21 +43,25 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
var result = new CPOOuterResponse();
|
|
|
//HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
|
|
|
int statusCode = StatusCodes.Status500InternalServerError;
|
|
|
+
|
|
|
try
|
|
|
{
|
|
|
- if (Request.Headers.ContainsKey(EVCBConfiguration.Header_PartnerId))
|
|
|
+ if (!IsCustomerIdAvaliable())
|
|
|
{
|
|
|
- var _customerId = Request.Headers[EVCBConfiguration.Header_PartnerId].First();
|
|
|
- ChargingStationService _service = serviceProvider.GetRequiredService<ChargingStationService>();
|
|
|
+ return StatusCode(statusCode, result);
|
|
|
+ }
|
|
|
|
|
|
- var _innerResponse = new { Stations = await _service.GetStationsbyCustomerIdAsync(_customerId) };
|
|
|
+ var _customerId = GetCustomerId();
|
|
|
|
|
|
- result.Data = JsonConvert.SerializeObject(_innerResponse, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
- result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
- result.StatusMessage = CPO_StatusMessage.Success;
|
|
|
- //statusCode = HttpStatusCode.OK;
|
|
|
- statusCode = StatusCodes.Status200OK;
|
|
|
- }
|
|
|
+ ChargingStationService _service = serviceProvider.GetRequiredService<ChargingStationService>();
|
|
|
+
|
|
|
+ var _innerResponse = new { Stations = await _service.GetStationsbyCustomerIdAsync(_customerId) };
|
|
|
+
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerResponse, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.Success;
|
|
|
+ //statusCode = HttpStatusCode.OK;
|
|
|
+ statusCode = StatusCodes.Status200OK;
|
|
|
//return Request.CreateResponse(statusCode, result);
|
|
|
return StatusCode(statusCode, result);
|
|
|
}
|
|
@@ -68,9 +73,6 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
//return Request.CreateResponse(statusCode, result);
|
|
|
return StatusCode(statusCode, result);
|
|
|
}
|
|
|
- finally
|
|
|
- {
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
[Route("information")]
|
|
@@ -86,49 +88,52 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
{
|
|
|
ChargePointService _CPService = serviceProvider.GetRequiredService<ChargePointService>();// new ChargePointService();
|
|
|
var tt = _CPService.GetLastUpdatedTimebyMachineId("0da4f4a6-a952-46f0-b2f3-696385a9a56a");
|
|
|
- if (Request.Headers.ContainsKey(EVCBConfiguration.Header_PartnerId))
|
|
|
+ if (!IsCustomerIdAvaliable())
|
|
|
{
|
|
|
- var _customerId = Request.Headers[EVCBConfiguration.Header_PartnerId].First();
|
|
|
+ //return Request.CreateResponse(statusCode, result);
|
|
|
+ return StatusCode(statusCode, result);
|
|
|
+ }
|
|
|
|
|
|
- var _innerResponse = new { EVSEs = new List<EVSE>() };
|
|
|
- ChargingStationService _stationService = serviceProvider.GetRequiredService<ChargingStationService>();// new ChargingStationService();
|
|
|
+ var _customerId = GetCustomerId();
|
|
|
|
|
|
- if (StationId > -1)
|
|
|
+ var _innerResponse = new { EVSEs = new List<EVSE>() };
|
|
|
+ ChargingStationService _stationService = serviceProvider.GetRequiredService<ChargingStationService>();// new ChargingStationService();
|
|
|
+
|
|
|
+ if (StationId > -1)
|
|
|
+ {
|
|
|
+ if (_stationService.ContainsStation(_customerId, StationId))
|
|
|
{
|
|
|
- if (_stationService.ContainsStation(_customerId, StationId))
|
|
|
+ if (DateTo.HasValue)
|
|
|
{
|
|
|
- if (DateTo.HasValue)
|
|
|
+ if (!DateFrom.HasValue)
|
|
|
{
|
|
|
- if (!DateFrom.HasValue)
|
|
|
- {
|
|
|
-
|
|
|
- result.StatusMessage = CPO_StatusMessage.ERROR_MSG_PARAMETER_OUTOFRANGE_INCORRECT;
|
|
|
- result.StatusCode = (int)CPO_StatusCode.PARAMETER_OUTOFRANGE_INCORRECT;
|
|
|
- //statusCode = HttpStatusCode.BadRequest;
|
|
|
- statusCode = StatusCodes.Status400BadRequest;
|
|
|
- //return Request.CreateResponse(statusCode, result);
|
|
|
- return StatusCode(statusCode, result);
|
|
|
- }
|
|
|
- }
|
|
|
- _innerResponse = new { EVSEs = _stationService.GetEVSEsbyStationId(StationId, DateFrom, DateTo, Offset.Value, Limit == -1 ? 1000 : Limit.Value) };
|
|
|
-
|
|
|
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_PARAMETER_OUTOFRANGE_INCORRECT;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.PARAMETER_OUTOFRANGE_INCORRECT;
|
|
|
+ //statusCode = HttpStatusCode.BadRequest;
|
|
|
+ statusCode = StatusCodes.Status400BadRequest;
|
|
|
+ //return Request.CreateResponse(statusCode, result);
|
|
|
+ return StatusCode(statusCode, result);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _innerResponse = new { EVSEs = new List<EVSE>() };
|
|
|
- _innerResponse.EVSEs.Add(_CPService.GetEVSEsbyChargeBoxId(ChargeBoxId, DateFrom, DateTo));
|
|
|
+ _innerResponse = new { EVSEs = _stationService.GetEVSEsbyStationId(StationId, DateFrom, DateTo, Offset.Value, Limit == -1 ? 1000 : Limit.Value) };
|
|
|
|
|
|
|
|
|
}
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _innerResponse = new { EVSEs = new List<EVSE>() };
|
|
|
+ _innerResponse.EVSEs.Add(_CPService.GetEVSEsbyChargeBoxId(ChargeBoxId, DateFrom, DateTo));
|
|
|
+
|
|
|
|
|
|
- result.Data = JsonConvert.SerializeObject(_innerResponse, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
- result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
- result.StatusMessage = CPO_StatusMessage.Success;
|
|
|
- //statusCode = HttpStatusCode.OK;
|
|
|
- statusCode = StatusCodes.Status200OK;
|
|
|
}
|
|
|
+
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerResponse, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.Success;
|
|
|
+ //statusCode = HttpStatusCode.OK;
|
|
|
+ statusCode = StatusCodes.Status200OK;
|
|
|
//return Request.CreateResponse(statusCode, result);
|
|
|
return StatusCode(statusCode, result);
|
|
|
}
|
|
@@ -154,9 +159,10 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
var _innerData = new { Result = CommandResponseType.Rejected.ToString(), Timeout = 60 };
|
|
|
try
|
|
|
{
|
|
|
- string _CustomerId = string.Empty;
|
|
|
+ string _CustomerId = GetCustomerId();
|
|
|
+ logger.LogTrace($"StartSession {request.ChargeBoxId} {_CustomerId}");
|
|
|
|
|
|
- if (!ContainsChargePoint(request.ChargeBoxId, out _CustomerId))
|
|
|
+ if (!await ContainsChargePointAsync(request.ChargeBoxId, _CustomerId))
|
|
|
{
|
|
|
// 沒槍~ 沒得充...
|
|
|
result.StatusMessage = CPO_StatusMessage.ERROR_MSG_CHARGEBOXID_DOESNT_EXIST;
|
|
@@ -171,9 +177,12 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
|
|
|
ChargePointService _CPService = serviceProvider.GetRequiredService<ChargePointService>();
|
|
|
|
|
|
- if (!string.IsNullOrEmpty(request.ChargeBoxId) && request.ChargeBoxId.Length <= 25 && (!request.ConnectorId.HasValue
|
|
|
- || (_CPService.GetNumberofConnectors(request.ChargeBoxId) >= request.ConnectorId && request.ConnectorId > 0))
|
|
|
- && !string.IsNullOrEmpty(request.Token) && request.Token.Length <= 20)
|
|
|
+ if (!string.IsNullOrEmpty(request.ChargeBoxId) &&
|
|
|
+ request.ChargeBoxId.Length <= 25 &&
|
|
|
+ (!request.ConnectorId.HasValue ||
|
|
|
+ (_CPService.GetNumberofConnectors(request.ChargeBoxId) >= request.ConnectorId && request.ConnectorId > 0)) &&
|
|
|
+ !string.IsNullOrEmpty(request.Token) &&
|
|
|
+ request.Token.Length <= 20)
|
|
|
{
|
|
|
InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
|
|
|
ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
|
|
@@ -183,7 +192,6 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
{
|
|
|
ConnectorId = request.ConnectorId,
|
|
|
IdTag = request.Token
|
|
|
-
|
|
|
};
|
|
|
|
|
|
string urlformat = "{0}://{1}";
|
|
@@ -258,9 +266,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
var _innerData = new { Result = CommandResponseType.Rejected.ToString(), Timeout = 60 };
|
|
|
try
|
|
|
{
|
|
|
- string _CustomerId = string.Empty;
|
|
|
+ string _CustomerId = GetCustomerId();
|
|
|
|
|
|
- if (!ContainsChargePoint(ChargeBoxId, out _CustomerId))
|
|
|
+ if (!await ContainsChargePointAsync(ChargeBoxId, _CustomerId))
|
|
|
{
|
|
|
// 沒槍~ 沒得充...
|
|
|
result.StatusMessage = CPO_StatusMessage.ERROR_MSG_CHARGEBOXID_DOESNT_EXIST;
|
|
@@ -1186,7 +1194,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
[Route("activesession")]
|
|
|
[Produces(typeof(CPOOuterResponse))]
|
|
|
[HttpGet]
|
|
|
- public IActionResult ActiveSession(string ChargeBoxId, string SessionId = "", string IdTag = "")
|
|
|
+ public async Task<IActionResult> ActiveSession(string ChargeBoxId, int? SessionId = null, string IdTag = null)
|
|
|
{
|
|
|
var result = new CPOOuterResponse();
|
|
|
//HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
|
|
@@ -1194,9 +1202,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
|
|
|
try
|
|
|
{
|
|
|
- string _CustomerId = string.Empty;
|
|
|
+ string _CustomerId = GetCustomerId();
|
|
|
|
|
|
- if (!ContainsChargePoint(ChargeBoxId, out _CustomerId))
|
|
|
+ if (!await ContainsChargePointAsync(ChargeBoxId, _CustomerId))
|
|
|
{
|
|
|
// 沒槍~ 沒得充...
|
|
|
result.StatusMessage = CPO_StatusMessage.ERROR_MSG_CHARGEBOXID_DOESNT_EXIST;
|
|
@@ -1209,66 +1217,40 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
|
|
|
// query meter value
|
|
|
ChargePointService _service = serviceProvider.GetRequiredService<ChargePointService>();
|
|
|
- var transactionDatas = _service.GetActiveSessionInfo(ChargeBoxId, new List<Measurand>()
|
|
|
+ var transactionDatas = await _service.GetActiveSessionInfoAsync(ChargeBoxId, new List<Measurand>()
|
|
|
{ Measurand.Voltage,
|
|
|
Measurand.Current_Import,
|
|
|
Measurand.SoC,
|
|
|
Measurand.Power_Active_Import,
|
|
|
Measurand.TotalEnergy,
|
|
|
Measurand.ChargingCost
|
|
|
- }, SessionId, IdTag);
|
|
|
+ }, _CustomerId, SessionId, IdTag);
|
|
|
|
|
|
- if (transactionDatas == null)
|
|
|
+ if (transactionDatas is null)
|
|
|
{
|
|
|
result.StatusCode = (int)CPO_StatusCode.CANT_FOUND_DATA;
|
|
|
result.StatusMessage = CPO_StatusMessage.ERROR_MSG_CANT_FIND_RESULT;
|
|
|
//statusCode = HttpStatusCode.NotFound;
|
|
|
statusCode = StatusCodes.Status404NotFound;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- List<ActiveSession> _innerData = new();
|
|
|
|
|
|
- foreach (var transactionData in transactionDatas)
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
- string currencyText = string.IsNullOrEmpty(transactionData.Fee) ? "TWD" : transactionData.Fee.Remove(0, transactionData.Fee.Length - 3);
|
|
|
+ return StatusCode(statusCode, result);
|
|
|
+ }
|
|
|
|
|
|
- _innerData.Add(new ActiveSession()
|
|
|
- {
|
|
|
+ List<ActiveSession> _innerData = new();
|
|
|
|
|
|
- ChargeBoxId = ChargeBoxId,
|
|
|
- SessionId = transactionData.Id,
|
|
|
- ElaspedTime = (int)DateTime.UtcNow.Subtract(transactionData.StartTime).TotalMinutes,
|
|
|
- ConnectorId = transactionData.ConnectorId,
|
|
|
- IdTag = transactionData.StartIdTag,
|
|
|
- Power = transactionData.MeterValues == null ? "0" : transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Power_Active_Import).Select(x => x.Value).FirstOrDefault(),
|
|
|
- Power_Format = transactionData.MeterValues == null ? UnitOfMeasure.W.ToString() : transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Power_Active_Import).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
|
- Current = transactionData.MeterValues == null ? "0" : transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Current_Import).Select(x => x.Value).FirstOrDefault(),
|
|
|
- Current_Format = transactionData.MeterValues == null ? UnitOfMeasure.A.ToString() : transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Current_Import).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
|
- Energy = transactionData.MeterValues == null ? "0" : transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.TotalEnergy).Select(x => x.Value).FirstOrDefault(),
|
|
|
- Energy_Format = transactionData.MeterValues == null ? UnitOfMeasure.Wh.ToString() : transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.TotalEnergy).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
|
- Voltage = transactionData.MeterValues == null ? "0" : transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Voltage).Select(x => x.Value).FirstOrDefault(),
|
|
|
- Voltage_Format = transactionData.MeterValues == null ? UnitOfMeasure.V.ToString() : transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Voltage).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
|
- SOC = transactionData.MeterValues == null ? "0" : transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.SoC).Select(x => x.Unit.ToString()).FirstOrDefault() == null ? null : transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.SoC).Select(x => x.Value).FirstOrDefault(),
|
|
|
- SOC_Format = transactionData.MeterValues == null ? UnitOfMeasure.Percent.ToString() : transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.SoC).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
|
- CurrentCost = transactionData.MeterValues == null ? "0" : transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.ChargingCost).Select(x => x.Value).FirstOrDefault(),
|
|
|
- Currency = currencyText
|
|
|
- });
|
|
|
- decimal energy = decimal.Parse(_innerData[_innerData.Count - 1].Energy);
|
|
|
- energy = _innerData[^1].Energy_Format == UnitOfMeasure.Wh.ToString() ? Decimal.Divide(energy, 1000) : energy;
|
|
|
- _innerData[^1].Energy = energy.ToString("0.000");
|
|
|
- _innerData[^1].Energy_Format = UnitOfMeasure.kWh.ToString();
|
|
|
- }
|
|
|
- var _innerResponse = new { Sessions = _innerData };
|
|
|
- result.Data = JsonConvert.SerializeObject(_innerResponse, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ foreach (TransasctionData transactionData in transactionDatas)
|
|
|
+ {
|
|
|
+ string currencyText = string.IsNullOrEmpty(transactionData.Fee) ? "TWD" : transactionData.Fee.Remove(0, transactionData.Fee.Length - 3);
|
|
|
|
|
|
- result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
- result.StatusMessage = CPO_StatusMessage.Success;
|
|
|
- //statusCode = HttpStatusCode.OK;
|
|
|
- statusCode = StatusCodes.Status200OK;
|
|
|
+ _innerData.Add(ToActiveSession(ChargeBoxId, transactionData));
|
|
|
}
|
|
|
+ var _innerResponse = new { Sessions = _innerData };
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerResponse, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.Success;
|
|
|
+ //statusCode = HttpStatusCode.OK;
|
|
|
+ statusCode = StatusCodes.Status200OK;
|
|
|
|
|
|
//return Request.CreateResponse(statusCode, result);
|
|
|
return StatusCode(statusCode, result);
|
|
@@ -1794,16 +1776,102 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
private bool ContainsChargePoint(string chargeBoxId, out string customerId)
|
|
|
{
|
|
|
customerId = string.Empty;
|
|
|
+ if (!IsCustomerIdAvaliable())
|
|
|
+ return false;
|
|
|
+ customerId = GetCustomerId();
|
|
|
|
|
|
- if (!Request.Headers.ContainsKey(EVCBConfiguration.Header_PartnerId)) return false;
|
|
|
-
|
|
|
- customerId = Request.Headers[EVCBConfiguration.Header_PartnerId].First();
|
|
|
+ return ContainsChargePointAsync(chargeBoxId, customerId).Result;
|
|
|
+ }
|
|
|
|
|
|
+ private ValueTask<bool> ContainsChargePointAsync(string chargeBoxId, string customerId)
|
|
|
+ {
|
|
|
ChargePointService _service = serviceProvider.GetRequiredService<ChargePointService>();//;new ChargePointService();
|
|
|
- return _service.ContainsChargePoint(chargeBoxId, customerId);
|
|
|
+ return _service.ContainsChargePointAsync(chargeBoxId, customerId);
|
|
|
+ }
|
|
|
|
|
|
+ private string GetCustomerId()
|
|
|
+ {
|
|
|
+ if (!IsCustomerIdAvaliable())
|
|
|
+ return string.Empty;
|
|
|
+ return Request.Headers[EVCBConfiguration.Header_PartnerId].First();
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool IsCustomerIdAvaliable()
|
|
|
+ {
|
|
|
+ return Request.Headers.ContainsKey(EVCBConfiguration.Header_PartnerId);
|
|
|
}
|
|
|
|
|
|
+ private ActiveSession ToActiveSession(string ChargeBoxId, TransasctionData trans)
|
|
|
+ {
|
|
|
+ string currencyText = string.IsNullOrEmpty(trans.Fee) ? "TWD" : trans.Fee.Remove(0, trans.Fee.Length - 3);
|
|
|
+
|
|
|
+ var toRerurn = new ActiveSession()
|
|
|
+ {
|
|
|
+ ChargeBoxId = ChargeBoxId,
|
|
|
+ SessionId = trans.Id,
|
|
|
+ ElaspedTime = (int)DateTime.UtcNow.Subtract(trans.StartTime).TotalMinutes,
|
|
|
+ ConnectorId = trans.ConnectorId,
|
|
|
+ IdTag = trans.StartIdTag,
|
|
|
+ Currency = currencyText
|
|
|
+ };
|
|
|
+
|
|
|
+ toRerurn.Power = "0";
|
|
|
+ toRerurn.Power_Format = UnitOfMeasure.W.ToString();
|
|
|
+ toRerurn.Current = "0";
|
|
|
+ toRerurn.Current_Format = UnitOfMeasure.A.ToString();
|
|
|
+ toRerurn.Energy = "0";
|
|
|
+ toRerurn.Energy_Format = UnitOfMeasure.Wh.ToString();
|
|
|
+ toRerurn.Voltage = "0";
|
|
|
+ toRerurn.Voltage_Format = UnitOfMeasure.V.ToString();
|
|
|
+ toRerurn.SOC = "0";
|
|
|
+ toRerurn.SOC_Format = UnitOfMeasure.Percent.ToString();
|
|
|
+ toRerurn.CurrentCost = "0";
|
|
|
+
|
|
|
+ Models.ConnectorMeterValue power = trans.MeterValues.FirstOrDefault(x => x.Measurand == Measurand.Power_Active_Import);
|
|
|
+ if (power is not null)
|
|
|
+ {
|
|
|
+ toRerurn.Power = power.Value;
|
|
|
+ toRerurn.Power_Format = power.Unit.ToString();
|
|
|
+ }
|
|
|
+ Models.ConnectorMeterValue current = trans.MeterValues.FirstOrDefault(x => x.Measurand == Measurand.Current_Import);
|
|
|
+ if (current is not null)
|
|
|
+ {
|
|
|
+ toRerurn.Current = current.Value;
|
|
|
+ toRerurn.Current_Format = current.Unit.ToString();
|
|
|
+ }
|
|
|
+ Models.ConnectorMeterValue _energy = trans.MeterValues.FirstOrDefault(x => x.Measurand == Measurand.TotalEnergy);
|
|
|
+ if (_energy is not null)
|
|
|
+ {
|
|
|
+ toRerurn.Energy = _energy.Value;
|
|
|
+ toRerurn.Energy_Format = _energy.Unit.ToString();
|
|
|
+ }
|
|
|
+ Models.ConnectorMeterValue voltage = trans.MeterValues.FirstOrDefault(x => x.Measurand == Measurand.Voltage);
|
|
|
+ if (voltage is not null)
|
|
|
+ {
|
|
|
+ toRerurn.Voltage = voltage.Value;
|
|
|
+ toRerurn.Voltage_Format = voltage.Unit.ToString();
|
|
|
+ }
|
|
|
+ Models.ConnectorMeterValue soc = trans.MeterValues.FirstOrDefault(x => x.Measurand == Measurand.SoC);
|
|
|
+ if (soc is not null)
|
|
|
+ {
|
|
|
+ toRerurn.SOC = soc.Value;
|
|
|
+ toRerurn.SOC_Format = soc.Unit.ToString();
|
|
|
+ }
|
|
|
+ Models.ConnectorMeterValue cost = trans.MeterValues.FirstOrDefault(x => x.Measurand == Measurand.ChargingCost);
|
|
|
+ if (cost is not null)
|
|
|
+ {
|
|
|
+ toRerurn.CurrentCost = cost.Value;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (toRerurn.Energy_Format == UnitOfMeasure.Wh.ToString())
|
|
|
+ {
|
|
|
+ decimal energy = decimal.Parse(toRerurn.Energy);
|
|
|
+ energy = Decimal.Divide(energy, 1000);
|
|
|
+ toRerurn.Energy = energy.ToString("0.000");
|
|
|
+ toRerurn.Energy_Format = UnitOfMeasure.kWh.ToString();
|
|
|
+ }
|
|
|
|
|
|
+ return toRerurn;
|
|
|
+ }
|
|
|
}
|
|
|
}
|