Forráskód Böngészése

2020/10/07 Jessica
Actions:
1. Packet DLL 替換
2. 新增DataTransfer
3.Connector參數

Jessica Tseng 4 éve
szülő
commit
a8e80c64cd

+ 116 - 52
EVCB_OCPP.WEBAPI/Controllers/Version1/CPOController.cs

@@ -72,7 +72,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
         [Route("information")]
         [ResponseType(typeof(CPOOuterResponse))]
         [HttpGet]
-        public HttpResponseMessage BasicInformationofEVSEs(int StationId, DateTime? DateFrom = null, DateTime? DateTo = null, int? Offset = 0, int? Limit = 1)
+        public HttpResponseMessage BasicInformationofEVSEs(int StationId = -1, string ChargeBoxId = "", DateTime? DateFrom = null, DateTime? DateTo = null, int? Offset = 0, int? Limit = 1)
         {
 
             var result = new CPOOuterResponse();
@@ -88,23 +88,34 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     var _innerResponse = new { EVSEs = new List<EVSE>() };
                     ChargingStationService _stationService = new ChargingStationService();
 
-                    if (_stationService.ContainsStation(_customerId, StationId))
+                    if (StationId > -1)
                     {
-                        if (DateTo.HasValue)
+                        if (_stationService.ContainsStation(_customerId, StationId))
                         {
-                            if (!DateFrom.HasValue)
+                            if (DateTo.HasValue)
                             {
-
-                                result.StatusMessage = CPO_StatusMessage.ERROR_MSG_PARAMETER_OUTOFRANGE_INCORRECT;
-                                result.StatusCode = (int)CPO_StatusCode.PARAMETER_OUTOFRANGE_INCORRECT;
-                                statusCode = HttpStatusCode.BadRequest;
-                                return Request.CreateResponse(statusCode, result);
+                                if (!DateFrom.HasValue)
+                                {
+
+                                    result.StatusMessage = CPO_StatusMessage.ERROR_MSG_PARAMETER_OUTOFRANGE_INCORRECT;
+                                    result.StatusCode = (int)CPO_StatusCode.PARAMETER_OUTOFRANGE_INCORRECT;
+                                    statusCode = HttpStatusCode.BadRequest;
+                                    return Request.CreateResponse(statusCode, result);
+                                }
                             }
+                            _innerResponse = new { EVSEs = _stationService.GetEVSEsbyStationId(StationId, DateFrom, DateTo, Offset.Value, Limit.Value) };
+
+
                         }
-                        _innerResponse = new { EVSEs = _stationService.GetEVSEsbyStationId(StationId, DateFrom, DateTo, Offset.Value, 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;
@@ -166,9 +177,10 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                         IdTag = request.Token
                     };
 
-                    string urlformat = "http://localhost:{0}/api/v1/ocpp16/transaction?ChargeBoxId={1}";
+                    string[] parts = Request.RequestUri.ToString().Split('/');
+                    string urlformat = "{0}//{1}/api/v1/ocpp16/transaction?ChargeBoxId={3}";
 
-                    var _innerResult = await _client.Post(string.Format(urlformat, Request.RequestUri.Port, request.ChargeBoxId), new Dictionary<string, string>()
+                    var _innerResult = await _client.Post(string.Format(urlformat, parts[0], parts[2], Request.RequestUri.Port, request.ChargeBoxId), new Dictionary<string, string>()
                         {
                             { "PartnerId",_CustomerId}
 
@@ -179,23 +191,24 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     result = GetErrorDescription(_innerResult);
                     result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
 
-                    if (_innerResult.Success)
+                    if (_innerResult.Status == HttpStatusCode.InternalServerError)
                     {
-                        result.SerialNo = _innerResult.SerialNo;
-                        result.StatusCode = (int)CPO_StatusCode.Success;
-                        result.StatusMessage = CPO_StatusMessage.Success;
-                        statusCode = HttpStatusCode.OK;
 
+                        result.StatusCode = _innerResult.ErrorCode;
+                        result.StatusMessage = CPO_StatusMessage.ERROR_MSG_INNERSERVICE_ERROR;
+                        statusCode = HttpStatusCode.InternalServerError;
                     }
                     else
                     {
-
+                        result.SerialNo = _innerResult.SerialNo;
                         result.StatusCode = _innerResult.ErrorCode;
-                        result.StatusMessage = CPO_StatusMessage.ERROR_MSG_INNERSERVICE_ERROR;
-                        statusCode = HttpStatusCode.BadRequest;
+                        result.StatusMessage = _innerResult.Message;
+                        statusCode = HttpStatusCode.OK;
+
                     }
 
 
+
                 }
                 else
                 {
@@ -247,10 +260,11 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 InternalHttpClient _client = new InternalHttpClient();
                 CustomerService _customer = new CustomerService();
 
+                string[] parts = Request.RequestUri.ToString().Split('/');              
 
-                string urlformat = "http://localhost:{0}/api/v1/ocpp16/transaction?ChargeBoxId={1}&TransactionId={2}";
+                string urlformat = "{0}//{1}/api/v1/ocpp16/transaction?ChargeBoxId={2}&TransactionId={3}";
 
-                var _innerResult = await _client.Put(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId, SessionId), new Dictionary<string, string>()
+                var _innerResult = await _client.Put(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, SessionId), new Dictionary<string, string>()
                         {
                             { "PartnerId",_CustomerId}
 
@@ -314,7 +328,8 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 InternalHttpClient _client = new InternalHttpClient();
                 CustomerService _customer = new CustomerService();
 
-                string urlformat = "http://localhost:{0}/api/v1/ocpp16/reservation?ChargeBoxId={1}";
+                string[] parts = Request.RequestUri.ToString().Split('/');
+                string urlformat = "{0}//{1}/api/v1/ocpp16/reservation?ChargeBoxId={2}";
 
                 var _innerRequest = new ReserveRequest()
                 {
@@ -388,7 +403,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 CustomerService _customer = new CustomerService();
 
 
-                string urlformat = "http://localhost:{0}/api/v1/ocpp16/reservation?ChargeBoxId={1}&ReservationId={2}";
+                string[] parts = Request.RequestUri.ToString().Split('/');
+
+                string urlformat = "{0}//{1}/api/v1/ocpp16/reservation?ChargeBoxId={2}&ReservationId={3}";
 
                 var _innerResult = await _client.Delete(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId, ReservationId), new Dictionary<string, string>()
                         {
@@ -454,7 +471,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 CustomerService _customer = new CustomerService();
 
 
-                string urlformat = "http://localhost:{0}/api/v1/ocpp16/compositeschedule?ChargeBoxId={1}&ConnectorId={2}&Duration={3}";
+                string[] parts = Request.RequestUri.ToString().Split('/');
+
+                string urlformat = "{0}//{1}/api/v1/ocpp16/compositeschedule?ChargeBoxId={2}&ConnectorId={3}&Duration={4}";
 
                 var _innerResult = await _client.Get(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId, ConnectorId, Duration), new Dictionary<string, string>()
                         {
@@ -520,7 +539,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
 
 
 
-                string urlformat = "http://localhost:{0}/api/v1/ocpp16/chargingprofile?ChargeBoxId={1}";
+                string[] parts = Request.RequestUri.ToString().Split('/');
+
+                string urlformat = "{0}//{1}/api/v1/ocpp16/chargingprofile?ChargeBoxId={2}";
 
 
 
@@ -587,7 +608,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 CustomerService _customer = new CustomerService();
 
 
-                string urlformat = "http://localhost:{0}/api/v1/ocpp16/chargingprofile?ChargeBoxId={1}{2}";
+                string[] parts = Request.RequestUri.ToString().Split('/');
+
+                string urlformat = "{0}//{1}/api/v1/ocpp16/chargingprofile?ChargeBoxId={2}{3}";
 
                 var _innerResult = await _client.Delete(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId, ChargeProfileId == -1 ? "" : "&Id=" + ChargeProfileId), new Dictionary<string, string>()
                         {
@@ -653,7 +676,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
 
 
 
-                string urlformat = "http://localhost:{0}/api/v1/ocpp16/locallist?ChargeBoxId={1}";
+                string[] parts = Request.RequestUri.ToString().Split('/');
+
+                string urlformat = "{0}//{1}/api/v1/ocpp16/locallist?ChargeBoxId={2}";
 
 
 
@@ -722,7 +747,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
 
 
 
-                string urlformat = "http://localhost:{0}/api/v1/ocpp16/locallistversion?ChargeBoxId={1}";
+                string[] parts = Request.RequestUri.ToString().Split('/');
+
+                string urlformat = "{0}//{1}/api/v1/ocpp16/locallistversion?ChargeBoxId={2}";
 
 
 
@@ -846,7 +873,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 }
 
 
-                string urlformat = "http://localhost:{0}/api/v1/ocpp16/command?ChargeBoxId={1}{2}&SerialNo={3}";
+                string[] parts = Request.RequestUri.ToString().Split('/');
+
+                string urlformat = "{0}//{1}/api/v1/ocpp16/command?ChargeBoxId={2}{3}&SerialNo={4}";
 
 
                 var _innerResult = await _client.Get(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId, orderNo.HasValue ? "&OrderNo=" + orderNo.Value : "", SerialNo), new Dictionary<string, string>()
@@ -945,10 +974,41 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
         }
 
 
+        [Route("version")]
+        [ResponseType(typeof(CPOOuterResponse))]
+        [HttpGet]
+        public HttpResponseMessage Version(string ChargeBoxId)
+        {
+            var result = new CPOOuterResponse();
+            HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
+
+            try
+            {
+                ChargePointService _service = new ChargePointService();
+                string version = _service.GetVersionbyChargeBoxId(ChargeBoxId);
+
+                result.Data = version;
+                result.StatusCode = (int)CPO_StatusCode.Success;
+                result.StatusMessage = CPO_StatusMessage.Success;
+                statusCode = HttpStatusCode.OK;
+            }
+            catch (Exception ex)
+            {
+                result.ErrorDetail = ex.ToString();
+                result.StatusMessage = CPO_StatusMessage.ERROR_MSG_UNEXPECTEDERROR;
+                result.StatusCode = (int)CPO_StatusCode.UnexpectedError;
+                return Request.CreateResponse(statusCode, result);
+            }
+
+            return Request.CreateResponse(statusCode, result);
+
+        }
+
+
         [Route("activesession")]
         [ResponseType(typeof(CPOOuterResponse))]
         [HttpGet]
-        public HttpResponseMessage ActiveSession(string ChargeBoxId, string SessionId)
+        public HttpResponseMessage ActiveSession(string ChargeBoxId, string SessionId = "", string IdTag = "")
         {
             var result = new CPOOuterResponse();
             HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
@@ -968,15 +1028,15 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
 
                 // query meter value
                 ChargePointService _service = new ChargePointService();
-                var _meterValues = _service.GetActiveSessionInfo(ChargeBoxId, SessionId, new List<Packet.Messages.SubTypes.Measurand>()
+                var transactionData = _service.GetActiveSessionInfo(ChargeBoxId, new List<Packet.Messages.SubTypes.Measurand>()
                 {   Packet.Messages.SubTypes.Measurand.Voltage,
-                    Packet.Messages.SubTypes.Measurand.Current_Export,
+                    Packet.Messages.SubTypes.Measurand.Current_Import,
                     Packet.Messages.SubTypes.Measurand.SoC,
-                    Packet.Messages.SubTypes.Measurand.Power_Active_Export,
-                    Packet.Messages.SubTypes.Measurand.Energy_Active_Export_Interval
-                });
+                    Packet.Messages.SubTypes.Measurand.Power_Active_Import,
+                    Packet.Messages.SubTypes.Measurand.Energy_Active_Import_Interval
+                }, SessionId, IdTag);
 
-                if (_meterValues.Count == 0)
+                if (transactionData == null)
                 {
                     result.StatusCode = (int)CPO_StatusCode.CANT_FOUND_DATA;
                     result.StatusMessage = CPO_StatusMessage.ERROR_MSG_CANT_FIND_RESULT;
@@ -986,16 +1046,21 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 {
                     var _innerData = new
                     {
-                        Power = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Power_Active_Export).Select(x => x.Value).FirstOrDefault(),
-                        Power_Format = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Power_Active_Export).Select(x => x.Unit.ToString()).FirstOrDefault(),
-                        Current = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Current_Export).Select(x => x.Value).FirstOrDefault(),
-                        Current_Format = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Current_Export).Select(x => x.Unit.ToString()).FirstOrDefault(),
-                        Energy = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Energy_Active_Export_Interval).Select(x => x.Value).FirstOrDefault(),
-                        Energy_Format = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Energy_Active_Export_Interval).Select(x => x.Unit.ToString()).FirstOrDefault(),
-                        Voltage = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Voltage).Select(x => x.Value).FirstOrDefault(),
-                        Voltage_Format = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Voltage).Select(x => x.Unit.ToString()).FirstOrDefault(),
-                        SOC = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.SoC).Select(x => x.Value).FirstOrDefault(),
-                        SOC_Format = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.SoC).Select(x => x.Unit.ToString()).FirstOrDefault(),
+                        ChargeBoxId= ChargeBoxId,
+                        SessionId = transactionData.Id,
+                        ElaspedTime = (int)DateTime.UtcNow.Subtract(transactionData.StartTime).TotalMinutes,
+                        ConnectorId = transactionData.ConnectorId,
+                        IdTag = transactionData.StartIdTag,
+                        Power = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Power_Active_Import).Select(x => x.Value).FirstOrDefault(),
+                        Power_Format = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Power_Active_Import).Select(x => x.Unit.ToString()).FirstOrDefault(),
+                        Current = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Current_Import).Select(x => x.Value).FirstOrDefault(),
+                        Current_Format = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Current_Import).Select(x => x.Unit.ToString()).FirstOrDefault(),
+                        Energy = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Energy_Active_Import_Interval).Select(x => x.Value).FirstOrDefault(),
+                        Energy_Format = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Energy_Active_Import_Interval).Select(x => x.Unit.ToString()).FirstOrDefault(),
+                        Voltage = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Voltage).Select(x => x.Value).FirstOrDefault(),
+                        Voltage_Format = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Voltage).Select(x => x.Unit.ToString()).FirstOrDefault(),
+                        SOC = 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.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.SoC).Select(x => x.Unit.ToString()).FirstOrDefault(),
                     };
 
                     result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
@@ -1020,7 +1085,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
         [Route("completedsession")]
         [ResponseType(typeof(CPOOuterResponse))]
         [HttpGet]
-        public HttpResponseMessage CompletedSession(string ChargeBoxId, string SessionId)
+        public HttpResponseMessage CompletedSession(string ChargeBoxId, string SessionId = "", string IdTag = "", DateTime SearchTime = new DateTime())
         {
             var result = new CPOOuterResponse();
             HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
@@ -1040,11 +1105,10 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
 
                 // query meter value
                 ChargePointService _service = new ChargePointService();
-                var _innerData = _service.GetSessionDetail(ChargeBoxId, SessionId);
+                var _innerData = _service.GetSessionDetail(ChargeBoxId, SessionId, IdTag, SearchTime);
 
                 if (_innerData == null)
                 {
-
                     result.StatusCode = (int)CPO_StatusCode.CANT_FOUND_DATA;
                     result.StatusMessage = CPO_StatusMessage.ERROR_MSG_CANT_FIND_SESSIONDETAIL;
                     statusCode = HttpStatusCode.NotFound;
@@ -1327,9 +1391,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 if (_innerresult.StatusCode == HttpStatusCode.OK)
                 {
                     string titles = "\"Title\":[\"ChargeBox Id\",\"Connector Id\",\"Session Id\",\"DateFrom\",\"DateTo\",\"Duration(sec)\",\"Energy(kWh)\",\"Stop Reason\"],";
-        
+
                     _innerresult.Response = _innerresult.Response.Replace("data", "Session");
-                    _innerresult.Response= _innerresult.Response.Insert(1, titles);
+                    _innerresult.Response = _innerresult.Response.Insert(1, titles);
                     result.Data = _innerresult.Response;
                     result.StatusCode = (int)CPO_StatusCode.Success;
                     result.StatusMessage = CPO_StatusMessage.Success;

+ 62 - 34
EVCB_OCPP.WEBAPI/Controllers/Version1/InternalController.cs

@@ -427,10 +427,10 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
 
                 }
 
-
+                var currentStatus = chargePointService.GetChargePointCurrentSatus(ChargeBoxId, StartTransaction.ConnectorId.Value).Value;
 
                 if (StartTransaction.ConnectorId.HasValue && chargePointService.GetChargePointCurrentSatus(ChargeBoxId, StartTransaction.ConnectorId.Value).HasValue &&
-                    chargePointService.GetChargePointCurrentSatus(ChargeBoxId, StartTransaction.ConnectorId.Value).Value != ChargePointStatus.Available)
+                    (currentStatus != ChargePointStatus.Available && currentStatus != ChargePointStatus.Reserved && currentStatus != ChargePointStatus.Preparing ))
                 {
                     return Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse() { Code = 2103, Message = EVCBConfiguration.ERROR_MSG_CONNECTOR_ISNOT_AVAILIABLE_MODE });
                 }
@@ -505,7 +505,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 {
 
                     return Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse() { Code = 2101, Message = EVCBConfiguration.ERROR_MSG_CHARGEBOXID_ISNT_EXIST_OR_OFFLINE });
-                }             
+                }
 
                 var _ConnectorId = chargePointService.GetConnectorwithOngoingTransaction(ChargeBoxId, TransactionId);
 
@@ -604,7 +604,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
 
                 var connectorStatus = chargePointService.GetChargePointCurrentSatus(ChargeBoxId, ReserveNow.ConnectorId);
 
-                if (connectorStatus.HasValue && connectorStatus.Value == ChargePointStatus.Available)
+                if (connectorStatus.HasValue && (connectorStatus.Value == ChargePointStatus.Available || connectorStatus.Value == ChargePointStatus.Preparing))
                 {
                     //create reqest
 
@@ -860,6 +860,59 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
             return Request.CreateResponse(statusCode, result);
         }
 
+        [Route("datatransfer")]
+        [ResponseType(typeof(ErrorResponse))]
+        [ResponseType(typeof(InternalGenericResponse))]
+        [HttpPost]
+        public HttpResponseMessage SendDataTransfer(string ChargeBoxId, string VenderId, [FromBody]string Data, string MessageId = "")
+        {
+            string uuid = Guid.NewGuid().ToString();
+            var result = new InternalGenericResponse();
+            HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
+            try
+            {
+                if (string.IsNullOrEmpty(ChargeBoxId) || string.IsNullOrEmpty(VenderId))
+                {
+                    return Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse() { Code = 2100, Message = EVCBConfiguration.ERROR_MSG_PARAMETER_OUTOFRANGE_INCORRECT });
+                }
+                ChargePointService chargePointService = new ChargePointService();
+
+                if (!chargePointService.IsOnline(ChargeBoxId))
+                {
+                    return Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse() { Code = 2101, Message = EVCBConfiguration.ERROR_MSG_CHARGEBOXID_ISNT_EXIST_OR_OFFLINE });
+                }
+
+                var request = new DataTransferRequest()
+                {
+                    data = Data,
+                    messageId = MessageId,
+                    vendorId = VenderId
+                };
+
+                if (!AddCommandtoServer(ChargeBoxId, uuid, request))
+                {
+                    throw new Exception("Write Command Fail!!");
+                }
+
+
+                statusCode = HttpStatusCode.OK;
+                result.SerialNo = uuid;
+            }
+            catch (Exception ex)
+            {
+                return Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse()
+                {
+                    Code = 2999,
+                    Message = EVCBConfiguration.ERROR_MSG_UNEXPECTEDERROR,
+                    ErrorDetail = string.Format(EVCBConfiguration.ERRORMESSAGE_FORMAT, "SendDataTransfer", ex.ToString())
+
+                });
+
+            }
+
+            return Request.CreateResponse(statusCode, result);
+        }
+
 
         [Route("cache")]
         [ResponseType(typeof(ErrorResponse))]
@@ -921,36 +974,6 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
         [HttpPost]
         public HttpResponseMessage SetChargingProfile(string ChargeBoxId, [FromBody]ChargingProfileRequest ChargingProfile)
         {
-            var tt = new ChargingProfileRequest()
-            {
-                ChargingProfile = new AdvancedChargingProfiles()
-                {
-                    chargingProfileId = 444,
-                    chargingProfileKind = ChargingProfileKindType.Absolute,
-                    chargingProfilePurpose = ChargingProfilePurposeType.ChargePointMaxProfile,
-                    chargingSchedule = new ChargingScheduleBase()
-                    {
-                        chargingRateUnit = ChargingRateUnitType.A,
-                        chargingSchedulePeriod = new List<ChargingSchedulePeriod>()
-                               {
-                                    new ChargingSchedulePeriod(){  limit=1, startPeriod=10}
-                               },
-                        duration = 30000,
-                        minChargingRate = 10,
-                        startSchedule = DateTime.Now
-
-
-                    },
-                    recurrencyKind = RecurrencyKindType.Daily,
-                    stackLevel = 1,
-
-                },
-                connectorId = 1
-            };
-
-            var serialization = JsonConvert.SerializeObject(tt);
-            var array = JsonConvert.DeserializeObject<JArray>(serialization);
-
 
 
             string uuid = Guid.NewGuid().ToString();
@@ -978,6 +1001,11 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     return Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse() { Code = 2100, Message = EVCBConfiguration.ERROR_MSG_PARAMETER_OUTOFRANGE_INCORRECT });
                 }
 
+                if (ChargingProfile.ChargingProfile.chargingSchedule.chargingSchedulePeriod.Count == 0)
+                {
+                    return Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse() { Code = 2100, Message = EVCBConfiguration.ERROR_MSG_PARAMETER_OUTOFRANGE_INCORRECT });
+                }
+
                 var request = new SetChargingProfileRequest()
                 {
                     connectorId = ChargingProfile.connectorId,

BIN
EVCB_OCPP.WEBAPI/Dll/EVCB_OCPP.Packet.dll


+ 2 - 1
EVCB_OCPP.WEBAPI/EVCB_OCPP.WEBAPI.csproj

@@ -249,6 +249,7 @@
     <Compile Include="Models\WebAPI\Dto\ReserveNowRequest.cs" />
     <Compile Include="Models\WebAPI\Dto\StartSessionRequest.cs" />
     <Compile Include="Models\WebAPI\Dto\Status.cs" />
+    <Compile Include="Models\WebAPI\Dto\TransasctionData.cs" />
     <Compile Include="Models\WebAPI\ErrorResponse.cs" />
     <Compile Include="Models\WebAPI\InternalGenericRequest.cs" />
     <Compile Include="Models\WebAPI\InternalGenericResponse.cs" />
@@ -374,7 +375,7 @@
           <AutoAssignPort>True</AutoAssignPort>
           <DevelopmentServerPort>63823</DevelopmentServerPort>
           <DevelopmentServerVPath>/</DevelopmentServerVPath>
-          <IISUrl>http://172.17.40.23:63823/</IISUrl>
+          <IISUrl>http://localhost:63823/</IISUrl>
           <NTLMAuthentication>False</NTLMAuthentication>
           <UseCustomServer>False</UseCustomServer>
           <CustomServerUrl>

+ 1 - 0
EVCB_OCPP.WEBAPI/Models/WebAPI/CPOResponseDescription.cs

@@ -28,6 +28,7 @@ namespace EVCB_OCPP.WEBAPI.Models.WebAPI
     public static class CPO_StatusMessage
     {
         public static readonly string Success = "Success";
+     
         public static readonly string ERROR_MSG_INVALIDHEADER = "Invaild Headers";
         public static readonly string ERROR_MSG_INVALIDTIMESTAMP = "Invaild Timestamp";
         public static readonly string ERROR_MSG_INVALIDSIGNATURE = "Invaild Signature";

+ 4 - 2
EVCB_OCPP.WEBAPI/Models/WebAPI/Dto/Connector.cs

@@ -17,7 +17,9 @@ namespace EVCB_OCPP.WEBAPI.Models.WebAPI.Dto
         [JsonConverter(typeof(StringEnumConverter))]
         public ConnectorType ConnectorType { set; get; }
 
-        [JsonConverter(typeof(StringEnumConverter))]
-        public ConnectorPowerType PowerType { set; get; }
+        public string FaultMessage { set; get; }
+
+
+
     }
 }

+ 1 - 8
EVCB_OCPP.WEBAPI/Models/WebAPI/Dto/ConnectorPowerType.cs

@@ -5,12 +5,5 @@ using System.Web;
 
 namespace EVCB_OCPP.WEBAPI.Models.WebAPI.Dto
 {
-    public enum ConnectorPowerType
-    {
-        Unknown=-1,
-        AC_1_PHASE =1,
-        AC_3_PHASE,
-        DC,
-        
-    }
+  
 }

+ 13 - 0
EVCB_OCPP.WEBAPI/Models/WebAPI/Dto/ConnectorStatus.cs

@@ -11,5 +11,18 @@ namespace EVCB_OCPP.WEBAPI.Models.WebAPI.Dto
 
      
         public int Status { set; get; }
+
+
+        /// <summary>
+        /// errorCode
+        /// </summary>
+        public int ChargePointErrorCodeId { set; get; }
+
+       
+
+        /// <summary>
+        /// vendorErrorCode
+        /// </summary>      
+        public string VendorErrorCode { set; get; }
     }
 }

+ 5 - 4
EVCB_OCPP.WEBAPI/Models/WebAPI/Dto/ConnectorType.cs

@@ -9,10 +9,11 @@ namespace EVCB_OCPP.WEBAPI.Models.WebAPI.Dto
     {
         Other=-1,
         CHADEMO =1,
-        AC,
-        CCS1_COMBO,
-        CCS2_COMBO,
-        GBT
+        AC=4,
+        CCS=2,
+        GBT=3
       
     }
+
+    
 }

+ 1 - 0
EVCB_OCPP.WEBAPI/Models/WebAPI/Dto/Status.cs

@@ -8,6 +8,7 @@ namespace EVCB_OCPP.WEBAPI.Models.WebAPI.Dto
     public enum Status
     {
         Available,
+        Preparing,
         Unavailable,
         Charging,
         UnderConstruction,

+ 34 - 0
EVCB_OCPP.WEBAPI/Models/WebAPI/Dto/TransasctionData.cs

@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace EVCB_OCPP.WEBAPI.Models.WebAPI.Dto
+{
+    public class TransasctionData
+    {
+     
+        public Int32 Id { get; set; }        
+
+
+        /// <summary>
+        /// 槍號  1 byte string、本來是 string、改為byte
+        /// </summary>      
+        public byte ConnectorId { get; set; }
+       
+
+        /// <summary>
+        /// StartIdTag
+        /// </summary>    
+        public string StartIdTag { get; set; }
+    
+
+        /// <summary>
+        /// 開始充電開始時間
+        /// </summary>        
+        public DateTime StartTime { get; set; }
+
+        public List<ConnectorMeterValue> MeterValues { set; get; }
+
+    }
+}

+ 144 - 76
EVCB_OCPP.WEBAPI/Services/ChargePointService.cs

@@ -22,6 +22,7 @@ namespace EVCB_OCPP.WEBAPI.Services
     public class ChargePointService : IChargePointService
     {
         string mainConnectionString = ConfigurationManager.ConnectionStrings["MainDBContext"].ConnectionString;
+        string meterConnectionString = ConfigurationManager.ConnectionStrings["MeterValueDBContext"].ConnectionString;
 
         public DateTime GetLastUpdatedTimebyMachineId(string machineId)
         {
@@ -40,6 +41,50 @@ namespace EVCB_OCPP.WEBAPI.Services
 
         }
 
+        public string GetMachineIdbyChargeBoxId(string chargeBoxId)
+        {
+            string machineId = string.Empty;
+            using (SqlConnection conn = new SqlConnection(mainConnectionString))
+            {
+                var parameters = new DynamicParameters();
+                parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
+                string strSql = "Select Id from [dbo].[Machine] where ChargeBoxId=@ChargeBoxId and IsDelete=0; ";
+                machineId = conn.Query<string>(strSql, parameters).FirstOrDefault();
+
+            }
+
+            return machineId;
+
+        }
+
+
+        public string GetVersionbyChargeBoxId(string chargeBoxId)
+        {
+            string version = string.Empty;
+            using (SqlConnection conn = new SqlConnection(mainConnectionString))
+            {
+                var parameters = new DynamicParameters();
+                parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
+                string strSql = "Select BoardVersions from [dbo].[Machine] where ChargeBoxId=@ChargeBoxId and IsDelete=0; ";
+                version = conn.Query<string>(strSql, parameters).FirstOrDefault();
+            }
+            return version;
+        }
+
+        public EVSE GetEVSEsbyChargeBoxId(string chargeboxid, DateTime? dateFrom, DateTime? dateTo)
+        {
+            string machineId = GetMachineIdbyChargeBoxId(chargeboxid);
+            ChargePointService _CPService = new ChargePointService();
+
+            var _machineUpdateOn = _CPService.GetLastUpdatedTimebyMachineId(machineId);
+
+            var _machine = _CPService.GetBasicInfobyId(machineId);
+            _machine.LastUpdated = _machineUpdateOn;
+
+
+            return _machine;
+        }
+
 
         public EVSE GetBasicInfobyId(string machineId)
         {
@@ -49,7 +94,7 @@ namespace EVCB_OCPP.WEBAPI.Services
             {
                 var parameters = new DynamicParameters();
                 parameters.Add("@Id", machineId, DbType.String, ParameterDirection.Input);
-                string strSql = "Select ChargeBoxId,RatedPower,Online,OfflineOn ,GunAmt,Latitude,Longitude,ConnectorType,ConnectorPowerType from [dbo].[Machine] where Id=@Id; ";
+                string strSql = "Select ChargeBoxId,RatedPower,Online,OfflineOn ,GunAmt,Latitude,Longitude,ConnectorType from [dbo].[Machine] where Id=@Id and IsDelete=0; ";
                 _machine = conn.Query<Machine>(strSql, parameters).FirstOrDefault();
             }
             if (_machine != null)
@@ -70,17 +115,16 @@ namespace EVCB_OCPP.WEBAPI.Services
                         ConnectorId = _RefConnector == null ? i : _RefConnector.ConnectorId,
                         Status = cp.Status == Status.Remove ? Status.Remove : _RefConnector == null ? Status.Unknown : ConvertConnectorStatus(_RefConnector.Status),
                         ConnectorType = ConvertConnectorType(int.Parse(_machine.ConnectorType.Split(',')[i - 1])),
-                        PowerType = ConvertConnectorPowerType(int.Parse(_machine.ConnectorPowerType.Split(',')[i - 1])),
+                        FaultMessage = ((ChargePointErrorCode)_RefConnector.ChargePointErrorCodeId).ToString() + (string.IsNullOrEmpty(_RefConnector.VendorErrorCode) ? "" : "-" + _RefConnector.VendorErrorCode)
+
                     });
-                }
+                }                
             }
-
-
-
             return _machine == null ? null : cp;
         }
 
-       
+
+
 
         public List<ConnectorStatus> GetConnectorStatus(string chargeBoxId)
         {
@@ -90,7 +134,7 @@ namespace EVCB_OCPP.WEBAPI.Services
             {
                 var parameters = new DynamicParameters();
                 parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
-                string strSql = "Select ConnectorId,Status from [dbo].[ConnectorStatus] where ChargeBoxId=@ChargeBoxId order by  ConnectorId; ";
+                string strSql = "Select ConnectorId,Status,ChargePointErrorCodeId,VendorErrorCode from [dbo].[ConnectorStatus] where ChargeBoxId=@ChargeBoxId order by  ConnectorId; ";
                 _Connectors = conn.Query<ConnectorStatus>(strSql, parameters).SkipWhile(x => x.ConnectorId == 0).ToList();
             }
 
@@ -111,7 +155,7 @@ namespace EVCB_OCPP.WEBAPI.Services
                 parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
                 using (SqlConnection conn = new SqlConnection(mainConnectionString))
                 {
-                    string strSql = "Select GunAmt from [dbo].[Machine] where ChargeBoxId=@ChargeBoxId; ";
+                    string strSql = "Select GunAmt from [dbo].[Machine] where ChargeBoxId=@ChargeBoxId  and IsDelete=0; ";
                     count = conn.ExecuteScalarAsync<int>(strSql, parameters, null, EVCBConfiguration.DB_DefaultConnectionTimeout).Result;
                 }
 
@@ -128,7 +172,7 @@ namespace EVCB_OCPP.WEBAPI.Services
             parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
             using (SqlConnection conn = new SqlConnection(mainConnectionString))
             {
-                string strSql = "Select count(*) from [dbo].[Machine] where ChargeBoxId=@ChargeBoxId; ";
+                string strSql = "Select count(*) from [dbo].[Machine] where ChargeBoxId=@ChargeBoxId  and IsDelete=0; ";
                 exists = conn.ExecuteScalar<bool>(strSql, parameters, null, EVCBConfiguration.DB_DefaultConnectionTimeout);
             }
             return exists;
@@ -191,7 +235,7 @@ namespace EVCB_OCPP.WEBAPI.Services
 
             using (SqlConnection conn = new SqlConnection(mainConnectionString))
             {
-                string strSql = "Select online from [dbo].[Machine] where ChargeBoxId=@ChargeBoxId; ";
+                string strSql = "Select online from [dbo].[Machine] where ChargeBoxId=@ChargeBoxId  and IsDelete=0; ";
                 bool online = conn.ExecuteScalar<bool>(strSql, parameters, null, EVCBConfiguration.DB_DefaultConnectionTimeout);
 
                 if (online)
@@ -221,7 +265,7 @@ namespace EVCB_OCPP.WEBAPI.Services
 
             using (SqlConnection conn = new SqlConnection(mainConnectionString))
             {
-                string strSql = "Select online from [dbo].[Machine] where ChargeBoxId=@ChargeBoxId; ";
+                string strSql = "Select online from [dbo].[Machine] where ChargeBoxId=@ChargeBoxId  and IsDelete=0; ";
                 online = conn.ExecuteScalar<bool>(strSql, parameters, null, EVCBConfiguration.DB_DefaultConnectionTimeout);
             }
 
@@ -242,39 +286,67 @@ namespace EVCB_OCPP.WEBAPI.Services
 
             using (SqlConnection conn = new SqlConnection(mainConnectionString))
             {
-                string strSql = "Select Count(*) from [dbo].[Machine] where ChargeBoxId=@ChargeBoxId and CustomerId=@CustomerId; ";
+                string strSql = "Select Count(*) from [dbo].[Machine] where ChargeBoxId=@ChargeBoxId and CustomerId=@CustomerId  and IsDelete=0; ";
                 existed = conn.ExecuteScalar<bool>(strSql, parameters, null, EVCBConfiguration.DB_DefaultConnectionTimeout);
             }
 
             return existed;
         }
 
-        public List<ConnectorMeterValue> GetActiveSessionInfo(string chargeBoxId, string sessionId, List<Measurand> requiredMeasurands)
+        public TransasctionData GetActiveSessionInfo(string chargeBoxId, List<Measurand> requiredMeasurands, string sessionId = "", string idTag = "")
         {
             List<ConnectorMeterValue> meterValues = new List<ConnectorMeterValue>();
             ConnectorMeterValueModel meterModel = null;
-            if (string.IsNullOrEmpty(chargeBoxId)) return meterValues;
+            TransasctionData transactionData = null;
+            if (string.IsNullOrEmpty(chargeBoxId)) return transactionData;
+
+
+            try
+            {
+                var parameters = new DynamicParameters();
+                parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
+                parameters.Add(string.IsNullOrEmpty(sessionId) ? "@StartIdTag" : "@TransactionId", string.IsNullOrEmpty(sessionId) ? idTag : sessionId, DbType.String, ParameterDirection.Input);
+
+                using (SqlConnection conn = new SqlConnection(mainConnectionString))
+                {
+                    string date = DateTime.UtcNow.ToString("yyMMdd");
+                    string strSql = "Select Top(1) Id , ConnectorId, StartTime,StartIdTag from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and " + (string.IsNullOrEmpty(sessionId) ? "StartIdTag=@StartIdTag" : "Id=@TransactionId") + " and StopTime='1991-01-01 00:00:00.000'  order by Id desc;";
+                    transactionData = conn.Query<TransasctionData>(strSql, parameters, null, true, EVCBConfiguration.DB_DefaultConnectionTimeout).FirstOrDefault();
+
+                }
+
+            }
+            catch
+            {
+                ;
+            }
+
 
             for (int i = 0; i < requiredMeasurands.Count; i++)
             {
                 var parameters = new DynamicParameters();
                 parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
-                parameters.Add("@TransactionId", sessionId, DbType.String, ParameterDirection.Input);
+                parameters.Add("@TransactionId", transactionData.Id, DbType.String, ParameterDirection.Input);
                 parameters.Add("@MeasurandId", requiredMeasurands[i], DbType.String, ParameterDirection.Input);
 
                 try
                 {
-                    using (SqlConnection conn = new SqlConnection(mainConnectionString))
+                    using (SqlConnection conn = new SqlConnection(meterConnectionString))
                     {
-                        string date = DateTime.UtcNow.ToString("yyMMdd");
-                        string strSql = "Select Top(1) * from [dbo].[ConnectorMeterValueRecord" + date + "] where ChargeBoxId=@ChargeBoxId and Id=@TransactionId and MeasurandId=@MeasurandId order by CreatedOn desc;";
+                        string date = transactionData.StartTime.ToString("yyMMdd");
+                        string strSql = "Select Top(1) * from [dbo].[ConnectorMeterValueRecord" + date + "] where ChargeBoxId=@ChargeBoxId and TransactionId=@TransactionId and MeasurandId=@MeasurandId order by CreatedOn desc;";
                         meterModel = conn.Query<ConnectorMeterValueModel>(strSql, parameters, null, true, EVCBConfiguration.DB_DefaultConnectionTimeout).FirstOrDefault();
 
                     }
 
                     if (meterModel != null)
                     {
-                        meterValues.Add(new ConnectorMeterValue()
+                        if(transactionData.MeterValues== null)
+                        {
+                            transactionData.MeterValues = new List<ConnectorMeterValue>();
+                        }
+
+                        transactionData.MeterValues.Add(new ConnectorMeterValue()
                         {
                             ChargeBoxId = meterModel.ChargeBoxId,
                             ConnectorId = meterModel.ConnectorId,
@@ -294,23 +366,24 @@ namespace EVCB_OCPP.WEBAPI.Services
 
                     }
                 }
-                catch
+                catch(Exception ex)
                 {
                     break;
                 }
 
             }
 
-            return meterValues;
+            return transactionData;
         }
 
 
-        public SessionDetail GetSessionDetail(string chargeBoxId, string sessionId)
+        public List<SessionDetail> GetSessionDetail(string chargeBoxId, string sessionId, string idTag, DateTime searchTime)
         {
-            SessionDetail detail = null;
-            TransactionRecordModel transactionModel = null;
+            List<SessionDetail> detail = new List<SessionDetail>();
+            List<TransactionRecordModel> transactionModel = null;
             if (string.IsNullOrEmpty(chargeBoxId)) return detail;
 
+
             var parameters = new DynamicParameters();
             parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
             parameters.Add("@TransactionId", sessionId, DbType.String, ParameterDirection.Input);
@@ -319,24 +392,49 @@ namespace EVCB_OCPP.WEBAPI.Services
             {
                 using (SqlConnection conn = new SqlConnection(mainConnectionString))
                 {
-                    string date = DateTime.UtcNow.ToString("yyMMdd");
-                    string strSql = "Select Top(1) * from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and Id=@TransactionId and StopTime!='1991-01-01 00:00:00.000' ;";
-                    transactionModel = conn.Query<TransactionRecordModel>(strSql, parameters, null, true, EVCBConfiguration.DB_DefaultConnectionTimeout).FirstOrDefault();
+                    string strSql = string.Empty;
+                    if (!string.IsNullOrEmpty(sessionId))
+                    {
+                        parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
+                        parameters.Add("@TransactionId", sessionId, DbType.String, ParameterDirection.Input);
+                        strSql = "Select Top(1) * from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and Id=@TransactionId and StopTime!='1991-01-01 00:00:00.000' Order by Id desc ;";
+                    }
+                    else if (!string.IsNullOrEmpty(idTag))
+                    {
+                        parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
+                        parameters.Add("@StartIdTag", idTag, DbType.String, ParameterDirection.Input);
+                        strSql = "Select Top(1) * from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and StartIdTag=@StartIdTag   and StopTime!='1991-01-01 00:00:00.000' Order by Id desc  ;";
+
+                    }
+                    else
+                    {
+                        if (searchTime == new DateTime())
+                        {
+                            return detail;
+                        }
+
+                        parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
+                        parameters.Add("@StartIdTag", idTag, DbType.String, ParameterDirection.Input);
+                        strSql = "Select Top(1) * from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and StartIdTag=@StartIdTag   and StopTime!='1991-01-01 00:00:00.000' Order by Id desc  ;";
+
+                    }
+
+                    transactionModel = conn.Query<TransactionRecordModel>(strSql, parameters, null, true, EVCBConfiguration.DB_DefaultConnectionTimeout).ToList();
 
                 }
 
-                if (transactionModel != null)
+                foreach (var item in transactionModel)
                 {
-                    detail = new SessionDetail()
+                    detail.Add(new SessionDetail()
                     {
-                        ConnectorId = (int)transactionModel.ConnectorId,
-                        IdTag = transactionModel.StartIdTag,
-                        MeterStart = transactionModel.MeterStart,
-                        MeterStop = transactionModel.MeterStop,
-                        StartTime = transactionModel.StartTime.ToString(EVCBConfiguration.UTC_DATETIMEFORMAT),
-                        StopTime = transactionModel.StopTime.ToString(EVCBConfiguration.UTC_DATETIMEFORMAT),
-                        StopReason = transactionModel.StopReasonId < 1 ? Reason.Local : (Reason)transactionModel.StopReasonId
-                    };
+                        ConnectorId = (int)item.ConnectorId,
+                        IdTag = item.StartIdTag,
+                        MeterStart = item.MeterStart,
+                        MeterStop = item.MeterStop,
+                        StartTime = item.StartTime.ToString(EVCBConfiguration.UTC_DATETIMEFORMAT),
+                        StopTime = item.StopTime.ToString(EVCBConfiguration.UTC_DATETIMEFORMAT),
+                        StopReason = item.StopReasonId < 1 ? Reason.Local : (Reason)item.StopReasonId
+                    });
 
                 }
 
@@ -363,6 +461,10 @@ namespace EVCB_OCPP.WEBAPI.Services
                     }
                     break;
                 case 2://Preparing
+                    {
+                        result = Status.Preparing;
+                    }
+                    break;
                 case 3://Charging
                 case 4://SuspendedEVSE
                 case 5://SuspendedEV
@@ -396,36 +498,7 @@ namespace EVCB_OCPP.WEBAPI.Services
 
         }
 
-        private ConnectorPowerType ConvertConnectorPowerType(int value)
-        {
-            ConnectorPowerType result = ConnectorPowerType.Unknown;
 
-            switch (value)
-            {
-                case 1://AC_1_PHASE
-                    {
-                        result = ConnectorPowerType.AC_1_PHASE;
-                    }
-                    break;
-                case 2://AC_3_PHASE
-                    {
-                        result = ConnectorPowerType.AC_3_PHASE;
-                    }
-                    break;
-                case 3://DC
-                    {
-                        result = ConnectorPowerType.DC;
-                    }
-                    break;
-                default:
-                    break;
-
-
-
-            }
-            return result;
-
-        }
 
         private ConnectorType ConvertConnectorType(int value)
         {
@@ -438,22 +511,17 @@ namespace EVCB_OCPP.WEBAPI.Services
                         result = ConnectorType.CHADEMO;
                     }
                     break;
-                case 2://AC
+                case 4://AC
                     {
                         result = ConnectorType.AC;
                     }
                     break;
-                case 3://CCS1_COMBO
-                    {
-                        result = ConnectorType.CCS1_COMBO;
-                    }
-                    break;
-                case 4://CCS2_COMBO
+                case 2:
                     {
-                        result = ConnectorType.CCS2_COMBO;
+                        result = ConnectorType.CCS;
                     }
                     break;
-                case 5://GBT
+                case 3://GBT
                     {
                         result = ConnectorType.GBT;
                     }

+ 1 - 0
EVCB_OCPP.WEBAPI/Services/ServerTriggerService.cs

@@ -81,6 +81,7 @@ namespace EVCB_OCPP.WEBAPI.Services
         SetChargingProfile,
         TriggerMessage,
         UnlockConnector,
+        DataTransfer
 
     }