Example #1
0
    def getRoot(self, name):
        try:
            uri = self._ns.lookup("{}.{}".format(self._group, name))
            ret = PyroRoot(node=Pyro4.Proxy(uri), daemon=self._pyroDaemon)
            self._pyroDaemon.register(ret)

            ret._node.addVarListener(ret)
            return ret
        except:
            raise pr.NodeError("PyroClient Failed to find {}.{}.".format(
                self._group, name))
Example #2
0
    def __init__(self, group, localAddr=None, nsAddr=None):
        self._group = group

        Pyro4.config.THREADPOOL_SIZE = 100
        Pyro4.config.SERVERTYPE = "multiplex"
        Pyro4.config.POLLTIMEOUT = 3

        Pyro4.util.SerializerBase.register_dict_to_class(
            "collections.OrderedDict", recreate_OrderedDict)

        if nsAddr is None:
            nsAddr = localAddr

        try:
            self._ns = Pyro4.locateNS(host=nsAddr)
        except:
            raise pr.NodeError("PyroClient Failed to find nameserver")

        self._pyroDaemon = Pyro4.Daemon(host=localAddr)

        self._pyroThread = threading.Thread(
            target=self._pyroDaemon.requestLoop)
        self._pyroThread.start()
Example #3
0
    def start(self, timeout=1.0, initRead=False, initWrite=False, pollEn=True, zmqPort=9099):
        """Setup the tree. Start the polling thread."""

        if self._running:
            raise pr.NodeError("Root is already started! Can't restart!")

        # Create poll queue object
        if pollEn:
            self._pollQueue = pr.PollQueue(root=self)

        # Call special root level rootAttached
        self._rootAttached()

        # Get full list of Devices and Blocks
        tmpList = []
        for d in self.deviceList:
            tmpList.append(d)
            for b in d._blocks:
                if isinstance(b, pr.RemoteBlock):
                    tmpList.append(b)

        # Sort the list by address/size
        tmpList.sort(key=lambda x: (x.memBaseId, x.address, x.size))

        # Look for overlaps
        for i in range(1,len(tmpList)):

            self._log.debug("Comparing {} with address={:#x} to {} with address={:#x} and size={}".format(
                            tmpList[i].path,  tmpList[i].address,
                            tmpList[i-1].path,tmpList[i-1].address, tmpList[i-1].size))

            # Detect overlaps
            if (tmpList[i].size != 0) and (tmpList[i].memBaseId == tmpList[i-1].memBaseId) and \
               (tmpList[i].address < (tmpList[i-1].address + tmpList[i-1].size)):

                # Allow overlaps between Devices and Blocks if the Device is an ancestor of the Block and the block allows overlap.
                if not (isinstance(tmpList[i-1],pr.Device) and isinstance(tmpList[i],pr.BaseBlock) and \
                        (tmpList[i].path.find(tmpList[i-1].path) == 0 and tmpList[i]._overlapEn)):

                    print("\n\n\n------------------------ Memory Overlap Warning !!! --------------------------------")
                    print("{} at address={:#x} overlaps {} at address={:#x} with size={}".format(
                          tmpList[i].path,tmpList[i].address,
                          tmpList[i-1].path,tmpList[i-1].address,tmpList[i-1].size))
                    print("This warning will be replaced with an exception in the next release!!!!!!!!")

                    #raise pr.NodeError("{} at address={:#x} overlaps {} at address={:#x} with size={}".format(
                    #                   tmpList[i].name,tmpList[i].address,
                    #                   tmpList[i-1].name,tmpList[i-1].address,tmpList[i-1].size))

        # Set timeout if not default
        if timeout != 1.0:
            for key,value in self._nodes.items():
                value._setTimeout(timeout)

        # Start ZMQ server if enabled
        if zmqPort is not None:
            self._structure = jsonpickle.encode(self)
            self._zmqServer = pr.interfaces.ZmqServer(root=self,addr="*",port=zmqPort)

        # Read current state
        if initRead:
            self._read()

        # Commit default values
        # Read did not override defaults because set values are cached
        if initWrite:
            self._write()

        # Start update thread
        self._updateThread = threading.Thread(target=self._updateWorker)
        self._updateThread.start()

        # Start poller if enabled
        if pollEn:
            self._pollQueue._start()

        self._running = True
Example #4
0
    def start(self):
        """Setup the tree. Start the polling thread."""

        if self._running:
            raise pr.NodeError("Root is already started! Can't restart!")

        # Call special root level rootAttached
        self._rootAttached()

        # Get full list of Devices and Blocks
        tmpList = []
        for d in self.deviceList:
            tmpList.append(d)
            for b in d._blocks:
                if isinstance(b, rim.Block):
                    tmpList.append(b)

        # Sort the list by address/size
        tmpList.sort(key=lambda x: (x._reqSlaveId(), x.address, x.size))

        # Look for overlaps
        for i in range(1, len(tmpList)):

            self._log.debug(
                "Comparing {} with address={:#x} to {} with address={:#x} and size={}"
                .format(tmpList[i].path, tmpList[i].address,
                        tmpList[i - 1].path, tmpList[i - 1].address,
                        tmpList[i - 1].size))

            # Detect overlaps
            if (tmpList[i].size != 0) and (tmpList[i]._reqSlaveId() == tmpList[i-1]._reqSlaveId()) and \
               (tmpList[i].address < (tmpList[i-1].address + tmpList[i-1].size)):

                # Allow overlaps between Devices and Blocks if the Device is an ancestor of the Block and the block allows overlap.
                # Check for instances when device comes before block and when block comes before device
                # This will be removed in the future and an error will always be raised
                if (not (isinstance(tmpList[i-1],pr.Device) and isinstance(tmpList[i],rim.Block) and (tmpList[i].path.find(tmpList[i-1].path) == 0 and tmpList[i].overlapEn))) and \
                        (not (isinstance(tmpList[i],pr.Device) and isinstance(tmpList[i-1],rim.Block) and (tmpList[i-1].path.find(tmpList[i].path) == 0 and tmpList[i-1].overlapEn))):

                    raise pr.NodeError(
                        "{} at address={:#x} overlaps {} at address={:#x} with size={}"
                        .format(tmpList[i].path, tmpList[i].address,
                                tmpList[i - 1].path, tmpList[i - 1].address,
                                tmpList[i - 1].size))

                # Deprecation Error
                print("")
                print(
                    "========== Deprecation Warning ==============================="
                )
                print(
                    " Detected overlap between the following Devices/Blocks        "
                )
                print("    {} at address={:#x} wht size {}".format(
                    tmpList[i].path, tmpList[i].address, tmpList[i].size))
                print("    {} at address={:#x} wht size {}".format(
                    tmpList[i - 1].path, tmpList[i - 1].address,
                    tmpList[i - 1].size))
                print(
                    " Creating these types of overlaps can generate inconsistencies"
                )
                print(
                    " in the variable state and can cause errors. Please consider  "
                )
                print(
                    " using a listDevice and or a MemoryDevice class instead.      "
                )
                print(
                    " Link variables can be used to map multiple variables to the  "
                )
                print(
                    " underlying address space. Future releases of Rogue will treat"
                )
                print(" these overlaps as errors.")
                print(
                    "=============================================================="
                )

        # Set timeout if not default
        if self._timeout != 1.0:
            for key, value in self._nodes.items():
                value._setTimeout(self._timeout)

        # Start ZMQ server if enabled
        if self._serverPort is not None:
            self._zmqServer = pr.interfaces.ZmqServer(root=self,
                                                      addr="*",
                                                      port=self._serverPort)
            self._serverPort = self._zmqServer.port()
            print(
                f"Start: Started zmqServer on ports {self._serverPort}-{self._serverPort+2}"
            )

        # Start sql interface
        if self._sqlUrl is not None:
            self._sqlLog = pr.interfaces.SqlLogger(self._sqlUrl)

        # Start update thread
        self._running = True
        self._updateThread = threading.Thread(target=self._updateWorker)
        self._updateThread.start()

        # Start heartbeat
        if self._doHeartbeat:
            self._hbeatThread = threading.Thread(target=self._hbeatWorker)
            self._hbeatThread.start()

        # Start interfaces and protocols
        pr.Device._start(self)

        # Read current state
        if self._initRead:
            self._read()

        # Commit default values
        # Read did not override defaults because set values are cached
        if self._initWrite:
            self._write()

        # Start poller if enabled
        self._pollQueue._start()
        self.PollEn.set(self._pollEn)
Example #5
0
 def _setDict(self, d, writeEach, modes=['RW']):
     raise pr.NodeError('_setDict not supported in VirtualNode')
Example #6
0
 def _getDict(self, modes):
     raise pr.NodeError('_getDict not supported in VirtualNode')
Example #7
0
 def _rootAttached(self, parent, root):
     raise pr.NodeError('_rootAttached not supported in VirtualNode')
Example #8
0
 def callRecursive(self, func, nodeTypes=None, **kwargs):
     raise pr.NodeError('callRecursive not supported in VirtualNode')
Example #9
0
 def add(self, node):
     raise pr.NodeError('add not supported in VirtualNode')
Example #10
0
 def addToGroup(self, group):
     raise pr.NodeError('addToGroup not supported in VirtualNode')
Example #11
0
 def _setDict(self, *args, **kwargs):
     raise pr.NodeError('_setDict not supported in VirtualNode')
Example #12
0
 def removeFromGroup(self, group):
     raise pr.NodeError('removeFromGroup not supported in VirtualNode')