|
@@ -0,0 +1,124 @@
|
|
|
+using AwInitilizer.Assist;
|
|
|
+using Newtonsoft.Json;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Collections.Specialized;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
+using System.Threading.Tasks;
|
|
|
+
|
|
|
+namespace AwInitilizer.Procedure
|
|
|
+{
|
|
|
+ public class WifRssiCheckProcedure : ProcedureBase
|
|
|
+ {
|
|
|
+ public WifRssiCheckProcedure() : base()
|
|
|
+ {
|
|
|
+ Name = "WiFi Rssi Check";
|
|
|
+ Content = "Check Wifi Rssi Signal";
|
|
|
+ }
|
|
|
+
|
|
|
+ internal override async Task<bool> Run()
|
|
|
+ {
|
|
|
+ if (!UpdateData.SystemID.ModelName.Network.ToString().Contains("WiFi"))
|
|
|
+ {
|
|
|
+ //if does not support Wifi then end init
|
|
|
+ InfoLog += "model name does not support Wifi ,skip check process\n";
|
|
|
+ ReportLog.Add("Wifi not supported, skip procedure");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ Logger.Print("Connecting to EVSE");
|
|
|
+ var checkResult = await CheckWifiRssi();
|
|
|
+ return checkResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ internal async Task<bool> CheckWifiRssi()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (WebClientTimeout webClient = new WebClientTimeout())
|
|
|
+ {
|
|
|
+ NameValueCollection parameters = new NameValueCollection();
|
|
|
+ parameters.Add("opt", "3");
|
|
|
+ webClient.QueryString = parameters;
|
|
|
+
|
|
|
+ using (Stream stream = await webClient.OpenReadTaskAsync($"https://{ServerIpAddress}/get_query_action.php"))
|
|
|
+ // 使用 StreamReader 讀取 stream 內的字元
|
|
|
+ using (StreamReader reader = new StreamReader(stream))
|
|
|
+ {
|
|
|
+ // 將 StreamReader 所讀到的字元轉為 string
|
|
|
+ string request = reader.ReadToEnd();
|
|
|
+ InfoLog += $"GetResponse:{request}";
|
|
|
+ Logger.Print($"GetResponse:{request}", isError: false);
|
|
|
+
|
|
|
+ Regex rx_mode = new Regex("(WifiMode)\\\": ([0-9]*)");
|
|
|
+ var matches_mode = rx_mode.Matches(request);
|
|
|
+
|
|
|
+ if (matches_mode.Count != 0)
|
|
|
+ {
|
|
|
+ var match = matches_mode[0];
|
|
|
+ if (match.Groups.Count != 3)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (int.TryParse(match.Groups[2].Value, out var wifiMode))
|
|
|
+ {
|
|
|
+ if (wifiMode != 1)
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ Regex rx = new Regex("(WifiRssi)\\\": (-?[0-9]*)");
|
|
|
+ var matches = rx.Matches(request);
|
|
|
+
|
|
|
+ if (matches.Count != 0)
|
|
|
+ {
|
|
|
+ var match = matches[0];
|
|
|
+ if (match.Groups.Count != 3)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (int.TryParse(match.Groups[2].Value, out var rssiSignal))
|
|
|
+ {
|
|
|
+ LogPair.Add("WifiRssi", rssiSignal.ToString());
|
|
|
+ return rssiSignal >= -80;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ Logger.Print("Get Wifi Rssi Failed", isError: true);
|
|
|
+ Logger.Print(e.Message + "", isError: true);
|
|
|
+
|
|
|
+ InfoLog += "Get Wifi Rssi Failed\n";
|
|
|
+ InfoLog += e.Message;
|
|
|
+ InfoLog += "\n";
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|