Esempio n. 1
0
        private bool prepareToSave(
			ref InfoApp infoApp,
			bool compile,
			RichTextBox textCompile,
			SaveToFileData data
			)
        {
            infoApp.IsPotrait = (byte)(IsPotrait ? 1 : 0);
            infoApp.ScreenWidth = (IsPotrait ? LcdHeight : LcdWidth);
            infoApp.ScreenHeight = (IsPotrait ? LcdWidth : LcdHeight);

            bool success = true;
            ushort customDataLength = 0;
            OverBytes = Utility.ToBytes((uint)customDataLength);

            if (compile)
            {
                for (int idxPage = 0; idxPage < HmiPages.Count; idxPage++)
                {
                    HmiPage hmiPage = HmiPages[idxPage];
                    for (int idxObj = 0; idxObj < hmiPage.HmiObjects.Count; ++idxObj)
                    {
                        HmiObject hmiObj = hmiPage.HmiObjects[idxObj];

                        hmiObj.ObjInfo.ObjType = hmiObj.Attributes[0].Data[0];
                        hmiObj.ObjInfo.IsCustomData = hmiObj.Attributes[1].Data[0];

                        if (hmiObj.ObjInfo.IsCustomData == 1)
                        {
                            hmiObj.ObjInfo.AttributeStart = customDataLength;
                            int objRambytes = hmiObj.GetObjRamBytes(ref OverBytes, customDataLength);
                            if (objRambytes != 0)
                            {
                                hmiObj.ObjInfo.AttributeLength = (ushort)objRambytes;
                                customDataLength += hmiObj.ObjInfo.AttributeLength;
                            }
                        }
                    }
                }
            }
            addString(OverBytes, data);

            List<byte[]> bts = new List<byte[]>();
            for (int idxPage = 0; idxPage < HmiPages.Count; idxPage++)
            {
                HmiPage hmiPage = HmiPages[idxPage];

                if (compile && !hmiPage.Compile(textCompile))
                    success = false;
                else
                {
                    Application.DoEvents();

                    InfoPage infoPage = new InfoPage
                    {
                        ObjCount = (byte)hmiPage.HmiObjects.Count,
                        Name = Utility.ToStruct<InfoName>(Utility.ToBytes(hmiPage.Name, 14))
                    };
                    if (infoPage.ObjCount > 0)
                    {
                        infoPage.ObjStart = (ushort)data.m_infoObjects.Count;

                        for (int idxObj = 0; idxObj < hmiPage.HmiObjects.Count; idxObj++)
                        {
                            HmiObject hmiObj = hmiPage.HmiObjects[idxObj];
                            hmiObj.ObjInfo.Name = Utility.ToStruct<InfoName>(Utility.ToBytes(hmiObj.ObjName, 14));
                            bts.Clear();
                            if (compile)
                                hmiObj.CompileCodes(bts);
                            else
                                hmiObj.GetCodes(bts);

                            if (bts.Count > 0)
                            {
                                hmiObj.ObjInfo.StringInfoStart = (ushort)data.m_infoStrings.Count;
                                for (int k = 0; k < bts.Count; k++)
                                    addString(bts[k], data);

                                hmiObj.ObjInfo.StringInfoEnd = (ushort)((hmiObj.ObjInfo.StringInfoStart + bts.Count) - 1);
                            }
                            else
                            {
                                MessageBox.Show("Detect the component code is 0, error will occur when save the source file".Translate());
                                hmiObj.ObjInfo.StringInfoStart = 0xffff;
                                hmiObj.ObjInfo.StringInfoEnd = 0xffff;
                            }
                            data.m_infoObjects.Add(hmiObj.ObjInfo);
                        }
                        infoPage.ObjEnd = (ushort)((infoPage.ObjStart + hmiPage.HmiObjects.Count) - 1);
                    }
                    else
                    {
                        infoPage.ObjStart = 0xffff;
                        infoPage.ObjEnd = 0xffff;
                    }
                    if (compile)
                    {
                        infoPage.InstStart = (ushort)data.m_infoStrings.Count;
                        for (int num5 = 0; num5 < hmiPage.Codes.Count; num5++)
                            addString(hmiPage.Codes[num5], data);
                        infoPage.InstEnd = (ushort)(data.m_infoStrings.Count - 1);
                    }
                    else
                    {
                        infoPage.InstStart = 0xffff;
                        infoPage.InstEnd = 0xffff;
                    }
                    data.m_infoPages.Add(infoPage);
                }
            }

            if (success)
            {
                infoApp.PageCount = (ushort)data.m_infoPages.Count;
                infoApp.ObjectCount = (ushort)data.m_infoObjects.Count;
                infoApp.FontCount = (ushort)Fonts.Count;
                infoApp.PictureCount = (ushort)Pictures.Count;
                infoApp.PictureImageStart = (uint)HmiOptions.InfoAppSize;

                if (compile)
                    infoApp.PictureImageStart = 0x1000;

                infoApp.FontImageStart = infoApp.PictureImageStart + ((uint)getPictureImagesSize());
                infoApp.StringDataStart = infoApp.FontImageStart + ((uint)getFontImagesSize());
                if (compile)
                {
                    uint num6 = infoApp.StringDataStart % 0x1000;
                    if (num6 != 0)
                        infoApp.StringDataStart += 0x1000 - num6;
                }

                infoApp.FirmwareStart = infoApp.StringDataStart + (uint)data.m_stringDataAddress;
                infoApp.FirmwareSize = 0;

                if (compile)
                {	// Add bootloader if compile
                    StreamReader reader = new StreamReader(Path.Combine(Application.StartupPath, "fwc.bin"));
                    infoApp.FirmwareSize = (uint)reader.BaseStream.Length;
                    reader.Close();
                }

                infoApp.PageStart = infoApp.FirmwareStart + infoApp.FirmwareSize;
                infoApp.ObjectStart = infoApp.PageStart + ((uint)(data.m_infoPages.Count * HmiOptions.InfoPageSize));
                infoApp.PictureStart = infoApp.ObjectStart + ((uint)(infoApp.ObjectCount * HmiOptions.InfoObjectSize));
                infoApp.StringStart = infoApp.PictureStart + ((uint)(HmiOptions.InfoPictureSize * infoApp.PictureCount));
                infoApp.StringCount = (uint)data.m_infoStrings.Count;
                infoApp.FontStart = infoApp.StringStart + ((uint)(HmiOptions.InfoStringSize * data.m_infoStrings.Count));
                infoApp.FontDataStart = infoApp.FontStart + ((uint)(HmiOptions.InfoFontSize * infoApp.FontCount));
            }
            return success;
        }
Esempio n. 2
0
        private bool prepareToSave(
            ref InfoApp infoApp,
            bool compile,
            RichTextBox textCompile,
            SaveToFileData data
            )
        {
            infoApp.IsPotrait    = (byte)(IsPotrait ? 1 : 0);
            infoApp.ScreenWidth  = (IsPotrait ? LcdHeight : LcdWidth);
            infoApp.ScreenHeight = (IsPotrait ? LcdWidth : LcdHeight);

            bool   success          = true;
            ushort customDataLength = 0;

            OverBytes = Utility.ToBytes((uint)customDataLength);

            if (compile)
            {
                for (int idxPage = 0; idxPage < HmiPages.Count; idxPage++)
                {
                    HmiPage hmiPage = HmiPages[idxPage];
                    for (int idxObj = 0; idxObj < hmiPage.HmiObjects.Count; ++idxObj)
                    {
                        HmiObject hmiObj = hmiPage.HmiObjects[idxObj];

                        hmiObj.ObjInfo.ObjType      = hmiObj.Attributes[0].Data[0];
                        hmiObj.ObjInfo.IsCustomData = hmiObj.Attributes[1].Data[0];

                        if (hmiObj.ObjInfo.IsCustomData == 1)
                        {
                            hmiObj.ObjInfo.AttributeStart = customDataLength;
                            int objRambytes = hmiObj.GetObjRamBytes(ref OverBytes, customDataLength);
                            if (objRambytes != 0)
                            {
                                hmiObj.ObjInfo.AttributeLength = (ushort)objRambytes;
                                customDataLength += hmiObj.ObjInfo.AttributeLength;
                            }
                        }
                    }
                }
            }
            addString(OverBytes, data);

            List <byte[]> bts = new List <byte[]>();

            for (int idxPage = 0; idxPage < HmiPages.Count; idxPage++)
            {
                HmiPage hmiPage = HmiPages[idxPage];

                if (compile && !hmiPage.Compile(textCompile))
                {
                    success = false;
                }
                else
                {
                    Application.DoEvents();

                    InfoPage infoPage = new InfoPage
                    {
                        ObjCount = (byte)hmiPage.HmiObjects.Count,
                        Name     = Utility.ToStruct <InfoName>(Utility.ToBytes(hmiPage.Name, 14))
                    };
                    if (infoPage.ObjCount > 0)
                    {
                        infoPage.ObjStart = (ushort)data.m_infoObjects.Count;

                        for (int idxObj = 0; idxObj < hmiPage.HmiObjects.Count; idxObj++)
                        {
                            HmiObject hmiObj = hmiPage.HmiObjects[idxObj];
                            hmiObj.ObjInfo.Name = Utility.ToStruct <InfoName>(Utility.ToBytes(hmiObj.ObjName, 14));
                            bts.Clear();
                            if (compile)
                            {
                                hmiObj.CompileCodes(bts);
                            }
                            else
                            {
                                hmiObj.GetCodes(bts);
                            }

                            if (bts.Count > 0)
                            {
                                hmiObj.ObjInfo.StringInfoStart = (ushort)data.m_infoStrings.Count;
                                for (int k = 0; k < bts.Count; k++)
                                {
                                    addString(bts[k], data);
                                }

                                hmiObj.ObjInfo.StringInfoEnd = (ushort)((hmiObj.ObjInfo.StringInfoStart + bts.Count) - 1);
                            }
                            else
                            {
                                MessageBox.Show("Detect the component code is 0, error will occur when save the source file".Translate());
                                hmiObj.ObjInfo.StringInfoStart = 0xffff;
                                hmiObj.ObjInfo.StringInfoEnd   = 0xffff;
                            }
                            data.m_infoObjects.Add(hmiObj.ObjInfo);
                        }
                        infoPage.ObjEnd = (ushort)((infoPage.ObjStart + hmiPage.HmiObjects.Count) - 1);
                    }
                    else
                    {
                        infoPage.ObjStart = 0xffff;
                        infoPage.ObjEnd   = 0xffff;
                    }
                    if (compile)
                    {
                        infoPage.InstStart = (ushort)data.m_infoStrings.Count;
                        for (int num5 = 0; num5 < hmiPage.Codes.Count; num5++)
                        {
                            addString(hmiPage.Codes[num5], data);
                        }
                        infoPage.InstEnd = (ushort)(data.m_infoStrings.Count - 1);
                    }
                    else
                    {
                        infoPage.InstStart = 0xffff;
                        infoPage.InstEnd   = 0xffff;
                    }
                    data.m_infoPages.Add(infoPage);
                }
            }

            if (success)
            {
                infoApp.PageCount         = (ushort)data.m_infoPages.Count;
                infoApp.ObjectCount       = (ushort)data.m_infoObjects.Count;
                infoApp.FontCount         = (ushort)Fonts.Count;
                infoApp.PictureCount      = (ushort)Pictures.Count;
                infoApp.PictureImageStart = (uint)HmiOptions.InfoAppSize;

                if (compile)
                {
                    infoApp.PictureImageStart = 0x1000;
                }

                infoApp.FontImageStart  = infoApp.PictureImageStart + ((uint)getPictureImagesSize());
                infoApp.StringDataStart = infoApp.FontImageStart + ((uint)getFontImagesSize());
                if (compile)
                {
                    uint num6 = infoApp.StringDataStart % 0x1000;
                    if (num6 != 0)
                    {
                        infoApp.StringDataStart += 0x1000 - num6;
                    }
                }

                infoApp.FirmwareStart = infoApp.StringDataStart + (uint)data.m_stringDataAddress;
                infoApp.FirmwareSize  = 0;

                if (compile)
                {                       // Add bootloader if compile
                    StreamReader reader = new StreamReader(Path.Combine(Application.StartupPath, "fwc.bin"));
                    infoApp.FirmwareSize = (uint)reader.BaseStream.Length;
                    reader.Close();
                }

                infoApp.PageStart     = infoApp.FirmwareStart + infoApp.FirmwareSize;
                infoApp.ObjectStart   = infoApp.PageStart + ((uint)(data.m_infoPages.Count * HmiOptions.InfoPageSize));
                infoApp.PictureStart  = infoApp.ObjectStart + ((uint)(infoApp.ObjectCount * HmiOptions.InfoObjectSize));
                infoApp.StringStart   = infoApp.PictureStart + ((uint)(HmiOptions.InfoPictureSize * infoApp.PictureCount));
                infoApp.StringCount   = (uint)data.m_infoStrings.Count;
                infoApp.FontStart     = infoApp.StringStart + ((uint)(HmiOptions.InfoStringSize * data.m_infoStrings.Count));
                infoApp.FontDataStart = infoApp.FontStart + ((uint)(HmiOptions.InfoFontSize * infoApp.FontCount));
            }
            return(success);
        }