public override bool Run() { using (var ctx = new ManufacturingStoreEntities()) { JiliaHub dbjhub = new JiliaHub(); dbjhub.EuiId = _dbeui.Id; dbjhub.MacAddressId = _dbmac.Id; dbjhub.Mac = MacAddressGenerator.LongToStr(_dbmac.MAC); TestStatusTxt = $"Hub MAC {dbjhub.Mac}"; dbjhub.Bid = $"J{_dbeui.Id}"; TestStatusTxt = $"Hub BId {dbjhub.Bid}"; // Activation // /config/activation_key string line = WriteCommand("cat /config/activation_key"); Regex regex = new Regex(@"([0-9,a-z,A-Z]{8})"); Match match = regex.Match(line); if (!match.Success || match.Groups.Count < 2) { TestErrorTxt = $"Unable to parse hub activation. Line was {line}"; return(false); } dbjhub.Activation = match.Groups[1].Value; TestStatusTxt = $"Hub activation {dbjhub.Activation}"; // Uid line = WriteCommand("cat /data/run/.system"); regex = new Regex(@"uuid: ([0-9,a-f]{8}-([0-9,a-f]{4}-){3}[0-9,a-f]{12})"); match = regex.Match(line); if (!match.Success || match.Groups.Count < 2) { TestErrorTxt = $"Unable to parse hub uuid. Line was {line}"; return(false); } dbjhub.Uid = match.Groups[1].Value; TestStatusTxt = $"Hub uuid {dbjhub.Uid}"; // Insert ctx.JiliaHubs.Add(dbjhub); ctx.SaveChanges(); TestStatusTxt = $"Hub dbrid {dbjhub.Id}"; } return(true); }
public override bool Run() { // Check if a file already exists and extract info if it does string onBoardMac = INVALID_MAC_ADDRESS; string hub_file_mac = WriteCommand($"cat /config/mac1"); string mmac = MacAddressGenerator.ExtractMacString(hub_file_mac); if (mmac != null) { onBoardMac = mmac; } // Check it is in the database MacAddress dbmac = null; if (onBoardMac != INVALID_MAC_ADDRESS) { try { dbmac = DataUtils.GetMacAddress(onBoardMac); } catch { }; if (dbmac != null) { TestStatusTxt = $"MAC address already assigned {onBoardMac} on {dbmac.Date.ToShortDateString()}"; dbmac = DataUtils.GetMacAddress(onBoardMac); TestSequence.HUB_MAC_ADDR = MacAddressGenerator.LongToStr(dbmac.MAC); return(verifyIFConfig()); } } // If we got this far, we need to check whether hub already in database with a mac // For that we need the hub eui. We use the testSequence eui property //HUB_EUI = TestSequence.HUB_EUI; if (string.IsNullOrEmpty(TestSequence.HUB_EUI)) { TestErrorTxt = "HUB_EUI needs to be set before this test"; return(false); } JiliaHub dbhub = null; try { dbhub = DataUtils.GetHub(TestSequence.HUB_EUI); } catch { }; if (dbhub != null) { // This hub was previously tested, use this mac... // So why its local mac file not set??? TestStatusTxt = $"MAC address already assigned {dbhub.Mac} during test on {dbhub.Timestamp.ToShortDateString()}"; // Need to create the hub file WriteCommand($"echo $'{dbhub.Mac}' > /config/mac1"); dbmac = DataUtils.GetMacAddress(dbhub.Mac); TestSequence.HUB_MAC_ADDR = MacAddressGenerator.LongToStr(dbmac.MAC); return(verifyIFConfig()); } // OK, so new hub, generate one mac address for it TestStatusTxt = "Generating MAC address"; if (StartAddress == -1 || EndAddress == -1) { TestErrorTxt = $"Invalid start ({StartAddress}) or end ({EndAddress}) address"; return(false); } else { string macstr = MacAddressGenerator.Generate(StartAddress, EndAddress); if (macstr != INVALID_MAC_ADDRESS) { WriteCommand($"echo $'{macstr}' > /config/mac1"); dbmac = DataUtils.GetMacAddress(macstr); TestSequence.HUB_MAC_ADDR = MacAddressGenerator.LongToStr(dbmac.MAC); return(verifyIFConfig(true)); } else { TestErrorTxt = $"Unable to generate mac address"; return(false); } } }