コード例 #1
0
ファイル: SP_ConfigMenu.c プロジェクト: virqin/brew_code
/*======================================================================= 
Function: SamplePosDet_PortSettings_HandleEvent()

Description: 
   Event handler function for the port settings menu.

Prototype:

   boolean SamplePosDet_PortSettings_HandleEvent(CSamplePosDet *pMe, AEEEvent eCode,
                                                 uint16 wParam, uint32 dwParam)

Parameters:
   pMe: [in]. CSamplePosDet instance.
   eCode: [in]. Event code.
   wParam: [in]. Event wParam.
   dwParam: [in]. Event dwParam.

Return Value:

   TRUE - If the event was handled by this menu.
   FALSE - If the event was not handled.
 
Comments:  
   None

Side Effects: 
   None

See Also:
   None
=======================================================================*/
boolean SamplePosDet_PortSettings_HandleEvent(CSamplePosDet *pMe, AEEEvent eCode,
                                                 uint16 wParam, uint32 dwParam)
{
   boolean bHandled = FALSE;
   CTextCtlData *ptcd = SamplePosDet_GetScreenData( pMe );
   ITextCtl *pTextCtl = NULL;
   IMenuCtl *pSoftKeyMenu = NULL;
   char * pszStr;
   AECHAR * pPort;
   uint32 nResult;

   if (ptcd) {
      pSoftKeyMenu = ptcd->pSoftKey;
      pTextCtl = ptcd->pTextCtl;
   }

   switch( eCode ) {
   case EVT_SCREEN:
      if( wParam == SCREEN_PARAM_INIT ) {
         if( pTextCtl ) {  /* This is not expected to happen */
            SamplePosDet_DrawScreen( pMe, 0 );
            bHandled = TRUE;
         }
         else {
            if( ISHELL_CreateInstance( pMe->theApp.m_pIShell, AEECLSID_TEXTCTL, 
               (void **)&pTextCtl ) == SUCCESS ) {
               if (ISHELL_CreateInstance(pMe->theApp.m_pIShell, AEECLSID_SOFTKEYCTL,
                  (void **)&pSoftKeyMenu) == SUCCESS) {

                  IMENUCTL_AddItem( pSoftKeyMenu, SAMPLEPOSDET_RES_FILE, IDS_SOFTKEY_SAVE,
                     IDS_SOFTKEY_SAVE, NULL, (uint32)pSoftKeyMenu );

                  ITEXTCTL_SetSoftKeyMenu( pTextCtl, pSoftKeyMenu );
                  ITEXTCTL_SetTitle( pTextCtl, SAMPLEPOSDET_RES_FILE, IDS_PORT_SETTINGS_TITLE, NULL );
                  ITEXTCTL_SetInputMode( pTextCtl, AEE_TM_NUMBERS );

                  // Load the current port number, if it exists
                  if (AEEGPS_SERVER_IP == pMe->gpsSettings.server.svrType) {
                     pszStr = MALLOC(50);
                     pPort = MALLOC(100);
                     SPRINTF(pszStr, "%d", AEE_ntohs(pMe->gpsSettings.server.svr.ipsvr.port));
                     STRTOWSTR(pszStr, pPort, 100);
                     ITEXTCTL_SetText(pTextCtl, pPort, -1);
                     FREE(pszStr);
                     FREE(pPort);
                  }

                  ptcd = MALLOC( sizeof(CTextCtlData) );

                  ptcd->pSoftKey = pSoftKeyMenu;
                  ptcd->pTextCtl = pTextCtl;
                  SamplePosDet_SetScreenData( pMe, (void *)ptcd );
                  SamplePosDet_DrawScreen( pMe, 0 );
                  bHandled = TRUE;
               }
            }
         }
      }
      else if( wParam == SCREEN_PARAM_CLOSE ) {
         ITEXTCTL_Release( pTextCtl );
         IMENUCTL_Release( pSoftKeyMenu );
         FREE( ptcd );
         SamplePosDet_SetScreenData( pMe, 0 );
         pMe->currentHandler = 0;
         bHandled = TRUE;
      }
      else if( wParam == SCREEN_PARAM_PAINT ) {
         if( ITEXTCTL_IsActive( pTextCtl ) ) {
            ITEXTCTL_Redraw( pTextCtl );
         }
         else {
            ITEXTCTL_SetActive( pTextCtl, TRUE );  /* Also causes a menu draw */
         }
      }
      break;

   case EVT_KEY:
   case EVT_KEY_PRESS:
   case EVT_KEY_RELEASE:
      bHandled = ITEXTCTL_HandleEvent( pTextCtl, eCode, wParam, dwParam );
      if (!bHandled) {
         bHandled = IMENUCTL_HandleEvent( pSoftKeyMenu, eCode, wParam, dwParam );
         
         if(!bHandled && wParam == AVK_CLR && eCode == EVT_KEY) {
            SamplePosDet_GotoScreen( pMe, SCREENID_CONFIG, 0 );
            bHandled = TRUE;
         }
      }
      break;
   case EVT_COMMAND:
      bHandled = ITEXTCTL_HandleEvent( pTextCtl, eCode, wParam, dwParam );
      if (!bHandled) {
         if (IDS_SOFTKEY_SAVE == wParam) {
            // Need to validate and save the Port settings here
            pPort = ITEXTCTL_GetTextPtr(pTextCtl);
            pszStr = MALLOC(50);
            WSTRTOSTR(pPort, pszStr, 50);
            if (0 != (nResult = STRTOUL(pszStr, NULL, 10))) {
               pMe->gpsSettings.server.svr.ipsvr.port = AEE_htons((unsigned short)nResult);
               SamplePosDet_SaveGPSSettings(pMe);
               SamplePosDet_GotoScreen(pMe, SCREENID_CONFIG, 0);
            }
            else {
               ITEXTCTL_SetTitle(pTextCtl, SAMPLEPOSDET_RES_FILE, IDS_PORT_SETTINGS_INVALID, NULL);
               ITEXTCTL_Redraw(pTextCtl);
            }
            FREE(pszStr);
            // add code to save the new PDE IP address
            bHandled = TRUE;
         }
      }
      break;
   }
   return bHandled;
}
コード例 #2
0
ファイル: Location.c プロジェクト: TopSoup/BasicLoc
/*======================================================================= 
Function: Loc_WriteGPSSettings()

Description: 
   Write the GPS configuration settings from the configuration file.

Prototype:

   uint32 Loc_WriteGPSSettings(CLoc *pMe, IFile * pIFile);
=======================================================================*/
static uint32 Loc_WriteGPSSettings( IFile * pIFile , AEEGPSConfig *gpsConfig)
{
   char    *pszBuf;
   int32    nResult;

   if (pIFile == NULL || gpsConfig == NULL)
      return EFAILED;

   pszBuf = MALLOC( 1024 );

   // Truncate the file, in case it already contains data
   IFILE_Truncate( pIFile, 0 );

   // Write out the optimization setting:
   SPRINTF( pszBuf, LOC_CONFIG_OPT_STRING"%d;\r\n", gpsConfig->optim );
   nResult = IFILE_Write( pIFile, pszBuf, STRLEN( pszBuf ) );
   if ( 0 == nResult ) {
      FREE(pszBuf);
      return EFAILED;
   }
   
   // Write out the QoS setting:
   SPRINTF( pszBuf, LOC_CONFIG_QOS_STRING"%d;\r\n", gpsConfig->qos );
   nResult = IFILE_Write( pIFile, pszBuf, STRLEN( pszBuf ) );
   if ( 0 == nResult ) {
      FREE(pszBuf);
      return EFAILED;
   }
   
   // Write out the server type setting:
   SPRINTF( pszBuf, LOC_CONFIG_SVR_TYPE_STRING"%d;\r\n", gpsConfig->server.svrType );
   nResult = IFILE_Write( pIFile, pszBuf, STRLEN( pszBuf ) );
   if ( 0 == nResult ) {
      FREE(pszBuf);
      return EFAILED;
   }
   
   if ( AEEGPS_SERVER_IP == gpsConfig->server.svrType ) {
      // Write out the IP address setting:
      INET_NTOA( gpsConfig->server.svr.ipsvr.addr, pszBuf, 50 );
      nResult = IFILE_Write( pIFile, LOC_CONFIG_SVR_IP_STRING, STRLEN( LOC_CONFIG_SVR_IP_STRING ) );
      if ( 0 == nResult ) {
         FREE(pszBuf);
         return EFAILED;
      }
      nResult = IFILE_Write( pIFile, pszBuf, STRLEN( pszBuf ) );
      if ( 0 == nResult ) {
         FREE(pszBuf);
         return EFAILED;
      }
      nResult = IFILE_Write( pIFile, ";\r\n", STRLEN( ";\r\n" ) );
      if ( 0 == nResult ) {
         FREE(pszBuf);
         return EFAILED;
      }

      // Write out the port setting:
      SPRINTF( pszBuf, LOC_CONFIG_SVR_PORT_STRING"%d;\r\n", AEE_ntohs(gpsConfig->server.svr.ipsvr.port) );
      nResult = IFILE_Write( pIFile, pszBuf, STRLEN( pszBuf ) );
      if ( 0 == nResult ) {
         FREE(pszBuf);
         return EFAILED;
      }
   }

   FREE( pszBuf );

   return SUCCESS;
}
コード例 #3
0
ファイル: SP_ConfigMenu.c プロジェクト: virqin/brew_code
/*======================================================================= 
Function: SamplePosDet_WriteGPSSettings()

Description: 
   Write the GPS configuration settings from the configuration file.

Prototype:

   uint32 SamplePosDet_WriteGPSSettings(CSamplePosDet *pMe, IFile * pIFile);

Parameters:
   pMe: [in]. CSamplePosDet instance.
   pIFile: [in].  Pointer to the IFile instance representing the config
                  file.

Return Value:

  SUCCESS - If the settings were written successfully.
  EFAILED - If an error occured.
 
Comments:  
   None

Side Effects: 
   None

See Also:
   None
=======================================================================*/
uint32 SamplePosDet_WriteGPSSettings( CSamplePosDet *pMe, IFile * pIFile )
{
   char    *pszBuf;
   int32    nResult;

   pszBuf = MALLOC( 1024 );

   // Truncate the file, in case it already contains data
   IFILE_Truncate( pIFile, 0 );

   // Write out the optimization setting:
   SPRINTF( pszBuf, SPD_CONFIG_OPT_STRING"%d;\r\n", pMe->gpsSettings.optim );
   nResult = IFILE_Write( pIFile, pszBuf, STRLEN( pszBuf ) );
   if ( 0 == nResult ) {
      FREE(pszBuf);
      return EFAILED;
   }
   
   // Write out the QoS setting:
   SPRINTF( pszBuf, SPD_CONFIG_QOS_STRING"%d;\r\n", pMe->gpsSettings.qos );
   nResult = IFILE_Write( pIFile, pszBuf, STRLEN( pszBuf ) );
   if ( 0 == nResult ) {
      FREE(pszBuf);
      return EFAILED;
   }
   
   // Write out the server type setting:
   SPRINTF( pszBuf, SPD_CONFIG_SVR_TYPE_STRING"%d;\r\n", pMe->gpsSettings.server.svrType );
   nResult = IFILE_Write( pIFile, pszBuf, STRLEN( pszBuf ) );
   if ( 0 == nResult ) {
      FREE(pszBuf);
      return EFAILED;
   }
   
   if ( AEEGPS_SERVER_IP == pMe->gpsSettings.server.svrType ) {
      // Write out the IP address setting:
      INET_NTOA( pMe->gpsSettings.server.svr.ipsvr.addr, pszBuf, 50 );
      nResult = IFILE_Write( pIFile, SPD_CONFIG_SVR_IP_STRING, STRLEN( SPD_CONFIG_SVR_IP_STRING ) );
      if ( 0 == nResult ) {
         FREE(pszBuf);
         return EFAILED;
      }
      nResult = IFILE_Write( pIFile, pszBuf, STRLEN( pszBuf ) );
      if ( 0 == nResult ) {
         FREE(pszBuf);
         return EFAILED;
      }
      nResult = IFILE_Write( pIFile, ";\r\n", STRLEN( ";\r\n" ) );
      if ( 0 == nResult ) {
         FREE(pszBuf);
         return EFAILED;
      }

      // Write out the port setting:
      SPRINTF( pszBuf, SPD_CONFIG_SVR_PORT_STRING"%d;\r\n", AEE_ntohs(pMe->gpsSettings.server.svr.ipsvr.port) );
      nResult = IFILE_Write( pIFile, pszBuf, STRLEN( pszBuf ) );
      if ( 0 == nResult ) {
         FREE(pszBuf);
         return EFAILED;
      }
   }

   FREE( pszBuf );

   return SUCCESS;
}