public bool getMACAddressOfDUT() { if (GlobalData.macAddress.Trim().Length != 0) { return(true); } try { string _err; ContentGridFields t = new ContentGridFields() { INDEX = "1", STEPNAME = "Login to DUT", STANDARD = "root login on `console'", ACTUAL = "?", RETRY = "-", TIMEOUT = "10000", JUDGED = "?" }; if (!login_toDUT(t, out _err)) { return(false); } if (!read_MacAddress(t, out _err)) { return(false); } return(true); } catch { return(false); } }
protected bool setMac_forEthernet0(ContentGridFields content, out string _error) { _error = ""; bool _flag = false; content.JUDGED = "waiting..."; try { string stvalue = content.STANDARD; int tOut = content.TIMEOUT == "-" ? 1000 : int.Parse(content.TIMEOUT); int tRetry = content.RETRY == "-" ? 0 : int.Parse(content.RETRY); int index = 0; while (!_flag) { this.sendDataToDUT(string.Format("sys mac {0}\n", GlobalData.macAddress)); string st = string.Format("new mac addr = {0}:{1}:{2}:{3}:{4}:{5}", GlobalData.macAddress.Substring(0, 2).ToLower(), GlobalData.macAddress.Substring(2, 2).ToLower(), GlobalData.macAddress.Substring(4, 2).ToLower(), GlobalData.macAddress.Substring(6, 2).ToLower(), GlobalData.macAddress.Substring(8, 2).ToLower(), GlobalData.macAddress.Substring(10, 2).ToLower() ); while (!GlobalData.logContent.logviewUART.Contains(st)) { Thread.Sleep(1000); if (index >= (tOut / 1000)) { break; } else { index++; } } if (index >= (tOut / 1000)) { content.ACTUAL = (index * 1000).ToString(); _error = "Request time out"; break; } else { content.ACTUAL = st; _flag = true; } } goto END; } catch (Exception ex) { _error = ex.ToString(); goto END; } END: { content.JUDGED = _flag == true ? "PASS" : "FAIL"; GlobalData.logContent.logviewUART = ""; return(_flag); } }
protected bool rewait_DUT_Online(ContentGridFields content, out string _error) { _error = ""; bool _flag = false; content.JUDGED = "waiting..."; try { string stvalue = content.STANDARD; int tOut = content.TIMEOUT == "-" ? 1000 : int.Parse(content.TIMEOUT); int tRetry = content.RETRY == "-" ? 0 : int.Parse(content.RETRY); int index = 0; ////////////////////////////////////// if (GlobalData.logContent.logviewUART.Length != 0) { _flag = true; content.ACTUAL = "0"; goto END; } ////////////////////////////////////// callWaiDUT(tOut.ToString()); while (!_flag) { GlobalData.logContent.logviewUART = ""; while (GlobalData.logContent.logviewUART.Length == 0) { Thread.Sleep(100); if (index >= (tOut / 100)) { _error = "Request time out."; break; } else { index++; } } destroyWaitDUT(); content.ACTUAL = (index * 100).ToString(); if (index < (tOut / 100)) { _flag = true; } else { break; } } goto END; } catch (Exception ex) { _error = ex.ToString(); goto END; } END: { content.JUDGED = _flag == true ? "PASS" : "FAIL"; return(_flag); } }
protected bool get_MacAddress(ContentGridFields content, out string _error) { _error = ""; bool _flag = false; content.JUDGED = "waiting..."; try { string stvalue = content.STANDARD; int tOut = content.TIMEOUT == "-" ? 1000 : int.Parse(content.TIMEOUT); int tRetry = content.RETRY == "-" ? 0 : int.Parse(content.RETRY); int index = 0; callGetMAC(tRetry, tOut); while (!_flag) { GlobalData.macAddress = ""; while (GlobalData.macAddress.Length == 0) { Thread.Sleep(1000); if (index >= (tOut / 1000)) { _error = "Request time out."; break; } else { index++; } } destroyGetMAC(); content.ACTUAL = (index * 1000).ToString(); if (index < (tOut / 1000)) { if (GlobalData.macAddress.Length == 12) { _flag = true; } else { _error = "Mac Address sai định dạng!"; } break; } else { break; } } goto END; } catch (Exception ex) { _error = ex.ToString(); goto END; } END: { content.JUDGED = _flag == true ? "PASS" : "FAIL"; return(_flag); } }
protected bool pluginLANPort(ContentGridFields content, out string _error) { _error = ""; bool _flag = false; content.JUDGED = "waiting..."; try { string stvalue = content.STANDARD; int tOut = content.TIMEOUT == "-" ? 1000 : int.Parse(content.TIMEOUT); int tRetry = content.RETRY == "-" ? 0 : int.Parse(content.RETRY); int index = 0; GlobalData.lanResult = ""; callPlugLAN(0, tOut); while (!_flag) { while (GlobalData.lanResult.Length == 0) { Thread.Sleep(100); if (index >= (tOut / 100)) { _error = "Request time out."; break; } else { index++; } } destroyPlugLAN(); content.ACTUAL = (index * 100).ToString(); if (index < (tOut / 100)) { if (GlobalData.lanResult == "OK") { _flag = true; } else { break; } } else { break; } } goto END; } catch (Exception ex) { _error = ex.ToString(); goto END; } END: { content.JUDGED = _flag == true ? "PASS" : "FAIL"; return(_flag); } }
protected bool read_MacAddress(ContentGridFields content, out string _error) { _error = ""; bool _flag = false; content.JUDGED = "waiting..."; try { string stvalue = content.STANDARD; int tOut = content.TIMEOUT == "-" ? 1000 : int.Parse(content.TIMEOUT); int tRetry = content.RETRY == "-" ? 0 : int.Parse(content.RETRY); int index = 0; GlobalData.uartData = ""; while (!_flag) { this.sendDataToDUT(string.Format("ifconfig\n")); string st = string.Format("Link encap:Ethernet HWaddr"); while (!GlobalData.uartData.Contains(st)) { Thread.Sleep(1000); if (index >= (tOut / 1000)) { break; } else { index++; } } if (index >= (tOut / 1000)) { content.ACTUAL = (index * 1000).ToString(); _error = "Request time out"; break; } else { string tmpStr = GlobalData.uartData; string[] buffer = tmpStr.Split(new string[] { "HWaddr" }, StringSplitOptions.None); tmpStr = buffer[1].Replace("\r", "").Replace("\n", "").Trim(); string mac = tmpStr.Substring(0, 17); GlobalData.macAddress = mac.Replace(":", ""); content.ACTUAL = st; _flag = true; } } goto END; } catch (Exception ex) { _error = ex.ToString(); goto END; } END: { content.JUDGED = _flag == true ? "PASS" : "FAIL"; return(_flag); } }
protected bool wait_DUTBootComplete(ContentGridFields content, out string _error) { _error = ""; bool _flag = false; content.JUDGED = "waiting..."; GlobalData.uartData = ""; try { string stvalue = content.STANDARD; int tOut = content.TIMEOUT == "-" ? 1000 : int.Parse(content.TIMEOUT); int tRetry = content.RETRY == "-" ? 0 : int.Parse(content.RETRY); int index = 0; while (!_flag) { bool _end = false; while (!_end) { if (GlobalData.uartData.Contains("Please press Enter to activate this console")) { break; } Thread.Sleep(1000); if (index >= (tOut / 1000)) { break; } else { index++; } } content.ACTUAL = (index * 1000).ToString(); if (index < (tOut / 1000)) { _flag = true; } else { break; } } goto END; } catch (Exception ex) { _error = ex.ToString(); goto END; } END: { content.JUDGED = _flag == true ? "PASS" : "FAIL"; return(_flag); } }
protected bool set_FTPServer_IPAddress(ContentGridFields content, out string _error) { _error = ""; bool _flag = false; content.JUDGED = "waiting..."; try { string stvalue = content.STANDARD; int tOut = content.TIMEOUT == "-" ? 1000 : int.Parse(content.TIMEOUT); int tRetry = content.RETRY == "-" ? 0 : int.Parse(content.RETRY); int index = 0; while (!_flag) { if (!this.setFTPServerIPAddress(out _error)) { if (index >= tRetry) { _error = "Request time out."; break; } else { index++; } } else { content.ACTUAL = stvalue; _flag = true; break; } } if (!_flag) { content.ACTUAL = "Error"; } goto END; } catch (Exception ex) { _error = ex.ToString(); goto END; } END: { content.JUDGED = _flag == true ? "PASS" : "FAIL"; return(_flag); } }
private ObservableCollection <ContentGridFields> _loadfilecontent(localfiles _file) { ObservableCollection <ContentGridFields> t = new ObservableCollection <ContentGridFields>(); try { string SettingPath = string.Format("{0}\\Settings", System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); string[] lines = System.IO.File.ReadAllLines(string.Format("{0}\\{1}.csv", SettingPath, _file.ToString())); foreach (var line in lines) { if (line.Trim().Replace("\n", "").Replace("\r", "") != null && line.Contains("INDEX,STEPNAME,STANDARD,ACTUAL,RETRY,TIMEOUT,JUDGED") != true) { string[] buffer = line.Split(','); ContentGridFields c = new ContentGridFields(buffer); t.Add(c); } } } catch (Exception ex) { GlobalData.logContent.logviewSystem += ex.ToString(); } return(t.Count > 0 ? t : null); }
protected bool login_toDUT(ContentGridFields content, out string _error) { _error = ""; bool _flag = false; content.JUDGED = "waiting..."; try { string stvalue = content.STANDARD; int tOut = content.TIMEOUT == "-" ? 1000 : int.Parse(content.TIMEOUT); int tRetry = content.RETRY == "-" ? 0 : int.Parse(content.RETRY); int index = 0; while (!_flag) { this.sendDataToDUT("\r\n"); while (!GlobalData.logContent.logviewUART.Contains("tc login:"******"Request time out"; break; } this.sendDataToDUT(GlobalData.defaultSettings.DUT_User + "\n"); while (!GlobalData.logContent.logviewUART.Contains("Password:"******"Request time out"; break; } this.sendDataToDUT(GlobalData.defaultSettings.DUT_Pass + "\n"); while (!GlobalData.logContent.logviewUART.Contains(stvalue)) { Thread.Sleep(1000); if (index >= (tOut / 1000)) { break; } else { index++; } } if (index >= (tOut / 1000)) { content.ACTUAL = (index * 1000).ToString(); _error = "Request time out"; break; } else { content.ACTUAL = stvalue; _flag = true; } } goto END; } catch (Exception ex) { _error = ex.ToString(); goto END; } END: { content.JUDGED = _flag == true ? "PASS" : "FAIL"; return(_flag); } }
protected bool putFirm_ThroughWPS(ContentGridFields content, out string _error) { _error = ""; bool _flag = false; content.JUDGED = "waiting..."; try { string stvalue = content.STANDARD; int tOut = content.TIMEOUT == "-" ? 1000 : int.Parse(content.TIMEOUT); int tRetry = content.RETRY == "-" ? 0 : int.Parse(content.RETRY); int index = 0; while (!_flag) { if (!this.putFirwareThroughWPS(out _error)) { if (index >= tRetry) { break; } else { index++; } } else { index = 0; while (!System.IO.File.Exists(System.AppDomain.CurrentDomain.BaseDirectory + "wps.txt")) { Thread.Sleep(1000); if (index >= (tOut / 1000)) { break; } else { index++; } } if (index >= (tOut / 1000)) { _error = "Request time out."; break; } string tmpStr = System.IO.File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "wps.txt"); GlobalData.logContent.logviewWPS = tmpStr; if (tmpStr.ToUpper().Contains("ERROR") || tmpStr.Trim().Replace("\n", "").Replace("\r", "") == string.Empty) { _error = tmpStr; break; } bool _end = false; while (!_end) { int t1 = GlobalData.logContent.logviewUART.Length; Thread.Sleep(200); int t2 = GlobalData.logContent.logviewUART.Length; Thread.Sleep(200); int t3 = GlobalData.logContent.logviewUART.Length; Thread.Sleep(200); if (t1 == t2 && t2 == t3) { break; } } if (GlobalData.logContent.logviewUART.ToUpper().Contains("STARTING THE TFTP DOWNLOAD") && GlobalData.logContent.logviewUART.ToUpper().Contains("CHECK DATA SUCCESS, PREPARE TO UPLOAD")) { content.ACTUAL = stvalue; _flag = true; break; } else { break; } } } if (!_flag) { content.ACTUAL = "Error"; } goto END; } catch (Exception ex) { _error = ex.ToString(); goto END; } END: { content.JUDGED = _flag == true ? "PASS" : "FAIL"; return(_flag); } }
protected bool access_toUboot(ContentGridFields content, out string _error) { _error = ""; bool _flag = false; content.JUDGED = "waiting..."; try { string stvalue = content.STANDARD; int tOut = content.TIMEOUT == "-" ? 1000 : int.Parse(content.TIMEOUT); int tRetry = content.RETRY == "-" ? 0 : int.Parse(content.RETRY); int index = 0; while (!_flag) { while (!GlobalData.logContent.logviewUART.Contains("Press any key in 3 secs to enter boot command mode.")) { Thread.Sleep(1000); if (index >= (tOut / 1000)) { _error = "Request time out."; break; } else { index++; } } if (index >= (tOut / 1000)) { content.ACTUAL = (index * 1000).ToString(); break; } int rep = 0; REPEAT: if (!this.accessDUT(out _error)) { if (rep < tRetry) { rep++; goto REPEAT; } else { content.ACTUAL = "Error"; break; } } else { content.ACTUAL = stvalue; _flag = true; break; } } goto END; } catch (Exception ex) { _error = ex.ToString(); goto END; } END: { content.JUDGED = _flag == true ? "PASS" : "FAIL"; return(_flag); } }
protected bool wait_DUTWifiBootComplete(ContentGridFields content, out string _error) { _error = ""; bool _flag = false; content.JUDGED = "waiting..."; GlobalData.uartData = ""; ////////////////////////////////////// for (int i = 0; i < 10; i++) { string pattern = string.Format("br0: port {0}(ra0) entering forwarding state", i); if (GlobalData.logContent.logviewUART.Contains(pattern) == true) { _flag = true; content.ACTUAL = "0"; goto END; } } ////////////////////////////////////// try { string stvalue = content.STANDARD; int tOut = content.TIMEOUT == "-" ? 1000 : int.Parse(content.TIMEOUT); int tRetry = content.RETRY == "-" ? 0 : int.Parse(content.RETRY); int index = 0; while (!_flag) { bool _end = false; while (!_end) { bool ret = false; for (int i = 0; i < 10; i++) { string pattern = string.Format("br0: port {0}(ra0) entering forwarding state", i); if (GlobalData.uartData.Contains(pattern) == true) { ret = true; break; } } if (ret == true) { break; } Thread.Sleep(1000); if (index >= (tOut / 1000)) { break; } else { index++; } } content.ACTUAL = (index * 1000).ToString(); if (index < (tOut / 1000)) { _flag = true; } else { break; } } goto END; } catch (Exception ex) { _error = ex.ToString(); goto END; } END: { content.JUDGED = _flag == true ? "PASS" : "FAIL"; return(_flag); } }