/// <summary> /// This Function will return the location of the very first frame in the memory buffer.. /// </summary> /// <param name="internalMemoryBuffer">memory buffer reference</param> /// <param name="startIndexSearch">starting index inside the memory buffer where it will search</param> /// <returns>PositionFrame class which will give the position of the frame inside the memory buffer</returns> public PositionFrame GetPosition(List <byte> internalMemoryBuffer, int startIndexSearch) { if (startIndexSearch > internalMemoryBuffer.Count - startPattern.Length) { // return null; return(new PositionFrame(true, internalMemoryBuffer.Count - startPattern.Length)); } // find starting pattern // before finding the just invert the logic in here from start to end.. int frameStartIndex = FindPattern(internalMemoryBuffer, startPattern, startIndexSearch); if (frameStartIndex == -1) { return(new PositionFrame(true, internalMemoryBuffer.Count - startPattern.Length)); } int frameEndIndex = FindPattern(internalMemoryBuffer, endPattern, frameStartIndex + startPattern.Length); if (frameEndIndex == -1) { return(new PositionFrame(true, frameStartIndex)); } int Lenght = frameEndIndex - frameStartIndex + endPattern.Length; int nextSearchStartPosition = frameEndIndex + endPattern.Length; PositionFrame aPositionFrame = new PositionFrame(frameStartIndex, frameEndIndex, nextSearchStartPosition, Lenght); return(aPositionFrame); }
/// <summary> /// This Function will return the location of the very first frame in the memory buffer.. /// </summary> /// <param name="internalMemoryBuffer">memory buffer reference</param> /// <param name="startIndexSearch">starting index inside the memory buffer where it will search</param> /// <returns>PositionFrame class which will give the position of the frame inside the memory buffer</returns> public PositionFrame GetPosition(List <byte> internalMemoryBuffer, int startIndexSearch) { if (startIndexSearch > internalMemoryBuffer.Count - startPattern.Length) { return(new PositionFrame(true, internalMemoryBuffer.Count - startPattern.Length)); } // find starting pattern int frameStartIndex = FindPattern(internalMemoryBuffer, startPattern, startIndexSearch); if (frameStartIndex == -1) { return(new PositionFrame(true, internalMemoryBuffer.Count - startPattern.Length)); } int frameEndIndex = FindPattern(internalMemoryBuffer, endPattern, frameStartIndex + startPattern.Length); if (frameEndIndex == -1) { return(new PositionFrame(true, frameStartIndex)); } int Lenght = frameEndIndex - frameStartIndex + endPattern.Length; int nextSearchStartPosition = frameEndIndex + endPattern.Length; PositionFrame aPositionFrame = new PositionFrame(frameStartIndex, frameEndIndex, nextSearchStartPosition, Lenght); return(aPositionFrame); }
private void SearchFormatHandoff() { while (startIndexSearch < internalMemoryBuffer.Count) { byte[] locData = null; if (isFrameSearchingRequired) { PositionFrame position = frameSearcher.GetPosition(internalMemoryBuffer, startIndexSearch); if (position == null) { //Debugger.Break(); } // frame not Found... if (position.IsNullPosition()) { startIndexSearch = position.GetNextSearchStartingPosition(); return; } // else if frame found. startIndexSearch = position.GetNextSearchStartingPosition(); locData = new byte[position.GetFrameLength()]; int counter = 0; for (int i = position.GetFrameStartPosition(); i < position.GetFrameStartPosition() + position.GetFrameLength(); i++) { // now first XOR ith Element of Internal Memory Buffer with 55 here if (isDataFormattingRequired) { locData[counter++] = frameFormatter.FormatByte(internalMemoryBuffer[i]); } else { locData[counter++] = internalMemoryBuffer[i]; } } } else { // No frame search required now just copy the data to output buffer... locData = new byte[internalMemoryBuffer.Count - startIndexSearch]; int dataCounter = 0; for (int i = startIndexSearch; i < internalMemoryBuffer.Count; i++) { if (isDataFormattingRequired) { locData[dataCounter++] = frameFormatter.FormatByte(internalMemoryBuffer[i]); } else { locData[dataCounter++] = internalMemoryBuffer[i]; } } startIndexSearch = internalMemoryBuffer.Count; } // now Hand off data.. transferBuffer.TryAdd(locData); //publisher.UpdateUserInterface(locData); } }