示例#1
0
void StartupLogFreeRamAndStorage() {
  unsigned long freeram = CheckFreeRam()/1024;
  TCHAR buffer[MAX_PATH];
  LocalPath(buffer);
  unsigned long freestorage = FindFreeSpace(buffer);
  StartupStore(TEXT(". Free ram=%ld K  storage=%ld K%s"), freeram,freestorage,NEWLINE);
}
示例#2
0
void StartupLogFreeRamAndStorage() {
  size_t freeram = CheckFreeRam()/1024;
  TCHAR buffer[MAX_PATH];
  LocalPath(buffer);
  size_t freestorage = FindFreeSpace(buffer);
  StartupStore(TEXT(". Free ram=%u K  storage=%u K") NEWLINE, (unsigned int)freeram,(unsigned int)freestorage);
}
示例#3
0
void FailStore(const TCHAR *Str, ...)
{
  TCHAR buf[MAX_PATH];
  va_list ap;

  va_start(ap, Str);
  _vstprintf(buf, Str, ap);
  va_end(ap);

  FILE *stream=NULL;
  static TCHAR szFileName[MAX_PATH];
  static bool initialised = false;

  if (!initialised) {
	LocalPath(szFileName, TEXT(LKF_FAILLOG));
	stream = _tfopen(szFileName, TEXT("ab+"));
	if (stream) {
		fclose(stream);
	}
	initialised = true;
  } 
  stream = _tfopen(szFileName,TEXT("ab+"));
  if (stream == NULL) {
	StartupStore(_T("------ FailStore failed, cannot open <%s>%s"), szFileName, NEWLINE);
	return;
  }
  fprintf(stream, "------%s%04d%02d%02d-%02d:%02d:%02d [%09u] FailStore Start, Version %s%s (%s %s) FreeRam=%ld %s",SNEWLINE,
	GPS_INFO.Year,GPS_INFO.Month,GPS_INFO.Day, GPS_INFO.Hour,GPS_INFO.Minute,GPS_INFO.Second,
	(unsigned int)GetTickCount(),LKVERSION, LKRELEASE,
	"",
#if WINDOWSPC >0
	"PC",
#else
	#ifdef PNA
	"PNA",
	#else
	"PDA",
	#endif
#endif

CheckFreeRam(),SNEWLINE); 
  fprintf(stream, "Message: %S%s", buf, SNEWLINE);
  fprintf(stream, "GPSINFO: Latitude=%f Longitude=%f Altitude=%f Speed=%f %s", 
	GPS_INFO.Latitude, GPS_INFO.Longitude, GPS_INFO.Altitude, GPS_INFO.Speed, SNEWLINE);

  fclose(stream);
  StartupStore(_T("------ %s%s"),buf,NEWLINE);
}
示例#4
0
void Topology::initCache()
{
    //Selecting caching scenarios based on available memory and topo size
    // Unfortunatelly I don't find a suitable algorithm to estimate the loaded
    // shapefile's memory footprint so we never choose mode2. KR
    long free_size = CheckFreeRam();
    long bounds_size = sizeof(rectObj)*shpfile.numshapes;

    //Cache mode selection based on available memory
    cache_mode = 0;
    free_size -= 10000*1024;		// Safe: if we don't have enough memory we use mode0
    if (free_size>bounds_size) cache_mode = 1;

    // TESTING ONLY, mode override
    //cache_mode = 2;

    shpBounds = NULL;
    shps = NULL;

    for (int i=0; i<shpfile.numshapes; i++) shpCache[i] = NULL;

    switch (cache_mode) {
    default:
    case 0:
        // Original
#ifdef DEBUG_TFC
        StartupStore(_T("Topology cache using mode 0%s"), NEWLINE);
#endif
        break;

    case 1:
        // Using bounds array in memory
#ifdef DEBUG_TFC
        StartupStore(_T(". Topology cache using mode 1%s"), NEWLINE);
#endif
        shpBounds = (rectObj*)malloc(sizeof(rectObj)*shpfile.numshapes);
        if (shpBounds == NULL) {
            //Fallback to mode 0
            StartupStore(_T("------ WARN Topology,  malloc failed shpBounds, fallback to mode0%s"), NEWLINE);
            cache_mode = 0;
            break;
        }
        // Get bounds for each shape from shapefile
        rectObj *prect;
        int retval;
        for (int i=0; i<shpfile.numshapes; i++) {
            prect = &shpBounds[i];
            retval = msSHPReadBounds(shpfile.hSHP, i, prect);
            if (retval) {
                StartupStore(_T("------ WARN Topology, shape bounds reading failed, fallback to mode0%s"), NEWLINE);
                // Cleanup
                free(shpBounds);
                shpBounds=NULL;
                cache_mode = 0;
                break;
            }
        }//for
        break;

    case 2:
        // Using shape array in memory
#ifdef DEBUG_TFC
        StartupStore(_T(". Topology cache using mode 2%s"), NEWLINE);
#endif
        shpBounds = NULL;
        shps = (XShape**)malloc(sizeof(XShape*)*shpfile.numshapes);
        if (shps == NULL) {
            //Fallback to mode 0
            StartupStore(_T("------ WARN Topology,  malloc failed shps, fallback to mode0%s"), NEWLINE);
            cache_mode = 0;
            break;
        }
        // Load all shapes to shps
        for (int i=0; i<shpfile.numshapes; i++) {
            if ( (shps[i] = addShape(i)) == NULL ) {
                StartupStore(_T("------ WARN Topology,  addShape failed for shps[%d], fallback to mode0%s"), i, NEWLINE);
                // Cleanup
                for (int j=0; j<i; j++) delete(shps[i]);
                free(shps);
                shps=NULL;
                cache_mode = 0;
                break;
            }
        }
    } //sw
}
示例#5
0
void Topology::updateCache(rectObj thebounds, bool purgeonly) {
  if (!triggerUpdateCache) return;

  if (!shapefileopen) return;

  in_scale = CheckScale();

  if (!in_scale) {
    // not visible, so flush the cache
    // otherwise we waste time on looking up which shapes are in bounds
    flushCache();
    triggerUpdateCache = false;
    in_scale_last = false;
    return;
  }

  if (purgeonly) {
    in_scale_last = in_scale;
    return;
  }

  triggerUpdateCache = false;

#ifdef DEBUG_TFC
#ifdef TOPOFASTCACHE
  StartupStore(TEXT("---UpdateCache() starts, mode%d%s"),cache_mode,NEWLINE);
#else
  StartupStore(TEXT("---UpdateCache() starts, original code%s"),NEWLINE);
#endif
  int starttick = GetTickCount();
#endif

#ifdef TOPOFASTCACHE
  if(msRectOverlap(&shpfile.bounds, &thebounds) != MS_TRUE) {
    // this happens if entire shape is out of range
    // so clear buffer.
    flushCache();
    in_scale_last = in_scale;
    return;
  }

  bool smaller = false;
  bool bigger = false;
  bool in_scale_again = in_scale && !in_scale_last;
  int shapes_loaded = 0;
  shapes_visible_count = 0;
  in_scale_last = in_scale;
  
  switch (cache_mode) {
    case 0: // Original code plus one special case
      smaller = (msRectContained(&thebounds, &lastBounds) == MS_TRUE);
      if (smaller) { //Special case, search inside, we don't need to load additional shapes, just remove
        shapes_visible_count = 0;
        for (int i=0; i<shpfile.numshapes; i++) {
          if (shpCache[i]) {
            if(msRectOverlap(&(shpCache[i]->shape.bounds), &thebounds) != MS_TRUE) {
              removeShape(i);
            } else shapes_visible_count++;
          }
        }//for
      } else { 
        //In this case we have to run the original algoritm
        msSHPWhichShapes(&shpfile, thebounds, 0);
        shapes_visible_count = 0;
        for (int i=0; i<shpfile.numshapes; i++) {
          if (msGetBit(shpfile.status, i)) {
            if (shpCache[i]==NULL) {
              // shape is now in range, and wasn't before
              shpCache[i] = addShape(i);
              shapes_loaded++;
            }
            shapes_visible_count++;
          } else {
            removeShape(i);
          }
        }//for
      }
      break;

    case 1:  // Bounds array in memory
      bigger = (msRectContained(&lastBounds, &thebounds) == MS_TRUE);
      smaller = (msRectContained(&thebounds, &lastBounds) == MS_TRUE);
      if (bigger || in_scale_again) { //We don't need to remove shapes, just load, so skip loaded ones
        for (int i=0; i<shpfile.numshapes; i++) {
          if (shpCache[i]) continue;
          if(msRectOverlap(&shpBounds[i], &thebounds) == MS_TRUE) {
            // shape is now in range, and wasn't before
            shpCache[i] = addShape(i);
            shapes_loaded++;
          }
        }//for
        shapes_visible_count+=shapes_loaded;
      } else
      if (smaller) { //Search inside, we don't need to load additional shapes, just remove
        for (int i=0; i<shpfile.numshapes; i++) {
          if (shpCache[i]==NULL) continue;
          if(msRectOverlap(&shpBounds[i], &thebounds) != MS_TRUE) {
            removeShape(i);
          } else shapes_visible_count++;
        }//for
      } else { 
        //Otherwise we have to search the all array
        for (int i=0; i<shpfile.numshapes; i++) {
          if(msRectOverlap(&shpBounds[i], &thebounds) == MS_TRUE) {
            if (shpCache[i]==NULL) {
              // shape is now in range, and wasn't before
              shpCache[i] = addShape(i);
              shapes_loaded++;
            }
            shapes_visible_count++;
          } else {
            removeShape(i);
          }
        }//for
      }
      break;

    case 2: // All shapes in memory	
      XShape *pshp;
      shapes_visible_count = 0;
      for (int i=0; i<shpfile.numshapes; i++) {
        pshp = shps[i];
        if(msRectOverlap(&(pshp->shape.bounds), &thebounds) == MS_TRUE) {
          shpCache[i] = pshp;
          shapes_visible_count++;
        } else {
          shpCache[i] = NULL;
        }
      }//for
      break;
    }//sw

    lastBounds = thebounds;
#else

  msSHPWhichShapes(&shpfile, thebounds, 0);
  if (!shpfile.status) {
    // this happens if entire shape is out of range
    // so clear buffer.
    flushCache();
    return;
  }

  shapes_visible_count = 0;

  for (int i=0; i<shpfile.numshapes; i++) {

    if (msGetBit(shpfile.status, i)) {
      
      if (shpCache[i]==NULL) {
	// shape is now in range, and wasn't before
	shpCache[i] = addShape(i);
      }
      shapes_visible_count++;
    } else {
      removeShape(i);
    }
  }
#endif

#ifdef DEBUG_TFC
  long free_size = CheckFreeRam();
  StartupStore(TEXT("   UpdateCache() ends, shps_visible=%d ram=%li (%dms)%s"),shapes_visible_count, free_size, GetTickCount()-starttick,NEWLINE);
#endif
}
示例#6
0
static void OnSplashPaint(WindowControl * Sender, HDC hDC){

 TCHAR srcfile[MAX_PATH];
 TCHAR fprefix[20];

 if (RUN_MODE==RUN_SHUTDOWN) return;

 if (RUN_MODE==RUN_WELCOME) 
	_tcscpy(fprefix,_T("LKSTART"));
 else
	_tcscpy(fprefix,_T("LKPROFILE"));

 LoadSplash(hDC,fprefix);

  if (RUN_MODE==RUN_WELCOME) {
	TCHAR mes[100];
	int pos=0;
	switch (ScreenSize) {
		case ss800x480:
			pos=12;
			break;
		case ss400x240:
			pos=12;
			break;
		case ss480x272:
			if (ScreenSizeX==854)
				pos=14;
			else
				pos=11;
			break;
		case ss640x480:
			pos=12;
			break;
		case ss320x240:
			pos=12;
			break;
		case ss896x672:
			pos=14;
			break;
		// --------- portrait -------------
		case ss240x320:
			pos=17;
			break;
		case ss480x640:
			pos=17;
			break;
		case ss272x480:
			pos=18;
			break;
		case ss240x400:
			pos=16;
			break;
		case ss480x800:
			pos=18;
			break;
		default:
			pos=11;
			break;
	}
	if (fullresetasked) {
		_stprintf(mes,_T("*** %s ***"),gettext(_T("_@M1757_")));
		RawWrite(hDC,mes,pos,1, RGB_DARKWHITE,WTMODE_NORMAL);
	} else {
#ifndef LKCOMPETITION
		_stprintf(mes,_T("Version %S.%S (%S)"),LKVERSION,LKRELEASE,__DATE__);
#else
		_stprintf(mes,_T("V%S.%S COMPETITION"),LKVERSION,LKRELEASE,__DATE__);
#endif
		RawWrite(hDC,mes,pos,1, RGB_DARKWHITE,WTMODE_NORMAL);
	}
  }

  if (RUN_MODE!=RUN_WELCOME) {

	// FillRect(hDC,&ScreenSizeR, LKBrush_Black); // REMOVE 

	TCHAR mes[100];
#ifndef LKCOMPETITION
	_stprintf(mes,_T("%S v%S.%S - %s"),LKFORK,LKVERSION,LKRELEASE,gettext(_T("_@M2054_")));
#else
	_stprintf(mes,_T("%SC v%S.%S - %s"),LKFORK,LKVERSION,LKRELEASE,gettext(_T("_@M2054_")));
#endif
	RawWrite(hDC,mes,1,1, RGB_LIGHTGREY,WTMODE_NORMAL);

	unsigned long freeram = CheckFreeRam()/1024;
	TCHAR buffer[MAX_PATH];
	LocalPath(buffer);
	unsigned long freestorage = FindFreeSpace(buffer);
	_stprintf(mes,_T("free ram %.1ldM  storage %.1ldM"), freeram/1024,freestorage/1024);
	RawWrite(hDC,mes,3,0, RGB_LIGHTGREY,WTMODE_NORMAL);

	if ( ScreenSize != ss320x240 && ScreenLandscape )
	RawWrite(hDC,_T("_______________________"),2,2, RGB_LIGHTGREY,WTMODE_NORMAL);

	if (fullresetasked) {
		_stprintf(mes,_T("%s"),gettext(_T("_@M1757_")));	// LK8000 PROFILES RESET
		RawWrite(hDC,mes,5,2, RGB_ICEWHITE, WTMODE_OUTLINED);
		_stprintf(mes,_T("%s"),gettext(_T("_@M1759_")));	// SELECTED IN SYSTEM
		RawWrite(hDC,mes,6,2, RGB_ICEWHITE, WTMODE_OUTLINED);
	} else {
		_stprintf(mes,_T("%s"),PilotName_Config);
		RawWrite(hDC,mes,4,2, RGB_ICEWHITE, WTMODE_OUTLINED);

		_stprintf(mes,_T("%s"),AircraftRego_Config);
		RawWrite(hDC,mes,5,2, RGB_AMBER, WTMODE_OUTLINED);

		_stprintf(mes,_T("%s"),AircraftType_Config);
		RawWrite(hDC,mes,6,2, RGB_AMBER, WTMODE_OUTLINED);

    LKASSERT(szPolarFile[0]);
		extern void LK_wsplitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext);
		LK_wsplitpath(szPolarFile, (WCHAR*) NULL, (WCHAR*) NULL, srcfile, (WCHAR*) NULL);

		_stprintf(mes,_T("%s %s"),gettext(_T("_@M528_")),srcfile);  // polar file
		RawWrite(hDC,mes,7,2, RGB_AMBER, WTMODE_OUTLINED);

    LKASSERT(startProfileFile[0]);
		LK_wsplitpath(startProfileFile, (WCHAR*) NULL, (WCHAR*) NULL, srcfile, (WCHAR*) NULL);
		_stprintf(mes,_T("%s: %s"),MsgToken(1746),srcfile);  
		RawWrite(hDC,mes,11,1, RGB_ICEWHITE, WTMODE_NORMAL);
	}


	// RawWrite(hDC,_T("_______________________"),8,2, RGB_LIGHTGREY,WTMODE_NORMAL); // REMOVE FOR THE 3.0

	return;
  }

}
示例#7
0
static void OnSplashPaint(WindowControl * Sender, LKSurface& Surface) {

    TCHAR srcfile[MAX_PATH];

    if (RUN_MODE == RUN_SHUTDOWN) return;

    if(RUN_MODE == RUN_WELCOME) {
        if(!StartBitmap) {
            StartBitmap = LoadSplash(_T("LKSTART"));
        }
        if(StartBitmap) {
            DrawSplash(Surface, StartBitmap);
        }
    } else {
        if(!ProfileBitmap) {
            ProfileBitmap = LoadSplash(_T("LKPROFILE"));
        }
        if(ProfileBitmap) {
            DrawSplash(Surface, ProfileBitmap);
        }
    }

    if (RUN_MODE == RUN_WELCOME) {
        TCHAR mes[100];
        int pos = 0;
        switch (ScreenSize) {
            case ss480x272:
                if (ScreenSizeX == 854)
                    pos = 14;
                else
#ifdef __linux__
                    pos = 12;
#else
                    pos = 11;
#endif
                break;
                // --------- portrait -------------
            case ss240x320:
#ifdef __linux__
                pos = 19;
#else
                pos = 17;
#endif
                break;
            default:
                // customized definition
                if (ScreenLandscape) {
                    switch (ScreenGeometry) {
                        case SCREEN_GEOMETRY_43:
                            pos = 12;
                            break;
                        case SCREEN_GEOMETRY_53:
                            pos = 12;
                            break;
                        case SCREEN_GEOMETRY_169:
                            pos = 11;
                            break;
                        default:
                            pos = 11;
                            break;
                    }
                } else {
                    // Portrait
                    // try to get a rule for text position...
                    switch (ScreenGeometry) {
                        case SCREEN_GEOMETRY_43:
#ifdef __linux__
                            pos = 18;
#else
                            pos = 17;
#endif
                            break;
                        case SCREEN_GEOMETRY_53:
                            pos = 20;
                            break;
                        case SCREEN_GEOMETRY_169:
#ifdef __linux__
                            pos = 22;
#else
                            pos = 20;
#endif
                            break;
                        default:
                            pos = 21;
                            break;
                    }

                }
                break;
        }
        if (FullResetAsked) {
            _stprintf(mes, _T("*** %s ***"), MsgToken(1757));
            RawWrite(Surface, mes, pos, 1, RGBDARKWHITE, WTMODE_NORMAL);
        } else {
#ifndef LKCOMPETITION
            _stprintf(mes, _T("Version %s.%s (%s)"), _T(LKVERSION), _T(LKRELEASE), _T(__DATE__));
#else
            _stprintf(mes, _T("V%s.%s (%s) COMPETITION"), _T(LKVERSION), _T(LKRELEASE), _T(__DATE__));
#endif
            RawWrite(Surface, mes, pos, 1, RGBDARKWHITE, WTMODE_NORMAL);
#ifdef KOBO
            if(IsKoboOTGKernel()) {
                RawWrite(Surface, _T("- USB host kernel -"), pos+1, 1, RGBDARKWHITE, WTMODE_NORMAL);
            }
#endif
        }
    }

    if (RUN_MODE != RUN_WELCOME) {

        // FillRect(hDC,&ScreenSizeR, LKBrush_Black); // REMOVE

        TCHAR mes[100];
#ifndef LKCOMPETITION
        _stprintf(mes, _T("%s v%s.%s - %s"), _T(LKFORK), _T(LKVERSION), _T(LKRELEASE), MsgToken(2054));
#else
        _stprintf(mes, _T("%sC v%s.%s - %s"), _T(LKFORK), _T(LKVERSION), _T(LKRELEASE), MsgToken(2054));
#endif
        #ifdef DITHER
        RawWrite(Surface, mes, 1, 1, RGBLIGHTGREY, WTMODE_OUTLINED);
        #else
        RawWrite(Surface, mes, 1, 1, RGBLIGHTGREY, WTMODE_NORMAL);
        #endif

        size_t freeram = CheckFreeRam() / 1024;
        TCHAR buffer[MAX_PATH];
        LocalPath(buffer);
        size_t freestorage = FindFreeSpace(buffer);
        _stprintf(mes, _T("free ram %.1uM  storage %.1uM"), (unsigned int) freeram / 1024, (unsigned int) freestorage / 1024);
        #ifdef DITHER
        RawWrite(Surface, mes, 3, 0, RGBLIGHTGREY, WTMODE_OUTLINED);
        #else
        RawWrite(Surface, mes, 3, 0, RGBLIGHTGREY, WTMODE_NORMAL);
        #endif

        if (ScreenSize != ss320x240 && ScreenLandscape)
            RawWrite(Surface, _T("_______________________"), 2, 2, RGBLIGHTGREY, WTMODE_NORMAL);

        if (FullResetAsked) {
            _stprintf(mes, _T("%s"), MsgToken(1757)); // LK8000 PROFILES RESET
            RawWrite(Surface, mes, 5, 2, RGBICEWHITE, WTMODE_OUTLINED);
            _stprintf(mes, _T("%s"), MsgToken(1759)); // SELECTED IN SYSTEM
            RawWrite(Surface, mes, 6, 2, RGBICEWHITE, WTMODE_OUTLINED);
        } else {
            _stprintf(mes, _T("%s"), PilotName_Config);
            RawWrite(Surface, mes, 4, 2, RGBICEWHITE, WTMODE_OUTLINED);

            _stprintf(mes, _T("%s"), AircraftRego_Config);
            RawWrite(Surface, mes, 5, 2, RGBAMBER, WTMODE_OUTLINED);

            _stprintf(mes, _T("%s"), AircraftType_Config);
            RawWrite(Surface, mes, 6, 2, RGBAMBER, WTMODE_OUTLINED);

            LKASSERT(szPolarFile[0]);
            extern void LK_tsplitpath(const TCHAR* path, TCHAR* drv, TCHAR* dir, TCHAR* name, TCHAR * ext);
            LK_tsplitpath(szPolarFile, (TCHAR*) NULL, (TCHAR*) NULL, srcfile, (TCHAR*) NULL);

            _stprintf(mes, _T("%s %s"), MsgToken(528), srcfile); // polar file
            RawWrite(Surface, mes, 7, 2, RGBAMBER, WTMODE_OUTLINED);

            LKASSERT(startProfileFile[0]);
            LK_tsplitpath(startProfileFile, (TCHAR*) NULL, (TCHAR*) NULL, srcfile, (TCHAR*) NULL);
            _stprintf(mes, _T("%s: %s"), MsgToken(1746), srcfile);
            RawWrite(Surface, mes, 11, 1, RGBICEWHITE, WTMODE_NORMAL);
        }


        // RawWrite(hDC,_T("_______________________"),8,2, RGB_LIGHTGREY,WTMODE_NORMAL); // REMOVE FOR THE 3.0

        return;
    }

}