Exemplo n.º 1
0
    def recv(self, data, is_binary):
        if is_binary:
            data = ro.binary_decode(data)

        print "Length of data received: %d" % len(data)

        return 1
    def putFile(self, encodedBuffer):
        """
        A remote method that takes a base64-encoded buffer, decodes it,
        and writes it to a file (self.dstfile).  Returns True on success,
        otherwise logs an error and returns False.
        """

        try:
            data = ro.binary_decode(encodedBuffer)

            with self.lock:
                self.data = data
                self.logger.info("Received update: %s" % (
                    time.ctime(time.time())))

            #f_out = open(self.dstfile, 'w')

            #f_out.write(data)
            #f_out.close()
            #self.logger.info("Wrote file '%s'" % self.dstfile)

            return True

        except Exception, e:
            self.logger.error("Error writing file: %s" % str(e))
Exemplo n.º 3
0
    def archive_fitsbuf(self, frameid, fitsbuf, modtime):

        info = getFrameInfoFromPath(frameid)
        if not info:
            raise DAQerror("Malformed frameid: '%s'" % frameid)

        (frameid, fitsname, fitsdir, inscode, frametype, frame_no) = info

        insno = self.insconfig.getNumberByCode(inscode)

        fitspath = ('%s/obcp%02d/%s.fits' % (self.fitsdir, insno, frameid))
        if os.path.exists(fitspath):
            raise DAQerror("File already exists: %s" % fitspath)

        # Decode binary data
        data = ro.binary_decode(fitsbuf)

        try:
            out_f = open(fitspath, 'w')

            out_f.write(data)
            out_f.close()

        except IOError, e:
            raise DAQerror("Error saving file '%s': %s" % (fitspath, str(e)))
Exemplo n.º 4
0
    def region_selection(self):

        print 'region_selection called'

        if options.debug:
            print 'def region_selection called'

        # Decode binary data
        decode_image = ro.binary_decode(self.region_selection_data)

        # string to numpy
        decode_image = numpy.fromstring(decode_image,
                                        numpy.float32,
                                        shape=(self.data_x, self.data_y))

        #numpy.reshape(self.image.data, (self.pixDeltaX,self.pixDeltaY)).astype('Float32'),

        try:
            os.remove('/tmp/VGW.fits')
        except:
            print 'No tmp/VGW.fits file'
            pass

        try:
            hdu = pyfits.PrimaryHDU(decode_image)
            hdu.writeto('/tmp/VGW.fits')
        except IOError, e:
            print 'region selection write error %s' % (str(e))
Exemplo n.º 5
0
    def update_i_cut_figure(self):

        try:
            #self.diplay_image=DISPLAY_QUEUE.get(block=True, timeout=0.2)
            self.decode_image, self.X, self.Y = I_CUT_QUEUE.get(block=True,
                                                                timeout=0.1)

            if options.debug:
                print 'def update_i_cut_figure: get image from display Q  X:%s  Y:%s' % (
                    self.X, self.Y)

            # Decode binary data
            self.decode_image = ro.binary_decode(self.decode_image)

            # string to numpy
            self.decode_image = numpy.fromstring(self.decode_image,
                                                 numpy.uint32,
                                                 shape=(self.X, self.Y))

            self.i_cut_image = self.decode_image - self.decode_image.mean()

            self.axes.imshow(where(less(self.i_cut_image, 0), 0,
                                   self.i_cut_image),
                             origin='lower',
                             cmap=cm.gray)

            #self.axes.imshow(where(less(self.i_cut_image-self.i_cut_image.mean(), 0), 0, self.i_cut_image-self.i_cut_image.mean()), origin='lower', cmap=cm.gray)
            self.draw()

        except:
            pass
Exemplo n.º 6
0
    def process_ast(self, ast_id, vals):
        #print ast_id, vals

        with self.lock:
            try:
                page = self.pages[ast_id]
            except KeyError:
                # this page is not received/set up yet
                page = Bunch.Bunch(vals)
                page.nodes = {}
                self.pages[ast_id] = page

            if vals.has_key('ast_buf'):
                ast_str = ro.binary_decode(vals['ast_buf'])
                # Get the time of the command to construct the tab title
                title = self.time2str(vals['ast_time'])

                # TODO: what if this page has already been deleted?
                if self.save_decode_result.get():
                    self.addpage(ast_id + '.decode', title, ast_str)

                self.addpage(ast_id, title, ast_str)

            elif vals.has_key('ast_track'):
                path = vals['ast_track']

                curvals = self.monitor.getitems_suffixOnly(path)
                if isinstance(curvals, dict):
                    vals.update(curvals)

                # Make an entry for this ast node, if there isn't one already
                ast_num = '%d' % vals['ast_num']
                state = page.nodes.setdefault(ast_num, vals)

                bnch = Bunch.Bunch(page=page, state=state)
                self.track.setdefault(vals['ast_track'], bnch)

                # Replace the decode string with the actual parameters
                pos = page.tw.index('%s.first' % ast_num)
                page.tw.delete('%s.first' % ast_num, '%s.last' % ast_num)
                page.tw.insert(pos, vals['ast_str'], (ast_num, ))

                self.update_page(bnch)
Exemplo n.º 7
0
    def _playSound_bg(self,
                      buffer,
                      filename=None,
                      decode=True,
                      format=None,
                      decompress=False,
                      priority=20):

        # First thing is to add our priority to the priority list
        # so it will be noticed by any other threads playing sounds
        with self.lock_sound:
            self.priority_list.append(priority)

        # Record start time and add interval we should wait before playing
        time_start = time.time()
        time_limit = time_start + self.waitval

        try:
            try:
                # Decode binary data
                if decode:
                    data = ro.binary_decode(buffer)
                else:
                    data = buffer

                # Decompress data if necessary
                if decompress:
                    data = ro.uncompress(data)

                # If format is not explicitly provided, then assume 'au' and
                # override if a filename was given with an extension
                if not format:
                    format = 'au'
                    if filename:
                        dirname, filename = os.path.split(filename)
                        pfx, ext = os.path.splitext(filename)
                        format = ext[1:].lower()

                # Get a temp filename and write out our buffer to a file
                with self.lock_sound:
                    self.count = (self.count + 1) % self.maxcount
                    tmpfile = "_snd%d_%d.%s" % (os.getpid(), self.count,
                                                format)

                tmppath = os.path.join('/tmp', tmpfile)
                with open(tmppath, 'w') as out_f:
                    out_f.write(data)

                # Now sleep the remaining time until our required delay
                # time is reached.  This allows a small window in which
                # other sounds with higher priority might reach us and
                # be played first
                time_delta = time_limit - time.time()
                if time_delta > 0:
                    self.logger.debug("Sleeping for %.3f sec" % (time_delta))
                    time.sleep(time_delta)

                # Acquire the condition and then check the highest priority
                # in the queue.  If there are sounds with higher priority
                # then wait until we are notified.
                with self.playcond:
                    with self.lock_sound:
                        minval = min(self.priority_list)
                    self.logger.info("minval: %d priority: %d list: %s" %
                                     (minval, priority, self.priority_list))

                    while minval < priority:
                        self.playcond.wait()
                        self.logger.debug("awakened by notifier!")
                        with self.lock_sound:
                            minval = min(self.priority_list)
                        self.logger.info(
                            "minval: %d priority: %d list: %s" %
                            (minval, priority, self.priority_list))

                # Play the file and remove the temp file
                cmd_str = "%s %s" % (self.playcmd, tmppath)
                self.logger.info("Play command is: %s" % cmd_str)
                res = os.system(cmd_str)
                #os.remove(tmppath)

            except (IOError, OSError), e:
                self.logger.error("Failed to play sound buffer: %s" % (str(e)))
        finally:
            # Finally, remove our priority from the list and notify any
            # waiters (presumably with lower priority).
            with self.playcond:
                with self.lock_sound:
                    self.priority_list.remove(priority)
                    self.playcond.notifyAll()
    def process_ast(self, ast_id, vals):
        #print ast_id, vals
        name = str(ast_id)

        with self.lock:
            try:
                info = self.db[name]
                page = info.page
            except KeyError:
                # this ast_id is not received/set up yet
                #info = Bunch.Bunch(nodes={}, page=None)
                info = Bunch.Bunch(page=None, pageid=ast_id)
                self.db[name] = info
                page = None

            if vals.has_key('ast_buf'):
                ast_str = ro.binary_decode(vals['ast_buf'])
                ast_str = ro.uncompress(ast_str)
                # Due to an unfortunate way in which we have to search for
                # tags in common.get_region()
                if not ast_str.endswith('\n'):
                    ast_str = ast_str + '\n'
                #print "BUF!"; print ast_str

                # Get the time of the command to construct the tab title
                title = self.time2str(vals['ast_time'])
                info.asttime = vals['ast_time']

                # TODO: what if this page has already been deleted?
                if self.save_decode_result:
                    self.addpage(name + '.decode', title, ast_str)

                page = self.addpage(name, title, ast_str)
                info.page = page

            elif vals.has_key('ast_track'):
                path = vals['ast_track']

                # GLOBAL VAR READ
                curvals = common.controller.getvals(path)
                if isinstance(curvals, dict):
                    vals.update(curvals)

                # Make an entry for this ast node, if there isn't one already
                tagname = '%d' % vals['ast_num']
                # ?? necessary to have "nodes" table?
                #state = info.nodes.setdefault(tagname, vals)
                state = vals.copy()

                bnch = Bunch.Bunch(info=info,
                                   state=state,
                                   tag=tagname,
                                   level=0,
                                   count=0)
                self.track.setdefault(path, bnch)

                # It's possible in some cases that the ast_track could
                # arrive before the page is added or set up
                if not page:
                    return

                # Replace the decode string with the actual parameters
                # ?? Has string really changed at this point??
                #self.replace_text(page, tagname, vals['ast_str'])

                self.update_page(bnch)