예제 #1
0
        public void Test_GetBit()
        {
            Assert.AreEqual(1, BitmaskCore.GetBit(277, 0)); // 0b100010101
            Assert.AreEqual(0, BitmaskCore.GetBit(277, 1)); // 0b100010101
            Assert.AreEqual(1, BitmaskCore.GetBit(277, 2)); // 0b100010101
            Assert.AreEqual(0, BitmaskCore.GetBit(277, 3)); // 0b100010101
            Assert.AreEqual(1, BitmaskCore.GetBit(277, 4)); // 0b100010101
            Assert.AreEqual(0, BitmaskCore.GetBit(277, 5)); // 0b100010101

            Assert.AreEqual(0, BitmaskCore.GetBit(277, 7)); // 0b100010101
            Assert.AreEqual(1, BitmaskCore.GetBit(277, 8)); // 0b100010101
        }
예제 #2
0
        private AFValue Calculate(AFTime time, AFAttributeList inputAttributes, AFValues inputValues)
        {
            if (time == null)
            {
                throw new ArgumentException("No timestamp");
            }

            if (inputValues.Count == 0)
            {
                throw new ArgumentException(Resources.ERR_NoInputValues);
            }

            int bit;

            if (!int.TryParse(fBit, out bit))
            {
                throw new ArgumentException(Resources.ERR_NoBitSpecified);
            }

            if (bit < 0 || bit > (int)BitEnum.bit31)
            {
                throw new ArgumentException(Resources.ERR_InvalidBit);
            }

            AFValue inVal  = inputValues[0];
            object  objVal = inVal.Value;

            if (inVal.IsGood && objVal != null)
            {
                if (BitmaskCore.IsIntVal(objVal))
                {
                    ulong curVal  = (ulong)BitmaskCore.ConvertToType(objVal, TypeCode.UInt64);
                    int   tempVal = BitmaskCore.GetBit(curVal, (byte)bit);
                    return(new AFValue(base.Attribute, tempVal, inVal.Timestamp, Attribute.DefaultUOM));
                }
                else
                {
                    throw new ArgumentException(Resources.ERR_SourceAttributeMustBeAnIntegerType);
                }
            }
            else
            {
                return(AFValue.CreateSystemStateValue(Attribute, AFSystemStateCode.BadInput, inVal.Timestamp));
            }
        }
        private void ProcessAttributes(AFAttributeTemplates attributes, string prefix)
        {
            foreach (AFAttributeTemplate attr in attributes)
            {
                if (attr == dataReference.Attribute)
                {
                    continue;
                }

                string attrName = prefix + "|" + attr.Name;

                if (BitmaskCore.IsIntVal(attr.Type))
                {
                    txtAttribute.Items.Add(attrName);
                }

                ProcessAttributes(attr.AttributeTemplates, attrName);
            }
        }