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

PDA 09  5/27/03  8:50 AM  Page 177
                                            Chapter 9 / PDA Robot Software for Pocket PC 2002
                                 Double-clicking on a button will create a function that is called when
                                 it is clicked. Users will be directed into the function where they can
                                 add the code. The name of the function is generated by the IDE. For
                                 example,  the  function  generated  for  the  Wireless  button  is  named
                                 OnWireless.
                                 void CPDABotDlg::OnWireless()
                                 {
                                 // Add Code here
                                 }

                                 Creating the IrDA Link

                                 The following code is used to establish the Infrared Data Association
                                 (IrDA) data link with PDABot’s body. This socket could be equivalent
                                 to the information that flows up and down the spinal column, trans-
                                 ferring information to the brain (PDA), where it makes a decision and
                                 sends a return control command. The PDA initiates a conversion with
                                 the body and asks, “Who are you?” The MCP2150 will identify itself
                                 as “Generic IrDA” until its identifier is reprogrammed to that which
                                 the designer chooses. How to do this is discussed in detail in the chap-
                                 ter about the MCP2150. For the explanation of this code, I will use the
                                 default MCP2150 identifier (“Generic IrDA”). The fact that a device
                                 must identify itself by the IrDA standard allows users to use this secu-
                                 rity feature by means of a keyed handshake or simply by agreeing to
                                 only accept the socket agreed upon association name.

                                 When  users  click  on  the  Connect  button  program  control,  they  are
                                 directed to the function OnConnectIrda() shown in the following code.
                                 It checks to see if a link is already established by referencing the mem-
                                 ber  variable  m_bIrDAConnected,  which  is  set  by  the  return  value  of
                                 InitiateIrDAConnection(). I wrote the function InitiateIrDAConnection()
                                 to do the work of creating the socket and establishing the link with PDA
                                 Robot.

                                 void CPDABotDlg::OnConnectIrda()
                                 {
                                   //
                                   // Create the IrDA association with PDA Robot
                                   //

                                   if( !m_bIrDAConnected)
                                   {
                                      m_bIrDAConnected = InitiateIrDAConnection();

                                                                                               177
   196   197   198   199   200   201   202   203   204   205   206