dbdexter-dev / sdrpp_radiosonde

Radiosonde decoder plugin for SDR++
MIT License
87 stars 12 forks source link

Building on Windows #4

Closed gvanem closed 2 years ago

gvanem commented 2 years ago

This is a great plugin!

Trying to build on Windows (using clang-cl), gave only 2 problems:

I patched 2 files to fix it:

--- a/src/decode/dfm09/decoder.cpp 2022-01-06 08:51:39
+++ b/src/decode/dfm09/decoder.cpp 2022-01-06 09:43:01
@@ -10,6 +10,12 @@

 static time_t my_timegm(struct tm *tm);

+#ifdef _WIN32
+  #define timegm(tm)                   my_timegm(tm)
+  #define setenv(env, val, overwrite)  _putenv_s(env, val)
+  #define unsetenv(env)                _putenv_s(env, "=")
+#endif
+
 DFM09Decoder::DFM09Decoder(dsp::stream<uint8_t> *in, void (*handler)(SondeData *data, void *ctx), void *ctx)
 {
        init(in, handler, ctx);

--- a/src/main.cpp 2022-01-06 08:51:39
+++ b/src/main.cpp 2022-01-06 10:44:54
@@ -24,6 +24,20 @@

 ConfigManager config;

+static std::string GetTempFile (std::string file)
+{
+    const char *env = getenv("TMP");  /* Unix / Apple */
+
+    if (!env)
+       env = getenv("TEMP");  /* Windows */
+    if (!env)
+       env = "/tmp";
+#ifdef _WIN32
+    return (std::string(env) + "/" + file);
+#else
+    return (std::string(env) + "\\" + file);
+#endif
+}

 RadiosondeDecoderModule::RadiosondeDecoderModule(std::string name)
 {
@@ -40,8 +54,8 @@

        config.acquire();
        if (!config.conf.contains(name)) {
-               config.conf[name]["gpxPath"] = "/tmp/radiosonde.gpx";
-               config.conf[name]["ptuPath"] = "/tmp/radiosonde_ptu.csv";
+               config.conf[name]["gpxPath"] = GetTempFile ("radiosonde.gpx");
+               config.conf[name]["ptuPath"] = GetTempFile ("radiosonde_ptu.csv");
                config.conf[name]["sondeType"] = 0;
                created = true;
        }

Hope you could clean it up.

IMHO most of this should go into utils.c. Or better yet, into sdrpp_core.dll.

dbdexter-dev commented 2 years ago

Took me a bit to come around and implement it, but I have added your changes and tested them with MSVC and clang-cl.

GetTempFile() is in utils.hpp, while timegm() and setenv() got implemented in the new decoding backend, sondedump.

Thank you for the suggestion and the .diff! Let me know if you have any issues compiling the updated codebase.

gvanem commented 2 years ago

Let me know if you have any issues compiling the updated codebase.

I have lots! Very confusing to understand where and how e.g. gpx.c vs gpx.cpp are used. In the SDR++ plugin or the sondedump program? Basically they both do the same AFAICS.

IMHO there should be common library for such functionality. Or just do:

--- a/src/gpx.cpp 2022-01-23 05:33:03
+++ b/src/gpx.cpp 2022-01-25 11:16:37
@@ -4,11 +4,18 @@
 #include <ctype.h>
 #include "gpx.hpp"

+#ifdef USE_sondedump_lib
+#include "sondedump/io/gpx.h"
+#endif
+
 #define GPX_TIME_FORMAT "%Y-%m-%dT%H:%M:%SZ"

 bool
 GPXWriter::init(const char *fname)
 {
+#ifdef USE_sondedump_lib
+       return gpx_init (m_GPXFile, fname);
+#else
        if (m_fd) deinit();

        m_fd = fopen(fname, "wb");
@@ -24,6 +31,7 @@
        m_offset = ftell(m_fd);
        terminateFile();
        return true;
+#endif
 }
gvanem commented 2 years ago

GetTempFile() is in utils.h

Another issue ; a getTempFile() is needed for sondedump.exe too. Add to utils.c? Otherwise it crashes good when NDEBUG is not defined.