Ejemplo n.º 1
0
        void GenerateRteCDataFunction(StreamWriter writer, ComponentDefenition compDef, CDataDefenition cdataDef)
        {
            String returnValue = cdataDef.DataTypeName + " ";
            String RteFuncName = RteFunctionsGenerator.GenerateFullCDataFunctionName(compDef, cdataDef);

            String fieldVariable = RteFunctionsGenerator.GenerateMultipleInstanceFunctionArguments(compDef.MultipleInstantiation);

            writer.WriteLine(returnValue + RteFuncName + fieldVariable);
            writer.WriteLine("{");

            if (!compDef.MultipleInstantiation) //single instantiation component
            {
                ComponentInstancesList components = AutosarApplication.GetInstance().GetComponentInstanceByDefenition(compDef);
                if (components.Count > 0)
                {
                    /* At least one component exists at this step */
                    ComponentInstance compInstance = components[0];
                    String            compName     = RteFunctionsGenerator.GenerateComponentName(compInstance.Name);
                    String            field        = RteFunctionsGenerator.GenerateRteCDataFieldInComponentDefenitionStruct(compDef, cdataDef);
                    writer.WriteLine("    return " + compName + "." + field + ";");
                }
            }
            else //multiple instantiation component
            {
                String field = RteFunctionsGenerator.GenerateRteCDataFieldInComponentDefenitionStruct(compDef, cdataDef);
                writer.WriteLine("    return ((" + compDef.Name + "*)instance)->" + field + ";");
            }

            writer.WriteLine("}");
            writer.WriteLine("");
        }
Ejemplo n.º 2
0
        /* Generate funcitons for Sender-Receiver ports and call operations from client ports */
        public void CreateRteIncludes(String dir, ComponentDefenition componentDefenition)
        {
            String       filename = dir + "\\" + "Rte_" + componentDefenition.Name + ".h";
            StreamWriter writer   = new StreamWriter(filename);

            RteFunctionsGenerator.GenerateFileTitle(writer, filename, "Implementation for " + componentDefenition.Name + " header file");
            string guardDefine = RteFunctionsGenerator.OpenGuardDefine(writer);

            writer.WriteLine("");
            writer.WriteLine(RteFunctionsGenerator.IncludesLine);
            RteFunctionsGenerator.AddInclude(writer, Properties.Resources.SYSTEM_ERRORS_H_FILENAME);
            RteFunctionsGenerator.AddInclude(writer, Properties.Resources.RTE_DATATYPES_H_FILENAME);
            writer.WriteLine("");
            writer.WriteLine(RteFunctionsGenerator.EndOfIncludesLine);
            writer.WriteLine("");

            /* MACROS */
            writer.WriteLine("");
            writer.WriteLine(RteFunctionsGenerator.MacrosLine);

            /* Write all runnables frequences */
            writer.WriteLine("/* Runnables frequences */");
            foreach (PeriodicRunnableDefenition runnable in componentDefenition.Runnables)
            {
                String runnableFreqMacroName = "Rte_Period_" + componentDefenition.Name + "_ru" + runnable.Name;
                String define = RteFunctionsGenerator.CreateDefine(runnableFreqMacroName, (runnable.PeriodMs * 1000).ToString() + "UL");
                writer.WriteLine(define);
            }

            /* Write all pims */
            foreach (PimDefenition pim in componentDefenition.PerInstanceMemoryList)
            {
                String define = RteFunctionsGenerator.CreateDefine(RteFunctionsGenerator.GenerateShortPimFunctionName(pim), RteFunctionsGenerator.GenerateFullPimFunctionName(componentDefenition, pim), false);
                writer.WriteLine(define);
            }

            /* Write all cdata */
            foreach (CDataDefenition cdata in componentDefenition.CDataDefenitions)
            {
                String define = RteFunctionsGenerator.CreateDefine(RteFunctionsGenerator.GenerateShortCDataFunctionName(cdata), RteFunctionsGenerator.GenerateFullCDataFunctionName(componentDefenition, cdata), false);
                writer.WriteLine(define);
            }

            String externFunctions = "";

            /* Add defines for all ports */
            foreach (PortDefenition portDefenition in componentDefenition.Ports)
            {
                if ((portDefenition.PortType == PortType.Sender) || (portDefenition.PortType == PortType.Receiver))
                {
                    SenderReceiverInterface srInterface = AutosarApplication.GetInstance().SenderReceiverInterfaces.FindObject(portDefenition.InterfaceGUID);
                    foreach (SenderReceiverInterfaceField field in srInterface.Fields)
                    {
                        String funcName    = RteFunctionsGenerator.GenerateReadWriteFunctionName(portDefenition, field);
                        String RteFuncName = RteFunctionsGenerator.GenerateReadWriteConnectionFunctionName(portDefenition, field);
                        writer.WriteLine(RteFunctionsGenerator.CreateDefine(funcName, RteFuncName, false));
                        String fieldVariable = RteFunctionsGenerator.GenerateSenderReceiverInterfaceArguments(field, portDefenition.PortType, componentDefenition.MultipleInstantiation);

                        externFunctions += Properties.Resources.STD_RETURN_TYPE + funcName + fieldVariable + ";" + Environment.NewLine;
                    }
                }
                else if (portDefenition.PortType == PortType.Client)
                {
                    ClientServerInterface csInterface = AutosarApplication.GetInstance().ClientServerInterfaces.FindObject(portDefenition.InterfaceGUID);
                    foreach (ClientServerOperation operation in csInterface.Operations)
                    {
                        String funcName     = RteFunctionsGenerator.Generate_RteCall_FunctionName(portDefenition, operation);
                        String RteFuncName  = RteFunctionsGenerator.Generate_RteCall_ConnectionGroup_FunctionName(componentDefenition, portDefenition, operation);
                        String funcArgument = RteFunctionsGenerator.GenerateClientServerInterfaceArguments(operation, componentDefenition.MultipleInstantiation);
                        writer.WriteLine(RteFunctionsGenerator.CreateDefine(funcName, RteFuncName, false));
                        externFunctions += Properties.Resources.STD_RETURN_TYPE + funcName + funcArgument + ";" + Environment.NewLine;
                    }
                }
                else if (portDefenition.PortType == PortType.Server)
                {
                    ClientServerInterface csInterface = AutosarApplication.GetInstance().ClientServerInterfaces.FindObject(portDefenition.InterfaceGUID);
                    foreach (ClientServerOperation operation in csInterface.Operations)
                    {
                        String funcName     = RteFunctionsGenerator.Generate_RteCall_FunctionName(portDefenition, operation);
                        String RteFuncName  = RteFunctionsGenerator.Generate_RteCall_ConnectionGroup_FunctionName(componentDefenition, portDefenition, operation);
                        String funcArgument = RteFunctionsGenerator.GenerateClientServerInterfaceArguments(operation, componentDefenition.MultipleInstantiation);
                        writer.WriteLine(RteFunctionsGenerator.CreateDefine(funcName, RteFuncName, false));
                    }
                }
            }

            writer.WriteLine("");
            writer.WriteLine(RteFunctionsGenerator.EndOfMacrosLine);
            writer.WriteLine("");

            writer.WriteLine("");
            writer.WriteLine(RteFunctionsGenerator.RteFunctionsDefenitionsLine);
            writer.WriteLine("");

            /* Add function */
            writer.Write(externFunctions);

            /* Add Pim's functions */
            foreach (PimDefenition pimDefenition in componentDefenition.PerInstanceMemoryList)
            {
                String datatype    = pimDefenition.DataTypeName;
                String pimFuncName = RteFunctionsGenerator.GenerateShortPimFunctionName(pimDefenition);
                String arguments   = "(";
                if (componentDefenition.MultipleInstantiation)
                {
                    arguments += RteFunctionsGenerator.ComponentInstancePointerDatatype + " instance";
                }
                arguments += ");";
                writer.WriteLine(datatype + " * " + pimFuncName + arguments);
            }

            /* Add CData functions */
            foreach (CDataDefenition cdataDefenition in componentDefenition.CDataDefenitions)
            {
                String datatype      = cdataDefenition.DataTypeName;
                String cdataFuncName = RteFunctionsGenerator.GenerateShortCDataFunctionName(cdataDefenition);
                String arguments     = "(";
                if (componentDefenition.MultipleInstantiation)
                {
                    arguments += RteFunctionsGenerator.ComponentInstancePointerDatatype + " instance";
                }
                arguments += ");";
                writer.WriteLine(datatype + " " + cdataFuncName + arguments);
            }

            writer.WriteLine(RteFunctionsGenerator.EndOfRteFunctionsDefenitionsLine);
            writer.WriteLine("");

            writer.WriteLine("");
            RteFunctionsGenerator.CloseGuardDefine(writer);
            writer.Close();
        }