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

Driver for LX Navigation Eos57 #1284

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

jirimaier
Copy link
Contributor

@jirimaier jirimaier commented Aug 16, 2023

Brief summary of the changes

Driver for LX Navigation Eos57 variometer.

Features

  • Receiving NMEA data, correctly interpreting altitude
  • Task declaration, including observation zones shape
  • Flight log download
  • MacCready and bugs and ballast synchronization

Compatibility

  • Tested on Eos57
  • Might work well with Era and Eos80 too. That is not tested, and it is possible that some features will not work properly. Anyway, it will most likely work better than the LXNAV driver.

Known issues

  • Declaration does not set the Landing entry in the task settings. This behavior is the same as with the LXNAV driver and is probably caused by a bug in Eos's firmware. It does not pose any problem for usage, as the Landing point doesn't have any practical usage.
  • Ballast synchronization may not be precise. The value provided by vario is relative to polar reference mass. The reference mass of vario's polar (can be different from XCSoar's polar) cannot be directly obtained and is estimated from polar coefficients.

Related issues and discussions

New generation LX Navigation Device #389
Wrong altitude from Lx Eos variometer #969
ERA80-Xcsoar #415

@MaxKellermann
Copy link
Contributor

This PRs copies lots of existing code. That is not acceptable and will not get merged.

@MaxKellermann MaxKellermann added the needs-work this closed pull request requires some action to be merged label Aug 16, 2023
@jirimaier jirimaier force-pushed the LX-Eos-Driver branch 2 times, most recently from 3dc8060 to 335c911 Compare August 16, 2023 23:22
@jirimaier
Copy link
Contributor Author

Thank you for the feedback.

I modified the code to call the LXNAV driver's methods for parsing LXWP1 and LXWP3 sentences instead of copying the code (I think this was the main issue with copying existing code).

I also modified the tests to use an LXWP1 sentence which is given as an example in the LX Navigation Communication Protocol documentation (instead of copying the one from the LXNAV driver test).

I think that now there is no copied code. Some parts may be similar because the protocol is similar, but not exactly the same. I don't think that I could reuse other code from the LXNAV driver without making modifications to that driver.

The Codacy Analysis shows issues regarding unused variables in src/Device/RecordedFlight.hpp, I believe these are false positives. These variables are used in DownloadFlight and GetFlightInfo methods of LXEosDevice.

@lordfolken
Copy link
Contributor

This ignores the vario's qnh setting.
We can hope that somehow xcsoars autoqnh and the varios undocumented autoqnh somehow arrive at the same conclusion.

@lordfolken
Copy link
Contributor

Also please test the driver post launch detection. I.e. with pressure on the tas. The vario behaves different post launch.

@jirimaier
Copy link
Contributor Author

This ignores the vario's qnh setting. We can hope that somehow xcsoars autoqnh and the varios undocumented autoqnh somehow arrive at the same conclusion.

The QNH of XCSoar is set based on the "alt_offset" from LXWP3 sentence.

I am not sure what you mean by "varios autoqnh". When the vario is turned on, the user sets the current altitude (airport elevation), and the QNH of the vario is set accordingly. The altitude offset in LXWP3 can then be converted to the QNH setting so that the QNH in XCSoar gets set to the same value as on the vario.

@lordfolken
Copy link
Contributor

This ignores the vario's qnh setting. We can hope that somehow xcsoars autoqnh and the varios undocumented autoqnh somehow arrive at the same conclusion.

The QNH of XCSoar is set based on the "alt_offset" from LXWP3 sentence.

I am not sure what you mean by "varios autoqnh". When the vario is turned on, the user sets the current altitude (airport elevation), and the QNH of the vario is set accordingly. The altitude offset in LXWP3 can then be converted to the QNH setting so that the QNH in XCSoar gets set to the same value as on the vario.

The alt_offset will remain the same value, after launch detection on the nmea side, no matter what you set the qnh on the varios ui to.

@jirimaier
Copy link
Contributor Author

I will test the in-flight behavior soon (probably tomorrow).

@jirimaier
Copy link
Contributor Author

jirimaier commented Aug 18, 2023

If I understand the behavior of the vario correctly:

  1. After turning on the vario, pilot sets the elevation.
  2. Vario calculates QNH based on the elevation
  3. Pilot can change the QNH value, but that doesn't change the altitude (which is intentional, because you just want to tweak the QNH while keeping the elevation that you set)
  4. After confirming this settings, the elevation cannot be changed, but it is possible to change the QNH in settings.
  5. Changing QNH before takeoff has no effect on altitude (same as in initial setup)
  6. Changing QNH in-fligh will change the true altitude

And you say that the alt_offset doesn't change when the QNH is changed in flight (This is a bug in the vario, right?).

So this means that if the pilot changes QNH on the vario during flight, they also have to change QNH in the XCSoar. This is not so big problem I guess. I just need to make sure that the new (manually set) QNH in XCSoar doesn't get overwritten to the old value by the next LXWP3 sentence (that has outdated alt_offset).

@lordfolken
Copy link
Contributor

That summarizes it pretty well.
Yes, its a bug at least in the era i have.
Basically stop accepting the alt_offset post takeoff.

@jirimaier
Copy link
Contributor Author

I tested it in flight today.

When changing QNH on the vario, the QNH in XCSoar also got changed.

So it seems that the bug is not present in Eos.

The baro altitude and FL shown by XCSoar always matched the values shown by vario, so the testing is successful.

To make it compatible with the bug in Era, I can modify the LXWP3 parsing so that the QNH will be set only if the alt_offset is different from the one received in previous LXWP3 (or if it is the first sentence since connecting).
That way, change in alt_offset will cause change of QNH, but constant value will be ignored. It wouldn't affect the behavior in Eos, and also would fix the problem with overwriting new QNH se by user in case of Era.

Anyway, I noticed that if I set the QNH in XCSoar manually, all changes of QNH in the vario are ignored.
Is this intended behavior of XCSoar (that it ignores attempts to change QNH from the driver once the QNH was changed by user)?

@jirimaier
Copy link
Contributor Author

It is a bit strange that in the initial setup of the vario, the elevation and QNH can be set independently. In XCSoar, the QNH and the difference between true and standard altitude are totaly dependent on each other.

The alt_offset in LXWP3 only depends on the initial elevation and on in-flight changes of QNH, it doesn't depend on the initial QNH.

If the initial QNH on vario is changed to different value than the one calculated from elevation (for whatever reason), the QNH in XCSoar (based on alt_offset) will be different from the QNH in vario. But this is fine, because the QNH in XCSoar will lead to correct conversion of true altitude to standard altitude,as it is based on the alt_offset.

@jirimaier
Copy link
Contributor Author

I noticed one more issue:

If the Eos is connected together with another device (Flarm, for example), the altitude provided by the other dece is prioritized regardless of the order in the device list.

In other words: the info.ProvideBaroAltitudeTrue(altitude_true) is "weaker" than info.ProvidePressureAltitude(value).

Can this be considered a bug in XCSoar, or is it a feature?

@jirimaier jirimaier marked this pull request as draft August 24, 2023 18:51
@jirimaier jirimaier force-pushed the LX-Eos-Driver branch 2 times, most recently from 509b4d7 to 09671ff Compare August 25, 2023 13:56
uint8_t prg[12];

// TP Longitude in degrees multiplied by 60000.0f
int32_t lon[12];
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the byte order?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

big-endian, I added that to the comment

Copy link
Contributor

Choose a reason for hiding this comment

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

Then why not use a safe class like PackedBE32 here? That way, it's impossible to misuse it, and you don't even need a comment.


uint8_t bAutoNext = 1; // Is this auto next TP or AAT TP
uint8_t bIsLine = 0; // Is this line flag
float fA1; // Angle A1 in radians
Copy link
Contributor

Choose a reason for hiding this comment

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

Byte order? What bit format is being used? Is this bit format guaranteed on all CPU architectures?

Comment on lines 185 to 177
LXEosDevice::CalculateCRC(std::byte* msg, const int len, const uint8_t initial)
{
uint8_t result{ initial };

for (int byte = 0; byte < len; byte++) {
uint8_t d = static_cast<uint8_t>(msg[byte]);
for (int count = 8; --count >= 0; d <<= 1) {
uint8_t tmp = result ^ d;
result <<= 1;
if ((tmp & 0x80) != 0)
result ^= 0x69;
}
}

return result;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicate code, already exists in the LXNAV driver

const uint8_t cmd = 0xF1;

// Flight ID is the index (1 = newest), not the ID from FlightInfo
uint16_t flight_id;
Copy link
Contributor

Choose a reason for hiding this comment

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

Byte order?

}

bool
LXEosDevice::GetFlightLogBlock(AllocatedArray<std::byte>& block,
Copy link
Contributor

Choose a reason for hiding this comment

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

This function should return the AllocatedArray instead of passing it by reference; throw an exception on error.

Comment on lines 180 to 183
std::memcpy(&julianDate, &response[13], 4);
std::memcpy(&time_takeoff, &response[17], 4);
std::memcpy(&time_landing, &response[21], 4);
std::memcpy(&file_size, &response[89], 4);
Copy link
Contributor

Choose a reason for hiding this comment

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

Byte order? Why are you using a byte array with hard-coded offsets here, instead of declaring a (documented) struct, as you did in other parts of this PR?

env,
std::chrono::milliseconds(5000));
} catch (...) {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the point of catching this exception? You discard all information about the failure by converting it tofalse here.

uint8_t crc = CalculateCRC(responseHeader, sizeof(responseHeader), 0xFF);
crc = CalculateCRC(block.data(), block.size(), crc);
if (CalculateCRC(crc_byte, 1, crc) != 0)
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Throw exception instead of returning false

}

BrokenDate
LXEosDevice::julianToDate(uint32_t julian_date)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it could be useful to move this to class BrokenDate, e.g. BrokenDate::FromJulianDay(unsigned).

@jirimaier jirimaier force-pushed the LX-Eos-Driver branch 4 times, most recently from 2dda702 to 910e893 Compare April 14, 2024 21:39
@jirimaier jirimaier force-pushed the LX-Eos-Driver branch 9 times, most recently from b361cf7 to 6172135 Compare April 28, 2024 14:34
NEWS.txt Outdated Show resolved Hide resolved
@jirimaier jirimaier force-pushed the LX-Eos-Driver branch 6 times, most recently from 78a732e to 80e5cd8 Compare April 29, 2024 21:15
@jirimaier jirimaier marked this pull request as ready for review April 29, 2024 21:16
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.

New generation LX Navigation Device
3 participants