# plot_thread.start()

    # allow some time for commandThread to open listening socket
    time.sleep(2)

    # open a socket to the command thread
    hostname = Dada.getHostMachineName()
    port = int(cfg["IBOB_MANAGER_PORT"])

    # wait for all roaches to be active, then start bramdumping till exit
    roaches_all_active = False
    command_sock = 0

    # connect to our own command thread
    Dada.logMsg(3, DL, "main: openSocket(" + hostname + ", " + str(port) + ")")
    command_sock = Dada.openSocket(DL, hostname, port)
    Dada.logMsg(3, DL, "main: command_sock=" + repr(command_sock))

    response = command_sock.recv(4096)

    Dada.logMsg(
        1, DL, 'Configuring ' + roach_cfg["NUM_ROACH"] +
        ' ROACH boards with HISPEC gateware')
    Dada.logMsg(3, DL, "main: <- 'config'")
    result, response = Dada.sendTelnetCommand(command_sock, 'config')
    Dada.logMsg(3, DL, "main: -> " + result + " " + response)

    time.sleep(0.1)

    Dada.logMsg(1, DL, 'Setting levels to nominal values')
    Dada.logMsg(3, DL, "main: <- 'levels'")
Exemple #2
0
    def run(self):
        self.quit_event = quit_event
        cond = self.cond
        lock = self.lock
        raw = self.raw
        images = self.images
        data = self.data
        cfg = self.cfg

        bytes = 128 * 2 * self.nsamps
        raw_bytes = []

        count = 1

        try:
            Dada.logMsg(2, DL, "monitorThread: starting")

            while (not quit_event.isSet()):

                # open a socket to each instance of mopsr_dbstats
                for i in range(int(cfg["NSEND"])):

                    host = cfg["SEND_" + str(i)]
                    port = 54321

                    Dada.logMsg(
                        3, DL, "monitorThread: openSocket(" + host + ", " +
                        str(port) + ")")
                    sock = Dada.openSocket(DL, host, port)

                    Dada.logMsg(3, DL,
                                "monitorThread: " + host + " <- 'nsamp'")
                    result, response = Dada.sendTelnetCommand(sock, 'nsamp')
                    Dada.logMsg(
                        3, DL, "monitorThread: " + host + " -> " + result +
                        " " + response)
                    self.nsamps = int(response)

                    for j in range(2):

                        ant = 2 * i + j

                        bytes = 128 * 2 * self.nsamps

                        Dada.logMsg(
                            3, DL, "monitorThread: " + host + " <- 'dump " +
                            str(ant) + "'")
                        sock.send("dump " + str(ant) + "\r\n")

                        lock.acquire()
                        Dada.logMsg(3, DL, "monitorThread: [lock acquired]")

                        raw_bytes = ''
                        recvd = 0
                        while (len(raw_bytes) < bytes):
                            chunk = sock.recv(bytes - recvd)
                            if (chunk == ''):
                                raise RuntimeError("socket connection broken")
                            raw_bytes = raw_bytes + chunk

                        Dada.logMsg(
                            3, DL, "monitorThread: len(raw_bytes)=" +
                            str(len(raw_bytes)))

                        #raw[ant] = numpy.zeros ((128, self.nsamps), dtype=numpy.complex64)
                        raw[ant] = Mopsr.unpack(NCHAN, self.nsamps, 2,
                                                raw_bytes)

                        # delete all buffered images pertaining to this antenna
                        images[ant].clear()
                        data[ant].clear()

                        Dada.logMsg(
                            3, DL, "monitorThread: " + host + " -> binary [" +
                            str(bytes) + "]")
                        lock.release()
                        Dada.logMsg(3, DL, "monitorThread: [lock released]")

                    Dada.logMsg(3, DL, "monitorThread: sock.close()")
                    sock.close()

                Dada.logMsg(3, DL, "monitorThread: sleep(2)")
                time.sleep(5)

        except:
            Dada.logMsg(
                -2, DL,
                "monitorThread: exception caught: " + str(sys.exc_info()[0]))
            print '-' * 60
            traceback.print_exc(file=sys.stdout)
            print '-' * 60
            quit_event.set()
            lock.release()

        if (not sock == []):
            Dada.logMsg(2, DL, "monitorThread: closing server socket")
            sock.close()

        Dada.logMsg(2, DL, "monitorThread: exiting")