Esempio n. 1
0
 public unsafe byte[] GetAreaDataBuffer(AREA area)
 {
     byte[] map2Datas = null;
     if (area.type == AREA_Type.map3)
     {
         foreach (MAP_3_Item map3 in area.Items)
         {
             map2Datas = this.GetDatesBuffer(map3.CommondItem);
         }
     }
     return(map2Datas);
 }
Esempio n. 2
0
        unsafe private void CalculatedAreaHeader(ref AREA area)
        {
            if (area.type == AREA_Type.map1)
            {
                area.AreaHeader.TableNumber = (byte)area.Items.Count;

                int totalItemSize = 0;
                foreach (MAP_1_Item item in area.Items)
                {
                    totalItemSize += this.GetTypeSize(item.CommondItem.ItemType) * item.CommondItem.Data.Length + MAP_HEADER_SIZE;
                }
                area.AreaHeader.Size = (short)(sizeof(HEADER_S) + totalItemSize);
            }
            else if (area.type == AREA_Type.map2)
            {
                area.AreaHeader.TableNumber = (byte)area.Items.Count;

                int totalItemSize = 0;
                foreach (MAP_2_Item item in area.Items)
                {
                    totalItemSize += this.GetTypeSize(item.CommondItem.ItemType) * item.CommondItem.Data.Length + MAP_HEADER_SIZE;
                }
                area.AreaHeader.Size = (short)(sizeof(HEADER_S) + totalItemSize);
            }
            else
            {
                area.AreaHeader.TableNumber = 0;
                int totalItemSize = 0;
                foreach (CommondItem item in area.Items)
                {
                    totalItemSize += this.GetTypeSize(item.ItemType) * item.Data.Length;
                }
                area.AreaHeader.Size = (short)(sizeof(HEADER_S) + totalItemSize);
            }

            //area.AreaHeader.Checksum1 += area.AreaHeader.Reserve;
            //area.AreaHeader.Checksum1 += area.AreaHeader.TableNumber;
            //area.AreaHeader.Checksum1 += area.AreaHeader.Size;

            //area.AreaHeader.Checksum2 ^= area.AreaHeader.Reserve;
            //area.AreaHeader.Checksum2 ^= area.AreaHeader.TableNumber;
            //area.AreaHeader.Checksum2 ^= area.AreaHeader.Size;
        }
Esempio n. 3
0
        unsafe public byte[] GetAREABuffer(AREA area)
        {
            int AllSize = area.AreaHeader.Size;

            byte[] AreaBuffer = new byte[AllSize];
            int    i          = 0;

            byte[] areaheader1 = area.AreaHeader.GetAreaHeader(); //俩个checknum先按0计算
            for (int j = 0; j < areaheader1.Length; j++)
            {
                AreaBuffer[i++] = areaheader1[j];
            }

            short offset = (short)(sizeof(HEADER_S) + area.Items.Count * MAP_HEADER_SIZE);

            switch (area.type)
            {
            case AREA_Type.none:
                foreach (CommondItem comm in area.Items)
                {
                    byte[] commDatas = this.GetDatesBuffer(comm);
                    for (int j = 0; j < commDatas.Length; j++)
                    {
                        AreaBuffer[i++] = commDatas[j];
                    }
                }
                break;

            case AREA_Type.map1:
                foreach (MAP_1_Item map1 in area.Items)
                {
                    byte[] maphead = map1.GetMapHeader(MAP_1_MARK, offset);
                    for (int j = 0; j < maphead.Length; j++)
                    {
                        AreaBuffer[i++] = maphead[j];
                    }
                    offset += map1.CommondItem.realLen;
                }
                foreach (MAP_1_Item map1 in area.Items)
                {
                    byte[] map1Datas = this.GetDatesBuffer(map1.CommondItem);
                    for (int j = 0; j < map1Datas.Length; j++)
                    {
                        AreaBuffer[i++] = map1Datas[j];
                    }
                }
                break;

            case AREA_Type.map2:
                foreach (MAP_2_Item map2 in area.Items)
                {
                    byte[] maphead = map2.GetMapHeader(MAP_2_MARK, offset);
                    for (int j = 0; j < maphead.Length; j++)
                    {
                        AreaBuffer[i++] = maphead[j];
                    }
                    offset += map2.CommondItem.realLen;
                }
                foreach (MAP_2_Item map2 in area.Items)
                {
                    byte[] map2Datas = this.GetDatesBuffer(map2.CommondItem);
                    for (int j = 0; j < map2Datas.Length; j++)
                    {
                        AreaBuffer[i++] = map2Datas[j];
                    }
                }
                break;

            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }

            for (int m = 4; m < AreaBuffer.Length; m++)
            {
                area.AreaHeader.Checksum1 += AreaBuffer[m];
                area.AreaHeader.Checksum2 ^= AreaBuffer[m];
            }

            i = 0;
            byte[] areaheader2 = area.AreaHeader.GetAreaHeader(); //计算checknum后重写areaheader
            for (int j = 0; j < areaheader2.Length; j++)
            {
                AreaBuffer[i++] = areaheader2[j];
            }

            return(AreaBuffer);
        }
Esempio n. 4
0
        public unsafe byte[] GetWaveformAreaBuffer(AREA area)
        {
            List <byte> val         = new List <byte>();
            int         nStartIndex = 0;

            switch (area.type)
            {
            case AREA_Type.map3:
                foreach (MAP_3_Item map3 in area.Items)
                {
                    byte[] body = new byte[map3.CommondItem.downWave.len];
                    map3.CommondItem.downWave.len += 2;    //crc size
                    Int32  size   = Marshal.SizeOf(typeof(MyStruct));
                    IntPtr buffer = Marshal.AllocHGlobal(size);
                    Marshal.WriteByte(buffer, 0);
                    Marshal.StructureToPtr(map3.CommondItem.downWave, buffer, true);
                    byte[] header     = new byte[size];
                    byte[] contenData = new byte[map3.CommondItem.charData.Length];
                    for (int i = 0; i < contenData.Length; i++)
                    {
                        contenData[i] = (byte)map3.CommondItem.charData[i];
                    }
                    Marshal.Copy(buffer, header, nStartIndex, size);
                    Marshal.Copy(buffer, body, nStartIndex, size);
                    Array.Copy(contenData, 0, body, size, map3.CommondItem.charData.Length);
                    val.AddRange(header);
                    val.AddRange(contenData);
                    val.AddRange(System.BitConverter.GetBytes((short)CoreInterface.Crc16(body, (ushort)(body.Length))));
                }
                break;

            case AREA_Type.map4:
                foreach (MAP_4_Item map4 in area.Items)
                {
                    byte[] body = new byte[map4.CommondItem.downWave.len];
                    map4.CommondItem.downWave.len += 2;    //crc size
                    Int32  size   = Marshal.SizeOf(typeof(MyStruct));
                    IntPtr buffer = Marshal.AllocHGlobal(size);
                    Marshal.WriteByte(buffer, 0);
                    Marshal.StructureToPtr(map4.CommondItem.downWave, buffer, true);
                    byte[] header     = new byte[size];
                    byte[] contenData = new byte[map4.CommondItem.shortData.Length * 2];
                    for (int i = 0; i < map4.CommondItem.shortData.Length; i++)
                    {
                        byte[] pByte = BitConverter.GetBytes(map4.CommondItem.shortData[i]);
                        if (null != pByte)
                        {
                            contenData[2 * i]     = pByte[0];
                            contenData[i * 2 + 1] = pByte[1];
                        }
                    }
                    Marshal.Copy(buffer, header, nStartIndex, size);
                    Marshal.Copy(buffer, body, nStartIndex, size);
                    Array.Copy(contenData, 0, body, size, map4.CommondItem.shortData.Length * 2);
                    val.AddRange(header);
                    val.AddRange(contenData);
                    val.AddRange(System.BitConverter.GetBytes((short)CoreInterface.Crc16(body, (ushort)(body.Length))));
                }
                break;

            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }
            return(val.ToArray());
        }
Esempio n. 5
0
        public void ReadXml(string filename)
        {
            if (!File.Exists(filename))
            {
                return;
            }

            if (this.ReadStatusChanged != null)
            {
                this.ReadStatusChanged(this, strRead_start);
            }

            SelfcheckXmlDocument doc = new SelfcheckXmlDocument();

            doc.Load(filename);
            XmlNode root = doc.FirstChild;

            foreach (XmlNode subnode in doc.ChildNodes)
            {
                if (subnode.Name.ToLower() == "headboardeepromdata")
                {
                    root = subnode;
                }
            }

            AREAsFromXml.Clear();
            AreaIndex = 0;
            foreach (XmlNode node in root.ChildNodes)
            {
                if (node.Name.ToLower() == "area")
                {
                    AreaIndex++;
                    AREA sub = new AREA(null);
                    foreach (XmlAttribute attr in node.Attributes)
                    {
                        if (attr.Name.ToLower() == "name")
                        {
                            sub.Name = attr.Value;
                        }
                        else if (attr.Name.ToLower() == "type")
                        {
                            sub.type = Get_AREA_Type(attr.Value.ToLower());
                        }
                        else if (attr.Name.ToLower() == "addr")
                        {
                            sub.ADDR = (short)GetValueByStr(attr.Value);
                        }
                    }

                    int   checkOder  = 0;
                    short AddrOffset = sub.ADDR;
                    foreach (XmlNode item in node.ChildNodes)
                    {
                        if (item.Name.ToLower() != "item")
                        {
                            continue;
                        }
                        else
                        {
                            SubItemIndex++;
                        }
                        if (this.ReadStatusChanged != null)
                        {
                            this.ReadStatusChanged(this, string.Format(strRead_Commond, AreaIndex.ToString(), sub.type.ToString(), SubItemIndex.ToString()));
                        }
                        switch (sub.type)
                        {
                        case AREA_Type.none:
                            sub.Items.Add(this.Get_CommondItem(item, checkOder));    //, ref AddrOffset));
                            break;

                        case AREA_Type.map1:
                            sub.Items.Add(this.Get_MAP_1_Item(item, checkOder));    //, ref AddrOffset));
                            break;

                        case AREA_Type.map2:
                            sub.Items.Add(this.Get_MAP_2_Item(item, checkOder));    //, ref AddrOffset));
                            break;

                        case AREA_Type.map3:
                            sub.Items.Add(this.Get_MAP_3_Item(item, checkOder));    //, ref AddrOffset));
                            break;

                        case AREA_Type.map4:
                            sub.Items.Add(this.Get_MAP_4_Item(item, checkOder));    //, ref AddrOffset));
                            break;

                        default:
                        {
                            System.Diagnostics.Debug.Assert(false);
                            break;
                        }
                        }
                        checkOder++;
                    }
                    if (sub.type != AREA_Type.map3 && sub.type != AREA_Type.map4)
                    {
                        this.CalculatedAreaHeader(ref sub);
                    }
                    this.AREAsFromXml.Add(sub);
                }
            }
            if (this.ReadStatusChanged != null)
            {
                this.ReadStatusChanged(this, strRead_end);
            }
        }