Hello RakWireless Team,
I traced the 400 meters error to the OutOfChina function in the gps.c source file , https://github.com/RAKWireless/RAK5205-WisTrio-LoRa/blob/master/src/LoRaWAN/master/system/gps.c
and the gps84_To_Gcj02() function where you have a defined offsetting if the coordinates are within “China”. The boundaries set on the OutOfChina() are actually encompassing a huge geographic area, from near Russia at the north side and Borneo on the south side and at middle of pacific ocean on the east side. There is a need to revise the values for the lat/lon pairs defined in the OutOfChina() function. You are defining a rectangular boundary with the set of coordinates.My suggestion is to disable this coordinates checking function since it is flawed. China is not on a rectangular box.
BTW, i can upload and provide my test source code in C on this , using the sources at gps.c
The current code is the one causing the 400 meters offset to the south/east.
Expected: latitude 14.510805, longitude 121.032250
Transformed: latitude 14.509103 longitude 121.035666
I dont have uVision Kiel IDE and I cant compile a firmware with revisions based on github sources so I did standalone run for the gps routines in Linux GCC. If you can show how I can revise this on RUI, I will be glad to do so.
I noticed that logic at OutOfChina() is not quite correct because of the big scope of the boundary defined.
static bool outOfChina(double lat, double lon) {
if (lon < 72.004 || lon > 137.8347)
return true;
if (lat < 0.8293 || lat > 55.8271)
return true;
return false;
}
since the calling function was done in gps84_To_Gcj02() as
if (outOfChina(lat, lon)) {
*lat02 = lat;
*lon02 = lon;
return;
}
We should be returning true when not on the boundaries and false if the coordinates fall within the boundaries. The if statement expects a logical True value to execute what is inside the {…}
In sample case for my revision just to show the program error (misjudjing im in China since the box boundary is very big) ,I use the following coordinates, 14.51N, 121.03E,
A = 14.51 < 0.8293 is false
B = 14.51 > 55.8271 is false
C = 121.03 < 72.004 is false
D = 121.03 > 137.8347 is false
(A || B) && (C||D) results to false, making the if statement not evaluated and returns true.
On my simulation (on LInux GCC ) i revised it to ;
(this is actually still not correct if you really want rectangular boundary, I made this just to demo the error of the logic on the OutOfChina() function because of the big boundary)
static bool outOfChina(double lat, double lon) {
if ((lon < 72.004 || lon > 137.8347) && (lat < 0.8293 || lat > 55.8271))
return false;
return true;
}
This now gives me a correct reading based on my simulation and location
If you can revise such, and compile a new firmware, I would be glad to test
The results are consistent with what Im seeing from the RAK5205 with firmware version 3.0.0.3.L, which is being offset by 400 meters towards south east.
Here is a log of my simulation on linux pc
##############################################################
This is the GPS Sentence : $GPGGA,092725.00,1430.64833,N,12101.93500,E,1,08,1.01,499.6,M,48.0,M,*51
GPS84 OutOfChina Original Code Scenario
5 1
NMEA GPS Sentence is checksum is correct
1 NMEA NmeaDataType: GPGGA,
1 NMEA UTC Time: 092725.00,
1 NMEA NmeaLatitude: 1430.64833,
1 NMEA NmeaLatitudePole: N,
1 NMEA NmeaLongitude: 12101.93500,
1 NMEA NmeaLongitudePole: E,
from GpsFormatData -->> latitude: 14.510805, longitude: 121.032250 , altitude: 499.6, ;
NMEA Data Type : GPGGA
NMEA UTC Time : 092725.00
NMEA Latitude : 1430.64833
NMEA Latitude Pole : N
NMEA Longitude : 12101.93500
NMEA Longitude Pole: E
NMEA NmeaFixQuality: 1
NMEA NmeaSatelliteTracked: 08
NMEA NmeaHorizontalDilution: 1.01
NMEA NmeaAltitude: 499.6
NMEA NmeaAltitudeUnit: M
NMEA NmeaHeightGeoid: 48.0
NMEA NmeaHeightGeoidUnit: M
NMEA NmeaChecksum: *51
from GpsFormatData -->> latitude: 14.510805, longitude: 121.032250 , altitude: 499.6 ;
Before transforming geographic coordinates inside gps84_To_Gcj02 function
Before transformation : latitude : 14.510805, longitude : 121.032250
after calling gps84_To_Gcj02 --> latitude: 14.509103 , longitude: 121.035666
Inside FormatToLPP after gps84_To_Gcj02 function executed
@FormatToLPP latitude: 14.509103, longitude: 121.035666 , altitudeGps: 499m
GPS Cayenne LPP Data 0: 01
GPS Cayenne LPP Data 1: 88
GPS Cayenne LPP Data 2: 02
GPS Cayenne LPP Data 3: 36
GPS Cayenne LPP Data 4: c3
GPS Cayenne LPP Data 5: 12
GPS Cayenne LPP Data 6: 77
GPS Cayenne LPP Data 7: f4
GPS Cayenne LPP Data 8: 00
GPS Cayenne LPP Data 9: c2
GPS Cayenne LPP Data 10: ec
GPS Cayenne LPP Data : 01880236c31277f400c2ec
Expected: latitude 14.510805, longitude 121.032250
Transformed: latitude 14.509103 longitude 121.035666
GPS84 OutOfChina Corrected and Revised Code Scenario
5 1
NMEA GPS Sentence is checksum is correct
1 NMEA NmeaDataType: GPGGA,
1 NMEA UTC Time: 092725.00,
1 NMEA NmeaLatitude: 1430.64833,
1 NMEA NmeaLatitudePole: N,
1 NMEA NmeaLongitude: 12101.93500,
1 NMEA NmeaLongitudePole: E,
NMEA Data Type : GPGGA
NMEA UTC Time : 092725.00
NMEA Latitude : 1430.64833
NMEA Latitude Pole : N
NMEA Longitude : 12101.93500
NMEA Longitude Pole: E
NMEA NmeaFixQuality: 1
NMEA NmeaSatelliteTracked: 08
NMEA NmeaHorizontalDilution: 1.01
NMEA NmeaAltitude: 499.6
NMEA NmeaAltitudeUnit: M
NMEA NmeaHeightGeoid: 48.0
NMEA NmeaHeightGeoidUnit: M
NMEA NmeaChecksum: *51
from GpsFormatData -->> latitude: 14.510805, longitude: 121.032250 , altitude: 499.6 ;
Before transforming geographic coordinates inside gps84_To_Gcj02 function
Before transformation : latitude : 14.510805, longitude : 121.032250
after calling gps84_To_Gcj02 --> latitude: 14.510805 , longitude: 121.032250
Inside FormatToLPP after gps84_To_Gcj02 function executed
@FormatToLPP latitude: 14.510805, longitude: 121.032250 , altitudeGps: 499m
GPS Cayenne LPP Data 0: 01
GPS Cayenne LPP Data 1: 88
GPS Cayenne LPP Data 2: 02
GPS Cayenne LPP Data 3: 36
GPS Cayenne LPP Data 4: d4
GPS Cayenne LPP Data 5: 12
GPS Cayenne LPP Data 6: 77
GPS Cayenne LPP Data 7: d2
GPS Cayenne LPP Data 8: 00
GPS Cayenne LPP Data 9: c2
GPS Cayenne LPP Data 10: ec
GPS Cayenne LPP Data : 01880236d41277d200c2ec
Expected: latitude 14.510805, longitude 121.032250
Transformed: latitude 14.510805 longitude 121.032250