示例#1
0
        public void CreateEEPROMPropsFromByteArr(PageDetails details, Dictionary <object, object> ByteArrDic, PropertyInfo[] pinf, object obj)
        {
            EEPROM_Props val = null;

            for (int i = 0; i < details.NumberOfStructures; i++)
            {
                StructureDetails structDetails = details.details[i];
                if (structDetails.NumberOfBytes == 0)
                {
                    object         result  = GetSettingsInstanceFromStructureType(structDetails.TypeOfStructure);
                    StrutureTypes  st      = (StrutureTypes)structDetails.TypeOfStructure;
                    byte[]         arr     = byteArrList[structDetails.StructStartPage];
                    PropertyInfo[] propInf = result.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
                    val             = EEPROM_Props.CreateIVLProperties(EEPROM_Type_Info.CreateEEPROM_TypeInfo(DataTypes.Tree, structDetails.TypeOfStructure), result);
                    val.name        = st.ToString();
                    val.text        = resourceManager.GetString(val.name);
                    val.PageDetails = GetPageDetailsFromByteArr(arr);
                    Dictionary <object, object> dic = new Dictionary <object, object>();
                    offset = 0;
                    CreateEEPROMPropsFromByteArr(val.PageDetails, dic, propInf, result);
                    ByteArrDic.Add(val, dic);
                }
                else
                {
                    val      = pinf[i].GetValue(obj) as EEPROM_Props;
                    val.name = pinf[i].Name;
                    val.text = resourceManager.GetString(val.name);
                    byte[] arr = new Byte[details.details[i].NumberOfBytes];

                    if (details.details[i].StuctNumberOfPages > 1)
                    {
                        byte[] byteArr1 = byteArrList[details.details[i].StructStartPage];
                        Array.Copy(byteArr1, offset, arr, 0, pageSize - offset);
                        byte[] byteArr2 = byteArrList[details.details[i].StructStartPage + 1];
                        Array.Copy(byteArr2, 0, arr, pageSize - offset, arr.Length - (pageSize - offset));
                    }
                    else
                    {
                        byteArr = byteArrList[details.details[i].StructStartPage];
                        Array.Copy(byteArr, offset, arr, 0, arr.Length);
                    }
                    val.GetValFromBytes(arr);
                    ByteArrDic.Add("EEPROM." + val.name, val);
                    offset += details.details[i].NumberOfBytes;
                    if (offset > pageSize)
                    {
                        offset = (byte)((int)offset - (int)pageSize);
                    }
                    else if (offset == pageSize)
                    {
                        offset = 0;
                    }
                }
            }
        }
示例#2
0
        public PageDetails GetPageDetailsFromByteArr(byte[] Arr)
        {
            PageDetails TempPageDetails = new PageDetails();

            TempPageDetails.NumberOfStructures = Arr[3];
            int indx = 4;

            for (int i = 0; i < TempPageDetails.NumberOfStructures; i++)
            {
                StructureDetails structDetails = new StructureDetails();
                structDetails.StructStartPage = Arr[indx];
                indx += (byte)(1);
                structDetails.StuctNumberOfPages = Arr[indx];
                indx += (byte)(1);
                structDetails.NumberOfBytes = Arr[indx];
                indx += (byte)(1);
                structDetails.TypeOfStructure = Arr[indx];
                indx += (byte)(1);
                TempPageDetails.details.Add(structDetails);
            }
            return(TempPageDetails);
        }
示例#3
0
        public void TraverseProperties(PropertyInfo[] finf, object obj, Dictionary <object, object> dic, PageDetails pageDetails, int byteArrIndx)
        {
            EEPROM_Props val = null;

            pageDetails.NumberOfStructures = (byte)finf.Length;
            numberOfbytes = 0;
            for (int i = 0; i < finf.Length; i++)
            {
                Type t = finf[i].PropertyType;
                if (t == typeof(EEPROM_Props))
                {
                    val      = finf[i].GetValue(obj) as EEPROM_Props;
                    val.name = finf[i].Name;
                    val.text = resourceManager.GetString(val.name);

                    if (val.eepromDataType.dataType == DataTypes.Tree)
                    {
                        offset          = 0;
                        val.PageDetails = new PageDetails();

                        StructureDetails structureDetails = new StructureDetails();

                        object         objProperty = GetSettingsInstanceFromStructureType(val.eepromDataType.length);
                        PropertyInfo[] pinf        = objProperty.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
                        val.PageDetails.NumberOfStructures = Convert.ToByte(pinf.Length);

                        Dictionary <object, Object> temp = new Dictionary <object, object>();
                        byteArr = new byte[pageSize];
                        byteArrList.Add(byteArr);
                        int index = byteArrList.Count - 1;
                        TraverseProperties(pinf, objProperty, temp, val.PageDetails, index);
                        byte[] tempArr = GetBytesFromPageDetails(val.PageDetails);
                        Array.Copy(tempArr, byteArrList[index], tempArr.Length);
                        structureDetails.StructStartPage = Convert.ToByte(index);
                        int pages = (int)GetNumberOfPages(val.PageDetails);

                        structureDetails.StuctNumberOfPages = (byte)(pages + 1);   // the + 1 is for pageDetails page.
                        structureDetails.TypeOfStructure    = val.eepromDataType.length;
                        pageDetails.details.Add(structureDetails);

                        dic.Add(val, temp);
                    }
                    else
                    {
                        dic.Add("EEPROM." + val.name, val);
                        byte[] arr    = val.GetBytesFromVal();
                        byte[] resArr = new byte[pageSize];
                        if (offset == 0)
                        {
                            byteArrList.Add(resArr);
                        }

                        StructureDetails structureDetails = new StructureDetails();

                        structureDetails.StructStartPage = (byte)(byteArrList.Count - 1);
                        //structureDetails.OffsetPageIndx = offset;
                        structureDetails.NumberOfBytes = Convert.ToByte(arr.Length);//+ (int) numberOfbytes);
                        numberOfbytes += structureDetails.NumberOfBytes;
                        float pagesInfloat = ((float)numberOfbytes / (float)pageSize);
                        if (pagesInfloat % 1 != 0)
                        {
                            pagesInfloat += 0.5f;
                        }
                        int pages = (int)Math.Round(pagesInfloat, MidpointRounding.AwayFromZero);
                        if (numberOfbytes > pageSize)
                        {
                            structureDetails.StuctNumberOfPages = Convert.ToByte(pages);
                            int pageOverFlow = (((int)structureDetails.StuctNumberOfPages - 1) * (int)pageSize);
                            pageOverFlow -= (int)offset;
                            numberOfbytes = 0;
                            byte[] arr1   = new byte[pageSize];
                            byte[] arr2   = new byte[pageSize];
                            int    index1 = pageSize - offset;
                            Array.Copy(arr, 0, byteArrList[byteArrList.Count - 1], offset, index1);
                            Array.Copy(arr, index1, arr2, 0, arr.Length - index1);
                            byteArrList.Add(arr2);
                            offset = Convert.ToByte((int)structureDetails.NumberOfBytes - pageOverFlow);
                        }
                        else
                        {
                            structureDetails.StuctNumberOfPages = 1;
                            byte[] arr1 = byteArrList[byteArrList.Count - 1];
                            Array.Copy(arr, 0, byteArrList[byteArrList.Count - 1], offset, arr.Length);
                            offset += structureDetails.NumberOfBytes;
                            if (numberOfbytes == pageSize)
                            {
                                numberOfbytes = 0;
                                offset        = 0;
                            }
                        }
                        pageDetails.details.Add(structureDetails);
                    }
                }
            }
        }