junzis / pyModeS

Python decoder for Mode S and ADS-B signals
GNU General Public License v3.0
546 stars 153 forks source link

Fix surface positions for negative longitude #48

Closed richardjanssen closed 5 years ago

richardjanssen commented 5 years ago

Hi Junzi Sun,

First of all, great work on the pyModeS project, it is of great help in my coding activities!

When decoding surface position messages with the receiver reference location in the western hemisphere, I found that these messages were wrongly decoded. This is because the four possible longitude solutions are all positive, between 0 and 360 degrees, whereas the reference location has a negative longitude (i.e. between -180 and 0). Your algorithm always picks the longitude closest to the reference location. For example, when the four possible longitudes are [45, 135, 225, 315] and my reference location is -45, the decoded longitude will be +45.

A one line fix places all four possible longitudes between -180 and +180, before choosing the one that is closest to the reference location. So in the example the possible longitudes would be [45, 135, -135, -45] and the decoded longitude would be -45. I've added a small test with two messages on the western hemisphere to verify the new correct functionality.

Regards, Richard

junzis commented 5 years ago

@richardjanssen - Great! Many thanks for spotting and fixing this error!