//Variables CTextFile
int Code;
int LinesRX;
char Temp[256];
int decimal, precision = 12, sign;
//CString sDataBuffer(DataBuffer);
//LPCTSTR lpszDataBuffer = sDataBuffer;
CString str, Lat, Long, Alt, Azi, Dist;
CStringArray sensorval;
double Latgcs, Longcs, Altgcs, Compgcs;
double Distance, Azimuth, Angle;
double Latitude, Longitude, Altitude;
CTextFile Sensor;
BOOL res;
str=_T("E:\\sensorfile.txt");
Code = mgcAttach(MGC_KEY_CODE); // attach MGC component
if (mgcOpen(MGC_COM2)== 0)
SetDlgItemText(IDC_GPSPORT, (LPCTSTR) L"OK");
else
SetDlgItemText(IDC_GPSPORT, (LPCTSTR) L"Port Error");
res = Sensor.ReadTextFile(str, sensorval);
Latgcs = wcstod(sensorval[0], NULL);
SetDlgItemText(IDC_LATITUDE, sensorval[0]);
Longcs = wcstod(sensorval[1], NULL);
SetDlgItemText(IDC_LONGITUDE, sensorval[1]);
Altgcs = wcstod(sensorval[2], NULL);
SetDlgItemText(IDC_ALTITUDE, sensorval[2]);
Compgcs = wcstod(sensorval[3], NULL);
SetDlgItemText(IDC_NORTH, sensorval[3]);
while (1)
{
Code = mgcSetInteger(MGC_SET_SENTENCE_TYPE, MGC_SENTENCE_GPGGA);
mgcLockData(1);
Latitude = mgcLatitude();
Lat = _ecvt( Latitude, precision, &decimal, &sign );
SetDlgItemText(IDC_ACLAT, Lat);
Code = mgcGetData(GPGGA_LONGITUDE,(LPSTR)DataBuffer);
Longitude = atof (DataBuffer);
Long = _ecvt( Longitude, precision, &decimal, &sign );
SetDlgItemText(IDC_ACLONG, Long);
Code = mgcGetData(GPGGA_ALTITUDE,(LPSTR)DataBuffer);
Altitude = atof(DataBuffer);
Alt = _ecvt( Altitude, precision, &decimal, &sign );
SetDlgItemText(IDC_ACALT, Alt);
Distance = mgcGreatCircle(IDC_LATITUDE, IDC_LONGITUDE, IDC_ACLAT, IDC_ACLONG);
Dist = _ecvt( Distance, precision, &decimal, &sign );
SetDlgItemText(IDC_ACDIST, Dist);
Angle = mgcBearing (IDC_LATITUDE, IDC_LONGITUDE, IDC_ACLAT, IDC_ACLONG);
Azimuth = Angle / 60000.0;
Azi = _ecvt( Azimuth, precision, &decimal, &sign );
SetDlgItemText(IDC_ACBEAR, Azi);
mgcLockData(0);
}
return TRUE; // return TRUE unless you set the focus to a control
}