private FirmwareUpdatePackage DecodePackage() { var package = new FirmwareUpdatePackage(); package.DecodeFrame(_buffer.ToArray()); Debug.WriteLine(package.PackageStatus); while (true) { if (package.PackageStatus == PackageStatus.BufferHaveNoEnoughLength) { break; } if (package.PackageStatus == PackageStatus.DecodeCompleted) { _buffer.RemoveRange(0, package.PackageLength); break; } if (_buffer.Count > 0) { _buffer.RemoveAt(0); } package.DecodeFrame(_buffer.ToArray()); Debug.WriteLine(package.PackageStatus); } return(package); }
private FirmwareUpdatePackage DecodePackage() { var package = new FirmwareUpdatePackage(); package.DecodeFrame(_buffer.ToArray()); if (package.PackageStatus == PackageStatus.InvalidHead) { if (_buffer.Count > 0) { _buffer.RemoveAt(0); } DecodePackage(); } else if (package.PackageStatus == PackageStatus.BufferHaveNoEnoughLength) { return(package); } else { _buffer.Clear(); } return(package); }