Ejemplo n.º 1
0
        void GenerateRteWritePortFieldFunction(StreamWriter writer, ComponentDefenition compDef, PortDefenition port, SenderReceiverInterfaceField field)
        {
            String returnValue   = Properties.Resources.STD_RETURN_TYPE;
            String RteFuncName   = RteFunctionsGenerator.GenerateReadWriteConnectionFunctionName(port, field);
            String fieldVariable = RteFunctionsGenerator.GenerateSenderReceiverInterfaceArguments(field, port.PortType, 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)
                {
                    ComponentInstance compInstance = components[0];
                    String            compName     = RteFunctionsGenerator.GenerateComponentName(compInstance.Name);
                    String            fieldName    = RteFunctionsGenerator.GenerateRteWriteFieldInComponentDefenitionStruct(port, field);
                    writer.WriteLine("    " + compName + "." + fieldName + " = *" + field.Name + ";");
                }
            }
            else //multiple instantiation component
            {
                String rteStructFieldName = RteFunctionsGenerator.GenerateRteWriteFieldInComponentDefenitionStruct(port, field);
                String instanceLine       = "((" + compDef.Name + "*)instance)->" + rteStructFieldName + " = *" + field.Name + ";";
                writer.WriteLine("    " + instanceLine);
            }

            writer.WriteLine("    return " + Properties.Resources.RTE_E_OK + ";");
            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();
        }
Ejemplo n.º 3
0
        void GenerateRteReadPortFieldFunction(StreamWriter writer, ComponentDefenition compDef, PortDefenition port, SenderReceiverInterfaceField field)
        {
            String returnValue   = Properties.Resources.STD_RETURN_TYPE;
            String RteFuncName   = RteFunctionsGenerator.GenerateReadWriteConnectionFunctionName(port, field);
            String fieldVariable = RteFunctionsGenerator.GenerateSenderReceiverInterfaceArguments(field, port.PortType, 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];

                    PortPainter       portPainter = compInstance.Ports.FindPortByItsDefenition(port);
                    ComponentInstance oppositCompInstance;
                    PortPainter       oppositePort;
                    AutosarApplication.GetInstance().GetOppositePortAndComponent(portPainter, out oppositCompInstance, out oppositePort);
                    if (oppositCompInstance != null)
                    {
                        String copyFromField    = RteFunctionsGenerator.GenerateRteWriteFieldInComponentDefenitionStruct(oppositePort.PortDefenition, field);
                        String oppositeCompName = RteFunctionsGenerator.GenerateComponentName(oppositCompInstance.Name);
                        writer.WriteLine("    memcpy(" + field.Name + ", " + "&" + oppositeCompName + "." + copyFromField + ", sizeof(" + field.DataTypeName + "));");
                        writer.WriteLine("    return " + Properties.Resources.RTE_E_OK + ";");
                    }
                    else
                    {
                        writer.WriteLine("    memset(" + field.Name + ", " + "0, sizeof(" + field.DataTypeName + "));");
                        writer.WriteLine("    return " + Properties.Resources.RTE_E_UNCONNECTED + ";");
                    }
                }
            }
            else //multiple instantiation component
            {
                ComponentInstancesList components = AutosarApplication.GetInstance().GetComponentInstanceByDefenition(compDef);
                if (components.Count > 0)
                {
                    writer.WriteLine("    switch(((" + compDef.Name + "*)" + "instance)->index)");
                    writer.WriteLine("    {");
                    for (int i = 0; i < components.Count; i++)
                    {
                        ComponentInstance compInstance = components[i];
                        PortPainter       portPainter  = compInstance.Ports.FindPortByItsDefenition(port);
                        ComponentInstance oppositCompInstance;
                        PortPainter       oppositePort;
                        AutosarApplication.GetInstance().GetOppositePortAndComponent(portPainter, out oppositCompInstance, out oppositePort);

                        writer.WriteLine("        case " + i.ToString() + ": ");
                        writer.WriteLine("        {");

                        if (oppositCompInstance != null)
                        {
                            String copyFromField    = RteFunctionsGenerator.GenerateRteWriteFieldInComponentDefenitionStruct(oppositePort.PortDefenition, field);
                            String oppositeCompName = RteFunctionsGenerator.GenerateComponentName(oppositCompInstance.Name);
                            writer.WriteLine("            memcpy(" + field.Name + ", " + "&" + oppositeCompName + "." + copyFromField + ", sizeof(" + field.DataTypeName + "));");
                            writer.WriteLine("            return " + Properties.Resources.RTE_E_OK + ";");
                        }
                        else
                        {
                            writer.WriteLine("            memset(" + field.Name + ", " + "0, sizeof(" + field.DataTypeName + "));");
                            writer.WriteLine("            return " + Properties.Resources.RTE_E_UNCONNECTED + ";");
                        }

                        writer.WriteLine("        }");
                    }
                    writer.WriteLine("    }");
                }
                writer.WriteLine("    return " + Properties.Resources.RTE_E_UNCONNECTED + ";");
            }

            writer.WriteLine("}");
            writer.WriteLine("");
        }