Browse Source

1. add api log
2. add support of DD

Robert 1 year ago
parent
commit
5acfa48e98

+ 10 - 0
AwInitilizer/Assist/EvHttpClient.cs

@@ -32,6 +32,8 @@ namespace AwInitilizer.Assist
         private static string pass = "1231231238";
         internal static string ServerIpAddress = "192.168.1.10";
         internal static string ServerUrl = "https://192.168.1.10";
+        //internal static string ServerIpAddress = "172.18.13.84";
+        //internal static string ServerUrl = "https://172.18.13.84";
         //updated EV
         //internal static string ServerIpAddress = "192.168.80.197";
         //internal static string ServerUrl = "https://192.168.80.197";
@@ -134,6 +136,8 @@ namespace AwInitilizer.Assist
             try
             {
                 var url = string.Format("{0}/{1}", ServerUrl, api);
+                EvHttpClientLogger.Instance.Log(url);
+
                 Dictionary<string, string> pams = new Dictionary<string, string>
                 {
                     { "account", account },
@@ -193,13 +197,17 @@ namespace AwInitilizer.Assist
 
                     try
                     {
+                        EvHttpClientLogger.Instance.Log("post with new version");
                         postResult = await evClient.PostAsync(url, formContent);
+                        EvHttpClientLogger.Instance.Log(postResult.StatusCode.ToString());
+
                         //MessageBox.Show("Rest Result:" + postResult.StatusCode);
                         if (postResult == null || !postResult.IsSuccessStatusCode)
                         {
                             throw new Exception("Post fail");
                         }
                         result = await postResult.Content.ReadAsStringAsync();
+                        EvHttpClientLogger.Instance.Log(result);
 
                         //MessageBox.Show("Rest Result:" + result);
 
@@ -238,6 +246,7 @@ namespace AwInitilizer.Assist
 
                 using (WebClientTimeout webClient = new WebClientTimeout())
                 {
+                    EvHttpClientLogger.Instance.Log("post with old version");
                     NameValueCollection parameters = new NameValueCollection();
                     foreach (var inpam in param)
                     {
@@ -252,6 +261,7 @@ namespace AwInitilizer.Assist
                         // 將 StreamReader 所讀到的字元轉為 string
                         result = await reader.ReadToEndAsync();
                     }
+                    EvHttpClientLogger.Instance.Log(result);
 
                     var check = JsonConvert.DeserializeObject<EvAuthMsg>(result);
                     if (check != null &&

+ 58 - 0
AwInitilizer/Assist/EvHttpClientLogger.cs

@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AwInitilizer.Assist
+{
+    public class EvHttpClientLogger
+    {
+        public static EvHttpClientLogger Instance => _Instance;
+
+        private static EvHttpClientLogger _Instance = new EvHttpClientLogger();
+
+        private EvHttpClientLogger()
+        {
+            if (!Directory.Exists(FolderName))
+            {
+                Directory.CreateDirectory(FolderName);
+            }
+        }
+        private const string FolderName = "ApiLog";
+        private const int MaxLogCnt = 10;
+        private string LogFileName = null;
+
+        internal void StartNewLog(string name)
+        {
+            TryRemoveOneLog();
+            LogFileName = name + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".txt";
+        }
+
+        internal void Log(string mesasage)
+        {
+            if (string.IsNullOrEmpty(LogFileName))
+            {
+                return;
+            }
+            File.AppendAllText(Path.Combine(FolderName, LogFileName), mesasage + Environment.NewLine);
+        }
+
+        private void TryRemoveOneLog()
+        {
+            var files = Directory.GetFiles(FolderName).ToList();
+            if (files.Count < MaxLogCnt)
+            {
+                return;
+            }
+
+            List<FileInfo> fileInfos = new List<FileInfo>();
+            foreach (var file in files) {
+                fileInfos.Add(new FileInfo(file));
+            }
+            var candidateFile = fileInfos.OrderBy(x => x.LastWriteTimeUtc).First();
+            candidateFile.Delete();
+        }
+    }
+}

+ 8 - 0
AwInitilizer/Initializer.csproj

@@ -91,9 +91,13 @@
     </ApplicationDefinition>
     <Compile Include="Assist\EvApi.cs" />
     <Compile Include="Assist\EvHttpClient.cs" />
+    <Compile Include="Assist\EvHttpClientLogger.cs" />
     <Compile Include="Converter\MesErrorCodeMaper.cs" />
     <Compile Include="Converter\PressStatusConverter.cs" />
     <Compile Include="KeyinListener.cs" />
+    <Compile Include="ManualSn.xaml.cs">
+      <DependentUpon>ManualSn.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Model\AppSettingConfig.cs" />
     <Compile Include="ProcedureLog\LogWriter.cs" />
     <Compile Include="Procedure\FirmwareFtpUploadProcedure.cs" />
@@ -142,6 +146,10 @@
       <DependentUpon>MainWindow.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
+    <Page Include="ManualSn.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="SigninDialog.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 1 - 0
AwInitilizer/MainWindow.xaml

@@ -12,6 +12,7 @@
     Height="1080"
     input:InputMethod.IsInputMethodEnabled="False"
     Background="#FF363535"
+    PreviewKeyDown="MainWindow_PreviewKeyDown"
     WindowStartupLocation="CenterScreen"
     WindowState="Maximized"
     mc:Ignorable="d"

+ 98 - 58
AwInitilizer/MainWindow.xaml.cs

@@ -1,4 +1,5 @@
-using AwInitilizer.Model;
+using AwInitilizer.Assist;
+using AwInitilizer.Model;
 using AwInitilizer.Procedure;
 using MesAdaptor;
 using Microsoft.Win32;
@@ -19,6 +20,7 @@ using System.Windows.Controls;
 using System.Windows.Data;
 using System.Windows.Documents;
 using System.Windows.Input;
+using System.Windows.Interop;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
@@ -125,9 +127,10 @@ namespace AwInitilizer
 
         private void MainWindow_PreviewKeyDown(object sender, KeyEventArgs e)
         {
+            CheckDisplayManulEnterSN(e.Key);
             ResetLogoutTimer();
-        }
-
+        }
+
         private void SystemIDScanReseived(SystemID systemID)
         {
             ViewModel.IsInputCheckpassed = false;
@@ -193,6 +196,7 @@ namespace AwInitilizer
             {
                 ViewModel.IsUdatIng = true;
                 UpdateStatus = UpdateStatus.Updating;
+                EvHttpClientLogger.Instance.StartNewLog(serialNumber);
                 _ = UpdateTask();
             }
         }
@@ -642,6 +646,7 @@ namespace AwInitilizer
                 ViewModel.ICCID = setting.ICCID;
                 ViewModel.IMSI = setting.IMSI;
                 ViewModel.SkipEmergencyButton = setting.SkipEmergencyButton;
+                ViewModel.SkipButtonTest = setting.SkipButtonTest;
                 ViewModel.FirmwareUpdateModels = setting.FirmwareUpdateList
                     .Where(x => !string.IsNullOrEmpty(x.Module) && !string.IsNullOrEmpty(x.FirmwareFileName)
                     ).ToList();
@@ -774,59 +779,7 @@ namespace AwInitilizer
                             {
                                 try
                                 {
-                                    using (var fs = File.OpenRead(filePath))
-                                    {
-                                        byte[] systemIDBytes = new byte[16];
-                                        if (fs.Read(systemIDBytes, 0, 16) == 16)
-                                        {
-                                            if (systemIDBytes.ToList().Contains(0x00))
-                                            {
-                                                int endIndex = Array.FindIndex(systemIDBytes, (x) => { return x == 0x00; });
-                                                //int endIndex = parameter.FindIndex((x) => { return x == 0x00; });
-                                                if (endIndex != default && endIndex != -1)
-                                                {
-                                                    systemIDBytes = systemIDBytes.Take(endIndex).ToArray();
-                                                }
-                                            }
-
-                                            if (ModelName.TryLooseParse(systemIDBytes, out var modelName))
-                                            {
-                                                if (modelName.ToString() != setting.ModelName)
-                                                {
-                                                    //HintDialog.ShowMessage($"{model.Module} Firemware and ModelName is Mismatched");
-                                                    HintDialog.ShowMessage(string.Format(Resx.AppResources.InitFirmwareFileHeaderMismatchAlert, model.Module));
-                                                    isCheckPassed = false;
-                                                }
-                                            }
-                                            else
-                                            {
-                                                // HintDialog.ShowMessage($"{model.Module} Firemware header ERROR");
-                                                HintDialog.ShowMessage(string.Format(Resx.AppResources.InitFirmwareFileHeaderFormatAlert, model.Module));
-                                                isCheckPassed = false;
-                                            }
-                                        }
-                                        else
-                                        {
-                                            //HintDialog.ShowMessage($"{model.Module} Firemware header ERROR");
-                                            HintDialog.ShowMessage(string.Format(Resx.AppResources.InitFirmwareFileHeaderFormatAlert, model.Module));
-                                            isCheckPassed = false;
-                                        }
-
-                                        //byte[] imgType = new byte[4];
-                                        //if (fs.Read(imgType, 0, 4) == 4)
-                                        //{
-                                        //    if (!imgType.SequenceEqual(new byte[] { 0x10, 0x00, 0x00, 0x04, }))
-                                        //    {
-                                        //        HintDialog.ShowMessage($"{model.Module} Firemware type ERROR");
-                                        //        isCheckPassed = false;
-                                        //    }
-                                        //}
-                                        //else
-                                        //{
-                                        //    HintDialog.ShowMessage($"{model.Module} Firemware header ERROR");
-                                        //    isCheckPassed = false;
-                                        //}
-                                    }
+                                    //isCheckPassed = CheckFileHeaderModel(setting, isCheckPassed, model, filePath);
                                 }
                                 catch
                                 {
@@ -843,8 +796,67 @@ namespace AwInitilizer
             }
 
             return isCheckPassed;
-        }
-
+        }
+
+        private static bool CheckFileHeaderModel(SettingConfig setting, bool isCheckPassed, FirmwareUpdateModel model, string filePath)
+        {
+            using (var fs = File.OpenRead(filePath))
+            {
+                byte[] systemIDBytes = new byte[16];
+                if (fs.Read(systemIDBytes, 0, 16) == 16)
+                {
+                    if (systemIDBytes.ToList().Contains(0x00))
+                    {
+                        int endIndex = Array.FindIndex(systemIDBytes, (x) => { return x == 0x00; });
+                        //int endIndex = parameter.FindIndex((x) => { return x == 0x00; });
+                        if (endIndex != default && endIndex != -1)
+                        {
+                            systemIDBytes = systemIDBytes.Take(endIndex).ToArray();
+                        }
+                    }
+
+                    if (ModelName.TryLooseParse(systemIDBytes, out var modelName))
+                    {
+                        if (modelName.ToString() != setting.ModelName)
+                        {
+                            //HintDialog.ShowMessage($"{model.Module} Firemware and ModelName is Mismatched");
+                            HintDialog.ShowMessage(string.Format(Resx.AppResources.InitFirmwareFileHeaderMismatchAlert, model.Module));
+                            isCheckPassed = false;
+                        }
+                    }
+                    else
+                    {
+                        // HintDialog.ShowMessage($"{model.Module} Firemware header ERROR");
+                        HintDialog.ShowMessage(string.Format(Resx.AppResources.InitFirmwareFileHeaderFormatAlert, model.Module));
+                        isCheckPassed = false;
+                    }
+                }
+                else
+                {
+                    //HintDialog.ShowMessage($"{model.Module} Firemware header ERROR");
+                    HintDialog.ShowMessage(string.Format(Resx.AppResources.InitFirmwareFileHeaderFormatAlert, model.Module));
+                    isCheckPassed = false;
+                }
+
+                //byte[] imgType = new byte[4];
+                //if (fs.Read(imgType, 0, 4) == 4)
+                //{
+                //    if (!imgType.SequenceEqual(new byte[] { 0x10, 0x00, 0x00, 0x04, }))
+                //    {
+                //        HintDialog.ShowMessage($"{model.Module} Firemware type ERROR");
+                //        isCheckPassed = false;
+                //    }
+                //}
+                //else
+                //{
+                //    HintDialog.ShowMessage($"{model.Module} Firemware header ERROR");
+                //    isCheckPassed = false;
+                //}
+            }
+
+            return isCheckPassed;
+        }
+
         private void ResetLogoutTimer()
         {
             if (LogoutTimer != null)
@@ -963,6 +975,34 @@ namespace AwInitilizer
                 uxStatus.Foreground = new SolidColorBrush(Colors.White);
                 uxStatus.Content = Resx.AppResources.StatusFail;//"Fail";
             }
+        }
+
+        private void CheckDisplayManulEnterSN(Key key)
+        {
+            if (key != Key.F1)
+            {
+                return;
+            }
+
+            var dialog = new ManualSn() {};
+            try
+            {
+                dialog.Owner = Application.Current.MainWindow;
+            }
+            catch
+            {
+
+            }
+            dialog.ShowDialog();
+            var enteredSN = dialog.EnteredSn;
+
+            if (string.IsNullOrEmpty(enteredSN)||
+               !SystemID.TryLooseParse(enteredSN, out var enteredSystemID))
+            {
+                return;
+            }
+
+            SystemIDScanReseived(enteredSystemID);
         }
     }
 }

+ 41 - 0
AwInitilizer/ManualSn.xaml

@@ -0,0 +1,41 @@
+<Window
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+    xmlns:local="clr-namespace:AwInitilizer"
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    Title="ManualSn"
+    Width="600"
+    Height="150"
+    ResizeMode="NoResize"
+    Topmost="True"
+    WindowStartupLocation="CenterOwner"
+    WindowStyle="SingleBorderWindow"
+    mc:Ignorable="d"
+    x:Class="AwInitilizer.ManualSn">
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="*" />
+            <RowDefinition Height="auto" />
+        </Grid.RowDefinitions>
+        <Grid Grid.Row="0">
+            <TextBox
+                x:Name="uxSn"
+                Margin="20"
+                VerticalAlignment="Center" />
+        </Grid>
+        <Grid
+            x:Name="uxCancelContainer"
+            Grid.Row="1"
+            Height="40">
+            <Button
+                Width="100"
+                Height="30"
+                HorizontalAlignment="Center"
+                VerticalAlignment="Center"
+                Click="Button_Click">
+                <Label x:Name="uxBtnText" Content="Confirm" />
+            </Button>
+        </Grid>
+    </Grid>
+</Window>

+ 35 - 0
AwInitilizer/ManualSn.xaml.cs

@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace AwInitilizer
+{
+    /// <summary>
+    /// ManualSn.xaml 的互動邏輯
+    /// </summary>
+    public partial class ManualSn : Window
+    {
+        public ManualSn()
+        {
+            InitializeComponent();
+        }
+
+        public string EnteredSn { get; private set; }
+
+        private void Button_Click(object sender, RoutedEventArgs e)
+        {
+            this.EnteredSn = uxSn.Text;
+            this.Close();
+        }
+    }
+}

+ 1 - 0
AwInitilizer/Model/SettingConfig.cs

@@ -15,6 +15,7 @@ namespace AwInitilizer.Model
         public string ICCID { get; set; }
         public string IMSI { get; set; }
         public bool SkipEmergencyButton { get; set; }
+        public bool SkipButtonTest { get; set; }
         public List<FirmwareUpdateModel> FirmwareUpdateList { get; set; }
     }
 }

+ 14 - 0
AwInitilizer/Model/UpdateData.cs

@@ -119,6 +119,20 @@ namespace AwInitilizer.Model
             }
         }
 
+        private bool _SkipButtonTest;
+        public bool SkipButtonTest
+        {
+            get => _SkipButtonTest;
+            set
+            {
+                if (_SkipButtonTest != value)
+                {
+                    _SkipButtonTest = value;
+                    RaisePropertyChanged("SkipButtonTest");
+                }
+            }
+        }
+
         private List<FirmwareUpdateModel> _FirmwareUpdateModels;
         public List<FirmwareUpdateModel> FirmwareUpdateModels
         {

+ 5 - 0
AwInitilizer/Procedure/ButtonStatusCheckPorcedure.cs

@@ -61,6 +61,11 @@ namespace AwInitilizer.Procedure.ButtonStatusCheck
 
         internal override async Task<bool> Run()
         {
+            if (UpdateData.SkipButtonTest)
+            {
+                return true;
+            }
+
             //await PressBtnCheck(0);
             //DismisDialog();
             //await PressBtnCheck(1);

+ 2 - 1
AwInitilizer/Procedure/FirmwareCheckVersionProcedure.cs

@@ -111,7 +111,8 @@ namespace AwInitilizer.Procedure.FirmwareCheckVersion
                 LogWriter.Log(string.Format("Read {0} version : {1} , Expect:{2}", model.Module, versionPair[model.Module], model.Version));
 
                 bool isVersionMatched = false;
-                if (model.Module == "CsuRootFsFwRev")
+                if (model.Module == "CsuRootFsFwRev" ||
+                    model.Module.StartsWith("DDCsuRootFsFwRev"))
                 {
                     isVersionMatched = versionPair[model.Module].StartsWith(model.Version);
                 }

+ 2 - 0
AwInitilizer/Procedure/ProcedureBase.cs

@@ -39,6 +39,8 @@ namespace AwInitilizer.Procedure
 
         internal static string ServerIpAddress = "192.168.1.10";
 
+        //internal static string ServerIpAddress = "172.18.13.84";
+
         public async Task<bool> DoWork() {
             if (!IsActivated)
                 return false;

+ 5 - 0
AwInitilizer/Procedure/VersionLogProcedure.cs

@@ -80,6 +80,11 @@ namespace AwInitilizer.Procedure.VersionLog
 
             foreach (var infoPair in versionPair)
             {
+                if (string.IsNullOrEmpty(infoPair.Value))
+                {
+                    continue;
+                }
+
                 if (!excludeHeaderList.Contains(infoPair.Key))
                 {
                     var mesKey = GetMesReportKey(infoPair.Key);

+ 1 - 1
AwInitilizer/Properties/AssemblyInfo.cs

@@ -34,4 +34,4 @@ using System.Runtime.InteropServices;
 // [assembly: AssemblyVersion("1.10.3.0")]
 [assembly: AssemblyVersion("1.10.3.0")]
 [assembly: AssemblyFileVersion("1.10.3.0")]
-[assembly: AssemblyInformationalVersion("038adc6")]
+[assembly: AssemblyInformationalVersion("90391dc")]

+ 1 - 1
Initilizer/AssemblyInfo.cs

@@ -11,5 +11,5 @@
 
 [assembly: AssemblyVersion("1.10.3.0")]
 [assembly: AssemblyFileVersion("1.10.3.0")]
-[assembly: AssemblyInformationalVersion("038adc6")]
+[assembly: AssemblyInformationalVersion("90391dc")]
 

+ 1 - 1
MesAdaptor/Properties/AssemblyInfo.cs

@@ -34,4 +34,4 @@ using System.Runtime.InteropServices;
 // [assembly: AssemblyVersion("1.10.3.0")]
 [assembly: AssemblyVersion("1.10.3.0")]
 [assembly: AssemblyFileVersion("1.10.3.0")]
-[assembly: AssemblyInformationalVersion("038adc6")]
+[assembly: AssemblyInformationalVersion("90391dc")]