MCPcopy Create free account
hub / github.com/RangeNetworks/openbts / writeSamples

Method writeSamples

Transceiver52M/USRPDevice.cpp:453–506  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

451}
452
453int USRPDevice::writeSamples(short *buf, int len, bool *underrun,
454 unsigned long long timestamp,
455 bool isControl)
456{
457 writeLock.lock();
458
459#ifndef SWLOOPBACK
460 if (!m_uTx) return 0;
461
462 static uint32_t outData[128*20];
463
464 for (int i = 0; i < len*2; i++) {
465 buf[i] = host_to_usrp_short(buf[i]);
466 }
467
468 int numWritten = 0;
469 unsigned isStart = 1;
470 unsigned RSSI = 0;
471 unsigned CHAN = (isControl) ? 0x01f : 0x00;
472 len = len*2*sizeof(short);
473 int numPkts = (int) ceil((float)len/(float)504);
474 unsigned isEnd = (numPkts < 2);
475 uint32_t *outPkt = outData;
476 int pktNum = 0;
477 while (numWritten < len) {
478 // pkt is pointer to start of a USB packet
479 uint32_t *pkt = outPkt + pktNum*128;
480 isEnd = (len - numWritten <= 504);
481 unsigned payloadLen = ((len - numWritten) < 504) ? (len-numWritten) : 504;
482 pkt[0] = (isStart << 12 | isEnd << 11 | (RSSI & 0x3f) << 5 | CHAN) << 16 | payloadLen;
483 pkt[1] = timestamp & 0x0ffffffffll;
484 memcpy(pkt+2,buf+(numWritten/sizeof(short)),payloadLen);
485 numWritten += payloadLen;
486 timestamp += payloadLen/2/sizeof(short);
487 isStart = 0;
488 pkt[0] = host_to_usrp_u32(pkt[0]);
489 pkt[1] = host_to_usrp_u32(pkt[1]);
490 pktNum++;
491 }
492 m_uTx->write((const void*) outPkt,sizeof(uint32_t)*128*numPkts,NULL);
493
494 samplesWritten += len/2/sizeof(short);
495 writeLock.unlock();
496
497 return len/2/sizeof(short);
498#else
499 int retVal = len;
500 memcpy(loopbackBuffer+loopbackBufferSize,buf,sizeof(short)*2*len);
501 samplesWritten += retVal;
502 loopbackBufferSize += retVal*2;
503
504 return retVal;
505#endif
506}
507
508bool USRPDevice::updateAlignment(TIMESTAMP timestamp)
509{

Callers

nothing calls this directly

Calls 3

host_to_usrp_shortFunction · 0.85
host_to_usrp_u32Function · 0.85
writeMethod · 0.45

Tested by

no test coverage detected