Skip to content

Commit 3f54566

Browse files
committed
Clean up for Windows
1 parent 1aac82a commit 3f54566

File tree

4 files changed

+76
-60
lines changed

4 files changed

+76
-60
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: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -97,103 +97,103 @@ class SoapyRTLTCP : public SoapySDR::Device
9797
public:
9898
SoapyRTLTCP(const SoapySDR::Kwargs &args);
9999

100-
~SoapyRTLTCP(void);
100+
~SoapyRTLTCP(void) override;
101101

102102
/*******************************************************************
103103
* Identification API
104104
******************************************************************/
105105

106-
std::string getDriverKey(void) const;
106+
std::string getDriverKey(void) const override;
107107

108-
std::string getHardwareKey(void) const;
108+
std::string getHardwareKey(void) const override;
109109

110-
SoapySDR::Kwargs getHardwareInfo(void) const;
110+
SoapySDR::Kwargs getHardwareInfo(void) const override;
111111

112112
/*******************************************************************
113113
* Channels API
114114
******************************************************************/
115115

116-
size_t getNumChannels(const int) const;
116+
size_t getNumChannels(const int) const override;
117117

118-
bool getFullDuplex(const int direction, const size_t channel) const;
118+
bool getFullDuplex(const int direction, const size_t channel) const override;
119119

120120
/*******************************************************************
121121
* Stream API
122122
******************************************************************/
123123

124-
std::vector<std::string> getStreamFormats(const int direction, const size_t channel) const;
124+
std::vector<std::string> getStreamFormats(const int direction, const size_t channel) const override;
125125

126-
std::string getNativeStreamFormat(const int direction, const size_t channel, double &fullScale) const;
126+
std::string getNativeStreamFormat(const int direction, const size_t channel, double &fullScale) const override;
127127

128-
SoapySDR::ArgInfoList getStreamArgsInfo(const int direction, const size_t channel) const;
128+
SoapySDR::ArgInfoList getStreamArgsInfo(const int direction, const size_t channel) const override;
129129

130130
SoapySDR::Stream *setupStream(
131131
const int direction,
132132
const std::string &format,
133133
const std::vector<size_t> &channels = std::vector<size_t>(),
134-
const SoapySDR::Kwargs &args = SoapySDR::Kwargs());
134+
const SoapySDR::Kwargs &args = SoapySDR::Kwargs()) override;
135135

136-
void closeStream(SoapySDR::Stream *stream);
136+
void closeStream(SoapySDR::Stream *stream) override;
137137

138-
size_t getStreamMTU(SoapySDR::Stream *stream) const;
138+
size_t getStreamMTU(SoapySDR::Stream *stream) const override;
139139

140140
int activateStream(
141141
SoapySDR::Stream *stream,
142142
const int flags = 0,
143143
const long long timeNs = 0,
144-
const size_t numElems = 0);
144+
const size_t numElems = 0) override;
145145

146-
int deactivateStream(SoapySDR::Stream *stream, const int flags = 0, const long long timeNs = 0);
146+
int deactivateStream(SoapySDR::Stream *stream, const int flags = 0, const long long timeNs = 0) override;
147147

148148
int readStream(
149149
SoapySDR::Stream *stream,
150150
void *const *buffs,
151151
const size_t numElems,
152152
int &flags,
153153
long long &timeNs,
154-
const long timeoutUs = 100000);
154+
const long timeoutUs = 100000) override;
155155

156156
/*******************************************************************
157157
* Antenna API
158158
******************************************************************/
159159

160-
std::vector<std::string> listAntennas(const int direction, const size_t channel) const;
160+
std::vector<std::string> listAntennas(const int direction, const size_t channel) const override;
161161

162-
void setAntenna(const int direction, const size_t channel, const std::string &name);
162+
void setAntenna(const int direction, const size_t channel, const std::string &name) override;
163163

164-
std::string getAntenna(const int direction, const size_t channel) const;
164+
std::string getAntenna(const int direction, const size_t channel) const override;
165165

166166
/*******************************************************************
167167
* Frontend corrections API
168168
******************************************************************/
169169

170-
bool hasDCOffsetMode(const int direction, const size_t channel) const;
170+
bool hasDCOffsetMode(const int direction, const size_t channel) const override;
171171

172-
bool hasFrequencyCorrection(const int direction, const size_t channel) const;
172+
bool hasFrequencyCorrection(const int direction, const size_t channel) const override;
173173

174-
void setFrequencyCorrection(const int direction, const size_t channel, const double value);
174+
void setFrequencyCorrection(const int direction, const size_t channel, const double value) override;
175175

176-
double getFrequencyCorrection(const int direction, const size_t channel) const;
176+
double getFrequencyCorrection(const int direction, const size_t channel) const override;
177177

178178
/*******************************************************************
179179
* Gain API
180180
******************************************************************/
181181

182-
std::vector<std::string> listGains(const int direction, const size_t channel) const;
182+
std::vector<std::string> listGains(const int direction, const size_t channel) const override;
183183

184-
bool hasGainMode(const int direction, const size_t channel) const;
184+
bool hasGainMode(const int direction, const size_t channel) const override;
185185

186-
void setGainMode(const int direction, const size_t channel, const bool automatic);
186+
void setGainMode(const int direction, const size_t channel, const bool automatic) override;
187187

188-
bool getGainMode(const int direction, const size_t channel) const;
188+
bool getGainMode(const int direction, const size_t channel) const override;
189189

190-
void setGain(const int direction, const size_t channel, const double value);
190+
void setGain(const int direction, const size_t channel, const double value) override;
191191

192-
void setGain(const int direction, const size_t channel, const std::string &name, const double value);
192+
void setGain(const int direction, const size_t channel, const std::string &name, const double value) override;
193193

194-
double getGain(const int direction, const size_t channel, const std::string &name) const;
194+
double getGain(const int direction, const size_t channel, const std::string &name) const override;
195195

196-
SoapySDR::Range getGainRange(const int direction, const size_t channel, const std::string &name) const;
196+
SoapySDR::Range getGainRange(const int direction, const size_t channel, const std::string &name) const override;
197197

198198
/*******************************************************************
199199
* Frequency API
@@ -204,35 +204,35 @@ class SoapyRTLTCP : public SoapySDR::Device
204204
const size_t channel,
205205
const std::string &name,
206206
const double frequency,
207-
const SoapySDR::Kwargs &args = SoapySDR::Kwargs());
207+
const SoapySDR::Kwargs &args = SoapySDR::Kwargs()) override;
208208

209-
double getFrequency(const int direction, const size_t channel, const std::string &name) const;
209+
double getFrequency(const int direction, const size_t channel, const std::string &name) const override;
210210

211-
std::vector<std::string> listFrequencies(const int direction, const size_t channel) const;
211+
std::vector<std::string> listFrequencies(const int direction, const size_t channel) const override;
212212

213-
SoapySDR::RangeList getFrequencyRange(const int direction, const size_t channel, const std::string &name) const;
213+
SoapySDR::RangeList getFrequencyRange(const int direction, const size_t channel, const std::string &name) const override;
214214

215-
SoapySDR::ArgInfoList getFrequencyArgsInfo(const int direction, const size_t channel) const;
215+
SoapySDR::ArgInfoList getFrequencyArgsInfo(const int direction, const size_t channel) const override;
216216

217217
/*******************************************************************
218218
* Sample Rate API
219219
******************************************************************/
220220

221-
void setSampleRate(const int direction, const size_t channel, const double rate);
221+
void setSampleRate(const int direction, const size_t channel, const double rate) override;
222222

223-
double getSampleRate(const int direction, const size_t channel) const;
223+
double getSampleRate(const int direction, const size_t channel) const override;
224224

225-
std::vector<double> listSampleRates(const int direction, const size_t channel) const;
225+
std::vector<double> listSampleRates(const int direction, const size_t channel) const override;
226226

227-
SoapySDR::RangeList getSampleRateRange(const int direction, const size_t channel) const;
227+
SoapySDR::RangeList getSampleRateRange(const int direction, const size_t channel) const override;
228228

229-
void setBandwidth(const int direction, const size_t channel, const double bw);
229+
void setBandwidth(const int direction, const size_t channel, const double bw) override;
230230

231-
double getBandwidth(const int direction, const size_t channel) const;
231+
double getBandwidth(const int direction, const size_t channel) const override;
232232

233-
std::vector<double> listBandwidths(const int direction, const size_t channel) const;
233+
std::vector<double> listBandwidths(const int direction, const size_t channel) const override;
234234

235-
SoapySDR::RangeList getBandwidthRange(const int direction, const size_t channel) const;
235+
SoapySDR::RangeList getBandwidthRange(const int direction, const size_t channel) const override;
236236

237237
/*******************************************************************
238238
* Utility
@@ -247,11 +247,11 @@ class SoapyRTLTCP : public SoapySDR::Device
247247
* Settings API
248248
******************************************************************/
249249

250-
SoapySDR::ArgInfoList getSettingInfo(void) const;
250+
SoapySDR::ArgInfoList getSettingInfo(void) const override;
251251

252-
void writeSetting(const std::string &key, const std::string &value);
252+
void writeSetting(const std::string &key, const std::string &value) override;
253253

254-
std::string readSetting(const std::string &key) const;
254+
std::string readSetting(const std::string &key) const override;
255255

256256
private:
257257
SOCKET connectToServer(char const *serverName, char const *defaultPort);
@@ -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)