Example #1
0
        public void SaveShowMfg()
        {
            using (SerialCOM dutport = getDUTPort())
            {
                // Make sure we can talk to hub
                dutport.WriteWait("", "#", 3);
                dutport.Data = "";
                string mfg_data = dutport.WriteWait("show mfg", "Batch Number:", 3);

                fire_status(mfg_data);

                string fileloc = Path.Combine(this.LogFolder, "d" + SMT_Serial.ToString() + ".txt");
                using (FileStream fs = new FileStream(fileloc, FileMode.Create, FileAccess.Write, FileShare.Read))
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.Write(mfg_data);
                        sw.Close();
                    }
            }
        }
Example #2
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();
                }
        }