Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial alpha of Skysight weather integration #182

Closed
wants to merge 4 commits into from

Conversation

jfwells
Copy link

@jfwells jfwells commented Apr 10, 2019

Hi, this is still work in progress and not yet ready to pull, but would appreciate some feedback and advice at this stage. Let me know if there's a better place for this.

In particular, but not limited to:

  • I have had to make some kludges in order to get the additional libraries to build for Android (curl with SSL support, and netcdf4 and C++ bindings). For example:

    • build/python/build/openssl.py: Latest versions of the openssl configure script require various environment variables to be set, including "ANDROID_HOME" and various things in PATH. I've taken ndk location from toolchain.env['ANDROID_NDK'], but I'm not clear whether this will always be available.
    • build/python/build/netcdfcxx.py is likewise a kludge -- I can only get this to build with these include files. I'm sure there's a better way to do his.
  • I use the main "render" loop to trigger updates in Skysight (should the forecast data be updated, should the overlay be advanced). I've copied the approach used by the RASP implementation here. I'm not clear if this is the right approach, or if a timer would be better here. One particular problem is that on the ground, the initial overlay is not displayed until a render is triggered, which can be some time if GPS is not yet connected. On the flip side, when in flight, or if the map is being manipulated, the render loop gets called far more frequently than is necessary for my needs. Data downloads in background threads, but as these cannot access the map safely I need an asynchronous trigger from the main thread somewhere.

  • The overlays in Android and Unix are pretty much identical, but they display quite differently. The images are fairly low-res, but when zoomed seem to be interpolated nicely on Unix. On Android they just show as larger, blocky pixels. Screenshot comparison on the forum. Any points as to why this might be would be much appreciated.

There are other stylistic issues to fix (not happy with the Metric/ActiveMetric/DisplayedMetric model, and I have an over-reliance on unneeded std::strings for a start). I also need to add documentaion, but I will fix those in the next round.

Note that this requires netcdf4 and netcdfcxx4 (development) libraries to compile. On Arch these are netcdf and netcdf-cxx.

Instructions for using the implementation are here: https://forum.xcsoar.org/viewtopic.php?f=7&t=3227&p=19689#p19689

Thanks in advance for any help/advice/review.

@jfwells jfwells changed the title Initial alpha of Skysight weaher integration Initial alpha of Skysight weather integration Apr 10, 2019
@Plantain
Copy link
Contributor

XCSoar developers are welcome to contact me (matthew .(at). skysight.io) if you need a SkySight account to work on or with this integration.

@MaxKellermann
Copy link
Contributor

Before we even begin: please note that linking XCSoar with OpenSSL is illegal, because the OpenSSL license is incompatible with the GPL. This means that you can be sued for copyright violation for distributing your build: http://jfwhome.com/XCSoar-debug.apk - please take it down quickly!

Now if you really enable CURL's https features, please make that a separate commit. (And of course, choose a TLS library which is compatible with the GPL.)

The OpenSSL/GPL situation is very unfortunate, but that's what it is, and we need to obey copyright law and licenses.

Keep your branch rebased on the official master branch. Do not merge! No "Merge remote-tracking branch 'upstream/master'" commits!

Copy link
Contributor

@MaxKellermann MaxKellermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start for this PR, but there are many many quirks and problems. I've left you a whole bunch of comments in the first round, for things that seemed obvious to me.

src/Dialogs/Settings/Panels/WeatherConfigPanel.cpp Outdated Show resolved Hide resolved

uint64_t elapsed = BrokenDateTime::NowUTC().ToUnixTimeUTC() - m.mtime;

second_row.Format(_("Data from %04u/%02u/%02u %02u:%02u to %04u/%02u/%02u %02u:%02u. Updated %s ago"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't roll your own date formatter.

src/Dialogs/Weather/SkysightDialog.cpp Outdated Show resolved Hide resolved
src/Dialogs/Weather/SkysightDialog.cpp Outdated Show resolved Hide resolved

SkysightActiveMetric a = skysight->GetActiveMetric(index);
if(!skysight->DownloadActiveMetric(a.metric->id))
ShowMessageBox(_("Couldn't update data."), _("Update Error"), MB_OK);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use C++ exceptions to propagate error details and show them here?

std::map<tstring, tstring> GetRegions() {
return api.regions;
}
tstring GetRegion() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allocates a std::string copy for no reason. Please keep the bloat in your code smaller!

bool MetricExists(const tstring id) {
return api.MetricExists(id);
}
int NumMetrics() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a signed integer?

Timer::Cancel();
}

SkysightMetric SkysightAPI::GetMetric(int index) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a signed integer?



int SkysightAPI::NumMetrics() {
return (int)metrics.size();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why cast to signed?


struct BrokenDateTime;

class SkysightAPI final : public Timer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this class? What is a SkysightAPI?

@jfwells
Copy link
Author

jfwells commented Apr 11, 2019

Before we even begin: please note that linking XCSoar with OpenSSL is illegal, because the OpenSSL license is incompatible with the GPL. This means that you can be sued for copyright violation for distributing your build: http://jfwhome.com/XCSoar-debug.apk - please take it down quickly!

Now if you really enable CURL's https features, please make that a separate commit. (And of course, choose a TLS library which is compatible with the GPL.)

The OpenSSL/GPL situation is very unfortunate, but that's what it is, and we need to obey copyright law and licenses.

Keep your branch rebased on the official master branch. Do not merge! No "Merge remote-tracking branch 'upstream/master'" commits!

Thanks. I'll hive off the Android changes into a separate commit for now, assuming that most people can build/test on machines that have curl libraries with SSL support.

Shame about OpenSSL (it looks like https support was removed from the codebase and I had wondered why). I must admit I had tried LibreSSL as getitng openSSL to compile was a bit of a pain. No luck. It looks like there are a few options: OpenSSL 3.0 (unstable), LibreSSL, BoringSSL and GnuTLS. I'll probably try them in reverse order, unless anyone has any experience or preferences that suggest otherwise.

Thanks very much for the additional comments and pointers.

@MaxKellermann
Copy link
Contributor

Since both LibreSSL and BoringSSL are OpenSSL forks (IIRC), I think they share the licensing problem.

@hor63
Copy link
Member

hor63 commented Apr 11, 2019 via email

@jfwells
Copy link
Author

jfwells commented Apr 11, 2019

The next major version of OpenSSL 3.0 is supposed to be released under the Apache 2.0 license which is compatible with the GPL. However I did not find any hint when this version is going to be released. I would not hold my breath while waiting on it.

Thanks. It does seem a bit early to use v3. I'm trying to get GnuTLS to compile. It depends on Nettle which in turn needs GMP.

I can get GnuTLS and Nettle (without GMP) to compile using libs.py/Automake, but I can't (yet) get GMP to pass the "configure" step as it fails on various compiler tests. Looks like it might be messy.

@hor63
Copy link
Member

hor63 commented Apr 11, 2019

but I can't (yet) get GMP to pass the "configure" step as it fails on various compiler tests. Looks like it might be messy.

What are the error messages? GMP is a prerequisite for compiling GCC. I don't care to remember how often I configured and compiled GMP over that course. You may send me a message directly.

@jfwells jfwells reopened this Jun 10, 2019
@jfwells
Copy link
Author

jfwells commented Jun 10, 2019

I've got a working compile with WolfSSL replacing openSSL. Sorry for the force-push mess.

The code is not ready for review yet -- I have more changes to make, and to clean up the commits. Hopefully within the next couple of weeks.

@lordfolken
Copy link
Contributor

lordfolken commented Jun 11, 2019

So I got this to compile on Debian stable.

The following changes where necessary for the UNIX target on Debian:
in:

apt install libnetcdf-dev libnetcdf-c++4-dev

diff --git a/src/Weather/Skysight/CDFDecoder.cpp b/src/Weather/Skysight/CDFDecoder.cpp
index b30e101063..22dd125cf1 100644
--- a/src/Weather/Skysight/CDFDecoder.cpp
+++ b/src/Weather/Skysight/CDFDecoder.cpp
@@ -29,8 +29,8 @@ Copyright_License {
#include <netcdfcpp.h>
#endif

-#include <geotiffio.h>
-#include <xtiffio.h>
+#include <geotiff/geotiffio.h>
+#include <geotiff/xtiffio.h>
#include "SkysightAPI.hpp"
#include "OS/FileUtil.hpp"
#include "LogFile.hpp"

The files where not found in the search path as they are indeed in the subdirectory on debian. I'm not sure how one does this correctly.

diff --git a/build/netcdf.mk b/build/netcdf.mk
index 5439bb28cc..c0f50dd4d4 100644
--- a/build/netcdf.mk
+++ b/build/netcdf.mk
@@ -3,7 +3,7 @@ NETCDF = y
ifneq ($(TARGET),ANDROID)
$(eval $(call pkg-config-library,NETCDF,netcdf-cxx4))
$(eval $(call link-library,netcdfcpp,NETCDF))
-NETCDF_LDLIBS = -lnetcdf_c++4 -lnetcdf -lhdf5_hl -lhdf5 -lsz -ldl
+NETCDF_LDLIBS = -v -lnetcdf_c++4 -lnetcdf -lhdf5_hl_cpp -lhdf5_cpp -lsz -ldl
else
NETCDF_LDLIBS += -l:libnetcdf_c++.a -l:libnetcdf.a
endif

For some reason the hdf5_hl library ends with _cpp in debian.

@jfwells
Copy link
Author

jfwells commented Jun 11, 2019

So I got this to compile on Debian stable.

Thanks so much for testing!

I'm not sure about the correct approach for the first issue, but for the second, I know that my NETCDF_LDLIBS lines that manually specifies the packages are temporary kludges. The pkg_config line above it should be doing the trick (I'm not sure what else needs to be done to make it so!)

@lordfolken
Copy link
Contributor

So I'm still working on compiling the android version. Since the netcdf library is not in the toolchain, I think it needs to be added to the thirdparty.mk in the build directory. But I haven't yet managed to compile it.

@lordfolken
Copy link
Contributor

Any progress on the implementation? :)

@MaxKellermann
Copy link
Contributor

No progress, closing for now

@kerel-fs kerel-fs added the needs-work this closed pull request requires some action to be merged label Sep 18, 2019
fb added a commit to fb/XCSoar that referenced this pull request Apr 12, 2020
fb added a commit to fb/XCSoar that referenced this pull request Apr 26, 2020
fb added a commit to fb/XCSoar that referenced this pull request Apr 29, 2020
This is almost identical to the code submitted in XCSoar#182.
The following was changed:
- no changes to thirdparty builds
- remove dead includes that made the build fail
fb added a commit to fb/XCSoar that referenced this pull request Apr 29, 2020
fb added a commit to fb/XCSoar that referenced this pull request May 2, 2020
This is almost identical to the code submitted in XCSoar#182.
The following was changed:
- no changes to thirdparty builds
- remove dead includes that made the build fail
si-gr pushed a commit to si-gr/XCSoar that referenced this pull request Jun 3, 2020
This is almost identical to the code submitted in XCSoar#182.
The following was changed:
- no changes to thirdparty builds
- remove dead includes that made the build fail
fb added a commit to fb/XCSoar that referenced this pull request Jun 4, 2020
This is almost identical to the code submitted in XCSoar#182.
The following was changed:
- no changes to thirdparty builds
- remove dead includes that made the build fail
si-gr pushed a commit to si-gr/XCSoar that referenced this pull request Jun 14, 2020
This is almost identical to the code submitted in XCSoar#182.
The following was changed:
- no changes to thirdparty builds
- remove dead includes that made the build fail
si-gr pushed a commit to si-gr/XCSoar that referenced this pull request Jun 14, 2020
This is almost identical to the code submitted in XCSoar#182.
The following was changed:
- no changes to thirdparty builds
- remove dead includes that made the build fail
si-gr pushed a commit to si-gr/XCSoar that referenced this pull request Jul 26, 2020
This is almost identical to the code submitted in XCSoar#182.
The following was changed:
- no changes to thirdparty builds
- remove dead includes that made the build fail
si-gr pushed a commit to si-gr/XCSoar that referenced this pull request Jul 28, 2020
This is almost identical to the code submitted in XCSoar#182.
The following was changed:
- no changes to thirdparty builds
- remove dead includes that made the build fail
si-gr pushed a commit to si-gr/XCSoar that referenced this pull request Jul 30, 2020
This is almost identical to the code submitted in XCSoar#182.
The following was changed:
- no changes to thirdparty builds
- remove dead includes that made the build fail
si-gr pushed a commit to si-gr/XCSoar that referenced this pull request Jul 30, 2020
This is almost identical to the code submitted by jfwells in XCSoar#182.
The following was changed:
- no changes to thirdparty builds
- remove dead includes that made the build fail

Further code refactoring:
- Change queues to std::queue
- Implement API requests as deque
- Remove rvalues in SkysightCallback
- Skysight/Metrics: timestamps as unsigned
- Rename metric to layer for consistency
- Use auto for iterator types
- SkysightImageFile: remove redundant filepath
- Remove SkysightImageFile
- Remove LoadFromFile
- Include geotiff in CDFDecoder compilation
- Change datatype of displayed layer to unsigned
- Remove timer inheritance
- Refactored DownloadStandbyLayer and removed SetStandbyLayerUpdateState
- Use new ResponseHandler implementation
- CDFDecoder: Allocate arrays on heap
si-gr pushed a commit to si-gr/XCSoar that referenced this pull request Aug 11, 2020
This is almost identical to the code submitted by jfwells in XCSoar#182.
The following was changed:
- no changes to thirdparty builds
- remove dead includes that made the build fail

Further code refactoring:
- Change queues to std::queue
- Implement API requests as deque
- Remove rvalues in SkysightCallback
- Skysight/Metrics: timestamps as unsigned
- Rename metric to layer for consistency
- Use auto for iterator types
- SkysightImageFile: remove redundant filepath
- Remove SkysightImageFile
- Remove LoadFromFile
- Include geotiff in CDFDecoder compilation
- Change datatype of displayed layer to unsigned
- Remove timer inheritance
- Refactored DownloadStandbyLayer and removed SetStandbyLayerUpdateState
- Use new ResponseHandler implementation
- CDFDecoder: Allocate arrays on heap
- CDFDecoder: Remove duplicate code
si-gr pushed a commit to si-gr/XCSoar that referenced this pull request Aug 11, 2020
This is almost identical to the code submitted by jfwells in XCSoar#182.
The following was changed:
- no changes to thirdparty builds
- remove dead includes that made the build fail

Further code refactoring:
- Change queues to std::queue
- Implement API requests as deque
- Remove rvalues in SkysightCallback
- Skysight/Metrics: timestamps as unsigned
- Rename metric to layer for consistency
- Use auto for iterator types
- SkysightImageFile: remove redundant filepath
- Remove SkysightImageFile
- Remove LoadFromFile
- Include geotiff in CDFDecoder compilation
- Change datatype of displayed layer to unsigned
- Remove timer inheritance
- Refactored DownloadStandbyLayer and removed SetStandbyLayerUpdateState
- Use new ResponseHandler implementation
- CDFDecoder: Allocate arrays on heap
si-gr pushed a commit to si-gr/XCSoar that referenced this pull request Jan 14, 2021
This is almost identical to the code submitted by jfwells in XCSoar#182.
The following was changed:
- no changes to thirdparty builds
- remove dead includes that made the build fail

Further code refactoring:
- Change queues to std::queue
- Implement API requests as deque
- Remove rvalues in SkysightCallback
- Skysight/Metrics: timestamps as unsigned
- Rename metric to layer for consistency
- Use auto for iterator types
- SkysightImageFile: remove redundant filepath
- Remove SkysightImageFile
- Remove LoadFromFile
- Include geotiff in CDFDecoder compilation
- Change datatype of displayed layer to unsigned
- Remove timer inheritance
- Refactored DownloadStandbyLayer and removed SetStandbyLayerUpdateState
- Use new ResponseHandler implementation
- CDFDecoder: Allocate arrays on heap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-work this closed pull request requires some action to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants