Hi

If any one can give me your advices I will apreciate the help.

For some reason the struct.unpack argument receives only 71 bytes, when
should receive 4096 bytes.

I placed several prints in the code.


rolando@rolando-MS-7815:~/poco_arte$ sudo python plot_auto.py
i4_c1024_arte.config

Parsing config file i4_c1024_arte.config...OK
Connecting to IBOB on port /dev/ttyUSB0.
listdev

Address map :

<NO ADDR>  -> XSG core config

<NO ADDR>  -> XSG core config

0xD0000000 -> acc_num

Trying to decode address of
0xD0000000 -> acc_num
13 9 48 120 68 48 48 48 48 48 48 48 32 45 62 32 97 99 99 95 110 117 109 10
This is the address of register or bram 3489660928
0xD0000100 -> ant0_sum_sq

Trying to decode address of
0xD0000100 -> ant0_sum_sq
13 9 48 120 68 48 48 48 48 49 48 48 32 45 62 32 97 110 116 48 95 115 117
109 95 115 113 10
This is the address of register or bram 3489661184
0xD0000200 -> ant1_sum_sq

Trying to decode address of
0xD0000200 -> ant1_sum_sq
13 9 48 120 68 48 48 48 48 50 48 48 32 45 62 32 97 110 116 49 95 115 117
109 95 115 113 10
This is the address of register or bram 3489661440
0xD0000300 -> ant2_sum_sq

Trying to decode address of
0xD0000300 -> ant2_sum_sq
13 9 48 120 68 48 48 48 48 51 48 48 32 45 62 32 97 110 116 50 95 115 117
109 95 115 113 10
This is the address of register or bram 3489661696
0xD0000400 -> ant3_sum_sq

Trying to decode address of
0xD0000400 -> ant3_sum_sq
13 9 48 120 68 48 48 48 48 52 48 48 32 45 62 32 97 110 116 51 95 115 117
109 95 115 113 10
This is the address of register or bram 3489661952
0xD0000500 -> ctrl_sw

Trying to decode address of
0xD0000500 -> ctrl_sw
13 9 48 120 68 48 48 48 48 53 48 48 32 45 62 32 99 116 114 108 95 115 119
10
This is the address of register or bram 3489662208
0xD0000600 -> delay_a

Trying to decode address of
0xD0000600 -> delay_a
13 9 48 120 68 48 48 48 48 54 48 48 32 45 62 32 100 101 108 97 121 95 97 10
This is the address of register or bram 3489662464
0xD0000700 -> delay_b

Trying to decode address of
0xD0000700 -> delay_b
13 9 48 120 68 48 48 48 48 55 48 48 32 45 62 32 100 101 108 97 121 95 98 10
This is the address of register or bram 3489662720
0xD0000800 -> delay_c

Trying to decode address of
0xD0000800 -> delay_c
13 9 48 120 68 48 48 48 48 56 48 48 32 45 62 32 100 101 108 97 121 95 99 10
This is the address of register or bram 3489662976
0xD0000900 -> delay_d

Trying to decode address of
0xD0000900 -> delay_d
13 9 48 120 68 48 48 48 48 57 48 48 32 45 62 32 100 101 108 97 121 95 100
10
This is the address of register or bram 3489663232
0xD0000A00 -> eq_coeff

Trying to decode address of
0xD0000A00 -> eq_coeff
13 9 48 120 68 48 48 48 48 65 48 48 32 45 62 32 101 113 95 99 111 101 102
102 10
This is the address of register or bram 3489663488
0xD0002000 -> ibob_lwip/ethlite

Trying to decode address of
0xD0002000 -> ibob_lwip/ethlite
13 9 48 120 68 48 48 48 50 48 48 48 32 45 62 32 105 98 111 98 95 108 119
105 112 47 101 116 104 108 105 116 101 10
This is the address of register or bram 3489669120
<NO ADDR>  -> ibob_lwip/lwip

0xD0004000 -> ibob_lwip/macbits

Trying to decode address of
0xD0004000 -> ibob_lwip/macbits
13 9 48 120 68 48 48 48 52 48 48 48 32 45 62 32 105 98 111 98 95 108 119
105 112 47 109 97 99 98 105 116 115 10
This is the address of register or bram 3489677312
<NO ADDR>  -> ibob_lwip/machdr

<NO ADDR>  -> led1_sync_rnd

<NO ADDR>  -> led2_sync_gen

<NO ADDR>  -> led4_eq_clip

<NO ADDR>  -> quadc0

0xD1000000 -> sync_gen/period

Trying to decode address of
0xD1000000 -> sync_gen/period
13 9 48 120 68 49 48 48 48 48 48 48 32 45 62 32 115 121 110 99 95 103 101
110 47 112 101 114 105 111 100 10
This is the address of register or bram 3506438144
0xD1002000 -> xengine/aa/real

Trying to decode address of
0xD1002000 -> xengine/aa/real
13 9 48 120 68 49 48 48 50 48 48 48 32 45 62 32 120 101 110 103 105 110 101
47 97 97 47 114 101 97 108 10
This is the address of register or bram 3506446336
0xD1004000 -> xengine/ab/imag

Trying to decode address of
0xD1004000 -> xengine/ab/imag
13 9 48 120 68 49 48 48 52 48 48 48 32 45 62 32 120 101 110 103 105 110 101
47 97 98 47 105 109 97 103 10
This is the address of register or bram 3506454528
0xD1006000 -> xengine/ab/real

Trying to decode address of
0xD1006000 -> xengine/ab/real
13 9 48 120 68 49 48 48 54 48 48 48 32 45 62 32 120 101 110 103 105 110 101
47 97 98 47 114 101 97 108 10
This is the address of register or bram 3506462720
0xD1008000 -> xengine/ac/imag

Trying to decode address of
0xD1008000 -> xengine/ac/imag
13 9 48 120 68 49 48 48 56 48 48 48 32 45 62 32 120 101 110 103 105 110 101
47 97 99 47 105 109 97 103 10
This is the address of register or bram 3506470912
0xD100A000 -> xengine/ac/real

Trying to decode address of
0xD100A000 -> xengine/ac/real
13 9 48 120 68 49 48 48 65 48 48 48 32 45 62 32 120 101 110 103 105 110 101
47 97 99 47 114 101 97 108 10
This is the address of register or bram 3506479104
0xD100C000 -> xengine/ad/imag

Trying to decode address of
0xD100C000 -> xengine/ad/imag
13 9 48 120 68 49 48 48 67 48 48 48 32 45 62 32 120 101 110 103 105 110 101
47 97 100 47 105 109 97 103 10
This is the address of register or bram 3506487296
0xD100E000 -> xengine/ad/real

Trying to decode address of
0xD100E000 -> xengine/ad/real
13 9 48 120 68 49 48 48 69 48 48 48 32 45 62 32 120 101 110 103 105 110 101
47 97 100 47 114 101 97 108 10
This is the address of register or bram 3506495488
0xD1010000 -> xengine/bb/real

Trying to decode address of
0xD1010000 -> xengine/bb/real
13 9 48 120 68 49 48 49 48 48 48 48 32 45 62 32 120 101 110 103 105 110 101
47 98 98 47 114 101 97 108 10
This is the address of register or bram 3506503680
0xD1012000 -> xengine/bc/imag

Trying to decode address of
0xD1012000 -> xengine/bc/imag
13 9 48 120 68 49 48 49 50 48 48 48 32 45 62 32 120 101 110 103 105 110 101
47 98 99 47 105 109 97 103 10
This is the address of register or bram 3506511872
0xD1014000 -> xengine/bc/real

Trying to decode address of
0xD1014000 -> xengine/bc/real
13 9 48 120 68 49 48 49 52 48 48 48 32 45 62 32 120 101 110 103 105 110 101
47 98 99 47 114 101 97 108 10
This is the address of register or bram 3506520064
0xD1016000 -> xengine/bd/imag

Trying to decode address of
0xD1016000 -> xengine/bd/imag
13 9 48 120 68 49 48 49 54 48 48 48 32 45 62 32 120 101 110 103 105 110 101
47 98 100 47 105 109 97 103 10
This is the address of register or bram 3506528256
0xD1018000 -> xengine/bd/real

Trying to decode address of
0xD1018000 -> xengine/bd/real
13 9 48 120 68 49 48 49 56 48 48 48 32 45 62 32 120 101 110 103 105 110 101
47 98 100 47 114 101 97 108 10
This is the address of register or bram 3506536448
0xD101A000 -> xengine/cc/real

Trying to decode address of
0xD101A000 -> xengine/cc/real
13 9 48 120 68 49 48 49 65 48 48 48 32 45 62 32 120 101 110 103 105 110 101
47 99 99 47 114 101 97 108 10
This is the address of register or bram 3506544640
0xD101C000 -> xengine/cd/imag

Trying to decode address of
0xD101C000 -> xengine/cd/imag
13 9 48 120 68 49 48 49 67 48 48 48 32 45 62 32 120 101 110 103 105 110 101
47 99 100 47 105 109 97 103 10
This is the address of register or bram 3506552832
0xD101E000 -> xengine/cd/real

Trying to decode address of
0xD101E000 -> xengine/cd/real
13 9 48 120 68 49 48 49 69 48 48 48 32 45 62 32 120 101 110 103 105 110 101
47 99 100 47 114 101 97 108 10
This is the address of register or bram 3506561024
0xD1020000 -> xengine/dd/real

Trying to decode address of
0xD1020000 -> xengine/dd/real
13 9 48 120 68 49 48 50 48 48 48 48 32 45 62 32 120 101 110 103 105 110 101
47 100 100 47 114 101 97 108 10
This is the address of register or bram 3506569216
Grabbing spectrum number 1
Sleeping in 1 for 2 Seconds
This is the read address 3506446336
num_pkts 9
st_offset 0
request_size 127
this is the address 3506446336
what is being written 6
st_offset 127
request_size 127
this is the address 3506446336
what is being written 6
st_offset 254
request_size 127
this is the address 3506446336
what is being written 6
st_offset 381
request_size 127
this is the address 3506446336
what is being written 6
st_offset 508
request_size 127
this is the address 3506446336
what is being written 6
st_offset 635
request_size 127
this is the address 3506446336
what is being written 6
st_offset 762
request_size 127
this is the address 3506446336
what is being written 6
st_offset 889
request_size 127
this is the address 3506446336
what is being written 6
st_offset 1016
request_size 8
this is the address 3506446336
what is being written 6
length argument 71
Traceback (most recent call last):
  File "plot_auto.py", line 74, in updatefig
    inputs[input] = brd.read_uint(bram_map[input], size=n_chans)
  File "/home/rolando/poco_arte/poco/ibob_serial.py", line 89, in read_uint
    out=struct.unpack('>%iL'%size,check)
struct.error: unpack requires a string argument of length 4096


Best Regards

RP
#!/usr/bin/env python

'''
Plots the auto correlations for all four inputs.
'''
import gtk, gobject, poco, time, numpy, struct, sys, math, matplotlib
matplotlib.use('GTKAgg')
from matplotlib import rcParams
import pylab

bram_map=['xengine/aa/real','xengine/bb/real','xengine/cc/real','xengine/dd/real']

if __name__ == '__main__':
    from optparse import OptionParser

    p = OptionParser()
    p.set_usage('plot_auto.py CONFIG FILE')
    p.set_description(__doc__)
    p.add_option('-v', '--verbose', dest='verbose', action='store_true',
        help='Be verbose (good for debugging)')
    p.add_option('-l', '--log', dest='log', action='store_true', default=False,
        help='''Plot the power in logarithmic scale (requires some non-zero value signal).''')
    p.add_option('--hold', dest='hold', action='store_true', default=False,
        help='''Turn on hold. This will plot subsequent specra on top of each other.''')
    p.add_option('-f', '--freq', dest='freq', action='store_true', default=False,
        help='''Plot the input frequency on the X-axis rather than the channel number.''')



    opts, args = p.parse_args(sys.argv[1:])


    if args==[]:
        print 'Please specify a configuration file! \nExiting.'
        exit()

    config = poco.poco_conf.CorrConf(args[0])
    config_status = config.read_all()
    print '\n\nParsing config file %s...%s'%(args[0],config_status)
    sys.stdout.flush()
    if not config_status == 'OK': exit()

port = config['connection']['port']
n_chans = config['n_chans']
cen_freq = config['adc_clk']*1000.*config['ddc_mix_freq']
bandwidth = config['adc_clk']*1000./config['ddc_decimation']


print 'Connecting to IBOB on port %s.'%port
brd = poco.ibob_serial.IbobClient(port)

fig = pylab.figure(1)
manager = pylab.get_current_fig_manager()
cnt = 0

if opts.freq:
    channel_size=float(bandwidth)/n_chans
    print 'Bandwidth: %f. Cent freq: %f. Channel size: %f'%(bandwidth,cen_freq,channel_size)
    x=((numpy.array(range(0,n_chans))*channel_size)+cen_freq-bandwidth/2)
    xlab=('Input Frequency (MHz)')
else:
    x=range(0,n_chans)
    xlab=('Input channel number')


def updatefig(*args):
    global cnt
    cnt += 1
    print 'Grabbing spectrum number %i'%cnt
    #get the data...    
    inputs=[[],[],[],[]]
    self_reord=[]
    for input in range(4):
        inputs[input] = brd.read_uint(bram_map[input], size=n_chans)

    pylab.figure(num=1,figsize=(10,10))
    pylab.ioff()
    ymax=0
    ax=[]
    for input in range(4):
        self_reord.append (numpy.concatenate((inputs[input][512:1024], inputs[input][0:512])))
        ax.append(pylab.subplot(411+input))
        pylab.hold(opts.hold)

        if opts.log:
            pylab.semilogy(x,self_reord[input])
            pylab.ylabel('Power (log scale, arbitrary units)')

        else:
            pylab.plot(self_reord[input])
            pylab.ylabel('Power (linear scale, arbitrary units)')

        pylab.grid()
        #pylab.setp(ax[input].get_xticklabels(),visible=False)
        pylab.ylabel('Power (arbitrary units)')
        pylab.title('Power: Input %i. Spectrum number %i'%(input,cnt))
        if ymax<(ax[input].axes.yaxis.get_data_interval()[-1]): 
            ymax=(ax[input].axes.yaxis.get_data_interval()[-1])

    for i in range(4):
        ax[i].set_ylim(0,ymax*1.1)

    pylab.setp(ax[input].get_xticklabels(),visible=True)
    pylab.xlabel(xlab)
    pylab.xlim(x[0],x[n_chans-1])
    print 'Ymax: %i'%ymax
        
    pylab.draw()
    return True

gobject.idle_add(updatefig)
pylab.show()
print 'Done with all' 

Attachment: i4_c1024_arte.config
Description: Binary data

'''
This Class provides a Python interface to TinySH over an RS232 link

Requires PySerial.

Author: Jason Manley
Date: 2008/11/20
Version: 0.0.1

'''

import time, numpy, os, struct, serial
import pdb

class IbobClient:
    def __init__(self,port):
        self.port = port
        self.cmds = []
        self.devs={}
        self.ser = serial.Serial(port=port,baudrate=115200,parity='N',stopbits=1,timeout=1,xonxoff=0,rtscts=0)
        self.flush_text_buffers()
        self._listdev()

    def flush_text_buffers(self):
        self.ser.write('\n')
        time.sleep(1)
        self.ser.flushInput()
        #self.ser.flushOutput()
        self.ser.write('\n')
        line = self.ser.read(9)
        if line != '\n\rIBOB % ': raise Exception("Bad Reply: '%s'"%line)

    def _listdev(self):
        """ List all the devices (registers, brams etc) available on the device and figure out their memory addresses. """
        self.ser.write('listdev\n')
        time.sleep(1)
        for i in range(3):
            line=self.ser.readline()
            print line
        time.sleep(5)
        while line != '\rIBOB % ' and line != '':
            print line
            if line[2:11] !='<NO ADDR>' and line !='\n' and line != '\r': 
                name = line[16:-1]
                print 'Trying to decode address of \n%s'%line,
                for i in line:
                    print ord(i),
                print ''
                addr = int(line[2:12],16) 
                self.devs[name]=addr
		print 'This is the address of register or bram', addr
            line = self.ser.readline()
	    

    def _binary_read(self,size,addr,offset=0):
        """ Reads data from the IBOB in binary mode. 
        Offset and size are measured in 32 bit words. ie Requesting size of 1 will return 4 bytes.
        The IBOB addresses bytes, but the size is 32bit delimited."""
	#pdb.set_trace()
        num_pkts = int(numpy.ceil(size/float(127)))
	print 'num_pkts', num_pkts
        output = ''
        for i in range(num_pkts):
            st_offset = (i*127)+offset
	    print 'st_offset', st_offset	
            request_size = numpy.min([size-(i*127),127])
	    print 'request_size', request_size
            cmd = chr((0<<7) + request_size)
	    print 'this is the address', addr
	    request_addr = struct.pack('>L',addr+(st_offset*4))
	    wr = self.ser.write(chr(128) + cmd + request_addr)
	    print 'what is being written', wr	
	    time.sleep(.1)
            output+=self.ser.read(request_size*4)
	return output
	
        #return struct.unpack('>L',ser.read(4))

    def _binary_write(self,size,addr,data):
        assert(size<128)
        assert(type(data)==str)
        cmd = chr((1<<7) + size)
        addr = struct.pack('>L',addr)
        self.ser.write(bin_mode + cmd + addr + data)
       
    def read_uint(self, register, size=1):
	direccion = self.devs[register]
	print 'This is the read address', direccion
	check = self._binary_read(size=size,addr=direccion)
	print 'length argument', len(check)
        out=struct.unpack('>%iL'%size,check)
        if size==1: return out[0]
        else: return out
    
    def read_int(self, register, size=1):
        out=struct.unpack('>%il'%size,self._binary_read(size=size,addr=self.devs[register]))
        if size==1: return out[0]
        else: return out
    
    def write_uint(self, register, data):
        self._binary_write(size=1,addr=self.devs[register],data=struct.pack('>L',data))
 
import ConfigParser,exceptions
"""
Library for parsing CASPER correlator configuration files

Author: Jason Manley
Revision: 2008-02-08


Revs:
2008-02-08: JRM Replaced custom tokeniser with string.split
                Changed EQ to EQ_polys
                Changed max_payload_len to rx_buffer_size

"""
LISTDELIMIT = ','
PORTDELIMIT = ':'


class CorrConf:    
    def __init__(self, config_file):
        self.config_file=config_file
        self.cp = ConfigParser.ConfigParser()
        self.cp.read(config_file)
        self.config=dict()
        self.read_all()

    def __getitem__(self,item):
        return self.config[item]

    def __setitem__(self,item, value):
        self.config[item] = value

    def file_exists(self):
        try:
            f = open(self.config_file)
        except IOError:
            exists = False
        else:
            exists = True
            f.close()
        return exists

    def read_all(self):
        if not self.file_exists():
            return 'ERR: Config file not found'
        self.config['correlator']=dict()
        
        #Get the servers:
        self.config['connection']=dict()
        try:
            port=self.cp.get('connection','port')
            self.config['connection']['port']=port          
        except ConfigParser.NoOptionError:
            return 'ERR: %s not found'%'port parameter'
        except exceptions.ValueError:
            return 'ERR: value %s'%'port parameter'
        except ConfigParser.NoSectionError:
            return 'ERR: %s section not found'%'connection'
        except:
            return 'ERR: unknown error in %s section'%'connection'        
        
        #get the correlator config stuff:
        try:
            self.read_int('correlator','n_chans')
            self.read_int('correlator','n_ants')
            self.read_int('correlator','acc_len')
            self.read_float('correlator','adc_clk')
            self.read_str('correlator','fft_shift')
            self.read_str('correlator','ibob_ip')
            self.read_int('correlator','zero_ground')
            self.read_float('correlator','ddc_mix_freq')
            self.read_int('correlator','ddc_decimation')
        except:
            return 'ERR Processing the correlator section'
            
        #get the transmit section:
        try:
            self.config['transmit']=dict()
            self.read_int('transmit','tx_pkt_size')
            self.read_int('transmit','tx_pkt_header_size')
            self.read_int('transmit','nchan_per_bram')
            self.read_int('transmit','pkts_per_bram')
            self.read_int('transmit','brams_per_pkt')
            self.read_int('transmit','nbrams')
            self.read_str('transmit','design_name')
        except:
            return 'ERR Processing the transmit section'
        
        #get the receiver section:
        try:
            self.config['receiver']=dict()
            self.read_int('receiver','t_per_file')
            self.read_int('receiver','rx_buffer_size')
            self.read_str('receiver','rx_ip_address')
            self.read_int('receiver','udp_port')
            self.read_int('receiver','max_payload_len')
        except:
            return 'ERR Processing the receiver section'

        #equalisation section:
        self.read_int('equalisation','eq_blocks')
        self.read_int('equalisation','eq_chans')
        self.read_int('equalisation','auto_eq')
        self.config['eq']=dict()
        self.config['eq']['eq_polys']=[]
        for ant in range(self.config['eq_blocks']):
            ant_eq_str=self.get_line('equalisation','EQ_poly_%i'%(ant))
            if (ant_eq_str):
                self.config['eq']['eq_polys'].append([int(coef) for coef in ant_eq_str.split(LISTDELIMIT)])
            else:
                return 'ERR EQ_poly_%i'%(ant)
                break
        

        # get the antenna info:
        self.config['antennas']=dict()

        self.config['antennas']['pos']=[]
        for ant in range(self.config['n_ants']):
            ant_pos_str=self.get_line('antennas','pos_%i'%(ant))
            if (ant_pos_str):
                self.config['antennas']['pos'].append([float(coef) for coef in ant_pos_str.split(LISTDELIMIT)])
            else:
                return 'ERR pos_%i'%(ant)
                break

        self.config['antennas']['location']=[]
        ant_loc_str=self.get_line('antennas','location')
        if (ant_loc_str):
            location = ant_loc_str.split(LISTDELIMIT)
            if len(location) == 2:
                self.config['antennas']['location']= location
            else: 
                return 'ERR setting array location'
        else:
            return 'ERR setting array location'

        self.config['antennas']['order']=[]
        ant_ord_str=self.get_line('antennas','order')
        if (ant_ord_str):
            order = ant_ord_str.split(LISTDELIMIT)
            if len(order) == self.config['n_ants']:
                try:
                    self.config['antennas']['order']= [int(ant) for ant in order]
                except:
                    return 'ERR setting antenna ordering'                    
            else: 
                return 'ERR setting antenna ordering'
        else:
            return 'ERR setting antenna ordering'

        
        return 'OK'



    def get_line(self,section,variable):
        try:
            return self.cp.get(section,variable)
        except:
            return None

    def read_int(self,section,variable):
        self.config[variable]=self.cp.getint(section,variable)

    def read_str(self,section,variable):
        self.config[variable]=self.cp.get(section,variable)

    def read_float(self,section,variable):
        self.config[variable]=self.cp.getfloat(section,variable)
        
    def calc_consts(self):
        print 'Calculating constants and populating as necessary'

Reply via email to