public void UpdatePims() { /* Delete unexists */ for (int i = PerInstanceMemories.Count - 1; i >= 0; i--) { PimInstance pimInstance = PerInstanceMemories[i]; if (ComponentDefenition.PerInstanceMemoryList.FindObject(pimInstance.DefenitionGuid) == null) { PerInstanceMemories.RemoveAt(i); } } /* Adding */ foreach (PimDefenition pimDef in ComponentDefenition.PerInstanceMemoryList) { if (PerInstanceMemories.GetPim(pimDef) == null) { PimInstance pimInstace = PimFabric.GetInstance().CreatePimInstance(pimDef); PerInstanceMemories.Add(pimInstace); } } /* Refresh default values */ foreach (PimInstance pim in PerInstanceMemories) { pim.UpdateDefaultValues(); } }
void WritePIMDefaultValues(StreamWriter writer, PimInstance pim) { String FieldValue = " " + TestArtefactsVariable + "." + RteFunctionsGenerator.GenerateShortPimFunctionName(pim.Defenition) + ".data"; IGUID datatype = pim.Defenition.DataType; if ((datatype is BaseDataType) || (datatype is SimpleDataType) || (datatype is EnumDataType)) { String defValue = GetDefaultValueForUnComplexDataType(pim); writer.WriteLine(FieldValue + " = " + defValue + ";"); } else if (datatype is ComplexDataType) { for (int defValueIndex = 0; defValueIndex < pim.DefaultValues.Count; defValueIndex++) { ComplexDataType complexDataType = (ComplexDataType)datatype; PimDefaultValue defaultValue = pim.DefaultValues[defValueIndex]; ComplexDataTypeField dataTypefield = complexDataType.Fields.FindObject(defaultValue.FieldGuid); if (dataTypefield != null) { String dataToWrite = FieldValue + "." + dataTypefield.Name + " = " + defaultValue.DefaultValue + ";"; writer.WriteLine(dataToWrite); } } } }
public PimInstance CreatePimInstance(PimDefenition pimDefenition) { PimInstance pimInstance = new PimInstance(); pimInstance.DefenitionGuid = pimDefenition.GUID; pimInstance.Name = pimDefenition.Name; pimInstance.UpdateDefaultValues(); return(pimInstance); }
public void UpdatePimNames() { for (int i = PerInstanceMemories.Count - 1; i >= 0; i--) { PimInstance pimInstance = PerInstanceMemories[i]; pimInstance.Name = pimInstance.Defenition.Name; pimInstance.SyncronizeName(); } }
String GetDefaultValueForUnComplexDataType(PimInstance pim) { if (pim.DefaultValues.Count == 1) { if (pim.DefaultValues[0].DefaultValue.Length > 0) { return(pim.DefaultValues[0].DefaultValue); } else { return("0"); } } else { return("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(""); }
public static void WriteDefaultValueForPimDefenition(StreamWriter writer, ComponentInstance component, PimInstance pimInstance) { if (pimInstance.DefaultValues.Count == 1) { if (pimInstance.DefaultValues[0].DefaultValue.Length > 0) { writer.Write(pimInstance.DefaultValues[0].DefaultValue); } else { writer.Write("0"); } } else { writer.Write("0"); } }
void GenerateTestInitializationFile(ComponentDefenition compDef, String outputDir) { String FileName = outputDir + "\\" + Properties.Resources.TEST_INITIALIZATION_FILENAME; StreamWriter writer = new StreamWriter(FileName); RteFunctionsGenerator.GenerateFileTitle(writer, Properties.Resources.TEST_RTE_C_FILENAME, "This file contains functions for component initialization before each test"); String guardDefine = RteFunctionsGenerator.OpenGuardDefine(writer); /* Add includes */ RteFunctionsGenerator.AddInclude(writer, Properties.Resources.TEST_RTE_H_FILENAME); RteFunctionsGenerator.AddInclude(writer, Properties.Resources.RTE_DATATYPES_H_FILENAME); writer.WriteLine(); /* Write parameters count as equal value to component instances */ ComponentInstancesList componentInstances = AutosarApplication.GetInstance().GetComponentInstanceByDefenition(compDef); writer.WriteLine("const int " + ParametersCount + " = " + componentInstances.Count.ToString() + ";"); writer.WriteLine(); /* Add function for component variable initialization */ writer.WriteLine("/* User function for variable initialization */"); writer.WriteLine("extern void VariableInitialization();"); writer.WriteLine(); /* Declare test initialization function */ writer.WriteLine("void " + TestInitializationFunctionName + "(int paramIndex)"); writer.WriteLine("{"); /* Clear test structure */ writer.WriteLine(" memset(&" + TestArtefactsVariable + ", 0, sizeof(" + TestArtefactsStructureDataType + " ));"); if (componentInstances.Count > 0) { /* Fill CData constants */ writer.WriteLine(" switch(paramIndex)"); writer.WriteLine(" {"); for (int i = 0; i < componentInstances.Count; i++) { writer.WriteLine(" case " + i.ToString() + ":"); writer.WriteLine(" {"); /* CDATA */ for (int j = 0; j < compDef.CDataDefenitions.Count; j++) { CDataDefenition cdataDef = compDef.CDataDefenitions[j]; CDataInstance cdataInstance = componentInstances[i].CDataInstances.GetCData(cdataDef.GUID); writer.Write(" " + TestArtefactsVariable + "." + RteFunctionsGenerator.GenerateShortCDataFunctionName(cdataDef) + ".Value = "); IGUID datatype = cdataDef.DataType; if ((datatype is BaseDataType) || (datatype is SimpleDataType) || (datatype is EnumDataType)) { RteFunctionsGenerator.WriteDefaultValueForCDataDefenition(writer, componentInstances[i], cdataInstance); } writer.WriteLine(";"); } for (int j = 0; j < compDef.PerInstanceMemoryList.Count; j++) { PimDefenition pimDef = compDef.PerInstanceMemoryList[j]; PimInstance pimInstance = componentInstances[i].PerInstanceMemories.GetPim(pimDef.GUID); WritePIMDefaultValues(writer, pimInstance); } writer.WriteLine(" break;"); writer.WriteLine(" }"); } writer.WriteLine(" }"); } /* Write RTE_OK to all return functions */ foreach (PortDefenition portDef in compDef.Ports) { if (portDef.InterfaceDatatype is SenderReceiverInterface) { SenderReceiverInterface srInterface = (SenderReceiverInterface)portDef.InterfaceDatatype; foreach (SenderReceiverInterfaceField srField in srInterface.Fields) { String fieldName = RteFunctionsGenerator.GenerateReadWriteFunctionName(portDef, srField); writer.WriteLine(" " + TestArtefactsVariable + "." + fieldName + ".ReturnValue = RTE_E_OK;"); } } } writer.WriteLine(); /* Initialize component variables */ writer.WriteLine(" VariableInitialization();"); writer.WriteLine("}"); RteFunctionsGenerator.CloseGuardDefine(writer); RteFunctionsGenerator.WriteEndOfFile(writer); writer.Close(); }