Page 213 - PDA Robotics Using Your Personal Digital Assistant to Control Your Robot
P. 213

PDA 09  5/27/03  8:50 AM  Page 189
                                            Chapter 9 / PDA Robot Software for Pocket PC 2002
                                 If you do not specify the purpose of the socket, the constructor con-
                                 structs a data socket by default.
                                 OnWireless: Implementing the CPDASocket Class
                                 The following code is from CPDABotDlg and gets called when the user
                                 clicks the Wireless button. It creates the socket, identifying itself as the
                                 name of the PDA it is running on by calling gethostname() and then
                                 initiates the connection with the command center. If it went well, the
                                 command center will send back the message “SUCCESS.” We then lis-
                                 ten for other commands such as FORWARD, REVERSE, RIGHT, LEFT,
                                 STOP, and RANGE. The PDA sends the corresponding commands to
                                 PDA Robot via the infrared socket.

                                 //
                                 // OnWireless connects to the command center over the wireless network. NOTE: YOU
                                 // MUST connect to the command center before initializing the IrDA. If you initialize the
                                 // IrDA first this button will be disable until the application is restarted. This will be fixed
                                 // in the next version which can be downloaded at www.pda-robotics.com
                                 //

                                 void CPDABotDlg::OnWireless()
                                 {
                                   //
                                   // Listen on the wireless socket for commands from the
                                   // command center and forward them to PDA Robot on the
                                   // Infrared socket.
                                   //

                                   UpdateData(TRUE);
                                   m_hostname.GetWindowText(m_strServer);
                                   m_username.GetWindowText(m_strUsername);
                                   m_password.GetWindowText(m_strPassword);
                                   CheckForAuthentication();

                                   ::SetTimer(this->CWnd::m_hWnd, 1, 1000, NULL);
                                 }

                                 bool CPDABotDlg::CheckForAuthentication()
                                 {
                                   if(!StartApplication())
                                   {
                                      return FALSE;
                                   }

                                   m_bClientConnected=true;

                                                                                               189
   208   209   210   211   212   213   214   215   216   217   218