def handle(self): """ Handle the request. It should contain the directory, model name and tranformation name. The handle will make a Himesis of the model The handle will make a Himesis of the rules and a schedule The handle will execute the transformation The handle will export the transformed model to Simulink @return: None """ sys.stdout.write( "started thread") self.mh = self.server.getFromPool() self.wfile.write('RDY') data = self.rfile.readline().rstrip('\n') self.wfile.write('OK') sys.stdout.write(data) path,model,transformation = data.split(';') self.mh.chDir(path) # Model to Himesis modelToHimesis = SimulinkModelToHimesis(self.mh,model,path) modelToHimesis.SimulinkModelToHimesis() # Transfornation to T-Core transformationToHimesis = SimulinkTransformationToHimesis(transformation,path,self.mh) transformationToHimesis.SimulinkTransformationModelToHimesis() # Execute the Transformation exec("from Server.temp."+ Himesis.standardize_name(model) + " import "+ Himesis.standardize_name(model)) exec("import Server.temp.T_" + transformation) packet = Packet() exec("packet.graph = "+ Himesis.standardize_name(model) + "()") exec('packet = Server.temp.T_'+ transformation +'.packet_in(packet)') #export: simulinkExport = SimulinkExporter(model,self.mh,packet.graph) simulinkExport.exportSimulink() self.wfile.write('finished')
def run(self, path, model, opt_name): if not self.mh == None: start = time.time() self.mh.chDir(path) # turn Simulink model into himesis graph modelToHimesis = SimulinkModelToHimesis(self.mh, model, path) modelToHimesis.SimulinkModelToHimesis() end = time.time() print("Time taken to import from Simulink: " + str(end - start) + " seconds") # draw model # print("Start drawing") # self.mh.drawSystem(model, "~/") # print("End drawing") start = time.clock() hToCBD = HimesisToCBD() self.model = hToCBD.convertFile("himesis/" + Himesis.standardize_name(model) + ".py") end = time.clock() print("Time taken for Himesis to CBD: " + str(end - start) + " seconds") # TODO: only needed for dep graph, should remove this start = time.clock() self.simulator = CBDsimulator(self.model) end = time.clock() print("Time taken to build simulator: " + str(end - start) + " seconds") opt = opt_name(self.simulator, self.mh) self.model = opt.optimize(self.model) start = time.clock() CBDToH = CBDToHimesis() h = CBDToH.convert(self.model) h2 = CBDToH.convert(self.model, False) h.compile("himesis/") end = time.clock() print("Time taken for CBD to Himesis: " + str(end - start) + " seconds") if not self.mh == None: start = time.clock() simulinkExport = SimulinkExporter(model, self.mh, h) simulinkExport.exportSimulink() end = time.clock() print("Time taken to export to Simulink: " + str(end - start) + " seconds") self.mh.endLib()