public async Task SaveLoad_CorrectProjectContent() { var random = new Random(); var networkInfo = new NetworkInfo(); networkInfo.ChCenterFrequency = (uint)random.Next(); networkInfo.Channel = (uint)random.Next(); networkInfo.LinkQuality = (uint)random.Next(); networkInfo.Mac = Guid.NewGuid().ToString(); networkInfo.Rssi = random.Next(); networkInfo.Ssid = Guid.NewGuid().ToString(); var scanPoint = new ScanPoint(); scanPoint.Position = new Point(random.Next(), random.Next()); scanPoint.BssInfo.Add(networkInfo); var expected = new Project(); expected.Bitmap = new byte[100]; random.NextBytes(expected.Bitmap); expected.ScanPoints.Add(scanPoint); var tempFileName = Path.GetTempFileName(); var jsonFileStorage = new JsonFileStorage <Project>(tempFileName); await jsonFileStorage.Save(expected); var actual = await jsonFileStorage.Load(); Assert.Equal(expected, actual); }
public async Task Save_CorrectFileContent() { var networkInfo = new NetworkInfo(); networkInfo.ChCenterFrequency = 1; networkInfo.Channel = 2; networkInfo.LinkQuality = 3; networkInfo.Mac = "4"; networkInfo.Rssi = 5; networkInfo.Ssid = "6"; var scanPoint = new ScanPoint(); scanPoint.Position = new Point(7, 8); scanPoint.BssInfo.Add(networkInfo); var project = new Project(); project.Bitmap = new byte[] { 9, 10, 11 }; project.ScanPoints.Add(scanPoint); var tempFileName = Path.GetTempFileName(); var jsonFileStorage = new JsonFileStorage <Project>(tempFileName); await jsonFileStorage.Save(project); var actual = await File.ReadAllTextAsync(tempFileName); var expected = await File.ReadAllTextAsync("Data\\test.json"); Assert.Equal(expected, actual); }
public async Task Load_CorrectFileContent() { var networkInfo = new NetworkInfo(); networkInfo.ChCenterFrequency = 1; networkInfo.Channel = 2; networkInfo.LinkQuality = 3; networkInfo.Mac = "4"; networkInfo.Rssi = 5; networkInfo.Ssid = "6"; var scanPoint = new ScanPoint(); scanPoint.Position = new Point(7, 8); scanPoint.BssInfo.Add(networkInfo); var expected = new Project(); expected.Bitmap = new byte[] { 9, 10, 11 }; expected.ScanPoints.Add(scanPoint); var jsonFileStorage = new JsonFileStorage <Project>("Data\\test.json"); var actual = await jsonFileStorage.Load(); Assert.Equal(expected, actual); }
private ScanPoint newscanPoint(string icon, string name) { //logger.Trace("Service : IRestService, Method : newscanPoint , Request : {"Icon" : icon, "Name" : name };") ScanPoint mscanpoint = new ScanPoint(); mscanpoint.ScanType = icon; mscanpoint.Location = name; mscanpoint.DateTime = DateTime.Now.ToString("HH:mm MMM dd, yyyy"); //logger.Trace("Service : IRestService, Method : newscanPoint , Response : ScanPoint = {"ScanType" : mscanpoint.ScanType, "Location" : mscanpoint.Location , "DateTime" = mscanpoint.DateTime };") return(mscanpoint); }
private ScanPoint newscanPoint(string icon, string name) { logger.Trace("Service : IRestService, Method : newscanPoint , Request : {'Icon' : icon, 'Name' : name };"); ScanPoint mscanpoint = new ScanPoint(); mscanpoint.ScanType = icon; mscanpoint.Location = name; mscanpoint.DateTime = DateTime.Now.ToString("HH:mm MMM dd, yyyy"); logger.Trace("Service : IRestService, Method : newscanPoint , Response : ScanPoint = {'ScanType' : mscanpoint.ScanType, 'Location' : mscanpoint.Location , 'DateTime' = mscanpoint.DateTime };"); return(mscanpoint); }
public void AddScanPoint(ScanPoint sp) { currentScan.Points.Add(sp); }
private static List<GPoint> PostProcess (Grid g, GPoint.PType scanType, GPoint.PType fillType) { List<GPoint> processedPoints = new List<GPoint> (); Debug.Log ("scanning " + g.GetPoints (scanType).Count + "unique points"); List<Direction[]> ds = new List<Direction[]> (); ds.Add (new Direction[]{Direction.n, Direction.ne, Direction.e}); ds.Add (new Direction[]{Direction.e, Direction.se, Direction.s}); ds.Add (new Direction[]{Direction.s, Direction.sw, Direction.w}); ds.Add (new Direction[]{Direction.w, Direction.nw, Direction.n}); foreach (GPoint gp in g.GetPoints(scanType)) { //List<bool> values = new List<bool> (); ScanPoint scan = new ScanPoint (gp.GetPosition ()); if (ProcessPoint (g, scan, scanType, ds)) { processedPoints.Add (new GPoint (scan.Position (), fillType)); } } Debug.Log (processedPoints.Count + " processed points added"); return processedPoints; }
private static bool ProcessPoint (Grid g, ScanPoint sc, GPoint.PType st, List<Direction[]> scanMethod) { foreach (Direction[] dpat in scanMethod) { bool match = true; /*if (g.GetPoint (sc.VirtualMove (dpat [0])).GetPType () == st && g.GetPoint (sc.VirtualMove (dpat [1])).GetPType () == st && g.GetPoint (sc.VirtualMove (dpat [2])).GetPType () == st) { return true; }*/ for (int i =0; i <dpat.Length; i++) { if (g.GetPoint (sc.VirtualMove (dpat [i])).GetPType () != st) { match = false; } } if (match) { return match; } } return false; }
public static List<GPoint> Generate (Grid g, GPoint.PType walkType, int steps) { //make the last direction random, to randomise the opposite of the first direction //start at 1 //pick a new direction //if the direction is okay //move the test vector //if the new position is in bounds //add the point //iterate the loop //set the last direction to the new direction List<GPoint> points = new List<GPoint> (); //set the scanpoint in the middle of the grid ScanPoint scan = new ScanPoint (g.GetSize () / 2); //set the last direction as a new direction Direction lastDir = PickNewDirection (); //set the stepcount at 1 int stepcount = 1; //if the stepcount is less than or equal to the max number of steps while (stepcount<=steps) { //pick a new direction and set it as the new direction Direction newDir = PickNewDirection (); //if the new direction is not the opposite of the last direction if (IsValidDirection (newDir, lastDir)) { //move the testposition in the new direction Vector2 testPos = scan.VirtualMove (newDir); //check if the new position is within the constraints if (g.PositionInBounds (testPos)) { //if it is, move the scanpoint in the direction scan.Move (newDir); //iterate the stepcount stepcount++; //add a new gpoint to the list of the designated type points.Add (new GPoint (scan.Position (), walkType)); //Debug.Log ("point added to grid at " + scan.Position ()); } //set the last dir to the new dir to ensure accurate direction checking //when the loop repeats lastDir = newDir; } //otherwise, do absolutely nothing } Debug.Log ("generated a " + points.Count + " point line of " + walkType); Grid tg = new Grid (g); tg.Clear (); tg.UpdatePoints (points); List<GPoint> processed = new List<GPoint> (); processed = PostProcess (tg, walkType, walkType); return processed; }
public static List<GPoint> FixRoads (Grid g, List<GPoint> rVHplusO, Vector2 blockSize) { //we will need to create a temporary grid that contains all of the new points //then iterate through it by the blocksize as done earlier //for each intersection check if there is a road to the left or down //if there is one left, then create a vertical road as done earlier //if there is one down, then create a horizontal road as done earlier //also create an intersection at the point List<GPoint> fixedRoads = new List<GPoint> (); Grid tG = new Grid (g); tG.Fill (GPoint.PType.TILE_GRASS); tG.UpdatePoints (rVHplusO); for (float ix=1.0f; ix<tG.GetXYMax().x; ix+=blockSize.x) { //iterate up by blocksize for (float iy=1.0f; iy<tG.GetXYMax().y; iy+=blockSize.y) { //iterate right by blocksize //set the scan point to the current position on the grid ScanPoint sp1 = new ScanPoint (new Vector2 (ix, iy)); //move the scanpoint to the left and check if is anything but background if (!tG.GetPoint (sp1.VirtualMove (Direction.w)).IsBackgroundTile ()) { //create a vertical road blocksize.y units long //probably going to do this with a for loop fixedRoads.Add (new GPoint (sp1.Position (), GPoint.PType.TILE_ROADI)); fixedRoads.Add (new GPoint (new Vector2 (sp1.Position ().x, sp1.Position ().y + blockSize.y), GPoint.PType.TILE_ROADI)); for (float iy2 = 1.0f; iy2<blockSize.y; iy2+=1.0f) { fixedRoads.Add (new GPoint (new Vector2 (sp1.Position ().x, sp1.Position ().y + iy2), GPoint.PType.TILE_ROADV)); } } if (!tG.GetPoint (sp1.VirtualMove (Direction.s)).IsBackgroundTile ()) { //create a horizontal road blocksize.x units long //probably going to do this with a for loop fixedRoads.Add (new GPoint (sp1.Position (), GPoint.PType.TILE_ROADI)); fixedRoads.Add (new GPoint (new Vector2 (sp1.Position ().x + blockSize.x, sp1.Position ().y), GPoint.PType.TILE_ROADI)); for (float ix2 = 1.0f; ix2<blockSize.x; ix2+=1.0f) { fixedRoads.Add (new GPoint (new Vector2 (sp1.Position ().x + ix2, sp1.Position ().y), GPoint.PType.TILE_ROADH)); } } } } return fixedRoads; }
public static GPoint.Direction CalculateDirection (Grid g, GPoint gp) { ScanPoint scp = new ScanPoint (gp.GetPosition ()); List<string> dirs = new List<string> (); string direction = ""; switch (g.GetPoint (scp.VirtualMove (Direction.n)).GetPType ()) { case GPoint.PType.TILE_ROADH: dirs.Add ("N"); break; case GPoint.PType.TILE_ROADV: dirs.Add ("N"); break; default: //nothing break; } switch (g.GetPoint (scp.VirtualMove (Direction.s)).GetPType ()) { case GPoint.PType.TILE_ROADH: dirs.Add ("S"); break; case GPoint.PType.TILE_ROADV: dirs.Add ("S"); break; default: //nothing break; } switch (g.GetPoint (scp.VirtualMove (Direction.e)).GetPType ()) { case GPoint.PType.TILE_ROADH: dirs.Add ("E"); break; case GPoint.PType.TILE_ROADV: dirs.Add ("E"); break; default: //nothing break; } switch (g.GetPoint (scp.VirtualMove (Direction.w)).GetPType ()) { case GPoint.PType.TILE_ROADH: dirs.Add ("W"); break; case GPoint.PType.TILE_ROADV: dirs.Add ("W"); break; default: //nothing break; } /* foreach (string s in dirs) { Debug.Log (s); }*/ int val = (int)Random.Range (0, dirs.Count ()); //Debug.Log ("integer " + val); //Debug.Log ("directions " + dirs.Count ()); direction = dirs.ElementAt (val); //Debug.Log ("direction chosen" + direction); switch (direction) { case "N": //Debug.Log ("turn north"); return GPoint.Direction.NORTH; //break; case "S": //Debug.Log ("turn south"); return GPoint.Direction.SOUTH; //break; case "E": //Debug.Log ("turn east"); return GPoint.Direction.EAST; //break; case "W": //Debug.Log ("turn west"); return GPoint.Direction.WEST; //break; default: return GPoint.Direction.NORTH; //break; } ; //return GPoint.Direction.NORTH; }
private void Acquire() { try { // lock a monitor onto the acquisitor, to synchronise with the controller // when acquiring a set number of scans - the monitor is released in // AcquisitionFinishing() Monitor.Enter(AcquisitorMonitorLock); // initialise all of the plugins config.outputPlugin.AcquisitionStarting(); config.pgPlugin.AcquisitionStarting(); config.shotGathererPlugin.AcquisitionStarting(); config.switchPlugin.AcquisitionStarting(); config.yagPlugin.AcquisitionStarting(); config.analogPlugin.AcquisitionStarting(); for (int scanNumber = 0;; scanNumber++) { // prepare for the scan start config.outputPlugin.ScanStarting(); config.pgPlugin.ScanStarting(); config.shotGathererPlugin.ScanStarting(); config.switchPlugin.ScanStarting(); config.yagPlugin.ScanStarting(); config.analogPlugin.ScanStarting(); for (int pointNumber = 0; pointNumber < (int)config.outputPlugin.Settings["pointsPerScan"]; pointNumber++) { // calculate the new scan parameter and move the scan along config.outputPlugin.ScanParameter = NextScanParameter(pointNumber, scanNumber); // check for a change in the pg parameters lock (this) { if (tweakFlag) { // now it's safe to update the pattern generator settings // and ask the pg to reload SettingsReflector sr = new SettingsReflector(); sr.SetField(config.pgPlugin, latestTweak.parameter, latestTweak.newValue.ToString()); config.pgPlugin.ReloadPattern(); tweakFlag = false; } } ScanPoint sp = new ScanPoint(); sp.ScanParameter = config.outputPlugin.ScanParameter; for (int shotNum = 0; shotNum < (int)(config.outputPlugin.Settings["shotsPerPoint"]); shotNum++) { // Set the switch state config.switchPlugin.State = true; // wait for the data gatherer to finish config.shotGathererPlugin.ArmAndWait(); // read out the data sp.OnShots.Add(config.shotGathererPlugin.Shot); if ((bool)config.switchPlugin.Settings["switchActive"]) { config.switchPlugin.State = false; config.shotGathererPlugin.ArmAndWait(); sp.OffShots.Add(config.shotGathererPlugin.Shot); } } // sample the analog channels and add them to the ScanPoint config.analogPlugin.ArmAndWait(); sp.Analogs.AddRange(config.analogPlugin.Analogs); // send up the data bundle DataEventArgs evArgs = new DataEventArgs(); evArgs.point = sp; OnData(evArgs); // check for exit if (CheckIfStopping()) { AcquisitionFinishing(config); return; } } // prepare for the start of the next scan OnScanFinished(); config.pgPlugin.ScanFinished(); config.yagPlugin.ScanFinished(); config.outputPlugin.ScanFinished(); config.shotGathererPlugin.ScanFinished(); config.switchPlugin.ScanFinished(); config.analogPlugin.ScanFinished(); // I think that this pause will workaround an annoying threading bug // I should probably be less cheezy and put a lock in, but I'm not really // sure that I know what the bug is as it's intermittent (and rare). Thread.Sleep(750); // check if we are finished scanning if (scanNumber + 1 == numberOfScans) { backendState = AcquisitorState.stopped; // set the controller state to stopped Controller.GetController().appState = Controller.AppState.stopped; AcquisitionFinishing(config); return; } } } catch (Exception e) { // last chance exception handler - this stops a rogue exception in the // acquire loop from killing the whole program Console.Error.Write(e.Message + e.StackTrace); MessageBox.Show("Exception caught in acquire loop.\nTake care - the program " + "is probably unstable.\n" + e.Message + "\n" + e.StackTrace, "Acquire error", MessageBoxButtons.OK, MessageBoxIcon.Error); // Try and stop the pattern gracefully before the program dies config.pgPlugin.AcquisitionFinished(); lock (this) backendState = AcquisitorState.stopped; } }