home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c11 / lab04 / ex01 / gpsnk / gpssocket.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  1.5 KB  |  68 lines

  1. // GpsSocket.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "gpsnk.h"
  6. #include "GpsSocket.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CGpsSocket
  16.  
  17. CGpsSocket::CGpsSocket()
  18. {    m_pDlg= NULL;
  19. }
  20. CGpsSocket::CGpsSocket(CDialog* pDlg)
  21. {
  22.     m_pDlg= pDlg;
  23. }
  24.  
  25. CGpsSocket::~CGpsSocket()
  26. {
  27. }
  28.  
  29.  
  30. // Do not edit the following lines, which are needed by ClassWizard.
  31. #if 0
  32. BEGIN_MESSAGE_MAP(CGpsSocket, CAsyncSocket)
  33.     //{{AFX_MSG_MAP(CGpsSocket)
  34.     //}}AFX_MSG_MAP
  35. END_MESSAGE_MAP()
  36. #endif    // 0
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CGpsSocket member functions
  40.  
  41. void CGpsSocket::OnReceive(int nErrorCode) 
  42. {
  43.     // TODO: Add your specialized code here and/or call the base class
  44.  
  45.     // Get datagram that came from GPS source.
  46.     char buf[512+1];
  47.     int num= Receive(buf, 512);
  48.     buf[num]= '\0';
  49.  
  50.     // Expected format: "DDD1:MM1:SS1 DDD2:MM2:SS2" where
  51.     // DD1:MM1:SS1 is the longitude value and 
  52.     // DD2:MM2:SS2 is the latitude value.
  53.     CString strLon;
  54.     CString strLat;
  55.     char* sep= " ";
  56.     char* p= strtok(buf,sep);
  57.     strLon= p;            // Longitude value
  58.     p= strtok(NULL, sep);
  59.     strLat= p;            // Latitude value
  60.  
  61.     // Now update the edit controls in the dialog.
  62.     CEdit* pEdit;
  63.     pEdit= (CEdit*) m_pDlg->GetDlgItem(IDC_EDIT_LON);
  64.     pEdit->SetWindowText(strLon);
  65.     pEdit= (CEdit*) m_pDlg->GetDlgItem(IDC_EDIT_LAT);
  66.     pEdit->SetWindowText(strLat);
  67. }
  68.