Example #1
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Show declaration progress dialog.
///
/// @param dlgType  message type to be shown
///
//static
void DevBase::ShowProgress(DeclDlg dlgType)
{
  const TCHAR* msgId;

  switch (dlgType)
  {
    case decl_enable:
      // LKTOKEN  _@M1401_ = "Enabling declaration mode"
      msgId = _T("_@M1401_"); break;

    case decl_disable:
      // LKTOKEN  _@M1402_ = "Disabling declaration mode"
      msgId = _T("_@M1402_"); break;

    case decl_send:
      // LKTOKEN  _@M1403_ = "Sending declaration"
      msgId = _T("_@M1403_"); break;

    default:
      #if BUGSTOP
      LKASSERT(0);
      #endif
      msgId = _T("_@M1402_"); break;
      return;
  }

  TCHAR buffer[max_dlg_msg_sz];

  _sntprintf(buffer, max_dlg_msg_sz, _T("%s..."), gettext(msgId));

  CreateProgressDialog(buffer);

} // ShowProgress()
Example #2
0
/**
 * Create special startup message for some devices
 */
void XCSoarInterface::StartupInfo() {
  // TODO speed: TB: this slows down the bootup process because of sleep()
#ifdef CREDITS_FIVV
  CreateProgressDialog(gettext(TEXT("Special ITA version")));
  Sleep(1000);
#endif
#ifdef PNA // VENTA-ADDON
  TCHAR sTmp[MAX_PATH];
  _stprintf(sTmp, TEXT("PNA MODEL=%s (%d)"), GlobalModelName, GlobalModelType);
  CreateProgressDialog(sTmp); Sleep(3000);
#endif // non PNA

  if (is_simulator()) {
    CreateProgressDialog(TEXT("SIMULATION"));
    Sleep(2000);
  }

#ifdef PNA
  if ( SetBacklight() == true )
    CreateProgressDialog(TEXT("AUTOMATIC BACKLIGHT CONTROL"));
  else
    CreateProgressDialog(TEXT("NO BACKLIGHT CONTROL"));
  Sleep(3000);

  // this should work ok for all pdas as well
  if ( SetSoundVolume() == true )
    CreateProgressDialog(TEXT("AUTOMATIC SOUND LEVEL CONTROL"));
  else
    CreateProgressDialog(TEXT("NO SOUND LEVEL CONTROL"));
  Sleep(3000);
#endif
}
Example #3
0
void RasterTerrain::ServiceFullReload(double lat, double lon) {

  Lock();
  if (TerrainMap) {
    CreateProgressDialog(gettext(TEXT("_@M901_"))); // Loading terrain tiles...
    #if TESTBENCH
    StartupStore(_T(". Loading terrain tiles...%s"),NEWLINE);
    #endif
    TerrainMap->ServiceFullReload(lat, lon);
  }
  Unlock();
}
Example #4
0
void ReadAirfieldFile() {
  #if TESTBENCH
  StartupStore(TEXT(". ReadAirfieldFile%s"),NEWLINE);
  #endif

	// LKTOKEN  _@M400_ = "Loading Waypoint Notes File..."
  CreateProgressDialog(MsgToken(400));

  {
    OpenAirfieldDetails();
    ParseAirfieldDetails();
    CloseAirfieldDetails();
  }

}
Example #5
0
BOOL devDeclare(PDeviceDescriptor_t d, Declaration_t *decl, unsigned errBufferLen, TCHAR errBuffer[])
{
  BOOL result = FALSE;

  if (SIMMODE)
    return TRUE;
  
  const unsigned BUFF_LEN = 128;
  TCHAR buffer[BUFF_LEN];

  // We must be sure we are not going to attempt task declaration
  // while a port reset is already in progress. If this happens, a Flarm device will not be Flarm anymore
  // until a Flarm nmea sentence is parsed again once. 
  
  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M571_ = "START"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), gettext(_T("_@M1400_")), gettext(_T("_@M571_")));
  CreateProgressDialog(buffer);

  /***********************************************************/
  devDirectLink(d,true);
  /***********************************************************/
  LockComm();

  if ((d != NULL) && (d->Declare != NULL))
	result = d->Declare(d, decl, errBufferLen, errBuffer);
  else {
	if ((d != NULL) && NMEAParser::PortIsFlarm(d->Port)) {
		result |= FlarmDeclare(d, decl, errBufferLen, errBuffer);
	}
  }


  UnlockComm();
  /***********************************************************/
  devDirectLink(d,false);
  /***********************************************************/
  CloseProgressDialog();
  
  return result;
}
Example #6
0
void RasterTerrain::OpenTerrain(void)
{
  #if TESTBENCH
  StartupStore(TEXT(". Loading Terrain... %s"),NEWLINE);
  #endif
  CreateProgressDialog(MsgToken(900)); // Loading Terrain File...

  TCHAR szFile[MAX_PATH] = _T("\0");
  _tcscpy(szFile,szTerrainFile);
  ExpandLocalPath(szFile);

  if ( (_tcslen(szFile)>0) && ( _tcsstr(szFile, _T(".DEM")) || _tcsstr(szFile, _T(".dem")) ) ) {
	if (!CreateTerrainMap(szFile)) {
      // If no terrain will be found, the registry will be invalid on next run
      _tcscpy(szTerrainFile,_T(""));
      StartupStore(_T("... INVALID TERRAIN file <%s>%s"),szFile,NEWLINE);
	}
  } else {
    StartupStore(_T(". NO TERRAIN file available.%s"),NEWLINE);
  }
}
Example #7
0
void XCSoarInterface::PreloadInitialisation(bool ask) {
  if (ask) {
#ifdef PNA
    CleanRegistry(); // VENTA2-FIX for PNA we can't delete all registries..by now
#endif
  }

  SetToRegistry(TEXT("XCV"), 1);

#ifdef DEBUG_TRANSLATIONS
  ReadLanguageFile();
#endif

  // Registry (early)

  if (ask) {
    Profile::RestoreRegistry();
    Profile::ReadRegistrySettings();

    // CreateProgressDialog(gettext(TEXT("Initialising")));

  } else {
    dlgStartupShowModal();
    Profile::RestoreRegistry();
    Profile::ReadRegistrySettings();

    CreateProgressDialog(gettext(TEXT("Initialising")));
  }

  // Interface (before interface)
  if (!ask) {
#ifndef DEBUG_TRANSLATIONS
    ReadLanguageFile();
#endif
    status_messages.LoadFile();
    InputEvents::readFile();
  }

}
Example #8
0
BOOL
DoResume(PMAIN_WND_INFO Info)
{
    HWND hProgress;
    BOOL bRet = FALSE;

    /* Create a progress window to track the progress of the resuming service */
    hProgress = CreateProgressDialog(Info->hMainWnd,
                                     IDS_PROGRESS_INFO_RESUME);
    if (hProgress)
    {
        /* Set the service name and reset the progress bag */
        InitializeProgressDialog(hProgress, Info->pCurrentService->lpServiceName);

        /* Resume the requested service */
        bRet = DoControl(Info, hProgress, SERVICE_CONTROL_CONTINUE);

        /* Complete and destroy the progress bar */
        DestroyProgressDialog(hProgress, bRet);
    }

    return bRet;
}
Example #9
0
BOOL
DoStart(PMAIN_WND_INFO Info, LPWSTR lpStartParams)
{
    HWND hProgress;
    BOOL bRet = FALSE;

    /* Create a progress window to track the progress of the stopping service */
    hProgress = CreateProgressDialog(Info->hMainWnd,
                                     IDS_PROGRESS_INFO_START);
    if (hProgress)
    {
        /* Set the service name and reset the progress bag */
        InitializeProgressDialog(hProgress, Info->pCurrentService->lpServiceName);

        /* Start the requested service */
        bRet = DoStartService(Info, hProgress, lpStartParams);

        /* Complete and destroy the progress bar */
        DestroyProgressDialog(hProgress, bRet);
    }

    return bRet;
}
Example #10
0
void Shutdown(void) {
  int i;

  // LKTOKEN _@M1219_ "Shutdown, please wait..."
  CreateProgressDialog(gettext(TEXT("_@M1219_")));

  LKSound(_T("LK_DISCONNECT.WAV")); Poco::Thread::sleep(500); // real WAV length is 410+ms
  if (!GlobalRunning) { // shutdown on startup (before sim/fly or clicking on the window X)
	StartupStore(_T(". Quick shutdown requested before terminating startup%s"),NEWLINE);
	// force exit mode for the case of being in welcome screen: OnTimerNotify will catch it
	RUN_MODE=RUN_SHUTDOWN;
	CloseCalculations();
	CloseGeoid();
	DeInitCustomHardware();
	LKRunStartEnd(false);
	return;
  }

  StartupStore(_T(". Entering shutdown %s%s"), WhatTimeIsIt(),NEWLINE);
  MapWindow::Event_Pan(0);  // return from PAN restores the Task in case of Turnpoint moving
  #if TESTBENCH
  StartupLogFreeRamAndStorage();
  #endif

  // turn off all displays
  GlobalRunning = false;

  // LKTOKEN _@M1220_ "Shutdown, saving logs..."
  CreateProgressDialog(gettext(TEXT("_@M1220_")));

  // In case we quit while are still flying
  UpdateLogBook(false); // false=only log if still flying
  // stop logger
  guiStopLogger(true);

  // LKTOKEN _@M1221_ "Shutdown, saving profile..."
  CreateProgressDialog(gettext(TEXT("_@M1221_")));
  extern void LKAircraftSave(const TCHAR *szFile);
  extern void LKPilotSave(const TCHAR *szFile);
  extern void LKDeviceSave(const TCHAR *szFile);
  LKPilotSave(defaultPilotFile);
  LKAircraftSave(defaultAircraftFile);
  LKProfileSave(defaultProfileFile);
  LKDeviceSave(defaultDeviceFile);

  #if TESTBENCH
  StartupStore(TEXT(". Save_Recent_WP_history%s"),NEWLINE);
  #endif
  SaveRecentList();
  // Stop sound

  // Stop drawing
  // LKTOKEN _@M1219_ "Shutdown, please wait..."
  CreateProgressDialog(gettext(TEXT("_@M1219_")));
 
  // 100526 this is creating problem in SIM mode when quit is called from X button, and we are in waypoint details
  // or probably in other menu related screens. However it cannot happen from real PNA or PDA because we don't have
  // that X button.
  MapWindow::CloseDrawingThread();

  // Stop calculating too (wake up)
  dataTriggerEvent.set();
  drawTriggerEvent.set();

  // Clear data
  // LKTOKEN _@M1222_ "Shutdown, saving task..."
  CreateProgressDialog(gettext(TEXT("_@M1222_")));

  #if TESTBENCH
  StartupStore(TEXT(".... Save default task%s"),NEWLINE);
  #endif

  SaveDefaultTask();

  #if TESTBENCH
  StartupStore(TEXT(".... Clear task data%s"),NEWLINE);
  #endif

  LockTaskData();
  Task[0].Index = -1;  ActiveWayPoint = -1; 
  AATEnabled = FALSE;
  CloseWayPoints();
  UnlockTaskData();

  // LKTOKEN _@M1219_ "Shutdown, please wait..."
  CreateProgressDialog(gettext(TEXT("_@M1219_")));
  #if TESTBENCH
  StartupStore(TEXT(".... CloseTerrainTopology%s"),NEWLINE);
  #endif

  RasterTerrain::CloseTerrain();

  CloseTopology();
  #if USETOPOMARKS
  TopologyCloseMarks();
  #endif
  CloseTerrainRenderer();

  LiveTrackerShutdown();

#ifndef NO_DATARECORDER
  CloseFlightDataRecorder();
#endif  
  // Stop COM devices
  StartupStore(TEXT(". Stop COM devices%s"),NEWLINE);
  devCloseAll();

  CloseFLARMDetails();

  ProgramStarted = psInitInProgress;

  // Kill windows
  #if TESTBENCH
  StartupStore(TEXT(".... Close Messages%s"),NEWLINE);
  #endif
  Message::Destroy();
  #if TESTBENCH 
  StartupStore(TEXT(".... Destroy Button Labels%s"),NEWLINE);
  #endif
  ButtonLabel::Destroy();

  #if TESTBENCH
  StartupStore(TEXT(".... Delete Objects%s"),NEWLINE);
  #endif
  
  // Kill graphics objects

  #ifdef LXMINIMAP
  hBrushButtonHasFocus.Release();
  #endif

  CAirspaceManager::Instance().CloseAirspaces();
  #if TESTBENCH
  StartupStore(TEXT(".... Delete Critical Sections%s"),NEWLINE);
  #endif

  // Wait end of Calculation thread before deinit critical section.
  WaitThreadCalculation();

  #if TESTBENCH
  StartupStore(TEXT(".... Close Progress Dialog%s"),NEWLINE);
  #endif
  CloseProgressDialog();
  #if TESTBENCH
  StartupStore(TEXT(".... Close Calculations%s"),NEWLINE);
  #endif
  CloseCalculations();

  CloseGeoid();
  DeInitCustomHardware();

  #if TESTBENCH
  StartupStore(TEXT(".... Close Windows%s"),NEWLINE);
  #endif

  #if TESTBENCH
  StartupLogFreeRamAndStorage();
  #endif
  for (i=0;i<NUMDEV;i++) {
	if (ComPortStatus[i]!=0) {
		StartupStore(_T(". ComPort %d: status=%d Rx=%ld Tx=%ld ErrRx=%ld + ErrTx=%ld (==%ld)%s"), i,
		ComPortStatus[i], ComPortRx[i],ComPortTx[i], ComPortErrRx[i],ComPortErrTx[i],ComPortErrors[i],NEWLINE);
	}
  }
  StartupStore(_T(". Finished shutdown %s%s"), WhatTimeIsIt(),NEWLINE);
  LKRunStartEnd(false);

#ifdef DEBUG
  TCHAR foop[80];
  TASK_POINT wp;
  TASK_POINT *wpr = &wp;
  _stprintf(foop,TEXT(". Sizes %d %d %d%s"),
	    sizeof(TASK_POINT), 
	    ((long)&wpr->AATTargetLocked)-((long)wpr),
	    ((long)&wpr->Target)-((long)wpr), NEWLINE
	    );
  StartupStore(foop);
#endif
  StartupStore(_T("Destroy MainWindow" NEWLINE));
  MainWindow.Destroy();
}
Example #11
0
void XCSoarInterface::Shutdown(void) {
  CreateProgressDialog(gettext(TEXT("Shutdown, please wait...")));
  StartHourglassCursor();

  StartupStore(TEXT("Entering shutdown...\n"));
  StartupLogFreeRamAndStorage();

  // turn off all displays
  globalRunningEvent.reset();

  StartupStore(TEXT("dlgAirspaceWarningDeInit\n"));
  dlgAirspaceWarningDeInit();

  CreateProgressDialog(gettext(TEXT("Shutdown, saving logs...")));
  // stop logger
  logger.guiStopLogger(Basic(),true);

  CreateProgressDialog(gettext(TEXT("Shutdown, saving profile...")));
  // Save settings
  Profile::StoreRegistry();

  // Stop sound

  StartupStore(TEXT("SaveSoundSettings\n"));
  Profile::SaveSoundSettings();

#ifndef DISABLEAUDIOVARIO
  //  VarioSound_EnableSound(false);
  //  VarioSound_Close();
#endif

  // Stop drawing
  CreateProgressDialog(gettext(TEXT("Shutdown, please wait...")));

  StartupStore(TEXT("CloseDrawingThread\n"));
  closeTriggerEvent.trigger();

  calculation_thread->join();
  StartupStore(TEXT("- calculation thread returned\n"));

  instrument_thread->join();
  StartupStore(TEXT("- instrument thread returned\n"));

  draw_thread->join();
  StartupStore(TEXT("- draw thread returned\n"));

  delete draw_thread;

  // Clear data

  CreateProgressDialog(gettext(TEXT("Shutdown, saving task...")));
  StartupStore(TEXT("Resume abort task\n"));
  task.ResumeAbortTask(SettingsComputer(), -1); // turn off abort if it was on.
  StartupStore(TEXT("Save default task\n"));
  task.SaveDefaultTask();
  StartupStore(TEXT("Clear task data\n"));
  task.ClearTask();
  StartupStore(TEXT("Close airspace\n"));
  CloseAirspace();

  StartupStore(TEXT("Close waypoints\n"));
  way_points.clear();

  CreateProgressDialog(gettext(TEXT("Shutdown, please wait...")));

  StartupStore(TEXT("CloseTerrainTopology\n"));

  RASP.Close();
  terrain.CloseTerrain();

  delete topology;
  delete marks;

  devShutdown();

  SaveCalculationsPersist(Basic(),Calculated());
#if (EXPERIMENTAL > 0)
  //  CalibrationSave();
#endif

  #if defined(GNAV) && !defined(PCGNAV)
    StartupStore(TEXT("Altair shutdown\n"));
    Sleep(2500);
    StopHourglassCursor();
    InputEvents::eventDLLExecute(TEXT("altairplatform.dll SetShutdown 1"));
    while(1) {
      Sleep(100); // free time up for processor to perform shutdown
    }
  #endif

  CloseFLARMDetails();

  // Kill windows

  StartupStore(TEXT("Destroy Info Boxes\n"));
  InfoBoxManager::Destroy();

  StartupStore(TEXT("Destroy Button Labels\n"));
  ButtonLabel::Destroy();

  StartupStore(TEXT("Delete Objects\n"));

  // Kill graphics objects

  DeleteFonts();

  DeleteAirspace();

  StartupStore(TEXT("Close Progress Dialog\n"));

  CloseProgressDialog();

  CloseGeoid();

  StartupStore(TEXT("Close Windows - main \n"));
  main_window.reset();
  StartupStore(TEXT("Close Graphics\n"));
  MapGfx.Destroy();

#ifdef DEBUG_TRANSLATIONS
  StartupStore(TEXT("Writing missing translations\n"));
  WriteMissingTranslations();
#endif

  StartupLogFreeRamAndStorage();
  StartupStore(TEXT("Finished shutdown\n"));
  StopHourglassCursor();

}
Example #12
0
/**
 * "Boots" up XCSoar
 * @param hInstance Instance handle
 * @param lpCmdLine Command line string
 * @return True if bootup successful, False otherwise
 */
bool XCSoarInterface::Startup(HINSTANCE hInstance, LPTSTR lpCmdLine)
{
  // The title bar text
  TCHAR szTitle[MAX_LOADSTRING];

  // Store instance handle in our global variable
  hInst = hInstance;

  // IDS_APP_TITLE = XCSoar (see XCSoar.rc)
  LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);

  //If it is already running, then focus on the window
  if (MainWindow::find(szTitle))
    return false;

  // Send the SettingsMap to the DeviceBlackboard
  SendSettingsMap();

  // Register window classes
  PaintWindow::register_class(hInst);
  MainWindow::register_class(hInst);
  MapWindow::register_class(hInst);

  // Fill the fast(co)sine table
  InitSineTable();

  PreloadInitialisation(true);

  // Send the SettingsMap to the DeviceBlackboard
  SendSettingsMap();

  // Creates the main window
  StartupStore(TEXT("Create main window\n"));
  RECT WindowSize = SystemWindowSize();
  main_window.set(szTitle,
		  WindowSize.left, WindowSize.top,
		  WindowSize.right, WindowSize.bottom);

  if (!main_window.defined()) {
    return false;
  }
  main_window.install_timer();

  // Initialize DeviceBlackboard
  device_blackboard.Initialise();

  // Initialize Marks
  marks = new Marks("xcsoar-marks");
  topology = new TopologyStore(marks->GetTopology());

  // Show the main and map windows
  StartupStore(TEXT("Create map window\n"));
  main_window.show();
  main_window.map.show();

#ifdef HAVE_ACTIVATE_INFO
  SHSetAppKeyWndAssoc(VK_APP1, main_window);
  SHSetAppKeyWndAssoc(VK_APP2, main_window);
  SHSetAppKeyWndAssoc(VK_APP3, main_window);
  SHSetAppKeyWndAssoc(VK_APP4, main_window);
  // Typical Record Button
  //	Why you can't always get this to work
  //	http://forums.devbuzz.com/m_1185/mpage_1/key_/tm.htm
  //	To do with the fact it is a global hotkey, but you can with code above
  //	Also APPA is record key on some systems
  SHSetAppKeyWndAssoc(VK_APP5, main_window);
  SHSetAppKeyWndAssoc(VK_APP6, main_window);
#endif

  // Initialize main blackboard data
  task.ClearTask();
  glide_computer.Initialise();
  logger.LinkGRecordDLL(); // try to link DLL if it exists

  // Load the EGM96 geoid data
  OpenGeoid();

  PreloadInitialisation(false);

  Profile::LoadWindFromRegistry();

  // TODO TB: seems to be out of date?!
  CalculateNewPolarCoef();

  // Calculate polar-related data and saves it to the cache
  StartupStore(TEXT("GlidePolar::UpdatePolar\n"));
  GlidePolar::UpdatePolar(false, SettingsComputer());

  // Show startup info depending on device
  StartupInfo();

  // Read the topology file(s)
  topology->Open();

  // Read the terrain file
  terrain.OpenTerrain();

  // Read the waypoint files
  ReadWayPoints(way_points, terrain);

  // Read and parse the airfield info file
  ReadAirfieldFile();

  // Set the home waypoint
  SetHome(way_points, terrain, SetSettingsComputer(), false, true);

  // ReSynchronise the blackboards here since SetHome touches them
  ReadBlackboardBasic(device_blackboard.Basic());

  terrain.ServiceFullReload(Basic().Location);

  // Scan for weather forecast
  CreateProgressDialog(gettext(TEXT("Scanning weather forecast")));
  StartupStore(TEXT("RASP load\n"));
  RASP.ScanAll(Basic().Location);

  // Reads the airspace files
  ReadAirspace();
  // Sorts the airspaces by priority
  SortAirspace();

  // Read the FLARM details file
  OpenFLARMDetails();

#ifndef DISABLEAUDIOVARIO
  /*
  VarioSound_Init();
  VarioSound_EnableSound(EnableSoundVario);
  VarioSound_SetVdead(SoundDeadband);
  VarioSound_SetV(0);
  VarioSound_SetSoundVolume(SoundVolume);
  */
#endif

  // Start the device thread(s)
  CreateProgressDialog(gettext(TEXT("Starting devices")));
  devStartup(lpCmdLine);

  // Reset polar in case devices need the data
  StartupStore(TEXT("GlidePolar::UpdatePolar\n"));
  GlidePolar::UpdatePolar(true, SettingsComputer());

  CreateProgressDialog(gettext(TEXT("Initialising display")));

  // Finally ready to go.. all structures must be present before this.

  // Create the drawing thread
  StartupStore(TEXT("CreateDrawingThread\n"));
  draw_thread = new DrawThread(main_window.map, main_window.flarm);
  draw_thread->start();

  // Show the infoboxes
  StartupStore(TEXT("ShowInfoBoxes\n"));
  InfoBoxManager::Show();

  // Create the calculation thread
  StartupStore(TEXT("CreateCalculationThread\n"));
  CreateCalculationThread();

#ifdef NEWTASK  
  { // NEWTASK
    PeriodClock t;
    t.reset(); t.update();
    CreateProgressDialog(gettext(TEXT("Running test 0")));
    test_newtask(0);
    StartupStore(TEXT("test 0 %d\n"),t.elapsed());

    /*
    t.update();
    CreateProgressDialog(gettext(TEXT("Running test 1")));
    test_newtask(1);
    StartupStore(TEXT("test 1 %d\n"),t.elapsed());

    t.update();
    CreateProgressDialog(gettext(TEXT("Running test 2")));
    test_newtask(2);
    StartupStore(TEXT("test 2 %d\n"),t.elapsed());

    t.update();
    CreateProgressDialog(gettext(TEXT("Running test 3")));
    test_newtask(3);
    StartupStore(TEXT("test 3 %d\n"),t.elapsed());

    t.update();
    CreateProgressDialog(gettext(TEXT("Running test 4")));
    test_newtask(4);
    StartupStore(TEXT("test 4 %d\n"),t.elapsed());
    */
    CreateProgressDialog(gettext(TEXT("test complete")));
  }
#endif

  // Initialise the airspace warning dialog
  StartupStore(TEXT("dlgAirspaceWarningInit\n"));
  dlgAirspaceWarningInit();

  // Find unique ID of this PDA
  ReadAssetNumber();

  StartupStore(TEXT("ProgramStarted\n"));

  // Give focus to the map
  main_window.map.set_focus();

  // Start calculation thread
  calculation_thread->start();

  // Start instrument thread
  instrument_thread->start();

  globalRunningEvent.trigger();

  return true;
}
Example #13
0
BOOL
DoStop(PMAIN_WND_INFO pInfo)
{
    HWND hProgress;
    LPWSTR lpServiceList;
    BOOL bRet = FALSE;
    BOOL bStopMainService = TRUE;

    if (pInfo)
    {
        /* Does the service have any dependent services which need stopping first */
        lpServiceList = GetListOfServicesToStop(pInfo->pCurrentService->lpServiceName);
        if (lpServiceList)
        {
            /* Tag the service list to the main wnd info */
            pInfo->pTag = (PVOID)lpServiceList;

            /* List them and ask the user if they want to stop them */
            if (DialogBoxParamW(hInstance,
                                     MAKEINTRESOURCEW(IDD_DLG_DEPEND_STOP),
                                     pInfo->hMainWnd,
                                     StopDependsDialogProc,
                                     (LPARAM)pInfo) == IDOK)
            {
                /* Create a progress window to track the progress of the stopping services */
                hProgress = CreateProgressDialog(pInfo->hMainWnd,
                                                 IDS_PROGRESS_INFO_STOP);

                /* Stop all the dependant services */
                StopDependantServices(pInfo, lpServiceList, hProgress);

                /* Now stop the requested one */
                bRet = StopService(pInfo,
                                   pInfo->pCurrentService->lpServiceName,
                                   hProgress);

                /* We've already stopped the main service, don't try to stop it again */
                bStopMainService = FALSE;

                if (hProgress)
                {
                    /* Complete and destroy the progress bar */
                    DestroyProgressDialog(hProgress, TRUE);
                }
            }
            else
            {
                /* Don't stop the main service if the user selected not to */
                bStopMainService = FALSE;
            }

            HeapFree(GetProcessHeap(),
                     0,
                     lpServiceList);
        }

        /* If the service has no running dependents, then we stop it here */
        if (bStopMainService)
        {
            /* Create a progress window to track the progress of the stopping service */
            hProgress = CreateProgressDialog(pInfo->hMainWnd,
                                             IDS_PROGRESS_INFO_STOP);

            /* Stop the requested service */
            bRet = StopService(pInfo,
                               pInfo->pCurrentService->lpServiceName,
                               hProgress);

            if (hProgress)
            {
                /* Complete and destroy the progress bar */
                DestroyProgressDialog(hProgress, TRUE);
            }
        }
    }

    return bRet;
}
Example #14
0
void PreloadInitialisation(bool ask) {
  LKLanguageReady=false;
  LKReadLanguageFile(szLanguageFile);
  FillDataOptions(); // Load infobox list

  if (ask) {
    // Load default profile and status file: we are at an early stage
    LKProfileResetDefault();
    LKProfileLoad(startAircraftFile);
    LKProfileLoad(startPilotFile);
    LKProfileLoad(startDeviceFile);
    // if DEFAULT PROFILE does not exist, initialize ResetDefaults!
    // This is because LKProfileLoad will do this at its end, normally.
    // Notice: aircraft and pilot files will not be overridden by defaults
    if (!LKProfileLoad(startProfileFile)) {
	LKProfileInitRuntime();
    }

    StatusFileInit();
  } else {
    // We are in the dialog startup phase
    FullScreen();
    short retstartup;
    do {
	retstartup=dlgStartupShowModal();
    } while (retstartup>0);

    if (retstartup<0) return;

    if (_tcscmp(startProfileFile,_T("PROFILE_RESET"))==0) {
	StartupStore(_T(". USER ASKED FOR PROFILE FULL RESET!%s"),NEWLINE);
	DoStatusMessage(gettext(_T("_@M1757_"))); // LK8000 PROFILES RESET
	LKProfileResetDefault();
	LKProfileInitRuntime();
	// Notice: this is also resetting the default Aircraft and Pilot profiles to demo settings
    } else  {
	if (!LKProfileLoad(startPilotFile)) {
		#if TESTBENCH
		StartupStore(_T(". PilotFile RESET to defaults%s"),NEWLINE);
		#endif
	}
	if (!LKProfileLoad(startDeviceFile)) {
		#if TESTBENCH
		StartupStore(_T(". DeviceFile RESET to defaults%s"),NEWLINE);
		#endif
	}
	if (!LKProfileLoad(startAircraftFile)) {
		#if TESTBENCH
		StartupStore(_T(". AircraftFile RESET to defaults%s"),NEWLINE);
		#endif
	}
	LKProfileLoad(startProfileFile); // this is calling adjust and InitRuntime itself
    }

    // LKTOKEN _@M1206_ "Initialising..."
	CreateProgressDialog(gettext(TEXT("_@M1206_"))); 
  }

  // Interface (before interface)
  if (!ask) {
    LKReadLanguageFile(szLanguageFile);
    InputEvents::readFile();
  }
  
  InitCustomHardware();
}
Example #15
0
BOOL VLDeclare(PDeviceDescriptor_t d, Declaration_t *decl, unsigned errBufferLen, TCHAR errBuffer[])
{
  vl.set_device(d);
  nturnpoints = 0;

  const unsigned BUFF_LEN = 128;
  TCHAR buffer[BUFF_LEN];
  int err = VLA_ERR_NOERR;

  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1404_ = "Opening connection"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1404));
  CreateProgressDialog(buffer);
  if((err = vl.open(1, 20, 1, 38400L)) != VLA_ERR_NOERR) {
    // LKTOKEN  _@M1411_ = "Device not connected!"
    _tcsncpy(errBuffer, MsgToken(1411), errBufferLen);
    return FALSE;
  }

  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1405_ = "Testing connection"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1405));
  CreateProgressDialog(buffer);
  if((err = vl.read_info()) != VLA_ERR_NOERR) {
    // LKTOKEN  _@M1414_ = "Device not responsive!"
    _tcsncpy(errBuffer, MsgToken(1414), errBufferLen);
    return FALSE;
  }

  TCHAR2usascii(decl->PilotName, vl.declaration.flightinfo.pilot, 66);
  vl.declaration.flightinfo.pilot[64]='\0';

  TCHAR2usascii(decl->AircraftRego, vl.declaration.flightinfo.gliderid, 8);
  vl.declaration.flightinfo.gliderid[7]='\0';

  TCHAR2usascii(decl->AircraftType, vl.declaration.flightinfo.glidertype, 13);
  vl.declaration.flightinfo.glidertype[12]='\0';

  TCHAR2usascii(decl->CompetitionID, vl.declaration.flightinfo.competitionid, 4);
  vl.declaration.flightinfo.competitionid[3]='\0'; // BUGFIX 100331

  TCHAR2usascii(decl->CompetitionClass, vl.declaration.flightinfo.competitionclass, 13);
  vl.declaration.flightinfo.competitionclass[12]='\0'; // BUGFIX 100331

  if (ValidWayPoint(HomeWaypoint)) {

    TCHAR2usascii(WayPointList[HomeWaypoint].Name, vl.declaration.flightinfo.homepoint.name, 7);
    vl.declaration.flightinfo.homepoint.name[6]='\0'; // BUGFIX 100331

    vl.declaration.flightinfo.homepoint.lon =
      WayPointList[HomeWaypoint].Longitude;
    vl.declaration.flightinfo.homepoint.lat =
      WayPointList[HomeWaypoint].Latitude;
  }

  int i;
  for (i = 0; i < decl->num_waypoints; i++)
    VLDeclAddWayPoint(d, decl->waypoint[i]);

  vl.declaration.task.nturnpoints = max(min(nturnpoints-2, 12), 0);

  LockTaskData();

  // start..
  switch(StartLine) {
  case 0: // cylinder
    vl.declaration.task.startpoint.oztyp = VLAPI_DATA::DCLWPT::OZTYP_CYLSKT;
    vl.declaration.task.startpoint.lw = min(1500,(int)StartRadius);
    vl.declaration.task.startpoint.rz = min(1500,(int)StartRadius);
    vl.declaration.task.startpoint.rs = 0;
    break;
  case 1: // line
    vl.declaration.task.startpoint.oztyp = VLAPI_DATA::DCLWPT::OZTYP_LINE;
    vl.declaration.task.startpoint.lw = StartRadius * 2;
    vl.declaration.task.startpoint.rs = 0;
    vl.declaration.task.startpoint.rz = 0;
    break;
  case 2: // fai sector
    vl.declaration.task.startpoint.oztyp = VLAPI_DATA::DCLWPT::OZTYP_CYLSKT;
    vl.declaration.task.startpoint.lw = min(15000,(int)StartRadius);
    vl.declaration.task.startpoint.rz = 0;
    vl.declaration.task.startpoint.rs = min(15000,(int)StartRadius);
    break;
  }
  vl.declaration.task.startpoint.ws = 360;

  // rest of task...
  for (i=0; i<nturnpoints; i++) {
    // note this is for non-aat only!
    switch (SectorType) {
    case 0: // cylinder
      vl.declaration.task.turnpoints[i].oztyp = VLAPI_DATA::DCLWPT::OZTYP_CYLSKT;
      vl.declaration.task.turnpoints[i].rz = min(1500,(int)SectorRadius);
      vl.declaration.task.turnpoints[i].rs = 0;
      vl.declaration.task.turnpoints[i].lw = 0;
      break;
    case 1: // sector
      vl.declaration.task.turnpoints[i].oztyp = VLAPI_DATA::DCLWPT::OZTYP_CYLSKT;
      vl.declaration.task.turnpoints[i].rz = 0;
      vl.declaration.task.turnpoints[i].rs = min(15000,(int)SectorRadius);
      vl.declaration.task.turnpoints[i].lw = 0;
      break;
    case 2: // German DAe 0.5/10
      vl.declaration.task.turnpoints[i].oztyp = VLAPI_DATA::DCLWPT::OZTYP_CYLSKT;
      vl.declaration.task.turnpoints[i].rz = 500;
      vl.declaration.task.turnpoints[i].rs = 10000;
      vl.declaration.task.turnpoints[i].lw = 0;
      break;
    };
    vl.declaration.task.turnpoints[i].ws = 360; // auto direction

  }

  // Finish
  switch(FinishLine) {
  case 0: // cylinder
    vl.declaration.task.finishpoint.oztyp = VLAPI_DATA::DCLWPT::OZTYP_CYLSKT;
    vl.declaration.task.finishpoint.lw = min(1500,(int)FinishRadius);
    vl.declaration.task.finishpoint.rz = min(1500,(int)FinishRadius);
    vl.declaration.task.finishpoint.rs = 0;
    break;
  case 1: // line
    vl.declaration.task.finishpoint.oztyp = VLAPI_DATA::DCLWPT::OZTYP_LINE;
    vl.declaration.task.finishpoint.lw = FinishRadius*2;
    vl.declaration.task.finishpoint.rz = 0;
    vl.declaration.task.finishpoint.rs = 0;
    break;
  case 2: // fai sector
    vl.declaration.task.finishpoint.oztyp = VLAPI_DATA::DCLWPT::OZTYP_CYLSKT;
    vl.declaration.task.finishpoint.lw = min(15000,(int)FinishRadius);
    vl.declaration.task.finishpoint.rz = 0;
    vl.declaration.task.finishpoint.rs = min(15000,(int)FinishRadius);
    break;
  }
  vl.declaration.task.finishpoint.ws = 360;

  UnlockTaskData();

  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1403_ = "Sending  declaration"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1403));
  CreateProgressDialog(buffer);
  if((err = vl.write_db_and_declaration()) != VLA_ERR_NOERR) {
    // LKTOKEN  _@M1415_ = "Declaration not accepted!"
    _tcsncpy(errBuffer, MsgToken(1415), errBufferLen);
  }

  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1406_ = "Closing connection"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1406));
  CreateProgressDialog(buffer);
  vl.close(1);

  return err == VLA_ERR_NOERR;
}
Example #16
0
BOOL CDevCAIGpsNav::DeclareTask(PDeviceDescriptor_t d, Declaration_t *decl, unsigned errBufSize, TCHAR errBuf[])
{
  // check requirements
  if(!CheckWPCount(*decl, 1, 9, errBufSize, errBuf))  /// @todo: check min number
    return false;

  // create a unique set of task waypoints
  CTaskWPSet wps;
  for(int i=0; i<decl->num_waypoints; i++)
    wps.insert(decl->waypoint[i]);

  // create a list of waypoint indexes in a task
  CTaskWPIdxArray task;
  for(int i=0; i<decl->num_waypoints; i++) {
    int j=0;
    for(CTaskWPSet::const_iterator it=wps.begin(), end=wps.end(); it!=end; ++it, j++)
      if(decl->waypoint[i] == *it)
        task.push_back(j);
  }

  const unsigned BUFF_LEN = 128;
  TCHAR buffer[BUFF_LEN];
  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1404_ = "Opening connection"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1404));
  CreateProgressDialog(buffer);

  // prepare communication
  if(!StopRxThread(d, errBufSize, errBuf))
    return false;
  int timeout;
  bool status = SetRxTimeout(d, 500, timeout, errBufSize, errBuf);

  if(status) {
    EmptyRXBuffer(d);
    status = CAICommandMode(d, errBufSize, errBuf);
  }

  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1403_ = "Sending declaration"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1403));
  CreateProgressDialog(buffer);

  if(status) {
    int temptimeout;
    status = SetRxTimeout(d, 5000, temptimeout, errBufSize, errBuf);
  }

  if(status)
    status = WaypointsClear(d, errBufSize, errBuf);

  if(status)
    // enter CAI download mode
    status = CAIDownloadMode(d, errBufSize, errBuf);

  if(status)
    // upload waypoints
    status = WaypointsUpload(d, wps, errBufSize, errBuf);

  if(status)
    // upload task
    status = TaskUpload(d, task, errBufSize, errBuf);

  if(status)
    // upload pilot and glider data
    status = PilotAndGliderUpload(d, *decl, errBufSize, errBuf);

  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1406_ = "Closing connection"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1406));
  CreateProgressDialog(buffer);

  // restore NMEA mode
  status &= CAINMEAMode(d, errBufSize, errBuf);

  // restore regular communication
  status &= SetRxTimeout(d, timeout, timeout, errBufSize, errBuf);
  status &= StartRxThread(d, errBufSize, errBuf);

  return status;
}
Example #17
0
BOOL EWMicroRecorderDeclare(PDeviceDescriptor_t d, Declaration_t *decl, unsigned errBufferLen, TCHAR errBuffer[])
{
  const WAYPOINT *wp;
  nDeclErrorCode = 0;

  // Must have at least two, max 12 waypoints
  if(decl->num_waypoints < 2) {
    // LKTOKEN  _@M1412_ = "Not enough waypoints!"
    _tcsncpy(errBuffer, MsgToken(1412), errBufferLen);
    return FALSE;
  }
  if(decl->num_waypoints > 12) {
    // LKTOKEN  _@M1413_ = "Too many waypoints!"
    _tcsncpy(errBuffer, MsgToken(1413), errBufferLen);
    return FALSE;
  }

  d->Com->StopRxThread();

  d->Com->SetRxTimeout(500);                     // set RX timeout to 500[ms]

  const unsigned BUFF_LEN = 128;
  TCHAR buffer[BUFF_LEN];

  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1405_ = "Testing connection"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1405));
  CreateProgressDialog(buffer);
  if (!EWMicroRecorderTryConnect(d)) {
    // LKTOKEN  _@M1411_ = "Device not connected!"
    _tcsncpy(errBuffer, MsgToken(1411), errBufferLen);
    return FALSE;
  }

  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1403_ = "Sending  declaration"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1403));
  CreateProgressDialog(buffer);
  d->Com->WriteString(TEXT("\x18"));         // start to upload file
  d->Com->WriteString(user_data);

  TCHAR EWRecord[128];
  _stprintf(EWRecord, TEXT("Pilot Name:     %s\r\n"), decl->PilotName);
  d->Com->WriteString(EWRecord);
  _stprintf(EWRecord, TEXT("Competition ID: %s\r\n"), decl->CompetitionID);
  d->Com->WriteString(EWRecord);
  _stprintf(EWRecord, TEXT("Aircraft Type:  %s\r\n"), decl->AircraftType);
  d->Com->WriteString(EWRecord);
  _stprintf(EWRecord, TEXT("Aircraft ID:    %s\r\n"), decl->AircraftRego);
  d->Com->WriteString(EWRecord);

  d->Com->WriteString(TEXT("Description:      Declaration\r\n"));

  for (int i = 0; i < 11; i++) {
    wp = decl->waypoint[i];
    if (i == 0) {
      EWMicroRecorderWriteWayPoint(d, wp, TEXT("Take Off LatLong: "));
      EWMicroRecorderWriteWayPoint(d, wp, TEXT("Start LatLon:     "));
    } else if (i + 1 < decl->num_waypoints) {
      EWMicroRecorderWriteWayPoint(d, wp, TEXT("TP LatLon:        "));
    } else {
      d->Com->WriteString(TEXT("TP LatLon:        0000000N00000000E TURN POINT\r\n"));
    }
  }

  wp = decl->waypoint[decl->num_waypoints - 1];
  EWMicroRecorderWriteWayPoint(d, wp, TEXT("Finish LatLon:    "));
  EWMicroRecorderWriteWayPoint(d, wp, TEXT("Land LatLon:      "));

  d->Com->WriteString(TEXT("\x03"));         // finish sending user file

  if (!ExpectStringWait(d, TEXT("uploaded successfully"))) {
    // error!
    // LKTOKEN  _@M1415_ = "Declaration not accepted!"
    _tcsncpy(errBuffer, MsgToken(1415), errBufferLen);
    nDeclErrorCode = 1;
  }

  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1402_ = "Disabling declaration mode"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1402));
  CreateProgressDialog(buffer);
  d->Com->WriteString(TEXT("!!\r\n"));         // go back to NMEA mode

  d->Com->SetRxTimeout(RXTIMEOUT);                       // clear timeout
  d->Com->StartRxThread();                       // restart RX thread

  return(nDeclErrorCode == 0);                    // return() TRUE on success
}
Example #18
0
void RasterTerrain::OpenTerrain(void)
{
  terrain_initialised = false;
  #if TESTBENCH
  StartupStore(TEXT(". Loading Terrain... %s"),NEWLINE);
  #endif
  CreateProgressDialog(gettext(TEXT("_@M900_"))); // Loading Terrain File...

  TCHAR szFile[MAX_PATH] = _T("\0");

  _tcscpy(szFile,szTerrainFile);

  TCHAR szOrigFile[MAX_PATH] = _T("\0");
  ExpandLocalPath(szFile);
  _tcscpy(szOrigFile, szFile);
  ContractLocalPath(szOrigFile);

  // If no terrain will be found, the registry will be invalid on next run
  _tcscpy(szTerrainFile,_T(""));


#ifdef LKMTERRAIN
  static TCHAR  szMFile[MAX_PATH] = TEXT("\0");
  if (_tcslen(szFile)==0) {
    StartupStore(_T(". NO TERRAIN file configured%s"),NEWLINE);
    _tcscpy(szMFile,szMapFile);
    ExpandLocalPath(szMFile);
    _tcscpy(szFile,szMFile);

     _tcscpy(szFile,szMFile);
     _tcscat(szFile, _T("/terrain.dem")); 
     StartupStore(_T(". Attempting to use DEM <%s> inside mapfile%s"),szFile,NEWLINE);
  }

  if (CreateTerrainMap(szFile)) {
	_tcscpy(szTerrainFile,szOrigFile);
	terrain_initialised = true;
	return;
  } else {
	_tcscpy(szFile,szMFile);
	_tcscat(szFile, _T("/terrain.dat")); 
	StartupStore(_T(". Attempting to use DAT <%s> inside mapfile%s"),szFile,NEWLINE);

	if (CreateTerrainMap(szFile)) {
		_tcscpy(szTerrainFile,szOrigFile);
		terrain_initialised = true;
		return;
	}
   }
#else

  if ( (_tcslen(szFile)>0) && ( _tcsstr(szFile, _T(".DEM")) || _tcsstr(szFile, _T(".dem")) ) ) {
	if (CreateTerrainMap(szFile)) {
		_tcscpy(szterrainFile,szOrigFile);
		terrain_initialised = true;
		return;
	} else {
		StartupStore(_T("... INVALID TERRAIN file <%s>%s"),szFile,NEWLINE);
	}
  }

#endif

  if (TerrainMap) {
	TerrainMap->Close();
	delete TerrainMap;
	TerrainMap = NULL;
  }
  terrain_initialised = false;
  StartupStore(_T(". NO TERRAIN file available.%s"),NEWLINE);
}
Example #19
0
// returns -1 if error, or the WpFileType 
int ReadWayPointFile(ZZIP_FILE *fp, TCHAR *CurrentWpFileName)
{
  WAYPOINT *new_waypoint;
  TCHAR szTemp[100];
  DWORD fSize, fPos=0;
  int nLineNumber=0;
  short fileformat=LKW_DAT;

  HWND hProgress;

  hProgress = CreateProgressDialog(gettext(TEXT("_@M903_"))); // Loading Waypoints File...

  fSize = zzip_file_size(fp);

  fileformat=GetWaypointFileFormatType(CurrentWpFileName);

  if (fileformat<0) {
	StartupStore(_T("... Unknown file format in waypoint file <%s\n"),CurrentWpFileName);
	// We do NOT return, because first we analyze the content.
  }

  if (fSize <10) {
	StartupStore(_T("... ReadWayPointFile: waypoint file %s type=%d is empty%s"), CurrentWpFileName,fileformat,NEWLINE);
	return -1;
  }

  if (!AllocateWaypointList()) {
	StartupStore(_T("!!!!!! ReadWayPointFile: AllocateWaypointList FAILED%s"),NEWLINE);
	return -1;
  }

  new_waypoint = WayPointList+NumberOfWayPoints;


  memset(nTemp2String, 0, sizeof(nTemp2String)); // clear Temp Buffer

  // check file format
  bool fempty=true;
  int  slen=0; // 100204 WIP
  while ( ReadString(fp,READLINE_LENGTH,nTemp2String) ) {
	slen=_tcslen(nTemp2String);
	if (slen<1) continue;
	if ( _tcsncmp(_T("G  WGS 84"),nTemp2String,9) == 0 ||
	   _tcsncmp(_T("G WGS 84"),nTemp2String,8) == 0 ||
	   // consider UCS header, 3 bytes in fact. This is a workaround.
	   _tcsncmp(_T("G  WGS 84"),&nTemp2String[3],9) == 0) {
		if ( !ReadString(fp,READLINE_LENGTH,nTemp2String) ) {
			StartupStore(_T(". Waypoint file %d format: CompeGPS truncated, rejected%s"),globalFileNum+1,NEWLINE);
			return -1;
		}
		slen=_tcslen(nTemp2String);
		if (slen<1) {
			StartupStore(_T(". Waypoint file %d format: CompeGPS MISSING second U line, rejected%s"),globalFileNum+1,NEWLINE);
			return -1;
		}
		if ( (_tcsncmp(_T("U  0"),nTemp2String,4) == 0) ||
		     (_tcsncmp(_T("U 0"),nTemp2String,3) == 0)) {
			StartupStore(_T(". Waypoint file %d format: CompeGPS with UTM coordinates UNSUPPORTED%s"),globalFileNum+1,NEWLINE);
			return -1;
		}
		if ( _tcsncmp(_T("U  1"),nTemp2String,4) != 0 && 
		     _tcsncmp(_T("U 1"),nTemp2String,3) != 0 ) {
			StartupStore(_T(". Waypoint file %d format: CompeGPS unknown U field, rejected%s"),globalFileNum+1,NEWLINE);
			return -1;
		}
		
		StartupStore(_T(". Waypoint file %d format: CompeGPS, LatLon coordinates%s"),globalFileNum+1,NEWLINE);
		fempty=false;
		fileformat=LKW_COMPE;
		break;
	}
	if ( (_tcsncmp(_T("name,code,country"),nTemp2String,17) == 0) || 
		(_tcsncmp(_T("Title,Code,Country"),nTemp2String,18) == 0)  // 100314
	) {
		StartupStore(_T(". Waypoint file %d format: SeeYou%s"),globalFileNum+1,NEWLINE);
		fempty=false;
		fileformat=LKW_CUP;
		break;
	}

	if ( ( _tcsstr(nTemp2String, _T("OziExplorer Waypoint File")) == nTemp2String )||
			   // consider UCS header, 3 bytes in fact. This is a workaround.
			(_tcsstr(&nTemp2String[3], _T("OziExplorer Waypoint File")) == &nTemp2String[3]) ) {
		StartupStore(_T(". Waypoint file %d format: OziExplorer%s"),globalFileNum+1,NEWLINE);
		fempty=false;
		fileformat=LKW_OZI;
		break;
	}

	// consider also the case of empty file, when a waypoint if saved starting with numbering after
	// the virtual wps (including the 0);
	// Warning, using virtualdatheader 3 tcsncmp because virtuals are now more than 9.
	TCHAR virtualdatheader[5];
	wsprintf(virtualdatheader,_T("%d,"),RESWP_END+2);
	if ( _tcsncmp(_T("1,"),nTemp2String,2) == 0 ||
	  _tcsncmp(virtualdatheader,nTemp2String,3) == 0) {
		StartupStore(_T(". Waypoint file %d format: WinPilot%s"),globalFileNum+1,NEWLINE);
		fempty=false;
		fileformat=LKW_DAT;
		break;
	}
	// Otherwise we use the fileformat .xxx suffix. 
	// Why we did not do it since the beginning? Simply because we should not rely on .xxx suffix
	// because some formats like CompeGPS and OZI, for example, share the same .WPT suffix.
	// 
	if (fileformat<0) {
		StartupStore(_T(".. Unknown WP header, unknown format in <%s>%s"),nTemp2String,NEWLINE);
		// leaving fempty true, so no good file available
		break;
	} else {
		fempty=false;
		StartupStore(_T(".. Unknown WP header, using format %d.  Header: <%s>%s"),fileformat,nTemp2String,NEWLINE);
		break;
	}
  }
  if (fempty) {
	return -1;
  }

  // SetFilePointer(hFile,0,NULL,FILE_BEGIN);
  fPos = 0;

  // a real shame, too lazy to change into do while loop
  // Skip already read lines containing header, unless we are using DAT, which has no header
  if ( fileformat==LKW_DAT) goto goto_inloop; 

  memset(nTemp2String, 0, sizeof(nTemp2String)); // clear Temp Buffer

  while(ReadString(fp, READLINE_LENGTH, nTemp2String)){
goto_inloop:    
	nLineNumber++;
	nTemp2String[READLINE_LENGTH]=_T('\0');
	nTemp2String[READLINE_LENGTH-1]=_T('\n');
	nTemp2String[READLINE_LENGTH-2]=_T('\r');
	fPos += _tcslen(nTemp2String);
   
	if (_tcsstr(nTemp2String, TEXT("**")) == nTemp2String) // Look For Comment
		continue;

	if (_tcsstr(nTemp2String, TEXT("*")) == nTemp2String)  // Look For SeeYou Comment
		continue;

	if (nTemp2String[0] == '\0')
		continue;

	new_waypoint->Details = NULL; 
	new_waypoint->Comment = NULL; 

	if ( fileformat == LKW_DAT || fileformat== LKW_XCW ) {
		if (ParseDAT(nTemp2String, new_waypoint)) {

			if ( (_tcscmp(new_waypoint->Name, gettext(TEXT(RESWP_TAKEOFF_NAME)))==0) && (new_waypoint->Number==RESWP_ID)) {
				StartupStore(_T("... FOUND TAKEOFF (%s) INSIDE WAYPOINTS FILE%s"), gettext(TEXT(RESWP_TAKEOFF_NAME)), NEWLINE);
				memcpy(WayPointList,new_waypoint,sizeof(WAYPOINT));
				continue;
			}

			if (WaypointInTerrainRange(new_waypoint)) { 
				new_waypoint = GrowWaypointList();
				if (!new_waypoint) {
					return -1; // failed to allocate
				}
				new_waypoint++; // we want the next blank one
			}	
	  	}
	}
	if ( fileformat == LKW_CUP ) {
		if ( _tcsncmp(_T("-----Related Tasks"),nTemp2String,18)==0) {
			break;
		}
		if (ParseCUPWayPointString(nTemp2String, new_waypoint)) {
			if ( (_tcscmp(new_waypoint->Name, gettext(TEXT(RESWP_TAKEOFF_NAME)))==0) && (new_waypoint->Number==RESWP_ID)) {
				StartupStore(_T("... FOUND TAKEOFF (%s) INSIDE WAYPOINTS FILE%s"), gettext(TEXT(RESWP_TAKEOFF_NAME)), NEWLINE);
				memcpy(WayPointList,new_waypoint,sizeof(WAYPOINT));
				continue;
			}

			if (WaypointInTerrainRange(new_waypoint)) { 
				new_waypoint = GrowWaypointList();
				if (!new_waypoint) {
					return -1; // failed to allocate
				}
				new_waypoint++; // we want the next blank one
			}
		}
	}
	if ( fileformat == LKW_COMPE ) {
		if (ParseCOMPEWayPointString(nTemp2String, new_waypoint)) {
			if ( (_tcscmp(new_waypoint->Name, gettext(TEXT(RESWP_TAKEOFF_NAME)))==0) && (new_waypoint->Number==RESWP_ID)) {
				StartupStore(_T("... FOUND TAKEOFF (%s) INSIDE WAYPOINTS FILE%s"), gettext(TEXT(RESWP_TAKEOFF_NAME)), NEWLINE);
				memcpy(WayPointList,new_waypoint,sizeof(WAYPOINT));
				continue;
			}

			if (WaypointInTerrainRange(new_waypoint)) { 
				new_waypoint = GrowWaypointList();
				if (!new_waypoint) {
					return -1; // failed to allocate
				}
				new_waypoint++; // we want the next blank one
			}
		}
	}

	if(fileformat == LKW_OZI){
		// Ignore first four header lines
		if(nLineNumber <= 3)
			continue;

		if(ParseOZIWayPointString(nTemp2String, new_waypoint)){
			if ( (_tcscmp(new_waypoint->Name, gettext(TEXT(RESWP_TAKEOFF_NAME)))==0) && (new_waypoint->Number==RESWP_ID)) {
				StartupStore(_T("... FOUND TAKEOFF (%s) INSIDE WAYPOINTS FILE%s"), gettext(TEXT(RESWP_TAKEOFF_NAME)), NEWLINE);
				memcpy(WayPointList,new_waypoint,sizeof(WAYPOINT));
				continue;
			}

			if (WaypointInTerrainRange(new_waypoint)) {
				new_waypoint = GrowWaypointList();
				if (!new_waypoint) {
					return -1; // failed to allocate
				}
				new_waypoint++; // we want the next blank one
			}
		}
	}

	memset(nTemp2String, 0, sizeof(nTemp2String)); // clear Temp Buffer

	continue;

  }

  if (hProgress) {
	_stprintf(szTemp,TEXT("100%%"));       
	SetDlgItemText(hProgress,IDC_PROGRESS,szTemp);
  }
  return fileformat;

}
Example #20
0
void RefactoringEngine::DoFindReferences(const wxString& symname, const wxFileName& fn, int line, int pos, const wxFileList_t& files, bool onlyDefiniteMatches)
{
    // Clear previous results
    Clear();
    
    if ( ! m_storage.IsCacheReady() ) {
        m_storage.InitializeCache( files );
        return;
    }
    
    // Container for the results found in the 'files'
    CppTokensMap tokensMap;

    // Load the file and get a state map + the text from the scanner
    CppWordScanner scanner(fn.GetFullPath());

    // get the current file states
    TextStatesPtr states = scanner.states();
    if(!states)
        return;

    // Attempt to understand the expression that the caret is currently located at (using line:pos:file)
    RefactorSource rs;
    if(!DoResolveWord(states, fn, pos + symname.Len(), line, symname, &rs))
        return;

    wxFileList_t modifiedFilesList = m_storage.FilterUpToDateFiles( files );
    clProgressDlg* prgDlg = NULL;
    if ( !modifiedFilesList.empty() ) {
        prgDlg = CreateProgressDialog(_("Updating cache..."), files.size());
        // Search the provided input files for the symbol to rename and prepare
        // a CppTokensMap
        for (size_t i=0; i<modifiedFilesList.size(); i++) {
            wxFileName curfile = modifiedFilesList.at(i);

            wxString msg;
            msg << _("Caching file: ") << curfile.GetFullName();
            // update the progress bar
            if (!prgDlg->Update(i, msg)) {
                prgDlg->Destroy();
                Clear();
                return;
            }

            // Scan only valid C / C++ files
            switch(FileExtManager::GetType(curfile.GetFullName())) {
            case FileExtManager::TypeHeader:
            case FileExtManager::TypeSourceC:
            case FileExtManager::TypeSourceCpp: {
                // load matches for a give symbol
                m_storage.Match(symname, curfile.GetFullPath(), tokensMap);
            }
            break;
            default:
                break;
            }
        }
        prgDlg->Destroy();
    }
    // load all tokens, first we need to parse the workspace files...
    CppToken::List_t tokens = m_storage.GetTokens(symname, files);
    if (tokens.empty())
        return;

    // sort the tokens
    tokens.sort();

    RefactorSource target;
    std::list<CppToken>::iterator iter = tokens.begin();
    int counter(0);

    TextStatesPtr statesPtr(NULL);
    wxString      statesPtrFileName;
    prgDlg = CreateProgressDialog(_("Stage 2/2: Parsing matches..."), (int) tokens.size());

    for (; iter != tokens.end(); ++iter) {

        // TODO :: send an event here to report our progress
        wxFileName f( iter->getFilename() );
        wxString   msg;
        msg << _("Parsing expression ") << counter << wxT("/") << tokens.size() << _(" in file: ") << f.GetFullName();
        if ( !prgDlg->Update(counter, msg) ) {
            // user clicked 'Cancel'
            Clear();
            prgDlg->Destroy();
            return;
        }

        counter++;
        // reset the result
        target.Reset();

        if(!statesPtr || statesPtrFileName != iter->getFilename() ) {
            // Create new statesPtr
            CppWordScanner sc(iter->getFilename());
            statesPtr         = sc.states();
            statesPtrFileName = iter->getFilename();
        }

        if(!statesPtr)
            continue;

        if (DoResolveWord(statesPtr, wxFileName( iter->getFilename() ), iter->getOffset(), iter->getLineNumber(), symname, &target)) {

            // set the line number
            if(statesPtr->states.size() > iter->getOffset())
                iter->setLineNumber( statesPtr->states[iter->getOffset()].lineNo );

            if (target.name == rs.name && target.scope == rs.scope) {
                // full match
                m_candidates.push_back( *iter );

            } else if (target.name == rs.scope && !rs.isClass) {
                // source is function, and target is class
                m_candidates.push_back( *iter );

            } else if (target.name == rs.name && rs.isClass) {
                // source is class, and target is ctor
                m_candidates.push_back( *iter );

            } else if (!onlyDefiniteMatches) {
                // add it to the possible match list
                m_possibleCandidates.push_back( *iter );
            }
        } else if( !onlyDefiniteMatches) {
            // resolved word failed, add it to the possible list
            m_possibleCandidates.push_back( *iter );
        }
    }

    prgDlg->Destroy();
}
Example #21
0
BOOL DSXDeclare(PDeviceDescriptor_t d, Declaration_t *decl, unsigned errBufferLen, TCHAR errBuffer[])
{
  // Must have at least two, max 12 waypoints
  if(decl->num_waypoints < 2) {
    // LKTOKEN  _@M1412_ = "Not enough waypoints!"
    _tcsncpy(errBuffer, MsgToken(1412), errBufferLen);
    return FALSE;
  }
  if(decl->num_waypoints > 12) {
    // LKTOKEN  _@M1413_ = "Too many waypoints!"
    _tcsncpy(errBuffer, MsgToken(1413), errBufferLen);
    return FALSE;
  }

  bool status = true;

  // Stop RX thread
  d->Com->StopRxThread();
  d->Com->SetRxTimeout(3000);                     // set RX timeout to 3000[ms]

  const unsigned BUFF_LEN = 128;
  TCHAR buffer[BUFF_LEN];

  // Enable DSX declaration mode
  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1401_ = "Enabling declaration mode"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1401));
  CreateProgressDialog(buffer);
  status = DSXSwitchDeclareMode(d, true, errBufferLen, errBuffer);

  if(status) {
    // Send user, glider and competition data
    // LKTOKEN  _@M1400_ = "Task declaration"
    // LKTOKEN  _@M1403_ = "Sending  declaration"
    _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1403));
    CreateProgressDialog(buffer);
    status = status && DSXHSend(d, *decl, errBufferLen, errBuffer);

    // Send T1 sentence with task general data
    status = status && DSXT1Send(d, *decl, errBufferLen, errBuffer);

    // Send T2 sentence with takeoff, start, finish, landing data
    status = status && DSXT2Send(d, *decl, errBufferLen, errBuffer);

    // Send T3 sentence for each turnpoint
    unsigned tpCount = decl->num_waypoints - 2;   // skip Start and Finish waypoint
    for(unsigned i=0; i<tpCount; i++)
      status = status && DSXT3Send(d, *decl, i, errBufferLen, errBuffer);
  }

  // Disable DSX declaration mode
  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1402_ = "Disabling declaration mode"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1402));
  CreateProgressDialog(buffer);
  status = DSXSwitchDeclareMode(d, false, errBufferLen, errBuffer) && status; // always do that step otherwise NMEA will not be send

  // Restart RX thread
  d->Com->SetRxTimeout(RXTIMEOUT);    // clear timeout
  d->Com->StartRxThread();

  return status;
}
Example #22
0
void PreloadInitialisation(bool ask) {
  LKReadLanguageFile(szLanguageFile);

  if (ask) {
    // Load default profile and status file: we are at an early stage
    LKProfileResetDefault();
    LKProfileLoad(startAircraftFile);
    LKProfileLoad(startPilotFile);
    LKProfileLoad(startDeviceFile);
    LKProfileLoad(startProfileFile);

	LKProfileInitRuntime();
    
  } else {
    // We are in the dialog startup phase
    FullScreen();
    short retstartup;
    do {
	retstartup=dlgStartupShowModal();
    } while (retstartup>0);

    if (retstartup<0) return;

    if (_tcscmp(startProfileFile,_T("PROFILE_RESET"))==0) {
        StartupStore(_T(". USER ASKED FOR PROFILE FULL RESET!%s"),NEWLINE);
        DoStatusMessage(MsgToken(1757)); // LK8000 PROFILES RESET
        LKProfileResetDefault();
	// Notice: this is also resetting the default Aircraft and Pilot profiles to demo settings
    } else  {
        if (!LKProfileLoad(startPilotFile)) {
            #if TESTBENCH
            StartupStore(_T(". PilotFile RESET to defaults%s"),NEWLINE);
            #endif
        }
        if (!LKProfileLoad(startDeviceFile)) {
            #if TESTBENCH
            StartupStore(_T(". DeviceFile RESET to defaults%s"),NEWLINE);
            #endif
        }
        if (!LKProfileLoad(startAircraftFile)) {
            #if TESTBENCH
            StartupStore(_T(". AircraftFile RESET to defaults%s"),NEWLINE);
            #endif
        }
    	if(!LKProfileLoad(startProfileFile)) {
            #if TESTBENCH
            StartupStore(_T(". SystemFile RESET to defaults%s"),NEWLINE);
            #endif
        }
    }
	LKProfileInitRuntime();

    InitLKFonts();
    // We are sure that buttons have been created already
    ButtonLabel::SetFont(MapWindowBoldFont);

    // font change, we need to reset "Messge
    Message::InitFont();

    // LKTOKEN _@M1206_ "Initialising..."
	CreateProgressDialog(MsgToken(1206));
  }

  // Interface (before interface)
  if (!ask) {
    LKReadLanguageFile(szLanguageFile);
    InputEvents::readFile();
  }

  InitCustomHardware();
}