Пример #1
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;
        }
Пример #2
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);
        }
Пример #3
0
        public void ReadXml(string filename)
        {
            if (!File.Exists(filename))
            {
                return;
            }
            XmlDocument doc = new XmlDocument();

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

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

            AREAsFromXml.Clear();
            foreach (XmlNode node in root.ChildNodes)
            {
                if (node.Name.ToLower() == "area")
                {
                    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;
                        }
                        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;

                        default:
                        {
                            System.Diagnostics.Debug.Assert(false);
                            break;
                        }
                        }
                        checkOder++;
                    }
                    this.CalculatedAreaHeader(ref sub);

                    this.AREAsFromXml.Add(sub);
                }
            }
        }