Skip to content

Commit f213fa6

Browse files
committed
Clean up for Windows
1 parent 1aac82a commit f213fa6

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
build
1+
# Ignore CMake generated output
2+
/build
3+
*~
4+
*.swp
5+
/.vscode

Settings.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
#include <algorithm>
2828
#include <cstring>
2929

30+
#ifdef _MSC_VER
31+
#include <BaseTsd.h>
32+
typedef SSIZE_T ssize_t;
33+
#endif
34+
3035
#define DEFAULT_PORT "1234"
3136

3237
SoapyRTLTCP::SoapyRTLTCP(const SoapySDR::Kwargs &args):
@@ -113,16 +118,16 @@ int SoapyRTLTCP::recvHeader()
113118
// worst case at 100ms for 12 bytes is 1.2 secs
114119
struct timeval tv = {0, 100000};
115120

116-
int ret = select(serverSocket + 1, &readfds, NULL, NULL, &tv);
117-
if (ret)
121+
SOCKET ret = select(serverSocket + 1, &readfds, NULL, NULL, &tv);
122+
if (ret != INVALID_SOCKET)
118123
{
119-
ssize_t received = recv(serverSocket, (char *)&cmd + (sizeof(cmd) - left), left, 0);
124+
ssize_t received = recv(serverSocket, &cmd[0] + (sizeof(cmd) - left), left, 0);
120125
if (received < 0)
121126
{
122127
SoapySDR_logf(SOAPY_SDR_DEBUG, "server recv error");
123128
break;
124129
}
125-
left -= received;
130+
left -= (int)received;
126131
}
127132
}
128133

@@ -150,16 +155,16 @@ int SoapyRTLTCP::sendCommand(rtltcpCommand command, unsigned int param)
150155
// worst case at 100ms for 5 bytes is 0.5 secs
151156
struct timeval tv = {0, 100000};
152157

153-
int ret = select(serverSocket + 1, NULL, &writefds, NULL, &tv);
154-
if (ret)
158+
SOCKET ret = select(serverSocket + 1, NULL, &writefds, NULL, &tv);
159+
if (ret != INVALID_SOCKET)
155160
{
156161
ssize_t sent = send(serverSocket, (char *)&cmd + (sizeof(cmd) - left), left, 0);
157162
if (sent < 0)
158163
{
159164
SoapySDR_logf(SOAPY_SDR_WARNING, "RTL-TCP server send error");
160165
break;
161166
}
162-
left -= sent;
167+
left -= (int)sent; // this is sound since sent must be small
163168
}
164169
}
165170

@@ -233,7 +238,7 @@ SOCKET SoapyRTLTCP::connectToServer(char const *serverName, char const *defaultP
233238
}
234239

235240
struct sockaddr_storage addr = {};
236-
unsigned addr_len = sizeof(addr);
241+
socklen_t addr_len = sizeof(addr);
237242
SOCKET sock = INVALID_SOCKET;
238243
for (res = res0; res; res = res->ai_next)
239244
{
@@ -514,7 +519,7 @@ double SoapyRTLTCP::getGain(const int /*direction*/, const size_t /*channel*/, c
514519
}
515520
if (tunerType == RTLSDR_TUNER_E4000)
516521
{
517-
return getE4000Gain(stage, IFGain[stage - 1]);
522+
return getE4000Gain(stage, (int)IFGain[stage - 1]);
518523
}
519524

520525
return IFGain[stage - 1];
@@ -940,6 +945,7 @@ std::vector<int> SoapyRTLTCP::rtlTunerGains(rtlsdr_tuner tunerType)
940945
case RTLSDR_TUNER_R820T:
941946
case RTLSDR_TUNER_R828D:
942947
return r82xx_gains;
948+
case RTLSDR_TUNER_UNKNOWN:
943949
default:
944950
return unknown_gains;
945951
}

SoapyRTLTCP.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ class SoapyRTLTCP : public SoapySDR::Device
284284
rtltcpRXFormat rxFormat;
285285
rtlsdr_tuner tunerType;
286286
int tunerGainCount;
287-
uint32_t sampleRate, centerFrequency, bandwidth;
287+
uint32_t sampleRate, centerFrequency;
288+
double bandwidth;
288289
int ppm, directSamplingMode;
289290
bool iqSwap, gainMode, offsetMode, digitalAGC, biasTee;
290291
double IFGain[6], tunerGain;

Streaming.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
#include <climits> //SHRT_MAX
3131
#include <cstring> // memcpy
3232

33+
#ifdef _MSC_VER
34+
#include <BaseTsd.h>
35+
typedef SSIZE_T ssize_t;
36+
#endif
37+
3338
std::vector<std::string> SoapyRTLTCP::getStreamFormats(const int /*direction*/, const size_t /*channel*/) const
3439
{
3540
std::vector<std::string> formats;
@@ -99,7 +104,7 @@ void SoapyRTLTCP::net_recv_operation(void)
99104
}
100105

101106
// Block on recv
102-
ssize_t received = recv(serverSocket, _buf + tail, chunk_size, 0);
107+
ssize_t received = recv(serverSocket, (char *)_buf + tail, (int)chunk_size, 0);
103108
if (received <= 0)
104109
{
105110
SoapySDR_logf(SOAPY_SDR_DEBUG, "RTL-TCP server recv end");
@@ -168,7 +173,7 @@ SoapySDR::Stream *SoapyRTLTCP::setupStream(
168173
// Create lookup tables
169174
for (unsigned int i = 0; i <= 0xffff; i++)
170175
{
171-
#if (__BYTE_ORDER == __LITTLE_ENDIAN)
176+
#if (__BYTE_ORDER__ == __LITTLE_ENDIAN__)
172177
float re = ((i & 0xff) - 127.4f) * (1.0f / 128.0f);
173178
float im = ((i >> 8) - 127.4f) * (1.0f / 128.0f);
174179
#else
@@ -388,5 +393,5 @@ int SoapyRTLTCP::readStream(
388393
if (_buf_head != _buf_tail)
389394
flags |= SOAPY_SDR_MORE_FRAGMENTS;
390395

391-
return returnedElems;
396+
return (int)returnedElems; // this conversion is sound since _buf is small
392397
}

0 commit comments

Comments
 (0)