Ejemplo n.º 1
0
        public long ProcessData2(string line)
        {
            // decoder 2
            if (string.IsNullOrWhiteSpace(line))
            {
                throw new ArgumentNullException(nameof(line));
            }

            if (line.StartsWith("mask = "))
            {
                // update the mask
                Mask      = line.Substring(7);
                MaskArray = Mask.ToCharArray();
                return(0);
            }
            // line of data
            var  parts = line.Split(new char[] { '=' });
            long mem   = long.Parse(parts[0].Replace("mem[", "").Replace("]", "").Trim());
            long value = long.Parse(parts[1].Trim());

            string bmem    = Convert.ToString(mem, 2).PadLeft(36).Replace(" ", "0");
            var    bmemarr = bmem.ToCharArray();
            int    len     = Math.Max(bmemarr.Length, MaskArray.Length);

            for (int i = 0; i < len; i++)
            {
                switch (MaskArray[i])
                {
                case '0':
                    // 0 don't change anything
                    break;

                case '1':
                    bmemarr[i] = '1';
                    break;

                default:
                    bmemarr[i] = 'X';
                    break;
                }
            }
            bmem = string.Join(null, bmemarr);
            var memArr = GenerateMemoryAddresses(bmem);

            foreach (var addr in memArr)
            {
                if (DockingData.ContainsKey(addr))
                {
                    DockingData[addr] = value;
                }
                else
                {
                    DockingData.Add(addr, value);
                }
            }
            return(value);
        }
Ejemplo n.º 2
0
        public long ProcessData(string line)
        {
            if (string.IsNullOrWhiteSpace(line))
            {
                throw new ArgumentNullException(nameof(line));
            }

            if (line.StartsWith("mask = "))
            {
                // update the mask
                Mask      = line.Substring(7);
                MaskArray = Mask.ToCharArray();
                return(0);
            }
            // line of data
            var    parts   = line.Split(new char[] { '=' });
            long   mem     = long.Parse(parts[0].Replace("mem[", "").Replace("]", "").Trim());
            long   value   = long.Parse(parts[1].Trim());
            string bval    = Convert.ToString(value, 2).PadLeft(36).Replace(" ", "0");
            var    bvalarr = bval.ToCharArray();
            int    len     = Math.Max(bvalarr.Length, MaskArray.Length);

            for (int i = 0; i < len; i++)
            {
                bvalarr[i] = MaskArray[i] == 'X' ? bvalarr[i] : MaskArray[i];
            }
            bval  = string.Join(null, bvalarr);
            value = Convert.ToInt64(bval, 2);
            if (DockingData.ContainsKey(mem))
            {
                DockingData[mem] = value;
            }
            else
            {
                DockingData.Add(mem, value);
            }
            return(value);
        }