예제 #1
0
        public byte[] ToBytes()
        {
            var bytes = new byte[48];

            bytes.Initialize();

            bytes[0] = (byte)((uint)LI << 6 | (uint)VersionNumber << 3 | (uint)Mode);
            bytes[1] = Stratum;
            bytes[2] = PollInterval;
            bytes[3] = Precision;

            RootDelay.CopyTo(bytes, 4);
            RootDispersion.CopyTo(bytes, 8);
            ReferenceIdentifier.Select(c => (byte)c).ToArray().CopyTo(bytes, 12);
            ReferenceTimestamp.ToBytes().CopyTo(bytes, 16);
            OriginateTimestamp.ToBytes().CopyTo(bytes, 24);
            ReceiveTimestamp.ToBytes().CopyTo(bytes, 32);
            TransmitTimestamp.ToBytes().CopyTo(bytes, 40);

            return(bytes);
        }
예제 #2
0
        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            string str;

            str = "Leap Indicator: ";
            switch (LeapIndicator)
            {
            case LeapIndicator.NoWarning:
                str += "No warning";
                break;

            case LeapIndicator.LastMinute61:
                str += "Last minute has 61 seconds";
                break;

            case LeapIndicator.LastMinute59:
                str += "Last minute has 59 seconds";
                break;

            case LeapIndicator.Alarm:
                str += "Alarm Condition (clock not synchronized)";
                break;
            }
            str += "\r\nVersion number: " + VersionNumber.ToString() + "\r\n";
            str += "Mode: ";
            switch (Mode)
            {
            case NtpMode.Unknown:
                str += "Unknown";
                break;

            case NtpMode.SymmetricActive:
                str += "Symmetric Active";
                break;

            case NtpMode.SymmetricPassive:
                str += "Symmetric Pasive";
                break;

            case NtpMode.Client:
                str += "Client";
                break;

            case NtpMode.Server:
                str += "Server";
                break;

            case NtpMode.Broadcast:
                str += "Broadcast";
                break;
            }
            str += "\r\nStratum: ";
            switch (Stratum)
            {
            case NtpStratum.Unspecified:
            case NtpStratum.Reserved:
                str += "Unspecified";
                break;

            case NtpStratum.PrimaryReference:
                str += "Primary Reference";
                break;

            case NtpStratum.SecondaryReference:
                str += "Secondary Reference";
                break;
            }
            str += "\r\nOriginate (Send request): " + OriginateTimestamp.ToString("dd/MM/yyyy HH:mm:ss.fff");
            str += "\r\nRecieve (Server recieved): " + ReceiveTimestamp.ToString("dd/MM/yyyy HH:mm:ss.fff");
            str += "\r\nTransmit (Server reply): " + TransmitTimestamp.ToString("dd/MM/yyyy HH:mm:ss.fff");
            str += "\r\nReception (Request recieved): " + ReceptionTimestamp.ToString("dd/MM/yyyy HH:mm:ss.fff");
            str += "\r\nServer transmit time (Local zone): " + TransmitTimestamp.ToString("dd/MM/yyyy HH:mm:ss.fff");
            str += "\r\nPrecision: " + Precision.ToString() + " ms";
            str += "\r\nPoll Interval: " + PollInterval.ToString() + " s";
            str += "\r\nReference ID: " + ReferenceID.ToString();
            str += "\r\nRoot Dispersion: " + RootDispersion.ToString() + " ms";
            str += "\r\nRound Trip Delay: " + RoundTripDelay.TotalMilliseconds.ToString() + " ms";
            str += "\r\nLocal Clock Offset: " + LocalClockOffset.TotalMilliseconds.ToString() + " ms";
            str += "\r\n";

            return(str);
        }