Esempio n. 1
0
void StopLogger(void) {
  TCHAR szMessage[(MAX_PATH*2)+1] = TEXT("\0");
  int iLoggerError=0;  // see switch statement for error handler
  TCHAR sztmplogfile[MAX_PATH+1] = TEXT("\0");
  int retval=0;

  _tcscpy(sztmplogfile,szLoggerFileName); // use LOGGER_TMP, unsigned

  if (LoggerActive) {
    LoggerActive = false;
    if (LoggerClearFreeSpace()) {

    #if (TESTBENCH && DEBUG_LOGGER)
    if (LoggerGActive())
    #else
    if (!SIMMODE && LoggerGActive())
    #endif
	{

	extern int RunSignature();
	retval = RunSignature();
	if (retval!=0) {
		StartupStore(_T(".... LOGGER SIGNATURE ERROR, CODE=%d%s"),retval,NEWLINE);
		switch(retval) {
			case -1:
				StartupStore(_T(".... (EXEQ DEBUG FAILURE)%s"),NEWLINE);
				break;
			case 1:
				StartupStore(_T(".... (SOURCE FILE DISAPPEARED)%s"),NEWLINE);
				break;
			case 3:
				StartupStore(_T(".... (EXEQ WITH WRONG ARGUMENTS)%s"),NEWLINE);
				break;
			case 4:
				StartupStore(_T(".... (BAD ENVIRONMENT)%s"),NEWLINE);
				break;
			case 11:
				StartupStore(_T(".... (LOGGER_TMP DISAPPEARED)%s"),NEWLINE);
				break;
			case 12:
				StartupStore(_T(".... (LOGGER_SIG ALREADY EXISTING)%s"),NEWLINE);
				break;
			case 21:
				StartupStore(_T(".... (MUTEX FAILURE=)%s"),NEWLINE);
				break;
			case 259:
				StartupStore(_T(".... (PROCESS DID NOT TERMINATE!)%s"),NEWLINE);
				break;
			default:
				break;
		}
		// we shall be moving LOGGER_TMP, and leave LOGGER_SIG untouched. In fact we do not know
		// if LOGGER_SIG is or will be available.
	} else {
		// RunSig ok, change logfile to new logger_sig
		StartupStore(_T(". Logger OK, IGC signed with G-Record%s"),NEWLINE);
		DeleteFile(szLoggerFileName);	// remove old LOGGER_TMP
		_tcscpy(sztmplogfile,szSLoggerFileName); // use LOGGER_SIG, signed
	}

	} // logger active

      int imCount=0;
      const int imMax=3;
      for (imCount=0; imCount < imMax; imCount++) {
        // MoveFile() nonzero==Success
        if (0 != MoveFile( sztmplogfile, szFLoggerFileName)) {
          iLoggerError=0;
          break; // success
        }
        Sleep(750); // wait for file system cache to fix itself?
      }
      if (imCount == imMax) { // MoveFile() failed all attempts

        if (0 == MoveFile( sztmplogfile, szFLoggerFileNameRoot)) { // try rename it and leave in root
          iLoggerError=1; //Fail.  NoMoveNoRename
        }
        else {
          iLoggerError=2; //NoMoveYesRename
        }
      }

    } // logger clearfreespace
    else { // Insufficient disk space.  // MoveFile() nonzero==Success
      if (0 == MoveFile( sztmplogfile, szFLoggerFileNameRoot)) { // try rename it and leave in root
        iLoggerError=3; //Fail.  Insufficient Disk Space, NoRename
      }
      else {
        iLoggerError=4; //Success.  Insufficient Disk Space, YesRename
      }
    }

    switch (iLoggerError) { //0=Success 1=NoMoveNoRename 2=NoMoveYesRename 3=NoSpaceNoRename 4=NoSpaceYesRename
    case 0:
      StartupStore(TEXT(". Logger: File saved %s%s"),WhatTimeIsIt(),NEWLINE);
      break;

    case 1: // NoMoveNoRename
      LK_tcsncpy(szMessage,TEXT("--- Logger file not copied.  It is in the root folder of your device and called "),MAX_PATH);
      _tcsncat(szMessage,sztmplogfile,MAX_PATH);

      MessageBoxX(hWndMapWindow,
		gettext(szMessage),
	// LKTOKEN  _@M404_ = "Logger Error" 
		gettext(TEXT("_@M404_")), MB_OK| MB_ICONERROR);
      _tcsncat(szMessage,TEXT(SNEWLINE),MAX_PATH);
      StartupStore(szMessage);
      break;

    case 2: // NoMoveYesRename
      LK_tcsncpy(szMessage,TEXT("--- Logger file not copied.  It is in the root folder of your device"),MAX_PATH);

      MessageBoxX(hWndMapWindow,
		gettext(szMessage),
	// LKTOKEN  _@M404_ = "Logger Error" 
		gettext(TEXT("_@M404_")), MB_OK| MB_ICONERROR);
      _tcsncat(szMessage,TEXT(SNEWLINE),MAX_PATH);
      StartupStore(szMessage);
      break;

    case 3: // Insufficient Storage.  NoRename
      LK_tcsncpy(szMessage,TEXT("++++++ Insuff. storage. Logger file in device's root folder, called "),MAX_PATH);
      _tcsncat(szMessage,sztmplogfile,MAX_PATH);

      MessageBoxX(hWndMapWindow,
		gettext(szMessage),
	// LKTOKEN  _@M404_ = "Logger Error" 
		gettext(TEXT("_@M404_")), MB_OK| MB_ICONERROR);
      _tcsncat(szMessage,TEXT(SNEWLINE),MAX_PATH);
      StartupStore(szMessage);
      break;

    case 4: // Insufficient Storage.  YesRename
      LK_tcsncpy(szMessage,TEXT("++++++ Insufficient storage.  Logger file is in the root folder of your device"),MAX_PATH);

      MessageBoxX(hWndMapWindow,
		gettext(szMessage),
	// LKTOKEN  _@M404_ = "Logger Error" 
		gettext(TEXT("_@M404_")), MB_OK| MB_ICONERROR);
      _tcsncat(szMessage,TEXT(SNEWLINE),MAX_PATH);
      StartupStore(szMessage);
      break;
} // error handler

    NumLoggerBuffered = 0;
  }
}
Esempio n. 2
0
static void UpdateValuesSystem() {

  static int extGPSCONNECT_last = extGPSCONNECT;
  static bool NAVWarning_last = GPS_INFO.NAVWarning;
  static int SatellitesUsed_last = GPS_INFO.SatellitesUsed;
  static int VarioAvailable_last = GPS_INFO.VarioAvailable;
  static int FLARM_Available_last = GPS_INFO.FLARM_Available;
  static bool LoggerActive_last = LoggerActive;
  static bool DeclaredToDevice_last = DeclaredToDevice;
  static double SupplyBatteryVoltage_last = GPS_INFO.SupplyBatteryVoltage;
  static int PDABatteryPercent_last = PDABatteryPercent;
  static int batterybank_last = GPS_INFO.ExtBatt_Bank;
  static double extbatt1_voltage = GPS_INFO.ExtBatt1_Voltage;
  static double extbatt2_voltage = GPS_INFO.ExtBatt2_Voltage;

  static double FLARM_HW_Version = GPS_INFO.FLARM_HW_Version;
  static double FLARM_SW_Version = GPS_INFO.FLARM_SW_Version;


  if (first ||
      (extGPSCONNECT_last != extGPSCONNECT) ||
      (NAVWarning_last != GPS_INFO.NAVWarning) ||
      (SatellitesUsed_last != GPS_INFO.SatellitesUsed) ||
      (VarioAvailable_last != GPS_INFO.VarioAvailable) ||
      (FLARM_Available_last != GPS_INFO.FLARM_Available) ||
      (LoggerActive_last != LoggerActive) ||
      (DeclaredToDevice_last != DeclaredToDevice) ||
      (SupplyBatteryVoltage_last != GPS_INFO.SupplyBatteryVoltage) ||
      (batterybank_last != GPS_INFO.ExtBatt_Bank) ||
      (extbatt1_voltage != GPS_INFO.ExtBatt1_Voltage) ||
      (extbatt2_voltage != GPS_INFO.ExtBatt2_Voltage) ||
      (FLARM_HW_Version != GPS_INFO.FLARM_HW_Version) ||
      (FLARM_SW_Version != GPS_INFO.FLARM_SW_Version) ||
      (PDABatteryPercent_last != PDABatteryPercent)) {
    first = false;

    extGPSCONNECT_last = extGPSCONNECT;
    NAVWarning_last = GPS_INFO.NAVWarning;
    SatellitesUsed_last = GPS_INFO.SatellitesUsed;
    VarioAvailable_last = GPS_INFO.VarioAvailable;
    FLARM_Available_last = GPS_INFO.FLARM_Available;
    LoggerActive_last = LoggerActive;
    DeclaredToDevice_last = DeclaredToDevice;
    SupplyBatteryVoltage_last = GPS_INFO.SupplyBatteryVoltage;
    PDABatteryPercent_last = PDABatteryPercent;
    batterybank_last = GPS_INFO.ExtBatt_Bank;
    extbatt1_voltage = GPS_INFO.ExtBatt1_Voltage;
    extbatt2_voltage = GPS_INFO.ExtBatt2_Voltage;
    FLARM_HW_Version = GPS_INFO.FLARM_HW_Version;
    FLARM_SW_Version = GPS_INFO.FLARM_SW_Version;
  } else {
    return;
  }
  
  TCHAR Temp[80];
  TCHAR Temp2[80];

  WndProperty* wp;
  wp = (WndProperty*)wf->FindByName(TEXT("prpGPS"));
  if (wp) {
    if (extGPSCONNECT) {
      if (GPS_INFO.NAVWarning) {
	// LKTOKEN  _@M303_ = "Fix invalid" 
        wp->SetText(gettext(TEXT("_@M303_")));
      } else {
        if (GPS_INFO.SatellitesUsed==0) {
	// LKTOKEN  _@M471_ = "No fix" 
          wp->SetText(gettext(TEXT("_@M471_")));
        } else {
	// LKTOKEN  _@M31_ = "3D fix" 
          wp->SetText(gettext(TEXT("_@M31_")));
        }
      }
      wp->RefreshDisplay();

      wp = (WndProperty*)wf->FindByName(TEXT("prpNumSat"));
      if (wp) {
        if (GPS_INFO.SatellitesUsed >= 0) {  // known numer of sats
          _stprintf(Temp,TEXT("%d"),GPS_INFO.SatellitesUsed);
        } else { // valid but unknown number of sats
          _stprintf(Temp,TEXT(">3"));
        }
	if (nmeaParser1.activeGPS==true)
		_tcscat(Temp,_T("  (Dev:A)"));
	else
		_tcscat(Temp,_T("  (Dev:B)"));
        wp->SetText(Temp);
        wp->RefreshDisplay();
      }
    } else {
	// LKTOKEN  _@M240_ = "Disconnected" 
      wp->SetText(gettext(TEXT("_@M240_")));
      wp->RefreshDisplay();
    }
  }

  wp = (WndProperty*)wf->FindByName(TEXT("prpVario"));
  if (wp) {
    if (GPS_INFO.VarioAvailable) {
	// LKTOKEN  _@M199_ = "Connected" 
#ifdef DEVICE_SERIAL	
     if(GPS_INFO.HardwareId >0)
     {
    	  TCHAR sDevice[32]={0};
 		if((pDevSecondaryBaroSource != NULL))
           if(!(pDevSecondaryBaroSource->Disabled) &&
              (pDevSecondaryBaroSource->Name != NULL))
           {
             _stprintf(sDevice, TEXT("%s"), pDevSecondaryBaroSource->Name  );
           }

 		if((pDevPrimaryBaroSource != NULL))
           if(!(pDevPrimaryBaroSource->Disabled) &&
              (pDevPrimaryBaroSource->Name != NULL))
           {
             _stprintf(sDevice, TEXT("%s"), pDevPrimaryBaroSource->Name );
           }

	  _stprintf(Temp,TEXT("%s (%i)"),sDevice, GPS_INFO.HardwareId);
		wp->SetText(Temp);
     }
     else
#endif     
	   wp->SetText(gettext(TEXT("_@M199_")));
    } else {
	// LKTOKEN  _@M240_ = "Disconnected" 
      wp->SetText(gettext(TEXT("_@M240_")));
    }
    wp->RefreshDisplay();
  }

  if (wp) {
    wp = (WndProperty*)wf->FindByName(TEXT("prpFLARM"));
    if (GPS_INFO.FLARM_Available) {
	// LKTOKEN  _@M199_ = "Connected" 

      if(FLARM_SW_Version > 0.0)
      {
    //	StartupStore(_T("STATUS: Flarm Version: %4.2f/%4.2f\n"),FLARM_SW_Version, FLARM_HW_Version);
		_stprintf(Temp,TEXT("OK (%4.2f/%4.2f) "),FLARM_SW_Version, FLARM_HW_Version);
    	wp->SetText(Temp);
      }
      else
        wp->SetText(gettext(TEXT("_@M199_")));
    } else {
	// LKTOKEN  _@M240_ = "Disconnected" 
      wp->SetText(gettext(TEXT("_@M240_")));
    }
    wp->RefreshDisplay();
  }

  wp = (WndProperty*)wf->FindByName(TEXT("prpLogger"));
  if (wp) {
    if (LoggerGActive()) {
      if (LoggerActive) {
	// LKTOKEN  _@M494_ = "ON (G)" 
        wp->SetText(gettext(TEXT("_@M494_")));
      } else {
	// LKTOKEN  _@M489_ = "OFF (G)" 
        wp->SetText(gettext(TEXT("_@M489_")));
      }
    }
    else { // no G Record
      if (LoggerActive) {
	// LKTOKEN  _@M495_ = "ON (no G)" 
        wp->SetText(gettext(TEXT("_@M495_")));
      } else {
	// LKTOKEN  _@M490_ = "OFF (no G)" 
        wp->SetText(gettext(TEXT("_@M490_")));
      }
    }
    wp->RefreshDisplay();
  }

  wp = (WndProperty*)wf->FindByName(TEXT("prpDeclared"));
  if (wp) {
    if (DeclaredToDevice) {
	// LKTOKEN  _@M827_ = "Yes" 
      wp->SetText(gettext(TEXT("_@M827_")));
    } else {
      wp->SetText(gettext(TEXT("_@M890_"))); // No
    }
    wp->RefreshDisplay();
  }

  wp = (WndProperty*)wf->FindByName(TEXT("prpVersion"));
  if (wp) {
      TCHAR softversion[100];
#ifndef LKCOMPETITION
      wsprintf(softversion,_T("%s.%s"),_T(LKVERSION), _T(LKRELEASE));
#else
      wsprintf(softversion,_T("%s.%s Competition"),_T(LKVERSION), _T(LKRELEASE));
#endif
      wp->SetText(softversion);
      wp->RefreshDisplay();
  }

  wp = (WndProperty*)wf->FindByName(TEXT("prpBattBank"));
  if (wp) {
    _stprintf(Temp,TEXT("%d"),GPS_INFO.ExtBatt_Bank);
    wp->SetText(Temp);
    wp->RefreshDisplay();
  }
  wp = (WndProperty*)wf->FindByName(TEXT("prpBatt1Volt"));
  if (wp) {
	if (GPS_INFO.ExtBatt1_Voltage>=1000)
		_stprintf(Temp,TEXT("%.0f%%"),GPS_INFO.ExtBatt1_Voltage-1000);
	else
		_stprintf(Temp,TEXT("%.2f V"),GPS_INFO.ExtBatt1_Voltage);
    wp->SetText(Temp);
    wp->RefreshDisplay();
  }
  wp = (WndProperty*)wf->FindByName(TEXT("prpBatt2Volt"));
  if (wp) {
	if (GPS_INFO.ExtBatt1_Voltage>=1000)
		_stprintf(Temp,TEXT("%.0f%%"),GPS_INFO.ExtBatt2_Voltage-1000);
	else
		_stprintf(Temp,TEXT("%.2f V"),GPS_INFO.ExtBatt2_Voltage);
    wp->SetText(Temp);
    wp->RefreshDisplay();
  }

  wp = (WndProperty*)wf->FindByName(TEXT("prpBattery"));
  if (wp) {
    _stprintf(Temp,TEXT("\0"));
#if (WINDOWSPC<1)
    _stprintf(Temp2,TEXT("%d%% "), PDABatteryPercent);
    _tcscat(Temp, Temp2);
#endif
    if (GPS_INFO.SupplyBatteryVoltage == 0) {
      _stprintf(Temp2,TEXT("\0"));
    } else {
      _stprintf(Temp2,TEXT("%.1f V"),GPS_INFO.SupplyBatteryVoltage);
    }
    _tcscat(Temp, Temp2);

    wp->SetText(Temp);
    wp->RefreshDisplay();
  }
}
Esempio n. 3
0
void
LoggerImpl::StopLogger(const NMEA_INFO &gps_info) {
  TCHAR szMessage[MAX_PATH] = TEXT("\0");
  int iLoggerError=0;  // see switch statement for error handler
  if (LoggerActive) {
    LoggerActive = false;
    if (LoggerClearFreeSpace(gps_info)) {

      if (!is_simulator() && LoggerGActive())
        LoggerGStop(szLoggerFileName);

      int imCount=0;
      const int imMax=3;
      for (imCount=0; imCount < imMax; imCount++) {
        // MoveFile() nonzero==Success
        if (0 != MoveFile( szLoggerFileName, szFLoggerFileName)) {
          iLoggerError=0;
          break; // success
        }
        Sleep(750); // wait for file system cache to fix itself?
      }
      if (imCount == imMax) { // MoveFile() failed all attempts

        if (0 == MoveFile( szLoggerFileName, szFLoggerFileNameRoot)) { // try rename it and leave in root
          iLoggerError=1; //Fail.  NoMoveNoRename
        }
        else {
          iLoggerError=2; //NoMoveYesRename
        }
      }
    } else { // Insufficient disk space.  // MoveFile() nonzero==Success
      if (0 == MoveFile( szLoggerFileName, szFLoggerFileNameRoot)) { // try rename it and leave in root
        iLoggerError=3; //Fail.  Insufficient Disk Space, NoRename
      }
      else {
        iLoggerError=4; //Success.  Insufficient Disk Space, YesRename
      }
    }

    switch (iLoggerError) { //0=Success 1=NoMoveNoRename 2=NoMoveYesRename 3=NoSpaceNoRename 4=NoSpaceYesRename
    case 0:
      StartupStore(TEXT("Logger file successfully moved\r\n"));
      break;

    case 1: // NoMoveNoRename
      _tcsncpy(szMessage,TEXT("Logger file not copied.  It is in the root folder of your device and called "),MAX_PATH);
      _tcsncat(szMessage,szLoggerFileName,MAX_PATH);

      MessageBoxX(gettext(szMessage),
		gettext(TEXT("Logger Error")), MB_OK| MB_ICONERROR);
      _tcsncat(szMessage,TEXT("\r\n"),MAX_PATH);
      StartupStore(szMessage);
      break;

    case 2: // NoMoveYesRename
      _tcsncpy(szMessage,TEXT("Logger file not copied.  It is in the root folder of your device"),MAX_PATH);

      MessageBoxX(gettext(szMessage),
		gettext(TEXT("Logger Error")), MB_OK| MB_ICONERROR);
      _tcsncat(szMessage,TEXT("\r\n"),MAX_PATH);
      StartupStore(szMessage);
      break;

    case 3: // Insufficient Storage.  NoRename
      _tcsncpy(szMessage,TEXT("Insuff. storage. Logger file in device's root folder, called "),MAX_PATH);
      _tcsncat(szMessage,szLoggerFileName,MAX_PATH);

      MessageBoxX(gettext(szMessage),
		gettext(TEXT("Logger Error")), MB_OK| MB_ICONERROR);
      _tcsncat(szMessage,TEXT("\r\n"),MAX_PATH);
      StartupStore(szMessage);
      break;

    case 4: // Insufficient Storage.  YesRename
      _tcsncpy(szMessage,TEXT("Insufficient storage.  Logger file is in the root folder of your device"),MAX_PATH);

      MessageBoxX(gettext(szMessage),
		gettext(TEXT("Logger Error")), MB_OK| MB_ICONERROR);
      _tcsncat(szMessage,TEXT("\r\n"),MAX_PATH);
      StartupStore(szMessage);
      break;
} // error handler

    NumLoggerBuffered = 0;
  }
}