/// <summary> /// Appends header specific attributes to <paramref name="attributes"/> dictionary. /// </summary> /// <param name="attributes">Dictionary to append header specific attributes to.</param> internal void AppendHeaderAttributes(Dictionary <string, string> attributes) { attributes.Add("Frame Type", (ushort)TypeID + ": " + TypeID); attributes.Add("Frame Length", FrameLength.ToString()); attributes.Add("Header Length", Length.ToString()); attributes.Add("Payload Length", DataLength.ToString()); attributes.Add("Second of Century", SecondOfCentury.ToString()); attributes.Add("Fraction of Second", FractionOfSecond.ToString()); uint timeQualityFlags = (uint)TimeQualityFlags; attributes.Add("Time Quality Flags", timeQualityFlags.ToString()); if (timeQualityFlags > 0) { attributes.Add("Leap Second State", TimeQualityFlags.ToString()); } else { attributes.Add("Leap Second State", "No leap second is currently pending"); } attributes.Add("Time Quality Indicator Code", (uint)TimeQualityIndicatorCode + ": " + TimeQualityIndicatorCode); attributes.Add("Time Base", Timebase + (Timebase != Common.Timebase ? " - NON STANDARD" : "")); if (m_frameType != IEC61850_90_5.FrameType.DataFrame) { attributes.Add("Version", Version.ToString()); } else { attributes.Add("SPDU Length", m_spduLength.ToString()); attributes.Add("ASDU Payload Length", m_payloadSize.ToString()); attributes.Add("Packet Number", PacketNumber.ToString()); attributes.Add("Key ID", m_keyID.ToString("X").PadLeft(8, '0')); attributes.Add("Security Algorithm", (byte)m_securityAlgorithm + ": " + m_securityAlgorithm); attributes.Add("Signature Algorithm", (byte)m_signatureAlgorithm + ": " + m_signatureAlgorithm); if ((object)m_sourceHash != null && m_sourceHash.Length > 0) { attributes.Add("Parsed Signature Hash", ByteEncoding.Hexadecimal.GetString(m_sourceHash, ' ')); } else { attributes.Add("Parsed Signature Hash", "null"); } if ((object)m_calculatedHash != null && m_calculatedHash.Length > 0) { attributes.Add("Calculated Signature Hash", ByteEncoding.Hexadecimal.GetString(m_calculatedHash, ' ')); } else { attributes.Add("Calculated Signature Hash", "null"); } attributes.Add("Ignoring Checksum Validation", IgnoreSignatureValidationFailures.ToString()); attributes.Add("Number of ASDUs", m_asduCount.ToString()); attributes.Add("ConfigurationRevision", m_configurationRevision.ToString()); attributes.Add("Simulated Data", m_simulatedData.ToString()); attributes.Add("Application ID", m_applicationID.ToString()); attributes.Add("Using ETR Configuration", UseETRConfiguration.ToString()); attributes.Add("Configuration Guessing Allowed", GuessConfiguration.ToString()); attributes.Add("Parsing Redundant ASDUs", ParseRedundantASDUs.ToString()); attributes.Add("Ignoring Signature Validation Errors", IgnoreSignatureValidationFailures.ToString()); attributes.Add("Ignoring Sample Size Validation Errors", IgnoreSampleSizeValidationFailures.ToString()); attributes.Add("Selected Angle Format", m_angleFormat.ToString()); } }
/// <summary> /// Retrieves a formatted text for a degree value /// according to a given angle format. /// </summary> /// <param name="decDegrees">The degree value (with decimal places).</param> /// <param name="angleFormat">A <see cref="AngleFormat" /> member.</param> /// <param name="decimalPlaces">The number of decimal places (after decimal point) for the last unit.</param> /// <param name="forceAsciiCharacters">If true: Use 7 Bit ASCII characters only instead of special characters.</param> /// <returns>The formatted text.</returns> public static string GetFormattedText(double decDegrees, AngleFormat angleFormat, int decimalPlaces, bool forceAsciiCharacters) { string degreeSymbol, minuteSymbol, secondsSymbol; if (forceAsciiCharacters) { degreeSymbol = "d"; minuteSymbol = "'"; secondsSymbol = "\""; } else { degreeSymbol = "\x00B0".ToString(); //DEGREE SIGN minuteSymbol = "\x2032".ToString(); //PRIME secondsSymbol = "\x2033".ToString(); //DOUBLE PRIME } string separator = " "; string result; switch (angleFormat) { case AngleFormat.sD: { bool isNegative; double degrees; Utilities.DegreesToD(decDegrees, out isNegative, out degrees); result = GetSignSymbol(isNegative) + string.Format(Utilities.GetFormatString(1, decimalPlaces), degrees) + degreeSymbol ; } break; case AngleFormat.sDD: { bool isNegative; double degrees; Utilities.DegreesToD(decDegrees, out isNegative, out degrees); result = GetSignSymbol(isNegative) + string.Format(Utilities.GetFormatString(2, decimalPlaces), degrees) + degreeSymbol ; } break; case AngleFormat.sDM: { bool isNegative; int degrees; double minutes; Utilities.DegreesToDM(decDegrees, out isNegative, out degrees, out minutes); Utilities.Round(decimalPlaces, ref degrees, ref minutes); result = GetSignSymbol(isNegative) + string.Format(Utilities.GetFormatString(1, 0), degrees) + degreeSymbol + separator + string.Format(Utilities.GetFormatString(1, decimalPlaces), minutes) + minuteSymbol ; } break; case AngleFormat.sDDMM: { bool isNegative; int degrees; double minutes; Utilities.DegreesToDM(decDegrees, out isNegative, out degrees, out minutes); Utilities.Round(decimalPlaces, ref degrees, ref minutes); result = GetSignSymbol(isNegative) + string.Format(Utilities.GetFormatString(2, 0), degrees) + degreeSymbol + separator + string.Format(Utilities.GetFormatString(2, decimalPlaces), minutes) + minuteSymbol ; } break; case AngleFormat.sDMS: { bool isNegative; int degrees; int minutes; double seconds; Utilities.DegreesToDMS(decDegrees, out isNegative, out degrees, out minutes, out seconds); Utilities.Round(decimalPlaces, ref degrees, ref minutes, ref seconds); result = GetSignSymbol(isNegative) + string.Format(Utilities.GetFormatString(1, 0), degrees) + degreeSymbol + separator + string.Format(Utilities.GetFormatString(1, 0), minutes) + minuteSymbol + separator + string.Format(Utilities.GetFormatString(1, decimalPlaces), seconds) + secondsSymbol ; } break; case AngleFormat.sDDMMSS: { bool isNegative; int degrees; int minutes; double seconds; Utilities.DegreesToDMS(decDegrees, out isNegative, out degrees, out minutes, out seconds); Utilities.Round(decimalPlaces, ref degrees, ref minutes, ref seconds); result = GetSignSymbol(isNegative) + string.Format(Utilities.GetFormatString(2, 0), degrees) + degreeSymbol + separator + string.Format(Utilities.GetFormatString(2, 0), minutes) + minuteSymbol + separator + string.Format(Utilities.GetFormatString(2, decimalPlaces), seconds) + secondsSymbol ; } break; default: throw new NotSupportedException(angleFormat.ToString()); } return(result); }