tkuester / taky

A simple python TAK server
MIT License
192 stars 42 forks source link

Translate location or course data to . delimitator if , is sent in #75

Closed skadakar closed 1 year ago

skadakar commented 2 years ago

I've seen this happen both in the point and the track level.

Example with course:

<event version="2.0" uid="xxxxxxx" type="a-f-G-U-C-I" time="2022-08-18T19:44:02.78Z" start="2022-08-18T19:44:02.78Z" stale="2022-08-18T19:50:17.78Z" how="h-g-i-g-o">
  <point lat="0" lon="0" hae="0" ce="9999999" le="9999999"/>
  <detail>
    <takv version="4.1.0.231" platform="WinTAK-CIV" os="Microsoft Windows 10 Home" device="LENOVO xxx"/>
    <contact callsign="xxxx" endpoint="*:-1:stcp"/>
    <uid Droid="Golf OPS"/>
    <__group name="Purple" role="HQ"/>
    <status battery="45"/>
    <track course="0,00000000" speed="0,00000000"/>
  </detail>
  <__taky_err>
    <!--Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/taky/cot/models/event.py", line 90, in from_elm
    ret.detail = TAKUser.from_elm(child, uid=ret.uid)
  File "/usr/local/lib/python3.8/dist-packages/taky/cot/models/takuser.py", line 91, in from_elm
    ret.course = float(d_elm.get("course"))
ValueError: could not convert string to float: '0,00000000'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/taky/cot/client.py", line 270, in feed
    evt = models.Event.from_elm(elm)
  File "/usr/local/lib/python3.8/dist-packages/taky/cot/models/event.py", line 97, in from_elm
    raise UnmarshalError(f"Issue parsing {child.tag}") from exc
taky.cot.models.errors.UnmarshalError: Issue parsing detail
-->
  </__taky_err>
</event>
tkuester commented 1 year ago

Oooog. There are four ways to go about fixing this.

  1. The hacky way is to say, "Look for commas, and replace with periods". This would probably work in most cases, but is a bit risky.

  2. The more appropriate way is to take the locale from the XML document (which is being tossed right now), and use that to parse number fields correctly per user. One frustration with this is that Python seemingly uses a global locale for the entire program.

  3. Another way is to just... treat it as a string instead of a float, and send that out without casting it at all. How do other ATAK / WinTAK clients handle getting commas?

  4. It seems, looking at the TAKServer implementation, that they are using Float.parseFloat(), which doesn't handle internationalization. Perhaps we can just ask clients to change their localization?

skadakar commented 1 year ago
  1. is what we've done so far and people are usually okay with that.

For instances where they are not there exist workarounds to trick single programs. Closing out the issue.

sgofferj commented 1 year ago

@tkuester At least WinTAK hangs / crashes on startup if the localization does not use . and , the US way...