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
        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.º 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("");
        }
Ejemplo n.º 4
0
        void GenerateComponentInstance(StreamWriter writer, ComponentInstance component)
        {
            ComponentDefenition compDefenition = component.ComponentDefenition;

            int elementsCount = compDefenition.Ports.PortsWithSenderInterface().Count + compDefenition.CDataDefenitions.Count + compDefenition.PerInstanceMemoryList.Count;

            if ((elementsCount == 0) && (compDefenition.MultipleInstantiation == false))
            {
                return; // because nothing to generate.
            }

            writer.WriteLine("/* Component instance :" + component.Name + "  */");

            String compDefString = RteFunctionsGenerator.FillStringForCount(compDefenition.Name, ' ', 50);
            String compName      = RteFunctionsGenerator.GenerateComponentName(component.Name);

            writer.WriteLine(compDefString + compName + " = ");
            writer.WriteLine("{");
            /* Fill variables */

            /* Component index */
            if (compDefenition.MultipleInstantiation)
            {
                ComponentInstancesList compInstances = AutosarApplication.GetInstance().GetComponentInstanceByDefenition(compDefenition);
                int compIndex = compInstances.IndexOf(component);
                writer.WriteLine("    .index = " + compIndex.ToString() + ", ");
            }

            /* Pim*/
            int count = 0;

            for (int i = 0; i < compDefenition.PerInstanceMemoryList.Count; i++)
            {
                PimDefenition pimDef = compDefenition.PerInstanceMemoryList[i];
                count++;

                PimInstance pimInstance = component.PerInstanceMemories.GetPim(pimDef.GUID);

                writer.Write("    ." + RteFunctionsGenerator.GenerateRtePimFieldInComponentDefenitionStruct(component.ComponentDefenition, pimDef) + " = ");

                IGUID datatype = pimDef.DataType;
                if ((datatype is BaseDataType) || (datatype is SimpleDataType) || (datatype is EnumDataType))
                {
                    RteFunctionsGenerator.WriteDefaultValueForPimDefenition(writer, component, pimInstance);
                }
                else if (datatype is ArrayDataType)
                {
                    writer.Write(" {{ ");
                    if (!((datatype as ArrayDataType).DataType is PlainDataType))
                    {
                        writer.Write("{ ");
                    }
                    writer.Write(" 0 ");

                    if (!((datatype as ArrayDataType).DataType is PlainDataType))
                    {
                        writer.Write("} ");
                    }

                    writer.Write(" }}");
                }
                else if (datatype is ComplexDataType)
                {
                    writer.Write("{ 0 }");
                }
                if ((i != compDefenition.PerInstanceMemoryList.Count - 1) || ((compDefenition.CDataDefenitions.Count > 0) || (compDefenition.Ports.PortsWithSenderInterface().Count > 0)))
                {
                    writer.WriteLine(",");
                }
            }

            /* CData */
            for (int i = 0; i < compDefenition.CDataDefenitions.Count; i++)
            {
                count++;
                CDataDefenition cdataDef = compDefenition.CDataDefenitions[i];

                CDataInstance cdataInstance = component.CDataInstances.GetCData(cdataDef.GUID);

                writer.Write("    ." + RteFunctionsGenerator.GenerateRteCDataFieldInComponentDefenitionStruct(component.ComponentDefenition, cdataDef) + " = ");

                IGUID datatype = cdataDef.DataType;
                if ((datatype is BaseDataType) || (datatype is SimpleDataType) || (datatype is EnumDataType))
                {
                    RteFunctionsGenerator.WriteDefaultValueForCDataDefenition(writer, component, cdataInstance);
                }
                else if (datatype is ArrayDataType)
                {
                    writer.Write(" {{ ");
                    if (!((datatype as ArrayDataType).DataType is PlainDataType))
                    {
                        writer.Write("{ ");
                    }
                    writer.Write(" 0 ");

                    if (!((datatype as ArrayDataType).DataType is PlainDataType))
                    {
                        writer.Write("} ");
                    }

                    writer.Write(" }}");
                }
                else if (datatype is ComplexDataType)
                {
                    writer.WriteLine(" { 0 }");
                }

                if ((i != compDefenition.CDataDefenitions.Count - 1) || (compDefenition.Ports.PortsWithSenderInterface().Count > 0))
                {
                    writer.WriteLine(",");
                }
            }

            /* Port */
            PortDefenitionsList senderPorts = component.ComponentDefenition.Ports.PortsWithSenderInterface();

            for (int i = 0; i < senderPorts.Count; i++)
            {
                SenderReceiverInterface srInterface = (SenderReceiverInterface)senderPorts[i].InterfaceDatatype;
                WriteZeroDefaultValueForSenderPort(writer, senderPorts[i], srInterface);

                if (i < senderPorts.Count - 1)
                {
                    writer.WriteLine(",");
                }
            }
            writer.WriteLine();
            writer.WriteLine("};");
            writer.WriteLine("");
        }