/// <summary> /// Checks if the frame given has a CRC error /// </summary> /// <param name="frame">Frame to be checked</param> /// <param name="crc">CRC to be compare to</param> /// <returns>True if there is a CRC error, false otherwise</returns> protected static bool HasCrcError(TcmpFrame frame, byte[] crc) { List <byte> data = new List <byte>(frame.ToArray()); byte[] temp = CalculateCrc(data.GetRange(1, frame.FrameLength - 4)); if (temp[0] != frame.Crc[0] || temp[1] != frame.Crc[1]) { return(true); } else { return(false); } }
/// <summary> /// Checks if the frame given has a LCS errors, CRC errors, or other errors /// </summary> /// <param name="frame"></param> /// <returns>True is frame has no errors, false otherwise</returns> public static bool IsValidFrame(TcmpFrame frame) { if (frame == null) { return(false); } byte[] contents = frame.ToArray(); if (contents.Length < 10) { return(false); } if (contents[0] != 0x7E) { return(false); } if (HasLcsError(frame.Len1, frame.Len0, frame.Lcs)) { return(false); } if (frame.Length + 5 != contents.Length) { return(false); } if (HasCrcError(frame, frame.Crc)) { return(false); } return(true); }