private void ExpandScanner(ScannerDecode scannerDecode, byte[] data) { Id6Count++; Array.Copy(data, 0, Id6Whole, Id6LastIndex, data.Length); Id6Distance.AddRange(scannerDecode.Distance); Id6LastBlock = scannerDecode.Block; Id6LastIndex = Id6LastIndex + data.Length; }
private void RefreshScanner(ScannerDecode scannerDecode) { Degree = 0; AngleDifference = 0; Id6Blocks = scannerDecode.Block_From_Calc; Id6LastBlock = -1; Id6LastIndex = 0; Id6Count = 0; Id6Distance.Clear(); Array.Clear(Id6Whole, 0, Id6Whole.Length); }
public ScannerDecode Decode(byte[] rawbyte) { ScannerDecode Dec_Data = new ScannerDecode() { ID = ScannerFunctionality.GetID(rawbyte), Block = ScannerFunctionality.GetBlock(rawbyte), ToatalLength = ScannerFunctionality.GetTotalLength(rawbyte) }; if (Dec_Data.ID == 1) { Dec_Data.Start_Index = ScannerFunctionality.GetStartIndex(rawbyte); Dec_Data.Stop_Index = ScannerFunctionality.GetStopIndex(rawbyte); Dec_Data.Resolution = ScannerFunctionality.GetResolution(rawbyte); Dec_Data.Block_From_Calc = ScannerFunctionality.GetBlockFromCalculation(rawbyte); } else { Dec_Data.Distance = ScannerFunctionality.GetDistanceList(rawbyte); } return(Dec_Data); }
public void ProcessReceive() { LogFiler.Log(Category.Info, MethodBase.GetCurrentMethod().DeclaringType.Name + "_" + MethodBase.GetCurrentMethod().Name + ": started receiving data."); try { while (!IsStopped) { var watch = new System.Diagnostics.Stopwatch(); watch.Start(); Task <byte[]> receive = TReceive(); ScannerDecode Info = new ScannerDecode().Decode(receive.Result); if (Info.ID == 1) { RefreshScanner(Info); Tuple <float, float> angleinfo = ScannerFunctionality.GetAngleId1(receive.Result); Degree = angleinfo.Item1; AngleDifference = angleinfo.Item2; } else if (Info.ID == 6) { if (BlockOrderCorrect(Info.Block)) { ExpandScanner(Info, receive.Result); // if the id6 telegramblocks are finished - split the distance based on the scannergap information (not visible area) // if its not getting split, the averaging will create datapoints where the scanner couldnt be able to see at all - leads to consequential errors if (Id6Complete()) { Distance = ScannerFunc.GetProcessedDistance(Id6Distance.ToList()); if (Mainframe.IsNormalizedbyMedian[Tag]) { Distance = ScannerFunc.GetMedianAverageArray(Distance.ToList()); } XYCoord = ScannerFunc.GetXYCoordinate(Distance.ToList(), this); XYCoordinate = ScannerFunctionality.MergeXYArray(XYCoord.ToList()); OnScannerRaw(this, XYCoordinate.ToList()); List <List <Tuple <int, int, int> > > Normalizer = new List <List <Tuple <int, int, int> > >(); List <Tuple <int, int, int> > Normalized = new List <Tuple <int, int, int> >(); // try to accomplish the necessary kinds of averaging the distance sent by the scanner // data averaged by time if (Mainframe.IsNormalizedbyTime[Tag]) { List <Tuple <int, int, int> > xycollection = new List <Tuple <int, int, int> >(XYCoordinate); XYCollection[RingBufferCount] = xycollection; List <List <Tuple <int, int, int> > > xycolle = new List <List <Tuple <int, int, int> > >(XYCoord); XYColl[RingBufferCount] = xycolle; RingBufferCount++; CountTimeAverage++; if (RingBufferCount == Mainframe.NormalizebyTimeCountStoredData[Tag]) { RingBufferCount = 0; } if (CountTimeAverage == Mainframe.NormalizebyTimeCountDataAverage[Tag]) { Normalizer = ScannerFunc.NormalizationByTime(RingBufferCount, XYColl); CountTimeAverage = 0; } } else { Normalizer = XYCoord; } if (Normalizer.Count != 0) { if (Mainframe.IsNormalizedbyTriangle[Tag]) { Normalizer = ScannerFunc.Normalization(Normalizer.ToList()); } Normalized = ScannerFunctionality.MergeNormalizeArray(Normalizer.ToList()); Normalized = ScannerFunc.ChangePositionOfXY(Normalized.ToList()); NormalizedData = Normalized; OnScannerNormalized(this, new List <Tuple <int, int, int> >(NormalizedData)); List <Tuple <int, int, int> > Analyser = new List <Tuple <int, int, int> >(Normalized); AnalyseData = Analyser; } if (watch.IsRunning) { watch.Stop(); LogFiler.Log(Category.Info, "normalise" + watch.ElapsedMilliseconds.ToString()); } } } } } } catch (Exception ex) { LogFiler.Log(Category.Error, MethodBase.GetCurrentMethod().DeclaringType.Name + "_" + MethodBase.GetCurrentMethod().Name + ": " + ex.Message); } }