Exemplo n.º 1
0
int main(int argc, char *argv[])
{
    int type, chans;
    RadioDevice *usrp;
    RadioInterface *radio = NULL;
    Transceiver *trx = NULL;
    struct trx_config config;

    handle_options(argc, argv, &config);

    setup_signal_handlers();

    /* Check database sanity */
    if (!trx_setup_config(&config)) {
        std::cerr << "Config: Database failure - exiting" << std::endl;
        return EXIT_FAILURE;
    }

    gLogInit("transceiver", config.log_level.c_str(), LOG_LOCAL7);

    srandom(time(NULL));

    /* Create the low level device object */
    usrp = RadioDevice::make(config.sps, config.chans,
                             config.diversity, config.offset);
    type = usrp->open(config.dev_args, config.extref, config.swap_channels);
    if (type < 0) {
        LOG(ALERT) << "Failed to create radio device" << std::endl;
        goto shutdown;
    }

    /* Setup the appropriate device interface */
    radio = makeRadioInterface(&config, usrp, type);
    if (!radio)
        goto shutdown;

    /* Create the transceiver core */
    trx = makeTransceiver(&config, radio);
    if (!trx)
        goto shutdown;

    chans = trx->numChans();
    std::cout << "-- Transceiver active with "
              << chans << " channel(s)" << std::endl;

    while (!gshutdown)
        sleep(1);

shutdown:
    std::cout << "Shutting down transceiver..." << std::endl;

    delete trx;
    delete radio;
    delete usrp;

    return 0;
}
Exemplo n.º 2
0
int main(int argc, char *argv[]) {

  // Configure logger.
  if (argc>1) gLogInit(argv[1]);
  else gLogInit("DEBUG");
  //if (argc>2) gSetLogFile(argv[2]);

  RadioDevice *usrp = RadioDevice::make(52.0e6/192.0);

  usrp->open("");

  TIMESTAMP timestamp;

  usrp->setTxFreq(825.4e6);
  usrp->setRxFreq(825.4e6);

  usrp->start();

  usrp->setRxGain(57);

  LOG(INFO) << "Looping...";
  bool underrun;

  short data[]={0x00,0x02};

  usrp->updateAlignment(20000);
  usrp->updateAlignment(21000);

  int numpkts = 1;
  short data2[512*2*numpkts];
  for (int i = 0; i < 512*numpkts; i++) {
    data2[i<<1] = 10000;//4096*cos(2*3.14159*(i % 126)/126);
    data2[(i<<1) + 1] = 10000;//4096*sin(2*3.14159*(i % 126)/126);
  }

  for (int i = 0; i < 1; i++) 
    usrp->writeSamples((short*) data2,512*numpkts,&underrun,102000+i*1000);

  timestamp = 19000;
  double sum = 0.0;
  unsigned long num = 0;
  while (1) {
    short readBuf[512*2];
    int rd = usrp->readSamples(readBuf,512,&underrun,timestamp);
    if (rd) {
      LOG(INFO) << "rcvd. data@:" << timestamp;
      for (int i = 0; i < 512; i++) {
        uint32_t *wordPtr = (uint32_t *) &readBuf[2*i];
	printf ("%llu: %d %d\n", timestamp+i,readBuf[2*i],readBuf[2*i+1]);
        sum += (readBuf[2*i+1]*readBuf[2*i+1] + readBuf[2*i]*readBuf[2*i]);
        num++;
        //if (num % 10000 == 0) printf("avg pwr: %f\n",sum/num);
      }
      timestamp += rd;
      //usrp->writeSamples((short*) data2,512*numpkts,&underrun,timestamp+1000);
    }
  }

}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
  if ( signal( SIGINT, ctrlCHandler ) == SIG_ERR )
  {
    cerr << "Couldn't install signal handler for SIGINT" << endl;
    exit(1);
  }

  if ( signal( SIGTERM, ctrlCHandler ) == SIG_ERR )
  {
    cerr << "Couldn't install signal handler for SIGTERM" << endl;
    exit(1);
  }

  // Configure logger.
  if (argc<2) {
    cerr << argv[0] << " <logLevel> [logFilePath]" << endl;
    cerr << "Log levels are ERROR, ALARM, WARN, NOTICE, INFO, DEBUG, DEEPDEBUG" << endl;
    exit(0);
  }
  gLogInit(argv[1]);
  if (argc>2) gSetLogFile(argv[2]);

  srandom(time(NULL));

  RadioDevice *usrp = RadioDevice::make(DEVICERATE);
  if (!usrp->open()) {
    //delete usrp;
    return EXIT_FAILURE;
  }
  RadioInterface* radio = new RadioInterface(usrp,3);
  Transceiver *trx = new Transceiver(5700,"127.0.0.1",SAMPSPERSYM,GSM::Time(3,0),radio);
  trx->receiveFIFO(radio->receiveFIFO());

  trx->start();
  //int i = 0;
  while(!gbShutdown) { sleep(1); }//i++; if (i==60) break;}

  cout << "Shutting down transceiver..." << endl;

//  trx->stop();
//  delete trx;
//  delete radio;
}
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
  if ( signal( SIGINT, ctrlCHandler ) == SIG_ERR )
  {
    cerr << "Couldn't install signal handler for SIGINT" << endl;
    exit(1);
  }

  if ( signal( SIGTERM, ctrlCHandler ) == SIG_ERR )
  {
    cerr << "Couldn't install signal handler for SIGTERM" << endl;
    exit(1);
  }
  // Configure logger.
  gLogInit("transceiver",gConfig.getStr("Log.Level").c_str(),LOG_LOCAL7);
  if (gLogConn.valid())
    Log::gHook = Connection::LogConnection::hook;

  // Device specific global initialization
  RadioDevice::staticInit();

  int numARFCN=1;
  if (argc>1) numARFCN = atoi(argv[1]);

  std::string deviceArgs = "";
  if (argc>2) deviceArgs = argv[2];

  srandom(time(NULL));

  int mOversamplingRate = 1;
  switch(numARFCN) {

	  // DAVID COMMENT: I have no way to test this, but I would bet that you can
	  // just change these numbers to get different oversampling rates for single-ARFCN
	  // operation..

  case 1: 
	mOversamplingRate = 1;
	break;
  case 2:
	mOversamplingRate = 6;
 	break;
  case 3:
	mOversamplingRate = 8;
	break;
  case 4:
	mOversamplingRate = 12;
	break;
  case 5:
	mOversamplingRate = 16;
	break;
  default:
	break;
  }
  int minOver = gConfig.getNum("TRX.MinOversampling");
  if (mOversamplingRate < minOver)
    mOversamplingRate = minOver;
  //int mOversamplingRate = numARFCN/2 + numARFCN;
  //mOversamplingRate = 15; //mOversamplingRate*2;
  //if ((numARFCN > 1) && (mOversamplingRate % 2)) mOversamplingRate++;

/*
  RAD1Device *usrp = new RAD1Device(mOversamplingRate*1625.0e3/6.0);
  //DummyLoad *usrp = new DummyLoad(mOversamplingRate*1625.0e3/6.0);
  usrp->make(false, deviceID); 
*/
  RadioDevice* usrp = RadioDevice::make(mOversamplingRate);
  if (!usrp->open(deviceArgs)) {
    LOG(ALERT) << "Transceiver exiting..." << std::endl;
    return EXIT_FAILURE;
  }

  RadioInterface* radio = new RadioInterface(usrp,3,SAMPSPERSYM,SAMPSPERSYM*mOversamplingRate,false,numARFCN);
  Transceiver *trx = new Transceiver(gConfig.getNum("TRX.Port"),gConfig.getStr("TRX.IP").c_str(),SAMPSPERSYM,GSM::Time(2,0),radio,
				     numARFCN,mOversamplingRate,false);
  trx->receiveFIFO(radio->receiveFIFO());

/*
  signalVector *gsmPulse = generateGSMPulse(2,1);
  BitVector normalBurstSeg = "0000101010100111110010101010010110101110011000111001101010000";
  BitVector normalBurst(BitVector(normalBurstSeg,gTrainingSequence[0]),normalBurstSeg);
  signalVector *modBurst = modulateBurst(normalBurst,*gsmPulse,8,1);
  signalVector *modBurst9 = modulateBurst(normalBurst,*gsmPulse,9,1);
  signalVector *interpolationFilter = createLPF(0.6/mOversamplingRate,6*mOversamplingRate,1);
  signalVector totalBurst1(*modBurst,*modBurst9);
  signalVector totalBurst2(*modBurst,*modBurst);
  signalVector totalBurst(totalBurst1,totalBurst2);
  scaleVector(totalBurst,usrp->fullScaleInputValue());
  double beaconFreq = -1.0*(numARFCN-1)*200e3;
  signalVector finalVec(625*mOversamplingRate);
  for (int j = 0; j < numARFCN; j++) {
	signalVector *frequencyShifter = new signalVector(625*mOversamplingRate);
	frequencyShifter->fill(1.0);
	frequencyShift(frequencyShifter,frequencyShifter,2.0*M_PI*(beaconFreq+j*400e3)/(1625.0e3/6.0*mOversamplingRate));
  	signalVector *interpVec = polyphaseResampleVector(totalBurst,mOversamplingRate,1,interpolationFilter);
	multVector(*interpVec,*frequencyShifter);
	addVector(finalVec,*interpVec); 	
  }
  signalVector::iterator itr = finalVec.begin();
  short finalVecShort[2*finalVec.size()];
  short *shortItr = finalVecShort;
  while (itr < finalVec.end()) {
	*shortItr++ = (short) (itr->real());
	*shortItr++ = (short) (itr->imag());
	itr++;
  }
  usrp->loadBurst(finalVecShort,finalVec.size());
*/
  trx->start();
  gLogConn.write("Starting transceiver");
  //int i = 0;
  while(!gbShutdown) { sleep(1); } //i++; if (i==60) exit(1);}

  cout << "Shutting down transceiver..." << endl;

//  trx->stop();
  delete trx;
//  delete radio;
}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
	int i, chanM, numARFCN = 1;
	int chanMap[CHAN_MAX];
	RadioDevice *usrp;
	RadioInterface* radio;
	DriveLoop *drive;
	Transceiver *trx[CHAN_MAX];

	gLogInit("transceiver", gConfig.getStr("Log.Level").c_str(), LOG_LOCAL7);

	if (argc > 1) {
		numARFCN = atoi(argv[1]);
		if (numARFCN > (CHAN_MAX - 1)) {
			LOG(ALERT) << numARFCN << " channels not supported with current build";
			exit(-1);
		}
	}

	srandom(time(NULL));

	if (setupSignals() < 0) {
		LOG(ERR) << "Failed to setup signal handlers, exiting...";
		exit(-1);
	}

	/*
	 * Select the number of channels according to the number of ARFCNs's
	 * and generate ARFCN-to-channelizer path mappings. The channelizer
	 * aliases and extracts 'M' equally spaced channels to baseband. The
	 * number of ARFCN's must be less than the number of channels in the
	 * channelizer.
	 */
	switch (numARFCN) {
	case 1:
		chanM = 1;
		break;
	case 2:
	case 3:
		chanM = 5;
		break;
	default:
		chanM = 10;
	}
	genChanMap(numARFCN, chanM, chanMap);

	/* Find a timing offset based on the channelizer configuration */
	double rxOffset = getRadioOffset(chanM);
	if (rxOffset == 0.0f) {
		LOG(ALERT) << "Rx sample offset not found, using offset of 0.0s";
		LOG(ALERT) << "Rx burst timing may not be accurate"; 
	}

	double deviceRate = chanM * CHAN_RATE * DEV_RESAMP_OUTRATE / DEV_RESAMP_INRATE;
	usrp = RadioDevice::make(deviceRate, rxOffset, DEVICE_TX_AMPL / numARFCN);
	if (!usrp->open()) {
		LOG(ALERT) << "Failed to open device, exiting...";
		return EXIT_FAILURE;
	}

	radio = new RadioInterface(usrp, chanM, 3, SAMPSPERSYM, 0, false);
	drive = new DriveLoop(5700, "127.0.0.1", chanM, chanMap[0],
			      SAMPSPERSYM, GSM::Time(3,0), radio);

	/* Create, attach, and activate all transceivers */
	createTrx(trx, chanMap, numARFCN, radio, drive);

	while (!gbShutdown) { 
		sleep(1);
	}

	LOG(NOTICE) << "Shutting down transceivers...";
	for (i = 0; i < numARFCN; i++) {
		trx[i]->shutdown();
	}

	/*
	 * Allow time for threads to end before we start freeing objects
	 */
	sleep(2);

	for (i = 0; i < numARFCN; i++) {
		delete trx[i];
	}

	delete drive;
	delete radio;
	delete usrp;
}