Browse Source

add main commit
Commit 0c503b3e: 1. LoadingBalance 邏輯調整,只有手動模式和平均模式,平均模式會除1.05 約 站點契約容量的95%
2.OTA 改成發布後僅下發一次
3.移除台泥程式碼

Robert 1 year ago
parent
commit
31d6030679

+ 0 - 18
EVCB_OCPP.WSServer/Dto/TCCStationInfoDto.cs

@@ -1,18 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace EVCB_OCPP.WSServer.Dto
-{
-    public class TCCStationInfoDto
-    {
-        public decimal Lat { set; get; }
-
-        public decimal Long { set; get; }
-
-        public string ZipCode { set; get; }
-
-    }
-}

+ 0 - 16
EVCB_OCPP.WSServer/Dto/TCCWeatherDto.cs

@@ -1,16 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace EVCB_OCPP.WSServer.Dto
-{
-    public class TCCWeatherDto
-    {
-        public int WeatherID { set; get; }
-
-
-        public int Temperature { set; get; }
-    }
-}

+ 0 - 9
EVCB_OCPP.WSServer/HostedProtalServer.cs

@@ -73,15 +73,6 @@ namespace EVCB_OCPP.WSServer
                         .RepeatForever())
                 );
 
-                q.ScheduleJob<ServerWeatherNotificationJob>(trigger =>
-                    trigger
-                    .WithIdentity("ServerWeatherNotificationJobTrigger")
-                    .StartNow()
-                    .WithSimpleSchedule(x => x
-                        .WithIntervalInMinutes(1)
-                        .RepeatForever())
-                );
-
                 q.ScheduleJob<HealthCheckTriggerJob>(trigger =>
                     trigger
                     .WithIdentity("HealthCheckTriggerJobTrigger")

+ 0 - 217
EVCB_OCPP.WSServer/Jobs/ServerWeatherNotificationJob.cs

@@ -1,217 +0,0 @@
-using EVCB_OCPP.Domain.Models.Database;
-using EVCB_OCPP.WSServer.Dto;
-using EVCB_OCPP.WSServer.Message;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json;
-using OCPPServer.Protocol;
-using Quartz;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Http;
-using System.Text;
-using System.Threading.Tasks;
-using EVCB_OCPP.WSServer.Service;
-using Microsoft.Extensions.Logging;
-using EVCB_OCPP.Domain;
-using Microsoft.EntityFrameworkCore;
-using EVCB_OCPP.Packet.Features;
-using EVCB_OCPP.Packet.Messages.Core;
-
-namespace EVCB_OCPP.WSServer.Jobs;
-
-[DisallowConcurrentExecution]
-public class ServerWeatherNotificationJob : IJob
-{
-    public ServerWeatherNotificationJob(
-        ProtalServer protalServer,
-        IDbContextFactory<MainDBContext> maindbContextFactory,
-        ILogger<ServerWeatherNotificationJob> logger)
-    {
-        this.protalServer = protalServer;
-        this.maindbContextFactory = maindbContextFactory;
-        this.logger = logger;
-    }
-
-    private readonly ProtalServer protalServer;
-    private readonly IDbContextFactory<MainDBContext> maindbContextFactory;
-    private readonly ILogger<ServerWeatherNotificationJob> logger;
-    private OuterHttpClient httpClient = new OuterHttpClient();
-
-    public async Task Execute(IJobExecutionContext context)
-    {
-        //logger.LogDebug("{0} Started", nameof(ServerWeatherNotificationJob));
-        // Console.WriteLine("in...............ServerWeatherNotificationTrigger");
-        BasicMessageHandler msgAnalyser = new BasicMessageHandler();
-        Dictionary<string, ClientData> _copyClientDic = protalServer.ClientDic;
-        var _CheckWeatherDt = DateTime.UtcNow;
-
-        var locations = _copyClientDic.Where(x => !string.IsNullOrEmpty(x.Value.StationLocation)).Distinct().Select(x => x.Value.StationLocation).ToList();
-
-        // Console.WriteLine("in...............ServerWeatherNotificationTrigger");
-        foreach (var location in locations)
-        {
-            try
-            {   //query weather
-                var httpResult = await httpClient.GetWeather("https://api.weatherapi.com/v1/current.json?key=874346abc0874e69a9423510222201&q=" + location, null, null);
-
-                string temp = "17";
-                string weather_code = "1183";
-                if (httpResult.Status == System.Net.HttpStatusCode.OK)
-                {
-                    try
-                    {
-                        var jsonResult = JsonConvert.DeserializeObject(httpResult.Response) as JObject;
-                        temp = jsonResult["current"]["temp_c"].ToString();
-                        weather_code = jsonResult["current"]["condition"]["code"].ToString();
-
-
-                    }
-                    catch (Exception ex)
-                    {
-                        ;
-                    }
-
-                }
-
-                #region 台泥氣象Mapping
-                switch (weather_code)
-                {
-                    case "1000":
-                        weather_code = "1";
-                        break;
-                    case "1003":
-                    case "1006":
-                    case "1009":
-                        weather_code = "2";
-                        break;
-                    case "1063":
-                    case "1072":
-                    case "1150":
-                    case "1153":
-                    case "1168":
-                    case "1171":
-                    case "1180":
-                    case "1183":
-                    case "1186":
-                    case "1189":
-                    case "1192":
-                    case "1195":
-                    case "1198":
-                    case "1201":
-                    case "1237":
-                    case "1240":
-                    case "1243":
-                    case "1246":
-                    case "1261":
-                    case "1264":
-                        weather_code = "3";
-                        break;
-                    case "1087":
-                    case "1273":
-                    case "1276":
-                    case "1279":
-                    case "1282":
-                        weather_code = "4";
-                        break;
-                    case "1066":
-                    case "1069":
-                    case "1114":
-                    case "1117":
-                    case "1204":
-                    case "1207":
-                    case "1210":
-                    case "1213":
-                    case "1216":
-                    case "1219":
-                    case "1222":
-                    case "1225":
-                    case "1249":
-                    case "1252":
-                    case "1255":
-                    case "1258":
-                        weather_code = "5";
-                        break;
-                    case "1030":
-                    case "1135":
-                    case "1147":
-                        weather_code = "2";
-                        break;
-                    default:
-                        weather_code = "2";
-                        break;
-                }
-                #endregion
-
-
-                if (protalServer.TCCStationDic.ContainsKey(location))
-                {
-                    protalServer.TCCStationDic[location].Temperature = (int)double.Parse(temp);
-                    protalServer.TCCStationDic[location].WeatherID = int.Parse(weather_code);
-                }
-                else
-                {
-                    protalServer.TCCStationDic.Add(location, new TCCWeatherDto() { WeatherID = int.Parse(weather_code), Temperature = (int)double.Parse(temp) });
-                }
-
-            }
-            catch (Exception ex)
-            {
-                logger.LogError("ServerWeatherNotificationTrigger ChargeBoxId:{0}  Ex:{1}", location, ex.ToString());
-            }
-        }
-
-        var clients = _copyClientDic.Where(x => x.Value.CustomerId == new Guid("009E603C-79CD-4620-A2B8-D9349C0E8AD8")).
-        Select(x => new { ChargeBoxId = x.Value.ChargeBoxId, StationLocation = x.Value.StationLocation }).ToList();
-
-        using (var db = maindbContextFactory.CreateDbContext())
-        {
-
-            foreach (var client in clients)
-            {
-                try
-                {
-                    if (string.IsNullOrEmpty(client.StationLocation))
-                    {
-                        Console.WriteLine(client.StationLocation + " is empty");
-                        continue;
-                    }
-
-
-                    if (protalServer.TCCStationDic.ContainsKey(client.StationLocation))
-                    {
-                        db.ServerMessage.Add(new ServerMessage()
-                        {
-                            ChargeBoxId = client.ChargeBoxId,
-                            CreatedBy = "Server",
-                            CreatedOn = DateTime.UtcNow,
-                            OutAction = Actions.DataTransfer.ToString(),
-                            OutRequest = JsonConvert.SerializeObject(
-                                               new DataTransferRequest()
-                                               {
-                                                   messageId = "ID_Weather_Info",
-                                                   vendorId = "Phihong Technology",
-                                                   data = JsonConvert.SerializeObject(
-                                                       new
-                                                       {
-                                                           weatherId = protalServer.TCCStationDic[client.StationLocation].WeatherID,
-                                                           Temperature = protalServer.TCCStationDic[client.StationLocation].Temperature
-                                                       })
-                                               },
-                                               new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
-                            SerialNo = Guid.NewGuid().ToString(),
-                            InMessage = string.Empty
-
-                        });
-
-                        db.SaveChanges();
-                    }
-                }
-                catch (Exception ex)
-                {
-                    logger.LogError("ServerWeatherNotificationTrigger ChargeBoxId:{0}  Ex:{1}", client.ChargeBoxId, ex.ToString());
-                }
-            }
-        }
-    }
-}

+ 10 - 13
EVCB_OCPP.WSServer/Message/FirmwareManagementProfileHandler.cs

@@ -79,6 +79,9 @@ namespace EVCB_OCPP.WSServer.Message
 
                                         db.SaveChanges();
 
+                                        var clearMachine = db.Machine.Where(x => x.Id == machine.Id).FirstOrDefault();
+                                        clearMachine.FW_AssignedVersion = null;
+                                        db.SaveChanges();
                                     }
 
                                 }
@@ -93,22 +96,16 @@ namespace EVCB_OCPP.WSServer.Message
                                     {
                                         item.EVSE_Status = (int)_request.status;
                                         item.FinishedOn = DateTime.UtcNow;
-                                        if (string.IsNullOrEmpty(item.EVSE_Value))
-                                        {
-                                            Console.WriteLine("怎麼悾悾的");
-                                        }
 
-                                        if (!string.IsNullOrEmpty(item.EVSE_Value) && _request.status == Packet.Messages.SubTypes.FirmwareStatus.Installed)
-                                        {
-                                            int version = 0;
-                                            int.TryParse(item.EVSE_Value.Split(':').Last(), out version);
-                                            var machine = await db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).FirstOrDefaultAsync();
-                                            machine.FW_VersionReport = version;
-                                        }
+                                        //if (!string.IsNullOrEmpty(item.EVSE_Value) && _request.status == Packet.Messages.SubTypes.FirmwareStatus.Installed)
+                                        //{
+                                        //    int version = 0;
+                                        //    int.TryParse(item.EVSE_Value.Split(':').Last(), out version);
+                                        //    var machine = await db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).FirstOrDefaultAsync();
+                                        //    machine.FW_VersionReport = version;
+                                        //}
                                     }
 
-
-
                                     db.SaveChanges();
                                 }
                             }

+ 3 - 3
EVCB_OCPP.WSServer/Message/SmartChargingProfileHandler.cs

@@ -35,9 +35,9 @@ namespace EVCB_OCPP.WSServer.Message
                             chargingRateUnit = unit,
                             chargingSchedulePeriod = new List<Packet.Messages.SubTypes.ChargingSchedulePeriod>()
                                                     {
-                                                        new Packet.Messages.SubTypes.ChargingSchedulePeriod(){  startPeriod=0, limit=value*1000}
+                                                        new Packet.Messages.SubTypes.ChargingSchedulePeriod(){  startPeriod=0, limit=value}
                                                     },
-                            duration = 60,
+                            duration = 86400,
 
                         },
                         recurrencyKind = Packet.Messages.SubTypes.RecurrencyKindType.Daily,
@@ -53,7 +53,7 @@ namespace EVCB_OCPP.WSServer.Message
                     CreatedOn = DateTime.UtcNow,
                     OutAction = _setProfileRequest.Action.ToString(),
                     OutRequest = JsonConvert.SerializeObject(_setProfileRequest, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
-                    SerialNo = Guid.Empty.ToString(),
+                    SerialNo = Guid.NewGuid().ToString(),
                     InMessage = string.Empty
 
                 });

+ 5 - 14
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -89,6 +89,7 @@ namespace EVCB_OCPP.WSServer
             WarmUpLog();
         }
 
+        #region private fields
         private OuterHttpClient httpClient = new OuterHttpClient();
         private DateTime lastcheckdt = DateTime.UtcNow.AddSeconds(-20);
         private ConcurrentDictionary<string, ClientData> clientDic = new ConcurrentDictionary<string, ClientData>();
@@ -107,9 +108,9 @@ namespace EVCB_OCPP.WSServer
         private List<NeedConfirmMessage> needConfirmPacketList = new List<NeedConfirmMessage>();
         private DateTime checkUpdateDt = DateTime.UtcNow;
         private DateTime _CheckFeeDt = DateTime.UtcNow;
-        private DateTime _CheckWeatherDt = DateTime.UtcNow;
+        private DateTime _CheckLBDt = DateTime.UtcNow;
         private readonly LoadingBalanceService _loadingBalanceService;// = new LoadingBalanceService();
-        internal Dictionary<string, TCCWeatherDto> TCCStationDic = new Dictionary<string, TCCWeatherDto>();
+        private List<StationInfoDto> _StationInfo = new List<StationInfoDto>();
 
         private List<string> needConfirmActions = new List<string>()
         {
@@ -146,7 +147,7 @@ namespace EVCB_OCPP.WSServer
         };
         private CancellationTokenSource _cts = new CancellationTokenSource();
         private CancellationToken _ct;
-        private string _ocpp20NetworkSetting = "";
+        #endregion
 
         internal Dictionary<string, ClientData> ClientDic
         {
@@ -208,7 +209,7 @@ namespace EVCB_OCPP.WSServer
                 Console.WriteLine("Please check App.Config setting .");
                 return;
             }
-            //ReadTCCSetting();
+            
             OpenNetwork();
 
             if (!isInDocker)
@@ -243,7 +244,6 @@ namespace EVCB_OCPP.WSServer
                         Console.WriteLine("Command GC");
                         GC.Collect();
                         break;
-
                     case "lc":
                         {
                             Console.WriteLine("Command List Clients");
@@ -382,19 +382,12 @@ namespace EVCB_OCPP.WSServer
                 Dictionary<string, ClientData> _copyClientDic = null;
                 _copyClientDic = new Dictionary<string, ClientData>(clientDic);
                 var list = _copyClientDic.Select(c => c.Value).ToList();
-                var locations = _copyClientDic.Where(x => !string.IsNullOrEmpty(x.Value.StationLocation)).Distinct().Select(x => x.Value.StationLocation).ToList();
                 int i = 1;
                 foreach (var c in list)
                 {
                     toReturn.Add(i + ":" + c.ChargeBoxId + " " + c.SessionID);
                     i++;
                 }
-
-                foreach (var c in TCCStationDic)
-                {
-                    toReturn.Add(i + ":" + c.Key + "-" + c.Value.Temperature + "/" + c.Value.WeatherID);
-                    i++;
-                }
                 return string.Join("\r\n", toReturn);
             });
 
@@ -895,7 +888,6 @@ namespace EVCB_OCPP.WSServer
 
                                                 });
 
-
                                                 db.SaveChanges();
                                             }
 
@@ -1209,7 +1201,6 @@ namespace EVCB_OCPP.WSServer
             }
         }
 
-
         private void Send(ClientData session, string msg, string messageType, string errorMsg = "")
         {
             try

+ 1 - 2
EVCB_OCPP.WSServer/SuperSocket.Protocol/ClientData.cs

@@ -78,10 +78,9 @@ namespace OCPPServer.Protocol
         public string CustomerName { get; set; }
 
 
-        public string StationName { set; get; }
+        public string StationId { set; get; }
 
 
-        public string StationLocation { set; get; }
 
         public delegate void OCPPClientDataEventHandler<ClientData, String>(ClientData clientdata, String msg);