Ejemplo n.º 1
0
        /*
         * start, column number,
         * loc, byte loc in column
         * datalength total lungth;
         */
        public void DrawLine(double start, int datalength, byte[] value, double basewidth, DataCell nextCell)
        {
            double xgap = basewidth / (8 * 2);
            double x;
            double address;

            Console.WriteLine("start" + start + "datalength:" + datalength);
            for (int k = 0; k < datalength; k++)
            {
                address = 0.5 + start * basewidth + k * basewidth;
                chartForm2.L05Add(address, value[k].ToString("X2"));

                if (L1Control[(int)start + k] != 0)
                {
                    for (int i = 0; i < 16; i++)
                    {
                        // byte j = (byte)((byte)(k << (7 - i))>>7);
                        byte j = Utils.getbitValue(value[k], (byte)(7 - (i / 2)));//i=2468
                        byte m;
                        if (j == 0x01)
                        {
                            m = 0x00;
                        }
                        else
                        {
                            m = 0x01;
                        }

                        x = start * basewidth + k * 16.0 * xgap + (i) * xgap;
                        chartForm2.L1Add(x, j, " ");
                        chartForm2.L15Add(x, m, " ");
                        //Console.WriteLine(">>:" + i.ToString() + "值:" + j + "dboult:" + x);

                        i++;
                        x = start * basewidth + k * 16 * xgap + (i) * xgap;
                        if (j == 0x01)
                        {
                            j = 0x00;
                        }
                        if (m == 0x01)
                        {
                            m = 0x00;
                        }
                        chartForm2.L1Add(x, j, " ");
                        chartForm2.L15Add(x, m, " ");
                        //Console.WriteLine(">>:" + i.ToString() + "值:" + j + "dboult:" + x);
                    }
                }
                else
                {
                    chartForm2.L1Add(start + k, 0, "01");
                    chartForm2.L15Add(start + k, 1, "01");
                }
            }
            if (nextCell != null)
            {
                int addgap = nextCell.address - (int)start - datalength;
                if (addgap > 0)
                {
                    int k = (int)start + datalength;
                    for (; k < nextCell.address; k++)
                    {
                        if (L1Control[k] == 1)
                        {
                            chartForm2.L1Add(k, 1, "01");
                            chartForm2.L15Add(k, 0, "01");
                        }
                    }
                }
            }


            //补齐高位
        }
Ejemplo n.º 2
0
        /*
         * Receiver数据解包
         */
        public static ArrayList Downunpackdata(byte[] data, ulong length)
        {
            int       line;
            int       loc        = 0;
            int       datalength = 0;
            int       lLen       = (int)length;
            ArrayList datavalue  = new ArrayList();
            int       i          = FindDownHeader(data, (int)length);

            if (i < 0)
            {
                updateErrorListCallback("no header found");
                return(null);
            }
            i = i + 3;
            for (int r = 0; r < TOTALADDRES; r++)
            {
                L1Control[r] = 0x01;
            }
            L1Data = new ArrayList();
            //dumpdata(data, length, "recev");
            Console.WriteLine("header end loc" + i);
            String log = "";

            for ( ; i < (int)length - 10; i++)
            {
                line = data[i];
                if (line < 0x31 || line > 0x36)
                {
                    i = FindeNewFrame(data, i, (int)length);
                    if (i < lLen)
                    {
                        line = data[i];
                        updateErrorListCallback("数据错误 line");
                    }
                    else
                    {
                        updateErrorListCallback("数据错误 line 退出");
                        return(datavalue);
                    }
                }
                DataCell cell = new DataCell();
                cell.line = line;

                //Console.WriteLine("Line=" + data[i]);
                i++;
                log = data[i].ToString("X2");
                loc = loc + data[i] * 256 * 256 * 256;
                i++;
                log = log + data[i].ToString("X2");
                loc = loc + data[i] * 256 * 256;
                i++;
                log = log + data[i].ToString("X2");
                loc = loc + data[i] * 256;
                i++;
                log = log + data[i].ToString("X2");
                loc = loc + data[i];
                i++;
                cell.address = loc;
                log          = data[i].ToString("X2");
                datalength   = datalength + data[i] * 256 * 256 * 256;
                i++;
                log        = log + data[i].ToString("X2");
                datalength = datalength + data[i] * 256 * 256;
                i++;
                log        = log + data[i].ToString("X2");
                datalength = datalength + data[i] * 256;
                i++;
                log        = log + data[i].ToString("X2");
                datalength = datalength + data[i];
                i++;
                if (datalength + i > lLen || datalength < 0)
                {
                    updateErrorListCallback("数据长度错误丢弃");

                    continue;
                }
                cell.datalength = datalength;

                //Console.WriteLine("datalengt:"+log);
                // Console.WriteLine("datalenght" + datalength);
                int c = i;
                int j = 0;
                cell.data = new byte[datalength];
                String valuestr = " ";

                for (; i < c + datalength; i++)
                {
                    //Console.Write(data[i].ToString("X2"));

                    // Console.Write(" ");
                    if (line != 0x31)
                    {
                        L1Control[cell.address + j] = 0;
                    }
                    valuestr = valuestr + data[i].ToString("X2") + " ";


                    cell.data[j] = data[i];
                    j++;
                }

                //Console.WriteLine(" ");

                //showvalue(line, loc, valuestr);
                byte crcres = CRCSUM(cell.data, (int)datalength);
                Console.WriteLine("CRC1" + data[i].ToString("X2") + "res:" + crcres.ToString("X2"));
                //updateErrorListCallback("CRC1" + data[i].ToString("X2") + "res:" + crcres.ToString("X2"));
                if (crcres == data[i])
                {
                    if (line == 0x31)
                    {
                        L1Data.Add(cell);
                    }
                    else
                    {
                        datavalue.Add(cell);
                    }


                    i++;
                    i = i + 2;
                    //Console.WriteLine("******************************" + i);
                    datalength = 0;
                    loc        = 0;
                    //updateErrorListCallback("Data Added");
                }
                else
                {
                    if (line == 0x31)
                    {
                        L1Data.Add(cell);
                    }
                    else
                    {
                        datavalue.Add(cell);
                    }
                    Console.WriteLine("CRCWRONG");
                    //updateErrorListCallback("Data Added with CRCERROR");
                    i++;
                    i = i + 2;
                    //Console.WriteLine("******************************" + i);
                    datalength = 0;
                    loc        = 0;
                }
            }
            return(datavalue);
        }
Ejemplo n.º 3
0
        /*
         * 显示数据
         */
        private void DrawItems(ArrayList datalist)
        {
            DataCell cell       = new DataCell();
            double   basewidth  = 1;
            double   basewidth2 = 0.25;
            double   address    = 0.0;

            for (int linc = 0; linc < L1Data.Count; linc++)
            {
                cell = (DataCell)L1Data[linc];
                if (linc + 1 < L1Data.Count)
                {
                    DrawLine(cell.address, cell.datalength, cell.data, basewidth, (DataCell)L1Data[linc + 1]);
                }
                else
                {
                    DrawLine(cell.address, cell.datalength, cell.data, basewidth, null);
                }
            }

            for (int i = 0; i < datalist.Count; i++)
            {
                cell = (DataCell)datalist[i];
                //updatelabelfunc(cell);
                String v = Utils.HextString(cell.data, cell.datalength, true);
                int    j;
                switch (cell.line)
                {
                case 0x31:
                    //cell.data[3] = 0x03;


                    Console.WriteLine("Line1 address" + cell.address);
                    break;

                case 0x32:
                    for (j = 0; j < cell.datalength; j++)
                    {
                        address = cell.address * basewidth2 + j * basewidth2;
                        chartForm2.L2Add(address, cell.data[j].ToString("X2"));
                    }

                    Console.WriteLine("Line2 address" + address);
                    break;

                case 0x33:
                    for (j = 0; j < cell.datalength; j++)
                    {
                        address = cell.address * basewidth2 + j * basewidth2;
                        chartForm2.L3Add(address, cell.data[j].ToString("X2"));
                    }
                    Console.WriteLine("Line3 address" + cell.address);
                    break;

                case 0x34:
                    for (j = 0; j < cell.datalength; j++)
                    {
                        address = cell.address * basewidth2 + j * basewidth2;
                        chartForm2.L4Add(address, cell.data[j].ToString("X2"));
                    }
                    Console.WriteLine("Line4 address" + cell.address);
                    break;

                case 0x35:
                    for (j = 0; j < cell.datalength; j++)
                    {
                        address = cell.address * basewidth2 + j * basewidth2;
                        chartForm2.L5Add(address, cell.data[j].ToString("X2"));
                    }
                    Console.WriteLine("Line5 address" + cell.address);
                    break;
                }
            }

            m_totalPoints = (ulong)cell.address + (ulong)cell.datalength;
        }