Beispiel #1
0
        public static void ResetBit(ref uint[] array, int bitIndex)
        {
            BitPosition position = bitIndex;

            GrowDynamically(ref array, bitIndex + 1);
            uint mask = (uint)((1 << position.BitIndex) ^ 0xFF);

            array[position.IntIndex] &= mask;
        }
Beispiel #2
0
            public override bool Equals(object obj)
            {
                BitPosition bitPos = obj as BitPosition;

                if (bitPos == null)
                {
                    return(false);
                }

                return(this == bitPos);
            }
 /// <inheritdoc />
 protected TypedBitsPlcItem
 (
     PlcItemType type,
     ushort dataBlock,
     ushort position,
     BitPosition bitPosition,
     byte bitAmount,
     bool isFlexible,
     TValue initialValue,
     string identifier = default
 )
     : base(type, dataBlock, position, bitPosition, bitAmount, isFlexible, initialValue, identifier)
 {
 }
Beispiel #4
0
        /// <summary>
        /// Shifts compelete entries of the array right.
        /// </summary>
        /// <param name="array"></param>
        /// <param name="steps"></param>
        private static void ShiftEntriesRight(ref uint[] array, int steps)
        {
            BitPosition position = FirstBitNotZeroIndex(array);

            for (int i = 0; i <= position.IntIndex; i++)
            {
                if (i + steps <= position.IntIndex)
                {
                    array[i] = array[i + steps];
                }
                else
                {
                    array[i] = 0;
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Shifts compelete entries of the array left.
        /// </summary>
        /// <param name="array"></param>
        /// <param name="steps"></param>
        private static void ShiftEntriesLeft(ref uint[] array, int steps)
        {
            BitPosition position = GetBitLength(array);

            GrowDynamically(ref array, position.RealBitIndex + (steps * IntegerBitCount) + 1);

            for (int i = position.IntIndex; i >= 0; i--)
            {
                array[i + steps] = array[i];

                if (i < steps)
                {
                    array[i] = 0;
                }
            }
        }
Beispiel #6
0
        public string ToBinaryString(int fixedDigits)
        {
            if (FirstBitNotZeroIndex(m_internalArray) == -1)
            {
                if (fixedDigits == 0)
                {
                    return(Zero);
                }
                else
                {
                    return(ZeroPadding("", fixedDigits));
                }
            }

            int spaceModulo = fixedDigits % ByteToBitMultiplier;
            int spaceCount  = fixedDigits / ByteToBitMultiplier - (fixedDigits % ByteToBitMultiplier == 0 ? 1 : 0);

            string result = "";

            for (int bitIndex = fixedDigits - 1; bitIndex >= 0; bitIndex--)
            {
                bool lastOrFirst = result.Length <= 0 || bitIndex <= 0;
                if ((fixedDigits - (bitIndex + 1)) % ByteToBitMultiplier == spaceModulo && !lastOrFirst)
                {
                    result += " ";
                }

                BitPosition bitPosition = new BitPosition(bitIndex);

                if (bitPosition.IntIndex >= m_internalArray.Length)
                {
                    result += Zero;
                }
                else if (bitIndex < 0)
                {
                    break;
                }
                else
                {
                    result += IsBitSet(bitIndex) ? One : Zero;
                }
            }

            return(SetStringFixedSize(result, fixedDigits + spaceCount));
        }
        /// <summary>
        /// Applies the <see cref="bool"/> array to the <paramref name="data"/>.
        /// </summary>
        /// <param name="data"> The extended <see cref="byte"/> array. </param>
        /// <param name="bytePosition"> The starting position at where to apply <paramref name="value"/>. </param>
        /// <param name="bitPosition"> A specific <see cref="BitPosition"/> at where to apply <paramref name="value"/>. </param>
        /// <param name="value"> The value to apply. </param>
        /// <returns> The same <paramref name="data"/> instance. </returns>
        public static byte[] ApplyValue(this byte[] data, ushort bytePosition, BitPosition bitPosition, bool[] value)
        {
            var offset = bytePosition * 8 + (int)bitPosition;

            if (offset + value.Length > data.Length * 8)
            {
                throw new ArgumentOutOfRangeException($"The combined length of byte position, bit position and the new values length with a total of {offset + value.Length} bits is outside of the data length of {data.Length * 8} bits.");
            }

            var currentBooleans = DataConverter.ToBooleans(data);

            for (var index = 0; index < value.Length; index++)
            {
                currentBooleans[index + offset] = value[index];
            }

            return(data.ApplyValue(0, DataConverter.ToBytes(currentBooleans)));
        }
Beispiel #8
0
        public string ToCsvLineString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendFormat(InternalID.ToString() + ",");
            stringBuilder.AppendFormat(Number.ToString() + ",");
            stringBuilder.AppendFormat(Name + ",");
            stringBuilder.AppendFormat(Description + ",");
            stringBuilder.AppendFormat(this.Value.ToString() + ",");
            stringBuilder.AppendFormat(AddPrefixOfZerosIfNeeded(Convert.ToString(m_binaryValue, 2)) + ",");
            stringBuilder.AppendFormat(BitPosition.ToString() + ",");
            stringBuilder.AppendFormat(Key + ",");
            if (ParentCircuitBreaker != null)
            {
                string substation = ParentCircuitBreaker.ParentSubstation.Name;
                string device     = ParentCircuitBreaker.Name;
                stringBuilder.AppendFormat($"{substation}_{device}{Environment.NewLine}");
            }
            else
            {
                stringBuilder.AppendFormat($"Unclaimed{Environment.NewLine}");
            }
            return(stringBuilder.ToString());
        }
 public ILengthPlcItemBuilder <TPlcItem, TValue> AtPosition(ushort bytePosition, BitPosition bitPosition)
 {
     this.Position    = bytePosition;
     this.BitPosition = bitPosition;
     return(this);
 }
Beispiel #10
0
 /// <inheritdoc />
 /// <summary>
 /// Constructor with initial value.
 /// </summary>
 public BitsPlcItem(PlcItemType type, ushort dataBlock, ushort position, BitPosition bitPosition, BitCollection initialValue, string identifier = default)
     : base(type, dataBlock, position, bitPosition, initialValue, identifier)
 {
 }
Beispiel #11
0
 /// <inheritdoc />
 /// <summary>
 /// Constructor with bit amount.
 /// </summary>
 public BitsPlcItem(PlcItemType type, ushort dataBlock, ushort position, BitPosition bitPosition, byte bitAmount, string identifier = default)
     : base(type, dataBlock, position, bitPosition, bitAmount, isFlexible: false, identifier: identifier)
 {
 }
Beispiel #12
0
 /// <summary>
 /// Constructor
 /// </summary>
 public BitPlcItem(PlcItemType type, ushort dataBlock, ushort position, BitPosition bitPosition, bool initialValue = default, string identifier = default)
     : base(type, dataBlock, position, bitPosition, bitAmount: 1, false, initialValue, identifier)
 {
 }
 private bool GetBit(BitPosition bit)
 {
     return BinaryHelper.CheckBit(this.ISR, (byte)bit);
 }
Beispiel #14
0
 /// <summary>
 /// Returns true if the bit with the zero based index "bitIndex" is set.
 /// </summary>
 /// <param name="bitIndex"></param>
 /// <returns></returns>
 public bool IsBitSet(int bitIndex)
 {
     return(IsBitSet(m_internalArray, BitPosition.GetBitIndex(bitIndex), BitPosition.GetIntIndex(bitIndex)));
 }
Beispiel #15
0
 public static bool IsBitInArraySet(uint[] array, int bitIndex)
 {
     return(IsBitSet(array, BitPosition.GetBitIndex(bitIndex), BitPosition.GetIntIndex(bitIndex)));
 }
 public new IBitsLengthPlcItemConstructor AtPosition(ushort bytePosition, BitPosition bitPosition) => (IBitsLengthPlcItemConstructor)base.AtPosition(bytePosition, bitPosition);
Beispiel #17
0
 /// <inheritdoc />
 /// <summary>
 /// Constructor for <see cref="PlcItemType.Data"/> <see cref="BitsPlcItem"/>s with bit amount.
 /// </summary>
 public BitsPlcItem(ushort dataBlock, ushort position, BitPosition bitPosition, byte bitAmount, string identifier = default)
     : this(PlcItemType.Data, dataBlock, position, bitPosition, bitAmount, identifier)
 {
 }
Beispiel #18
0
 private bool GetBit(BitPosition bit)
 {
     return(BinaryHelper.CheckBit(this.IMR, (byte)bit));
 }
Beispiel #19
0
 /// <inheritdoc />
 /// <summary>
 /// Constructor for <see cref="PlcItemType.Data"/> <see cref="BitPlcItem"/>s with bit amount.
 /// </summary>
 public BitPlcItem(ushort dataBlock, ushort position, BitPosition bitPosition, bool initialValue = default, string identifier = default)
     : this(PlcItemType.Data, dataBlock, position, bitPosition, initialValue, identifier)
 {
 }