Example #1
0
        public string toCPkgFunctionDefinitionString()
        {
            string tempText = toCPkgFunctionPrototypeString();

            tempText = tempText.Replace("XPLAT_DLL_API", "");
            string startText = tempText.Substring(0, tempText.IndexOf("packStructPtr);\n") + ("packStructPtr)").Length);
            string endText   = tempText.Substring(tempText.IndexOf("packStructPtr);\n") + ("packStructPtr);\n").Length);

            endText = endText.Substring(0, endText.Length - 2);

            // Package Function Definition
            startText += "\n{\n";
            startText += "\t// Initialize pointer to start of packet area in output buffer\n\txplatAPI_Data->outPackBuffPtr = xplatAPI_Data->outputPacket;\n\t// Package bytes and increment pointer\n";
            int          PacketOffset       = 0;
            XPlatAutoGEN packXPlatAutoGEN   = new XPlatAutoGEN(4);
            XPlatAutoGEN unpackXPlatAutoGEN = new XPlatAutoGEN(4);

            foreach (imsSerialParamData SPD in PacketSPDs)
            {
                if (LinkedCommSystem.SystemIsBigEndian)
                {
                    packXPlatAutoGEN.AddLineTokens(SPD.toCPackFuncDefString(ref PacketOffset, "BIG"));
                }
                else
                {
                    packXPlatAutoGEN.AddLineTokens(SPD.toCPackFuncDefString(ref PacketOffset, "little"));
                }
            }
            packXPlatAutoGEN.AlignColumnsInputTokens();
            startText += packXPlatAutoGEN.ReturnOutputLines() + "}\n";

            // Unpack Function Definition
            endText     += "\n{\n";
            endText     += "\t// Initialize pointer to start of packet area in input buffer\n\txplatAPI_Data->inPackBuffPtr = xplatAPI_Data->inputPacket;\n\t// UnPack bytes and increment pointer\n";
            endText     += "\tswitch(xplatAPI_Data->inputBuffer[HDRPCKOFFSETINDEX])\n\t{\n";
            PacketOffset = 0;
            foreach (imsSerialParamData SPD in PacketSPDs)
            {
                if (LinkedCommSystem.SystemIsBigEndian)
                {
                    unpackXPlatAutoGEN.AddLineTokens(SPD.toCUnPackFuncDefString(ref PacketOffset, "BIG"));
                }
                else
                {
                    unpackXPlatAutoGEN.AddLineTokens(SPD.toCUnPackFuncDefString(ref PacketOffset, "little"));
                }
            }
            unpackXPlatAutoGEN.AlignColumnsInputTokens();
            endText += unpackXPlatAutoGEN.ReturnOutputLines() + "\n\t\tdefault:break;\n\t}\n}\n";

            return(startText + endText);
        }
Example #2
0
        public string toCTypeString()
        {
            // Loop SPDs in Packet
            // Add Opening Struct Text
            string       tempText       = "//\n// - " + PackDescription + " - //\n// \ntypedef struct\n{\n";
            int          tempInt        = 0;
            XPlatAutoGEN myXPlatAutoGEN = new XPlatAutoGEN(5);

            foreach (imsSerialParamData SPD in PacketSPDs)
            {
                myXPlatAutoGEN.AddLineTokens(SPD.toCTypeString(ref tempInt));
            }
            myXPlatAutoGEN.AlignColumnsInputTokens();
            tempText += myXPlatAutoGEN.ReturnOutputLines();


            // Add Closing Struct Text
            string tempString = "";

            foreach (char thisChar in PackDescription)
            {
                if (Char.IsLetterOrDigit(thisChar))
                {
                    tempString += thisChar;
                }
            }
            if (!Char.IsLetter(tempString[0]))
            {
                tempString = string.Concat("pck", tempString);
            }
            tempText += "}XPLAT_DLL_API " + tempString + "struct;\t// Export - " + PackDescription + " - //\n";
            tempText += "#define\tPckSize_" + tempString + "\t\t" + tempInt.ToString() + "\t\t// ( 0x" + tempInt.ToString("X2") + " )\n";
            tempText += "#define\tPckID_" + tempString + "\t\t" + PackID.ToString() + "\t\t// ( 0x" + PackID.ToString("X2") + " )\n";

            return(tempText);
        }
        protected virtual void AutoGen_FindNProcess()
        {
            List <string> AutoGen_Keys = new List <string>();

            AutoGen_Keys.Add("XPLAT_DLL_API_Packets Structures");                   // 0
            AutoGen_Keys.Add("XPLAT_DLL_API_PackagePacket Function Prototypes");    // 1
            AutoGen_Keys.Add("XPLAT_DLL_API_Comm Function Prototypes");             // 2
            AutoGen_Keys.Add("XPLAT_DLL_API_PackagePacket Function Definitions");   // 3
            AutoGen_Keys.Add("XPLAT_DLL_API_Comm Function Definitions");            // 4
            AutoGen_Keys.Add("XPLAT_CLASS_PackagePacket Method Definitions");       // 5
            AutoGen_Keys.Add("XPLAT_CLASS_Comm Method Definitions");                // 6
            AutoGen_Keys.Add("XPLAT_CLASS_PackagePacket Method Prototypes");        // 7
            AutoGen_Keys.Add("XPLAT_CLASS_Comm Method Prototypes");                 // 8
            AutoGen_Keys.Add("XPLAT_DLL_API_Comm Packet Structures");               // 9

            // Loop all files, process lines, insert new lines according to Auto-Gen::Key
            List <string> FileTexts = new List <string>(4)
            {
                BaseHText, BaseCText, ClassHppText, ClassCppText
            };

            for (int i = 0; i < FileTexts.Count; i++)
            {
                foreach (string keyString in AutoGen_Keys)
                {
                    if (FileTexts[i].Contains(keyString))
                    {
                        string tempText   = "";
                        string tempString = "";
                        switch (AutoGen_Keys.IndexOf(keyString))
                        {
                        case 0:     // Packet Structures
                        {
                            tempText += "//////////////////////////////////////////////////////////\n//\n// Auto-Gen Packet Structures \n//\n//////////////////////////////////////////////////////////\n";
                            tempText += "#ifdef PckHDRSize\n\t#undef PckHDRSize\n#endif\n#define PckHDRSize " + PacketHeaderSize.ToString() + "\n";
                            // Loop all Static Packets in Comm System
                            foreach (SerialParameterPacket SPDPacket in StaticSPDPackets)
                            {
                                tempText += SPDPacket.toCTypeString();
                            }


                            break;
                        }

                        case 1:     // Package Function Prototypes
                        {
                            tempText += "//////////////////////////////////////////////////////////\n//\n// Auto-Gen Packet Package Function Prototypes \n//\n//////////////////////////////////////////////////////////\n";
                            // Loop all Static Packets in Comm System
                            foreach (SerialParameterPacket SPDPacket in StaticSPDPackets)
                            {
                                tempText += SPDPacket.toCPkgFunctionPrototypeString();
                            }


                            break;
                        }

                        case 2:     // Comm Function Prototypes
                        {
                            tempText += "//////////////////////////////////////////////////////////\n//\n// Auto-Gen Packet Comm Function Prototypes \n//\n//////////////////////////////////////////////////////////\n";

                            tempText += "XPLAT_DLL_API void processRxPacket(xplatAPI_DATAstruct* xplatAPI_Data);\nXPLAT_DLL_API void prepareTxPacket(xplatAPI_DATAstruct* xplatAPI_Data);\n";


                            break;
                        }

                        case 3:     // Package Function Definitions
                        {
                            tempText += "//////////////////////////////////////////////////////////\n//\n// Auto-Gen Packet Package Function Definitions \n//\n//////////////////////////////////////////////////////////\n";
                            // Loop all Static Packets in Comm System
                            foreach (SerialParameterPacket SPDPacket in StaticSPDPackets)
                            {
                                tempText += SPDPacket.toCPkgFunctionDefinitionString();
                            }
                            break;
                        }

                        case 4:     // Comm Function Definitions
                        {
                            tempText += "//////////////////////////////////////////////////////////\n//\n// Auto-Gen Packet Comm Function Definitions \n//\n//////////////////////////////////////////////////////////\n";
                            tempText += "void processRxPacket(xplatAPI_DATAstruct* xplatAPI_Data)\n{\n\t// If the message type is anything other than readonly,\n\tif (xplatAPI_Data->inputBuffer[MessageTypeByteIndex] != 0u){\n\t// Based on byte 0 of the input buffer, switch on packetID\n\tswitch (xplatAPI_Data->inputBuffer[0])\n\t{\n\t\t// Auto-Gen cases from packets\n";
                            // Loop all Static Packets in Comm System
                            foreach (SerialParameterPacket SPDPacket in StaticSPDPackets)
                            {
                                tempText += SPDPacket.toCCommDefinitionString("unpack");
                            }
                            tempText += "\t\tdefault:break;\n\t}}\n\t// Initialize Outpacket ID with ID from Inpacket\n\txplatAPI_Data->outputBuffer[0] = xplatAPI_Data->inputBuffer[0];\n\t// Initialize Outpacket Message Type with Message Type from Inpacket\n\txplatAPI_Data->outputBuffer[MessageTypeByteIndex] = xplatAPI_Data->inputBuffer[MessageTypeByteIndex];\n\t// Initialize Outpacket Data Offset with Data Offset from Inpacket\n\txplatAPI_Data->outputBuffer[HDRPCKOFFSETINDEX] = xplatAPI_Data->inputBuffer[HDRPCKOFFSETINDEX];\n}\n";

                            tempText += "void prepareTxPacket(xplatAPI_DATAstruct* xplatAPI_Data)\n{\n\t// Based on byte 0 of the output buffer, switch on packetID\n\tswitch (xplatAPI_Data->outputBuffer[0])\n\t{\n\t\t// Auto-Gen cases from packets\n";
                            // Loop all Static Packets in Comm System
                            foreach (SerialParameterPacket SPDPacket in StaticSPDPackets)
                            {
                                tempText += SPDPacket.toCCommDefinitionString("package");
                            }
                            tempText += "\t\tdefault:break;\n\t}\n}\n";

                            break;
                        }

                        case 5:     // Package Method Definitions
                        {
                            break;
                        }

                        case 6:     // Comm Method Definitions
                        {
                            break;
                        }

                        case 7:     // Package Method Prototypes
                        {
                            break;
                        }

                        case 8:     // Comm Method Prototypes
                        {
                            break;
                        }

                        case 9:    // Packet Structures in SM
                        {
                            tempText += "//////////////////////////////////////////////////////////\n//\n// Auto-Gen Packet Structures \n//\n//////////////////////////////////////////////////////////\n";
                            // Loop all Static Packets in Comm System
                            XPlatAutoGEN myXPlatAutoGEN = new XPlatAutoGEN(2);
                            foreach (SerialParameterPacket SPDPacket in StaticSPDPackets)
                            {
                                myXPlatAutoGEN.AddLineTokens(SPDPacket.toCPacketStructString());
                            }
                            myXPlatAutoGEN.AlignColumnsInputTokens();
                            tempText += myXPlatAutoGEN.ReturnOutputLines();
                            break;
                        }

                        default:
                        {
                            break;
                        }
                        }
                        if (tempText != "")
                        {
                            int tempIndex = FileTexts[i].IndexOf(keyString) + keyString.Length;
                            FileTexts[i] = FileTexts[i].Insert(tempIndex, string.Concat("\n", tempText, "\n"));
                        }
                    }
                }
            }

            // (re)Capture
            BaseHText    = FileTexts[0];
            BaseCText    = FileTexts[1];
            ClassHppText = FileTexts[2];
            ClassCppText = FileTexts[3];
        }