dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1 | /* |
| 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> |
kurtis.heimerl | 965e757 | 2011-11-26 03:16:54 +0000 | [diff] [blame] | 31 | #include "radioDevice.h" |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 32 | |
| 33 | ConfigurationTable gConfig; |
| 34 | |
| 35 | using namespace std; |
| 36 | |
| 37 | int 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 | |
kurtis.heimerl | 965e757 | 2011-11-26 03:16:54 +0000 | [diff] [blame] | 44 | RadioDevice *usrp = RadioDevice::make(52.0e6/192.0); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 45 | |
ttsou | f60dafa | 2012-10-22 00:07:14 +0000 | [diff] [blame] | 46 | usrp->open(""); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 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]; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 85 | printf ("%llu: %d %d\n", timestamp+i,readBuf[2*i],readBuf[2*i+1]); |
| 86 | sum += (readBuf[2*i+1]*readBuf[2*i+1] + readBuf[2*i]*readBuf[2*i]); |
| 87 | num++; |
| 88 | //if (num % 10000 == 0) printf("avg pwr: %f\n",sum/num); |
| 89 | } |
| 90 | timestamp += rd; |
| 91 | //usrp->writeSamples((short*) data2,512*numpkts,&underrun,timestamp+1000); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | } |