示例#1
0
        public void Save(BinaryWriter b)
        {
            _comment = "Merthsoft Token IDE";
            List <byte> buffer = new List <byte>();

            #region Gen buffer
            #region Header
            List <byte> headerBuffer = new List <byte>();
            // Header section
            headerBuffer.AddRange(_sigArray);
            headerBuffer.AddRange(_fsigArray);
            headerBuffer.AddRange(Comment.ToByteArray(42));
            headerBuffer.AddRange(((short)(Length - 57)).GetBytes());
            #endregion

            #region Data
            List <byte> dataBuffer = new List <byte>();
            // Data section
            dataBuffer.AddRange(_flag1);
            dataBuffer.AddRange(DataLength.GetBytes());
            dataBuffer.Add((byte)ID);
            dataBuffer.AddRange(Name.ToByteArray(8));
            dataBuffer.Add(0);
            dataBuffer.Add(_archFlag);
            dataBuffer.AddRange(DataLength.GetBytes());
            dataBuffer.AddRange(_data.FullData);
            #endregion
            buffer.AddRange(headerBuffer);
            buffer.AddRange(dataBuffer);
            //buffer.AddRange(BitConverter.GetBytes(dataBuffer.ToArray().Checksum()));
            buffer.AddRange(dataBuffer.ToArray().Checksum().GetBytes());
            #endregion
            b.Write(buffer.ToArray());
        }
        private DataLength GetDataLength(string type, ref Utf8JsonReader reader)
        {
            var retVal = new DataLength
            {
                IsVariable = type == Variable
            };

            reader.Read();
            if (reader.TokenType == JsonTokenType.Number)
            {
                retVal.Length = reader.GetInt32();
            }

            return(retVal);
        }
示例#3
0
 public byte[] ToBytes()
 {
     byte[] bytes;
     if (Data != null)
     {
         bytes = new byte[Data.Length + 4];
         bytes.Fill(DataLength.ToBytes(), 0);
         bytes.Fill(ProtocolID.ToBytes(), 2);
         bytes.Fill(Data, 4);
     }
     else
     {
         bytes = new byte[4];
         bytes.Fill(DataLength.ToBytes(), 0);
         bytes.Fill(ProtocolID.ToBytes(), 2);
     }
     return(bytes);
 }
        /// <summary>
        /// Parses this instance.
        /// </summary>
        /// <returns>bytes count of the data used to build the tagged object.</returns>
        private int Parse()
        {
            var result = TlvDecoder.Decode(RawData);

            Tag = new DataTag()
            {
                FullTagValue = result.Tag,
                Length       = result.Tag.Length
            };

            workloadShift  = Tag.Length;
            workloadShift += result.LengthLength;
            workloadLength = (int)result.Length;

            Length = new DataLength()
            {
                Value  = (int)result.Length,
                Length = result.LengthLength
            };

            return(Tag.Length + Length.Length + Length.Value);
        }
示例#5
0
文件: Lcd.cs 项目: josemotta/Netduino
        /// <summary>
        /// Sets interface data length (DL), number of display lines (N), and character font (F).
        /// </summary>
        /// <param name="characterFont">Character font</param>
        /// <param name="lines">Number of display lines</param>
        /// <param name="dataLength">Interface data length</param>
        private void FunctionSet(CharacterFont characterFont, byte lines, DataLength dataLength)
        {
            //  DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
            //  0   0   1   DL  N   F   -   -

            byte funcSetCmd = FUNCTION_SET;

            // char font 5x10 dots
            if (characterFont == CharacterFont.Dots5x10)
            {
                funcSetCmd |= CHAR_FONT_5x10DOTS;
            }

            // max two display lines
            funcSetCmd |= (lines > 1) ? DISPLAY_LINES_2LINE : DISPLAY_LINES_1LINE;

            // 8 bit data length
            if (dataLength == DataLength.DataBit8)
            {
                funcSetCmd |= DATA_LENGTH_8BIT;
            }

            this.SendCommand(funcSetCmd); // 37 us (datasheet)
        }
示例#6
0
        /// <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>
        /// Parses this instance.
        /// </summary>
        /// <returns>bytes count of the data used to build the tagged object.</returns>
        private int Parse()
        {
            var result = TlvDecoder.Decode(RawData);
            Tag = new DataTag()
            {
                FullTagValue = result.Tag,
                Length = result.Tag.Length
            };

            workloadShift = Tag.Length;
            workloadShift += result.LengthLength;
            workloadLength = (int)result.Length;

            Length = new DataLength()
            {
                Value = (int)result.Length,
                Length = result.LengthLength
            };

            return Tag.Length + Length.Length + Length.Value;
        }
示例#8
0
 public override string ToString()
 {
     return(StructureNameHash.ToString() + ": " + DataPointer.ToString() + " (" + DataLength.ToString() + ")");
 }
示例#9
0
 public DataLengthAttribute(DataLength length)
 {
     Length = (int)length;
 }
示例#10
0
 public DataLengthAttribute(int minimum, DataLength maximum)
     : this(minimum)
 {
     MaximumLength = (int)maximum;
 }
示例#11
0
        /// <summary>
        /// Sets interface data length (DL), number of display lines (N), and character font (F).
        /// </summary>
        /// <param name="characterFont">Character font</param>
        /// <param name="lines">Number of display lines</param>
        /// <param name="dataLength">Interface data length</param>
        private void FunctionSet(CharacterFont characterFont, byte lines, DataLength dataLength)
        {
            //  DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
            //  0   0   1   DL  N   F   -   -

            byte funcSetCmd = FUNCTION_SET;

            // char font 5x10 dots
            if (characterFont == CharacterFont.Dots5x10)
                funcSetCmd |= CHAR_FONT_5x10DOTS;

            // max two display lines
            funcSetCmd |= (lines > 1) ? DISPLAY_LINES_2LINE : DISPLAY_LINES_1LINE;

            // 8 bit data length
            if (dataLength == DataLength.DataBit8)
                funcSetCmd |= DATA_LENGTH_8BIT;

            this.SendCommand(funcSetCmd); // 37 us (datasheet)
        }
 public Compressed(DataLength dataLength, CompressedHeader header, CompressedData data) : base(dataLength)
 {
     this.Header = header;
     this.Data   = data;
 }
示例#13
0
 protected MetaBlock(DataLength dataLength)
 {
     this.DataLength = dataLength;
 }
示例#14
0
 public ReadContext(BrotliGlobalState state, DataLength dataLength)
 {
     this.State      = state;
     this.DataLength = dataLength;
 }
示例#15
0
 public Context(CompressedHeader header, DataLength dataLength, BrotliGlobalState state)
 {
     this.Header     = header;
     this.DataLength = dataLength;
     this.State      = state;
 }