The approach that's already been shown for combining the two 16bit values into a single 32bit integer is nearly correct. How you treat the LW value is slightly more subtle than the approach grumpysculler showed. Hopefully this code is clear.
Code:
combineNumbers <- function(HW, LW) {
if(LW < 0)
return(2^16 * HW + (2^16 + LW))
else
return(2^16 * HW + LW)
}
You're then left with a signed 32bit integer.
First we'll look at the time/date example, as that's easier to interperate.
GPS Time HW : 1614
GPS Time LW : -8040
GPS Time (combined) : 105832.600
If you run the code above with those values you get:
Code:
combineNumbers(1614, -8040) = 105832600
The relationship between our 32bit integer and the desired result is obvious. I'm going to make the assumption that the software that interperates this always chops that into 5 characters for the seconds, 2 for the minutes and whatever's left is the hour, i.e it has a predefined understanding of how to interperate the 32bit integer in a particular situation.
We can then apply the similar logic to the coordinate data. I'll take the first example here:
ECU output: GPS Latitude HW : 8015
GPS Latitude LW : -13983
Maths gives : Coordinate 52.8870988 degrees latitude
Combine the two 16bit values into a single signed 32bit number.
Code:
combineNumbers(8015, -13983) = 525322593
People have already noted the degree part seems to be correct, but the bits after the decimal point don't work when dividing by 10^7. So the key to understanding what's going on with the fractional part is to remember that although the result we're looking for is in decimal fractions of degrees, you can also represent the values as degrees, minutes and seconds. Hence we need to work in base 60 (or atleast some multiple of 60), rather than 10.
Like the time of day example, we'll assume that a specific number of digits in our integer represent each of the seconds, minutes and degrees (in our case it's 3, 4 and 2), starting at the "right side" of the integer. If it's negative ignore that for the moment.
Code:
525322593 = 52 | 5322 | 593
We can then combine these as:
Code:
52 + (5322 / 6000) + (593 / 6000000) = 52.88709883
You'd then multiply by -1 if the orginal integer was negative.
Just to check it works we'll do the other example:
ECU output : GPS Longitude HW : -364
GPS Longitude LW : 14387
Maths gives : Coordinate -2.6401195 degrees longitude
Stick those values in the procedure:
Code:
combineNumbers(-364, 14387) = -23840717
2 + (3840 / 6000) + (717 / 6000000) = 2.6401195
Multiply by -1
-2.6401195
Hopefully that makes sense.