public void AddPGNDefn(PGNDefn pgn) { if (PGNDefns == null) { PGNDefns = new PGNDefn[1] { pgn }; } else { Array.Resize(ref pgnDefns, PGNDefns.Length + 1); PGNDefns[PGNDefns.Length - 1] = pgn; } SortAndBuildInternalStructures(); }
// Given a (possibly partially) completed PGN message, // described by a PGN number, and the apparent 'byte length' // for the message (which is only relevant if the message is a // multiple packet message), return the // PGNDefn that allows this message to be decoded public PGNDefn GetPGNDefn(N2kFrame msg) { uint PGN = (uint)msg.Header.PGN; int pgnIndex; if (!PGNDictionary.TryGetValue(PGN, out pgnIndex)) { // No matching PGN definition; return UnknownPGNDefn return(UnknownPGNDefn); } else { PGNDefn pgn = PGNDefns[pgnIndex]; // Is this a multiple definition PGN? (If so, it must be a fast packet PGN?) if (!pgn.HasMultipleDefinitions) { // Only one matching definition available; return it // int iBytesTransmitted = pgn.ByteLength <= 8 ? msg.Data.Length : msg.Data[1]; return(PGNDefns[pgnIndex]); } else { // Find the matching definition while ((pgnIndex < PGNDefns.Length) && (PGNDefns[pgnIndex].PGN == pgn.PGN)) { if (PGNDefns[pgnIndex].ByteLength == msg.Data[1]) { return(PGNDefns[pgnIndex]); } else { // Find any PGN that is not too long, just on case we cannot find any with an exact match if (pgn.ByteLength < msg.Data[1]) { pgn = PGNDefns[pgnIndex]; } pgnIndex++; } } return(pgn); } } }
public override int CompareTo(object obj) { PGNDefn oDefn = obj as PGNDefn; return((oDefn == null) ? -1 : this.PGN.CompareTo(oDefn.PGN)); }