Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time as tm
- import six
- import os
- #ordered dic for C
- import collections
- from .diagram import *
- from .sim import *
- from functools import partial
- from .stage import *
- from xml.dom import minidom, Node
- from xml.dom.minidom import parse, parseString, Document
- import numpy
- import tempfile
- from PyQt5.QtCore import *
- from PyQt5.QtGui import *
- from PyQt5.QtWidgets import *
- class esExporterWindow(QMainWindow):
- def __init__(self):
- super().__init__()
- self.initUI()
- def initUI(self):
- # Window
- self.setGeometry(500, 300, 500, 300)
- self.setWindowTitle('esExporter')
- inBrowseButton = QPushButton('Browse', self)
- inBrowseButton.move(370, 95)
- inBrowseButton.clicked.connect(self.addInAddress)
- self.inAddress = QLineEdit(self)
- self.inAddress.move(30, 96)
- self.inAddress.dragEnabled()
- self.inAddress.setFixedWidth(330)
- outBrowseButton = QPushButton('Browse', self)
- outBrowseButton.move(370, 180)
- outBrowseButton.clicked.connect(self.addOutAddress)
- self.outAddress = QLineEdit(self)
- self.outAddress.move(30, 181)
- self.outAddress.dragEnabled()
- self.outAddress.setFixedWidth(330)
- exportButton = QPushButton('Export', self)
- exportButton.move(200, 250)
- exportButton.clicked.connect(self.Export)
- self.exportFormat=QComboBox(self)
- self.exportFormat.addItem('VHDL') # self.exportFormat.currentIndex()=0
- self.exportFormat.addItem('XML') # self.exportFormat.currentIndex()=1
- self.exportFormat.addItem('GraphML') # self.exportFormat.currentIndex()=2
- self.exportFormat.addItem('C') # self.exportFormat.currentIndex()=3
- self.exportFormat.move(50, 250)
- # Texts
- titleText=QLabel('esExporter', self)
- titleText.move(200,20)
- inputText=QLabel('Input file (.esdf only)', self)
- inputText.move(30,65)
- inputText.setFixedWidth(200)
- outputText=QLabel('Output file', self)
- outputText.move(30, 153)
- inputText.setFixedWidth(200)
- conversionFormatText=QLabel('Format', self)
- conversionFormatText.move(80, 225)
- self.show()
- def addInAddress(self):
- fn = QFileDialog.getOpenFileName(self, 'Open', '..', filter='*.esdf')
- self.inAddress.setText(fn[0])
- def addOutAddress(self):
- fn = QFileDialog.getSaveFileName(self, 'Save', '..')
- self.outAddress.setText(fn[0])
- # Export programs
- def Export(self):
- # Analyse which format is asked by the user and select the right conversion program
- if self.exportFormat.currentIndex() == 0:
- self.exportToVHDL()
- elif self.exportFormat.currentIndex() == 1:
- self.exportToXML()
- elif self.exportFormat.currentIndex() == 2:
- self.exportToGRAPHML()
- elif self.exportFormat.currentIndex() == 3:
- self.exportToC()
- def exportToVHDL(self):
- # Creating variables
- inFileAddress=self.inAddress.text()
- outFileAddress=self.outAddress.text()
- # Check if the output file has the right extension
- if outFileAddress is not None:
- if outFileAddress.endswith('.vhd') is False:
- outFileAddress+='.vhd'
- # Create a diagram based on the input file and convert it in XML
- diagram = Actors_Canvas(inFileAddress)
- xml_file = convertXML(diagram)
- # Create XML file
- fileNameXML = open(outFileAddress + '.xml', 'w')
- fileNameXML.write(xml_file)
- fileNameXML.close()
- # Parse the XML file to extract all the information
- dom = parse(outFileAddress + '.xml')
- nbComponent = 1
- components = {}
- nbEdge = 1
- edges = {}
- componentNames = []
- terminalCheck = []
- for component in dom.getElementsByTagName('component'):
- components['cmp' + str(nbComponent)] = {}
- for name in component.getElementsByTagName('name'):
- components['cmp' + str(nbComponent)]['name'] = extractItem(name)
- for ref in component.getElementsByTagName('ref'):
- components['cmp' + str(nbComponent)]['ref'] = extractItem(ref)
- nbTerminal = 1
- components['cmp' + str(nbComponent)]['terminals'] = {}
- for terminal in component.getElementsByTagName('terminal'):
- components['cmp' + str(nbComponent)]['terminals']['t' + str(nbTerminal)] = {}
- for type in terminal.getElementsByTagName('type'):
- components['cmp' + str(nbComponent)]['terminals']['t' + str(nbTerminal)]['type'] = extractItem(type)
- for data_type in terminal.getElementsByTagName('data_type'):
- components['cmp' + str(nbComponent)]['terminals']['t' + str(nbTerminal)]['data_type'] = extractItem(
- data_type)
- nbTerminal += 1
- nbComponent += 1
- for edge in dom.getElementsByTagName('edge'):
- for name in edge.getElementsByTagName('name'):
- edges[extractItem(name)] = {}
- for delay in edge.getElementsByTagName('delay'):
- edges[extractItem(name)]['delay'] = extractItem(delay)
- for source in edge.getElementsByTagName('source'):
- edges[extractItem(name)]['source'] = {}
- for actor in source.getElementsByTagName('actor'):
- edges[extractItem(name)]['source']['actor'] = extractItem(actor)
- for port in source.getElementsByTagName('port'):
- edges[extractItem(name)]['source']['port'] = extractItem(port)
- for Dest in edge.getElementsByTagName('dest'):
- edges[extractItem(name)]['dest'] = {}
- for actor in Dest.getElementsByTagName('actor'):
- edges[extractItem(name)]['dest']['actor'] = extractItem(actor)
- for port in Dest.getElementsByTagName('port'):
- edges[extractItem(name)]['dest']['port'] = extractItem(port)
- nbEdge += 1
- # Analysing datas
- # Edges
- signals_1b_ToCreate = []
- signals_32b_ToCreate = []
- for edge_key in edges.keys():
- start = edges[edge_key]['source']['actor'] + edges[edge_key]['source']['port']
- stop = edges[edge_key]['dest']['actor'] + edges[edge_key]['dest']['port']
- signals_1b_ToCreate.append(start + '_TxRdy')
- signals_32b_ToCreate.append(start + '_dOut')
- signals_1b_ToCreate.append(start + '_RxRdy') # Creating all the FIFO signals
- signals_32b_ToCreate.append(stop + '_dIn')
- signals_1b_ToCreate.append(stop + '_TxRdy')
- signals_1b_ToCreate.append(stop + '_RxRdy')
- signals_32b_ToCreate.append(stop + '_dCount')
- for item in signals_1b_ToCreate:
- if signals_1b_ToCreate.count(item) != 1:
- while 1:
- signals_1b_ToCreate.remove(item)
- if signals_1b_ToCreate.count(item) == 1:
- break
- for item in signals_32b_ToCreate:
- if signals_32b_ToCreate.count(item) != 1:
- while 1:
- signals_32b_ToCreate.remove(item)
- if signals_32b_ToCreate.count(item) == 1:
- break
- # Create The VHDL File
- vhdl_file = '-- Diagram to VHDL Exporter\n\n'
- vhdl_file += 'Library IEEE;\n'
- vhdl_file += 'Use IEEE.std_logic_1164.all;\n'
- vhdl_file += 'Use IEEE.numeric_std.all;\n\n'
- vhdl_file += 'Library work;\n'
- vhdl_file += 'Use work.SDF_PACKAGE.all;\n\n'
- vhdl_file += 'entity bench is\n'
- vhdl_file += ' port(\n'
- vhdl_file += ' clk: in std_logic; \n'
- vhdl_file += ' aRstN: in std_logic;\n'
- vhdl_file += ' sRst: in std_logic\n'
- vhdl_file += ' );\n'
- vhdl_file += 'end bench;\n'
- vhdl_file += '\nArchitecture ar of bench is\n'
- vhdl_file += 'Signal en : std_logic; \n'
- for Signal_1b in signals_1b_ToCreate:
- vhdl_file = vhdl_file + 'Signal ' + Signal_1b + ' : std_logic;\n'
- for Signal_32b in signals_32b_ToCreate:
- vhdl_file = vhdl_file + 'Signal ' + Signal_32b + ' : std_logic_vector(31 downto 0);\n'
- vhdl_file += '\n'
- vhdl_file += ' Begin\n\n'
- # Instantiate all the FIFOs
- vhdl_file += '-- Instantiate all the FIFOs \n\n'
- for edge_key in edges.keys():
- vhdl_file = vhdl_file + ' FIFO_' + edge_key[1:] + ': FIFO\n'
- vhdl_file = vhdl_file + ' port map ( clk => clk,\n'
- vhdl_file = vhdl_file + ' aRstN => aRstN, \n'
- vhdl_file = vhdl_file + ' sRst => sRst, \n'
- vhdl_file = vhdl_file + ' wrEn => ' + (
- edges[edge_key]['source']['actor'] + edges[edge_key]['source']['port']) + '_TxRdy' + ',\n'
- vhdl_file = vhdl_file + ' dIn => ' + (
- edges[edge_key]['source']['actor'] + edges[edge_key]['source']['port']) + '_dOut' + ',\n'
- vhdl_file = vhdl_file + ' rdEn => ' + (
- edges[edge_key]['source']['actor'] + edges[edge_key]['source']['port']) + '_RxRdy' + ',\n'
- vhdl_file = vhdl_file + ' dOut => ' + (
- edges[edge_key]['dest']['actor'] + edges[edge_key]['dest']['port']) + '_dIn' + ',\n'
- vhdl_file = vhdl_file + ' empty => ' + (
- edges[edge_key]['dest']['actor'] + edges[edge_key]['dest']['port']) + '_TxRdy' + ',\n'
- vhdl_file = vhdl_file + ' full => ' + (
- edges[edge_key]['dest']['actor'] + edges[edge_key]['dest']['port']) + '_RxRdy' + ',\n'
- vhdl_file = vhdl_file + ' dCount => ' + (
- edges[edge_key]['dest']['actor'] + edges[edge_key]['dest']['port']) + '_dCount' + '\n'
- vhdl_file = vhdl_file + ' );\n\n'
- # Instantiate the components
- vhdl_file += '\n-- Instantiate all the components \n\n'
- for component_key in components.keys():
- if components[component_key]['name'] != 'Solver_SDF' and components[component_key]['name'] != 'Connection':
- componentNames.append(components[component_key]['name'])
- nbComponent = componentNames.count(components[component_key]['name'])
- vhdl_file = vhdl_file + ' ' + components[component_key]['name'] + '_' + str(nbComponent - 1) + ': ' + \
- components[component_key]['name'] + '\n'
- vhdl_file = vhdl_file + ' port map ( clk => clk,\n'
- vhdl_file = vhdl_file + ' aRstN => aRstN,\n'
- vhdl_file = vhdl_file + ' sRst => sRst,\n'
- vhdl_file = vhdl_file + ' en => en,\n'
- nbInOut = 1
- terminalCheck.clear()
- nbTermComponent = 0
- for terminal_key in components[component_key]['terminals'].keys():
- if components[component_key]['terminals'][terminal_key]['type'] == 'OUT':
- for edge_key in edges.keys():
- if components[component_key]['ref'] == edges[edge_key]['source']['actor']:
- if (edges[edge_key]['dest']['actor'] + edges[edge_key]['dest'][
- 'port']) not in terminalCheck:
- terminalCheck.append(
- edges[edge_key]['dest']['actor'] + edges[edge_key]['dest']['port'])
- vhdl_file = vhdl_file + ' ' + (
- edges[edge_key]['source']['port']) + '_dOut' + ' => ' + (
- edges[edge_key]['source']['actor'] + edges[edge_key]['source'][
- 'port']) + '_dOut' + ',\n'
- vhdl_file = vhdl_file + ' ' + (
- edges[edge_key]['source']['port']) + '_RxRdy' + ' => ' + (
- edges[edge_key]['source']['actor'] + edges[edge_key]['source'][
- 'port']) + '_RxRdy' + ',\n'
- vhdl_file = vhdl_file + ' ' + (
- edges[edge_key]['source']['port']) + '_TxRdy' + ' => ' + (
- edges[edge_key]['source']['actor'] + edges[edge_key]['source'][
- 'port']) + '_TxRdy'
- break
- elif components[component_key]['terminals'][terminal_key]['type'] == 'IN':
- for edge_key in edges.keys():
- if components[component_key]['ref'] == edges[edge_key]['dest']['actor']:
- if (edges[edge_key]['source']['actor'] + edges[edge_key]['source'][
- 'port']) not in terminalCheck:
- terminalCheck.append(
- edges[edge_key]['source']['actor'] + edges[edge_key]['source']['port'])
- vhdl_file = vhdl_file + ' ' + (
- edges[edge_key]['dest']['port']) + '_dIn' + ' => ' + (
- edges[edge_key]['dest']['actor'] + edges[edge_key]['dest'][
- 'port']) + '_dIn' + ',\n'
- vhdl_file = vhdl_file + ' ' + (
- edges[edge_key]['dest']['port']) + '_RxRdy' + ' => ' + (
- edges[edge_key]['dest']['actor'] + edges[edge_key]['dest'][
- 'port']) + '_RxRdy' + ',\n'
- vhdl_file = vhdl_file + ' ' + (
- edges[edge_key]['dest']['port']) + '_TxRdy' + ' => ' + (
- edges[edge_key]['dest']['actor'] + edges[edge_key]['dest'][
- 'port']) + '_TxRdy'
- break
- elif components[component_key]['terminals'][terminal_key]['type'] == 'INOUT':
- vhdl_file = vhdl_file + 'INOUT_' + str(nbInOut)
- nbInOut += 1
- nbTermComponent += 1
- if len(components[component_key]['terminals']) != nbTermComponent:
- vhdl_file += (',\n')
- else:
- vhdl_file += ('\n')
- vhdl_file = vhdl_file + ' );\n\n'
- # Finish the file
- vhdl_file += 'End ar;\n'
- file = open(outFileAddress, 'w')
- file.write(vhdl_file)
- file.close()
- os.remove(outFileAddress+ '.xml')
- def exportToXML(self):
- # Creating variables
- inFileAddress = self.inAddress.text()
- outFileAddress = self.outAddress.text()
- # Check if the output file has the right extension
- if outFileAddress is not None:
- if outFileAddress.endswith('.xml') is False:
- outFileAddress += '.xml'
- # Create a diagram based on the input file and convert it in XML
- diagram = Actors_Canvas(inFileAddress)
- xml_file = convertXML(diagram)
- # Create XML file
- fileNameXML = open(outFileAddress, 'w')
- fileNameXML.write(xml_file)
- fileNameXML.close()
- def exportToGRAPHML(self):
- # Creating variables
- inFileAddress = self.inAddress.text()
- outFileAddress = self.outAddress.text()
- # Check if the output file has the right extension
- if outFileAddress is not None:
- if outFileAddress.endswith('.graphml') is False:
- outFileAddress += '.graphml'
- # Create a diagram based on the input file and convert it in XML
- diagram = Actors_Canvas(inFileAddress)
- # Create GraphML document
- nbTermComponent = 0
- netNameCheck = []
- doc = minidom.Document()
- doc.appendChild(doc.createComment("Diagram to GraphML Exporter"))
- root = doc.createElement('root')
- doc.appendChild(root)
- for Component in diagram.diagram.componentList:
- if Component.className != 'Constant':
- component = doc.createElement('component')
- component.setAttribute('name', str(Component.className))
- component.setAttribute('Ref', str(Component.parameter['Ref'].value))
- root.appendChild(component)
- for key in Component.terminal.keys():
- terminal = doc.createElement('terminal')
- if Component.terminal[key].termType == 1:
- terminal.setAttribute('type', 'CONN')
- if Component.terminal[key].termType == 2:
- terminal.setAttribute('type', 'IN')
- if Component.terminal[key].termType == 4:
- terminal.setAttribute('type', 'OUT')
- if Component.terminal[key].termType == 8:
- terminal.setAttribute('type', 'INOUT')
- if str(type(Component.terminal[key].value)) == "<class 'float'>":
- terminal.setAttribute('data_type', 'float')
- component.appendChild(terminal)
- if Component.className == 'Constant':
- constant = doc.createElement('constant')
- constant.setAttribute('name', str(Component.parameter['Ref'].value))
- for key in Component.terminal.keys():
- constant.setAttribute('value', str(Component.terminal[key].value))
- root.appendChild(constant)
- if diagram.simEngine is None:
- diagram.simEngine = Action(diagram.diagram)
- netInfos = diagram.simEngine.checkNetwork()
- for key in netInfos.keys():
- if key not in netNameCheck:
- netNameCheck.append(key)
- edge = doc.createElement('edge')
- edge.setAttribute('name', str(key))
- edge.setAttribute('delay', str(netInfos[key][4]))
- root.appendChild(edge)
- source = doc.createElement('source')
- source.setAttribute('actor', str(netInfos[key][0]))
- source.setAttribute('port', str(netInfos[key][1]))
- edge.appendChild(source)
- dest = doc.createElement('dest')
- dest.setAttribute('actor', str(netInfos[key][2]))
- dest.setAttribute('port', str(netInfos[key][3]))
- edge.appendChild(dest)
- file = open(outFileAddress, 'w')
- file.write(doc.toprettyxml(indent=' '))
- file.close()
- def exportToC(self):
- # Creating variables
- inFileAddress = self.inAddress.text()
- outFileAddress = self.outAddress.text()
- # Check if the output file has the right extension
- if outFileAddress is not None:
- if outFileAddress.endswith('.c') is False:
- outFileAddress += '.c'
- # Create a diagram based on the input file and convert it in XML
- diagram = Actors_Canvas(inFileAddress)
- xml_file = convertXML(diagram)
- # Create XML file
- fileNameXML = open(outFileAddress + '.xml', 'w')
- fileNameXML.write(xml_file)
- fileNameXML.close()
- # Parse the XML file to extract all the information
- dom = parse(outFileAddress + '.xml')
- nbComponent = 1
- components = {}
- nbEdge = 1
- edges = {}
- componentNames = []
- terminalCheck = []
- for component in dom.getElementsByTagName('component'):
- components['cmp' + str(nbComponent)] = {}
- for name in component.getElementsByTagName('name'):
- components['cmp' + str(nbComponent)]['name'] = extractItem(name)
- for gain in component.getElementsByTagName('gain') :
- components['cmp' + str(nbComponent)]['gain'] = extractItem(gain)
- for offset in component.getElementsByTagName('offset'):
- components['cmp' + str(nbComponent)]['offset'] = extractItem(offset)
- for amplitude in component.getElementsByTagName('amplitude') :
- components['cmp' + str(nbComponent)]['amplitude'] = extractItem(amplitude)
- for frequency in component.getElementsByTagName('frequency') :
- components['cmp' + str(nbComponent)]['frequency'] = extractItem(frequency)
- for phase in component.getElementsByTagName('phase') :
- components['cmp' + str(nbComponent)]['phase'] = extractItem(phase)
- for slope in component.getElementsByTagName('slope') :
- components['cmp' + str(nbComponent)]['slope'] = extractItem(slope)
- for upper_random in component.getElementsByTagName('upper_random') :
- components['cmp' + str(nbComponent)]['upper_random'] = extractItem(upper_random)
- for lower_random in component.getElementsByTagName('lower_random') :
- components['cmp' + str(nbComponent)]['lower_random'] = extractItem(lower_random)
- for constant_value in component.getElementsByTagName('constant_value') :
- components['cmp' + str(nbComponent)]['constant_value'] = extractItem(constant_value)
- for pulse_width in component.getElementsByTagName('pulse_width') :
- components['cmp' + str(nbComponent)]['pulse_width'] = extractItem(pulse_width)
- for polarity in component.getElementsByTagName('polarity') :
- components['cmp' + str(nbComponent)]['polarity'] = extractItem(polarity)
- for ref in component.getElementsByTagName('ref'):
- components['cmp' + str(nbComponent)]['ref'] = extractItem(ref)
- nbTerminal = 1
- components['cmp' + str(nbComponent)]['terminals'] = {}
- for terminal in component.getElementsByTagName('terminal'):
- components['cmp' + str(nbComponent)]['terminals']['t' + str(nbTerminal)] = {}
- for type in terminal.getElementsByTagName('type'):
- components['cmp' + str(nbComponent)]['terminals']['t' + str(nbTerminal)]['type'] = extractItem(type)
- for data_type in terminal.getElementsByTagName('data_type'):
- components['cmp' + str(nbComponent)]['terminals']['t' + str(nbTerminal)]['data_type'] = extractItem(
- data_type)
- nbTerminal += 1
- nbComponent += 1
- for edge in dom.getElementsByTagName('edge'):
- for name in edge.getElementsByTagName('name'):
- edges[extractItem(name)] = {}
- for delay in edge.getElementsByTagName('delay'):
- edges[extractItem(name)]['delay'] = extractItem(delay)
- for source in edge.getElementsByTagName('source'):
- edges[extractItem(name)]['source'] = {}
- for actor in source.getElementsByTagName('actor'):
- edges[extractItem(name)]['source']['actor'] = extractItem(actor)
- for port in source.getElementsByTagName('port'):
- edges[extractItem(name)]['source']['port'] = extractItem(port)
- for Dest in edge.getElementsByTagName('dest'):
- edges[extractItem(name)]['dest'] = {}
- for actor in Dest.getElementsByTagName('actor'):
- edges[extractItem(name)]['dest']['actor'] = extractItem(actor)
- for port in Dest.getElementsByTagName('port'):
- edges[extractItem(name)]['dest']['port'] = extractItem(port)
- nbEdge += 1
- # Analysing datas
- # SDF structure : getting the scheduler from the data in the XMl
- compRef = []
- edgeNames = []
- quu = []
- cpt = 0
- v0 = []
- S0 = []
- b0 = [np.asarray([edges[edge]['delay'] for edge in edges], dtype=np.int64)]
- for comp in components.keys():
- if (components[comp]['name'] != 'Connection' and components[comp]['name'] != 'Solver_SDF'):
- compRef.append(components[comp]['ref'])
- nbComponent -= 2
- nbEdge -= 1
- gamma = np.zeros((nbEdge, nbComponent), dtype=np.int64)
- component_RateByRef = {}
- # getting the rates of the different components
- for component in diagram.diagram.componentList:
- component_ref = component.parameter["Ref"].value
- for terminal in component.terminal:
- key = component_ref + '_' + component.terminal[terminal].name
- component_RateByRef[key] = component.terminal[terminal].rate
- cpt = 0
- for i in edges:
- src_col = compRef.index(edges[i]['source']['actor'])
- snk_col = compRef.index(edges[i]['dest']['actor'])
- gamma[cpt][src_col] = component_RateByRef[edges[i]['source']['actor'] + '_' + edges[i]['source']['port']]
- gamma[cpt][snk_col] = - component_RateByRef[edges[i]['dest']['actor'] + '_' + edges[i]['dest']['port']]
- edgeNames.append(i)
- cpt += 1
- quu = nullspace(gamma).flatten()
- quu = (quu / quu.max())
- quu = np.rint(quu).astype(int)
- rem0 = [quu]
- while rem0[-1].any() != 0:
- v0.append(np.zeros(nbComponent))
- (b1, rem1) = (b0[-1], rem0[-1])
- v1 = np.zeros(nbComponent, dtype=np.int64)
- for i in range(gamma.shape[1]):
- # initialise remainder
- v1[i] = rem1[i]
- # iterate over elements of the column
- for j in range(gamma.shape[0]):
- # Â if actor consumes from this arc
- if gamma[j, i] < 0:
- # set number of reps to lower of v
- # or quotient of no. in buffer divide by rat
- v1[i] = min(v1[i], numpy.true_divide(-1 * b1[j], gamma[j, i]))
- if v1.any() != 0:
- v0[-1] = v1
- b0.append(np.dot(gamma, v1) + b1)
- rem0.append(rem1 - v1)
- # append the necessary firings to the schedule
- for k in range(len(v1)):
- for l in range(int(v1[k])):
- S0.append(compRef[k])
- # creating pointer for the struct of the C
- actor_pointer = []
- for component in components:
- if components[component]["name"] != "Solver_SDF":
- d = collections.OrderedDict()
- for edge in edges:
- for node in edges[edge]:
- if node =="source":
- if edges[edge]["source"]["actor"] == components[component]["ref"]:
- d[edges[edge]["source"]["port"]] = edge
- if node =="dest":
- if edges[edge]["dest"]["actor"] == components[component]["ref"]:
- d[edges[edge]["dest"]["port"]] = edge
- actor_pointer.append(d)
- #Creating the C file
- C_file = '#include <stdio.h>\n'
- C_file += '#include <stdlib.h>\n'
- C_file += '#include <string.h>\n'
- C_file += '#include <math.h>\n\n'
- #Must end all others includes
- C_file += "#define STEP_TIME 0.05\n"
- C_file += "#define END_SIMULATION 4.0\n\n"
- #declare needed variables
- #Beginning the instanciation of the FiFo
- C_file += '///////////////////////////////First In First Out///////////////////////////////\n'
- file = open(outFileAddress, 'w+')
- file.write(C_file)
- file.close()
- # Opening another C file, Fifo
- location = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fifo.txt')
- Fifo_file = open(location, 'r+', encoding='utf-8-sig')
- C_file = Fifo_file.read()
- Fifo_file.close()
- #Beginning the prototypes of each function
- C_file += '\n///////////////////////////////Function prototypes///////////////////////////////\n\n'
- file = open(outFileAddress, 'a', encoding='utf-8-sig')
- file.write(C_file)
- file.close()
- ComponentNameByRef = {}
- # looking at the component list to write the function head
- for component_key in components.keys():
- if components[component_key]['name'] != 'Solver_SDF' and components[component_key]['name'] != 'Connection':
- componentNames.append(components[component_key]['name'])
- nbComponent = componentNames.count(components[component_key]['name'])
- ComponentNameByRef[components[component_key]['ref']] = components[component_key]['name'] + '_' + str(nbComponent - 1)
- C_file = 'int ' + ComponentNameByRef[components[component_key]['ref']] \
- + '( Actor_context *data_structure '
- if (components[component_key]['name'] == 'GenSine' or components[component_key]['name'] == 'GenCos'
- or components[component_key]['name'] == 'GenSineContr' or components[component_key]['name'] == 'GenRamp'):
- C_file += ', float time'
- C_file += ')\n'
- C_file += '{\n'
- C_file += compFunctionC(components, component_key)
- C_file += '}\n\n'
- file = open(outFileAddress, 'a', encoding='utf-8-sig')
- file.write(C_file)
- file.close()
- # Beginning the Main
- C_file = '///////////////////////////////Main function///////////////////////////////\n\n'
- C_file += '\nvoid main (void)\n{\n//initialization of the Fifos\n\n'
- i= 0
- max_size_fifo = 2
- for rate_key in component_RateByRef:
- rate = component_RateByRef[rate_key]
- if rate>max_size_fifo:
- max_size_fifo = rate
- C_file += "\n//max fifo_size = %s \n//note : default size of Fifo is 2 instead of 1, because we want to use an array\n\n" % (str(max_size_fifo))
- i=0
- for edge in edges:
- max_size_fifo = 2
- for token_list in b0:
- if token_list[i]>max_size_fifo:
- max_size_fifo = token_list[i]
- C_file += "float fifodata_%s[2];\n" % edge
- C_file += "Float_fifo *fifo_%s = Fifo_initialize(fifodata_%s, %s);\n\n" % (edge, edge, str(max_size_fifo))
- i += 1
- C_file += "\n //Initialization of the different actor_context\n\n"
- i = 0
- for component in components:
- if components[component]["name"] != "Solver_SDF":
- if(len(actor_pointer[i]) == 1 ):
- value = next (iter (actor_pointer[i].values()))
- C_file += "Float_fifo *tab_tempo%i = fifo_%s;\n" % (i, value)
- else:
- C_file += "Float_fifo *tab_tempo%i[%i] = " % (i, len(actor_pointer[i]))
- C_file += "{"
- for j in range(len(actor_pointer[i])):
- if j>0:
- C_file += ','
- C_file +="fifo_"
- C_file += list(actor_pointer[i].values())[j]
- C_file += "};\n"
- l = actor_pointer[i].keys()
- nb_in = 0
- nb_out = 0
- if 'IN' in l:
- nb_in = 1
- else:
- j = 1
- while(j != 0):
- tempo = "IN" + str(j)
- if tempo in l:
- nb_in += 1
- j += 1
- else:
- j = 0
- if 'OUT' in l:
- nb_out = 1
- else:
- j = 1
- while(j != 0):
- tempo = "OUT" + str(j)
- if tempo in l:
- nb_out += 1
- j += 1
- else:
- j = 0
- C_file += "// nb in : %i, nb_out : %i \n" % (nb_in, nb_out)
- C_file += "Actor_context *struct_%s = Structure_initialize(%i,%i, tab_tempo%i);\n\n" % ( ComponentNameByRef[components[component]["ref"]],nb_in,nb_out,i)
- i += 1
- C_file += "\n//initialization of time :\nfloat time = 0;\n\n"
- C_file += 'while(time < END_SIMULATION)\n {\n'
- C_file += " //incrementing of time\n time = time + STEP_TIME;\n\n"
- for item in S0:
- for component in components:
- if components[component]["ref"] == item:
- #@todo check if some other components need time variable
- if(components[component]["name"] == "GenRamp" or components[component]["name"] == "GenSine" or components[component]["name"] == "GenCos"):
- tempo = '(struct_' + ComponentNameByRef[components[component]["ref"]] + ', time);\n'
- else:
- tempo = '(struct_' + ComponentNameByRef[components[component]["ref"]] + ');\n'
- C_file += ' ' + ComponentNameByRef[components[component]["ref"]] + tempo
- C_file += '\n }\n}'
- file = open(outFileAddress, 'a')
- file.write(C_file)
- file.close()
- """with open(outFileAddress, "a") as file:
- myfile.write(C_file)
- file.close()"""
- def compFunctionC(comp, compKey):
- # looking at the component name to fill the function body with the right functionning
- cfile = ''
- if comp[compKey]['name'] == 'Gain':
- cfile += ' // Gain formula : output = input * gain + offset\n'
- cfile += ' float tempo;\n\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[1], (tempo * ' + comp[compKey]['gain'] + ' + ' \
- + comp[compKey]['offset'] + '));\n'
- cfile += ' return 1;\n'
- if (comp[compKey]['name'] == 'Sum21' or comp[compKey]['name'] == 'Sum22' or comp[compKey]['name'] == 'Sum31'):
- cfile += ' // Component is is a simple sum block, summing all its input in the output\n'
- cfile += ' float tempo1, tempo2'
- if comp[compKey]['name'] == 'Sum31':
- cfile += ', tempo3;\n\n'
- else :
- cfile += ';\n\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo1);\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[1], &tempo2);\n'
- if comp[compKey]['name'] == 'Sum31' :
- cfile += ' Fifo_pop_data(data_structure->Fifo[2], &tempo3);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[3], tempo1 + tempo2 + tempo3);\n'
- else :
- cfile += ' Fifo_push_data(data_structure->Fifo[2], tempo1 + tempo2);\n'
- cfile += 'return 1;\n'
- if (comp[compKey]['name'] == 'Mult21' or comp[compKey]['name'] == 'Mult22' or comp[compKey]['name'] == 'Mult31'):
- cfile += ' // Component is is a simple multiplication block, multiplicating all its input and putting ' \
- 'the result in the output\n'
- cfile += ' float tempo1, tempo2'
- if comp[compKey]['name'] == 'Mult31':
- cfile += ', tempo3;\n\n'
- else:
- cfile += ';\n\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo1);\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[1], &tempo2);\n'
- if comp[compKey]['name'] == 'Mult31':
- cfile += ' Fifo_pop_data(data_structure->Fifo[2], &tempo3);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[3], tempo1 * tempo2 * tempo3);\n'
- else:
- cfile += ' Fifo_push_data(data_structure->Fifo[2], tempo1 * tempo2);\n'
- cfile += ' return 1;\n'
- if (comp[compKey]['name'] == 'GenSine' or comp[compKey]['name'] == 'GenCos') :
- cfile += ' // Component is a '
- if comp[compKey]['name'] == 'GenSine':
- cfile += 'Sine'
- elif comp[compKey]['name'] == 'GenCos':
- cfile += 'Cos'
- cfile += ' generator and the formula used is :\n // amplitude * '
- if comp[compKey]['name'] == 'GenSine':
- cfile += 'sin'
- elif comp[compKey]['name'] == 'GenCos' :
- cfile += 'cos'
- cfile += '(2 * M_PI * frequency * time + phase) + offset\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[0],(float)(' + comp[compKey]['amplitude'] + ' * '
- if comp[compKey]['name'] == 'GenSine':
- cfile += 'sin'
- elif comp[compKey]['name'] == 'GenCos' :
- cfile += 'cos'
- cfile += '( 2 * M_PI * ' + comp[compKey]['frequency'] + ' * time + ' + comp[compKey]['phase'] + ') + ' \
- + comp[compKey]['offset'] + '));\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'GenRandInt' :
- cfile += ' // Component is a random integer generator and the formula used is : output = rand()%(max-min)+min;\n'
- cfile += ' // max and min are the values that limit the generation of thoses integers\n'
- cfile += ' srand(time(NULL));\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[0], (rand()%(' + comp[compKey]['upper_random'] + '-' \
- + comp[compKey]['lower_random'] + ')' + comp[compKey]['lower_random'] + '));\n'
- if comp[compKey]['name'] == 'GenRamp' :
- cfile += ' // component is a ramp generator, using this formula : output = time * slope + offset\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[0], (time * ' + comp[compKey]['slope'] + ' + ' \
- + comp[compKey]['offset'] + '));\n'
- if comp[compKey]['name'] == 'GenPulse' :
- cfile += ' // Component is a Pulse generator.'
- cfile += ' float temp;\nfloat value;\n'
- cfile += ' temp = fmod(time + ' + comp[compKey]['phase'] + ', 1 / ' + comp[compKey]['frequency'] + ');\n'
- cfile += ' if(temp * ' + comp[compKey]['frequency'] + ' <= ' + comp[compKey]['pulse_width'] + ' * 0.01)\n'
- cfile += ' value = ' + comp[compKey]['amplitude'] + ' ;\n'
- cfile += ' else\n'
- cfile += ' value = -' + comp[compKey]['amplitude'] + ' ;\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[0], (value + ' + comp[compKey]['offset'] + '));\n'
- if comp[compKey]['name'] == 'GenConst' :
- cfile += ' Fifo_push_data(data_structure->Fifo[0],' + comp[compKey]['constant_value'] + ');\n'
- if comp[compKey]['name'] == 'GenSineContr' :
- cfile += ' // Data on the first port is the amplitude and the one on the second port is the frequency'
- cfile += ' float tempo1, tempo2;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo1);\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[1], &tempo2);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[2], (tempo1 * sin( 2 * pi * tempo2 * time)));\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'Console' :
- cfile += ' float tempo;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo);\n'
- cfile += ' printf("Output value : %f \\n\\n\\r",tempo);\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'Sqrt' :
- cfile += ' float tempo;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[1], sqrt(tempo));\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'Cos' :
- cfile += ' float tempo;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[1], cos(tempo));\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'Sin' :
- cfile += ' float tempo;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[1], sin(tempo));\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'Abs' :
- cfile += ' float tempo;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[1], abs(tempo));\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'Exp' :
- cfile += ' float tempo;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[1], exp(tempo));\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'Pow2' :
- cfile += ' float tempo;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[1], tempo * tempo);\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'Ln' :
- cfile += ' float tempo;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[1], log(tempo));\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'Log10' :
- cfile += ' float tempo;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[1], log10(tempo));\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'FuncEval' :
- cfile += ' float tempo;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[1], (4*sin(tempo)+tempo));\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'Min' :
- cfile += ' static double minVal;\n float tempo;\n unsigned char lock = 0;\n\n'
- cfile += ' if(lock == 0)\n {\n'
- cfile += ' lock = 1;\n'
- cfile += ' minVal = 1*exp(38);\n }\n\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo);\n'
- cfile += ' if(tempo < minVal)\n'
- cfile += ' minVal = tempo;\n\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[1], minVal);\n'
- cfile += ' return 1 ;\n'
- if comp[compKey]['name'] == 'Max' :
- cfile += ' static double maxVal;\n float tempo;\n unsigned char lock = 0;\n\n'
- cfile += ' if(lock == 0)\n {\n'
- cfile += ' lock = 1;\n'
- cfile += ' maxVal = -1*exp(38);\n }\n\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo);\n'
- cfile += ' if(tempo > maxVal)\n'
- cfile += ' maxVal = tempo;\n\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[1], maxVal);\n'
- cfile += ' return 1 ;\n'
- if comp[compKey]['name'] == 'Ratio' :
- cfile += ' float tempo;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[1], (1.0 / tempo));\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'Buffer':
- cfile += ' float tempo;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[1],tempo);\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'Invertor':
- cfile += ' float tempo;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[1], NOT tempo);\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'And3':
- cfile += ' float tempo1, tempo2, tempo3;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo1);\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[1], &tempo2);\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[2], &tempo3);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[3],(tempo1 and tempo2 and tempo 3));\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'Nand3':
- cfile += ' float tempo1, tempo2, tempo3;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo1);\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[1], &tempo2);\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[2], &tempo3);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[3], NOT(tempo1 and tempo2 and tempo 3));\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'And2':
- cfile += ' float tempo1, tempo2;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo1);\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[1], &tempo2);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[2],(tempo1 and tempo2));\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'Nand2':
- cfile += ' float tempo1, tempo2;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo1);\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[1], &tempo2);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[2], NOT(tempo1 and tempo2));\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'Nor2':
- cfile += ' float tempo1, tempo2;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo1);\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[1], &tempo2);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[2], NOT(tempo1 or tempo2));\n'
- cfile += ' return 1;\n'
- if comp[compKey]['name'] == 'Or2':
- cfile += ' float tempo1, tempo2;\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[0], &tempo1);\n'
- cfile += ' Fifo_pop_data(data_structure->Fifo[1], &tempo2);\n'
- cfile += ' Fifo_push_data(data_structure->Fifo[2],(tempo1 or tempo2));\n'
- cfile += ' return 1;\n'
- return cfile
- def constantValuesXML(comp, tabgain, taboffs, item, ItemNb, doc, tabslope, tabconst, tabamp, tabfreq, tabphase,
- tabpolarity, tabpulseWidth, tabUpRand, tabLowRand):
- # extract informations of the graph into the XML for others exports
- if (comp.className == 'Gain' or comp.className == 'Integ'):
- tabgain.append(doc.createElement('gain'))
- item[ItemNb].appendChild(tabgain[ItemNb])
- tabgain[ItemNb].appendChild(doc.createTextNode(str(comp.parameter['Gain'].value)))
- else:
- tabgain.append([])
- if (comp.className == 'Gain' or comp.className == 'GenPulse' or comp.className == 'GenRamp' or
- comp.className == 'GenSine' or comp.className == 'GenCos'):
- taboffs.append(doc.createElement('offset'))
- item[ItemNb].appendChild(taboffs[ItemNb])
- taboffs[ItemNb].appendChild(doc.createTextNode(str(comp.parameter['Offset'].value)))
- else:
- taboffs.append([])
- if (comp.className == 'GenRamp'):
- tabslope.append(doc.createElement('slope'))
- item[ItemNb].appendChild(tabslope[ItemNb])
- tabslope[ItemNb].appendChild(doc.createTextNode(str(comp.parameter['Slope'].value)))
- else:
- tabslope.append([])
- if (comp.className == 'GenConst'):
- tabconst.append(doc.createElement('constant_value'))
- item[ItemNb].appendChild(tabconst[ItemNb])
- tabconst[ItemNb].appendChild(doc.createTextNode(str(comp.parameter['Value'].value)))
- elif comp.className == 'FuncEval' :
- tabconst.append(doc.createElement('constant_value'))
- item[ItemNb].appendChild(tabconst[ItemNb])
- tabconst[ItemNb].appendChild(doc.createTextNode(str(comp.parameter['f(x)'].value)))
- else:
- tabconst.append([])
- if (comp.className == 'GenSine' or comp.className == 'GenPulse' or comp.className == 'GenCos'):
- tabamp.append(doc.createElement('amplitude'))
- item[ItemNb].appendChild(tabamp[ItemNb])
- tabamp[ItemNb].appendChild(doc.createTextNode(str(comp.parameter['Amplitude'].value)))
- tabfreq.append(doc.createElement('frequency'))
- item[ItemNb].appendChild(tabfreq[ItemNb])
- tabfreq[ItemNb].appendChild(doc.createTextNode(str(comp.parameter['Frequency'].value)))
- tabphase.append(doc.createElement('phase'))
- item[ItemNb].appendChild(tabphase[ItemNb])
- tabphase[ItemNb].appendChild(doc.createTextNode(str(comp.parameter['Phase'].value)))
- else:
- tabamp.append([])
- tabfreq.append([])
- tabphase.append([])
- if (comp.className == 'GenPulse'):
- tabpolarity.append(doc.createElement('polarity'))
- item[ItemNb].appendChild(tabpolarity[ItemNb])
- tabpolarity[ItemNb].appendChild(doc.createTextNode(str(comp.parameter['Polarity'].value)))
- tabpulseWidth.append(doc.createElement('pulse_width'))
- item[ItemNb].appendChild(tabpulseWidth[ItemNb])
- tabpulseWidth[ItemNb].appendChild(doc.createTextNode(str(comp.parameter['Pulse Width'].value)))
- else:
- tabpolarity.append([])
- tabpulseWidth.append([])
- if (comp.className == 'GenRandInt'):
- tabUpRand.append(doc.createElement('upper_random'))
- item[ItemNb].appendChild(tabUpRand[ItemNb])
- tabUpRand[ItemNb].appendChild(doc.createTextNode(str(comp.parameter['Upper limit'].value)))
- tabLowRand.append(doc.createElement('lower_random'))
- item[ItemNb].appendChild(tabLowRand[ItemNb])
- tabLowRand[ItemNb].appendChild(doc.createTextNode(str(comp.parameter['Lower limit'].value)))
- else:
- tabLowRand.append([])
- tabUpRand.append([])
- def convertXML(diagram):
- ItemNb = 0
- NetNb = 0
- ConstantNb = 0
- item = []
- name = []
- ref = []
- gainval = []
- offs = []
- slope = []
- constValue = []
- amp = []
- freq = []
- phase = []
- polarity = []
- pulseWidth = []
- upperRand = []
- lowerRand = []
- terminal = [] # terminal[Itemnb][TerminalNb]
- Ttype = []
- TDataType = []
- net = []
- netName = []
- netStart = []
- netEnd = []
- netDelay = []
- netSrcTerm = []
- netSnkTerm = []
- netNameCheck = []
- netActorSrc = []
- netActorSnk = []
- constant = []
- constantRef = []
- constantValue = []
- doc = minidom.Document()
- doc.appendChild(doc.createComment("Diagram to XML Exporter"))
- root = doc.createElement('root')
- doc.appendChild(root)
- for Component in diagram.diagram.componentList:
- if Component.className != 'Constant':
- item.append(doc.createElement('component'))
- root.appendChild(item[ItemNb])
- name.append(doc.createElement('name'))
- item[ItemNb].appendChild(name[ItemNb])
- name[ItemNb].appendChild(doc.createTextNode(Component.className))
- ref.append(doc.createElement('ref'))
- item[ItemNb].appendChild(ref[ItemNb])
- ref[ItemNb].appendChild(doc.createTextNode(Component.parameter['Ref'].value))
- constantValuesXML(Component, gainval, offs, item, ItemNb, doc, slope, constValue, amp, freq, phase,
- polarity, pulseWidth, upperRand, lowerRand)
- TerminalNb = 0
- terminal.append([])
- Ttype.append([])
- TDataType.append([])
- for key in Component.terminal.keys():
- terminal[ItemNb].append(doc.createElement('terminal'))
- item[ItemNb].appendChild(terminal[ItemNb][TerminalNb])
- Ttype[ItemNb].append(doc.createElement('type'))
- terminal[ItemNb][TerminalNb].appendChild(Ttype[ItemNb][TerminalNb])
- if Component.terminal[key].termType == 1:
- Ttype[ItemNb][TerminalNb].appendChild(doc.createTextNode('CONN'))
- elif Component.terminal[key].termType == 2:
- Ttype[ItemNb][TerminalNb].appendChild(doc.createTextNode('IN'))
- elif Component.terminal[key].termType == 4:
- Ttype[ItemNb][TerminalNb].appendChild(doc.createTextNode('OUT'))
- elif Component.terminal[key].termType == 8:
- Ttype[ItemNb][TerminalNb].appendChild(doc.createTextNode('INOUT'))
- TDataType[ItemNb].append(doc.createElement('data_type'))
- terminal[ItemNb][TerminalNb].appendChild(TDataType[ItemNb][TerminalNb])
- if str(type(Component.terminal[key].value)) == "<class 'float'>":
- TDataType[ItemNb][TerminalNb].appendChild(doc.createTextNode('float'))
- TerminalNb += 1
- ItemNb += 1
- for Component in diagram.diagram.componentList:
- if Component.className == 'Constant':
- constant.append(doc.createElement('constant'))
- root.appendChild(constant[ConstantNb])
- constantRef.append(doc.createElement('name'))
- constant[ConstantNb].appendChild(constantRef[ConstantNb])
- constantRef[ConstantNb].appendChild(doc.createTextNode(Component.parameter['Ref'].value))
- for key in Component.terminal.keys():
- constantValue.append(doc.createElement('value'))
- constant[ConstantNb].appendChild(constantValue[ConstantNb])
- constantValue[ConstantNb].appendChild(doc.createTextNode(str(Component.terminal[key].value)))
- ConstantNb += 1
- if diagram.simEngine is None:
- diagram.simEngine = Action(diagram.diagram)
- netInfos = diagram.simEngine.checkNetwork()
- for key in netInfos.keys():
- if key not in netNameCheck:
- netNameCheck.append(key)
- net.append(doc.createElement('edge'))
- root.appendChild(net[NetNb])
- netName.append(doc.createElement('name'))
- net[NetNb].appendChild(netName[NetNb])
- netName[NetNb].appendChild(doc.createTextNode(key))
- netDelay.append(doc.createElement('delay'))
- net[NetNb].appendChild(netDelay[NetNb])
- netDelay[NetNb].appendChild(doc.createTextNode(str(netInfos[key][4])))
- netStart.append(doc.createElement('source'))
- net[NetNb].appendChild(netStart[NetNb])
- netActorSrc.append(doc.createElement('actor'))
- netStart[NetNb].appendChild(netActorSrc[NetNb])
- netActorSrc[NetNb].appendChild(doc.createTextNode(netInfos[key][0]))
- netSrcTerm.append(doc.createElement('port'))
- netStart[NetNb].appendChild(netSrcTerm[NetNb])
- netSrcTerm[NetNb].appendChild(doc.createTextNode(str(netInfos[key][1])))
- netEnd.append(doc.createElement('dest'))
- net[NetNb].appendChild(netEnd[NetNb])
- netActorSnk.append(doc.createElement('actor'))
- netEnd[NetNb].appendChild(netActorSnk[NetNb])
- netActorSnk[NetNb].appendChild(doc.createTextNode(netInfos[key][2]))
- netSnkTerm.append(doc.createElement('port'))
- netEnd[NetNb].appendChild(netSnkTerm[NetNb])
- netSnkTerm[NetNb].appendChild(doc.createTextNode(str(netInfos[key][3])))
- NetNb += 1
- xml_file = doc.toprettyxml(indent=' ')
- return xml_file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement