MarshallSoft
MarshallSoft GPS Component Reference Manual

MarshallSoft GPS Component

for Windows / CE

Reference Library


(MGC_eREF)


Version 1.2

August 26, 2003


This software is provided as-is.
There are no warranties, expressed or implied.



Copyright (C) 2003
All rights reserved



MarshallSoft Computing, Inc.
Post Office Box 4543
Huntsville AL 35815 USA


Voice : 1.256.881.4630

FAX : 1.256.880.0925

email : info@marshallsoft.com

web : www.marshallsoft.com


MARSHALLSOFT is a registered trademark of MarshallSoft Computing.


TABLE OF CONTENTS

1 Introduction
1.1 General Remarks
1.2 Pocket PC and Handheld PC
1.3 Documentation Set
1.4 Prototype / Declaration Files
1.5 Argument Data Types
2 MGC functions
2.1 mgcAltitude
2.2 mgcAttach
2.3 mgcBearing
2.4 mgcClose
2.5 mgcErrorText
2.6 mgcGetData
2.7 mgcGetInteger
2.8 mgcGetString
2.9 mgcGreatCircle
2.10 mgcLatitude
2.11 mgcLockData
2.12 mgcLongitude
2.13 mgcOpen
2.14 mgcRelease
2.15 mgcSeaLevel
2.16 mgcSetInteger
2.17 mgcSleep
2.18 mgcSysTime
2.19 mgcTimestamp
3 Sentence Field Codes
4 Error Codes
4.1 Serial Port Error Codes
4.2 MGC Error Codes


1 Introduction

The MarshallSoft GPS Component for Win/CE (MGCeVC and MGC4eVB) is a 32-bit dynamic link library (DLL) which reads and decodes standard GPS NMEA 183 sentences from the RS232 serial port as well as computes great circle distances and bearings.

This is the Function Reference Manual for both MGC4eVC (MarshallSoft GPS Component for eVC) and MGC4eVB (MarshallSoft GPS Component for eVB).

Both the eVC (Embedded Visual C/C++) and eVB (Embedded Visual Basic) versions of MGC require Microsoft Embedded Tools, which can be downloaded from the Microsoft Web site.

Refer to the declaration files (see Section 1.3 below) for the exact syntax of each MGC function. Also note that the example programs show exactly how MGC functions are called.

Check http://www.marshallsoft.com for the latest version of our GPS communications software.


1.2 Pocket PC and Handheld PC

Both MGC4eVC and MGC4eVB run on Pocket PC (PPC) and Handheld PC (HPC) machines, and use the same Windows/CE DLL (MGC32.DLL).

MGC4eVC and MGC4eVB includes MGC32.DLL compiled for each CPU unit supported by Microsoft Embedded Tools, namely Strong ARM, MIPS, SH3, (SH4 for HPC), and X86 Emulation.

Although MGC4eVC and MGC4eVB has been tested only on Pocket PC machines, but they will also run on all Windows CE Platforms.


1.3 Documentation Set

The complete set of documentation consists of four manuals in three formats. This is the third manual (WSC_eREF) in the set.

Each manual comes in three formats:


1.4 Prototype / Declaration Files

The exact syntax for calling MGC functions are specific to the host language (eVC and eVB) and are defined for each language in the "MGC prototype/declaration files". Each MGC product comes with the appropriate declaration file for the supported language. For example,

MGC4eVC Embedded Visual C/C++           MGC.H
MGC4eVB Embedded Visual Visual Basic    MGC32.BAS

Most of the MGC functions are used in one or more of the example programs.


1.5 Argument Data Types

Each function argument is marked as:

Note that all pointers are passed as "LPSTR" (long pointer to a string) in eVC, even though some functions are passing pointers to 16-bit Unicode buffers.

When developing your own programs, be sure to pass arguments (particularly strings) in exactly the same way as is done in the example programs.



2 MGC Functions


2.1 mgcAltitude :: Gets the last altitude value.

SYNTAX

mgcAltitude()

REMARKS

The mgcAltitude function returns the last altitude value read provided that GPGGA sentence decoding has been selected. Altitude is returned in units of tenths of meters or tenths of feet. The default is meters.

For example, if 124 is returned and the units are meters, then the altitude is 12.4 meters.

EXAMPLE

C/C++ Example

     // get altitude (in meters) above sea level
     Altitude = (double)mgcAltitude()/10.0;

BASIC Example

' get altitude (in meters) above sea level Altitude = mgcAltitude() / 10.0

RETURNS



2.1 mgcAttach :: Attach MGC component.

SYNTAX

mgcAttach(KeyCode)

KeyCode : (L) Registration key code.

REMARKS

The mgcAttach function establishes communications with the MGC component. The mgcAttach function should be called once during the initialization portion of the application code.

When MGC is registered, you will receive a 'KeyCode' which matches the 'KeyCode' within the registered DLL. For the evaluation version, the keycode is 0. See file KEYCODE found in the APPS directory.

EXAMPLE

C/C++ Example

     unsigned int KeyCode;
     KeyCode = 0;
     // attach MGC component
     Code = mgcAttach(KeyCode);

BASIC Example

Dim KeyCode As Long KeyCode = 0 ' attach MGC component Code = mgcAttach(KeyCode)

RETURNS



2.3 mgcBearing :: Computes the bearing from one point to another.

SYNTAX

mgcBearing (Lat1,Lon1,Lat2,Lon2)

Lat1 : (I) Latitude of first position.

Lon1 : (I) Longitude of first position.

Lat2 : (I) Latitude of second position.

Lon2 : (I) Longitude of second position.

REMARKS

The mgcBearing function returns the bearing from (Lat1, Lon1) to (Lat2, Lon2) in units of hundredths of a degree. For example, if 4512 is returned, then the bearing is 45.12 degrees (true).

Note that 0 degrees is due North, 90 degrees is due East, 180 degrees is due South, and 280 degrees is due West.

EXAMPLE

C/C++ Example

     // Lat1 = (34 deg, 18.512 min), Lon1 = (-86 deg, 51.005 min)
     Lat1 = (60000 * 34) + (1000 * 18) + 512;
     Lon1 = (60000 * 86) + (1000 * 51) + 5;
     Angle = mgcBearing(Lat1, -Lon1, ..., ...) / 100.0;

BASIC Example

' Lat1 = (34 deg, 18.512 min), Lon1 = (-86 deg, 51.005 min)

     Lat1 = (60000 * 34) + (1000 * 18) + 512
     Lon1 = (60000 * 86) + (1000 * 51) + 5
     Angle = mgcBearing(Lat1, -Lon1, ..., ...) / 100.0

RETURNS



2.4 mgcClose :: Closes MGC.

SYNTAX

mgcClose()

REMARKS

The mgcClose function closes the serial port, after which no further processing can occur. mgcClose should be called before exiting your application.

RETURNS


EXAMPLE

C/C++ Example

     mgcClose()

BASIC Example

mgcClose()

ALSO SEE

mgcOpen



2.5 mgcErrorText :: Get text of error message.

SYNTAX

mgcErrorText(ErrCode, Buffer)

ErrCode : (I) Error code.

Buffer : (P) Buffer for error message.

REMARKS

The mgcErrorText function formats the error message for error 'ErrCode' in 'Buffer'.

Call this function when an error (a negative value) is returned from a MGC function so that the error message can be displayed or logged.

RETURNS


EXAMPLE

C/C++ Example

     int ErrCode;
     char ErrBuffer[128];
     mgcErrorText(ErrCode, (char *)ErrBuffer);
     printf("%s\n", ErrBuffer);

BASIC Example

Dim ErrCode As Long Dim ErrBuffer As String * 128 Code = mgcErrorText(ErrCode, ErrBuffer) PRINT ErrBuffer

ALSO SEE

mgcOpen


2.6 mgcGetData ::Gets data sentence field value.

SYNTAX

mgcGetData(DataID, Buffer)

DataID : (I) Field name.

Buffer : (P) Buffer for field text data.

REMARKS

The mgcGetData function returns the value of the field specified by DataID as specified in section 6. Note that only GPGGA and GPRMC sentences have DataID fields defined.

Note that for any sentence, individual fields are numbered beginning with 0. Therefore, to download the data for the third field of the current data record, specify DataID = 2.

The buffer passed must be able to hold at least 12 bytes.

RETURNS

EXAMPLE

C/C++ Example

     char DataBuffer[12];
     RefCount = mgcGetData(GPRMC_DATE,(LPSTR)DataBuffer);

BASIC Example

Dim DataBuffer As String * 12 RefCount = mgcGetData(GPRMC_DATE, DataBuffer)

ALSO SEE

mgcGetString


2.7 mgcGetInteger :: Gets MGC integer parameter.

SYNTAX

mgcGetInteger(ParmName)

ParmName : (I) Parameter name.

REMARKS

The mgcGetInteger function returns an integer parameter, depending on the parameter name passed, as follows:

     [Parameter Name]             [Returns]
     MGC_GET_VERSION               3 part (X.Y.Z) packed version number.
     MGC_GET_BUILD                 Build number
     MGC_GET_VERSION_DIGIT1        First digit of version number.
     MGC_GET_VERSION_DIGIT2        Second digit of version number.
     MGC_GET_VERSION_DIGIT3        Third digit of version number.
     MGC_GET_BYTES_RECEIVED        Total number of bytes received.
     MGC_GET_LINES_RECEIVED        Total number of lines received.
     MGC_GET_READY_BUFFER_COUNT    Number times current data record has been referenced.

RETURNS


EXAMPLE

C/C++ Example

// get MGC build number Build = mgcGetInteger(MGC_GET_BUILD);

BASIC Example

' get MGC build number Build = mgcGetInteger(MGC_GET_BUILD)

ALSO SEE

mgcSetInteger


2.8 mgcGetString :: Gets MGC string parameter.

SYNTAX

mgcGetString(ParmName, Buffer, BufLen)

ParmName : (I) Parameter.

Buffer : (P) Buffer pointer.

BufLen : (I) Length of above buffer.

REMARKS

The mgcGetString function returns the string corresponding to the parameter name specified, a follows:

[Parameter Name]       [String Returned]

MGC_GET_STRING            Gets (current) undecoded NMEA 183 sentence.
MGC_GET_REGISTRATION      Gets the registration string from MGC32.DLL.

Refer to the RAW example program.

RETURNS


EXAMPLE

C/C++ Example

     char DataBuffer[256];
     // get undecoded GPS sentence
     Code = mgcGetString(MGC_GET_STRING, (char *)DataBuffer, 255);

BASIC Example

Dim DataBuffer As String * 255 ' get undecoded GPS sentence Code = mgcGetString(MGC_GET_STRING, DataBuffer, 255)

ALSO SEE

mgcGetData


2.9 mgcGreatCircle :: Computes distance between two points.

SYNTAX

mgcGreatCircle(Lat1,Lon1,Lat2,Lon2)

Lat1 : (I) Latitude of first position.

Lon1 : (I) Longitude of first position.

Lat2 : (I) Latitude of second position.

Lon2 : (I) Longitude of second position.

REMARKS

The mgcGreatCircle function computes the great circle distance between two points of the surface of the earth. The latitude and longitude values are passed in units of thousandths of a minute. For example, pass 1000 for one minute of latitude or longitude.

Refer to Section 5.1, "Coordinates Used in MGC" in the MarshallSoft GPS Component User's Manual for more details.

RETURNS

EXAMPLE

C/C++ Example

     // Lat1 = (34 deg, 18.512 min), Lon1 = (-86 deg, 51.005 min)
     Lat1 = (60000 * 34) + (1000 * 18) + 512;
     Lon1 = (60000 * 86) + (1000 * 51) + 5;
     Distance = mgcGreatCircle(Lat1, -Lon1, ..., ...);

BASIC Example

' Lat1 = (34 deg, 18.512 min), Lon1 = (-86 deg, 51.005 min)

     Lat1 = (60000 * 34) + (1000 * 18) + 512
     Lon1 = (60000 * 86) + (1000 * 51) + 5
     Distance = mgcGreatCircle(Lat1, -Lon1, ..., ...)



2.10 mgcLatitude ::Gets last latitude value.

SYNTAX

mgcLatitude()

REMARKS

The mgcLatitude function returns the last latitude value read provided that GPGGA, GPRMC, or GPGLL sentence decoding has been selected.

Latitude is returned as an integer in units of thousandths of a minute.

RETURNS


EXAMPLE

C/C++ Example

     // get current latitude
     Code = mgcGetLatitude();

BASIC Example

' get current latitude Code = mgcGetLatitude()

ALSO SEE

mgcLongitude


2.11 mgcLockData:: Locks current data record.

SYNTAX

mgcLockData(Flag)

Flag : (I) Lock Flag (TRUE/FALSE).


REMARKS

The mgcLockData function locks (if Flag is not zero) or unlocks (if Flag is 0) the current data record so that field data may be copied.

Normally, the data record should be locked just prior to reading individual fields, then unlocked afterwards.

RETURNS


EXAMPLE

C/C++ Example

     // lock current sentence
     mgcLockData(1);
     // unlock current sentence
     mgcLockData(0);

BASIC Example

' lock current sentence mgcLockData(1) ' unlock current sentence mgcLockData(0)



2.12 mgcLongitude :: Gets current longitude value..

SYNTAX

mgcLongitude()

REMARKS

The mgcLongitude function returns the last longitude value read provided that GPGGA, GPRMC, or GPGLL sentence decoding has been selected.

Longitude is returned as an integer in units of thousandths of a minute.

RETURNS


EXAMPLE

C/C++ Example

     // get current Longitude
     Code = mgcGetLongitude();

BASIC Example

// get current longitude Code = mgcGetLongitude()

ALSO SEE

mgcLatitude


2.13 mgcOpen:: Open MGC serial port.

SYNTAX

mgcOpen(Port)

Port : (I) Port selected.

REMARKS

The mgcOpen function opens the specified serial port at 4800 baud in preparation for receiving MNEA sentences. mgcAttach must be called before mgcOpen.

Be sure to check the return code from mgcOpen().

RETURNS


EXAMPLE

C/C++ Example

     // open COM1 for NMEA sentence input
     Code = mgcOpen(MGC_COM1);

BASIC Example

' open COM1 for NMEA sentence input Code = mgcOpen(MGC_COM1)

ALSO SEE

mgcClose


2.14 mgcRelease:: Release MGC32.DLL.

SYNTAX

mgcRelease()

REMARKS

The mgcRelease function releases MGC32.DLL.

MGC32.DLL is normally released when your executable terminates.

The primary purpose of mgcRelease is to release MGC32.DLL so that mgcAttach can be called again in the same program.

RETURNS


EXAMPLE

C/C++ Example

     // release MGC32.DLL
     Code = mgcRelease();

BASIC Example

' release MGC32.DLL Code = mgcRelease()

ALSO SEE

mgcAttach


2.15 mgcSeaLevel :: Gets last sea level value.

SYNTAX

mgcSeaLevel()

REMARKS

The mgcSeaLevel function returns the last sea level value read provided that GPGGA sentence decoding has been selected.

Sea level altitude is returned in units of tenths of meters or tenths of feet. The default is meters.

RETURNS


EXAMPLE

C/C++ Example

     // get sea level
     SeaLevel = (double)mgcSeaLevel()/10.0;

BASIC Example

'get sea level SeaLevel = mgcSeaLevel()/10.0

ALSO SEE

mgcAltitude


2.16 mgcSetInteger :: Sets MGC integer parameter.

SYNTAX

mgcSetInteger(ParmName, ParmValue)

ParmName : (I) Parameter name

ParmValue : (I) Parameter value

REMARKS

The mgcSetInteger function sets a MGC parameter according to the following table.

[Parameter Name]           [Parameter Value]            [Description]
MGC_SET_SENTENCE_TYPE    Sets the sentence type:
                              MGC_SENTENCE_RAW           All sentences.
                              MGC_SENTENCE_GPRMC         GPRMC sentences.
                              MGC_SENTENCE_GPGGA         GPGGA sentences.
                              MGC_SENTENCE_GPGLL         GPGLL sentences.
                              MGC_SENTENCE_GPGSV         GPGSV sentences.
MGC_SET_ALTITUDE_UNIT    Sets the altitude units:
                              MGC_ALTITUDE_IN_FEET     Feet
                              MGC_ALTITUDE_IN_METERS   Meters
MGC_SET_DISTANCE_UNIT    Sets the distance units
                              MGC_DISTANCE_IN_FEET     Feet
                              MGC_DISTANCE_IN_METERS   Meters
                              MGC_DISTANCE_IN_KM       Kilometers
                              MGC_DISTANCE_IN_SM       Statue miles
                              MGC_DISTANCE_IN_NM       Nautical miles

RETURNS


EXAMPLE


C/C++ Example

     // specify RAW sentences
     Code = mgcSetInteger(MGC_SET_SENTENCE_TYPE, MGC_SENTENCE_RAW);

BASIC Example

' specify RAW sentences Code = mgcSetInteger(MGC_SET_SENTENCE_TYPE, MGC_SENTENCE_RAW)

ALSO SEE

mgcGetInteger


2.17 mgcSleep :: Sleeps specified time.

SYNTAX

mgcSleep(Time)

Time : (I) Time in milliseconds to sleep.

REMARKS

The mgcSleep function sleeps (approximately) for the number of milliseconds specified.

RETURNS

TRUE (1).

EXAMPLE

C/C++ Example

     /* sleep one second */
     mgcSleep(1000);

BASIC Example

' sleep one second N = mgcSleep(1000)



2.18 mgcSysTime :: Gets the system clock time.

SYNTAX

mgcSysTime()

REMARKS

The mgcSysTime function returns the number of milliseconds since bootup. This is the same value as returned by the GetCurrentTime() Win32 API function in Windows.

RETURNS

Number of milliseconds since bootup.

EXAMPLE

C/C++ Example

     /* get system clock time */
     Time = mgcSysTime();

BASIC Example

' get system clock time Time = mgcSysTime ()



2.19 mgcTimestamp :: Gets the last timestamp value.

SYNTAX

mgcTimestamp()

REMARKS

The mgcTimestamp function returns the last timestamp value read provided that GPGGA or GPRMC sentence decoding has been selected.

RETURNS


EXAMPLE

C/C++ Example

     unsigned long N;
     // get system timestamp
     N = mgcTimestamp();

BASIC Example

Dim N As Long ' get system timestamp N = mgcTimestamp()


3 Sentence Field Codes


     [NAME]                [VALUE]

     GPRMC_UTC_TIME         0
     GPRMC_VALIDITY         1
     GPRMC_LATITUDE         2
     GPRMC_NORTH_SOUTH      3
     GPRMC_LONGITUDE        4
     GPRMC_EAST_WEST        5
     GPRMC_SPEED            6
     GPRMC_COURSE           7
     GPRMC_DATE             8
     GPRMC_VARIATION        9
     GPRMC_VAR_EW          10
     GPRMC_CHECKSUM        11

     GPGGA_UTC_TIME         0
     GPGGA_LATITUDE         1
     GPGGA_NORTH_SOUTH      2
     GPGGA_LONGITUDE        3
     GPGGA_EAST_WEST        4
     GPGGA_QUALITY          5
     GPGGA_SATELLITES       6
     GPGGA_HDOP             7
     GPGGA_ALTITUDE         8
     GPGGA_ALT_UNITS        9
     GPGGA_GEOID           10
     GPGGA_AGE             11
     GPGGA_GEO_UNITS       12
     GPGGA_GEO_REF_ID      13
     GPGGA_CHECKSUM        14

     GPGLL_LATITUDE         0
     GPGLL_NORTH_SOUTH      1
     GPGLL_LONGITUDE        2
     GPGLL_EAST_WEST        3
     GPGLL_FIX              4
     GPGLL_VALIDITY         5

     GPGSV_NUMBER_SATS      0
     GPGSV_SENTENCE_NBR     1
     GPGSV_SATS_IN_VIEW     2
     GPGSV_SAT_NUMBER_1     3
     GPGSV_ELEVATION_1      4
     GPGSV_AZIMUTH_1        5
     GPGSV_SIGNAL_1         6
     GPGSV_SAT_NUMBER_2     7
     GPGSV_ELEVATION_2      8
     GPGSV_AZIMUTH_2        9
     GPGSV_SIGNAL_2        10
     GPGSV_SAT_NUMBER_3    11
     GPGSV_ELEVATION_3     12
     GPGSV_AZIMUTH_3       13
     GPGSV_SIGNAL_3        14
     GPGSV_SAT_NUMBER_4    15
     GPGSV_ELEVATION_4     16
     GPGSV_AZIMUTH_4       17
     GPGSV_SIGNAL_4        18


4 Error Codes


4.1 Serial Port Error Codes


     [NAME]             [VALUE]   [FUNCTION]
     WSC_NO_DATA        -100   No data available.
     WSC_RANGE          -101   Parameter not in legal range.
     WSC_ABORTED        -102   Internal checksum error.
     WSC_WIN32ERR       -103   Win32 API error.
     WSC_BUFFERS        -105   Cannot allocate dynamic memory.
     WSC_THREAD         -106   Cannot start Win32 thread.
     WSC_IE_BADID         -1   Bad port ID.
     WSC_IE_OPEN          -2   Port already open.
     WSC_IE_NOPEN         -3   Port not open.
     WSC_IE_MEMORY        -4   Dynamic memory error.
     WSC_IE_DEFAULT       -5   Error in default parameters.
     WSC_IE_HARDWARE     -10   Hardware error.
     WSC_IE_BYTESIZE     -11   Byte size not supported.
     WSC_IE_BAUDRATE     -12   Baud rate not supported.


4.2 MGC Error Codes


     [NAME]                   [VALUE]   [FUNCTION]
     MGC_PORT_ALREADY_OPEN      -501    Port is already open.
     MGC_PORT_NOT_OPEN          -502    Port is not open.
     MGC_CANNOT_START_THREAD    -503    Error starting thread.
     MGC_NO_SUCH_FIELD          -504    No such field.
     MGC_NO_SUCH_PARAMETER      -505    No such parameter.
     MGC_NO_SUCH_SENTENCE       -506    No such sentence type.
     MGC_BAD_DIGIT              -507    Bad digit found.
     MGC_NO_DATA_AVAILABLE      -508    No data is available.
     MGC_NO_SUCH_UNIT           -509    No such unit.
     MGC_NO_DATA                -510    No data stream.

     MGC_ABORTED                -512    Internal MGC32.DLL error.
     MGC_BUFFER_TOO_SMALL       -513    Buffer is too small.
     MGC_CANNOT_ATTACH          -601    Cannot attach MGC32.DLL
     MGC_ALREADY_ATTACHED       -602    Already attached.
     MGC_NOT_ATTACHED           -603    Not attached.