1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

SDRdaemon: code cleanup

This commit is contained in:
f4exb 2018-09-15 21:50:12 +02:00
parent 94befa3e4e
commit a2a07a1121
4 changed files with 3 additions and 91 deletions

View File

@ -121,7 +121,6 @@ void CSocket::BindLocalAddressAndPort( const string &localAddress, unsigned shor
void CSocket::FillAddr( const string & localAddress, unsigned short localPort, sockaddr_in& localAddr )
{
////cout<<"\n Inside Fille addr:"<<localAddress <<" port:"<<localPort;
memset(&localAddr, 0, sizeof(localAddr)); // Zero out address structure
localAddr.sin_family = AF_INET; // Internet address
@ -134,7 +133,6 @@ void CSocket::FillAddr( const string & localAddress, unsigned short localPort, s
localAddr.sin_addr.s_addr = *((unsigned long *) host->h_addr_list[0]);
localAddr.sin_port = htons(localPort); // Assign port in network byte order
////cout<<"\n returning from Fille addr";
}
unsigned long int CSocket::GetReadBufferSize()
@ -175,19 +173,14 @@ void CSocket::SetNonBlocking( bool bBlocking )
void CSocket::ConnectToHost( const string &foreignAddress, unsigned short foreignPort )
{
//cout<<"\nstart Connect to host";
// Get the address of the requested host
sockaddr_in destAddr;
//cout<<"\ninside Connect to host";
FillAddr(foreignAddress, foreignPort, destAddr);
//cout<<"trying to connect to host";
// Try to connect to the given port
if (::connect(m_sockDesc, (sockaddr *) &destAddr, sizeof(destAddr)) < 0) {
throw CSocketException("Connect failed (connect())", true);
}
//cout<<"\n after connecting";
}
void CSocket::Send( const void *buffer, int bufferLen )
@ -249,7 +242,6 @@ int CSocket::OnDataRead(unsigned long timeToWait)
{
/* master file descriptor list */
fd_set master;
//struct timeval *ptimeout = NULL;
/* temp file descriptor list for select() */
fd_set read_fds;
@ -268,8 +260,8 @@ int CSocket::OnDataRead(unsigned long timeToWait)
/* copy it */
read_fds = master;
//cout<<"Waiting for select";
int nRet;
if (timeToWait == ULONG_MAX)
{
nRet = select(fdmax+1, &read_fds, NULL, NULL, NULL);
@ -300,13 +292,6 @@ void CSocket::SetBindToDevice( const string& sInterface )
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", sInterface.c_str());
//Todo:SO_BINDTODEVICE not declared error comes in CygWin, need to compile in Linux.
/*int nRet = ::setsockopt(m_sockDesc, SOL_SOCKET, SO_BINDTODEVICE, (void*)&ifr, sizeof(ifr));
if (nRet < 0)
{
throw CSocketException("Error in binding to device ", true);
}*/
}
UDPSocket::UDPSocket():CSocket(UdpSocket,IPv4Protocol)
@ -346,10 +331,8 @@ void UDPSocket::DisconnectFromHost()
void UDPSocket::SendDataGram( const void *buffer, int bufferLen, const string &foreignAddress,
unsigned short foreignPort )
{
//cout<<"Befor Fill addr";
sockaddr_in destAddr;
FillAddr(foreignAddress, foreignPort, destAddr);
//cout<<"Befor socket send";
// Write out the whole buffer as a single message.
if (sendto(m_sockDesc, (void *) buffer, bufferLen, 0,(sockaddr *) &destAddr, sizeof(destAddr)) != bufferLen)
{

View File

@ -100,7 +100,6 @@ void UDPSinkFEC::setRemoteAddress(const QString& address, uint16_t port)
void UDPSinkFEC::write(const SampleVector::iterator& begin, uint32_t sampleChunkSize)
{
//qDebug("UDPSinkFEC::write(: %u samples", sampleChunkSize);
const SampleVector::iterator end = begin + sampleChunkSize;
SampleVector::iterator it = begin;
@ -186,10 +185,7 @@ void UDPSinkFEC::write(const SampleVector::iterator& begin, uint32_t sampleChunk
int nbBlocksFEC = m_nbBlocksFEC;
int txDelay = m_txDelay;
//qDebug("UDPSinkFEC::write: push frame to worker: %u", m_frameCount);
m_udpWorker->pushTxFrame(m_txBlocks[m_txBlocksIndex], nbBlocksFEC, txDelay, m_frameCount);
//m_txThread = new std::thread(transmitUDP, this, m_txBlocks[m_txBlocksIndex], m_frameCount, nbBlocksFEC, txDelay, m_cm256Valid);
//transmitUDP(this, m_txBlocks[m_txBlocksIndex], m_frameCount, m_nbBlocksFEC, m_txDelay, m_cm256Valid);
m_txBlocksIndex = (m_txBlocksIndex + 1) % 4;
m_txBlockIndex = 0;
@ -282,8 +278,6 @@ void UDPSinkFECWorker::encodeAndTransmit(SDRDaemonSuperBlock *txBlockx, uint16_t
if ((nbBlocksFEC == 0) || !m_cm256Valid)
{
// qDebug("UDPSinkFECWorker::encodeAndTransmit: transmit frame without FEC to %s:%d", m_remoteAddress.toStdString().c_str(), m_remotePort);
for (unsigned int i = 0; i < UDPSinkFEC::m_nbOriginalBlocks; i++)
{
m_socket.SendDataGram((const void *) &txBlockx[i], (int) UDPSinkFEC::m_udpSize, m_remoteAddress.toStdString(), (uint32_t) m_remotePort);
@ -328,8 +322,6 @@ void UDPSinkFECWorker::encodeAndTransmit(SDRDaemonSuperBlock *txBlockx, uint16_t
// Transmit all blocks
// qDebug("UDPSinkFECWorker::encodeAndTransmit: transmit frame with FEC to %s:%d", m_remoteAddress.toStdString().c_str(), m_remotePort);
for (int i = 0; i < cm256Params.OriginalCount + cm256Params.RecoveryCount; i++)
{
#ifdef SDRDAEMON_PUNCTURE
@ -337,22 +329,8 @@ void UDPSinkFECWorker::encodeAndTransmit(SDRDaemonSuperBlock *txBlockx, uint16_t
continue;
}
#endif
// std::cerr << "UDPSinkFEC::transmitUDP:"
// << " i: " << i
// << " frameIndex: " << (int) m_txBlocks[i].header.frameIndex
// << " blockIndex: " << (int) m_txBlocks[i].header.blockIndex
// << " i.q:";
//
// for (int j = 0; j < 10; j++)
// {
// std::cerr << " " << (int) m_txBlocks[i].protectedBlock.m_samples[j].m_real
// << "." << (int) m_txBlocks[i].protectedBlock.m_samples[j].m_imag;
// }
//
// std::cerr << std::endl;
m_socket.SendDataGram((const void *) &txBlockx[i], (int) UDPSinkFEC::m_udpSize, m_remoteAddress.toStdString(), (uint32_t) m_remotePort);
//m_udpSocket->writeDatagram((const char *) &txBlockx[i], (int) UDPSinkFEC::m_udpSize, m_remoteAddress, m_remotePort);
usleep(txDelay);
}
}

View File

@ -43,52 +43,6 @@ class UDPSinkFEC : public QObject
public:
static const uint32_t m_udpSize = 512; //!< Size of UDP block in number of bytes
static const uint32_t m_nbOriginalBlocks = 128; //!< Number of original blocks in a protected block sequence
//#pragma pack(push, 1)
// struct MetaDataFEC
// {
// uint32_t m_centerFrequency; //!< 4 center frequency in kHz
// uint32_t m_sampleRate; //!< 8 sample rate in Hz
// uint8_t m_sampleBytes; //!< 9 MSB(4): indicators, LSB(4) number of bytes per sample
// uint8_t m_sampleBits; //!< 10 number of effective bits per sample
// uint8_t m_nbOriginalBlocks; //!< 11 number of blocks with original (protected) data
// uint8_t m_nbFECBlocks; //!< 12 number of blocks carrying FEC
// uint32_t m_tv_sec; //!< 16 seconds of timestamp at start time of super-frame processing
// uint32_t m_tv_usec; //!< 20 microseconds of timestamp at start time of super-frame processing
// uint32_t m_crc32; //!< 24 CRC32 of the above
//
// bool operator==(const MetaDataFEC& rhs)
// {
// return (memcmp((const char *) this, (const char *) &rhs, 12) == 0); // Only the 12 first bytes are relevant
// }
//
// void init()
// {
// memset((char *) this, 0, sizeof(MetaDataFEC));
// m_nbFECBlocks = -1;
// }
// };
//
// struct Header
// {
// uint16_t frameIndex;
// uint8_t blockIndex;
// uint8_t filler;
// uint32_t filler2;
// };
//
// static const int bytesPerBlock = m_udpSize - sizeof(Header);
//
// struct ProtectedBlock
// {
// uint8_t m_buf[bytesPerBlock];
// };
//
// struct SuperBlock
// {
// Header header;
// ProtectedBlock protectedBlock;
// };
//#pragma pack(pop)
/**
* Construct UDP sink

View File

@ -224,11 +224,8 @@ void SDRdaemonSourceInput::applySettings(const SDRdaemonSourceSettings& settings
settings.m_iqCorrection ? "true" : "false");
}
// if (force || (m_settings.m_dataAddress != settings.m_dataAddress) || (m_settings.m_dataPort != settings.m_dataPort))
// {
m_SDRdaemonUDPHandler->configureUDPLink(settings.m_dataAddress, settings.m_dataPort);
m_SDRdaemonUDPHandler->getRemoteAddress(remoteAddress);
// }
mutexLocker.unlock();
m_settings = settings;