11 from numpy.fft import *;
14 myport = random.randint(1025,65535);
15 filename = "output.dat";
18 msdd_host = "10.45.4.43"
22 my_udp_addr = ('',10001);
23 my_udp_addr = ('10.45.1.229 ',10001);
25 UDPSock = socket(AF_INET,SOCK_DGRAM);
26 UDPSock.bind(my_udp_addr);
33 window = 3; #0=rect, 1=hanning, 2=hamming, 3=blackman
36 samples = samples*4; #bytes of data we are requesting
38 decim = 2; #0-8 (3 => 2^3 = 8)
39 decim = decim+16; # +16 to use 16bit floats instead of 32 bit floats
40 mode = 0; #0=IQ, 1=MAG, 2=MAGDB
45 request_len = 6*size_int; # 6 int items not including the 8 bytes for opcode and length fields
46 print "request len = %d"%(request_len);
48 #raw_data = struct.pack("<IIIIIIII", 0x01, 0x18, f_mhz, f_hz, gain, samples, decim, sets);
49 raw_data = struct.pack("<IIIIIIII", 0x01, request_len, f_mhz, f_hz, gain, samples, decim, sets);
53 UDPSock.sendto(data, (msdd_host, msdd_port));
75 data = UDPSock.recv(4);
76 [opcode] = struct.unpack("<I", data);
77 print "Opcode = %d"%(opcode);
80 # if UDP mode and sets_stream requested,
81 # we do not get a header reply back, only data
88 data = UDPSock.recv(7*4);
89 args = struct.unpack("<IIIIIII", data);
90 print ["reply_len", "freq_mhz", "offset_hz", "gain", "sample_bytes", "decim", "sets_remain"];
92 IQ_bytes = args[0] - 7*4;
96 data = UDPSock.recv(4);
97 [i,q] = struct.unpack("<hh", data);
102 mags.append(abs(tmp));
105 sample_count = sample_count + 1;
106 # print "sample count %d"%(sample_count)
108 IQ_bytes = IQ_bytes - 4;
110 print "got all data (total %d)"%(sample_count);
111 print "remaining: %d"%(IQ_bytes);
126 plot(20*log10(nmags));
128 fft_data = 20*log10(fftshift(fft(vals)));
134 f = open(filename, "w");
136 binchunk = struct.pack("<ff",float(sample.real), float(sample.imag) );