|
@@ -13,101 +13,149 @@ using System.Text.RegularExpressions;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
|
|
|
-namespace AwInitilizer.Procedure
|
|
|
+namespace AwInitilizer.Procedure.ButtonStatusCheck
|
|
|
{
|
|
|
+ public enum ErrorType
|
|
|
+ {
|
|
|
+ None,
|
|
|
+ ConnectFail,
|
|
|
+ GetStatusFail,
|
|
|
+ FirstButtonCheckFail,
|
|
|
+ SecondButtonCheckFail,
|
|
|
+ EmergencyButtonCheckFail,
|
|
|
+ }
|
|
|
+
|
|
|
+ public enum LogEvent
|
|
|
+ {
|
|
|
+ UnpressButtonTest
|
|
|
+ }
|
|
|
+
|
|
|
public class ButtonStatusCheckPorcedure : ProcedureBase
|
|
|
{
|
|
|
+ public ErrorType Error { get; set; } = ErrorType.None;
|
|
|
+
|
|
|
+ private ProcedureLog.LogWriter<ButtonStatusCheckPorcedure, LogEvent> LogWriter;
|
|
|
+
|
|
|
+ private readonly static Dictionary<LogEvent, string> ReportDict = new Dictionary<LogEvent, string>()
|
|
|
+ {
|
|
|
+ { LogEvent.UnpressButtonTest, "UnpressButtonTest" }
|
|
|
+ };
|
|
|
+
|
|
|
+ private readonly static Dictionary<LogEvent, string> LogDict = new Dictionary<LogEvent, string>()
|
|
|
+ {
|
|
|
+ { LogEvent.UnpressButtonTest, "Unpress check result" }
|
|
|
+ };
|
|
|
+
|
|
|
private HintDialog hintDialog = new HintDialog();
|
|
|
public ButtonStatusCheckPorcedure() : base()
|
|
|
{
|
|
|
Name = "Button Press Test";
|
|
|
Content = "Interaction to test button status";
|
|
|
+
|
|
|
+ LogWriter = new ProcedureLog.LogWriter<ButtonStatusCheckPorcedure, LogEvent>(this)
|
|
|
+ {
|
|
|
+ ReportPair = ReportDict,
|
|
|
+ LogPair = LogDict
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
internal override async Task<bool> Run()
|
|
|
{
|
|
|
- Logger.Print("Button Unpress Status check Start");
|
|
|
- //stage 0 - wait system ready
|
|
|
- //wait restart
|
|
|
- Logger.Print("Waiting response..");
|
|
|
-
|
|
|
- //object response = false;
|
|
|
- //int pollingCnt = 0;
|
|
|
- //for (pollingCnt = 0; pollingCnt < 14; pollingCnt++)
|
|
|
- //{
|
|
|
- // response = await GetButtonStatus();
|
|
|
- // if (response!=null)
|
|
|
- // break;
|
|
|
- // await Task.Delay(TimeSpan.FromSeconds(30));
|
|
|
- //}
|
|
|
-
|
|
|
- //ReportLog.Add(string.Format("EVSE connet elapsed minute(s) : {0}, Expect:<14", pollingCnt * 0.5));
|
|
|
-
|
|
|
- ////timeout
|
|
|
- //if (pollingCnt >= 14)
|
|
|
- //{
|
|
|
- // Logger.Print("Wait EVSE timeout", isError: true);
|
|
|
- // return false;
|
|
|
- //}
|
|
|
-
|
|
|
var response = await GetButtonStatus();
|
|
|
if (response == null)
|
|
|
{
|
|
|
- ReportLog.Add("EVSE connect failed");
|
|
|
- Logger.Print("EVSE connect failed", isError: true);
|
|
|
+ //ReportLog.Add("EVSE connect failed");
|
|
|
+ //Logger.Print("EVSE connect failed", isError: true);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
//stage 1 - unpress all
|
|
|
- //ShowDialog(
|
|
|
- // "Please make sure All button is Unpressed\nPress Ok while complete",
|
|
|
- // "Starting Button test",
|
|
|
- // "OK","", cancelAble: true);
|
|
|
+ if(!await CheckUnpressAllBtn())
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ //stage 2 - check press sequence
|
|
|
+ //Logger.Print("Button press Status check Start");
|
|
|
+ //MessageBox.Show("Press Button1,Button2,EmergencyButton in order\neach press continuous 2 secondes\nPress Ok to start", "Starting Button test");
|
|
|
+
|
|
|
+ //Button1,Button2,EmergencyButton in order 0,1,2
|
|
|
+ for (int testType = 0; testType < 3; testType++)
|
|
|
+ {
|
|
|
+ var checkResult = await PressBtnCheck(testType);
|
|
|
+ if (!checkResult)
|
|
|
+ {
|
|
|
+ if (testType == 0)
|
|
|
+ Error = ErrorType.FirstButtonCheckFail;
|
|
|
+ else if (testType == 1)
|
|
|
+ Error = ErrorType.SecondButtonCheckFail;
|
|
|
+ else if (testType == 2)
|
|
|
+ Error = ErrorType.EmergencyButtonCheckFail;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<bool> CheckUnpressAllBtn()
|
|
|
+ {
|
|
|
ShowDialog(
|
|
|
(string)Application.Current.FindResource("BtnPressUnpressHint"),
|
|
|
(string)Application.Current.FindResource("BtnPressHintTitle"),
|
|
|
(string)Application.Current.FindResource("Confirm"),
|
|
|
"", cancelAble: true);
|
|
|
+
|
|
|
ButtonStatus status = await GetButtonStatus();
|
|
|
|
|
|
if (status == null)
|
|
|
{
|
|
|
- InfoLog += "Get Butoon state failed\n";
|
|
|
- Logger.Print("Get Butoon state failed");
|
|
|
+ //InfoLog += "Get Butoon state failed\n";
|
|
|
+ //Logger.Print("Get Butoon state failed");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- InfoLog += "Unpress check result\n";
|
|
|
- InfoLog += $"Button1:{status.Button1},Button2:{status.Button2},EmgerncyButton:{status.EmergencyButton}\n";
|
|
|
- LogPair.Add("UnpressButtonTest", string.Format("{0}{1}{2}", status.Button1, status.Button2, status.EmergencyButton));
|
|
|
+ LogWriter.Report(LogEvent.UnpressButtonTest, string.Format("{0}{1}{2}", status.Button1, status.Button2, status.EmergencyButton));
|
|
|
+ //InfoLog += "Unpress check result\n";
|
|
|
+ //InfoLog += $"Button1:{status.Button1},Button2:{status.Button2},EmgerncyButton:{status.EmergencyButton}\n";
|
|
|
+ //LogPair.Add("UnpressButtonTest", string.Format("{0}{1}{2}", status.Button1, status.Button2, status.EmergencyButton));
|
|
|
|
|
|
- ReportLog.Add(string.Format("Button unpress test result : {0}, Expect:000",
|
|
|
+ LogWriter.Log(string.Format("Button unpress test result : {0}, Expect:000",
|
|
|
string.Format("{0}{1}{2}", status.Button1, status.Button2, status.EmergencyButton)
|
|
|
));
|
|
|
+ //ReportLog.Add(string.Format("Button unpress test result : {0}, Expect:000",
|
|
|
+ // string.Format("{0}{1}{2}", status.Button1, status.Button2, status.EmergencyButton)
|
|
|
+ // ));
|
|
|
|
|
|
bool isAllMatched = true;
|
|
|
if (status != null)
|
|
|
{
|
|
|
- isAllMatched = true;
|
|
|
if (status.Button1 != 0)
|
|
|
{
|
|
|
- Logger.Print("Button1 status ERROR, unpress is ecpected", isError: true);
|
|
|
+ Error = ErrorType.FirstButtonCheckFail;
|
|
|
+ LogWriter.Log("Button1 status ERROR, unpress is ecpected", isError: true);
|
|
|
+ //Logger.Print("Button1 status ERROR, unpress is ecpected", isError: true);
|
|
|
isAllMatched = false;
|
|
|
}
|
|
|
if (status.Button2 != 0)
|
|
|
{
|
|
|
- Logger.Print("Button3 status ERROR, unpress is ecpected", isError: true);
|
|
|
+ Error = ErrorType.SecondButtonCheckFail;
|
|
|
+ LogWriter.Log("Button2 status ERROR, unpress is ecpected", isError: true);
|
|
|
+ //Logger.Print("Button2 status ERROR, unpress is ecpected", isError: true);
|
|
|
isAllMatched = false;
|
|
|
}
|
|
|
if (status.EmergencyButton != 0)
|
|
|
{
|
|
|
- Logger.Print("EmergencyButton status ERROR, unpress is ecpected", isError: true);
|
|
|
+ Error = ErrorType.EmergencyButtonCheckFail;
|
|
|
+ LogWriter.Log("EmergencyButton status ERROR, unpress is ecpected", isError: true);
|
|
|
+ //Logger.Print("EmergencyButton status ERROR, unpress is ecpected", isError: true);
|
|
|
isAllMatched = false;
|
|
|
}
|
|
|
|
|
|
if (isAllMatched)
|
|
|
{
|
|
|
- Logger.Print("Unpress Check passed");
|
|
|
+ LogWriter.Log("Unpress Check passed");
|
|
|
+ //Logger.Print("Unpress Check passed");
|
|
|
+ return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -116,144 +164,129 @@ namespace AwInitilizer.Procedure
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Logger.Print("Get button press status Failed", isError: true);
|
|
|
+ LogWriter.Log("Get button press status Failed", isError: true);
|
|
|
+ //Logger.Print("Get button press status Failed", isError: true);
|
|
|
return false;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- //stage 2 - check press sequence
|
|
|
- Logger.Print("Button press Status check Start");
|
|
|
- //MessageBox.Show("Press Button1,Button2,EmergencyButton in order\neach press continuous 2 secondes\nPress Ok to start", "Starting Button test");
|
|
|
+ private async Task<bool> PressBtnCheck(int btnInt)
|
|
|
+ {
|
|
|
|
|
|
- bool isError = false;
|
|
|
- //Button1,Button2,EmergencyButton in order 0,1,2
|
|
|
+ string btn, btnLang, imgUrl;
|
|
|
+ (btn, btnLang, imgUrl) = GetBtnParam(btnInt);
|
|
|
+
|
|
|
+ ShowBtnPressRequestDialog(btnLang, imgUrl);
|
|
|
+
|
|
|
+ var btnStatus = await WaitAndtGetPressBtn();
|
|
|
+ LogWriter.Report($"{btn}PressTest", string.Format("{0}{1}{2}", btnStatus.Button1, btnStatus.Button2, btnStatus.EmergencyButton));
|
|
|
+ LogWriter.Log($"Press check stage {btn} result");
|
|
|
+ LogWriter.Log($"Button1:{btnStatus.Button1},Button2:{btnStatus.Button2},EmgerncyButton:{btnStatus.EmergencyButton}\n");
|
|
|
+
|
|
|
+ DismisDialog();
|
|
|
+ var btnStatusIsMatchedRequred = CheckBtnStatus(btnInt,btnStatus);
|
|
|
+ return btnStatusIsMatchedRequred;
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<ButtonStatus> WaitAndtGetPressBtn()
|
|
|
+ {
|
|
|
ButtonStatus pressStatus = null;
|
|
|
- for (int testType = 0; testType < 3; testType++)
|
|
|
+ //retry 20 times, 20*0.5 = 10 seconds
|
|
|
+ int testCnt;
|
|
|
+ for (testCnt = 0; testCnt < 20; testCnt++)
|
|
|
{
|
|
|
- string btn, btnLang, imgUrl;
|
|
|
- switch (testType)
|
|
|
- {
|
|
|
- case 1:
|
|
|
- btn = "Green Button";
|
|
|
- btnLang = (string)Application.Current.FindResource("BtnPressGreenBtn");
|
|
|
- imgUrl = "pack://application:,,,/AwInitilizer;component/Image/Green.png";
|
|
|
- break;
|
|
|
- case 0:
|
|
|
- btn = "Blue Button";
|
|
|
- btnLang = (string)Application.Current.FindResource("BtnPressBlueBtn");
|
|
|
- imgUrl = "pack://application:,,,/AwInitilizer;component/Image/Blue.png";
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- btn = "EmergencyButton";
|
|
|
- btnLang = (string)Application.Current.FindResource("BtnPressEmergencyBtn");
|
|
|
- imgUrl = "pack://application:,,,/AwInitilizer;component/Image/Emergency.png";
|
|
|
- break;
|
|
|
- default:
|
|
|
- btn = "";
|
|
|
- btnLang = "";
|
|
|
- imgUrl = null;
|
|
|
- break;
|
|
|
- };
|
|
|
-
|
|
|
- //MessageBox.Show($"press {btn}");
|
|
|
- //ShowDialog($"PRESS {btn.ToUpper()}", "Button press test", "", imgUrl, cancelAble: false);
|
|
|
- ShowDialog(
|
|
|
- string.Format((string)Application.Current.FindResource("BtnPressPressHint"), btnLang),
|
|
|
- (string)Application.Current.FindResource("BtnPressHintTitle"),
|
|
|
- "", imgUrl, cancelAble: false);
|
|
|
-
|
|
|
- //retry 20 times, 20*0.5 = 10 seconds
|
|
|
- int testCnt;
|
|
|
- for (testCnt = 0; testCnt < 20; testCnt++)
|
|
|
+ await Task.Delay(500);
|
|
|
+ pressStatus = await GetButtonStatus();
|
|
|
+ if (pressStatus == null)
|
|
|
{
|
|
|
- await Task.Delay(500);
|
|
|
- pressStatus = await GetButtonStatus();
|
|
|
- if (pressStatus == null)
|
|
|
- {
|
|
|
- InfoLog += "Get Butoon state failed\n";
|
|
|
- Logger.Print("Get Butoon state failed");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- //if any button is pressed
|
|
|
- if (pressStatus.Button1 != 0 ||
|
|
|
- pressStatus.Button2 != 0 ||
|
|
|
- pressStatus.EmergencyButton != 0)
|
|
|
- {
|
|
|
- bool success = false;
|
|
|
- if (pressStatus.Button1 == (testType == 0 ? 1 : 0) &&
|
|
|
- pressStatus.Button2 == (testType == 1 ? 1 : 0) &&
|
|
|
- pressStatus.EmergencyButton == (testType == 2 ? 1 : 0))
|
|
|
- {
|
|
|
- //Status correct
|
|
|
- success = true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //Status error
|
|
|
- isError = true;
|
|
|
- success = false;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if (success)
|
|
|
- {
|
|
|
- //wait release
|
|
|
- for (var releaseCnt = 0; releaseCnt < 20; releaseCnt++)
|
|
|
- {
|
|
|
- await Task.Delay(500);
|
|
|
- status = await GetButtonStatus();
|
|
|
- if (status == null)
|
|
|
- {
|
|
|
- InfoLog += "Get Butoon state failed\n";
|
|
|
- Logger.Print("Get Butoon state failed");
|
|
|
- return false;
|
|
|
- }
|
|
|
- if (status.Button1 == 0 &&
|
|
|
- status.Button2 == 0 &&
|
|
|
- status.EmergencyButton == 0)
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
- DismisDialog();
|
|
|
- InfoLog += $"Press check stage {btn} result\n";
|
|
|
- InfoLog += $"Button1:{pressStatus.Button1},Button2:{pressStatus.Button2},EmgerncyButton:{pressStatus.EmergencyButton}\n";
|
|
|
- LogPair.Add($"{btn}PressTest", string.Format("{0}{1}{2}", pressStatus.Button1, pressStatus.Button2, pressStatus.EmergencyButton));
|
|
|
-
|
|
|
- ReportLog.Add(string.Format("{0} Button press test result : {1}, Expect:{2}{3}{4}",
|
|
|
- btn,
|
|
|
- string.Format("{0}{1}{2}", status.Button1, status.Button2, status.EmergencyButton),
|
|
|
- testType == 0 ? "1" : "0",
|
|
|
- testType == 1 ? "1" : "0",
|
|
|
- testType == 2 ? "1" : "0"
|
|
|
- ));
|
|
|
-
|
|
|
- if (testCnt >= 20)
|
|
|
+ //if any button is pressed
|
|
|
+ if (pressStatus.Button1 != 0 ||
|
|
|
+ pressStatus.Button2 != 0 ||
|
|
|
+ pressStatus.EmergencyButton != 0)
|
|
|
{
|
|
|
- isError = true;
|
|
|
- Logger.Print($"{btn} press TIMEOUT", isError: true);
|
|
|
+ await WaitAllBtnRelease();
|
|
|
break;
|
|
|
}
|
|
|
- else if (isError)
|
|
|
- {
|
|
|
- Logger.Print($"{btn} press state ERROR", isError: true);
|
|
|
- Logger.Print($"Button1 {GetBtnStatusString(pressStatus.Button1)}, Button2 {GetBtnStatusString(pressStatus.Button2)}, EmergencyButton {GetBtnStatusString(pressStatus.EmergencyButton)}", isError: true);
|
|
|
+ }
|
|
|
+ return pressStatus;
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool CheckBtnStatus(int btnInt, ButtonStatus buttonStatus)
|
|
|
+ {
|
|
|
+ if (buttonStatus.Button1 == (btnInt == 0 ? 1 : 0) &&
|
|
|
+ buttonStatus.Button2 == (btnInt == 1 ? 1 : 0) &&
|
|
|
+ buttonStatus.EmergencyButton == (btnInt == 2 ? 1 : 0))
|
|
|
+ {
|
|
|
+ //Status correct
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ShowBtnPressRequestDialog(string btnLang, string imgUrl)
|
|
|
+ {
|
|
|
+ ShowDialog(
|
|
|
+ string.Format((string)Application.Current.FindResource("BtnPressPressHint"), btnLang),
|
|
|
+ (string)Application.Current.FindResource("BtnPressHintTitle"),
|
|
|
+ "", imgUrl, cancelAble: false);
|
|
|
+ }
|
|
|
+
|
|
|
+ private (string btn, string btnLang, string imgUrl) GetBtnParam(int btnInt)
|
|
|
+ {
|
|
|
+ string btn, btnLang, imgUrl;
|
|
|
+ switch (btnInt)
|
|
|
+ {
|
|
|
+ case 1:
|
|
|
+ btn = "Green Button";
|
|
|
+ btnLang = (string)Application.Current.FindResource("BtnPressGreenBtn");
|
|
|
+ imgUrl = "pack://application:,,,/AwInitilizer;component/Image/Green.png";
|
|
|
+ break;
|
|
|
+ case 0:
|
|
|
+ btn = "Blue Button";
|
|
|
+ btnLang = (string)Application.Current.FindResource("BtnPressBlueBtn");
|
|
|
+ imgUrl = "pack://application:,,,/AwInitilizer;component/Image/Blue.png";
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ btn = "EmergencyButton";
|
|
|
+ btnLang = (string)Application.Current.FindResource("BtnPressEmergencyBtn");
|
|
|
+ imgUrl = "pack://application:,,,/AwInitilizer;component/Image/Emergency.png";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ btn = "";
|
|
|
+ btnLang = "";
|
|
|
+ imgUrl = null;
|
|
|
break;
|
|
|
+ };
|
|
|
+ return (btn, btnLang, imgUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task WaitAllBtnRelease()
|
|
|
+ {
|
|
|
+ ButtonStatus status;
|
|
|
+ //wait release
|
|
|
+ for (var releaseCnt = 0; releaseCnt < 20; releaseCnt++)
|
|
|
+ {
|
|
|
+ await Task.Delay(500);
|
|
|
+ status = await GetButtonStatus();
|
|
|
+ if (status == null)
|
|
|
+ {
|
|
|
+ //InfoLog += "Get Butoon state failed\n";
|
|
|
+ //Logger.Print("Get Butoon state failed");
|
|
|
+ continue;
|
|
|
}
|
|
|
- else
|
|
|
+ if (status.Button1 == 0 &&
|
|
|
+ status.Button2 == 0 &&
|
|
|
+ status.EmergencyButton == 0)
|
|
|
{
|
|
|
- Logger.Print($"{btn} press state passed");
|
|
|
+ break ;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if(isError)
|
|
|
- return false;
|
|
|
- return true;
|
|
|
}
|
|
|
|
|
|
internal async Task<ButtonStatus> GetButtonStatus(bool isConnectTest = false)
|
|
@@ -268,7 +301,8 @@ namespace AwInitilizer.Procedure
|
|
|
{
|
|
|
// 將 StreamReader 所讀到的字元轉為 string
|
|
|
string request = reader.ReadToEnd();
|
|
|
- InfoLog += $"Get respone : {request}\n";
|
|
|
+ //InfoLog += $"Get respone : {request}\n";
|
|
|
+ LogWriter.Log($"Get respone : {request}", isDebugLog: true);
|
|
|
var values = JsonConvert.DeserializeObject<ButtonStatus>(request);
|
|
|
|
|
|
return values;
|
|
@@ -279,12 +313,16 @@ namespace AwInitilizer.Procedure
|
|
|
{
|
|
|
if (!isConnectTest)
|
|
|
{
|
|
|
- InfoLog += "Get Button Status Failed\n";
|
|
|
- InfoLog += e.Message;
|
|
|
- InfoLog += "\n";
|
|
|
+ Error = ErrorType.GetStatusFail;
|
|
|
+ LogWriter.Log("Get Button Status Failed", isError: true);
|
|
|
+ LogWriter.Log(e.Message, isDebugLog: true);
|
|
|
+
|
|
|
+ //InfoLog += "Get Button Status Failed\n";
|
|
|
+ //InfoLog += e.Message;
|
|
|
+ //InfoLog += "\n";
|
|
|
|
|
|
- Logger.Print("Get Button Status Failed", isError: true);
|
|
|
- Logger.Print(e.Message + "", isError: true);
|
|
|
+ //Logger.Print("Get Button Status Failed", isError: true);
|
|
|
+ //Logger.Print(e.Message + "", isError: true);
|
|
|
}
|
|
|
}
|
|
|
|