def __findEntryByDestination(self, _handle, _port, _partialTable): for entry in _partialTable: if cUtils.compareStringsIgnoreCase( entry.get("DstBlockHandle", ""), _handle) and (_port is None or cUtils.compareStringsIgnoreCase( entry.get("DstPort"), _port)): return entry return None
def getBlockById(self, blockId): result = {} if not isinstance(blockId, str): blockId = repr(blockId) for blk in self.getAllBlocks(): if cUtils.compareStringsIgnoreCase( repr(blk.get("Handle")), blockId) or cUtils.compareStringsIgnoreCase( blk.get("Name"), blockId) or cUtils.compareStringsIgnoreCase( blk.get("Path"), blockId) or cUtils.compareStringsIgnoreCase( blk.get("Origin_path"), blockId): result = blk break return result
def __findAllEntriesByDestination(self, _handle): allEntries = [] for entry in self.connectionTable: if cUtils.compareStringsIgnoreCase(entry.get("DstBlockHandle", ""), _handle): allEntries.append(entry) return allEntries
def __getAllComputationalBlocks(self): computationalBlocks = [] for blk in self.getAllBlocks(): if not any( cUtils.compareStringsIgnoreCase( s, blk.get("BlockType", "None")) for s in self.noncomputationalBlocks): computationalBlocks.append(blk) return computationalBlocks
def getBlockPredecessors(self, blockHandle): predecessors = [] for entry in self.connectionTable: if cUtils.compareStringsIgnoreCase(entry.get("DstBlockHandle", ""), blockHandle): predecessorBlock = self.getBlockById( entry.get("SrcBlockHandle", "")) predecessors.append(predecessorBlock) return predecessors
def parseModel(self): parsedSimulinkModel = self.__createParsedSimulinkModel() for sBlock in self.allBlocks: if not cUtils.compareStringsIgnoreCase( sBlock.get("ExecutionOrder", "-1"), "-1"): parsedSimulinkModel.addBlock( self.__createParsedSimulinkBlock(sBlock)) pass return parsedSimulinkModel
def __getAllPortBlocks(self): # this needs to be optimized later allPortBlocks = [] for blk in self.getAllBlocks(): if any( cUtils.compareStringsIgnoreCase( s, blk.get("BlockType", "None")) for s in self.portBlockTypes): allPortBlocks.append(blk) return allPortBlocks
def packAllBlocksForTransformation(self): packedBlocksForTransformation = [] for block in self.allBlocks: if not any( cUtils.compareStringsIgnoreCase(nonComputationalBlockType, blockCopy.get("BlockType")) for nonComputationalBlockType in self.noncomputationalBlocks): packedBlocksForTransformation.append( self.packBlockForTransformation(block)) return packedBlocksForTransformation
def __calculateSampleTimes(self): for blk in self.allBlocks: if any( cUtils.compareStringsIgnoreCase(s, blk.get( "BlockType", "")) for s in self.compositeBlockTypes): blk["calculated_sample_time"] = self.__calculateSubSystemSampleTime( blk) else: parentSS = self.getBlockById( cUtils.stringify(blk.get("ParentHandle"))) blk["calculated_sample_time"] = self.__calculateSubSystemSampleTime( parentSS) return
def __extractSignalType(self, block, portNumber): signalType = "" try: compiledInPortTypes = block.get("CompiledPortDataTypes", {}) if not (cUtils.compareStringsIgnoreCase(block.get("BlockType", ""), "inport") or cUtils.compareStringsIgnoreCase( block.get("BlockType", ""), "Outport")): compiledInPortTypes = compiledInPortTypes.get("Inport") elif cUtils.compareStringsIgnoreCase(block.get("BlockType", ""), "inport"): compiledInPortTypes = compiledInPortTypes.get("Outport") elif cUtils.compareStringsIgnoreCase(block.get("BlockType", ""), "outport"): compiledInPortTypes = compiledInPortTypes.get("Inport") if type(compiledInPortTypes) is not list: compiledInPortTypes = [compiledInPortTypes] signalType = compiledInPortTypes[int(portNumber) - 1] except Exception as exc: self.logger.exception("extract signal failed: {0}:{1}:{2}".format( block.get("BlockType"), block.get("Origin_path"), exc)) pass return signalType
def __mapConnectionSource(self, connection, partialTable): """ Initially the connections have been created. However, some of the sources might be an atomic computational block and in such cases we must find the atomic computational block which writes to that signal """ sourceBlock = self.getBlockById(connection.get("SrcBlockHandle", "")) if cUtils.compareStringsIgnoreCase(sourceBlock.get("BlockType", ""), "subsystem"): connection = self.__traceSubSystemBlock(sourceBlock, connection, partialTable) if cUtils.compareStringsIgnoreCase(sourceBlock.get("BlockType", ""), "demux"): connection = self.__traceDemuxBlock(sourceBlock, connection, partialTable) if cUtils.compareStringsIgnoreCase(sourceBlock.get("BlockType", ""), "mux"): connection = self.__traceMuxBlock(sourceBlock, connection, partialTable) if cUtils.compareStringsIgnoreCase(sourceBlock.get("BlockType", ""), "inport"): connection = self.__traceInPortBlock(sourceBlock, connection, partialTable) return connection
def __calculateSubSystemSampleTime(self, ssBlock): sampleTime = -1.0 istriggered = False portConectivity = ssBlock.get("PortConnectivity", {}) if not isinstance(portConectivity, list): portConectivity = [portConectivity] for line in portConectivity: if cUtils.compareStringsIgnoreCase(line.get("Type", ""), "Trigger"): triggerBlock = self.getBlockById(line.get("SrcBlock", "")) sampleTime = triggerBlock.get("sample_time", "-1") istriggered = True if not istriggered and not (ssBlock.get("ParentHandle", None) is None): parentSubSystemBlock = self.getBlockById( cUtils.stringify(ssBlock.get("ParentHandle", ""))) sampleTime = self.__calculateSubSystemSampleTime( parentSubSystemBlock) return sampleTime
def __findOutPortBlockByPortNumner(self, ssBlock, portNumber): result = None ssBlockContent = ssBlock.get("Content", {}) for innerBlockId in ssBlockContent: try: ssInnerBlock = ssBlockContent.get(innerBlockId, {}) if not isinstance(portNumber, int): portNumber = int(portNumber) intPortNumber = portNumber + 1 if cUtils.compareStringsIgnoreCase( ssInnerBlock.get("BlockType", ""), "Outport"): outPortBlockNumber = int(ssInnerBlock.get("Port", "-1")) if intPortNumber == outPortBlockNumber: result = ssInnerBlock break except Exception as e: self.logger.exception(e) return result
def __getAllBlocks(self): allBlocks = [] firstLevelComposite = 0 content = self.rawSimulinkModelJson.get(self.getModelName()).get( "Content", {}) blocks = 0 for blkId in content: blocks = blocks + 1 try: blk = content.get(blkId) if any( cUtils.compareStringsIgnoreCase( s, blk.get("BlockType", "")) for s in self.compositeBlockTypes): allBlocks.extend(self.__flattenSubSystem(blk)) else: allBlocks.append(blk) except Exception as e: self.logger.exception(e) return allBlocks
def __flattenSubSystem(self, ssBlock, sampleTime=None): # this is fully implemented allBlocks = [ssBlock] innerContents = ssBlock.get("Content", {}) ssBlockId = ssBlock.get("Handle", "") for blkName in innerContents: blk = innerContents.get(blkName) try: if any( cUtils.compareStringsIgnoreCase( s, blk.get("BlockType", None)) for s in self.compositeBlockTypes): blk["ParentHandle"] = repr(ssBlockId) allBlocks.extend(self.__flattenSubSystem(blk, sampleTime)) else: blk["ParentHandle"] = repr(ssBlockId) blk["calculated_sample_time"] = sampleTime allBlocks.append(blk) except Exception as e: self.logger.exception(e) return allBlocks