CHAPTER 32

 < Day Day Up > 



  1. The format of the location data received at the RS232 interface needs to be obtained from the data sheet of the GPS receiver vendor. The code given in Listing C.13 is for the Conexant (http://www.conexant.com) GPS receiver. As you can see from the code, the longitude and latitude positions are obtained as a series of characters. Figure C.11 gives a digitized map.

click to expand
Figure C.11: Digitized map.

Listing C.13: Location data from the GPS receiver.

start example
 /* Receive the data from the GPS modem */ void CGPSDlg::GpsReceiver() {    CString temp;    CPoint point;    int iLat, iLon;    unsigned char ch[1],Lat[12],Lon[13],Alt[11],string[60];    unsigned int i;    CSerial serObj;    if(!serObj.Open(1,9600,'n',8,1))    // Comm port opening using given settings    {       AfxMessageBox("failed to open Comm Port");          return;    }    while(1)    {       if(serObj.ReadData(ch,1) > 0)       {             if((ch[0] == 'g') || (ch[0] == 'G'))             {                   serObj.ReadData(ch,1);                   if((ch[0] == 'p') || (ch[0] == 'P'))                   {                         serObj.ReadData(ch,1);                         if((ch[0] == 'g') || (ch[0] == 'G'))                         {                               serObj.ReadData(ch,1);                   if((ch[0] == 'g') || (ch[0] == 'G'))                         {                   serObj.ReadData(ch,1);                   if((ch[0] == 'a') || (ch[0] == 'A'))                               {                         serObj.ReadData(ch,1); // ','                               if(ch[0] != ',')                               continue;                   serObj.ReadData(ch,1); //first char of time of ','                                      if(ch[0] == ',')                                            continue; serObj.ReadData(string,55);                            //remaining char of time                                              string[55] = '\0';                            // Assigning Latitude value                                              Lat[0] = string[6];                                              Lat[1] = string[7];                                              Lat[2] = string[8];                            Lat[3] = string[9];                            Lat[4] = string[10];                            Lat[5] = string[11];                            Lat[6] = string[12];                            Lat[7] = string[13];                            Lat[8] = string[14];                            Lat[9] = ' ';                            Lat[10] = string[16];                                  Lat[11] = '\0';                      // Assigning Longitude value                                  Lon[0] = string[18];                                  Lon[1] = string[19];                                  Lon[2] = string[20];                                  Lon[3] = string[21];                                  Lon[4] = string[22];                                  Lon[5] = string[23];                                  Lon[6] = string[24];                                  Lon[7] = string[25];                                  Lon[8] = string[26];                                  Lon[9] = string[27];                                        Lon[10] = ' ';                                  Lon[11] = string[29];                                        Lon[12] = '\0';                // Assigning Altitude value                                  for(i=0;i<10;i++)                                        {                                  Alt[i] = string[41+i];                                  if(string[41+i] == 'M')                                        { Alt[41+i-1] = ' ';                                        Alt[41+i+1] = '\0';                                        break;                                        }                                        }                            temp.Format("Lat : %s",Lat); m_lat.SetWindowText(temp);                            temp.Format("Lon : %s",Lon); m_lon.SetWindowText(temp);                            temp.Format("Alt : %s",Alt); m_alt.SetWindowText(temp);                                             Lat[4] = '\0';                                             Lon[5] = '\0';                                      temp.Format("%s",Lat);                                             iLat = atoi(temp); temp.Format("%s",Lon);                                             iLon = atoi(temp);                                             point.x = iLon;                                             point.y = iLat;    // Plot the location on the map m_location.SetWindowPos(NULL, point.x, point.y, 0, 0, SWP_NOSIZE);                                                continue;                                        }                                  }                            }                      }                }          }    } } 
end example

  1. To develop a navigation system, you need to calculate the distance between two points when the longitude and latitude of the two points are known.

    • At point P1, longitude = x1 and latitude = y1

    • At point P2, longitude = x2 and latitude = y2

    • Distance between P1 and P2 =*Ö((x2 x1) 2 + (y2 y1) 2)

    • Note that 1° = 60 minutes, 1° = 3600 seconds (1 minute = 60 seconds) and 1° corresponds to 108 KM (1 second corresponds to 30 Meters)

    • The listing of the program to calculate the distance given the longitude and latitude of two points is given in Listing C.14.

Listing C.14: Calculation of distance between two points given their latitude and longitude.

start example
 #include "stdafx.h" #include <cmath> int main(int argc, char* argv[]) {    float p1Longitude, p1Latitude, p2Longitude, p2Latitude;    double res1, res2, fres;    printf("\n \n Distance between two points when Longitude       and Latitude are known \t\n\n");    printf("Longitude of I point: ");    scanf("%f",&p1Longitude);    printf("Latitude of I point: ");    scanf("%f",&p1Latitude);    printf("\nLongitude of II point: ");    scanf("%f",&p2Longitude);    printf("Latitude of II point: ");    scanf("%f",&p2Latitude);    res1 = pow((double)(p2Longitude - p1Longitude),2.0);    res2 = pow((double)(p2Latitude - p1Latitude),2.0);    fres = pow((double)(res1 + res2),0.5) * 108;    //(Since 1 degree = 108 KM)    printf("\nDistance between two points: %lf KM \n",fres);    return 0; } 
end example

The output screen is shown in Figure C.12.

click to expand
Figure C.12: Screenshot showing the output of the program to calculate distance.

  1. Information about the GIS software can be obtained from the following sites: http://www.mapinfo.com, http://www.freegis.org, and http://www.opensourcegis.org.

  2. In differential GPS, the mobile devices will have a GPS receiver and an FM receiver using which the location parameters can be found very accurately. If the mobile device is also fitted with another FM transmitter that continuously transmits its GPS data to a centralized location, then the mobile device can be continuously tracked. Without the owner's knowledge, such a gadget can be fixed to a car and the car movement can be continuously tracked. Such applications are required for organizations involved in public safety. But certainly, this is invading the privacy of individuals.



 < Day Day Up > 



Principles of Digital Communication Systems and Computer Networks
Principles Digital Communication System & Computer Networks (Charles River Media Computer Engineering)
ISBN: 1584503297
EAN: 2147483647
Year: 2003
Pages: 313
Authors: K V Prasad

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net