News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

radians to degrees

Started by someone, May 24, 2010, 03:35:16 AM

Previous topic - Next topic

clive

; garmasm.asm
; ml -coff -Fl garmasm.asm \masm32\lib\msvcrt.lib -link /SUBSYSTEM:CONSOLE

        .486
        .MODEL FLAT, C
        .DATA

    c_msvcrt typedef PROTO C :VARARG

    externdef _imp__printf:PTR c_msvcrt
    crt_printf equ <_imp__printf>

Rec33   STRUC

GarminRecord            DB      ?
GarminLength            DB      ?

Altitude                REAL4   ?
ErrorPosition           REAL4   ?
ErrorHoriziontal        REAL4   ?
ErrorVertical           REAL4   ?

FixType                 DW      ?

GPSTimeOfWeek           REAL8   ?

Latitude                REAL8   ?
Longitude               REAL8   ?

VelocityLongitude       REAL4   ?
VelocityLatitude        REAL4   ?
VelocityVertical        REAL4   ?
MeanSeaLevelHeight      REAL4   ?

LeapSeconds             DW      ?
GarminDays              DD      ? ; Since GPS Week 521

Rec33   ENDS

Example db      033h,040h,017h,045h,03Fh,043h,0BFh,0EDh,92h,041h,058h,044h,01Bh,041h,0F8h,07Ch
        db      079h,041h,003h,000h,035h,039h,0FFh,0FFh,43h,049h,014h,041h,06Eh,033h,030h,0EAh
        db      03Fh,058h,0E7h,03Fh,072h,0D7h,044h,046h,60h,0A6h,0F8h,0BFh,0E0h,035h,040h,0BCh
        db      0CEh,02Fh,015h,0BCh,0B8h,028h,04Ah,03Bh,30h,0C6h,008h,042h,00Eh,000h,024h,01Ah
        db      000h,000h

rad2deg REAL8   57.2957795130823208767
answer  REAL8   ?
outdbl  db      "%14.10lf",10,13,0

        .CODE

start:
                lea     esi,Example

                fld     Rec33.Latitude[esi]
                fmul    rad2deg
                fstp    answer

                invoke  crt_printf, addr outdbl, answer

                fld     Rec33.Longitude[esi]
                fmul    rad2deg
                fstp    answer

                invoke  crt_printf, addr outdbl, answer

                ret

        END     start


41.7985697322
-88.2709756051


This is decimal degrees, not the DDDMM.mmmm format used by NMEA

The 80-bit version codes like this, but the printf doesn't support it (%Lf)
rad2deg REAL10  57.2957795130823208767
answer  REAL10   ?

                fld     Rec33.Latitude[esi]
                fld     rad2deg
                fmulp   st(1),st(0)
                fstp    answer


Technically that is probably overkill, as the value of PI used by GPS receivers should be 3.1415926535898, as defined in the ICD-200 interface control document. I was thinking more of a general radian/degree conversion when the question was initially posed.

Also 32-bit Microsoft C/C++ has both double and long double as 64-bit. The older DOS versions long double was 80-bit. Some more profession compilers and things like FORTRAN (REAL*10) can support 80-bit. The 80x87 intrinsically supports it.
It could be a random act of randomness. Those happen a lot as well.

someone

ok, the problem here is that i don't have the library msvcrt.lib
what function exactly is crt_printf in the dll, using Dependency Walker i can't find crt_printf or _imp__printf

clive

MSVCRT.DLL (\WINDOWS\SYSTEM32)

Exp Addr Hint   Ord Export Name by msvcrt.dll - Sun Apr 13 11:41:06 2008
-------- ---- ----- ---------------------------------------------------------
0003186A  2E5   742 printf


__imp__printf is a linker mechanism for pulling it in. If you have some other method for printing floats/doubles you could use that.

Download MASM32 if you need the libraries. http://www.masm32.com/masmdl.htm
It could be a random act of randomness. Those happen a lot as well.

vanjast

A thought...
May I suggest you do not waste your time with Garmin and move onto the cheaper GPSs, like TomTom..etc.
Garmin is 2x or 3x the price of the others (where I am at least) so probably has a very limited lifespan.
:lol

clive

The unit in question is an OEM puck antenna implementation, not a dash mount. Plus the poster is pulling raw PVT (Position,Velocity,Time) as a single binary message instead of a couple of $GPxxx NMEA sentences. This is a lot more efficient, and usually provides lat,lon,alt with more precision. Certainly the eTrex I have can push NMEA, or propriety raw data, but I can't say I was impressed with it's accuracy, quality of raw data, or it's MGRS conversion.

I'd probably pick up a $20 USB device which I could program to get 10 Hz raw measurements, and PVT solutions.
It could be a random act of randomness. Those happen a lot as well.

someone

ok, it's working now  :bg

from comparing your code to mine, i can see the difference, i had defined the structure wrong, uint16_fix (FixType) was only declared as one byte when it should have been using two, a stupid mistake
this threw off all values after that in the structure by one byte, which is why the floating point conversions always
shown something in scientific notation with exponent, rather than a clear decimal representation, i thought it was just me
doing the float to string conversion wrongly

i've been using a really old version of masm which didn't include msvcrt or fpulib among other things, now i've installed
the new version i still can't get the crt_printf function working from msvcrt, but that doesn't matter, because now i can
use the FpuFLtoA function from the fpulib which is even better

thank you so much for all your help

raymond

Quotenow i can use the FpuFLtoA function from the fpulib which is even better

If you recently downloaded the fpulib from:
http://www.ray.masmcode.com/fpu.html#fpulib
you are guaranteed to have the very latest version, last modified in January 2010. It does have more flexibility than older versions previously distributed with the MASM32 package or downloadable from other sites.

Otherwise, you may want to get that latest version.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com