瀏覽代碼

1.Transaction 加入SOC & 拿掉
2. RemotetriggerTool 加入 破壞模式的 SignedUpdateFirmware /V1.3.0 (20230613)

Jessica Tseng 1 年之前
父節點
當前提交
abfcf96e23

+ 4 - 4
EVCB_OCPP.WSServer/App.config

@@ -7,10 +7,10 @@
     <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
   </configSections>
    <connectionStrings>
-     <add name="ConnectionLogDBContext" connectionString="Server=tcp:zerova-evbackend.database.windows.net,1433;initial catalog=StandardOCPP_ConnectionLog;persist security info=True;user id=ev_user;password=Thw2DEa2hZPdg;MultipleActiveResultSets=True;App=EntityFramework; Max Pool Size=500" providerName="System.Data.SqlClient" />
-      <add name="MainDBContext" connectionString="Server=tcp:zerova-ev-dev.database.windows.net,1433;initial catalog=StandardOCPP_Main;;persist security info=True;user id=ev_user;password=azdevsoftware#az;MultipleActiveResultSets=True;App=EntityFramework; Max Pool Size=1000" providerName="System.Data.SqlClient" />
-     <add name="MeterValueDBContext" connectionString="Server=tcp:zerova-evbackend.database.windows.net,1433;initial catalog=StandardOCPP_MeterValue;;persist security info=True;user id=ev_user;password=Thw2DEa2hZPdg;MultipleActiveResultSets=True;App=EntityFramework; Max Pool Size=500" providerName="System.Data.SqlClient" />
-     <add name="WebDBContext" connectionString="Server=tcp:zerova-evbackend.database.windows.net,1433;initial catalog=StandardOCPP_Web;;persist security info=True;user id=ev_user;password=Thw2DEa2hZPdg;MultipleActiveResultSets=True;App=EntityFramework; Max Pool Size=500" providerName="System.Data.SqlClient" />
+     <add name="ConnectionLogDBContext" connectionString="data source=.\SQLEXPRESS;initial catalog=StandardOCPP_ConnectionLog;;persist security info=True;user id=Phihong;password=GOGOGO;MultipleActiveResultSets=True;App=EntityFramework; Max Pool Size=500" providerName="System.Data.SqlClient" />
+     <add name="MainDBContext" connectionString="data source=.\SQLEXPRESS;initial catalog=StandardOCPP_Main;;persist security info=True;user id=Phihong;password=GOGOGO;MultipleActiveResultSets=True;App=EntityFramework; Max Pool Size=500" providerName="System.Data.SqlClient" />
+     <add name="MeterValueDBContext" connectionString="data source=.\SQLEXPRESS;initial catalog=StandardOCPP_MeterValue;;persist security info=True;user id=Phihong;password=GOGOGO;MultipleActiveResultSets=True;App=EntityFramework; Max Pool Size=500" providerName="System.Data.SqlClient" />
+     <add name="WebDBContext" connectionString="data source=.\SQLEXPRESS;initial catalog=StandardOCPP_Web;;persist security info=True;user id=Phihong;password=GOGOGO;MultipleActiveResultSets=True;App=EntityFramework; Max Pool Size=500" providerName="System.Data.SqlClient" />
    </connectionStrings>
   <appSettings>   
     <add key="LocalAuthAPI" value="https://evcb.zerovatech.com/PortalApi/1" />    

+ 17 - 0
EVCB_OCPP.WSServer/Dto/TransactionSOCDto.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EVCB_OCPP.WSServer.Dto
+{
+    internal class TransactionSoCDto
+    {
+        public int TransactionId { set; get;}
+
+        public int MinSoC { set; get; }
+
+        public int MaxSoC { set; get; }
+    }
+}

+ 1 - 0
EVCB_OCPP.WSServer/EVCB_OCPP.WSServer.csproj

@@ -154,6 +154,7 @@
     <Compile Include="Dto\StationFee.cs" />
     <Compile Include="Dto\StationInfoDto.cs" />
     <Compile Include="Dto\TransactionEnergy.cs" />
+    <Compile Include="Dto\TransactionSOCDto.cs" />
     <Compile Include="Message\OCPP16MessageHandler.cs" />
     <Compile Include="Message\OCPP20MessageHandler.cs" />
     <Compile Include="Message\SecurityProfileHandler.cs" />

+ 58 - 3
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs

@@ -13,6 +13,7 @@ using NLog;
 using OCPPPackage.Profiles;
 using OCPPServer.Protocol;
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Configuration;
 using System.Data;
@@ -180,7 +181,7 @@ namespace EVCB_OCPP.WSServer.Message
                                 }
 
                                 confirm.status = DataTransferStatus.Accepted;
-                                confirm.data = JsonConvert.SerializeObject(new { certificateStatus = iso15118_token == "12345678901234" ? "Accepted" : "CertificateExpired", idTokenInfo = new  { status = iso15118_token=="12345678901234"? "Accepted" : "Invalid" }  });
+                                confirm.data = JsonConvert.SerializeObject(new { certificateStatus = iso15118_token == "12345678901234" ? "Accepted" : "CertificateExpired", idTokenInfo = new { status = iso15118_token == "12345678901234" ? "Accepted" : "Invalid" } });
 
 
                             }
@@ -592,10 +593,11 @@ namespace EVCB_OCPP.WSServer.Message
                             int _ConnectorId = 0;
 
                             var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
-
                             var _idTagInfo = string.IsNullOrEmpty(_request.idTag) ? null : (_request.idTag == "Backend" ?
                                 new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted } : (await businessService.Authorize(session.ChargeBoxId, _request.idTag)).IdTagInfo);
 
+
+
                             //特例****飛宏客戶旗下的電樁,若遇到Portal沒回應的狀況 ~允許充電
                             if (session.CustomerId.ToString().ToUpper() == "8456AED9-6DD9-4BF3-A94C-9F5DCB9506F7" && _idTagInfo != null && _idTagInfo.status == AuthorizationStatus.ConcurrentTx)
                             {
@@ -608,8 +610,27 @@ namespace EVCB_OCPP.WSServer.Message
                                     var transaction = db.TransactionRecord.Where(x => x.Id == _request.transactionId
                                      && x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
 
+                                    #region 加入Transaction Start/StopSOC
+                                    if (!session.IsAC && _request.transactionId > 0)
+                                    {
+                                        var SearchTime = transaction.StartTime;
+                                        var txStopTime = _request.timestamp;
+                                        List<int> SOCCollection = new List<int>();
 
+                                        while (SearchTime.Date <= txStopTime.Date)
+                                        {
+
+                                            var searchResults = await GetTransactionSOC(transaction.Id, SearchTime.Date);
+                                            SOCCollection.AddRange(searchResults);
+                                            SearchTime = SearchTime.AddDays(1);
+                                        }
 
+                                        SOCCollection.Sort();
+                                        logger.Debug(string.Format("SOCCollection:" + String.Join(",", SOCCollection.Select(x => x.ToString()).ToArray())));
+                                        transaction.StartSOC = SOCCollection.First().ToString("0");
+                                        transaction.StopSOC = SOCCollection.Last().ToString("0");
+                                    }
+                                    #endregion
                                     //遠傳太久以前的停止充電 直接拒絕 避免電樁持續重送~~~~~~~
                                     if (_request.timestamp < new DateTime(2021, 11, 1))
                                     {
@@ -878,7 +899,7 @@ namespace EVCB_OCPP.WSServer.Message
                                         db.Entry(machine).Property(x => x.BoardVersions).IsModified = true;
                                         await db.SaveChangesAsync();
                                     }
-                                }                              
+                                }
 
                                 if (_request.messageId == "ID_TxEnergy") //計費
                                 {
@@ -1639,5 +1660,39 @@ namespace EVCB_OCPP.WSServer.Message
 
             return money;
         }
+
+
+        async private Task<List<int>> GetTransactionSOC(int TxId, DateTime queryDate)
+        {
+            List<int> SOCCollection = new List<int>();
+            try
+            {
+                using (var _meterDb = new MeterValueDBContext())
+                {
+                    var parameters = new DynamicParameters();
+                    parameters.Add("@TransactionId", TxId, DbType.Int32, ParameterDirection.Input);
+
+                    string strSql = "SELECT [TransactionId],Min(Value) as MinSoC,Max(Value) as MaxSoC  " +
+                        "FROM [dbo].ConnectorMeterValueRecord" + queryDate.Date.ToString("yyMMdd") + "  where TransactionId=@TransactionId and MeasurandId=20 group by [TransactionId]";
+
+                    var result = await _meterDb.Database.Connection.QueryFirstOrDefaultAsync<TransactionSoCDto>(strSql, parameters);
+                    //  SOCCollection = results.Select(decimal.Parse).ToList();
+
+                    if(result != null)
+                    {
+               
+                        SOCCollection.Add(result.MaxSoC);
+                        SOCCollection.Add(result.MinSoC);
+                    }                  
+
+                }
+            }
+            catch (Exception ex)
+            {
+
+            }
+
+            return SOCCollection;
+        }
     }
 }

+ 1 - 1
EVCB_OCPP.WSServer/Properties/AssemblyInfo.cs

@@ -35,4 +35,4 @@ using System.Runtime.InteropServices;
 [assembly: AssemblyVersion("0.1.0.0")]
 [assembly: AssemblyFileVersion("0.1.0.0")]
 
-[assembly: AssemblyInformationalVersion("e4e1bcc")]
+[assembly: AssemblyInformationalVersion("327fc93")]

+ 9 - 2
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -1006,7 +1006,7 @@ namespace EVCB_OCPP.WSServer
         }
 
         async private void DenyModelCheckTrigger(bool warmup)
-        {
+        {           
             for (; ; )
             {
                 if (_ct.IsCancellationRequested)
@@ -1824,6 +1824,12 @@ namespace EVCB_OCPP.WSServer
         {
             try
             {
+                using (var main = new MainDBContext())
+                {
+                    main.Machine.Where(x => x.ChargeBoxId == "AAA").FirstOrDefault();
+                    // log.MachineConnectionLog.ToList();
+                }
+
                 using (var log = new ConnectionLogDBContext())
                 {
                     log.MachineConnectionLog.ToList();
@@ -1831,7 +1837,8 @@ namespace EVCB_OCPP.WSServer
             }
             catch (Exception ex)
             {
-                Console.WriteLine(ex.ToString());
+                logger.Error(ex.ToString());
+                //Console.WriteLine(ex.ToString());
             }
 
 

二進制
SuperWebSocket/bin/Debug/SuperWebSocket.dll


二進制
SuperWebSocket/bin/Debug/SuperWebSocket.pdb


+ 1 - 0
TestTool.RemoteTriggerAPP/MainWindow.xaml

@@ -47,6 +47,7 @@
                 <ComboBoxItem>TriggerMessage_Heartbeat</ComboBoxItem>
                 <ComboBoxItem>TriggerMessage_MeterValues</ComboBoxItem>
                 <ComboBoxItem>TriggerMessage_StatusNotification</ComboBoxItem>
+                <ComboBoxItem>SignedUpdateFirmware</ComboBoxItem>               
             </ComboBox>
             <Label  Content="Remote Trigger Cmd:" HorizontalAlignment="Left" Height="27" Margin="69,191,0,0" VerticalAlignment="Top" Width="137"/>
             <Button Name="uxSubmitBtn" Content="Submit" HorizontalAlignment="Left" Margin="265.333,188,0,0" VerticalAlignment="Top" Width="51" Height="34" Click="UxSubmitBtn_Click" Grid.Column="1"/>