Example #1
0
    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
Example #2
0
 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
Example #3
0
 def __findAllEntriesByDestination(self, _handle):
     allEntries = []
     for entry in self.connectionTable:
         if cUtils.compareStringsIgnoreCase(entry.get("DstBlockHandle", ""),
                                            _handle):
             allEntries.append(entry)
     return allEntries
Example #4
0
 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
Example #5
0
 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
Example #6
0
    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
Example #7
0
 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
Example #8
0
 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
Example #9
0
 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
Example #10
0
 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
Example #11
0
 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
Example #12
0
 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
Example #13
0
 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
Example #14
0
 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
Example #15
0
 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