cleaning up and putting much better code in. Step 1 of 2
[debian/gnuradio] / gr-msdd6000 / src / python_test / udp_stream_rate_test.py
1 #!/usr/bin/python
2
3 from socket import *
4 import string
5 import time
6 import struct;
7 import random;
8 import array;
9 import cmath;
10 from numpy import *;
11 from numpy.fft import *;
12 from pylab import *;
13
14 myport = random.randint(1025,65535);
15 filename = "output.dat";
16
17 msdd_port = 10001
18 msdd_host = "10.45.4.46"
19
20 buf = 100000;
21
22 my_udp_addr = ('',10001);
23 my_udp_addr = ('10.45.1.229 ',10001);
24
25 UDPSock = socket(AF_INET,SOCK_DGRAM);
26 UDPSock.bind(my_udp_addr);
27
28 #f_mhz = 3500;  
29 #f_mhz = 3500;  
30 f_mhz = 1000;   
31 f_hz = 0;       
32 gain = 0;       
33 window = 3;     #0=rect, 1=hanning, 2=hamming, 3=blackman
34
35 #samples = 65535;
36 samples = 16384;
37 #samples = samples*4;   #bytes of data we are requesting
38
39 decim = 2;      #0-8   (3 => 2^3 = 8)   # ok
40 decim = decim+16;       # +16 to use 16bit floats instead of 32 bit floats
41 mode = 0;       #0=IQ, 1=MAG, 2=MAGDB
42 #sets = 0;
43 sets = 0xffffffff;
44
45 size_int = 4;
46 request_len = 6*size_int;       # 6 int items not including the 8 bytes for opcode and length fields
47 print "request len = %d"%(request_len);
48
49 raw_data = struct.pack("<IIIIIIII", 0x01, request_len, f_mhz, f_hz, gain, samples, decim, sets);
50
51 data = raw_data;
52
53 UDPSock.sendto(data, (msdd_host, msdd_port));
54
55 print "sent"
56
57
58
59 count = 0;
60
61 total_data = [];
62
63 state = 0;
64
65 vals = [];
66 mags = [];
67 re = [];
68
69 sample_count = 0;
70 IQ_bytes=0;
71
72
73 numtocap = 1000;
74 IQ_bytes = numtocap * numtocap;
75
76 numbytes = 1000 * 65536;
77
78 num_rx = 0;
79 start = -1;
80 while(num_rx < numbytes):
81         data = UDPSock.recv(65536);
82
83         if(start==-1):
84                 start =  time.time();
85
86         num_rx = num_rx + len(data);
87 #       print num_rx;
88
89
90 end = time.time();
91 print "recieved %d bytes in %f sec"%(numbytes, end-start);
92
93 bytes_per_sec = numbytes / (end-start);
94 samples_per_sec = bytes_per_sec / 4;
95 MSPS = samples_per_sec / 1000000.0;
96
97 print "Got %f MSPS"%(MSPS);
98 print "Expected %f MSPS"%(102.4/math.pow(2,(decim-16)));
99         
100
101 halt_data = struct.pack("<II", 0x04, 0x00);
102 UDPSock.sendto(halt_data, (msdd_host, msdd_port));
103
104
105 UDPSock.close();
106