blob: b238c69b54c29d80556067915aafe79d7d55584a [file] [log] [blame]
dburgessb3a0ca42011-10-12 07:44:40 +00001/*
2* Copyright 2008, 2009 Free Software Foundation, Inc.
3*
4* This software is distributed under the terms of the GNU Public License.
5* See the COPYING file in the main directory for details.
6*
7* This use of this software may be subject to additional restrictions.
8* See the LEGAL file in the main directory for details.
9
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
22
23*/
24
25
26
27#include <stdint.h>
28#include <stdio.h>
29#include <Logger.h>
30#include <Configuration.h>
31#include "USRPDevice.h"
32
33ConfigurationTable gConfig;
34
35using namespace std;
36
37int main(int argc, char *argv[]) {
38
39 // Configure logger.
40 if (argc>1) gLogInit(argv[1]);
41 else gLogInit("DEBUG");
42 //if (argc>2) gSetLogFile(argv[2]);
43
44 USRPDevice *usrp = new USRPDevice(52.0e6/192.0);
45
46 usrp->make();
47
48 TIMESTAMP timestamp;
49
50 usrp->setTxFreq(825.4e6);
51 usrp->setRxFreq(825.4e6);
52
53 usrp->start();
54
55 usrp->setRxGain(57);
56
57 LOG(INFO) << "Looping...";
58 bool underrun;
59
60 short data[]={0x00,0x02};
61
62 usrp->updateAlignment(20000);
63 usrp->updateAlignment(21000);
64
65 int numpkts = 1;
66 short data2[512*2*numpkts];
67 for (int i = 0; i < 512*numpkts; i++) {
68 data2[i<<1] = 10000;//4096*cos(2*3.14159*(i % 126)/126);
69 data2[(i<<1) + 1] = 10000;//4096*sin(2*3.14159*(i % 126)/126);
70 }
71
72 for (int i = 0; i < 1; i++)
73 usrp->writeSamples((short*) data2,512*numpkts,&underrun,102000+i*1000);
74
75 timestamp = 19000;
76 double sum = 0.0;
77 unsigned long num = 0;
78 while (1) {
79 short readBuf[512*2];
80 int rd = usrp->readSamples(readBuf,512,&underrun,timestamp);
81 if (rd) {
82 LOG(INFO) << "rcvd. data@:" << timestamp;
83 for (int i = 0; i < 512; i++) {
84 uint32_t *wordPtr = (uint32_t *) &readBuf[2*i];
85 *wordPtr = usrp_to_host_u32(*wordPtr);
86 printf ("%llu: %d %d\n", timestamp+i,readBuf[2*i],readBuf[2*i+1]);
87 sum += (readBuf[2*i+1]*readBuf[2*i+1] + readBuf[2*i]*readBuf[2*i]);
88 num++;
89 //if (num % 10000 == 0) printf("avg pwr: %f\n",sum/num);
90 }
91 timestamp += rd;
92 //usrp->writeSamples((short*) data2,512*numpkts,&underrun,timestamp+1000);
93 }
94 }
95
96}