123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612 |
- using Evcb.Domain.Model;
- using Newtonsoft.Json;
- using OCPP_Packet.Packet.DataTransfer;
- using OCPPPacket.Packet.DataTransfer;
- using OCPPPacket.Packet.Messages;
- using OCPPPacket.Packet.Messages.Core;
- using OCPPPacket.Packet.Messages.FirmwareManagement;
- using OCPPPacket.Packet.Messages.LocalAuthListManagement;
- using OCPPPacket.Packet.Messages.RemoteTrigger;
- using OCPPPacket.Packet.Messages.Reservation;
- using OCPPPacket.Packet.Messages.SmartCharging;
- using OCPPPacket.Packet.Status;
- using OCPPServer.Common;
- using Packet.Cmd;
- using System;
- using System.Collections.Generic;
- namespace OCPPServer.Handler
- {
- public class MakeRequestHandler
- {
- #region Core
-
-
-
- static public IRequest MakeGetConfigurationRequest()
- {
- GetConfigurationRequest req = new GetConfigurationRequest();
- req.key = new List<string>();
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- return req;
- }
-
-
-
- static public IRequest MakeChangeConfigurationRequest(string key, string keyvalue)
- {
- ChangeConfigurationRequest req = new ChangeConfigurationRequest();
- if (key == "HeartbeatInterval")
- {
- req.key = "HeartbeatInterval";
- req.value = keyvalue;
- }
- return req;
- }
-
-
-
- public IRequest MakeRemoteStartTransactionRequest(int gunSerNo, string memberId)
- {
- RemoteStartTransactionRequest req = new RemoteStartTransactionRequest();
- req.connectorId = gunSerNo;
- req.idTag = memberId;
- req.chargingProfile = null;
- return req;
- }
-
-
-
- public IRequest MakeRemoteStopTransactionRequest(int transactionId)
- {
- RemoteStopTransactionRequest req = new RemoteStopTransactionRequest();
- req.transactionId = transactionId;
- return req;
- }
-
-
-
- public IRequest MakeClearCacheRequest()
- {
- ClearCacheRequest req = new ClearCacheRequest();
- return req;
- }
-
-
-
- public IRequest MakeHardResetRequest()
- {
- ResetRequest req = new ResetRequest();
- req.type = ResetType.Hard;
- return req;
- }
-
-
-
- public IRequest MakeSoftResetRequest()
- {
- ResetRequest req = new ResetRequest();
- req.type = ResetType.Soft;
- return req;
- }
-
-
-
- public IRequest MakeUnlockConnectorRequest(int connectorId)
- {
- UnlockConnectorRequest req = new UnlockConnectorRequest();
- req.connectorId = connectorId;
- return req;
- }
-
-
-
- public IRequest MakeGetConfigurationRequest(string key)
- {
- GetConfigurationRequest req = new GetConfigurationRequest();
-
-
-
- req.key = new List<string> { "AllowOfflineTxForUnknownId", "AuthorizationCacheEnabled", "LocalAuthListEnabled", "SendLocalListMaxLength", "ConnectionTimeOut", "HeartbeatInterval", "test1", "test2" };
- return req;
- }
-
-
-
- public IRequest MakeChangeAvailabilityRequest(int connectorId)
- {
- ChangeAvailabilityRequest req = new ChangeAvailabilityRequest();
- req.connectorId = connectorId;
- req.type = AvailabilityType.Operative;
- return req;
- }
- #endregion Core
- #region RemoteTrigger
-
-
-
- public IRequest MakeTriggerMessageRequest(MessageTrigger messageType, int connectorId)
- {
- TriggerMessageRequest req = new TriggerMessageRequest();
- req.requestedMessage = messageType;
- req.connectorId = connectorId;
- return req;
- }
- #endregion RemoteTrigger
- #region FirmwareManagement
-
-
-
- static public IRequest MakeGetDiagnosticsRequest(bool ac)
- {
- GetDiagnosticsRequest req = new GetDiagnosticsRequest();
- if (ac == true)
- req.location = new Uri("ftp://ipc_ui:pht2016@ftp.phihong.com.tw/AC/log/");
- else
- req.location = new Uri("ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/");
- return req;
- }
-
-
-
- static public IRequest MakeOCPPUpdateFirmwareRequest(string fileurl)
- {
- UpdateFirmwareRequest req = new UpdateFirmwareRequest();
- req.location = new Uri(fileurl);
- req.retrieveDate = DateTime.Now;
- return req;
- }
- #endregion FirmwareManagement
- #region LocalAuthListManagement
-
-
-
- static public IRequest MakeGetLocalListVersionRequest()
- {
- GetLocalListVersionRequest req = new GetLocalListVersionRequest();
- return req;
- }
-
-
-
- static public IRequest MakeSendLocalListRequest(List<OCPPServer.Common.LocalAuthorization> localauth, uint version, byte type)
- {
- SendLocalListRequest req = new SendLocalListRequest();
- req.localAuthorizationList = new List<AuthorizationData>();
- foreach (var localAuthorization in localauth)
- {
- AuthorizationData athData = new AuthorizationData();
- athData.IdToken = localAuthorization.CardNumber;
- IdTagInfo idTagInfo = new IdTagInfo();
- idTagInfo.expiryDate = DateTime.Parse(localAuthorization.ExpiryDate);
- idTagInfo.parentIdTag = localAuthorization.CardNumber;
- idTagInfo.status = (AuthorizationStatus)localAuthorization.Status;
- athData.idTagInfo = idTagInfo;
- req.localAuthorizationList.Add(athData);
- }
- req.listVersion = Convert.ToInt32(version);
-
- if (type == 0)
- {
- req.updateType = UpdateType.Full;
- }
- else
- {
- req.updateType = UpdateType.Differential;
- }
- return req;
- }
- #endregion LocalAuthListManagement
- #region Reservation
-
-
-
- public IRequest MakeReserveNowRequest(int connectorId, string memberId, bool reserveConnectorZeroSupported, int reservationId)
- {
- int RetainMinute = 5;
- ReserveNowRequest req = new ReserveNowRequest();
- if (reserveConnectorZeroSupported == true)
- req.connectorId = 0;
- else
- req.connectorId = connectorId;
- req.expiryDate = DateTime.Now.AddMinutes(RetainMinute);
- req.parentIdTag = memberId;
- req.idTag = memberId;
- req.reservationId = reservationId;
- return req;
- }
-
-
-
- public IRequest MakeCancelReservationRequest(int reservationId)
- {
- CancelReservationRequest req = new CancelReservationRequest();
- req.reservationId = reservationId;
- return req;
- }
- #endregion Reservation
- #region SmartCharging
-
-
-
- static public IRequest MakeSetChargingProfileRequest(int connectorId, int transactionId, int chargingProfileId, string purpose)
- {
- SetChargingProfileRequest req = new SetChargingProfileRequest();
- req.connectorId = connectorId;
- req.csChargingProfiles = new csChargingProfiles();
- req.csChargingProfiles.chargingProfileId = chargingProfileId;
- req.csChargingProfiles.transactionId = transactionId;
- if (purpose.Contains("ChargePointMaxProfile"))
- {
- req.csChargingProfiles.stackLevel = 2;
- req.csChargingProfiles.chargingProfilePurpose = ChargingProfilePurposeType.ChargePointMaxProfile;
- req.csChargingProfiles.chargingProfileKind = ChargingProfileKindType.Recurring;
- req.csChargingProfiles.recurrencyKind = RecurrencyKindType.Daily;
- }
- else if (purpose.Contains("TxDefaultProfile"))
- {
- req.csChargingProfiles.stackLevel = 1;
- req.csChargingProfiles.chargingProfilePurpose = ChargingProfilePurposeType.TxDefaultProfile;
- req.csChargingProfiles.chargingProfileKind = ChargingProfileKindType.Absolute;
- req.csChargingProfiles.recurrencyKind = RecurrencyKindType.Weekly;
- }
- else if (purpose.Contains("TxProfile"))
- {
- req.csChargingProfiles.stackLevel = 0;
- req.csChargingProfiles.chargingProfilePurpose = ChargingProfilePurposeType.TxProfile;
- req.csChargingProfiles.chargingProfileKind = ChargingProfileKindType.Relative;
- req.csChargingProfiles.recurrencyKind = RecurrencyKindType.Daily;
- }
- req.csChargingProfiles.validFrom = DateTime.Now;
- req.csChargingProfiles.validTo = DateTime.Now.AddHours(2);
- req.csChargingProfiles.chargingSchedule = new ChargingSchedule();
- req.csChargingProfiles.chargingSchedule.chargingRateUnit = ChargingRateUnitType.A;
- req.csChargingProfiles.chargingSchedule.chargingSchedulePeriod = new List<ChargingSchedulePeriod>();
- req.csChargingProfiles.chargingSchedule.duration = 120;
- req.csChargingProfiles.chargingSchedule.minChargingRate = 0.0m;
- req.csChargingProfiles.chargingSchedule.startSchedule = DateTime.Now;
- req.csChargingProfiles.chargingSchedule.chargingSchedulePeriod = new List<ChargingSchedulePeriod>();
- req.csChargingProfiles.chargingSchedule.chargingSchedulePeriod.Add(new ChargingSchedulePeriod() { startPeriod = 0, limit = 11000.0m, numberPhases = 3 });
- req.csChargingProfiles.chargingSchedule.chargingSchedulePeriod.Add(new ChargingSchedulePeriod() { startPeriod = 28800, limit = 6000.0m, numberPhases = 3 });
- req.csChargingProfiles.chargingSchedule.chargingSchedulePeriod.Add(new ChargingSchedulePeriod() { startPeriod = 72000, limit = 6000.0m, numberPhases = 3 });
-
-
- return req;
- }
-
-
-
- static public IRequest MakeSetChargingProfileRequest(BaseCmd cmd, int transactionId)
- {
- SetChargingProfileRequest req = new SetChargingProfileRequest();
- var c = cmd as Cmd1013;
- if(c.GunSerNo == 255)
- req.connectorId = 0;
- else
- req.connectorId = c.GunSerNo + 1;
- req.csChargingProfiles = new csChargingProfiles();
- req.csChargingProfiles.chargingProfileId = c.ChargingProfileId;
- req.csChargingProfiles.transactionId = transactionId;
- req.csChargingProfiles.stackLevel = c.stackLevel;
- req.csChargingProfiles.chargingProfilePurpose = (c.ChargingProfilePurpose == 0) ? ChargingProfilePurposeType.ChargePointMaxProfile : ((c.ChargingProfilePurpose == 1) ? ChargingProfilePurposeType.TxDefaultProfile : ChargingProfilePurposeType.TxProfile);
- req.csChargingProfiles.chargingProfileKind = (c.ChargingProfileKind == 0) ? ChargingProfileKindType.Absolute : ((c.ChargingProfileKind == 1) ? ChargingProfileKindType.Recurring : ChargingProfileKindType.Relative);
- req.csChargingProfiles.recurrencyKind = (c.RecurrencyKind == 0) ? RecurrencyKindType.Daily : RecurrencyKindType.Weekly;
- req.csChargingProfiles.validFrom = c.ValidFrom.Value;
- req.csChargingProfiles.validTo = c.ValidTo.Value;
- req.csChargingProfiles.chargingSchedule = new ChargingSchedule();
- req.csChargingProfiles.chargingSchedule.chargingRateUnit = (c.ChargingRateUnit == 0) ? ChargingRateUnitType.W: ChargingRateUnitType.A;
- req.csChargingProfiles.chargingSchedule.duration = Convert.ToInt32(c.Duration);
- req.csChargingProfiles.chargingSchedule.minChargingRate = c.MinChargingRate.RealValue;
- req.csChargingProfiles.chargingSchedule.startSchedule = c.StartSchedule.Value;
-
-
- req.csChargingProfiles.chargingSchedule.chargingSchedulePeriod = new List<ChargingSchedulePeriod>();
- var chargingPeriod = c.ChargingSchedulePeriod as List<ChargingSchedulePeriodParameter>;
- foreach (var csp in chargingPeriod)
- {
- req.csChargingProfiles.chargingSchedule.chargingSchedulePeriod.Add(new ChargingSchedulePeriod() { startPeriod = Convert.ToInt32(csp.StartPeriod), limit = csp.Limit.RealValue, numberPhases = 3 });
- }
-
- return req;
- }
-
-
-
- public IRequest MakeClearChargingProfileRequest(int connectorId)
- {
- ClearChargingProfileRequest req = new ClearChargingProfileRequest();
- req.connectorId = 0;
- req.id = 1;
- req.stackLevel = 1;
- req.chargingProfilePurpose = ChargingProfilePurposeType.TxDefaultProfile;
- return req;
- }
-
-
-
- public IRequest MakeClearChargingProfileRequest(BaseCmd cmd)
- {
- ClearChargingProfileRequest req = new ClearChargingProfileRequest();
- var c = cmd as Cmd1015;
- if (c.GunSerNo == 255)
- req.connectorId = 0;
- else
- req.connectorId = c.GunSerNo + 1;
- req.id = c.ChargingProfileId;
- req.stackLevel = c.stackLevel;
- req.chargingProfilePurpose = (c.ChargingProfilePurpose == 0) ? ChargingProfilePurposeType.ChargePointMaxProfile : ((c.ChargingProfilePurpose == 1) ? ChargingProfilePurposeType.TxDefaultProfile : ChargingProfilePurposeType.TxProfile);
- return req;
- }
-
-
-
- public IRequest MakeGetCompositeScheduleRequest(int connectorId)
- {
- GetCompositeScheduleRequest req = new GetCompositeScheduleRequest();
- req.connectorId = connectorId;
- req.duration = 120;
- req.chargingRateUnit = ChargingRateUnitType.A;
- return req;
- }
- #endregion SmartCharging
- #region DataTransfer
-
-
-
- public IRequest MakeUpdateFirmware(int type, ProgramParam param, UploadFile uploadFile)
- {
- UpdateFirmware updatefirm = new UpdateFirmware();
- updatefirm.type = (ProgramType)type;
- updatefirm.param = param;
- updatefirm.url = @"http://" + uploadFile.FileUrl;
- updatefirm.md5 = uploadFile.FileMD5.ToUpper();
- DataTransferRequest req = new DataTransferRequest();
- req.vendorId = "Phihong";
- req.messageId = "UpdateFirmware";
- req.data = JsonConvert.SerializeObject(updatefirm);
- return req;
- }
-
-
-
- static public IRequest MakeSendChargingConfigRequest(BaseCmd cmd)
- {
- var c = cmd as Cmd1017;
- DataTransferRequest req = new DataTransferRequest();
- req.vendorId = c.vendorId;
- req.messageId = "SetChargingConfig";
- req.data = JsonConvert.SerializeObject( new ChargingRate() { chargingRateUnit="A", limit=c.limit});
- return req;
- }
-
-
-
- static public IRequest MakeSendGetChargingConfigRequest(BaseCmd cmd)
- {
- var c = cmd as Cmd1019;
- DataTransferRequest req = new DataTransferRequest();
- req.vendorId = c.vendorId;
- req.messageId = "GetChargingConfig";
-
- return req;
- }
-
-
-
- public IRequest MakeSendPartnerPoleIdRequest(string partnerPoleId)
- {
- DataTransferRequest req = new DataTransferRequest();
- req.vendorId = "Phihong";
- req.messageId = "SendPartnerPoleId";
- req.data = partnerPoleId;
- return req;
- }
-
-
-
- public IRequest MakeServerDomainNameRequest(string ServerDomainName)
- {
- DataTransferRequest req = new DataTransferRequest();
- req.vendorId = "Phihong";
- req.messageId = "ServerDomainName";
- req.data = ServerDomainName;
- return req;
- }
-
-
-
- public IRequest MakeAllDayUniformElectricBillRequest(decimal pricePerKWH)
- {
- DataTransferRequest req = new DataTransferRequest();
- req.vendorId = "Phihong";
- req.messageId = "AllDayUniformElectricBill";
- req.data = System.Convert.ToString((double)pricePerKWH);
- return req;
- }
-
-
-
- public IRequest MakeAllDaySectionElectricBillRequest(List<double> sectionElectricBill)
- {
- DataTransferRequest req = new DataTransferRequest();
- req.vendorId = "Phihong";
- req.messageId = "AllDaySectionElectricBill";
- req.data = JsonConvert.SerializeObject(sectionElectricBill);
- return req;
- }
-
-
-
- public IRequest MakeFeePerKWHRequest(decimal pricePerKWH)
- {
- DataTransferRequest req = new DataTransferRequest();
- req.vendorId = "Phihong";
- req.messageId = "FeePerKWH";
- req.data = System.Convert.ToString((double)pricePerKWH);
- return req;
- }
-
-
-
- public IRequest MakeAccountBalanceRequest(string uniqueId, decimal balance, int VehicleType)
- {
- DataTransferRequest req = new DataTransferRequest();
- req.vendorId = "Phihong";
- req.messageId = "AccountBalance";
- AccountBalance account = new AccountBalance();
- account.uniqueId = uniqueId;
- account.balance = (double)balance;
- account.VehicleType = VehicleType;
- req.data = JsonConvert.SerializeObject(account);
- return req;
- }
-
-
-
- public IRequest MakeAutoChargeReservationRequest(AutoChargeReservation autoChargeReservationParam)
- {
- DataTransferRequest req = new DataTransferRequest();
- req.vendorId = "Phihong";
- req.messageId = "AutoChargeReservation";
- req.data = JsonConvert.SerializeObject(autoChargeReservationParam);
- return req;
- }
-
-
-
-
-
-
- public IRequest MakeCustomCommandRequest(int gunNo, int Type)
- {
- DataTransferRequest req = new DataTransferRequest();
- req.vendorId = "Phihong";
- req.messageId = "SetCustomCMD";
- CustomCommand customCommandParam = new CustomCommand();
- customCommandParam.connectorId = gunNo;
- customCommandParam.CommandType = (Type == 18) ? OCPP_Packet.Packet.Status.CustomCommandType.QRCodeFlash : ((Type == 19) ? OCPP_Packet.Packet.Status.CustomCommandType.DisableCharger : OCPP_Packet.Packet.Status.CustomCommandType.EnableCharger);
- req.data = JsonConvert.SerializeObject(customCommandParam);
- return req;
- }
- #endregion DataTransfer
- }
- }
|