public virtual IEnumerable <byte[]> Iterator(int[] apids, Int64 startTime, Int64 stopTime, long skip = 0L) { var counter = 0L; foreach (var p in Iterator()) { var timestamp = PacketAccessor.Time42(p); if (timestamp < startTime || timestamp > stopTime) { continue; } var apid = PacketAccessor.APID(p); var len = apids.Length; for (var i = 0; i < len; i++) { if (apid == apids[i]) { if (counter++ >= skip) { yield return(p); } break; } } } }
public IEnumerable <byte[]> Iterator(int[] apids, Int64 startTime, Int64 stopTime, long skip = 0L) { var counter = 0L; return(from p in Iterator() let timestamp = PacketAccessor.Time42(p) let apid = PacketAccessor.APID(p) where startTime <= timestamp && timestamp <= stopTime && apids.Contains(apid) && counter++ > skip select p); //return Iterator(); }
/// <summary> /// Used by the iterator with the skip operational parameter. This will cause two initial /// passes through the file and can be made more efficient. /// </summary> /// <param name="apids"></param> /// <param name="startTime"></param> /// <returns></returns> public int ApidMatchesAfterStart(int[] apids, Int64 startTime) { if (startTime == _cacheStartTime && _cacheApids == apids) { return(_cacheApidMatchesAfterStart); } // Cache miss _cacheApids = apids; _cacheStartTime = startTime; if (EndTime42 < startTime) { _cacheApidMatchesAfterStart = 0; return(_cacheApidMatchesAfterStart); } if (startTime <= BeginTime42) { _cacheApidMatchesAfterStart = ApidCount(apids); return(_cacheApidMatchesAfterStart); } var count = 0; var max = apids.Count(); foreach (var p in Iterator(startTime, Int64.MaxValue)) { var apid = PacketAccessor.APID(p); for (var i = 0; i < max; i++) { if (apid == apids[i]) { count++; break; } } } _cacheApidMatchesAfterStart = count; return(_cacheApidMatchesAfterStart); }
public void CheckPacketLength(byte[] packet, int packetPtr) { var len = PacketAccessor.PacketFixedHeaderLength + 1 + PacketAccessor.Length(packet); //if (len != packetPtr) // throw new Exception("Packet Length Check Exception"); if (len != packetPtr) { Console.Error.WriteLine(@"Packet length check exception: apid={0} timestamp={1}", PacketAccessor.APID(packet), PacketAccessor.Time42(packet)); } }
// This calculates that start, stop and a pseudo-start that's after 2014 (heuristically trying to find // times when the clock had been jammed). public void LoadStats() { var jamfilter = TimeUtilities.DateTimeToTime42(new DateTime(2014, 1, 1)); //var endFilter = TimeUtilities.DateTimeToTime42(new DateTime(2018, 1, 1)); const long endFilter = 37226859724800L; try { var dict = new Dictionary <int, int>(); var begin = Int64.MaxValue; var jam = Int64.MaxValue; var end = Int64.MinValue; var count = 0; foreach (var packet in Iterator()) { count++; var apid = PacketAccessor.APID(packet); var timestamp = PacketAccessor.Time42(packet); if (timestamp == 0L) { continue; // ignore CLCW packets, no timestamp } if (timestamp < begin) { begin = timestamp; } if (timestamp < endFilter) { if (timestamp > end) { end = timestamp; } if (timestamp < jam && timestamp > jamfilter) { jam = timestamp; } } int prev; if (dict.TryGetValue(apid, out prev)) { dict[apid] = prev + 1; } else { dict.Add(apid, 1); } } if (count > 0) { _BeginTime42 = begin; _EndTime42 = end; _BeginTime42Jammed = jam == long.MaxValue ? jamfilter : jam; } else { _BeginTime42 = 0L; _EndTime42 = 0L; _BeginTime42Jammed = 0L; } _PacketCount = count; _isFullyReadable = true; _ApidCount = dict; _Changed = true; _BeginString = TimeUtilities.Time42ToString(_BeginTime42); _EndString = TimeUtilities.Time42ToString(_EndTime42); _JammedString = TimeUtilities.Time42ToString(_BeginTime42Jammed); //Console.WriteLine("b={0}\nj={1}\ne={2} f={3}", _BeginString, _JammedString, _EndString, Name); } catch (Exception e1) { Console.WriteLine(e1); Console.WriteLine(e1.StackTrace); _isFullyReadable = false; } /* Console.WriteLine(Path); * var a = _PacketCount; * var b = Iterator().Count(); * var c = _ApidCount.Sum(pair => pair.Value); * * Console.WriteLine("_PacketCount={0}", a); * Console.WriteLine("Actual={0}", b); * Console.WriteLine("_ApidCount={0}",c); * if (a != b || b != c) * Console.WriteLine("friday"); * //todo*/ }
public static PacketFileType GetFileTypeId(string path) { try { var ext = System.IO.Path.GetExtension(path); ext = ext != null?ext.ToLower() : null; if (".meta".Equals(ext, StringComparison.InvariantCultureIgnoreCase) || ".dir".Equals(ext, StringComparison.InvariantCultureIgnoreCase) || ".gz".Equals(ext, StringComparison.InvariantCultureIgnoreCase) || ".itf".Equals(ext, StringComparison.InvariantCultureIgnoreCase)) { return(PacketFileType.UNRECOGNIZED_FILE); } if (".H".Equals(ext, StringComparison.InvariantCultureIgnoreCase)) { return(GetFileTypeFromItosMetafile(path)); } var fname = System.IO.Path.GetFileNameWithoutExtension(path); var buf = new byte[8]; using (var s = File.OpenRead(path)) { for (var i = 0; i < 8; i++) { buf[i] = (byte)s.ReadByte(); } } // CFE_PACKET_FILE if (buf[0] == 'c' && buf[1] == 'F' && buf[2] == 'E') { return(PacketFileType.CFE_PACKET_FILE); } if (buf[0] == 'R' && buf[1] == 'A' && buf[2] == 'F' && buf[3] == '1') { return(PacketFileType.RAF_FRAME_FILE); } // ITOS_FRAME_FILE if (buf[0] == 26 && buf[1] == 207 && (buf[4] & 248) == 72) { return(PacketFileType.ITOS_FRAME_FILE); } if (buf[0] == 0 && buf[1] == 0 && buf[2] == 252 && buf[3] == 29) { return(PacketFileType.ITOS_FRAME_FILE); } //for (var i = 0; i < 8; i++) // Console.WriteLine(@"buf[{0}]={1}", i, buf[i]); try { var i = 0; // ITOS_PACKET_FILE if ((buf[0] & 0xF8) == 0x08 || (buf[0] == 7 && 2001 == PacketAccessor.APID(buf))) { foreach (var p in (new ITOSPacketFile(path)).Iterator()) { //if (!PacketAccessor.IsValidApid(PacketAccessor.APID(p))) // goto tryAnno12PacketFile; if (i++ > 30) { break; } } return(PacketFileType.ITOS_PACKET_FILE); } //tryAnno12PacketFile: i = 0; foreach (var p in (new Anno12PacketFile(path)).Iterator()) { //if (!PacketAccessor.IsValidApid(PacketAccessor.APID(p))) // goto unrecognizedFile; if (i++ > 30) { break; } } return(PacketFileType.ANNO12_PACKET_FILE); } catch (Exception e) { Console.WriteLine(@"Error reading telemetry database: {0}", e); } } catch (IOException e) { Console.WriteLine(@"Error reading telemetry database: {0}", e); } //unrecognizedFile: return(PacketFileType.UNRECOGNIZED_FILE); }