Ejemplo n.º 1
0
    def _handleReadRequest(self, request):
        requestHeader = request.getHeader()
        words = IPbusHeader.getWords(requestHeader)
        baseAddr = request.getBody()[0]
        chipsLog.debug("Read requested on Addr=0x" + uInt32HexStr(baseAddr))

        # Response header is the request header but with the Info Code field changed to INFO_CODE_RESPONSE
        responseHeader = IPbusHeader.updateInfoCode(
            requestHeader, IPbusHeader.INFO_CODE_RESPONSE)

        # The (baseAddr & 0xffffffff) forces baseAddr to be in unsigned form (i.e. 0xfffffffc, say, rather than -4)
        if (
                baseAddr & 0xffffffff
        ) == 0xffffffff:  # A read on this register is a Dummy Hardware Reset Request.
            chipsLog.info(
                "** Dummy Hardware reset request received! Zeroing all registers. **"
            )
            self._registers.clear()

        responseBody = []
        appendToResponseBody = responseBody.append  # This is for a speed optimisation

        for offset in range(words):
            currentReg = baseAddr + offset
            # Create these registers if they don't already exist.
            if currentReg not in self._registers:
                self._registers[currentReg] = 0
            appendToResponseBody(self._registers[currentReg])
        return TransactionElement.makeFromHeaderAndBody(
            responseHeader, responseBody)
Ejemplo n.º 2
0
    def serveForever(self):
        """The only function any user of this class needs to run!
        
        Receives, acts on, and responds to UDP control packets as the Mini-T (or similar hardware) would.
        Packets are received by the main thread and queued for action and response by a second thread.
        """
        chipsLog.info("Dummy Hardware UDP Server starting")
        # This starts the packet "act and respond" handler thread
        self.start()

        while not self.stopServing:
            try:
                data, addr = self._socket.recvfrom(DummyHardware.SOCKET_BUFFER_SIZE)
            except KeyboardInterrupt:
                chipsLog.warning("\nKeyboard interrupt (ctrl-c) received whilst waiting for incoming UDP packet")
                self._stopServingAndJoinThreads()
                return
            except:
                chipsLog.warning("\nException caught whilst waiting for incoming UDP packet")
                self._stopServingAndJoinThreads()
                return

            if not data:
                chipsLog.warning("Socket received an empty packet from " + repr(addr) + \
                                 ".  Assuming socket now closed.\nTerminating dummy hardware server...")
                self._stopServingAndJoinThreads()
                return
            else:
                chipsLog.debug("\nReceived packet from " + repr(addr))
                transaction = Transaction.constructHostTransaction(data, addr)
                self._transaction_queue.put(transaction)
Ejemplo n.º 3
0
    def serveForever(self):
        """The only function any user of this class needs to run!
        
        Receives, acts on, and responds to TCP control packets as the Mini-T (or similar hardware) would.
        Packets are received by the main thread and queued for action and response by a second thread.
        """
        chipsLog.info("Dummy Hardware TCP Server starting")
        # This starts the packet "act and respond" handler thread
        self.start()

        try:
            chipsLog.debug("Awaiting connection...")
            self._connectedSocket, addr = self._socket.accept()  # TCP
            chipsLog.debug("Client connection accepted.")
        except KeyboardInterrupt:
            chipsLog.warning(
                "\nKeyboard interrupt (ctrl-c) received whilst waiting for a TCP connection"
            )
            self._stopServingAndJoinThreads()
            return

        while not self.stopServing:
            try:
                data = self._connectedSocket.recv(
                    DummyHardware.SOCKET_BUFFER_SIZE)  # TCP
            except KeyboardInterrupt:
                chipsLog.warning(
                    "\nKeyboard interrupt (ctrl-c) received whilst waiting for incoming TCP packet"
                )
                self._stopServingAndJoinThreads()
                return
            except:
                chipsLog.warning(
                    "\nException caught whilst waiting for incoming TCP packet"
                )
                self._stopServingAndJoinThreads()
                return

            if not data:
                chipsLog.debug("TCP socket received an empty packet from " +
                               repr(addr) + ": assuming connection closed.")
                try:
                    chipsLog.debug("Awaiting new connection...")
                    self._connectedSocket, addr = self._socket.accept()  # TCP
                    chipsLog.debug("Client connection accepted.")
                    continue
                except KeyboardInterrupt:
                    chipsLog.warning(
                        "\nKeyboard interrupt (ctrl-c) received whilst waiting for a TCP connection"
                    )
                    self._stopServingAndJoinThreads()
                    return

            chipsLog.debug("\nReceived TCP packet from " + repr(addr))
            transaction = Transaction.constructHostTransaction(data, addr)
            self._transaction_queue.put(transaction)

        chipsLog.info("Dummy Hardware TCP Server stopping.")
Ejemplo n.º 4
0
 def run(self):
     """Start the transaction handler thread"""
     chipsLog.info("Transaction handler thread started")
     while not self.stopServing:
         if self._transaction_queue.empty():
             sleep(0.001)
         else:
             transaction = self._transaction_queue.get()
             self._actAndRespond(transaction)
     chipsLog.info("Transaction handler thread stopping")
Ejemplo n.º 5
0
 def run(self):
     """Start the transaction handler thread"""
     chipsLog.info("Transaction handler thread started")
     while not self.stopServing:
         if self._transaction_queue.empty():
             sleep(0.001)
         else:
             transaction = self._transaction_queue.get()
             self._actAndRespond(transaction)
     chipsLog.info("Transaction handler thread stopping")
Ejemplo n.º 6
0
    def serveForever(self):
        """The only function any user of this class needs to run!
        
        Receives, acts on, and responds to TCP control packets as the Mini-T (or similar hardware) would.
        Packets are received by the main thread and queued for action and response by a second thread.
        """
        chipsLog.info("Dummy Hardware TCP Server starting")
        # This starts the packet "act and respond" handler thread
        self.start()

        try:
            chipsLog.debug("Awaiting connection...")
            self._connectedSocket, addr = self._socket.accept()  # TCP
            chipsLog.debug("Client connection accepted.")            
        except KeyboardInterrupt:
            chipsLog.warning("\nKeyboard interrupt (ctrl-c) received whilst waiting for a TCP connection")
            self._stopServingAndJoinThreads()
            return            

        while not self.stopServing:
            try:
                data = self._connectedSocket.recv(DummyHardware.SOCKET_BUFFER_SIZE)  # TCP
            except KeyboardInterrupt:
                chipsLog.warning("\nKeyboard interrupt (ctrl-c) received whilst waiting for incoming TCP packet")
                self._stopServingAndJoinThreads()
                return
            except:
                chipsLog.warning("\nException caught whilst waiting for incoming TCP packet")
                self._stopServingAndJoinThreads()
                return

            if not data:
                chipsLog.debug("TCP socket received an empty packet from " + repr(addr) + ": assuming connection closed.")
                try:
                    chipsLog.debug("Awaiting new connection...")
                    self._connectedSocket, addr = self._socket.accept()  # TCP
                    chipsLog.debug("Client connection accepted.")            
                    continue
                except KeyboardInterrupt:
                    chipsLog.warning("\nKeyboard interrupt (ctrl-c) received whilst waiting for a TCP connection")
                    self._stopServingAndJoinThreads()
                    return            

            chipsLog.debug("\nReceived TCP packet from " + repr(addr))
            transaction = Transaction.constructHostTransaction(data, addr)
            self._transaction_queue.put(transaction)

        chipsLog.info("Dummy Hardware TCP Server stopping.")
Ejemplo n.º 7
0
    def _handleReadRequest(self, request):
        requestHeader = request.getHeader()
        words = IPbusHeader.getWords(requestHeader)
        baseAddr = request.getBody()[0]
        chipsLog.debug("Read requested on Addr=0x" + uInt32HexStr(baseAddr))

        # Response header is the request header with direction bit changed
        responseHeader = IPbusHeader.updateDirection(requestHeader, 1)

        # The (baseAddr & 0xffffffff) forces baseAddr to be in unsigned form (i.e. 0xfffffffc, say, rather than -4)
        if (baseAddr & 0xffffffff) == 0xffffffff:  # A read on this register is a Dummy Hardware Reset Request.
            chipsLog.info("** Dummy Hardware reset request received! Zeroing all registers. **")
            self._registers.clear()
        
        responseBody = []
        appendToResponseBody = responseBody.append  # This is for a speed optimisation  
        
        for offset in range(words):
            currentReg = baseAddr + offset  
            # Create these registers if they don't already exist.
            if currentReg not in self._registers:
                self._registers[currentReg] = 0
            appendToResponseBody(self._registers[currentReg])
        return TransactionElement.makeFromHeaderAndBody(responseHeader, responseBody)
Ejemplo n.º 8
0
    def serveForever(self):
        """The only function any user of this class needs to run!
        
        Receives, acts on, and responds to UDP control packets as the Mini-T (or similar hardware) would.
        Packets are received by the main thread and queued for action and response by a second thread.
        """
        chipsLog.info("Dummy Hardware UDP Server starting")
        # This starts the packet "act and respond" handler thread
        self.start()

        while not self.stopServing:
            try:
                data, addr = self._socket.recvfrom(
                    DummyHardware.SOCKET_BUFFER_SIZE)
            except KeyboardInterrupt:
                chipsLog.warning(
                    "\nKeyboard interrupt (ctrl-c) received whilst waiting for incoming UDP packet"
                )
                self._stopServingAndJoinThreads()
                return
            except:
                chipsLog.warning(
                    "\nException caught whilst waiting for incoming UDP packet"
                )
                self._stopServingAndJoinThreads()
                return

            if not data:
                chipsLog.warning("Socket received an empty packet from " + repr(addr) + \
                                 ".  Assuming socket now closed.\nTerminating dummy hardware server...")
                self._stopServingAndJoinThreads()
                return
            else:
                chipsLog.debug("\nReceived packet from " + repr(addr))
                transaction = Transaction.constructHostTransaction(data, addr)
                self._transaction_queue.put(transaction)
Ejemplo n.º 9
0
 def _stopServingAndJoinThreads(self):
     self.stopServing = True
     self.join(1)  #Let's wait for the transaction handler thread to complete normally.
     chipsLog.info("Dummy hardware server stopping.")
Ejemplo n.º 10
0
 def _stopServingAndJoinThreads(self):
     self.stopServing = True
     self.join(
         1
     )  #Let's wait for the transaction handler thread to complete normally.
     chipsLog.info("Dummy hardware server stopping.")