static int Main(string[] args) { //Console.WriteLine("Press Enter to continue"); //Console.Read(); _log.Info("App started"); var options = new Options(); var parser_options = new CommandLine.ParserSettings { MutuallyExclusive = true }; var parser = new CommandLine.Parser(parser_options); var isValid = parser.ParseArguments(args, options); if (!isValid) { Console.WriteLine(CommandLine.Text.HelpText.AutoBuild(options).ToString()); return(-1); } // Don't allow lower case serial options.SMT_Serial = options.SMT_Serial.ToUpper(); Console.WriteLine("SMT Serial: " + options.SMT_Serial); Console.WriteLine("Host: " + options.Host); Console.WriteLine(); // Check board was passed diags try { using (CLStoreEntities cx = new CLStoreEntities()) { LowesHub h = cx.LowesHubs.Where(lh => lh.smt_serial == options.SMT_Serial).OrderByDescending(lh => lh.date).First(); string info = string.Format("Hub {0} last diags {1}", h.MacAddress.MAC.ToString("X"), h.date.ToString()); _log.Info(info); } } catch (Exception ex) { _log.Fatal("Problem retrieving Hub diag info\r\n\r\n" + ex.Message + "\r\n" + ex.StackTrace); return(-3); } if (options.CalibrateLEDs) { BatteryTest batcal = new BatteryTest(options.Host, options.SMT_Serial); char save_option = 'n'; while (true) { Console.WriteLine("Getting LEDs values...\r\n"); double[] values = batcal.GetLEDsValues(); int i = 0; Console.WriteLine("Red On : {0}", values[i++].ToString("G2")); Console.WriteLine("Green On : {0}", values[i++].ToString("G2")); Console.WriteLine("Yellow On: {0}", values[i++].ToString("G2")); Console.WriteLine(); Console.WriteLine("Red Off : {0}", values[i++].ToString("G2")); Console.WriteLine("Green Off : {0}", values[i++].ToString("G2")); Console.WriteLine("Yellow Off: {0}", values[i++].ToString("G2")); i = 0; Properties.Settings.Default.LED_Red_On_Val = values[i++]; Properties.Settings.Default.LED_Green_On_Val = values[i++]; Properties.Settings.Default.LED_Yellow_On_Val = values[i++]; Properties.Settings.Default.LED_Red_Off_Val = values[i++]; Properties.Settings.Default.LED_Green_Off_Val = values[i++]; Properties.Settings.Default.LED_Yellow_Off_Val = values[i++]; Console.WriteLine("Save Values? (y/n/r):"); save_option = Convert.ToChar(Console.Read()); if (save_option != 'r') { break; } } if (save_option == 'y') { Properties.Settings.Default.Save(); } } try { if (!options.NoJigMode) { BatteryTest battery_test = new BatteryTest(options.Host, options.SMT_Serial); battery_test.InvalidateEnabled = !options.DisableInvalidate; battery_test.Status_Event += Battery_test_Status_Event; battery_test.LogFolder = Properties.Settings.Default.Log_Folder; Directory.CreateDirectory(battery_test.LogFolder); battery_test.LED_Red.OnVal = Properties.Settings.Default.LED_Red_On_Val; battery_test.LED_Red.OffVal = Properties.Settings.Default.LED_Red_Off_Val; battery_test.LED_Green.OnVal = Properties.Settings.Default.LED_Green_On_Val; battery_test.LED_Green.OffVal = Properties.Settings.Default.LED_Green_Off_Val; battery_test.LED_Yellow.OnVal = Properties.Settings.Default.LED_Yellow_On_Val; battery_test.LED_Yellow.OffVal = Properties.Settings.Default.LED_Yellow_Off_Val; battery_test.Run(); } else { BatteryTestNoJig batery_test = new BatteryTestNoJig(options.Host, options.SMT_Serial); batery_test.InvalidateEnabled = !options.DisableInvalidate; batery_test.Status_Event += Baterytest_Status_Event; batery_test.LogFolder = Properties.Settings.Default.Log_Folder; Directory.CreateDirectory(batery_test.LogFolder); batery_test.Run(); } } catch (Exception ex) { _log.Fatal(ex.Message + "\r\n" + ex.StackTrace); return(-2); } finally { if (!options.NoJigMode) { BatteryJig.Set_all_relays(false); } } _log.Info("All Tests Passed"); if (!options.PrintLabelDisabled) { _log.Info("Printing label..."); try { DataUtils.PrintHubLabel( options.SMT_Serial, Properties.Settings.Default.ZPL_Lable_File, Properties.Settings.Default.Printer_Address); } catch (Exception ex) { _log.Fatal(ex.Message + "\r\n" + ex.StackTrace); return(-2); } finally { } } return(0); }
public void Serialize() { using (CLStoreEntities cx = new CLStoreEntities()) using (SerialCOM port = getDUTPort()) { // Make sure we can talk to hub port.WriteLine(); port.WaitFor("#", 3); LowesHub loweshub_data = new LowesHub(); // Gather info to serialize hub int production_site_id = MACAddrUtils.ProductionSiteId(); while (production_site_id > byte.MaxValue) { production_site_id = production_site_id >> 1; } int test_station_id = MACAddrUtils.StationSiteId(); loweshub_data.test_station_id = test_station_id; while (test_station_id > byte.MaxValue) { test_station_id = test_station_id >> 1; } int hw_ver = HW_Ver; loweshub_data.hw_ver = HW_Ver; while (hw_ver > byte.MaxValue) { hw_ver = hw_ver >> 1; } int operator_id = DataUtils.OperatorId(_tester); loweshub_data.operator_id = operator_id; while (operator_id > short.MaxValue) { operator_id = operator_id >> 1; } _lowes_serial = LowesSerial.GetSerial( model: LowesSerial.Model.IH200, hw_version: (byte)hw_ver, datetime: DateTime.Now, factory: (byte)production_site_id, test_station: (byte)test_station_id, tester: (short)operator_id); int customer_id = cx.LowesCustomers.Where(c => c.Name == Customer.ToString()).Single().Id; // See if this board already had a mac assigned long mac = MACAddrUtils.INVALID_MAC; var hubsq = cx.LowesHubs.Where(h => h.smt_serial == SMT_Serial).OrderByDescending(h => h.date); if (hubsq.Any()) { var hubs = hubsq.ToArray(); foreach (LowesHub hub in hubs) { long hubmac = hub.MacAddress.MAC; if (MACAddrUtils.Inrange(hubmac)) { mac = hubmac; break; } } } if (mac == MACAddrUtils.INVALID_MAC) { mac = MACAddrUtils.GetNewMac(); } int mac_id = MACAddrUtils.GetMacId(mac); string macstr = MACAddrUtils.LongToStr(mac); string cmd = string.Format("serialize {0} model {1} customer {2} hw_version {3} batch_no {4}", macstr, Serialize_Model, Customer.ToString(), HW_Ver, Lowes_Serial); fire_status(cmd); port.WriteLine(cmd); port.WaitFor("Device serialization is complete - please reboot", 5); fire_status("Device serialization is complete."); port.Data = ""; string mfg_data = port.WriteWait("show mfg", "Batch Number:", 3); Regex regx = new Regex(@"HubID:\s+([A-Z]+-\d+)"); Match m = regx.Match(mfg_data); if (!m.Success || m.Groups.Count < 2) { string emsg = string.Format("Unable to extract Hub id from data:{0}", mfg_data); throw new Exception(emsg); } string hubid = m.Groups[1].Value; fire_status("Hub ID: " + hubid); // Insert the hub loweshub_data.customer_id = customer_id; loweshub_data.mac_id = mac_id; loweshub_data.smt_serial = SMT_Serial.ToString().ToUpper(); loweshub_data.lowes_serial = Lowes_Serial; loweshub_data.hub_id = hubid; cx.LowesHubs.Add(loweshub_data); cx.SaveChanges(); } }