コード例 #1
0
ファイル: Diags.cs プロジェクト: vicmatmar/ZDiags
        void led_test(Sensors sensor, double min_val, double max_val, string color)
        {
            _dutport.WaitFor(color + " led on?", 3);
            double val = -1.0;

            for (int i = 0; i < 5; i++)
            {
                val = read_SingelAi(sensor);

                string rmsg = string.Format(color + " led Voltage: {0}", val.ToString("f2"));
                rmsg += string.Format(" ({0}-{1})", min_val.ToString("f1"), max_val.ToString("f1"));
                fire_status(rmsg);

                if (val >= min_val && val < max_val)
                {
                    break;
                }

                Thread.Sleep(250);
            }

            if (val >= min_val && val < max_val)
            {
                _dutport.WriteLine("y");
            }
            else
            {
                _dutport.WriteLine("n");
                string emsg = string.Format("Unable to detect {0} led. Voltage was: {1}", color, val.ToString("f2"));
                throw new Exception(emsg);
            }
        }
コード例 #2
0
ファイル: Diags.cs プロジェクト: vicmatmar/ZDiags
        public void BLETest()
        {
            using (SerialCOM dutport = getDUTPort())
                using (SerialCOM bleport = getBLEPort())
                {
                    // Make sure we can talk to hubs
                    dutport.WriteWait("", "#", 3);

                    Random rand    = new Random(DateTime.Now.Second);
                    int    channel = rand.Next(0, 27);
                    bleport.WriteLine("ble_rx " + channel.ToString() + " 3000");
                    dutport.WriteLine("ble_tx " + channel.ToString());
                    bleport.WaitFor("Packets received:", 5, clear_data: false);
                    string data  = bleport.Data;
                    Match  match = Regex.Match(data, @"Packets received: (\d*)", RegexOptions.Singleline);
                    if (!match.Success || match.Groups.Count < 2)
                    {
                        string emsg = string.Format("Unable to get packets received from BLE master.\r\nData was: {0}", data);
                        throw new Exception(emsg);
                    }
                    int packets_received = Convert.ToInt32(match.Groups[1].Value);
                    // if (packets_received < 1500)
                    if (packets_received < 800)
                    {
                        string emsg = string.Format("BLE packets received < 1500.\r\nPackets received were: {0}", packets_received);
                        throw new Exception(emsg);
                    }
                    string rmsg = string.Format("BLE packets received: {0}", packets_received);
                    fire_status(rmsg);
                }
        }
コード例 #3
0
ファイル: Diags.cs プロジェクト: vicmatmar/ZDiags
        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();
                }
        }
コード例 #4
0
ファイル: Diags.cs プロジェクト: vicmatmar/ZDiags
        public void Diagnostics()
        {
            using (SerialCOM dutport = getDUTPort())
            {
                // Make sure we can talk to hub
                //dutport.WriteWait("", "#", 3, clear_data:false);
                dutport.WaitForPrompt();

                // Diags
                fire_status("Start diagnostics");
                dutport.WriteWait("diagnostics", "Press the reset button...", 3);

                fire_status("Press the reset button...");
                write_SingleDIO(Relays.BUTTON, true);
                dutport.WaitFor(@"Insert both USB drives and attach increased load to usb0. Press <enter> when ready...", 10);
                fire_status("USB0 Test");
                write_SingleDIO(Relays.USB1, true);
                Thread.Sleep(500);
                dutport.WriteLine();

                dutport.WaitFor(@"Remove increased load from usb0 and attach load to usb1. Press <enter> when ready...", 5);
                fire_status("USB1 Test");
                write_SingleDIO(Relays.USB1, false);
                write_SingleDIO(Relays.USB2, true);
                Thread.Sleep(500);
                dutport.WriteLine();

                fire_status("Buzzer Test");
                dutport.WaitFor("Buzzer on?", 3);
                double val    = -1.0;
                double expval = 3.0;
                for (int i = 0; i < 5; i++)
                {
                    val = read_SingelAi(Sensors.BUZZER_AUDIO);
                    fire_status(string.Format("Buzzer Voltage: {0}", val.ToString("f2")));
                    if (val > expval)
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                }
                if (val > 3.0)
                {
                    dutport.WriteLine("y");
                }
                else
                {
                    dutport.WriteLine("n");
                    string emsg = string.Format("Unable to detect buzzer. Volatgae was: {0}. Expected more than {1}",
                                                val.ToString("f2"), expval.ToString("f2"));
                    throw new Exception(emsg);
                }


                fire_status("LED Tests");
                led_test(Sensors.GREEN_LIGHT, LED_Green_Low_Value, LED_Green_High_Value, "green");
                led_test(Sensors.RED_LIGHT, LED_Red_Low_Value, LED_Red_High_Value, "red");
                led_test(Sensors.YELLOW_LIGHT, LED_Yellow_Low_Value, LED_Yellow_High_Value, "yellow");

                // Other tests
                fire_status("Other Built-in Tests...");
                dutport.WaitFor("All Tests Passed", 20);
                fire_status("All Tests Passed");
            }
        }
コード例 #5
0
ファイル: Diags.cs プロジェクト: vicmatmar/ZDiags
        public void Run()
        {
            DateTime start_time = DateTime.Now;

            // Init the serial data log files
            string fileloc = Path.Combine(LogFolder, "log_dut_data.txt");

            _fs_dut_data = new FileStream(fileloc, FileMode.Create, FileAccess.Write, FileShare.Read);

            fileloc      = Path.Combine(LogFolder, "log_ble_data.txt");
            _fs_ble_data = new FileStream(fileloc, FileMode.Create, FileAccess.Write, FileShare.Read);

            Set_all_relays(false);
            Thread.Sleep(500);
            using (SerialCOM dutport = getDUTPort())
                using (SerialCOM bleport = getBLEPort())
                {
                    // Turn BLE board so
                    fire_status("Power up BLE master");
                    write_SingleDIO(Relays.BLE, true);
                    bleport.WaitFor("U-Boot", 3);

                    // Turn DUT on
                    fire_status("Power up DUT");
                    write_SingleDIO(Relays.DUT, true);
                    dutport.WaitFor("U-Boot", 3);
                    Thread.Sleep(3000);

                    // Login
                    fire_status("Login to DUT");
                    login(dutport);

                    // Program_Radios
                    if (Program_Radios)
                    {
                        fire_status("Program Radios");
                        dutport.Data = "";
                        DateTime t1 = DateTime.Now;
                        dutport.WriteLine("program_radios");
                        string data = dutport.WaitFor("Radio programming is complete.", Program_Radios_Timeout_Sec);
                        if (data.Contains("Error"))
                        {
                            throw new Exception("Errors detected during program radios.\r\nOutput was:\r\n" + data);
                        }
                        TimeSpan ts1 = DateTime.Now - t1;
                        fire_status("Radio programming is complete after " + ts1.TotalSeconds.ToString() + "sec");
                    }
                }

            if (_hub_ip != null && _hub_ip != "")
            {
                fire_status("Set Hub IP to " + _hub_ip);
                string data = setHubIpAddr(_hub_ip);
                fire_status(data);
            }

            fire_status("ZWave Update...");
            ZWaveUpdate();

            if (_zwave_updated)
            {
                fire_status("Show Radios...");
                ShowRadios();
            }

            fire_status("Diagnostics...");
            Diagnostics();

            if (BLETestDisable)
            {
                fire_status("BLE Test DISABLED!!!");
            }
            else
            {
                fire_status("BLE Test...");
                using (SerialCOM bleport = getBLEPort())
                {
                    fire_status("Login to BLE");
                    login(bleport);
                }
                int trycount = 0;
                while (true)
                {
                    try
                    {
                        BLETest();
                        break;
                    }
                    catch (Exception ex)
                    {
                        string msg = ex.Message;
                        if (!msg.Contains("BLE packets received"))
                        {
                            throw;
                        }

                        if (trycount++ > 3)
                        {
                            throw;
                        }
                    }
                }
            }

            fire_status("Serialize...");
            Serialize();

            fire_status("Certificate...");
            Certificate();

            fire_status("Show Mfg...");
            SaveShowMfg();

            TimeSpan ts   = DateTime.Now - start_time;
            string   tmsg = string.Format("ETime: {0}s.", ts.TotalSeconds);

            fire_status(tmsg);
        }