Пример #1
0
        private static void IncrementTargetValue(Parameter clone)
        {
            if (clone.TagId == ParameterTagId.ServerId)
            {
                var bytesStr = clone.TargetValue.Split('-');
                var bytes = bytesStr.Reverse().Take(4).Select(s => Convert.ToByte(s, 16)).ToArray();
                var val = BitConverter.ToInt32(bytes, 0);
                val++;
                bytes = BitConverter.GetBytes(val).Reverse().ToArray();
                bytesStr[bytesStr.Length - 1] = $"{bytes[3]:X2}";
                bytesStr[bytesStr.Length - 2] = $"{bytes[2]:X2}";
                bytesStr[bytesStr.Length - 3] = $"{bytes[1]:X2}";
                bytesStr[bytesStr.Length - 4] = $"{bytes[0]:X2}";

                clone.TargetValue = string.Join("-", bytesStr);
            }
            else
            {
                long tmp;
                if (long.TryParse(clone.TargetValue, out tmp))
                {
                    tmp++;
                    clone.TargetValue = $"{tmp:D8}";
                }
            }
        }
Пример #2
0
        public Parameter GetClone()
        {
            var clone = new Parameter()
            {
                Name = this.Name,
                ObisCode = this.ObisCode,
                TargetValue = this.TargetValue,
                TagId = this.TagId,
                IsActive = this.IsActive,
                IsAutoIncrement = this.IsAutoIncrement,
                IsPartOfMatrixCode = this.IsPartOfMatrixCode,
                IsWriteOnly = this.IsWriteOnly,
                IsReadOnly = this.IsReadOnly,
                IsNameplateOnly = this.IsNameplateOnly,
                IsRandomTargetValue = this.IsRandomTargetValue,
                ModifiedAt = new DateTime(1900, 1, 1),
                CreatedAt = DateTime.Now
            };

            return clone;
        }
Пример #3
0
        private static void RandomizeTargetValue(Parameter param)
        {

            if (param.TagId == ParameterTagId.InitialKeyM)
            {
                var buffer = new byte[16];
                Rnd.NextBytes(buffer);
                param.TargetValue = buffer.AsHexString("-");
            }
            else
            {
                param.TargetValue = $"{Rnd.Next(1, 9999):D4}";
            }
        }